add nodeid
This commit is contained in:
parent
6808386408
commit
03a7c2bc2f
@ -81,10 +81,24 @@ bool App::Init(int argc, char* argv[])
|
||||
this->argv = argv;
|
||||
|
||||
if (!ParseOpt()) {
|
||||
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
|
||||
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});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
a8::XPrintf("gameserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
|
||||
a8::XPrintf("gameserver starting node_id: %d instance_id:%d pid:%d game_id:%d\n",
|
||||
{
|
||||
node_id,
|
||||
instance_id,
|
||||
getpid(),
|
||||
GAME_ID
|
||||
});
|
||||
|
||||
loop_mutex_ = new std::mutex();
|
||||
loop_cond_ = new std::condition_variable();
|
||||
@ -100,7 +114,7 @@ bool App::Init(int argc, char* argv[])
|
||||
f8::HttpClientPool::Instance()->Init(10);
|
||||
JsonDataMgr::Instance()->Init();
|
||||
MetaMgr::Instance()->Init();
|
||||
uuid.SetMachineId(instance_id);
|
||||
uuid.SetMachineId((node_id - 1) * 500 + instance_id);
|
||||
RoomMgr::Instance()->Init();
|
||||
PlayerMgr::Instance()->Init();
|
||||
GGListener::Instance()->Init();
|
||||
@ -453,8 +467,13 @@ void App::UnInitLog()
|
||||
bool App::ParseOpt()
|
||||
{
|
||||
int ch = 0;
|
||||
while ((ch = getopt(argc, argv, "i:t:r:f:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "i:t:r:f:n:")) != -1) {
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
{
|
||||
node_id = a8::XValue(optarg);
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
{
|
||||
instance_id = a8::XValue(optarg);
|
||||
@ -477,7 +496,7 @@ bool App::ParseOpt()
|
||||
break;
|
||||
}
|
||||
}
|
||||
return instance_id > 0;
|
||||
return instance_id > 0 && node_id > 0;
|
||||
}
|
||||
|
||||
long long App::NewUuid()
|
||||
|
@ -61,6 +61,7 @@ public:
|
||||
|
||||
public:
|
||||
int instance_id = 0;
|
||||
int node_id = 0;
|
||||
bool is_test_mode = false;
|
||||
int test_param = 0;
|
||||
bool servicing = true;
|
||||
|
@ -161,3 +161,6 @@ const int MAP_CELL_WIDTH = 64 * 8;
|
||||
const int DOOR_THING_ID = 61701;
|
||||
|
||||
const int FIGHTING_MODE_BULLET_NUM = 10000 * 10000;
|
||||
|
||||
const int MAX_NODE_ID = 8;
|
||||
const int MAX_INSTANCE_ID = 500;
|
||||
|
@ -11,33 +11,43 @@ void JsonDataMgr::Init()
|
||||
std::string masterserver_cluster_json_file;
|
||||
if (!f8::IsOnlineEnv()) {
|
||||
if (App::Instance()->HasFlag(2)) {
|
||||
gameserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver/"
|
||||
gameserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver/node%d/"
|
||||
"game%d.gameserver.cluster.json",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id,
|
||||
GAME_ID,
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
masterserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/masterserver/"
|
||||
masterserver_cluster_json_file = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver/node%d/"
|
||||
"game%d.masterserver.cluster.json",
|
||||
{
|
||||
GAME_ID,
|
||||
App::Instance()->instance_id,
|
||||
GAME_ID,
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
} else {
|
||||
gameserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/"
|
||||
gameserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/node%d/"
|
||||
"game%d.gameserver.cluster.json",
|
||||
{GAME_ID, GAME_ID});
|
||||
masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/mastererver/"
|
||||
{GAME_ID, App::Instance()->node_id, GAME_ID});
|
||||
masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/gameserver/node%d/"
|
||||
"game%d.masterserver.cluster.json",
|
||||
{GAME_ID, GAME_ID});
|
||||
{GAME_ID, App::Instance()->node_id, GAME_ID});
|
||||
}
|
||||
} else {
|
||||
gameserver_cluster_json_file = a8::Format("../config/game%d.gameserver.cluster.json", {GAME_ID});
|
||||
masterserver_cluster_json_file = a8::Format("../config/game%d.masterserver.cluster.json", {GAME_ID});
|
||||
gameserver_cluster_json_file = a8::Format("../config/node%d/game%d.gameserver.cluster.json",
|
||||
{
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
masterserver_cluster_json_file = a8::Format("../config/node%d/game%d.masterserver.cluster.json",
|
||||
{
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
}
|
||||
gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file);
|
||||
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
||||
|
@ -195,6 +195,7 @@ void RoomMgr::ReportServerState(int instance_id, const std::string& host, int po
|
||||
port
|
||||
});
|
||||
a8::MutableXObject* url_params = a8::MutableXObject::NewObject();
|
||||
url_params->SetVal("node_id", App::Instance()->node_id);
|
||||
url_params->SetVal("instance_id", App::Instance()->instance_id);
|
||||
url_params->SetVal("ip", JsonDataMgr::Instance()->ip);
|
||||
url_params->SetVal("port", JsonDataMgr::Instance()->listen_port);
|
||||
|
Loading…
x
Reference in New Issue
Block a user