This commit is contained in:
aozhiwei 2019-05-30 17:44:16 +08:00
parent 03a7c2bc2f
commit 95a53e9fb6
7 changed files with 42 additions and 10 deletions

View File

@ -114,7 +114,7 @@ bool App::Init(int argc, char* argv[])
f8::HttpClientPool::Instance()->Init(10);
JsonDataMgr::Instance()->Init();
MetaMgr::Instance()->Init();
uuid.SetMachineId((node_id - 1) * 500 + instance_id);
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
RoomMgr::Instance()->Init();
PlayerMgr::Instance()->Init();
GGListener::Instance()->Init();

View File

@ -73,7 +73,15 @@ void App::Init(int argc, char* argv[])
if (!ParseOpt()) {
terminated = true;
a8::XPrintf("masterserver启动失败,缺少-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;
}
a8::XPrintf("masterserver starting instance_id:%d pid:%d game_id:%d\n", {instance_id, getpid(), GAME_ID});
@ -91,7 +99,7 @@ void App::Init(int argc, char* argv[])
f8::TGLog::Instance()->Init(a8::Format(PROJ_NAME_FMT, {GAME_ID}), false);
f8::HttpClientPool::Instance()->Init(10);
JsonDataMgr::Instance()->Init();
uuid.SetMachineId(instance_id);
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
GGListener::Instance()->Init();
a8::UdpLog::Instance()->Info("masterserver starting instance_id:%d pid:%d", {instance_id, getpid()});
@ -413,8 +421,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, "n:i:t:r:f:")) != -1) {
switch (ch) {
case 'n':
{
node_id = a8::XValue(optarg);
}
break;
case 'i':
{
instance_id = a8::XValue(optarg);
@ -437,7 +450,7 @@ bool App::ParseOpt()
break;
}
}
return instance_id > 0;
return instance_id > 0 && node_id > 0;
}
long long App::NewUuid()

View File

@ -57,6 +57,7 @@ public:
a8::uuid::SnowFlake uuid;
public:
int node_id = 0;
int instance_id = 0;
bool is_test_mode = false;
int test_param = 0;

View File

@ -144,3 +144,6 @@ const int MAP_WIDTH = 8192;
const int MAP_CELL_WIDTH = 64 * 8;
const int DOOR_THING_ID = 61701;
const int MAX_NODE_ID = 8;
const int MAX_INSTANCE_ID = 500;

View File

@ -41,6 +41,8 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
int port = request->request.Get("port");
int online_num = request->request.Get("online_num");
int room_num = request->request.Get("room_num");
int instance_id = request->request.Get("instance_id");
int node_id = request->request.Get("node_id");
std::string key = ip + a8::XValue(port).GetString();
auto itr = node_key_hash_.find(key);
@ -49,7 +51,8 @@ void GSMgr::___GSReport(f8::JsonHttpRequest* request)
itr->second.room_num = room_num;
} else {
GSNode gs;
gs.key = key;
gs.node_id = node_id;
gs.instance_id = instance_id;
gs.online_num = online_num;
gs.room_num = room_num;
gs.ip = ip;

View File

@ -6,10 +6,13 @@ struct GSNode
{
std::string key;
unsigned short node_idx = 0;
int node_id = 0;
int instance_id = 0;
int room_num = 0;
int online_num = 0;
std::string ip;
int port = 0;
bool servicing = false;
};
class GSMgr : public a8::Singleton<GSMgr>

View File

@ -10,21 +10,30 @@ void JsonDataMgr::Init()
std::string masterserver_cluster_json_file;
if (!f8::IsOnlineEnv()) {
if (App::Instance()->flags.find(2) != App::Instance()->flags.end()) {
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/masterserver/node%d/"
"game%d.masterserver.cluster.json",
{
GAME_ID,
App::Instance()->instance_id,
GAME_ID,
App::Instance()->node_id,
GAME_ID
});
} else {
masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/masterserver/"
masterserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/masterserver/node%d/"
"game%d.masterserver.cluster.json",
{GAME_ID, GAME_ID});
{
GAME_ID,
App::Instance()->node_id,
GAME_ID
});
}
} else {
masterserver_cluster_json_file = a8::Format("../config/game%d.masterserver.cluster.json", {GAME_ID});
masterserver_cluster_json_file = a8::Format("../config/node%d/game%d.masterserver.cluster.json",
{
App::Instance()->node_id,
GAME_ID
});
}
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
}