67 lines
1.9 KiB
C++
67 lines
1.9 KiB
C++
#include "precompile.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include <f8/utils.h>
|
|
|
|
#include "jsondatamgr.h"
|
|
#include "app.h"
|
|
|
|
void JsonDataMgr::Init()
|
|
{
|
|
if (!f8::IsOnlineEnv()) {
|
|
work_path_ = a8::Format
|
|
("../../../conf_test/game%d/%s",
|
|
{
|
|
GAME_ID,
|
|
f8::IsTestEnv() ? "wsproxy.test" : "wsproxy.dev"
|
|
});
|
|
}
|
|
|
|
std::string wsproxyserver_cluster_json_file;
|
|
std::string masterserver_cluster_json_file;
|
|
wsproxyserver_cluster_json_file = a8::Format
|
|
("%s/node%d/game%d.wsproxy.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->GetNodeId(),
|
|
GAME_ID
|
|
});
|
|
masterserver_cluster_json_file = a8::Format
|
|
("%s/node%d/game%d.masterserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->GetNodeId(),
|
|
GAME_ID
|
|
});
|
|
|
|
wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file);
|
|
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
|
udp_host_ = GetConf()->At("listen_udp_host")->AsXValue().GetString();
|
|
udp_port_ = GetConf()->At("listen_udp_port")->AsXValue();
|
|
}
|
|
|
|
void JsonDataMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
|
{
|
|
if (App::Instance()->GetInstanceId() < 1 ||
|
|
App::Instance()->GetInstanceId() > wsproxyserver_cluster_json_.Size()) {
|
|
abort();
|
|
}
|
|
return wsproxyserver_cluster_json_[App::Instance()->GetInstanceId() - 1];
|
|
}
|
|
|
|
void JsonDataMgr::TraverseMaster(std::function<void (int, std::string, int)> cb)
|
|
{
|
|
for (int i = 0; i < masterserver_cluster_json_.Size(); ++i) {
|
|
auto master_svr_conf = masterserver_cluster_json_.At(i);
|
|
int instance_id = master_svr_conf->At("instance_id")->AsXValue();
|
|
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
|
|
int remote_port = master_svr_conf->At("port")->AsXValue();
|
|
cb(instance_id, remote_ip, remote_port);
|
|
}
|
|
}
|