master mode ok
This commit is contained in:
parent
286f3055ef
commit
275709d03a
@ -466,13 +466,13 @@ void App::ProcessIMMsg()
|
|||||||
{
|
{
|
||||||
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
GameClientMgr::Instance()->OnClientDisconnect(pdelnode->params);
|
||||||
#if MASTER_MODE
|
#if MASTER_MODE
|
||||||
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender);
|
MasterSvrMgr::Instance()->RemoveRequest(pdelnode->params.param1, pdelnode->params.sender, true);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IM_TargetConnConnect:
|
case IM_TargetConnConnect:
|
||||||
{
|
{
|
||||||
GameClientMgr::Instance()->OnTargetServerDisconnect(pdelnode->params);
|
GameClientMgr::Instance()->OnTargetServerConnect(pdelnode->params);
|
||||||
TargetConn* conn = TargetConnMgr::Instance()->GetConnById(pdelnode->params.sender);
|
TargetConn* conn = TargetConnMgr::Instance()->GetConnById(pdelnode->params.sender);
|
||||||
if (conn && conn->Connected()) {
|
if (conn && conn->Connected()) {
|
||||||
conn->SendStockMsg();
|
conn->SendStockMsg();
|
||||||
@ -626,3 +626,4 @@ void App::FreeIMMsgQueue()
|
|||||||
}
|
}
|
||||||
im_msg_mutex_->unlock();
|
im_msg_mutex_->unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,20 +101,20 @@ void MasterSvr::on_socketread(a8::TcpClient* sender, char* buf, unsigned int len
|
|||||||
|
|
||||||
bool warning = false;
|
bool warning = false;
|
||||||
unsigned int offset = 0;
|
unsigned int offset = 0;
|
||||||
while (recv_bufflen_ - offset >= sizeof(f8::WSProxyPackHead_S)) {
|
while (recv_bufflen_ - offset >= sizeof(f8::PackHead)) {
|
||||||
f8::WSProxyPackHead_S* p = (f8::WSProxyPackHead_S*) &recv_buff_[offset];
|
f8::PackHead* p = (f8::PackHead*) &recv_buff_[offset];
|
||||||
if (p->magic_code == f8::MAGIC_CODE) {
|
if (p->magic_code == f8::MAGIC_CODE) {
|
||||||
if (recv_bufflen_ - offset < sizeof(f8::WSProxyPackHead_S) + p->packlen) {
|
if (recv_bufflen_ - offset < sizeof(f8::PackHead) + p->packlen) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
App::Instance()->AddSocketMsg(SF_MasterServer,
|
App::Instance()->AddSocketMsg(SF_MasterServer,
|
||||||
p->socket_handle,
|
0,
|
||||||
instance_id,
|
instance_id,
|
||||||
p->msgid,
|
p->msgid,
|
||||||
p->seqid,
|
p->seqid,
|
||||||
&recv_buff_[offset + sizeof(f8::WSProxyPackHead_S)],
|
&recv_buff_[offset + sizeof(f8::PackHead)],
|
||||||
p->packlen);
|
p->packlen);
|
||||||
offset += sizeof(f8::WSProxyPackHead_S) + p->packlen;
|
offset += sizeof(f8::PackHead) + p->packlen;
|
||||||
} else {
|
} else {
|
||||||
warning = true;
|
warning = true;
|
||||||
offset++;
|
offset++;
|
||||||
|
@ -28,9 +28,7 @@ class MasterSvr
|
|||||||
void SendMsg(T& msg)
|
void SendMsg(T& msg)
|
||||||
{
|
{
|
||||||
static int msgid = f8::Net_GetMessageId(msg);
|
static int msgid = f8::Net_GetMessageId(msg);
|
||||||
#if 0
|
f8::Net_SendMsg(tcp_client_, 0, msgid, msg);
|
||||||
f8::Net_SendProxyCMsg(tcp_client_, msgid, msg);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -42,6 +42,7 @@ void MasterSvrMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_
|
|||||||
{
|
{
|
||||||
f8::MsgHdr* context_hdr = GetHdrByContextId(msg.context_id());
|
f8::MsgHdr* context_hdr = GetHdrByContextId(msg.context_id());
|
||||||
if (context_hdr) {
|
if (context_hdr) {
|
||||||
|
bool auto_free = true;
|
||||||
if (msg.error_code() == 0) {
|
if (msg.error_code() == 0) {
|
||||||
TargetConn* conn = TargetConnMgr::Instance()->RecreateTargetConn(
|
TargetConn* conn = TargetConnMgr::Instance()->RecreateTargetConn(
|
||||||
msg.host(),
|
msg.host(),
|
||||||
@ -49,10 +50,11 @@ void MasterSvrMgr::_SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_
|
|||||||
);
|
);
|
||||||
assert(conn);
|
assert(conn);
|
||||||
if (conn) {
|
if (conn) {
|
||||||
conn->ForwardClientMsg(hdr);
|
auto_free = false;
|
||||||
|
conn->ForwardClientMsgEx(context_hdr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RemoveRequest(context_hdr->socket_handle, msg.context_id());
|
RemoveRequest(context_hdr->socket_handle, msg.context_id(), auto_free);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,11 +66,15 @@ MasterSvr* MasterSvrMgr::GetConnById(int instance_id)
|
|||||||
|
|
||||||
void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id)
|
void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id)
|
||||||
{
|
{
|
||||||
if (GetContextIdBySocket(hdr.socket_handle) == 0) {
|
if (GetContextIdBySocket(hdr.socket_handle) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unsigned int code = a8::openssl::Crc32((unsigned char*)team_id.data(), team_id.size());
|
unsigned int code = a8::openssl::Crc32((unsigned char*)team_id.data(), team_id.size());
|
||||||
|
#if 1
|
||||||
|
MasterSvr* svr = GetConnById(2);
|
||||||
|
#else
|
||||||
MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
MasterSvr* svr = GetConnById(code % mastersvr_hash_.size() + 1);
|
||||||
|
#endif
|
||||||
if (svr) {
|
if (svr) {
|
||||||
++curr_context_id_;
|
++curr_context_id_;
|
||||||
a8::TimerAttacher* timer_attacher = new a8::TimerAttacher();
|
a8::TimerAttacher* timer_attacher = new a8::TimerAttacher();
|
||||||
@ -98,17 +104,19 @@ void MasterSvrMgr::RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id)
|
void MasterSvrMgr::RemoveRequest(int socket_handle, long long context_id, bool auto_free)
|
||||||
{
|
{
|
||||||
if (context_id == GetContextIdBySocket(socket_handle)) {
|
if (context_id == GetContextIdBySocket(socket_handle)) {
|
||||||
f8::MsgHdr* hdr = GetHdrByContextId(context_id);
|
f8::MsgHdr* hdr = GetHdrByContextId(context_id);
|
||||||
if (hdr) {
|
if (hdr) {
|
||||||
a8::TimerAttacher* timer_attacher = (a8::TimerAttacher*)hdr->user_data;
|
a8::TimerAttacher* timer_attacher = (a8::TimerAttacher*)hdr->user_data;
|
||||||
delete timer_attacher;
|
delete timer_attacher;
|
||||||
if (hdr->buf) {
|
if (auto_free) {
|
||||||
free((char*)hdr->buf);
|
if (hdr->buf) {
|
||||||
|
free((char*)hdr->buf);
|
||||||
|
}
|
||||||
|
free(hdr);
|
||||||
}
|
}
|
||||||
free(hdr);
|
|
||||||
pending_request_hash_.erase(context_id);
|
pending_request_hash_.erase(context_id);
|
||||||
}
|
}
|
||||||
pending_socket_hash_.erase(socket_handle);
|
pending_socket_hash_.erase(socket_handle);
|
||||||
|
@ -27,7 +27,7 @@ class MasterSvrMgr : public a8::Singleton<MasterSvrMgr>
|
|||||||
|
|
||||||
void _SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_ResponseTargetServer& msg);
|
void _SS_MS_ResponseTargetServer(f8::MsgHdr& hdr, const ss::SS_MS_ResponseTargetServer& msg);
|
||||||
void RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id);
|
void RequestTargetServer(f8::MsgHdr& hdr, const std::string& team_id);
|
||||||
void RemoveRequest(int socket_handle, long long context_id);
|
void RemoveRequest(int socket_handle, long long context_id, bool auto_free);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long long GetContextIdBySocket(int socket_handle);
|
long long GetContextIdBySocket(int socket_handle);
|
||||||
|
@ -85,8 +85,17 @@ void TargetConn::SendStockMsg()
|
|||||||
TargetConnMsgNode* pdelnode = work_node;
|
TargetConnMsgNode* pdelnode = work_node;
|
||||||
work_node = work_node->next_node;
|
work_node = work_node->next_node;
|
||||||
|
|
||||||
f8::Net_SendProxyCMsg(tcp_client_, pdelnode->socket_handle, pdelnode->msgid, *pdelnode->msg);
|
if (pdelnode->msg) {
|
||||||
delete pdelnode->msg;
|
f8::Net_SendProxyCMsg(tcp_client_, pdelnode->socket_handle, pdelnode->msgid, *pdelnode->msg);
|
||||||
|
delete pdelnode->msg;
|
||||||
|
}
|
||||||
|
if (pdelnode->hdr) {
|
||||||
|
ForwardClientMsg(*pdelnode->hdr);
|
||||||
|
if (pdelnode->hdr->buf) {
|
||||||
|
free((char*)pdelnode->hdr->buf);
|
||||||
|
}
|
||||||
|
free(pdelnode->hdr);
|
||||||
|
}
|
||||||
delete pdelnode;
|
delete pdelnode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,6 +123,22 @@ void TargetConn::ForwardClientMsg(f8::MsgHdr& hdr)
|
|||||||
free(buff);
|
free(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetConn::ForwardClientMsgEx(f8::MsgHdr* hdr)
|
||||||
|
{
|
||||||
|
if (Connected()) {
|
||||||
|
if (top_node_) {
|
||||||
|
SendStockMsg();
|
||||||
|
}
|
||||||
|
ForwardClientMsg(*hdr);
|
||||||
|
if (hdr->buf) {
|
||||||
|
free((char*)hdr->buf);
|
||||||
|
}
|
||||||
|
free(hdr);
|
||||||
|
} else {
|
||||||
|
AddStockMsg(hdr->socket_handle, 0, nullptr, hdr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TargetConn::on_error(a8::TcpClient* sender, int errorId)
|
void TargetConn::on_error(a8::TcpClient* sender, int errorId)
|
||||||
{
|
{
|
||||||
a8::UdpLog::Instance()->Error("TargetConn errorid=%d", {errorId});
|
a8::UdpLog::Instance()->Error("TargetConn errorid=%d", {errorId});
|
||||||
@ -123,7 +148,7 @@ void TargetConn::on_connect(a8::TcpClient* sender)
|
|||||||
{
|
{
|
||||||
recv_bufflen_ = 0;
|
recv_bufflen_ = 0;
|
||||||
a8::UdpLog::Instance()->Info("target server connected", {});
|
a8::UdpLog::Instance()->Info("target server connected", {});
|
||||||
App::Instance()->AddIMMsg(IM_TargetConnDisconnect,
|
App::Instance()->AddIMMsg(IM_TargetConnConnect,
|
||||||
a8::XParams()
|
a8::XParams()
|
||||||
.SetSender(instance_id)
|
.SetSender(instance_id)
|
||||||
);
|
);
|
||||||
@ -204,12 +229,14 @@ void TargetConn::CheckAlive()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetConn::AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg)
|
void TargetConn::AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg,
|
||||||
|
f8::MsgHdr* hdr)
|
||||||
{
|
{
|
||||||
TargetConnMsgNode* node = new TargetConnMsgNode();
|
TargetConnMsgNode* node = new TargetConnMsgNode();
|
||||||
node->socket_handle = socket_handle;
|
node->socket_handle = socket_handle;
|
||||||
node->msgid = msgid;
|
node->msgid = msgid;
|
||||||
node->msg = msg;
|
node->msg = msg;
|
||||||
|
node->hdr = hdr;
|
||||||
if (bot_node_) {
|
if (bot_node_) {
|
||||||
bot_node_->next_node = node;
|
bot_node_->next_node = node;
|
||||||
bot_node_ = node;
|
bot_node_ = node;
|
||||||
|
@ -12,6 +12,7 @@ struct TargetConnMsgNode
|
|||||||
unsigned short socket_handle = 0;
|
unsigned short socket_handle = 0;
|
||||||
int msgid = 0;
|
int msgid = 0;
|
||||||
::google::protobuf::Message* msg = nullptr;
|
::google::protobuf::Message* msg = nullptr;
|
||||||
|
f8::MsgHdr* hdr = nullptr;
|
||||||
|
|
||||||
TargetConnMsgNode* next_node = nullptr;
|
TargetConnMsgNode* next_node = nullptr;
|
||||||
};
|
};
|
||||||
@ -45,12 +46,13 @@ class TargetConn
|
|||||||
} else {
|
} else {
|
||||||
T* new_msg = new T();
|
T* new_msg = new T();
|
||||||
*new_msg = msg;
|
*new_msg = msg;
|
||||||
AddStockMsg(socket_handle, msgid, new_msg);
|
AddStockMsg(socket_handle, msgid, new_msg, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendStockMsg();
|
void SendStockMsg();
|
||||||
void ForwardClientMsg(f8::MsgHdr& hdr);
|
void ForwardClientMsg(f8::MsgHdr& hdr);
|
||||||
|
void ForwardClientMsgEx(f8::MsgHdr* hdr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void on_error(a8::TcpClient* sender, int errorId);
|
void on_error(a8::TcpClient* sender, int errorId);
|
||||||
@ -59,7 +61,8 @@ class TargetConn
|
|||||||
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
void on_socketread(a8::TcpClient* sender, char* buf, unsigned int len);
|
||||||
|
|
||||||
void CheckAlive();
|
void CheckAlive();
|
||||||
void AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg);
|
void AddStockMsg(unsigned short socket_handle, int msgid, ::google::protobuf::Message* msg,
|
||||||
|
f8::MsgHdr* hdr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char *recv_buff_ = nullptr;
|
char *recv_buff_ = nullptr;
|
||||||
|
@ -63,6 +63,7 @@ TargetConn* TargetConnMgr::RecreateTargetConn(const std::string& host, int port)
|
|||||||
std::string remote_ip = host;
|
std::string remote_ip = host;
|
||||||
int remote_port = port;
|
int remote_port = port;
|
||||||
|
|
||||||
|
conn = new TargetConn();
|
||||||
conn->Init(instance_id, remote_ip, remote_port);
|
conn->Init(instance_id, remote_ip, remote_port);
|
||||||
id_hash_[conn->instance_id] = conn;
|
id_hash_[conn->instance_id] = conn;
|
||||||
key_hash_[key] = conn;
|
key_hash_[key] = conn;
|
||||||
|
2
third_party/a8engine
vendored
2
third_party/a8engine
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 3e1f116639d40a78e5ef625009685a611c5bf7bc
|
Subproject commit f9222e376f8a678a252932c4a3fb93860d7625f2
|
2
third_party/framework
vendored
2
third_party/framework
vendored
@ -1 +1 @@
|
|||||||
Subproject commit ca38a14dc4384b5654d21261130dc1bf75c8d5a8
|
Subproject commit 628e40d32269414703ba6a74b534593611aa5be8
|
Loading…
x
Reference in New Issue
Block a user