From 8ef28cf5560d88e3ec62a6367c24bba3cbf3a08c Mon Sep 17 00:00:00 2001 From: azw Date: Mon, 24 Apr 2023 11:18:04 +0000 Subject: [PATCH] 1 --- server/wsproxy/jsondatamgr.cc | 21 --------------------- server/wsproxy/jsondatamgr.h | 8 ++------ server/wsproxy/mastermgr.cc | 22 +++++++++------------- 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/server/wsproxy/jsondatamgr.cc b/server/wsproxy/jsondatamgr.cc index 6fafa4f..08fa337 100644 --- a/server/wsproxy/jsondatamgr.cc +++ b/server/wsproxy/jsondatamgr.cc @@ -9,8 +9,6 @@ void JsonDataMgr::Init() { - node_host_mutex_ = new std::mutex(); - if (!f8::IsOnlineEnv()) { if (f8::IsTestEnv()) { work_path_ = a8::Format("../../../conf_test/game%d/wsproxy.test", @@ -47,26 +45,12 @@ void JsonDataMgr::Init() wsproxyserver_cluster_json_.ReadFromFile(wsproxyserver_cluster_json_file); 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_json_.Size(); ++i) { - auto node_conf = routing_tables_json_.At(i); - int node_id = node_conf->At("node_id")->AsXValue(); - std::string host = node_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(); udp_host_ = GetConf()->At("listen_udp_host")->AsXValue().GetString(); udp_port_ = GetConf()->At("listen_udp_port")->AsXValue(); } void JsonDataMgr::UnInit() { - delete node_host_mutex_; - node_host_mutex_ = nullptr; } std::shared_ptr JsonDataMgr::GetConf() @@ -78,11 +62,6 @@ std::shared_ptr JsonDataMgr::GetConf() return wsproxyserver_cluster_json_[App::Instance()->GetInstanceId() - 1]; } -std::shared_ptr JsonDataMgr::GetMasterServerClusterConf() -{ - return std::make_shared(masterserver_cluster_json_); -} - void JsonDataMgr::TraverseMaster(std::function cb) { for (int i = 0; i < masterserver_cluster_json_.Size(); ++i) { diff --git a/server/wsproxy/jsondatamgr.h b/server/wsproxy/jsondatamgr.h index f3ee7bd..a4cbb52 100644 --- a/server/wsproxy/jsondatamgr.h +++ b/server/wsproxy/jsondatamgr.h @@ -12,19 +12,15 @@ class JsonDataMgr : public a8::Singleton void Init(); void UnInit(); - std::shared_ptr GetConf(); - std::shared_ptr GetMasterServerClusterConf(); - void TraverseMaster(std::function cb); std::string GetUdpHost() { return udp_host_; } int GetUdpPort() { return udp_port_; } + std::shared_ptr GetConf(); + void TraverseMaster(std::function cb); private: std::string work_path_ = "../config"; a8::XObject wsproxyserver_cluster_json_; a8::XObject masterserver_cluster_json_; - std::mutex* node_host_mutex_ = nullptr; - a8::XObject routing_tables_json_; - std::map node_host_hash_; std::string udp_host_; int udp_port_ = 0; }; diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 8720f4d..0ed36cc 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -35,19 +35,15 @@ void MasterMgr::Init() { curr_context_id_ = a8::MakeInt64(0, time(nullptr) + 1000 * 60 * 10); - auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetMasterServerClusterConf(); - for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) { - auto master_svr_conf = master_svr_cluster_conf->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(); - { - auto conn = std::make_shared(); - conn->Init(instance_id, remote_ip, remote_port); - mastersvr_hash_[conn->instance_id] = conn; - conn->Open(); - } - } + JsonDataMgr::Instance()->TraverseMaster + ( + [this] (int instance_id, std::string remote_ip, int remote_port) + { + auto conn = std::make_shared(); + conn->Init(instance_id, remote_ip, remote_port); + mastersvr_hash_[conn->instance_id] = conn; + conn->Open(); + }); } void MasterMgr::UnInit()