This commit is contained in:
aozhiwei 2019-05-15 14:18:55 +08:00
parent 37d7c529f4
commit fc5ed7f577
10 changed files with 85 additions and 14 deletions

View File

@ -16,14 +16,18 @@
#include "GCListener.h" #include "GCListener.h"
#include "jsondatamgr.h" #include "jsondatamgr.h"
#include "handlermgr.h" #include "handlermgr.h"
#include "target_conn.h"
#include "target_conn_mgr.h"
#include "gameclient.h" #include "gameclient.h"
#include "gameclientmgr.h" #include "gameclientmgr.h"
#include "ss_msgid.pb.h" #include "ss_msgid.pb.h"
#include "ss_proto.pb.h" #include "ss_proto.pb.h"
#if MASTER_MODE
#include "mastersvr.h" #include "mastersvr.h"
#include "mastersvrmgr.h" #include "mastersvrmgr.h"
#else
#include "target_conn.h"
#include "target_conn_mgr.h"
#endif
struct MsgNode struct MsgNode
{ {
@ -94,8 +98,11 @@ void App::Init(int argc, char* argv[])
GCListener::Instance()->Init(); GCListener::Instance()->Init();
uuid.SetMachineId(instance_id); uuid.SetMachineId(instance_id);
GameClientMgr::Instance()->Init(); GameClientMgr::Instance()->Init();
TargetConnMgr::Instance()->Init(); #if MASTER_MODE
MasterSvrMgr::Instance()->Init(); MasterSvrMgr::Instance()->Init();
#else
TargetConnMgr::Instance()->Init();
#endif
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()}); a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
{ {
@ -117,8 +124,11 @@ void App::UnInit()
if (terminated) { if (terminated) {
return; return;
} }
#if MASTER_MODE
MasterSvrMgr::Instance()->UnInit(); MasterSvrMgr::Instance()->UnInit();
#else
TargetConnMgr::Instance()->UnInit(); TargetConnMgr::Instance()->UnInit();
#endif
GameClientMgr::Instance()->UnInit(); GameClientMgr::Instance()->UnInit();
GCListener::Instance()->UnInit(); GCListener::Instance()->UnInit();
JsonDataMgr::Instance()->UnInit(); JsonDataMgr::Instance()->UnInit();
@ -301,12 +311,17 @@ void App::DispatchMsg()
break; break;
case SF_TargetServer: case SF_TargetServer:
{ {
#if MASTER_MODE
#else
ProcessTargetServerMsg(hdr); ProcessTargetServerMsg(hdr);
#endif
} }
break; break;
case SF_MasterServer: case SF_MasterServer:
{ {
#if MASTER_MODE
ProcessMasterServerMsg(hdr); ProcessMasterServerMsg(hdr);
#endif
} }
break; break;
} }
@ -330,6 +345,8 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
if (hdr.msgid < 100) { if (hdr.msgid < 100) {
return; return;
} }
#if MASTER_MODE
#else
TargetConn* conn = nullptr; TargetConn* conn = nullptr;
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) { if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReConnect) {
ss::SS_CMLogin_CMReConnect_CommonHead msg; ss::SS_CMLogin_CMReConnect_CommonHead msg;
@ -353,8 +370,15 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
if (conn) { if (conn) {
conn->ForwardClientMsg(hdr); conn->ForwardClientMsg(hdr);
} }
#endif
} }
#if MASTER_MODE
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
{
}
#else
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr) void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
{ {
if (hdr.msgid < 100) { if (hdr.msgid < 100) {
@ -366,11 +390,7 @@ void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
} }
GCListener::Instance()->ForwardTargetConnMsg(hdr); GCListener::Instance()->ForwardTargetConnMsg(hdr);
} }
#endif
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
{
}
void App::ProcessIMMsg() void App::ProcessIMMsg()
{ {

View File

@ -42,8 +42,11 @@ private:
void ProcessIMMsg(); void ProcessIMMsg();
void ProcessClientMsg(f8::MsgHdr& hdr); void ProcessClientMsg(f8::MsgHdr& hdr);
void ProcessTargetServerMsg(f8::MsgHdr& hdr); #if MASTER_MODE
void ProcessMasterServerMsg(f8::MsgHdr& hdr); void ProcessMasterServerMsg(f8::MsgHdr& hdr);
#else
void ProcessTargetServerMsg(f8::MsgHdr& hdr);
#endif
void InitLog(); void InitLog();
void UnInitLog(); void UnInitLog();

View File

@ -50,6 +50,8 @@ GameClient* GameClientMgr::GetGameClientBySocket(int sockhandle)
return itr != socket_hash_.end() ? itr->second : nullptr; return itr != socket_hash_.end() ? itr->second : nullptr;
} }
#if MASTER_MODE
#else
void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id) void GameClientMgr::BindTargetConn(int socket_handle, int conn_instance_id)
{ {
TargetConn* conn = TargetConnMgr::Instance()->GetConnByInstanceId(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

View File

@ -15,7 +15,10 @@ class GameClientMgr : public a8::Singleton<GameClientMgr>
void OnClientDisconnect(a8::XParams& param); void OnClientDisconnect(a8::XParams& param);
void OnTargetServerDisconnect(a8::XParams& param); void OnTargetServerDisconnect(a8::XParams& param);
GameClient* GetGameClientBySocket(int sockhande); GameClient* GetGameClientBySocket(int sockhande);
#if MASTER_MODE
#else
void BindTargetConn(int socket_handle, int conn_instance_id); void BindTargetConn(int socket_handle, int conn_instance_id);
#endif
private: private:
std::map<int, GameClient*> socket_hash_; std::map<int, GameClient*> socket_hash_;

View File

@ -6,18 +6,35 @@
void JsonDataMgr::Init() void JsonDataMgr::Init()
{ {
std::string wsproxyserver_cluster_json_file; std::string wsproxyserver_cluster_json_file;
#if MASTER_MODE
std::string masterserver_cluster_json_file;
#else
std::string targetserver_cluster_json_file; std::string targetserver_cluster_json_file;
#endif
if (f8::IsOnlineEnv()) { if (f8::IsOnlineEnv()) {
wsproxyserver_cluster_json_file = a8::Format("../config/game%d.wsproxy.cluster.json", {GAME_ID}); 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}); targetserver_cluster_json_file = a8::Format("../config/game%d.gameserver.cluster.json", {GAME_ID});
#endif
} else { } else {
wsproxyserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.wsproxy.cluster.json", wsproxyserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.wsproxy.cluster.json",
{GAME_ID, GAME_ID}); {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", targetserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.gameserver.cluster.json",
{GAME_ID, GAME_ID}); {GAME_ID, GAME_ID});
#endif
} }
wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file); 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); targetserver_cluster_json_.ReadFromFile(targetserver_cluster_json_file);
#endif
} }
void JsonDataMgr::UnInit() void JsonDataMgr::UnInit()
@ -32,7 +49,14 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
return wsproxyserver_cluster_json_[App::Instance()->instance_id - 1]; return wsproxyserver_cluster_json_[App::Instance()->instance_id - 1];
} }
#if MASTER_MODE
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
{
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
}
#else
std::shared_ptr<a8::XObject> JsonDataMgr::GetTargetServerClusterConf() std::shared_ptr<a8::XObject> JsonDataMgr::GetTargetServerClusterConf()
{ {
return std::make_shared<a8::XObject>(targetserver_cluster_json_); return std::make_shared<a8::XObject>(targetserver_cluster_json_);
} }
#endif

View File

@ -11,10 +11,19 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
void UnInit(); void UnInit();
std::shared_ptr<a8::XObject> GetConf(); std::shared_ptr<a8::XObject> GetConf();
#if MASTER_MODE
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
#else
std::shared_ptr<a8::XObject> GetTargetServerClusterConf(); std::shared_ptr<a8::XObject> GetTargetServerClusterConf();
#endif
private: private:
a8::XObject wsproxyserver_cluster_json_; a8::XObject wsproxyserver_cluster_json_;
#if MASTER_MODE
a8::XObject masterserver_cluster_json_;
#else
a8::XObject targetserver_cluster_json_; a8::XObject targetserver_cluster_json_;
#endif
}; };

View File

@ -6,7 +6,7 @@
void MasterSvrMgr::Init() 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) { for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) {
auto master_svr_conf = master_svr_cluster_conf->At(i); auto master_svr_conf = master_svr_cluster_conf->At(i);
int instance_id = master_svr_conf->At("instance_id")->AsXValue(); int instance_id = master_svr_conf->At("instance_id")->AsXValue();

View File

@ -29,11 +29,7 @@ class TargetConn
void SendMsg(T& msg) void SendMsg(T& msg)
{ {
static int msgid = f8::Net_GetMessageId(msg); static int msgid = f8::Net_GetMessageId(msg);
#if 1
f8::Net_SendProxyCMsg(tcp_client_, msgid, msg); f8::Net_SendProxyCMsg(tcp_client_, msgid, msg);
#else
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
#endif
} }
void ForwardClientMsg(f8::MsgHdr& hdr); void ForwardClientMsg(f8::MsgHdr& hdr);

View File

@ -6,6 +6,8 @@
void TargetConnMgr::Init() void TargetConnMgr::Init()
{ {
#if MASTER_MODE
#else
auto target_server_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf(); auto target_server_cluster_conf = JsonDataMgr::Instance()->GetTargetServerClusterConf();
for (int i = 0; i < target_server_cluster_conf->Size(); ++i) { for (int i = 0; i < target_server_cluster_conf->Size(); ++i) {
auto target_server_conf = target_server_cluster_conf->At(i); auto target_server_conf = target_server_cluster_conf->At(i);
@ -19,14 +21,18 @@ void TargetConnMgr::Init()
conn->Open(); conn->Open();
} }
} }
#endif
} }
void TargetConnMgr::UnInit() void TargetConnMgr::UnInit()
{ {
} }
#if MASTER_MODE
#else
TargetConn* TargetConnMgr::GetConnByInstanceId(int instance_id) TargetConn* TargetConnMgr::GetConnByInstanceId(int instance_id)
{ {
auto itr = target_conn_hash_.find(instance_id); auto itr = target_conn_hash_.find(instance_id);
return itr != target_conn_hash_.end() ? itr->second : nullptr; return itr != target_conn_hash_.end() ? itr->second : nullptr;
} }
#endif

View File

@ -12,8 +12,15 @@ class TargetConnMgr : public a8::Singleton<TargetConnMgr>
void Init(); void Init();
void UnInit(); void UnInit();
#if MASTER_MODE
#else
TargetConn* GetConnByInstanceId(int instance_id); TargetConn* GetConnByInstanceId(int instance_id);
#endif
private: private:
#if MASTER_MODE
#else
std::map<int, TargetConn*> target_conn_hash_; std::map<int, TargetConn*> target_conn_hash_;
#endif
}; };