Skip to content

Commit 3017c9d

Browse files
committed
优化-规范化命名
优化-规范化命名
1 parent a4627c9 commit 3017c9d

File tree

10 files changed

+137
-91
lines changed

10 files changed

+137
-91
lines changed

public/cpp/actor/actor_base/actor_base.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ namespace ngl
305305
static void send_client(i64_actorid aid, const std::shared_ptr<T>& adata)
306306
{
307307
if (aid == nguid::make())
308+
{
308309
return;
310+
}
309311
auto pro = create_cpro(adata);
310312
cpro_push_actorid(pro, aid);
311313
handle_pram lpram = handle_pram::create(aid, nguid::make(), pro);
@@ -318,9 +320,13 @@ namespace ngl
318320
{
319321
const tab_servers* tab = ttab_servers::tab(agatewayid);
320322
if (tab == nullptr)
323+
{
321324
return;
325+
}
322326
if (tab->m_type != ngl::NODE_TYPE::GATEWAY)
327+
{
323328
return;
329+
}
324330
auto pro = create_cpro(adata);
325331
cpro_push_actorid(pro, aid);
326332
send_server(agatewayid, *pro.get(), nguid::make(), aid);
@@ -338,7 +344,9 @@ namespace ngl
338344
static void client_pro(ITOR abeg, ITOR aend, const std::shared_ptr<T>& adata)
339345
{
340346
if (abeg == aend)
347+
{
341348
return;
349+
}
342350
auto pro = create_cpro(adata);
343351
std::for_each(abeg, aend, [&pro](i64_actorid aactorid)
344352
{
@@ -546,7 +554,9 @@ namespace ngl
546554
{
547555
static bool lfirst = true;
548556
if (lfirst == false)
557+
{
549558
return;
559+
}
550560
lfirst = false;
551561
TDerived::nregister();
552562
if (atype != ngl::ACTOR_LOG)

public/cpp/actor/actor_base/actor_client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,9 @@ namespace ngl
293293

294294
if (nconfig::m_nodetype != NODE_TYPE::ROBOT)
295295
{
296-
auto pro = std::make_shared<np_actornode_update>();
297-
*pro = lparm->m_mass;
296+
auto pro = std::make_shared<np_actornode_update_server>();
297+
pro->m_data = lparm->m_mass;
298+
pro->m_data.m_actorservermass = true;
298299
send_actor(actor_server::actorid(), pro);
299300
}
300301

public/cpp/actor/actor_base/actor_server.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ namespace ngl
3636

3737
register_handle_custom<actor_server>::func<
3838
np_actornode_register
39-
, np_actornode_update
39+
, np_actornode_update_server
4040
, np_actor_gatewayid_updata
41-
, np_actornode_update_mass
4241
>(true);
4342
}
4443

@@ -122,17 +121,17 @@ namespace ngl
122121
return true;
123122
}
124123

125-
bool actor_server::handle(const message<np_actornode_update>& adata)
124+
bool actor_server::handle(const message<np_actornode_update_server>& adata)
126125
{
127126
Try
128127
{
129128
auto lrecv = adata.get_data();
130129
auto lpack = adata.m_pack;
131130
Assert(lpack != nullptr)
132131
const i32_serverid lserverid = lpack->m_id;
133-
naddress::actor_add(lserverid, lrecv->m_add);
134-
naddress::actor_del(lrecv->m_del);
135-
if (lrecv->m_actorservermass)
132+
naddress::actor_add(lserverid, lrecv->m_data.m_add);
133+
naddress::actor_del(lrecv->m_data.m_del);
134+
if (lrecv->m_data.m_actorservermass)
136135
{
137136
// # 分发给其他结点
138137
std::vector<i32_sessionid> lvec;
@@ -147,7 +146,7 @@ namespace ngl
147146
);
148147
if (!lvec.empty())
149148
{
150-
nets::sendmore(lvec, *lrecv, nguid::moreactor(), id_guid());
149+
nets::sendmore(lvec, lrecv->m_data, nguid::moreactor(), id_guid());
151150
}
152151
}
153152
}Catch
@@ -183,21 +182,4 @@ namespace ngl
183182
}
184183
return true;
185184
}
186-
187-
bool actor_server::handle(const message<np_actornode_update_mass>& adata)
188-
{
189-
auto lparm = adata.get_data();
190-
auto lpack = adata.m_pack;
191-
int32_t lthreadid = adata.m_thread;
192-
193-
message<np_actornode_update> lmessage(lthreadid, lpack, (np_actornode_update*)&lparm->m_mass);
194-
195-
handle(lmessage);
196-
197-
if (lparm->m_fun != nullptr)
198-
{
199-
lparm->m_fun();
200-
}
201-
return true;
202-
}
203185
}//namespace ngl

public/cpp/actor/actor_base/actor_server.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ namespace ngl
3333
bool handle(const message<np_actornode_register>& adata);
3434

3535
// # 更新结点中的actor
36-
bool handle(const message<np_actornode_update>& adata);
36+
bool handle(const message<np_actornode_update_server>& adata);
3737

3838
// # 更新gateway表 actor_role.guidid与gateway server id对应关系
3939
bool handle(const message<np_actor_gatewayid_updata>& adata);
40-
41-
bool handle(const message<np_actornode_update_mass>& adata);
4240
};
4341
}//namespace ngl

public/cpp/actor/actor_logic/gateway/actor_gateway.cpp

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace ngl
2828
{
2929
register_handle_custom<actor_gateway>::func<
3030
np_actorrole_login
31+
, np_gateway_close_session
3132
, np_actorswitch_process<np_actorswitch_process_role>
3233
, np_actor_session_close
3334
, np_actor_kcp
@@ -61,6 +62,40 @@ namespace ngl
6162
send_actor(actor_gatewayg2c::actorid(id()), apro);
6263
}
6364

65+
bool actor_gateway::handle(const message<np_gateway_close_session>& adata)
66+
{
67+
i32_actordataid lroleid = adata.get_data()->m_roleid;
68+
i16_area larea = adata.get_data()->m_area;
69+
gateway_socket* linfo = m_info.get(larea, lroleid);
70+
if (linfo == nullptr)
71+
{
72+
return true;
73+
}
74+
75+
if (linfo->m_socket == 0)
76+
{
77+
m_info.remove_actorid(nguid::make(ACTOR_NONE, larea, lroleid));
78+
}
79+
80+
auto pro = std::make_shared<np_actor_gatewayinfo_updata>();
81+
pro->m_delactorid.push_back(nguid::make(ACTOR_NONE, larea, lroleid));
82+
update_gateway_info(pro);
83+
84+
{
85+
auto pro = std::make_shared<np_actor_disconnect_close>();
86+
pro->m_actorid = nguid::make(ACTOR_ROLE, larea, lroleid);
87+
// ##### 通知game服务器 玩家已经断开连接
88+
send_actor(pro->m_actorid, pro);
89+
// ##### 通知login服务器 玩家已经断开连接
90+
ttab_servers::foreach_server(LOGIN, tab_self_area, [&pro, this](const tab_servers* atab)
91+
{
92+
nguid lguid(ACTOR_LOGIN, tab_self_area, atab->m_id);
93+
send_actor(lguid, pro);
94+
});
95+
}
96+
return true;
97+
}
98+
6499
void actor_gateway::session_close(gateway_socket* ainfo)
65100
{
66101
Assert(ainfo != nullptr);
@@ -76,33 +111,12 @@ namespace ngl
76111
.m_count = 1,
77112
.m_fun = [this, lroleid, larea](const wheel_node* anode)
78113
{
79-
gateway_socket* linfo = m_info.get(larea, lroleid);
80-
if (linfo == nullptr)
81-
{
82-
return;
83-
}
84-
85-
if (linfo->m_socket == 0)
86-
{
87-
m_info.remove_actorid(nguid::make(ACTOR_NONE, larea, lroleid));
88-
}
89-
90-
auto pro = std::make_shared<np_actor_gatewayinfo_updata>();
91-
pro->m_delactorid.push_back(nguid::make(ACTOR_NONE, larea, lroleid));
92-
update_gateway_info(pro);
93-
94-
{
95-
auto pro = std::make_shared<np_actor_disconnect_close>();
96-
pro->m_actorid = nguid::make(ACTOR_ROLE, larea, lroleid);
97-
// ##### 通知game服务器 玩家已经断开连接
98-
send_actor(pro->m_actorid, pro);
99-
// ##### 通知login服务器 玩家已经断开连接
100-
ttab_servers::foreach_server(LOGIN, tab_self_area, [&pro, this](const tab_servers* atab)
101-
{
102-
nguid lguid(ACTOR_LOGIN, tab_self_area, atab->m_id);
103-
send_actor(lguid, pro);
104-
});
105-
}
114+
auto pro = std::make_shared<np_gateway_close_session>(np_gateway_close_session
115+
{
116+
.m_roleid = lroleid,
117+
.m_area = larea,
118+
});
119+
send_actor(id_guid(), pro);
106120
}
107121
};
108122
twheel::wheel().addtimer(lparm);

public/cpp/actor/actor_logic/gateway/actor_gateway.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ namespace ngl
4646

4747
void update_gateway_info(const std::shared_ptr<np_actor_gatewayinfo_updata>& ap);
4848

49+
bool handle(const message<np_gateway_close_session>& adata);
4950
void session_close(gateway_socket* ainfo);
5051

5152
// # actor_login繫列gateway鯤소綠쒔되쩌(깻셩쩌session섟뚤壇돨game륩蛟포)

public/cpp/actor/nactor_auto.cpp

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -158,37 +158,39 @@ namespace ngl
158158
/*200000010*/, np_actornode_register_response
159159
/*200000011*/, np_actorclient_node_connect
160160
/*200000012*/, np_actornode_update
161-
/*200000013*/, np_actornode_update_mass
162-
/*200000014*/, np_actornode_connect_task
163-
/*200000015*/, np_actorrole_login
164-
/*200000016*/, np_actorserver_connect
165-
/*200000017*/, np_actor_session_close
166-
/*200000018*/, np_actor_disconnect_close
167-
/*200000019*/, np_logitem
168-
/*200000020*/, np_actor_broadcast
169-
/*200000021*/, np_actor_reloadcsv
170-
/*200000022*/, np_actor_csv_verify_version
171-
/*200000023*/, np_actor_senditem
172-
/*200000024*/, np_actor_gatewayinfo_updata
173-
/*200000025*/, np_actor_addmail
174-
/*200000026*/, np_actor_activity
175-
/*200000027*/, np_actor_gatewayid_updata
176-
/*200000028*/, np_actorswitch_process<np_actorswitch_process_role>
177-
/*200000029*/, np_actor_kcp
178-
/*200000030*/, np_calendar
179-
/*200000031*/, np_actor_close
180-
/*200000032*/, np_channel_register<pbdb::db_brief>
181-
/*200000033*/, np_channel_register_reply<pbdb::db_brief>
182-
/*200000034*/, np_channel_data<pbdb::db_brief>
183-
/*200000035*/, np_channel_register<pbdb::db_keyvalue>
184-
/*200000036*/, np_channel_register_reply<pbdb::db_keyvalue>
185-
/*200000037*/, np_channel_data<pbdb::db_keyvalue>
186-
/*200000038*/, np_channel_check
187-
/*200000039*/, np_roleban
161+
/*200000013*/, np_actornode_update_server
162+
/*200000014*/, np_actornode_update_mass
163+
/*200000015*/, np_actornode_connect_task
164+
/*200000016*/, np_actorrole_login
165+
/*200000017*/, np_actorserver_connect
166+
/*200000018*/, np_actor_session_close
167+
/*200000019*/, np_actor_disconnect_close
168+
/*200000020*/, np_logitem
169+
/*200000021*/, np_actor_broadcast
170+
/*200000022*/, np_actor_reloadcsv
171+
/*200000023*/, np_actor_csv_verify_version
172+
/*200000024*/, np_actor_senditem
173+
/*200000025*/, np_actor_gatewayinfo_updata
174+
/*200000026*/, np_actor_addmail
175+
/*200000027*/, np_actor_activity
176+
/*200000028*/, np_actor_gatewayid_updata
177+
/*200000029*/, np_actorswitch_process<np_actorswitch_process_role>
178+
/*200000030*/, np_actor_kcp
179+
/*200000031*/, np_calendar
180+
/*200000032*/, np_actor_close
181+
/*200000033*/, np_channel_register<pbdb::db_brief>
182+
/*200000034*/, np_channel_register_reply<pbdb::db_brief>
183+
/*200000035*/, np_channel_data<pbdb::db_brief>
184+
/*200000036*/, np_channel_register<pbdb::db_keyvalue>
185+
/*200000037*/, np_channel_register_reply<pbdb::db_keyvalue>
186+
/*200000038*/, np_channel_data<pbdb::db_keyvalue>
187+
/*200000039*/, np_channel_check
188+
/*200000040*/, np_roleban
189+
/*200000041*/, np_gateway_close_session
188190
// ### 事件相关协议 start ### //
189-
/*200000040*/, actor_events_logic::np_event_register
190-
/*200000041*/, np_eevents_logic_rolelogin
191-
/*200000042*/, np_eevents_logic_roleoffline
191+
/*200000042*/, actor_events_logic::np_event_register
192+
/*200000043*/, np_eevents_logic_rolelogin
193+
/*200000044*/, np_eevents_logic_roleoffline
192194
// ### 事件相关协议 finish ### //
193195
> (EPROTOCOL_TYPE_CUSTOM);
194196
}

public/cpp/actor/nprotocol.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,20 @@ namespace ngl
107107
def_portocol(np_actornode_update, m_id, m_add, m_del, m_actorservermass)
108108
};
109109

110+
struct np_actornode_update_server
111+
{
112+
np_actornode_update m_data;
113+
114+
def_portocol(np_actornode_update_server, m_data)
115+
};
116+
110117
// 向actor客户端同步结点信息(群发)
111118
struct np_actornode_update_mass
112119
{
113120
np_actornode_update m_mass;
114121
std::function<void()> m_fun;
115122

116-
def_portocol(np_actornode_update_mass, m_mass)
123+
def_portocol(np_actornode_update_mass_client, m_mass)
117124
};
118125

119126
// ---- [local actor client]
@@ -332,6 +339,14 @@ namespace ngl
332339
def_portocol(np_actorrole_login, m_session, m_accountid, m_account, m_roleid, m_gameid, m_gatewayid, m_area, m_iscreate, m_socketid, m_request_actor)
333340
};
334341

342+
struct np_gateway_close_session
343+
{
344+
i32_actordataid m_roleid;
345+
i16_area m_area;
346+
347+
def_portocol(np_gateway_close_session, m_roleid, m_area)
348+
};
349+
335350
template <typename T, EPROTOCOL_TYPE PROTYPE, bool ISUSING, typename TREAL>
336351
struct np_actor_forward
337352
{

public/cpp/net/net.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,11 @@ namespace ngl
141141
{
142142
auto lcount = (int)amsg.size();
143143
auto lpack = std::make_shared<pack>();
144-
lpack->malloc(lcount);
144+
lpack->malloc(lcount+1);
145145
memcpy(lpack->m_buff, amsg.c_str(), lcount);
146-
lpack->m_len = lcount;
147-
lpack->m_pos = lcount;
146+
lpack->m_buff[lcount] = '\0';
147+
lpack->m_len = lcount+1;
148+
lpack->m_pos = lcount+1;
148149
return nets::sendpack(asession, lpack);
149150
}
150151

public/cpp/protocol/protocol/protocol.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,29 @@ namespace ngl
134134
handle_cmd::push("/actor_count", [](const std::shared_ptr<pack>& pack, const std::vector<std::string>&)
135135
{
136136
int32_t lcount = actor_manage::getInstance().actor_count();
137-
std::string lstr = std::format("actor count:{}\r\n", lcount);
137+
std::string lstr = std::format("actor count:{}\n", lcount);
138+
nets::sendmsg(pack->m_id, lstr);
139+
}
140+
);
141+
handle_cmd::push("/print_guid", [](const std::shared_ptr<pack>& pack, const std::vector<std::string>& avec)
142+
{
143+
ENUM_ACTOR ltype;
144+
ltype = em<ENUM_ACTOR>::get_enum(avec[1].c_str());
145+
if (ltype == em<ENUM_ACTOR>::enum_null())
146+
{
147+
return;
148+
}
149+
150+
auto lmap = naddress::get_actorserver_map();
151+
//nguid, i32_serverid
152+
std::string lstr = "#print_guid";
153+
for (const auto& [lguid, serverid] : lmap)
154+
{
155+
if (lguid.type() == ltype)
156+
{
157+
lstr += std::format("\r\n{}==={}", lguid, serverid);
158+
}
159+
}
138160
nets::sendmsg(pack->m_id, lstr);
139161
}
140162
);

0 commit comments

Comments
 (0)