This commit is contained in:
azw 2023-04-25 03:20:09 +00:00
parent acc4ae8a67
commit 5da25c735d
6 changed files with 32 additions and 14 deletions

View File

@ -37,7 +37,8 @@ public:
p->msgid,
p->seqid,
&buf[offset + sizeof(f8::PackHead)],
p->packlen);
p->packlen,
ST_Tcp);
offset += sizeof(f8::PackHead) + p->packlen;
} else {
warning = true;

View File

@ -40,6 +40,7 @@ struct MsgNode
long ip_saddr;
char* buf;
int buflen;
int tag;
MsgNode* next;
};
@ -227,7 +228,8 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen)
int bodylen,
int tag)
{
MsgNode *p = (MsgNode*)malloc(sizeof(MsgNode));
memset(p, 0, sizeof(MsgNode));
@ -238,6 +240,7 @@ void App::AddSocketMsg(SocketFrom_e sockfrom,
p->seqid = seqid;
p->buf = nullptr;
p->buflen = bodylen;
p->tag = tag;
if (bodylen > 0) {
p->buf = (char*)malloc(bodylen);
memmove(p->buf, msgbody, bodylen);
@ -350,17 +353,17 @@ void App::DispatchMsg()
switch (pdelnode->sockfrom) {
case SF_Client:
{
ProcessClientMsg(hdr);
ProcessClientMsg(hdr, pdelnode->tag);
}
break;
case SF_TargetServer:
{
ProcessTargetServerMsg(hdr);
ProcessTargetServerMsg(hdr, pdelnode->tag);
}
break;
case SF_MasterServer:
{
ProcessMasterServerMsg(hdr);
ProcessMasterServerMsg(hdr, pdelnode->tag);
}
break;
}
@ -379,7 +382,7 @@ void App::DispatchMsg()
}
}
void App::ProcessClientMsg(f8::MsgHdr& hdr)
void App::ProcessClientMsg(f8::MsgHdr& hdr, int tag)
{
if (hdr.msgid == ss::_SS_CMLogin ||
hdr.msgid == ss::_SS_CMReconnect ||
@ -438,14 +441,19 @@ void App::ProcessClientMsg(f8::MsgHdr& hdr)
} else {
auto down_wp = DownStreamMgr::Instance()->GetDownStream(hdr.socket_handle);
if (auto down = down_wp.lock(); !down_wp.expired()) {
if (!down->GetUpStream().expired()) {
bool need_sync_up = true;
#if 0
if (hdr.msgid == ss::_SS_CMPing && down->IsLongSession()) {
}
#endif
if (!down->GetUpStream().expired() && need_sync_up) {
down->GetUpStream().lock()->ForwardClientMsg(hdr);
}
}
}
}
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
void App::ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag)
{
f8::NetMsgHandler* handler = f8::GetNetMsgHandler(&HandlerMgr::Instance()->msmsghandler,
hdr.msgid);
@ -458,7 +466,7 @@ void App::ProcessMasterServerMsg(f8::MsgHdr& hdr)
}
}
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr)
void App::ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag)
{
if (hdr.msgid == ss::_SS_ForceCloseSocket) {
GCListener::Instance()->ForceCloseClient(hdr.socket_handle);

View File

@ -32,7 +32,8 @@ public:
unsigned short msgid,
unsigned int seqid,
const char *msgbody,
int bodylen);
int bodylen,
int tag = ST_Tcp);
void AddUdpMsg(a8::UdpPacket* pkt);
@ -54,9 +55,9 @@ private:
void DispatchMsg();
void DispatchUdpMsg();
void ProcessClientMsg(f8::MsgHdr& hdr);
void ProcessMasterServerMsg(f8::MsgHdr& hdr);
void ProcessTargetServerMsg(f8::MsgHdr& hdr);
void ProcessClientMsg(f8::MsgHdr& hdr, int tag);
void ProcessMasterServerMsg(f8::MsgHdr& hdr, int tag);
void ProcessTargetServerMsg(f8::MsgHdr& hdr, int tag);
void InitLog();
void UnInitLog();

View File

@ -7,6 +7,12 @@ enum SocketFrom_e
SF_MasterServer,
};
enum SocketTag_e
{
ST_Tcp = 1,
ST_Udp,
};
enum InnerMesssage_e
{
IM_ClientSocketDisconnect = 100,

View File

@ -11,6 +11,7 @@ class DownStream
int GetSocketHandle() const { return socket_handle_; }
std::weak_ptr<UpStream> GetUpStream() const { return up_; }
void ReBindUpStream(std::weak_ptr<UpStream> up);
bool IsLongSession() { return is_long_session_; }
void ForwardUpStreamMsg(f8::MsgHdr& hdr);
void OnClose();

View File

@ -99,7 +99,8 @@ void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
p->msgid,
p->seqid,
&buf[offset + sizeof(f8::PackHead) + GetSecretKeyLen()],
p->packlen);
p->packlen,
ST_Udp);
offset += sizeof(f8::PackHead) + p->packlen + GetSecretKeyLen();
} else {
warning = true;