1
This commit is contained in:
parent
efbfca944a
commit
ea3d340cd1
@ -13,7 +13,7 @@ enum InnerMesssage_e
|
|||||||
IM_PlayerOffline,
|
IM_PlayerOffline,
|
||||||
IM_ExecGM,
|
IM_ExecGM,
|
||||||
IM_UpStreamDisconnect,
|
IM_UpStreamDisconnect,
|
||||||
IM_MasterSvrDisconnect,
|
IM_MasterDisconnect,
|
||||||
IM_UpStreamConnect,
|
IM_UpStreamConnect,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
const int PACK_MAX = 1024 * 64;
|
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->instance_id = instance_id;
|
||||||
this->remote_ip = remote_ip;
|
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_ = new a8::TcpClient();
|
||||||
tcp_client_->remote_address = remote_ip;
|
tcp_client_->remote_address = remote_ip;
|
||||||
tcp_client_->remote_port = remote_port;
|
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_error = std::bind(&Master::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_connect = std::bind(&Master::on_connect, this, std::placeholders::_1);
|
||||||
tcp_client_->on_disconnect = std::bind(&MasterSvr::on_disconnect, this, std::placeholders::_1);
|
tcp_client_->on_disconnect = std::bind(&Master::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_socketread = std::bind(&Master::on_socketread, this ,std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||||
#if 0
|
#if 0
|
||||||
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
timer_ = a8::Timer::Instance()->AddRepeatTimer(1000 * 9 + a8::RandEx(500, 150),
|
||||||
a8::XParams().SetSender(this),
|
a8::XParams().SetSender(this),
|
||||||
[] (const a8::XParams& param)
|
[] (const a8::XParams& param)
|
||||||
{
|
{
|
||||||
MasterSvr* conn = (MasterSvr*)param.sender.GetUserData();
|
Master* conn = (Master*)param.sender.GetUserData();
|
||||||
conn->CheckAlive();
|
conn->CheckAlive();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::UnInit()
|
void Master::UnInit()
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
a8::Timer::Instance()->DeleteTimer(timer_);
|
a8::Timer::Instance()->DeleteTimer(timer_);
|
||||||
@ -56,24 +56,24 @@ void MasterSvr::UnInit()
|
|||||||
recv_buff_ = nullptr;
|
recv_buff_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::Open()
|
void Master::Open()
|
||||||
{
|
{
|
||||||
tcp_client_->Open();
|
tcp_client_->Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::Close()
|
void Master::Close()
|
||||||
{
|
{
|
||||||
tcp_client_->Close();
|
tcp_client_->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MasterSvr::Connected()
|
bool Master::Connected()
|
||||||
{
|
{
|
||||||
return tcp_client_->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,
|
errorId,
|
||||||
sender->remote_address,
|
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;
|
recv_bufflen_ = 0;
|
||||||
f8::UdpLog::Instance()->Info("masterserver connected", {});
|
f8::UdpLog::Instance()->Info("masterserver connected", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::on_disconnect(a8::TcpClient* sender)
|
void Master::on_disconnect(a8::TcpClient* sender)
|
||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
f8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id});
|
f8::UdpLog::Instance()->Info("masterserver %d disconnected after 10s later reconnect", {instance_id});
|
||||||
#if 0
|
#if 0
|
||||||
App::Instance()->AddIMMsg(IM_MasterSvrDisconnect,
|
App::Instance()->AddIMMsg(IM_MasterDisconnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(instance_id)
|
.SetSender(instance_id)
|
||||||
);
|
);
|
||||||
#endif
|
#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
|
#if 0
|
||||||
++App::Instance()->perf.read_count;
|
++App::Instance()->perf.read_count;
|
||||||
@ -148,7 +148,7 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvr::CheckAlive()
|
void Master::CheckAlive()
|
||||||
{
|
{
|
||||||
if (!Connected()) {
|
if (!Connected()) {
|
||||||
Open();
|
Open();
|
||||||
|
@ -9,7 +9,7 @@ namespace a8
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct timer_list;
|
struct timer_list;
|
||||||
class MasterSvr
|
class Master
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int instance_id = 0;
|
int instance_id = 0;
|
||||||
|
@ -27,7 +27,7 @@ void MasterMgr::Init()
|
|||||||
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
|
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
|
||||||
int remote_port = master_svr_conf->At("port")->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);
|
conn->Init(instance_id, remote_ip, remote_port);
|
||||||
mastersvr_hash_[conn->instance_id] = conn;
|
mastersvr_hash_[conn->instance_id] = conn;
|
||||||
conn->Open();
|
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);
|
auto itr = mastersvr_hash_.find(instance_id);
|
||||||
return itr != mastersvr_hash_.end() ? itr->second : nullptr;
|
return itr != mastersvr_hash_.end() ? itr->second : nullptr;
|
||||||
@ -108,7 +108,7 @@ void MasterMgr::RequestTargetServer(f8::MsgHdr& hdr,
|
|||||||
team_uuid = data;
|
team_uuid = data;
|
||||||
code = a8::openssl::Crc32((unsigned char*)data.data(), data.size());
|
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) {
|
if (svr) {
|
||||||
++curr_context_id_;
|
++curr_context_id_;
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -10,7 +10,7 @@ namespace ss
|
|||||||
class SS_MS_ResponseTargetServer;
|
class SS_MS_ResponseTargetServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MasterSvr;
|
class Master;
|
||||||
class MasterMgr : public a8::Singleton<MasterMgr>
|
class MasterMgr : public a8::Singleton<MasterMgr>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -37,12 +37,12 @@ class MasterMgr : public a8::Singleton<MasterMgr>
|
|||||||
private:
|
private:
|
||||||
long long GetContextIdBySocket(int socket_handle);
|
long long GetContextIdBySocket(int socket_handle);
|
||||||
f8::MsgHdr* GetHdrByContextId(long long context_id);
|
f8::MsgHdr* GetHdrByContextId(long long context_id);
|
||||||
MasterSvr* GetConnById(int instance_id);
|
Master* GetConnById(int instance_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int target_conn_id_ = 100;
|
int target_conn_id_ = 100;
|
||||||
long long curr_context_id_ = 0;
|
long long curr_context_id_ = 0;
|
||||||
std::map<int, MasterSvr*> mastersvr_hash_;
|
std::map<int, Master*> mastersvr_hash_;
|
||||||
std::map<int, long long> pending_socket_hash_;
|
std::map<int, long long> pending_socket_hash_;
|
||||||
std::map<long long, f8::MsgHdr*> pending_request_hash_;
|
std::map<long long, f8::MsgHdr*> pending_request_hash_;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user