This commit is contained in:
azw 2023-04-09 07:12:17 +00:00
parent 45af072c80
commit 504964ce43
6 changed files with 2 additions and 118 deletions

View File

@ -64,7 +64,6 @@ public:
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
std::string& location) override
{
#if MASTER_MODE
a8::HTTPRequest request;
a8::ParserUrlQueryString(querystr.c_str(), request);
if (a8::Get(request, "c").GetString() == "Ops" &&
@ -87,7 +86,6 @@ public:
}
}
}
#endif
return false;
}

View File

@ -23,10 +23,8 @@
#include "target_conn.h"
#include "target_conn_mgr.h"
#if MASTER_MODE
#include "mastersvr.h"
#include "mastersvrmgr.h"
#endif
struct MsgNode
{
@ -85,7 +83,6 @@ bool App::Init(int argc, char* argv[])
if (!ParseOpt()) {
terminated = true;
#if MASTER_MODE
if (node_id <= 0) {
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
} else if (node_id > MAX_NODE_ID) {
@ -95,9 +92,6 @@ bool App::Init(int argc, char* argv[])
} else if (instance_id > MAX_INSTANCE_ID) {
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
}
#else
a8::XPrintf("wsproxy启动失败,缺少-i参数\n", {});
#endif
return false;
}
a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d\n",
@ -116,15 +110,9 @@ bool App::Init(int argc, char* argv[])
HandlerMgr::Instance()->Init();
f8::Timer::Instance()->Init();
JsonDataMgr::Instance()->Init();
#if MASTER_MODE
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
#else
uuid.SetMachineId(instance_id);
#endif
GameClientMgr::Instance()->Init();
#if MASTER_MODE
MasterSvrMgr::Instance()->Init();
#endif
TargetConnMgr::Instance()->Init();
GCListener::Instance()->Init();
@ -180,9 +168,7 @@ void App::UnInit()
{
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
GCListener::Instance()->UnInit();
#if MASTER_MODE
MasterSvrMgr::Instance()->UnInit();
#endif
TargetConnMgr::Instance()->UnInit();
GameClientMgr::Instance()->UnInit();
JsonDataMgr::Instance()->UnInit();
@ -360,9 +346,8 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
if (hdr.msgid < 100) {
return;
}
#if MASTER_MODE
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) {
GameClient* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
Client* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
if (!client) {
switch (hdr.msgid) {
case ss::_SS_CMLogin:
@ -403,43 +388,17 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
}
}
} else {
GameClient* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
Client* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
if (client && client->conn) {
if (client->conn) {
client->conn->ForwardClientMsg(hdr);
}
}
}
#else
TargetConn* conn = nullptr;
if (hdr.msgid == ss::_SS_CMLogin || hdr.msgid == ss::_SS_CMReconnect) {
ss::SS_CMLogin_CMReConnect_CommonHead msg;
bool ok = msg.ParseFromArray(hdr.buf + hdr.offset, hdr.buflen - hdr.offset);
if (ok) {
conn = TargetConnMgr::Instance()->GetConnById(msg.server_id());
if (!conn) {
ss::SS_SMRpcError respmsg;
respmsg.set_error_code(10);
GCListener::Instance()->SendMsg(hdr.socket_handle, respmsg);
}
} else {
return;
}
} else {
Client* client = GameClientMgr::Instance()->GetGameClientBySocket(hdr.socket_handle);
if (client) {
conn = client->conn;
}
}
if (conn) {
conn->ForwardClientMsg(hdr);
}
#endif
}
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
{
#if MASTER_MODE
f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->msmsghandler,
hdr.msgid);
if (handler) {
@ -449,7 +408,6 @@ void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
break;
}
}
#endif
}
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
@ -484,9 +442,7 @@ void App::ProcessIMMsg()
case IM_ClientSocketDisconnect:
{
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
#if MASTER_MODE
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true);
#endif
}
break;
case IM_TargetConnConnect:
@ -569,11 +525,7 @@ bool App::ParseOpt()
break;
}
}
#if MASTER_MODE
return instance_id > 0 && node_id > 0;
#else
return instance_id > 0;
#endif
}
bool App::HasFlag(int flag)

View File

@ -9,9 +9,7 @@
void JsonDataMgr::Init()
{
#if MASTER_MODE
node_host_mutex_ = new std::mutex();
#endif
if (!f8::IsOnlineEnv()) {
if (f8::IsTestEnv()) {
@ -32,7 +30,6 @@ void JsonDataMgr::Init()
}
std::string wsproxyserver_cluster_json_file;
#if MASTER_MODE
std::string masterserver_cluster_json_file;
std::string routing_tables_json_file;
wsproxyserver_cluster_json_file = a8::Format("%s/node%d/game%d.wsproxy.cluster.json",
@ -51,22 +48,8 @@ void JsonDataMgr::Init()
{
work_path_
});
#else
std::string targetserver_cluster_json_file;
wsproxyserver_cluster_json_file = a8::Format("%s/game%d.wsproxy.cluster.json",
{
work_path_,
GAME_ID
});
targetserver_cluster_json_file = a8::Format("%s/game%d.gameserver.cluster.json",
{
work_path_,
GAME_ID
});
#endif
wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file);
#if MASTER_MODE
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
routing_tables_json_.ReadFromFile(routing_tables_json_file);
node_host_mutex_->lock();
@ -80,17 +63,12 @@ void JsonDataMgr::Init()
node_host_hash_[node_id] = host;
}
node_host_mutex_->unlock();
#else
targetserver_cluster_json_.ReadFromFile(targetserver_cluster_json_file);
#endif
}
void JsonDataMgr::UnInit()
{
#if MASTER_MODE
delete node_host_mutex_;
node_host_mutex_ = nullptr;
#endif
}
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
@ -105,9 +83,6 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
{
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
}
#if MASTER_MODE
bool JsonDataMgr::GetNodeHost(int node_id, std::string& host)
{
bool found = false;
@ -121,12 +96,3 @@ bool JsonDataMgr::GetNodeHost(int node_id, std::string& host)
node_host_mutex_->unlock();
return found;
}
#else
std::shared_ptr<a8::XObject> JsonDataMgr::GetTargetServerClusterConf()
{
return std::make_shared<a8::XObject>(targetserver_cluster_json_);
}
#endif

View File

@ -14,21 +14,13 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
std::shared_ptr<a8::XObject> GetConf();
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
#if MASTER_MODE
bool GetNodeHost(int node_id, std::string& host);
#else
std::shared_ptr<a8::XObject> GetTargetServerClusterConf();
#endif
private:
std::string work_path_ = "../config";
a8::XObject wsproxyserver_cluster_json_;
a8::XObject masterserver_cluster_json_;
#if MASTER_MODE
std::mutex* node_host_mutex_ = nullptr;
a8::XObject routing_tables_json_;
std::map<int, std::string> node_host_hash_;
#else
a8::XObject targetserver_cluster_json_;
#endif
};

View File

@ -20,7 +20,6 @@ void MasterSvrMgr::Init()
{
curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10);
#if MASTER_MODE
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);
@ -34,7 +33,6 @@ void MasterSvrMgr::Init()
conn->Open();
}
}
#endif
}
void MasterSvrMgr::UnInit()

View File

@ -7,28 +7,6 @@
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);
int instance_id = target_server_conf->At("instance_id")->AsXValue();
std::string remote_ip = target_server_conf->At("ip")->AsXValue();
int remote_port = target_server_conf->At("port")->AsXValue();
if (App::Instance()->HasFlag(3)) {
remote_ip = "127.0.0.1";
}
{
TargetConn* conn = new TargetConn();
conn->Init(instance_id, remote_ip, remote_port);
id_hash_[conn->instance_id] = conn;
conn->Open();
}
if (App::Instance()->HasFlag(3)) {
break;
}
}
#endif
}
void TargetConnMgr::UnInit()