btl_cnt_reward.cpp
1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "btl_cnt_reward.h"
#include "item.h"
#include "gateway.h"
#include "user.h"
btl_cnt_reward_cfg_mgr_t* g_btl_cnt_reward_cfg_mgr;
//////////////////////////////////////////////////////////////////////////
//btl_cnt_reward config
//////////////////////////////////////////////////////////////////////////
void btl_cnt_reward_cfg_mgr_t::init()
{
this->reward_map.clear();
}
bool btl_cnt_reward_cfg_mgr_t::load_cfg()
{
const std::string cfg_path = "./cfg/btl_cnt_reward.xml";
el::lib_xmlparser_t xml;
int ret = xml.open(cfg_path.c_str());
if (SUCC != ret){
ALERT_LOG("open");
return false;
}
this->init();
xml.move2children_node();
xmlNodePtr cur = xml.node_ptr;
while (cur) {
if (!xmlStrcmp(cur->name, (const xmlChar *)"reward")) {
uint32_t id = 0;
xml.get_xml_prop(cur, id, "id");
btl_cnt_reward_element_t bcre;
xml.get_xml_prop(cur, bcre.pr, "pr");
std::string str_def;
std::string str_item;
xml.get_xml_prop_def(cur, str_item, "item", str_def);
std::vector<uint_pair> uint_pair_val;
str_split_uint(str_item, uint_pair_val);
FOREACH(uint_pair_val, it) {
if (NULL == g_item_cfg_mgr->find(it->key)){
ALERT_LOG("[item_id:%u]", it->key);
return false;
}
share_msg::item_t item;
item.set_id(it->key);
item.set_cnt(it->val);
bcre.reward_vec.push_back(item);
}
this->reward_map.insert(std::make_pair(id, bcre));
}
cur = cur->next;
}//while
uint32_t all_pr = 0;
FOREACH(this->reward_map, it){
btl_cnt_reward_element_t& bcre = it->second;
if (0 == bcre.pr){
ALERT_LOG("[pr:0]");
return false;
}
all_pr += bcre.pr;
}
if (1000 != all_pr){
ALERT_LOG("[1000 != all_pr]");
return false;
}
return true;
}
btl_cnt_reward_element_t* btl_cnt_reward_cfg_mgr_t::find( uint32_t id )
{
auto it = this->reward_map.find(id);
if (this->reward_map.end() == it){
return NULL;
}
return &it->second;
}