添加断线重连处理

This commit is contained in:
aozhiwei 2020-08-10 16:41:50 +08:00
parent 053cfb95ae
commit 12f218650a
5 changed files with 60 additions and 10 deletions

View File

@ -13,6 +13,6 @@ enum SSMessageId_e
_SS_CMPing = 101;
_SS_SMRpcError = 102;
_SS_CMLogin = 103;
_SS_CMReConnect = 104;
_SS_CMReconnect = 104;
}

View File

@ -13,7 +13,14 @@ message SS_CMLogin_CMReConnect_CommonHead
optional int32 server_id = 1;
}
message SS_CMLogin_CMReConnect_CommonHead2
message SS_CMLogin
{
optional int32 server_id = 1; //
optional string team_uuid = 2; //
optional string account_id = 3; //id
}
message SS_CMReconnect
{
optional int32 server_id = 1; //
optional string team_uuid = 2; //
@ -28,6 +35,8 @@ message SS_WSP_RequestTargetServer
optional int64 context_id = 1;
optional string account_id = 2;
optional string team_id = 3;
optional string server_info = 4;
optional int32 is_reconnect = 5;
}
message SS_MS_ResponseTargetServer

View File

@ -422,11 +422,42 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
return;
}
#if MASTER_MODE
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
ss::SS_CMLogin_CMReConnect_CommonHead2 msg;
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) {
GameClient* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
if (!client) {
switch (hdr.msgid) {
case ss::_SS_CMLogin:
{
ss::SS_CMLogin msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
if (ok) {
MasterSvrMgr::Instance()->RequestTargetServer(hdr, msg.team_uuid(), msg.account_id());
MasterSvrMgr::Instance()->RequestTargetServer(hdr,
msg.team_uuid(),
msg.account_id(),
"",
0);
}
}
break;
case ss::_SS_CMReconnect:
{
ss::SS_CMReconnect msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
if (ok) {
MasterSvrMgr::Instance()->RequestTargetServer(hdr,
msg.team_uuid(),
msg.account_id(),
"",
1);
}
}
break;
default:
{
abort();
}
break;
}
}
} else {
GameClient* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
@ -487,7 +518,7 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
if (hdr.msgid < 100) {
return;
}
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) {
GameClientMgr::Instance()->BindTargetConn(hdr.socket_handle, hdr.ip_saddr);
GCListener::Instance()->MarkClient(hdr.socket_handle, true);
}

View File

@ -68,7 +68,11 @@ MasterSvr* MasterSvrMgr::GetConnById(int instance_id)
return itr != mastersvr_hash_.end() ? itr->second : nullptr;
}
void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id)
void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr,
const std::string& team_id,
const std::string& account_id,
const std::string& server_info,
int is_reconnect)
{
#if GAME_ID == 9003
{
@ -113,6 +117,8 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_
ss::SS_WSP_RequestTargetServer msg;
msg.set_context_id(curr_context_id_);
msg.set_team_id(team_uuid);
msg.set_server_info(server_info);
msg.set_is_reconnect(is_reconnect);
svr->SendMsg(msg);
pending_socket_hash_[hdr.socket_handle] = curr_context_id_;

View File

@ -26,7 +26,11 @@ class MasterSvrMgr : public a8::Singleton<MasterSvrMgr>
void UnInit();
void _SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_ResponseTargetServer& msg);
void RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id);
void RequestTargetServer(f8::MsgHdr& hdr,
const std::string& team_id,
const std::string& account_id,
const std::string& server_info,
int is_reconnect);
void RemoveRequest(int socket_handle, long long context_id, bool auto_free);
private: