From a6c8f4c85d6eb38fd8e44f7f417a5812c42dea8e Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 5 Jun 2019 16:10:39 +0800 Subject: [PATCH] 1 --- server/tools/protobuild/ss_proto.proto | 1 + server/wsproxy/app.cc | 3 +-- server/wsproxy/mastersvrmgr.cc | 16 ++++++++++------ server/wsproxy/mastersvrmgr.h | 2 +- server/wsproxy/target_conn.cc | 3 +++ 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/server/tools/protobuild/ss_proto.proto b/server/tools/protobuild/ss_proto.proto index 705cc84..382c412 100644 --- a/server/tools/protobuild/ss_proto.proto +++ b/server/tools/protobuild/ss_proto.proto @@ -17,6 +17,7 @@ message SS_CMLogin_CMReConnect_CommonHead2 { optional int32 server_id = 1; optional string team_uuid = 2; + optional string account_id = 3; } message SS_WSP_RequestTargetServer diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index aa9c5e7..1464e8b 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -382,7 +382,7 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr) ss::SS_CMLogin_CMReConnect_CommonHead2 msg; bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset); if (ok) { - MasterSvrMgr::Instance()->RequestTargetServer(hdr, msg.team_uuid()); + MasterSvrMgr::Instance()->RequestTargetServer(hdr, msg.team_uuid(), msg.account_id()); } } else { GameClient* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle); @@ -626,4 +626,3 @@ void App::FreeIMMsgQueue() } im_msg_mutex_->unlock(); } - diff --git a/server/wsproxy/mastersvrmgr.cc b/server/wsproxy/mastersvrmgr.cc index 8738e07..2a3fec5 100644 --- a/server/wsproxy/mastersvrmgr.cc +++ b/server/wsproxy/mastersvrmgr.cc @@ -1,5 +1,7 @@ #include "precompile.h" +#include + #include #include @@ -64,17 +66,19 @@ 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) +void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id) { if (GetContextIdBySocket(hdr.socket_handle) != 0) { return; } - unsigned int code = a8::openssl::Crc32((unsigned char*)team_id.data(), team_id.size()); - #if 1 - MasterSvr* svr = GetConnById(2); - #else + unsigned int code = 0; + if (!team_id.empty()) { + code = a8::openssl::Crc32((unsigned char*)team_id.data(), team_id.size()); + } else { + std::string data = a8::Format("!%s_%s_%d", {account_id, App::Instance()->uuid.Generate(), getpid()}); + code = a8::openssl::Crc32((unsigned char*)data.data(), data.size()); + } MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1); - #endif if (svr) { ++curr_context_id_; a8::TimerAttacher* timer_attacher = new a8::TimerAttacher(); diff --git a/server/wsproxy/mastersvrmgr.h b/server/wsproxy/mastersvrmgr.h index 23c421c..a6c14ed 100644 --- a/server/wsproxy/mastersvrmgr.h +++ b/server/wsproxy/mastersvrmgr.h @@ -26,7 +26,7 @@ class MasterSvrMgr : public a8::Singleton 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); + void RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id, const std::string& account_id); void RemoveRequest(int socket_handle, long long context_id, bool auto_free); private: diff --git a/server/wsproxy/target_conn.cc b/server/wsproxy/target_conn.cc index e1a01d9..12d47bd 100644 --- a/server/wsproxy/target_conn.cc +++ b/server/wsproxy/target_conn.cc @@ -14,6 +14,9 @@ const int PACK_MAX = 1024 * 64 * 2; void TargetConn::Init(int instance_id, const std::string& remote_ip, int remote_port) { + if (remote_ip.empty()) { + abort(); + } this->instance_id = instance_id; this->remote_ip = remote_ip; this->remote_port = remote_port;