From fc5ed7f5779dc2a6d73d227c29abe36d02882e06 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 15 May 2019 14:18:55 +0800 Subject: [PATCH] 1 --- server/wsproxy/app.cc | 36 ++++++++++++++++++++++++------- server/wsproxy/app.h | 5 ++++- server/wsproxy/gameclientmgr.cc | 3 +++ server/wsproxy/gameclientmgr.h | 3 +++ server/wsproxy/jsondatamgr.cc | 24 +++++++++++++++++++++ server/wsproxy/jsondatamgr.h | 9 ++++++++ server/wsproxy/mastersvrmgr.cc | 2 +- server/wsproxy/target_conn.h | 4 ---- server/wsproxy/target_conn_mgr.cc | 6 ++++++ server/wsproxy/target_conn_mgr.h | 7 ++++++ 10 files changed, 85 insertions(+), 14 deletions(-) diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index cb8715b..f092aa1 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -16,14 +16,18 @@ #include "GCListener.h" #include "jsondatamgr.h" #include "handlermgr.h" -#include "target_conn.h" -#include "target_conn_mgr.h" #include "gameclient.h" #include "gameclientmgr.h" #include "ss_msgid.pb.h" #include "ss_proto.pb.h" + +#if MASTER_MODE #include "mastersvr.h" #include "mastersvrmgr.h" +#else +#include "target_conn.h" +#include "target_conn_mgr.h" +#endif struct MsgNode { @@ -94,8 +98,11 @@ void App::Init(int argc, char* argv[]) GCListener::Instance()->Init(); uuid.SetMachineId(instance_id); GameClientMgr::Instance()->Init(); - TargetConnMgr::Instance()->Init(); +#if MASTER_MODE MasterSvrMgr::Instance()->Init(); +#else + TargetConnMgr::Instance()->Init(); +#endif a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()}); { @@ -117,8 +124,11 @@ void App::UnInit() if (terminated) { return; } +#if MASTER_MODE MasterSvrMgr::Instance()->UnInit(); +#else TargetConnMgr::Instance()->UnInit(); +#endif GameClientMgr::Instance()->UnInit(); GCListener::Instance()->UnInit(); JsonDataMgr::Instance()->UnInit(); @@ -301,12 +311,17 @@ void App::DispatchMsg() break; case SF_TargetServer: { +#if MASTER_MODE +#else ProcessTargetServerMsg(hdr); +#endif } break; case SF_MasterServer: { +#if MASTER_MODE ProcessMasterServerMsg(hdr); +#endif } break; } @@ -330,6 +345,8 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr) if (hdr.msgid < 100) { return; } +#if MASTER_MODE +#else TargetConn* conn = nullptr; if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) { ss::SS_CMLogin_CMReConnect_CommonHead msg; @@ -353,8 +370,15 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr) if (conn) { conn->ForwardClientMsg(hdr); } +#endif } +#if MASTER_MODE +void App::ProcessMasterServerMsg(f8::MsgHdr& hdr) +{ + +} +#else void App::ProcessTargetServerMsg(f8::MsgHdr& hdr) { if (hdr.msgid < 100) { @@ -366,11 +390,7 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr) } GCListener::Instance()->ForwardTargetConnMsg(hdr); } - -void App::ProcessMasterServerMsg(f8::MsgHdr& hdr) -{ - -} +#endif void App::ProcessIMMsg() { diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index 3308881..c8af816 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -42,8 +42,11 @@ private: void ProcessIMMsg(); void ProcessClientMsg(f8::MsgHdr& hdr); - void ProcessTargetServerMsg(f8::MsgHdr& hdr); +#if MASTER_MODE void ProcessMasterServerMsg(f8::MsgHdr& hdr); +#else + void ProcessTargetServerMsg(f8::MsgHdr& hdr); +#endif void InitLog(); void UnInitLog(); diff --git a/server/wsproxy/gameclientmgr.cc b/server/wsproxy/gameclientmgr.cc index 7a22c83..7ec1a84 100644 --- a/server/wsproxy/gameclientmgr.cc +++ b/server/wsproxy/gameclientmgr.cc @@ -50,6 +50,8 @@ GameClient* GameClientMgr::GetGameClientBySocket(int sockhandle) return itr != socket_hash_.end() ? itr->second : nullptr; } +#if MASTER_MODE +#else void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id) { TargetConn* conn = TargetConnMgr::Instance()->GetConnByInstanceId(conn_instance_id); @@ -65,3 +67,4 @@ void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id) } } } +#endif diff --git a/server/wsproxy/gameclientmgr.h b/server/wsproxy/gameclientmgr.h index aeeeeb0..0436687 100644 --- a/server/wsproxy/gameclientmgr.h +++ b/server/wsproxy/gameclientmgr.h @@ -15,7 +15,10 @@ class GameClientMgr : public a8::Singleton void OnClientDisconnect(a8::XParams& param); void OnTargetServerDisconnect(a8::XParams& param); GameClient* GetGameClientBySocket(int sockhande); +#if MASTER_MODE +#else void BindTargetConn(int socket_handle, int conn_instance_id); +#endif private: std::map socket_hash_; diff --git a/server/wsproxy/jsondatamgr.cc b/server/wsproxy/jsondatamgr.cc index 29eadf3..aec73a2 100644 --- a/server/wsproxy/jsondatamgr.cc +++ b/server/wsproxy/jsondatamgr.cc @@ -6,18 +6,35 @@ void JsonDataMgr::Init() { std::string wsproxyserver_cluster_json_file; +#if MASTER_MODE + std::string masterserver_cluster_json_file; +#else std::string targetserver_cluster_json_file; +#endif if (f8::IsOnlineEnv()) { wsproxyserver_cluster_json_file = a8::Format("../config/game%d.wsproxy.cluster.json", {GAME_ID}); +#if MASTER_MODE + masterserver_cluster_json_file = a8::Format("../config/game%d.masterserver.cluster.json", {GAME_ID}); +#else targetserver_cluster_json_file = a8::Format("../config/game%d.gameserver.cluster.json", {GAME_ID}); +#endif } else { wsproxyserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.wsproxy.cluster.json", {GAME_ID, GAME_ID}); +#if MASTER_MODE + masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.masterserver.cluster.json", + {GAME_ID, GAME_ID}); +#else targetserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.gameserver.cluster.json", {GAME_ID, GAME_ID}); +#endif } wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file); +#if MASTER_MODE + masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file); +#else targetserver_cluster_json_.ReadFromFile(targetserver_cluster_json_file); +#endif } void JsonDataMgr::UnInit() @@ -32,7 +49,14 @@ std::shared_ptr JsonDataMgr::GetConf() return wsproxyserver_cluster_json_[App::Instance()->instance_id - 1]; } +#if MASTER_MODE +std::shared_ptr JsonDataMgr::GetMasterServerClusterConf() +{ + return std::make_shared(masterserver_cluster_json_); +} +#else std::shared_ptr JsonDataMgr::GetTargetServerClusterConf() { return std::make_shared(targetserver_cluster_json_); } +#endif diff --git a/server/wsproxy/jsondatamgr.h b/server/wsproxy/jsondatamgr.h index d99fe56..8f69d59 100644 --- a/server/wsproxy/jsondatamgr.h +++ b/server/wsproxy/jsondatamgr.h @@ -11,10 +11,19 @@ class JsonDataMgr : public a8::Singleton void UnInit(); std::shared_ptr GetConf(); +#if MASTER_MODE + std::shared_ptr GetMasterServerClusterConf(); +#else std::shared_ptr GetTargetServerClusterConf(); +#endif + private: a8::XObject wsproxyserver_cluster_json_; +#if MASTER_MODE + a8::XObject masterserver_cluster_json_; +#else a8::XObject targetserver_cluster_json_; +#endif }; diff --git a/server/wsproxy/mastersvrmgr.cc b/server/wsproxy/mastersvrmgr.cc index bc66b85..f0afe91 100644 --- a/server/wsproxy/mastersvrmgr.cc +++ b/server/wsproxy/mastersvrmgr.cc @@ -6,7 +6,7 @@ void MasterSvrMgr::Init() { - auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf(); + auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetMasterServerClusterConf(); 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(); diff --git a/server/wsproxy/target_conn.h b/server/wsproxy/target_conn.h index 3660e38..4da2af3 100644 --- a/server/wsproxy/target_conn.h +++ b/server/wsproxy/target_conn.h @@ -29,11 +29,7 @@ class TargetConn 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); diff --git a/server/wsproxy/target_conn_mgr.cc b/server/wsproxy/target_conn_mgr.cc index 0e19e51..3fbbf00 100644 --- a/server/wsproxy/target_conn_mgr.cc +++ b/server/wsproxy/target_conn_mgr.cc @@ -6,6 +6,8 @@ void TargetConnMgr::Init() { +#if MASTER_MODE +#else auto target_server_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf(); for (int i = 0; i < target_server_cluster_conf->Size(); ++i) { auto target_server_conf = target_server_cluster_conf->At(i); @@ -19,14 +21,18 @@ void TargetConnMgr::Init() conn->Open(); } } +#endif } void TargetConnMgr::UnInit() { } +#if MASTER_MODE +#else TargetConn* TargetConnMgr::GetConnByInstanceId(int instance_id) { auto itr = target_conn_hash_.find(instance_id); return itr != target_conn_hash_.end() ? itr->second : nullptr; } +#endif diff --git a/server/wsproxy/target_conn_mgr.h b/server/wsproxy/target_conn_mgr.h index 9519bdb..0f7aa9c 100644 --- a/server/wsproxy/target_conn_mgr.h +++ b/server/wsproxy/target_conn_mgr.h @@ -12,8 +12,15 @@ class TargetConnMgr : public a8::Singleton void Init(); void UnInit(); +#if MASTER_MODE +#else TargetConn* GetConnByInstanceId(int instance_id); +#endif private: + +#if MASTER_MODE +#else std::map target_conn_hash_; +#endif };