#include "StdAfx.h" #include "NetPacketParser.h" #include #include #define DNPRJSAFE // DNPrjSafe.h Á¦¿Ü #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(lpRecvNotifyProcParam); if (uIoBytes < sizeof(DNTPacketHeader)) return TRUE; // ÆÐŶÀÇ ±âº» Çì´õ¸¦ ¹ÞÀº »óÅÂÀÓ UINT aParseProcessSize = 0; WHILE_INFINITE { SHORT aMainCmd = reinterpret_cast(lpcBuffer + iBufferPtr)->cMainCmd; SHORT aSubCmd = reinterpret_cast(lpcBuffer + iBufferPtr)->cSubCmd; SHORT aPacketLen = reinterpret_cast(lpcBuffer + iBufferPtr)->iLen; if (static_cast(aPacketLen) > uTotalBufferSize) { iBufferPtr = uIoBytes; return FALSE; } if (static_cast(aPacketLen) <= uIoBytes - iBufferPtr) { // ƯÁ¤ ÆÐŶÀ» ´Ù ¹ÞÀ½ if (lpThis->GetNotifyProc()) { if (NOERROR != lpThis->GetNotifyProc()(lpSession, aMainCmd, aSubCmd, reinterpret_cast((aPacketLen > sizeof(DNTPacketHeader))?(lpcBuffer + iBufferPtr + sizeof(DNTPacketHeader)):(NULL)), aPacketLen)) { iBufferPtr = uIoBytes; return FALSE; } } iBufferPtr += aPacketLen; aParseProcessSize += aPacketLen; } else { break; } if (aParseProcessSize >= uIoBytes) { // ÆÐŶÀ» ´Ù ó¸®Çß´Ù. break; } } return TRUE; }