1
This commit is contained in:
parent
70e076631c
commit
571a29eebb
@ -90,8 +90,20 @@ void KcpSession::UpdateInput()
|
|||||||
|
|
||||||
void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
|
void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
|
||||||
{
|
{
|
||||||
//packagelen + msgid + magiccode + msgbody
|
if (GetSecretKeyPlace()) {
|
||||||
//2 + 2 + 4+ xx + \0 + xx
|
DecodeUserPacketNew(buf, offset, buflen);
|
||||||
|
} else {
|
||||||
|
DecodeUserPacketOld(buf, offset, buflen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int KcpSession::GetSecretKeyPlace()
|
||||||
|
{
|
||||||
|
return secret_key_place_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void KcpSession::DecodeUserPacketOld(char* buf, int& offset, unsigned int buflen)
|
||||||
|
{
|
||||||
bool warning = false;
|
bool warning = false;
|
||||||
while (buflen - offset >= sizeof(f8::PackHead) + GetSecretKeyLen()) {
|
while (buflen - offset >= sizeof(f8::PackHead) + GetSecretKeyLen()) {
|
||||||
long long secret_key = KcpSession::ReadSecretKey(&buf[offset], buflen);
|
long long secret_key = KcpSession::ReadSecretKey(&buf[offset], buflen);
|
||||||
@ -123,11 +135,37 @@ void KcpSession::DecodeUserPacket(char* buf, int& offset, unsigned int buflen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (warning) {
|
if (warning) {
|
||||||
f8::UdpLog::Instance()->Warning("收到kcp client非法数据包", {});
|
f8::UdpLog::Instance()->Warning("收到kcp client非法数据包1", {});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int KcpSession::GetSecretKeyPlace()
|
void KcpSession::DecodeUserPacketNew(char* buf, int& offset, unsigned int buflen)
|
||||||
{
|
{
|
||||||
return secret_key_place_;
|
bool warning = false;
|
||||||
|
while (buflen - offset >= sizeof(f8::PackHead)) {
|
||||||
|
f8::PackHead* p = (f8::PackHead*)&buf[offset];
|
||||||
|
if (p->magic_code == f8::MAGIC_CODE) {
|
||||||
|
if (buflen - offset < sizeof(f8::PackHead) + p->packlen) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
App::Instance()->AddSocketMsg(SF_Client,
|
||||||
|
socket_handle_,
|
||||||
|
0,
|
||||||
|
//saddr,
|
||||||
|
p->msgid,
|
||||||
|
p->seqid,
|
||||||
|
&buf[offset + sizeof(f8::PackHead)],
|
||||||
|
p->packlen,
|
||||||
|
ST_Udp);
|
||||||
|
offset += sizeof(f8::PackHead) + p->packlen;
|
||||||
|
} else {
|
||||||
|
warning = true;
|
||||||
|
offset++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warning) {
|
||||||
|
f8::UdpLog::Instance()->Warning("收到kcp client非法数据包2", {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override;
|
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override;
|
||||||
|
void DecodeUserPacketOld(char* buf, int& offset, unsigned int buflen);
|
||||||
|
void DecodeUserPacketNew(char* buf, int& offset, unsigned int buflen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateInput();
|
void UpdateInput();
|
||||||
|
@ -133,30 +133,31 @@ void LongSessionMgr::ProcUdpPacket(a8::UdpPacket* pkt)
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
session->GetKcpSession()->OnRecvPacket(pkt);
|
if (session->GetSecretKeyPlace()) {
|
||||||
#if 0
|
if (pkt->buf_len > IKCP_OVERHEAD + KcpSession::GetSecretKeyLen()) {
|
||||||
if (pkt->buf_len > IKCP_OVERHEAD + KcpSession::GetSecretKeyLen()) {
|
long long secret_key = KcpSession::ReadSecretKey(pkt->buf + IKCP_OVERHEAD, pkt->buf_len);
|
||||||
long long secret_key = KcpSession::ReadSecretKey(pkt->buf + IKCP_OVERHEAD, pkt->buf_len);
|
if (secret_key == session->GetKcpSession()->GetSecretKey()) {
|
||||||
if (secret_key == session->GetKcpSession()->GetSecretKey()) {
|
session->GetKcpSession()->OnRecvPacket(pkt);
|
||||||
session->GetKcpSession()->OnRecvPacket(pkt);
|
} else {
|
||||||
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d socket_handle%d secret_key:%d secret_error",
|
||||||
|
{
|
||||||
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
|
pkt->remote_addr.sin_port,
|
||||||
|
socket_handle,
|
||||||
|
secret_key
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d socket_handle%d secret_key:%d secret_error",
|
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d buflen:%d bufflen_error",
|
||||||
{
|
{
|
||||||
inet_ntoa(pkt->remote_addr.sin_addr),
|
inet_ntoa(pkt->remote_addr.sin_addr),
|
||||||
pkt->remote_addr.sin_port,
|
pkt->remote_addr.sin_port,
|
||||||
socket_handle,
|
pkt->buf_len
|
||||||
secret_key
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
f8::UdpLog::Instance()->Warning("ProcUdpPacket host:%s port:%d buflen:%d bufflen_error",
|
session->GetKcpSession()->OnRecvPacket(pkt);
|
||||||
{
|
|
||||||
inet_ntoa(pkt->remote_addr.sin_addr),
|
|
||||||
pkt->remote_addr.sin_port,
|
|
||||||
pkt->buf_len
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LongSessionMgr::DelSession(int socket_handle)
|
void LongSessionMgr::DelSession(int socket_handle)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user