This commit is contained in:
aozhiwei 2023-11-03 19:38:31 +08:00
parent 8757627dbb
commit 7a33c2fc1d
10 changed files with 58 additions and 53 deletions

View File

@ -157,6 +157,6 @@ long long GGListener::GetSentBytesNum()
void GGListener::OnListenError(int errorid)
{
a8::XPrintf("GGListeneron_error %d\n", {errorid});
App::Instance()->terminated = true;
App::Instance()->Terminate();
exit(1);
}

View File

@ -124,17 +124,17 @@ static void SavePerfLog()
bool App::Init(int argc, char* argv[])
{
signal(SIGPIPE, SIG_IGN);
this->argc = argc;
this->argv = argv;
this->argc_ = argc;
this->argv_ = argv;
if (!ParseOpt()) {
if (node_id <= 0) {
if (node_id_ <= 0) {
a8::XPrintf("gameserver启动失败,缺少-n参数\n", {});
} else if (node_id > MAX_NODE_ID) {
} else if (node_id_ > MAX_NODE_ID) {
a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID});
} else if (instance_id <= 0) {
} else if (instance_id_ <= 0) {
a8::XPrintf("gameserver启动失败,缺少-i参数\n", {});
} else if (instance_id > MAX_INSTANCE_ID) {
} else if (instance_id_ > MAX_INSTANCE_ID) {
a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID});
}
return false;
@ -145,8 +145,8 @@ bool App::Init(int argc, char* argv[])
#endif
a8::XPrintf("gameserver starting node_id: %d instance_id:%d pid:%d game_id:%d debug_mode:%d\n",
{
node_id,
instance_id,
node_id_,
instance_id_,
getpid(),
GAME_ID,
debug_mode
@ -178,7 +178,7 @@ bool App::Init(int argc, char* argv[])
mt::MetaMgr::Instance()->Init();
SelfChecker::Init();
EntityFactory::Instance()->Init();
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
uuid_.SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_);
KillMgr::Instance()->Init();
RoomMgr::Instance()->Init();
MatchMgr::Instance()->Init();
@ -189,7 +189,7 @@ bool App::Init(int argc, char* argv[])
f8::UdpLog::Instance()->Info("gameserver starting instance_id:%d pid:%d debug_mode:%d channel:%d",
{
instance_id,
instance_id_,
getpid(),
debug_mode,
JsonDataMgr::Instance()->channel
@ -212,7 +212,7 @@ bool App::Init(int argc, char* argv[])
[] (int event, const a8::Args* args)
{
if (a8::TIMER_EXEC_EVENT == event) {
App::Instance()->terminated = true;
App::Instance()->Terminate();
}
}
);
@ -261,7 +261,7 @@ int App::Run()
f8::UdpLog::Instance()->Info("gameserver running", {});
last_run_tick_ = a8::XGetTickCount();
int delta_time = 0;
while (!terminated) {
while (!terminated_) {
a8::tick_t begin_tick = a8::XGetTickCount();
Global::g_nowtime = time(nullptr);
QuickExecute(delta_time);
@ -467,22 +467,22 @@ void App::UnInitLog()
bool App::ParseOpt()
{
int ch = 0;
while ((ch = getopt(argc, argv, "i:t:r:f:n:")) != -1) {
while ((ch = getopt(argc_, argv_, "i:t:r:f:n:")) != -1) {
switch (ch) {
case 'n':
{
node_id = a8::XValue(optarg);
node_id_ = a8::XValue(optarg);
}
break;
case 'i':
{
instance_id = a8::XValue(optarg);
instance_id_ = a8::XValue(optarg);
}
break;
case 't':
{
is_test_mode = true;
test_param = a8::XValue(optarg);
is_test_mode_ = true;
test_param_ = a8::XValue(optarg);
}
break;
case 'f':
@ -496,12 +496,12 @@ bool App::ParseOpt()
break;
}
}
return instance_id > 0 && node_id > 0;
return instance_id_ > 0 && node_id_ > 0;
}
long long App::NewUuid()
{
return uuid.Generate();
return uuid_.Generate();
}
bool App::HasFlag(int flag)

View File

@ -38,6 +38,13 @@ public:
void UnSetFlag(int flag);
long long AllocTempHeroUniId();
long long AllocTempWeaponUniId();
void Terminate() { terminated_ = true; }
int GetInstanceId() const { return instance_id_; }
int GetNodeId() const { return node_id_; }
bool IsTestMode() const { return is_test_mode_; }
int GetTestParam() const { return test_param_; }
bool IsServicing() const { return servicing_; }
void SetServicing(bool open) { servicing_ = open; }
private:
void QuickExecute(int delta_time);
@ -55,19 +62,6 @@ private:
bool ParseOpt();
void FreeSocketMsgQueue();
public:
int argc = 0;
char** argv = nullptr;
volatile bool terminated = false;
a8::uuid::SnowFlake uuid;
public:
int instance_id = 0;
int node_id = 0;
bool is_test_mode = false;
int test_param = 0;
bool servicing = true;
private:
/*
1:
@ -82,6 +76,17 @@ private:
std::set<int> flags;
private:
int argc_ = 0;
char** argv_ = nullptr;
volatile bool terminated_ = false;
int instance_id_ = 0;
int node_id_ = 0;
bool is_test_mode_ = false;
int test_param_ = 0;
bool servicing_ = true;
a8::uuid::SnowFlake uuid_;
long long last_run_tick_ = 0;
std::mutex *loop_mutex_ = nullptr;
std::condition_variable *loop_cond_ = nullptr;

View File

@ -8,7 +8,7 @@
bool DebugCmd::Enable()
{
return App::Instance()->instance_id == 6;
return App::Instance()->GetInstanceId() == 6;
}
void DebugCmd::CreateSphere(Creature* c,

View File

@ -35,8 +35,8 @@ void GameLog::GameStart(Player* hum)
//prop->SetVal("localuuid", "");
//prop->SetVal("start_param", "");
prop->SetVal("team_id", hum->team_id);
prop->SetVal("server_node_id", App::Instance()->node_id);
prop->SetVal("server_instance_id", App::Instance()->instance_id);
prop->SetVal("server_node_id", App::Instance()->GetNodeId());
prop->SetVal("server_instance_id", App::Instance()->GetInstanceId());
prop->SetVal("map_id", hum->room->GetMapMeta()->map_id());
prop->SetVal("map_name", hum->room->GetMapMeta()->map_name());
@ -75,8 +75,8 @@ void GameLog::GameEnd(Player* hum)
prop->SetVal("game_time", a8::XGetTickCount() - hum->create_tick);
//prop->SetVal("start_param", "");
prop->SetVal("team_id", hum->team_id);
prop->SetVal("server_node_id", App::Instance()->node_id);
prop->SetVal("server_instance_id", App::Instance()->instance_id);
prop->SetVal("server_node_id", App::Instance()->GetNodeId());
prop->SetVal("server_instance_id", App::Instance()->GetInstanceId());
prop->SetVal("map_id", hum->room->GetMapMeta()->map_id());
prop->SetVal("map_name", hum->room->GetMapMeta()->map_name());

View File

@ -25,7 +25,7 @@ static void _GMOpsSelfChecking(std::shared_ptr<f8::JsonHttpRequest> request)
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
request->resp_xobj->SetVal("healthy", 1);
request->resp_xobj->SetVal("servicing", App::Instance()->servicing ? 1 : 0);
request->resp_xobj->SetVal("servicing", App::Instance()->IsServicing() ? 1 : 0);
request->resp_xobj->SetVal("max_rundelay", PerfMonitor::Instance()->max_run_delay_time);
request->resp_xobj->SetVal("max_timer_idle", PerfMonitor::Instance()->max_timer_idle);
}
@ -42,22 +42,22 @@ static void _GMOpsStopService(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
App::Instance()->servicing = false;
App::Instance()->SetServicing(false);
}
static void _GMOpsStartService(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
App::Instance()->servicing = true;
App::Instance()->SetServicing(true);
}
static void _GMOpsServerInfo(std::shared_ptr<f8::JsonHttpRequest> request)
{
request->resp_xobj->SetVal("errcode", 0);
request->resp_xobj->SetVal("errmsg", "");
request->resp_xobj->SetVal("node_id", App::Instance()->node_id);
request->resp_xobj->SetVal("instance_id", App::Instance()->instance_id);
request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId());
request->resp_xobj->SetVal("instance_id", App::Instance()->GetInstanceId());
}
static void _GMStatGetRealTimeOnline(std::shared_ptr<f8::JsonHttpRequest> request)

View File

@ -29,7 +29,7 @@ void JsonDataMgr::Init()
gameserver_cluster_json_file = a8::Format("%s/node%d/game%d.gameserver.cluster.json",
{
work_path_,
App::Instance()->node_id,
App::Instance()->GetNodeId(),
GAME_ID
});
setting_json_file = a8::Format("%s/setting.json",
@ -83,7 +83,7 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
{
for (int i = 0; i < gameserver_cluster_json_.Size(); ++i) {
std::shared_ptr<a8::XObject> conf = gameserver_cluster_json_.At(i);
if (conf->At("instance_id")->AsXValue().GetInt() == App::Instance()->instance_id) {
if (conf->At("instance_id")->AsXValue().GetInt() == App::Instance()->GetInstanceId()) {
return conf;
}
}
@ -101,7 +101,7 @@ void JsonDataMgr::Reload()
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
{
work_path_,
App::Instance()->node_id,
App::Instance()->GetNodeId(),
GAME_ID
});
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);

View File

@ -54,13 +54,13 @@ namespace mt
res_path_ = a8::Format("../../../conf_test/game%d/gameserver.test/res%d/",
{
GAME_ID,
App::Instance()->instance_id
App::Instance()->GetInstanceId()
});
} else {
res_path_ = a8::Format("../../../conf_test/game%d/gameserver.dev/res%d/",
{
GAME_ID,
App::Instance()->instance_id
App::Instance()->GetInstanceId()
});
}
} else {

View File

@ -165,8 +165,8 @@ namespace mt
abort();
}
#ifdef DEBUG
if (App::Instance()->instance_id == 600 ||
App::Instance()->instance_id == 100) {
if (App::Instance()->GetInstanceId() == 600 ||
App::Instance()->GetInstanceId() == 100) {
_float_cd = 6;
}
#endif

View File

@ -449,15 +449,15 @@ void RoomMgr::ReportServerState(int instance_id, const std::string& host, int po
port
});
auto url_params = a8::MutableXObject::CreateObject();
url_params->SetVal("node_id", App::Instance()->node_id);
url_params->SetVal("instance_id", App::Instance()->instance_id);
url_params->SetVal("node_id", App::Instance()->GetNodeId());
url_params->SetVal("instance_id", App::Instance()->GetInstanceId());
url_params->SetVal("ip", JsonDataMgr::Instance()->ip);
url_params->SetVal("port", JsonDataMgr::Instance()->listen_port);
url_params->SetVal("online_num", PlayerMgr::Instance()->OnlineNum());
url_params->SetVal("room_num", RoomNum());
url_params->SetVal("channel", JsonDataMgr::Instance()->channel);
url_params->SetVal("alive_count", PerfMonitor::Instance()->real_alive_count);
url_params->SetVal("servicing", App::Instance()->servicing ? 1 : 0);
url_params->SetVal("servicing", App::Instance()->IsServicing() ? 1 : 0);
f8::HttpClientPool::Instance()->HttpGet
(
cb,