添加nodeid读取

This commit is contained in:
aozhiwei 2019-05-30 15:37:45 +08:00
parent 84a220e837
commit 2d98a0c6b4
4 changed files with 35 additions and 1 deletions

View File

@ -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)

View File

@ -62,6 +62,7 @@ private:
a8::uuid::SnowFlake uuid;
public:
int node_id = 0;
int instance_id = 0;
private:

View File

@ -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;

View File

@ -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()