diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index d1a141f..41c2acb 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -87,7 +87,19 @@ bool App::Init(int argc, char* argv[]) if (!ParseOpt()) { terminated = true; +#ifdef MASTER_MODE + if (node_id <= 0) { + a8::XPrintf("gameserver启动失败,缺少-n参数\n", {}); + } else if (node_id > MAX_NODE_ID) { + a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID}); + } else if (instance_id <= 0) { + a8::XPrintf("gameserver启动失败,缺少-i参数\n", {}); + } 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 instance_id:%d pid:%d\n", {instance_id, getpid()}); @@ -498,8 +510,13 @@ void App::UnInitLog() bool App::ParseOpt() { int ch = 0; - while ((ch = getopt(argc, argv, "i:f:")) != -1) { + while ((ch = getopt(argc, argv, "n:i:f:")) != -1) { switch (ch) { + case 'n': + { + node_id = a8::XValue(optarg); + } + break; case 'i': { instance_id = a8::XValue(optarg); @@ -516,7 +533,11 @@ bool App::ParseOpt() break; } } +#ifdef MASTER_MODE + return instance_id > 0 && node_id > 0; +#else return instance_id > 0; +#endif } a8::XParams* App::AddContext(long long context_id) diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index 1b3df90..f452dab 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -62,6 +62,7 @@ private: a8::uuid::SnowFlake uuid; public: + int node_id = 0; int instance_id = 0; private: diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index 3673a5a..9466d48 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -37,3 +37,6 @@ const char* const PROJ_NAME_FMT = "game%d_wsproxy"; const char* const PROJ_ROOT_FMT = "/data/logs/%s"; const int POSTFIX_LEN = 7; + +const int MAX_NODE_ID = 8; +const int MAX_INSTANCE_ID = 500; diff --git a/server/wsproxy/handlermgr.cc b/server/wsproxy/handlermgr.cc index 02f368c..2be6d42 100644 --- a/server/wsproxy/handlermgr.cc +++ b/server/wsproxy/handlermgr.cc @@ -6,6 +6,7 @@ #include "GCListener.h" #include "mastersvrmgr.h" +#include "app.h" #include "ss_proto.pb.h" @@ -17,10 +18,18 @@ static void _GMOpsSelfChecking(f8::JsonHttpRequest* request) request->resp_xobj->SetVal("max_rundelay", 10); } +static void _GMOpsGetNodeId(f8::JsonHttpRequest* request) +{ + request->resp_xobj->SetVal("errcode", 0); + request->resp_xobj->SetVal("errmsg", ""); + request->resp_xobj->SetVal("node_id", App::Instance()->node_id); +} + void HandlerMgr::Init() { RegisterNetMsgHandlers(); RegisterGMMsgHandler("Ops$selfChecking", _GMOpsSelfChecking); + RegisterGMMsgHandler("Ops$getNodeId", _GMOpsGetNodeId); } void HandlerMgr::UnInit()