72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
#include "precompile.h"
|
|
|
|
#include "jsondatamgr.h"
|
|
#include "app.h"
|
|
|
|
#include "framework/cpp/utils.h"
|
|
|
|
void JsonDataMgr::Init()
|
|
{
|
|
if (!f8::IsOnlineEnv()) {
|
|
if (f8::IsTestEnv()) {
|
|
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver.test",
|
|
{
|
|
GAME_ID,
|
|
App::Instance()->instance_id,
|
|
GAME_ID
|
|
});
|
|
} else {
|
|
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/gameserver.dev",
|
|
{
|
|
GAME_ID,
|
|
App::Instance()->instance_id,
|
|
GAME_ID
|
|
});
|
|
}
|
|
}
|
|
std::string gameserver_cluster_json_file;
|
|
gameserver_cluster_json_file = a8::Format("%s/node%d/game%d.gameserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->node_id,
|
|
GAME_ID
|
|
});
|
|
gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file);
|
|
ip = GetConf()->At("ip")->AsXValue().GetString();
|
|
listen_port = GetConf()->At("listen_port")->AsXValue();
|
|
if (GetConf()->HasKey("channel")) {
|
|
channel = GetConf()->At("channel")->AsXValue();
|
|
}
|
|
server_info = a8::Format("%s:%d", {ip, listen_port});
|
|
Reload();
|
|
}
|
|
|
|
void JsonDataMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
|
{
|
|
if (App::Instance()->instance_id < 1 || App::Instance()->instance_id > gameserver_cluster_json_.Size()) {
|
|
abort();
|
|
}
|
|
return gameserver_cluster_json_[App::Instance()->instance_id - 1];
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
|
|
{
|
|
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
|
|
}
|
|
|
|
void JsonDataMgr::Reload()
|
|
{
|
|
std::string masterserver_cluster_json_file;
|
|
masterserver_cluster_json_file = a8::Format("%s/node%d/game%d.masterserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->node_id,
|
|
GAME_ID
|
|
});
|
|
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
|
}
|