diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index 630bdc8..cb8715b 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -22,6 +22,8 @@ #include "gameclientmgr.h" #include "ss_msgid.pb.h" #include "ss_proto.pb.h" +#include "mastersvr.h" +#include "mastersvrmgr.h" struct MsgNode { @@ -93,6 +95,7 @@ void App::Init(int argc, char* argv[]) uuid.SetMachineId(instance_id); GameClientMgr::Instance()->Init(); TargetConnMgr::Instance()->Init(); + MasterSvrMgr::Instance()->Init(); a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()}); { @@ -114,6 +117,7 @@ void App::UnInit() if (terminated) { return; } + MasterSvrMgr::Instance()->UnInit(); TargetConnMgr::Instance()->UnInit(); GameClientMgr::Instance()->UnInit(); GCListener::Instance()->UnInit(); @@ -300,6 +304,11 @@ void App::DispatchMsg() ProcessTargetServerMsg(hdr); } break; + case SF_MasterServer: + { + ProcessMasterServerMsg(hdr); + } + break; } if (pdelnode->buf) { free(pdelnode->buf); @@ -358,6 +367,11 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr) GCListener::Instance()->ForwardTargetConnMsg(hdr); } +void App::ProcessMasterServerMsg(f8::MsgHdr& hdr) +{ + +} + void App::ProcessIMMsg() { if (!im_work_node_ && im_top_node_) { diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index e8c4563..3308881 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -43,6 +43,7 @@ private: void ProcessClientMsg(f8::MsgHdr& hdr); void ProcessTargetServerMsg(f8::MsgHdr& hdr); + void ProcessMasterServerMsg(f8::MsgHdr& hdr); void InitLog(); void UnInitLog(); diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index 4a5a9c8..cb07ea9 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -4,6 +4,7 @@ enum SocketFrom_e { SF_Client, SF_TargetServer, + SF_MasterServer, }; enum InnerMesssage_e diff --git a/server/wsproxy/mastersvr.cc b/server/wsproxy/mastersvr.cc index f6a7b31..d39dc5a 100644 --- a/server/wsproxy/mastersvr.cc +++ b/server/wsproxy/mastersvr.cc @@ -64,28 +64,6 @@ bool MasterSvr::Connected() return tcp_client_->Connected(); } -void MasterSvr::ForwardClientMsg(f8::MsgHdr& hdr) -{ - char* buff = (char*)malloc(sizeof(f8::WSProxyPackHead_C) + hdr.buflen); - f8::WSProxyPackHead_C* head = (f8::WSProxyPackHead_C*)buff; - head->packlen = hdr.buflen; - head->msgid = hdr.msgid; - head->seqid = hdr.seqid; - head->magic_code = f8::MAGIC_CODE; - #if 0 - head->rpc_error_code = 0; - #endif - head->socket_handle = hdr.socket_handle; - head->ip_saddr = hdr.ip_saddr; - - if (hdr.buflen > 0) { - memmove(buff + sizeof(f8::WSProxyPackHead_C), hdr.buf, hdr.buflen); - } - - tcp_client_->SendBuff(buff, sizeof(f8::WSProxyPackHead_C) + head->packlen); - free(buff); -} - void MasterSvr::on_error(a8::TcpClient* sender, int errorId) { a8::UdpLog::Instance()->Error("MasterSvr errorid=%d", {errorId}); @@ -129,7 +107,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len if (recv_bufflen_ - offset < sizeof(f8::WSProxyPackHead_S) + p->packlen) { break; } - App::Instance()->AddSocketMsg(SF_TargetServer, + App::Instance()->AddSocketMsg(SF_MasterServer, p->socket_handle, instance_id, p->msgid, diff --git a/server/wsproxy/mastersvr.h b/server/wsproxy/mastersvr.h index e79d435..86698ce 100644 --- a/server/wsproxy/mastersvr.h +++ b/server/wsproxy/mastersvr.h @@ -14,7 +14,6 @@ class MasterSvr int instance_id = 0; std::string remote_ip; int remote_port = 0; - int matching_player_num = 0; a8::tick_t last_pong_tick = 0; public: @@ -29,15 +28,9 @@ class MasterSvr void SendMsg(T& msg) { static int msgid = f8::Net_GetMessageId(msg); - #if 1 f8::Net_SendProxyCMsg(tcp_client_, msgid, msg); - #else - f8::Net_SendMsg(tcp_client_, 0, msgid, msg); - #endif } - void ForwardClientMsg(f8::MsgHdr& hdr); - private: void on_error(a8::TcpClient* sender, int errorId); void on_connect(a8::TcpClient* sender); diff --git a/server/wsproxy/mastersvrmgr.cc b/server/wsproxy/mastersvrmgr.cc index e69de29..bc66b85 100644 --- a/server/wsproxy/mastersvrmgr.cc +++ b/server/wsproxy/mastersvrmgr.cc @@ -0,0 +1,32 @@ +#include "precompile.h" + +#include "mastersvrmgr.h" +#include "mastersvr.h" +#include "jsondatamgr.h" + +void MasterSvrMgr::Init() +{ + auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf(); + for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) { + auto master_svr_conf = master_svr_cluster_conf->At(i); + int instance_id = master_svr_conf->At("instance_id")->AsXValue(); + std::string remote_ip = master_svr_conf->At("ip")->AsXValue(); + int remote_port = master_svr_conf->At("port")->AsXValue(); + { + MasterSvr* conn = new MasterSvr(); + conn->Init(instance_id, remote_ip, remote_port); + mastersvr_hash_[conn->instance_id] = conn; + conn->Open(); + } + } +} + +void MasterSvrMgr::UnInit() +{ +} + +MasterSvr* MasterSvrMgr::GetConnByInstanceId(int instance_id) +{ + auto itr = mastersvr_hash_.find(instance_id); + return itr != mastersvr_hash_.end() ? itr->second : nullptr; +} diff --git a/server/wsproxy/mastersvrmgr.h b/server/wsproxy/mastersvrmgr.h index 1fda6ad..c3e08d6 100644 --- a/server/wsproxy/mastersvrmgr.h +++ b/server/wsproxy/mastersvrmgr.h @@ -15,5 +15,5 @@ class MasterSvrMgr : public a8::Singleton MasterSvr* GetConnByInstanceId(int instance_id); private: - std::map target_conn_hash_; + std::map mastersvr_hash_; };