101 lines
3.5 KiB
C++
101 lines
3.5 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;
|
|
std::string setting_json_file;
|
|
|
|
gameserver_cluster_json_file = a8::Format("%s/node%d/game%d.gameserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->node_id,
|
|
GAME_ID
|
|
});
|
|
setting_json_file = a8::Format("%s/game%d.gameserver.setting.json",
|
|
{
|
|
work_path_,
|
|
GAME_ID
|
|
});
|
|
gameserver_cluster_json_.ReadFromFile(gameserver_cluster_json_file);
|
|
setting_json_.ReadFromFile(setting_json_file);
|
|
if (setting_json_.GetType() == a8::XOT_OBJECT &&
|
|
setting_json_.HasKey("battle_report_url")) {
|
|
battle_report_url_ = setting_json_.Get("battle_report_url").GetString();
|
|
}
|
|
|
|
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();
|
|
|
|
a8::UdpLog::Instance()->Info("battle_report_url:%s",
|
|
{
|
|
battle_report_url_
|
|
});
|
|
}
|
|
|
|
void JsonDataMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
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) {
|
|
return conf;
|
|
}
|
|
}
|
|
abort();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void JsonDataMgr::GetBattleReportUrl(std::string& url)
|
|
{
|
|
if (!battle_report_url_.empty()) {
|
|
url = battle_report_url_;
|
|
}
|
|
}
|