添加GetNodeHost
This commit is contained in:
parent
43403cb8ea
commit
af14aff442
@ -61,12 +61,31 @@ public:
|
||||
virtual bool HandleRedirect(const std::string& url, const std::string& querystr,
|
||||
std::string& location) override
|
||||
{
|
||||
#if 1
|
||||
#if MASTER_MODE
|
||||
a8::HTTPRequest request;
|
||||
a8::ParserUrlQueryString(querystr.c_str(), request);
|
||||
if (a8::Get(request, "c").GetString() == "Ops" &&
|
||||
a8::Get(request, "a").GetString() == "join") {
|
||||
std::string team_uuid = a8::Get(request, "team_uuid").GetString();
|
||||
std::vector<std::string> strings;
|
||||
a8::Split(team_uuid, strings, '_');
|
||||
if (strings.size() > 2) {
|
||||
int node_id = a8::XValue(strings[0]);
|
||||
if (node_id != App::Instance()->node_id) {
|
||||
std::string host;
|
||||
if (JsonDataMgr::Instance()->GetNodeHost(node_id, host)) {
|
||||
location = a8::Format("wss://%s/webapp/index.php?c=Ops&a=join&team_uuid=%s",
|
||||
{
|
||||
host,
|
||||
team_uuid
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
#else
|
||||
location = "ws://192.168.100.21:7101";
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
virtual void OnDisConnect() override
|
||||
|
@ -114,7 +114,6 @@ bool App::Init(int argc, char* argv[])
|
||||
HandlerMgr::Instance()->Init();
|
||||
a8::Timer::Instance()->Init();
|
||||
JsonDataMgr::Instance()->Init();
|
||||
GCListener::Instance()->Init();
|
||||
#if MASTER_MODE
|
||||
uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id);
|
||||
#else
|
||||
@ -123,6 +122,7 @@ bool App::Init(int argc, char* argv[])
|
||||
GameClientMgr::Instance()->Init();
|
||||
MasterSvrMgr::Instance()->Init();
|
||||
TargetConnMgr::Instance()->Init();
|
||||
GCListener::Instance()->Init();
|
||||
|
||||
a8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d", {instance_id, getpid()});
|
||||
{
|
||||
@ -154,10 +154,10 @@ bool App::Init(int argc, char* argv[])
|
||||
void App::UnInit()
|
||||
{
|
||||
a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id, getpid()});
|
||||
GCListener::Instance()->UnInit();
|
||||
MasterSvrMgr::Instance()->UnInit();
|
||||
TargetConnMgr::Instance()->UnInit();
|
||||
GameClientMgr::Instance()->UnInit();
|
||||
GCListener::Instance()->UnInit();
|
||||
JsonDataMgr::Instance()->UnInit();
|
||||
a8::Timer::Instance()->UnInit();
|
||||
HandlerMgr::Instance()->UnInit();
|
||||
@ -614,4 +614,3 @@ void App::FreeIMMsgQueue()
|
||||
}
|
||||
im_msg_mutex_->unlock();
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,20 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "jsondatamgr.h"
|
||||
#include "app.h"
|
||||
|
||||
void JsonDataMgr::Init()
|
||||
{
|
||||
#if MASTER_MODE
|
||||
node_host_mutex_ = new std::mutex();
|
||||
#endif
|
||||
|
||||
std::string wsproxyserver_cluster_json_file;
|
||||
std::string masterserver_cluster_json_file;
|
||||
std::string targetserver_cluster_json_file;
|
||||
std::string routing_tables_json_file;
|
||||
if (f8::IsOnlineEnv()) {
|
||||
#if MASTER_MODE
|
||||
wsproxyserver_cluster_json_file = a8::Format("../config/node%d/game%d.wsproxy.cluster.json",
|
||||
@ -20,6 +27,9 @@ void JsonDataMgr::Init()
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
routing_tables_json_file = a8::Format("../config/routing_tables.json",
|
||||
{
|
||||
});
|
||||
#else
|
||||
wsproxyserver_cluster_json_file = a8::Format("../config/game%d.wsproxy.cluster.json", {GAME_ID});
|
||||
masterserver_cluster_json_file = a8::Format("../config/game%d.masterserver.cluster.json", {GAME_ID});
|
||||
@ -38,6 +48,10 @@ void JsonDataMgr::Init()
|
||||
App::Instance()->node_id,
|
||||
GAME_ID
|
||||
});
|
||||
routing_tables_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/routing_tables.json",
|
||||
{
|
||||
GAME_ID
|
||||
});
|
||||
#else
|
||||
wsproxyserver_cluster_json_file = a8::Format("/var/data/conf_test/game%d/wsproxy/game%d.wsproxy.cluster.json",
|
||||
{GAME_ID, GAME_ID});
|
||||
@ -50,6 +64,17 @@ void JsonDataMgr::Init()
|
||||
wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file);
|
||||
#if MASTER_MODE
|
||||
masterserver_cluster_json_.ReadFromFile(masterserver_cluster_json_file);
|
||||
routing_tables_json_.ReadFromFile(routing_tables_json_file);
|
||||
node_host_mutex_->lock();
|
||||
for (int i = 0; i < routing_tables_conf->Size(); ++i) {
|
||||
int node_id = master_svr_conf->At("node_id")->AsXValue();
|
||||
std::string host = master_svr_conf->At("host")->AsXValue();
|
||||
if (node_host_hash_.find(node_id) != node_host_hash_.end()) {
|
||||
abort();
|
||||
}
|
||||
node_host_hash_[node_id] = host;
|
||||
}
|
||||
node_host_mutex_->unlock();
|
||||
#else
|
||||
targetserver_cluster_json_.ReadFromFile(targetserver_cluster_json_file);
|
||||
#endif
|
||||
@ -57,6 +82,10 @@ void JsonDataMgr::Init()
|
||||
|
||||
void JsonDataMgr::UnInit()
|
||||
{
|
||||
#if MASTER_MODE
|
||||
delete node_host_mutex_;
|
||||
node_host_mutex_ = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetConf()
|
||||
@ -73,9 +102,26 @@ std::shared_ptr<a8::XObject> JsonDataMgr::GetMasterServerClusterConf()
|
||||
}
|
||||
|
||||
#if MASTER_MODE
|
||||
|
||||
bool JsonDataMgr::GetNodeHost(int node_id, std::string& host)
|
||||
{
|
||||
bool found = false;
|
||||
node_host_mutex_->lock();
|
||||
auto itr = node_host_hash_.find(node_id);
|
||||
if (itr != node_host_hash_.end()) {
|
||||
//!!!因为std::string基于引用计数多线程下直接复制的话会有问题,所以要用这种方式赋值
|
||||
host = itr->second.c_str();
|
||||
found = true;
|
||||
}
|
||||
node_host_mutex_->unlock();
|
||||
return found;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
std::shared_ptr<a8::XObject> JsonDataMgr::GetTargetServerClusterConf()
|
||||
{
|
||||
return std::make_shared<a8::XObject>(targetserver_cluster_json_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -13,6 +13,7 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
std::shared_ptr<a8::XObject> GetConf();
|
||||
std::shared_ptr<a8::XObject> GetMasterServerClusterConf();
|
||||
#if MASTER_MODE
|
||||
bool GetNodeHost(int node_id, std::string& host);
|
||||
#else
|
||||
std::shared_ptr<a8::XObject> GetTargetServerClusterConf();
|
||||
#endif
|
||||
@ -21,6 +22,9 @@ class JsonDataMgr : public a8::Singleton<JsonDataMgr>
|
||||
a8::XObject wsproxyserver_cluster_json_;
|
||||
a8::XObject masterserver_cluster_json_;
|
||||
#if MASTER_MODE
|
||||
std::mutex* node_host_mutex_ = nullptr;
|
||||
a8::XObject routing_tables_json_;
|
||||
std::map<int, std::string> node_host_hash_;
|
||||
#else
|
||||
a8::XObject targetserver_cluster_json_;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user