95 lines
3.4 KiB
C++
95 lines
3.4 KiB
C++
#include "precompile.h"
|
|
|
|
#include <mutex>
|
|
|
|
#include "jsondatamgr.h"
|
|
#include "app.h"
|
|
|
|
void JsonDataMgr::Init()
|
|
{
|
|
if (!f8::IsOnlineEnv()) {
|
|
if (f8::IsTestEnv()) {
|
|
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/imserver.test",
|
|
{
|
|
GAME_ID,
|
|
App::Instance()->instance_id,
|
|
GAME_ID
|
|
});
|
|
} else {
|
|
work_path_ = a8::Format("/root/pub/%d/%d/conf_test/game%d/imserver.dev",
|
|
{
|
|
GAME_ID,
|
|
App::Instance()->instance_id,
|
|
GAME_ID
|
|
});
|
|
}
|
|
}
|
|
|
|
std::string imserver_cluster_json_file;
|
|
std::string masterserver_cluster_json_file;
|
|
std::string rankserver_cluster_json_file;
|
|
std::string mysql_cluster_json_file;
|
|
mysql_cluster_json_file = a8::Format("%s/node1/friend.imserver.mysql.cluster.json",
|
|
{
|
|
work_path_,
|
|
});
|
|
imserver_cluster_json_file = a8::Format("%s/node1/friend.imserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
});
|
|
masterserver_cluster_json_file = a8::Format("%s/node1/friend.masterserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
});
|
|
rankserver_cluster_json_file = a8::Format("%s/node1/friend.rankserver.cluster.json",
|
|
{
|
|
work_path_,
|
|
});
|
|
mysql_cluster_json_.ReadFromFile(mysql_cluster_json_file);
|
|
imserver_cluster_json_.ReadFromFile(imserver_cluster_json_file);
|
|
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
|
rankserver_cluster_json_.ReadFromFile(rankserver_cluster_json_file);
|
|
}
|
|
|
|
void JsonDataMgr::UnInit()
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
|
{
|
|
if (App::Instance()->instance_id < 1 ||
|
|
App::Instance()->instance_id > imserver_cluster_json_.Size()) {
|
|
abort();
|
|
}
|
|
return imserver_cluster_json_[App::Instance()->instance_id - 1];
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
|
|
{
|
|
return std::make_shared<a8::XObject>(masterserver_cluster_json_);
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetRankServerClusterConf()
|
|
{
|
|
return std::make_shared<a8::XObject>(rankserver_cluster_json_);
|
|
}
|
|
|
|
std::shared_ptr<a8::XObject> JsonDataMgr::GetMysqlClusterConf()
|
|
{
|
|
return std::make_shared<a8::XObject>(mysql_cluster_json_);
|
|
}
|
|
|
|
bool JsonDataMgr::GetRankServerConf(std::string& ip, int& port)
|
|
{
|
|
std::shared_ptr<a8::XObject> rankserver_cluster_conf = GetRankServerClusterConf();
|
|
std::shared_ptr<a8::XObject> conf = rankserver_cluster_conf->At(0);
|
|
ip = conf->At("ip")->AsXValue().GetString();
|
|
port = conf->At("port")->AsXValue();
|
|
return true;
|
|
}
|
|
|
|
int JsonDataMgr::GetIMInstanceId(long long id)
|
|
{
|
|
return (id % imserver_cluster_json_.Size()) + 1;
|
|
}
|