Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
#include "stdafx.h"
|
|
|
|
#include "AdminToolDispatch.h"
|
|
|
|
#include < Network/Packet/PacketBase.h >
|
|
#include < Network/Packet/WrapPacket.h >
|
|
#include < Network/XORCrypt/XORCrypt.h >
|
|
|
|
#include < Utility/Compress/MiniLZO/miniLZOWrapper.h >
|
|
#include < Log/ServerLog.h >
|
|
|
|
bool CClientMultiThreadDispatch::ParsePacket( char* const lpStream_In, unsigned long* dwStreamSize_InOut )
|
|
{
|
|
CXORCrypt& Crypt = CXORCrypt::GetInstance();
|
|
|
|
PktBase* lpPktBase = NULL;
|
|
char* lpBufferPos = lpStream_In;
|
|
|
|
unsigned long dwStreamSize = *dwStreamSize_InOut;
|
|
unsigned long dwDecompressedSize = 0;
|
|
char szDecompressedPacket[PktMaxLen] = "";
|
|
|
|
while(dwStreamSize >= sizeof(PktBase))
|
|
{
|
|
lpPktBase = reinterpret_cast<PktBase*>(lpBufferPos);
|
|
|
|
// 패킷 헤더가 vaild한지 확인한다. invalid한 경우는 그냥 끊어버린다.
|
|
if(StartBit != lpPktBase->GetStartBit())
|
|
{
|
|
PktBase::CMDType cCmd = lpPktBase->GetCmd();
|
|
Crypt.DecodeHeader(reinterpret_cast<char*>(&cCmd), 1, 0, 0);
|
|
//LogErrorPacket("패킷 헤더의 시작 비트가 잘못되었습니다.", cCmd);
|
|
return false;
|
|
}
|
|
|
|
// 패킷 헤더 디코딩
|
|
Crypt.DecodeHeader(lpBufferPos + 1, sizeof(PktBase) - 1, 0, 0);
|
|
|
|
// 헤더 길이 얻어 오기.
|
|
const PktBase::CMDType nPacketCMD = lpPktBase->GetCmd();
|
|
const PktBase::LengthType nPacketLength = lpPktBase->GetLen();
|
|
|
|
if(dwStreamSize < nPacketLength)
|
|
{
|
|
// 전체 스트림 사이즈가 파싱을 하기에는 모자람. 다시 인코딩 한 후 다음 턴을 기다림
|
|
Crypt.EncodeHeader(lpBufferPos + 1, sizeof(PktBase) - 1, 0, 0);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
// 패킷 디코딩.
|
|
if(lpPktBase->IsCrypt())
|
|
{
|
|
Crypt.DecodePacket(lpBufferPos + sizeof(PktBase),
|
|
nPacketLength - sizeof(PktBase), lpPktBase->GetCodePage());
|
|
}
|
|
|
|
// 패킷 압축 해제.
|
|
if(lpPktBase->IsCompress())
|
|
{
|
|
// 압축 지원하지 않음..
|
|
// return false;
|
|
dwDecompressedSize = PktMaxLen - sizeof(PktBase);
|
|
memcpy(szDecompressedPacket, lpPktBase, sizeof(PktBase));
|
|
|
|
// 로컬 버퍼에서 압축 해제.
|
|
if(!CMiniLZO::Decompress(lpBufferPos + sizeof(PktBase), nPacketLength - sizeof(PktBase),
|
|
szDecompressedPacket + sizeof(PktBase), &dwDecompressedSize))
|
|
{
|
|
//LogErrorPacket("패킷 압축 해제에 실패했습니다.", nPacketCMD);
|
|
return false;
|
|
}
|
|
|
|
// lpPktBase를 로컬 버퍼로 세팅.
|
|
lpPktBase = reinterpret_cast<PktBase*>(szDecompressedPacket);
|
|
lpPktBase->SetLen(static_cast<PktBase::LengthType>(dwDecompressedSize + sizeof(PktBase)));
|
|
}
|
|
|
|
if(!DispatchPacket(lpPktBase))
|
|
{
|
|
// 패킷 파싱에 실패. 세션을 종료한다.
|
|
return false;
|
|
}
|
|
|
|
dwStreamSize -= nPacketLength;
|
|
lpBufferPos += nPacketLength;
|
|
}
|
|
}
|
|
|
|
*dwStreamSize_InOut -= dwStreamSize;
|
|
return true;
|
|
} |