user_head.cpp
3.85 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "user_head.h"
#include "gateway.h"
#include <gateway_msg.pb.h>
#include "user.h"
#include <db.pb.h>
#include "dbproxy.h"
#include "level.h"
head_cfg_mgr_t* g_head_cfg_mgr;
//////////////////////////////////////////////////////////////////////////
//head config
//////////////////////////////////////////////////////////////////////////
head_cfg_t* head_cfg_mgr_t::find( USER_HEAD_ID id )
{
auto it = this->head_cfg_map.find(id);
if (this->head_cfg_map.end() == it){
return NULL;
}
return &it->second;
}
void head_cfg_mgr_t::init()
{
this->head_cfg_map.clear();
}
bool head_cfg_mgr_t::load_cfg()
{
const std::string cfg_path = "./cfg/head.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 *)"head")) {
head_cfg_t head_cfg;
uint32_t need = 0;
xml.get_xml_prop(cur, head_cfg.id, "id");
xml.get_xml_prop(cur, need, "needCard");
head_cfg.need_card = (0 == need ? false : true);
if (!this->head_cfg_map.insert(std::make_pair(head_cfg.id, head_cfg)).second) {
ALERT_LOG("[id:%u]", head_cfg.id);
return false;
}
}
if (!xmlStrcmp(cur->name, (const xmlChar *)"headFrame")) {
head_frame_cfg_t cfg;
xml.get_xml_prop(cur, cfg.id, "id");
xml.get_xml_prop_def(cur, cfg.need_score, "needScore", 0);
xml.get_xml_prop_def(cur, cfg.need_charm, "needCharm", 0);
if (0 < cfg.need_score){
}
if (0 < cfg.need_charm){
}
if (NULL == g_item_cfg_mgr->find(cfg.id)){
ALERT_LOG("[id:%u]", cfg.id);
return false;
}
// if (!g_gd_score_cfg_mgr->has_level(cfg.need_score_level)){
// ALERT_LOG("[id:%u]", cfg.id);
// return false;
// }
if (!this->head_frame_cfg_map.insert(std::make_pair(cfg.id, cfg)).second) {
ALERT_LOG("[id:%u]", cfg.id);
return false;
}
}
cur = cur->next;
}//while
return true;
}
head_frame_cfg_t* head_cfg_mgr_t::find_head_frame( USER_HEAD_FRAME_ID id )
{
auto it = this->head_frame_cfg_map.find(id);
if (this->head_frame_cfg_map.end() == it){
return NULL;
}
return &it->second;
}
head_cfg_t::head_cfg_t()
{
this->id = 0;
this->need_card = false;
}
//////////////////////////////////////////////////////////////////////////
int gateway_t::on_change_head_msg(el::lib_tcp_peer_info_t* peer_fd_info, google::protobuf::Message* msg, user_t* user)
{
if (!user->wx_unionid.empty()){
ERROR_LOG("");
return share_msg::EC_VALUE_INVALID;
}
auto in = (gateway_msg::change_head_msg*)msg;
auto head = in->head();
head_cfg_t* head_cfg = g_head_cfg_mgr->find(head);
if (NULL == head_cfg){
return share_msg::EC_VALUE_INVALID;
}
if (head_cfg->need_card){// need delete card
}
{//send to db
db_msg::change_head_msg out;
out.set_head(head);
g_dbproxy->send_msg(&out, user->uid(), db_change_head_msg_cmd, NULL);
}
{//send to user
gateway_msg::change_head_msg_res out;
out.set_head(head);
user->send_msg_res(&out);
}
user->user_show.set_head(head);
return 0;
}
int gateway_t::on_change_head_frame_msg(el::lib_tcp_peer_info_t* peer_fd_info, google::protobuf::Message* msg, user_t* user)
{
auto in = (gateway_msg::change_head_frame_msg*)msg;
auto head_frame = in->head_frame();
auto* cfg = g_head_cfg_mgr->find_head_frame(head_frame);
if (NULL == cfg){
return share_msg::EC_VALUE_INVALID;
}
if (user->item_mgr.get_item_cnt(head_frame) < 1){
return share_msg::EC_INEXISTENT_ITEM;
}
if (0 != cfg->need_score){
}
if (0 != cfg->need_charm){
}
{//send to db
user->event_mgr.update_event(user->uid(), common_msg::FOREVER_EVENT_HEAD_FRAME, 0, head_frame, 0);
}
{//send to user
gateway_msg::change_head_frame_msg_res out;
out.set_head_frame(head_frame);
user->send_msg_res(&out);
}
user->user_show.set_head_frame(head_frame);
return 0;
}