1
This commit is contained in:
parent
a480c642bf
commit
00f7a3663b
@ -22,6 +22,12 @@ public:
|
|||||||
void SendClientMsg(char* buf, int buf_len);
|
void SendClientMsg(char* buf, int buf_len);
|
||||||
virtual void OnRecvPacket(a8::UdpPacket* pkt) override;
|
virtual void OnRecvPacket(a8::UdpPacket* pkt) override;
|
||||||
|
|
||||||
|
static int GetSecretKeyLen() { return sizeof(long long) / 4; }
|
||||||
|
static long long ReadSecretKey(const char* buf, int buf_len)
|
||||||
|
{
|
||||||
|
return buf_len < GetSecretKeyLen() ? 0 : *((long long*)buf);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override;
|
virtual void DecodeUserPacket(char* buf, int& offset, unsigned int buflen) override;
|
||||||
|
|
||||||
|
@ -81,12 +81,15 @@ std::shared_ptr<LongSession> LongSessionMgr::GetSession(int socket_handle)
|
|||||||
|
|
||||||
void LongSessionMgr::ProcUdpPacket(a8::UdpPacket* pkt)
|
void LongSessionMgr::ProcUdpPacket(a8::UdpPacket* pkt)
|
||||||
{
|
{
|
||||||
int socket_handle = 0;
|
const int IKCP_OVERHEAD = 24;
|
||||||
long long secret_key = 0;
|
if (pkt->buf_len > IKCP_OVERHEAD + KcpSession::GetSecretKeyLen()) {
|
||||||
|
int socket_handle = ikcp_getconv(pkt->buf);
|
||||||
|
long long secret_key = KcpSession::ReadSecretKey(pkt->buf, pkt->buf_len);
|
||||||
auto session = GetSession(socket_handle);
|
auto session = GetSession(socket_handle);
|
||||||
if (session && secret_key == session->GetKcpSession()->GetSecretKey()) {
|
if (session && secret_key == session->GetKcpSession()->GetSecretKey()) {
|
||||||
session->GetKcpSession()->OnRecvPacket(pkt);
|
session->GetKcpSession()->OnRecvPacket(pkt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LongSessionMgr::DelSession(int socket_handle)
|
void LongSessionMgr::DelSession(int socket_handle)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user