DragonNest/Server/ServiceMonitorEx/Source/NetPacketParser.cpp

84 lines
3.7 KiB
C++
Raw Normal View History

2024-12-20 16:56:44 +08:00
<EFBFBD><EFBFBD>
#include "StdAfx.h"
#include "NetPacketParser.h"
#include <vector>
#include <map>
#define DNPRJSAFE // DNPrjSafe.h <EFBFBD>x<EFBFBD>
#include "CriticalSection.h"
#include "DNPacket.h"
#include "DNServerDef.h"
#include "DNServerPacket.h"
#include "SysBaseBase.h"
CNetPacketParser::CNetPacketParser()
{
m_lpfnPacketNotifyProc = NULL;
}
CNetPacketParser::~CNetPacketParser()
{
}
BOOL CNetPacketParser::PacketParse(class CSessionBase* lpSession, CHAR* lpcBuffer, INT& iBufferPtr, UINT uIoBytes, UINT uTotalBufferSize, LPVOID lpRecvNotifyProcParam, IN_ADDR /*stIpAddress*/, WORD /*wPortNumber*/)
{
CNetPacketParser* lpThis = reinterpret_cast<CNetPacketParser*>(lpRecvNotifyProcParam);
if (uIoBytes < sizeof(DNTPacketHeader))
return TRUE;
// (ӷ<EFBFBD>X<EFBFBD> 0<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD>T<EFBFBD>|<EFBFBD> <EFBFBD>@<EFBFBD> <EFBFBD><EFBFBD><EFBFBD>Є<EFBFBD>
UINT aParseProcessSize = 0;
WHILE_INFINITE
{
SHORT aMainCmd = reinterpret_cast<DNTPacketHeader*>(lpcBuffer + iBufferPtr)->cMainCmd;
SHORT aSubCmd = reinterpret_cast<DNTPacketHeader*>(lpcBuffer + iBufferPtr)->cSubCmd;
SHORT aPacketLen = reinterpret_cast<DNTPacketHeader*>(lpcBuffer + iBufferPtr)->iLen;
if (static_cast<UINT>(aPacketLen) > uTotalBufferSize)
{
iBufferPtr = uIoBytes;
return FALSE;
}
if (static_cast<UINT>(aPacketLen) <= uIoBytes - iBufferPtr)
{
// <EFBFBD><EFBFBD><EFBFBD> (ӷ<EFBFBD>D<EFBFBD> <EFBFBD><EFBFBD> <EFBFBD>L<EFBFBD>
if (lpThis->GetNotifyProc())
{
if (NOERROR != lpThis->GetNotifyProc()(lpSession, aMainCmd, aSubCmd,
reinterpret_cast<LPBYTE>((aPacketLen > sizeof(DNTPacketHeader))?(lpcBuffer + iBufferPtr + sizeof(DNTPacketHeader)):(NULL)),
aPacketLen))
{
iBufferPtr = uIoBytes;
return FALSE;
}
}
iBufferPtr += aPacketLen;
aParseProcessSize += aPacketLen;
}
else
{
break;
}
if (aParseProcessSize >= uIoBytes)
{
// (ӷ<EFBFBD>D<EFBFBD> <EFBFBD><EFBFBD> <EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
break;
}
}
return TRUE;
}