From ea3d340cd1c75c7b96d88a61d29e491e53641ae1 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 9 Apr 2023 07:44:33 +0000 Subject: [PATCH] 1 --- server/wsproxy/constant.h | 2 +- server/wsproxy/master.cc | 34 +++++++++++++++++----------------- server/wsproxy/master.h | 2 +- server/wsproxy/mastermgr.cc | 6 +++--- server/wsproxy/mastermgr.h | 6 +++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/server/wsproxy/constant.h b/server/wsproxy/constant.h index d118a4e..2c2a52e 100644 --- a/server/wsproxy/constant.h +++ b/server/wsproxy/constant.h @@ -13,7 +13,7 @@ enum InnerMesssage_e IM_PlayerOffline, IM_ExecGM, IM_UpStreamDisconnect, - IM_MasterSvrDisconnect, + IM_MasterDisconnect, IM_UpStreamConnect, }; diff --git a/server/wsproxy/master.cc b/server/wsproxy/master.cc index 2b8d191..6b7a0bd 100644 --- a/server/wsproxy/master.cc +++ b/server/wsproxy/master.cc @@ -15,7 +15,7 @@ const int PACK_MAX = 1024 * 64; -void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_port) +void Master::Init(int instance_id, const std::string& remote_ip, int remote_port) { this->instance_id = instance_id; this->remote_ip = remote_ip; @@ -27,22 +27,22 @@ void MasterSvr::Init(int instance_id, const std::string& remote_ip, int remote_p tcp_client_ = new a8::TcpClient(); tcp_client_->remote_address = remote_ip; tcp_client_->remote_port = remote_port; - tcp_client_->on_error = std::bind(&MasterSvr::on_error, this, std::placeholders::_1, std::placeholders::_2); - tcp_client_->on_connect = std::bind(&MasterSvr::on_connect, this, std::placeholders::_1); - tcp_client_->on_disconnect = std::bind(&MasterSvr::on_disconnect, this, std::placeholders::_1); - tcp_client_->on_socketread = std::bind(&MasterSvr::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); + tcp_client_->on_error = std::bind(&Master::on_error, this, std::placeholders::_1, std::placeholders::_2); + tcp_client_->on_connect = std::bind(&Master::on_connect, this, std::placeholders::_1); + tcp_client_->on_disconnect = std::bind(&Master::on_disconnect, this, std::placeholders::_1); + tcp_client_->on_socketread = std::bind(&Master::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); #if 0 timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150), a8::XParams().SetSender(this), [] (const a8::XParams& param) { - MasterSvr* conn = (MasterSvr*)param.sender.GetUserData(); + Master* conn = (Master*)param.sender.GetUserData(); conn->CheckAlive(); }); #endif } -void MasterSvr::UnInit() +void Master::UnInit() { #if 0 a8::Timer::Instance()->DeleteTimer(timer_); @@ -56,24 +56,24 @@ void MasterSvr::UnInit() recv_buff_ = nullptr; } -void MasterSvr::Open() +void Master::Open() { tcp_client_->Open(); } -void MasterSvr::Close() +void Master::Close() { tcp_client_->Close(); } -bool MasterSvr::Connected() +bool Master::Connected() { return tcp_client_->Connected(); } -void MasterSvr::on_error(a8::TcpClient* sender, int errorId) +void Master::on_error(a8::TcpClient* sender, int errorId) { - f8::UdpLog::Instance()->Error("MasterSvr errorid=%d remote_ip:%s remote_port:%d", + f8::UdpLog::Instance()->Error("Master errorid=%d remote_ip:%s remote_port:%d", { errorId, sender->remote_address, @@ -81,25 +81,25 @@ void MasterSvr::on_error(a8::TcpClient* sender, int errorId) }); } -void MasterSvr::on_connect(a8::TcpClient* sender) +void Master::on_connect(a8::TcpClient* sender) { recv_bufflen_ = 0; f8::UdpLog::Instance()->Info("masterserver connected", {}); } -void MasterSvr::on_disconnect(a8::TcpClient* sender) +void Master::on_disconnect(a8::TcpClient* sender) { recv_bufflen_ = 0; f8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id}); #if 0 - App::Instance()->AddIMMsg(IM_MasterSvrDisconnect, + App::Instance()->AddIMMsg(IM_MasterDisconnect, a8::XParams() .SetSender(instance_id) ); #endif } -void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len) +void Master::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len) { #if 0 ++App::Instance()->perf.read_count; @@ -148,7 +148,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len #endif } -void MasterSvr::CheckAlive() +void Master::CheckAlive() { if (!Connected()) { Open(); diff --git a/server/wsproxy/master.h b/server/wsproxy/master.h index 47654b1..8632cfb 100644 --- a/server/wsproxy/master.h +++ b/server/wsproxy/master.h @@ -9,7 +9,7 @@ namespace a8 } struct timer_list; -class MasterSvr +class Master { public: int instance_id = 0; diff --git a/server/wsproxy/mastermgr.cc b/server/wsproxy/mastermgr.cc index 798bb27..adc4774 100644 --- a/server/wsproxy/mastermgr.cc +++ b/server/wsproxy/mastermgr.cc @@ -27,7 +27,7 @@ void MasterMgr::Init() std::string remote_ip = master_svr_conf->At("ip")->AsXValue(); int remote_port = master_svr_conf->At("port")->AsXValue(); { - MasterSvr* conn = new MasterSvr(); + Master* conn = new Master(); conn->Init(instance_id, remote_ip, remote_port); mastersvr_hash_[conn->instance_id] = conn; conn->Open(); @@ -60,7 +60,7 @@ void MasterMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_Res } } -MasterSvr* MasterMgr::GetConnById(int instance_id) +Master* MasterMgr::GetConnById(int instance_id) { auto itr = mastersvr_hash_.find(instance_id); return itr != mastersvr_hash_.end() ? itr->second : nullptr; @@ -108,7 +108,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr, team_uuid = data; code = a8::openssl::Crc32((unsigned char*)data.data(), data.size()); } - MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1); + Master* svr = GetConnById(code % mastersvr_hash_.size() + 1); if (svr) { ++curr_context_id_; #if 0 diff --git a/server/wsproxy/mastermgr.h b/server/wsproxy/mastermgr.h index 0121d5a..eff71f0 100644 --- a/server/wsproxy/mastermgr.h +++ b/server/wsproxy/mastermgr.h @@ -10,7 +10,7 @@ namespace ss class SS_MS_ResponseTargetServer; } -class MasterSvr; +class Master; class MasterMgr : public a8::Singleton { public: @@ -37,12 +37,12 @@ class MasterMgr : public a8::Singleton private: long long GetContextIdBySocket(int socket_handle); f8::MsgHdr* GetHdrByContextId(long long context_id); - MasterSvr* GetConnById(int instance_id); + Master* GetConnById(int instance_id); private: int target_conn_id_ = 100; long long curr_context_id_ = 0; - std::map mastersvr_hash_; + std::map mastersvr_hash_; std::map pending_socket_hash_; std::map pending_request_hash_;