From b038b27c40af203beb3da18b6816f37743a19a5c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 24 Apr 2023 14:30:45 +0800 Subject: [PATCH] 1 --- server/wsproxy/app.cc | 33 +++++++++++++++++---------------- server/wsproxy/app.h | 23 +++++++++++++---------- server/wsproxy/handlermgr.cc | 2 +- server/wsproxy/jsondatamgr.cc | 13 +++++++------ server/wsproxy/mastermgr.cc | 2 +- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index 721f2f0..db5adf4 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -63,7 +63,7 @@ static void SavePerfLog() App::Instance()->perf.max_timer_idle, App::Instance()->perf.in_data_size, App::Instance()->perf.out_data_size, - App::Instance()->msgnode_size_, + //App::Instance()->msgnode_size_, App::Instance()->perf.read_count, App::Instance()->perf.max_login_time, App::Instance()->perf.max_join_time, @@ -91,24 +91,25 @@ bool App::Init(int argc, char* argv[]) if (!ParseOpt()) { terminated = true; - if (node_id <= 0) { + if (node_id_ <= 0) { a8::XPrintf("gameserver启动失败,缺少-n参数\n", {}); - } else if (node_id > MAX_NODE_ID) { + } else if (node_id_ > MAX_NODE_ID) { a8::XPrintf("gameserver启动失败,-n参数不能大于%d\n", {MAX_NODE_ID}); - } else if (instance_id <= 0) { + } else if (instance_id_ <= 0) { a8::XPrintf("gameserver启动失败,缺少-i参数\n", {}); - } else if (instance_id > MAX_INSTANCE_ID) { + } else if (instance_id_ > MAX_INSTANCE_ID) { a8::XPrintf("gameserver启动失败,-i参数不能大于%d\n", {MAX_INSTANCE_ID}); } return false; } a8::XPrintf("wsproxy starting node_id:%d instance_id:%d pid:%d\n", { - node_id, - instance_id, - getpid() + node_id_, + instance_id_, + getpid() }); + uuid_ = std::make_shared(); loop_mutex_ = new std::mutex(); loop_cond_ = new std::condition_variable(); msg_mutex_ = new std::mutex(); @@ -120,7 +121,7 @@ bool App::Init(int argc, char* argv[]) HandlerMgr::Instance()->Init(); f8::Timer::Instance()->Init(); JsonDataMgr::Instance()->Init(); - uuid.SetMachineId((node_id - 1) * MAX_NODE_ID + instance_id); + uuid_->SetMachineId((node_id_ - 1) * MAX_NODE_ID + instance_id_); DownStreamMgr::Instance()->Init(); MasterMgr::Instance()->Init(); UpStreamMgr::Instance()->Init(); @@ -129,7 +130,7 @@ bool App::Init(int argc, char* argv[]) f8::UdpLog::Instance()->Info("wsproxy starting instance_id:%d pid:%d", { - instance_id, + instance_id_, getpid(), }); { @@ -177,7 +178,7 @@ bool App::Init(int argc, char* argv[]) void App::UnInit() { - a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id, getpid()}); + a8::XPrintf("wsproxy terminating instance_id:%d pid:%d\n", {instance_id_, getpid()}); GCListener::Instance()->UnInit(); LongSessionMgr::Instance()->UnInit(); MasterMgr::Instance()->UnInit(); @@ -199,7 +200,7 @@ void App::UnInit() loop_cond_ = nullptr; delete loop_mutex_; loop_mutex_ = nullptr; - a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id, getpid()}); + a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id_, getpid()}); } int App::Run() @@ -489,12 +490,12 @@ bool App::ParseOpt() switch (ch) { case 'n': { - node_id = a8::XValue(optarg); + node_id_ = a8::XValue(optarg); } break; case 'i': { - instance_id = a8::XValue(optarg); + instance_id_ = a8::XValue(optarg); } break; case 'f': @@ -508,7 +509,7 @@ bool App::ParseOpt() break; } } - return instance_id > 0 && node_id > 0; + return instance_id_ > 0 && node_id_ > 0; } bool App::HasFlag(int flag) @@ -608,5 +609,5 @@ void App::DispatchUdpMsg() long long App::NewUuid() { - return uuid.Generate(); + return uuid_->Generate(); } diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index bfb896c..37946d3 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -1,22 +1,25 @@ #pragma once -#include #include namespace a8 { struct UdpPacket; + namespace uuid + { + class SnowFlake; + } } struct MsgNode; struct UdpMsgNode; class App : public a8::Singleton { - private: +private: App() {}; friend class a8::Singleton; - public: +public: bool Init(int argc, char* argv[]); void UnInit(); @@ -36,6 +39,8 @@ class App : public a8::Singleton void NotifyLoopCond(); bool HasFlag(int flag); long long NewUuid(); + int GetNodeId() { return node_id_; } + int GetInstanceId() { return instance_id_; } private: void QuickExecute(); @@ -57,20 +62,19 @@ private: void FreeSocketMsgQueue(); void FreeUdpMsgQueue(); - public: +public: int argc = 0; char** argv = nullptr; volatile bool terminated = false; volatile bool shutdowned = false; std::set flags; PerfMonitor perf; - a8::uuid::SnowFlake uuid; -public: - int node_id = 0; - int instance_id = 0; +private: + int node_id_ = 0; + int instance_id_ = 0; - private: + std::shared_ptr uuid_; std::mutex *loop_mutex_ = nullptr; std::condition_variable *loop_cond_ = nullptr; @@ -84,7 +88,6 @@ public: UdpMsgNode* udp_bot_node_ = nullptr; UdpMsgNode* udp_work_node_ = nullptr; - public: int msgnode_size_ = 0 ; int udp_msgnode_size_ = 0 ; int working_msgnode_size_ = 0; diff --git a/server/wsproxy/handlermgr.cc b/server/wsproxy/handlermgr.cc index 0bcc8a8..fdf963c 100644 --- a/server/wsproxy/handlermgr.cc +++ b/server/wsproxy/handlermgr.cc @@ -24,7 +24,7 @@ static void _GMOpsGetNodeId(std::shared_ptr request) { request->resp_xobj->SetVal("errcode", 0); request->resp_xobj->SetVal("errmsg", ""); - request->resp_xobj->SetVal("node_id", App::Instance()->node_id); + request->resp_xobj->SetVal("node_id", App::Instance()->GetNodeId()); } void HandlerMgr::Init() diff --git a/server/wsproxy/jsondatamgr.cc b/server/wsproxy/jsondatamgr.cc index f6c2616..c22ce6b 100644 --- a/server/wsproxy/jsondatamgr.cc +++ b/server/wsproxy/jsondatamgr.cc @@ -30,14 +30,14 @@ void JsonDataMgr::Init() std::string routing_tables_json_file; wsproxyserver_cluster_json_file = a8::Format("%s/node%d/game%d.wsproxy.cluster.json", { - work_path_, - App::Instance()->node_id, - GAME_ID + 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()->node_id, + App::Instance()->GetNodeId(), GAME_ID }); routing_tables_json_file = a8::Format("%s/routing_tables.json", @@ -71,10 +71,11 @@ void JsonDataMgr::UnInit() std::shared_ptr JsonDataMgr::GetConf() { - if (App::Instance()->instance_id < 1 || App::Instance()->instance_id > wsproxyserver_cluster_json_.Size()) { + if (App::Instance()->GetInstanceId() < 1 || + App::Instance()->GetInstanceId() > wsproxyserver_cluster_json_.Size()) { abort(); } - return wsproxyserver_cluster_json_[App::Instance()->instance_id - 1]; + return wsproxyserver_cluster_json_[App::Instance()->GetInstanceId() - 1]; } std::shared_ptr JsonDataMgr::GetMasterServerClusterConf() diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 448c6c5..2224dc3 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -110,7 +110,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, std::string data = a8::Format("!%s_%s_%d_%d", { account_id, - App::Instance()->uuid.Generate(), + App::Instance()->NewUuid(), getpid(), rand() });