116 lines
3.4 KiB
C++
116 lines
3.4 KiB
C++
#include "precompile.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include <f8/utils.h>
|
|
#include <f8/udplog.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 wsproxy_cluster_json_file;
|
|
std::string master_cluster_json_file;
|
|
std::string kcp_conf_json_file;
|
|
wsproxy_cluster_json_file = a8::Format
|
|
("%s/node%d/game%d.wsproxy.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->GetNodeId(),
|
|
GAME_ID
|
|
});
|
|
master_cluster_json_file = a8::Format
|
|
("%s/node%d/game%d.masterserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
App::Instance()->GetNodeId(),
|
|
GAME_ID
|
|
});
|
|
kcp_conf_json_file = a8::Format
|
|
("%s/kcp_conf.json",
|
|
{
|
|
work_path_,
|
|
});
|
|
|
|
wsproxy_cluster_json_.ReadFromFile(wsproxy_cluster_json_file);
|
|
master_cluster_json_.ReadFromFile(master_cluster_json_file);
|
|
kcp_conf_json_.ReadFromFile(kcp_conf_json_file);
|
|
udp_host_ = GetConf()->At("listen_udp_host")->AsXValue().GetString();
|
|
udp_port_ = GetConf()->At("listen_udp_port")->AsXValue();
|
|
{
|
|
kcp_conf_.open = kcp_conf_json_.At("open")->AsXValue();
|
|
|
|
kcp_conf_.sndwnd = kcp_conf_json_.At("sndwnd")->AsXValue();
|
|
kcp_conf_.rcvwnd = kcp_conf_json_.At("rcvwnd")->AsXValue();
|
|
|
|
kcp_conf_.nodelay = kcp_conf_json_.At("nodelay")->AsXValue();
|
|
kcp_conf_.interval = kcp_conf_json_.At("interval")->AsXValue();
|
|
kcp_conf_.resend = kcp_conf_json_.At("resend")->AsXValue();
|
|
kcp_conf_.nc = kcp_conf_json_.At("nc")->AsXValue();
|
|
|
|
kcp_conf_.rx_minrto = kcp_conf_json_.At("rx_minrto")->AsXValue();
|
|
kcp_conf_.fastresend = kcp_conf_json_.At("fastresend")->AsXValue();
|
|
|
|
f8::UdpLog::Instance()->Info
|
|
(" kcp_conf open:%d sndwnd:%d rcvwnd:%d "
|
|
"nodelay:%d interval:%d resend:%d nc:%d "
|
|
"rx_minrto:%d fastresend:%d",
|
|
{
|
|
kcp_conf_.open,
|
|
|
|
kcp_conf_.sndwnd,
|
|
kcp_conf_.rcvwnd,
|
|
|
|
kcp_conf_.nodelay,
|
|
kcp_conf_.interval,
|
|
kcp_conf_.resend,
|
|
kcp_conf_.nc,
|
|
|
|
kcp_conf_.rx_minrto,
|
|
kcp_conf_.fastresend
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
void JsonDataMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
|
{
|
|
for (int i = 0; i < wsproxy_cluster_json_.Size(); ++i) {
|
|
std::shared_ptr<a8::XObject> conf = wsproxy_cluster_json_.At(i);
|
|
if (conf->At("instance_id")->AsXValue().GetInt() == App::Instance()->GetInstanceId()) {
|
|
return conf;
|
|
}
|
|
}
|
|
A8_ABORT();
|
|
}
|
|
|
|
void JsonDataMgr::TraverseMaster(std::function<void (int, std::string, int)> cb)
|
|
{
|
|
for (int i = 0; i < master_cluster_json_.Size(); ++i) {
|
|
auto master_svr_conf = master_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);
|
|
}
|
|
}
|
|
|
|
void JsonDataMgr::SetKcpSwitch(int is_open)
|
|
{
|
|
kcp_conf_.open = is_open ? 1 : 0;
|
|
}
|