Files
LGram16 dd97ddec92 Restructure repository to include all source folders
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>
2025-11-29 20:17:20 +09:00

80 lines
1.5 KiB
C++

#ifndef _CPacket
#define _CPacket
#define WIN32_LEAN_AND_MEAN
#include <Winsock2.h>
#include <windows.h>
#include <new>
#include <vector>
#include <Thread/Lock.h>
#include "Socket/SocketIO.h"
class CMemoryPool
{
public:
CMemoryPool(size_t nPerAllocateSize, size_t PerAllocateNum);
~CMemoryPool();
void* Alloc(size_t size);
void Free(void* ptr);
private:
CCSLock m_PoolLock;
CACHE_PAD(PoolLockPadding, sizeof(CCSLock));
size_t m_nPerAllocateSize;
size_t m_nPerAllocateNum;
std::vector<char*> m_Pool;
};
class CPacket
{
protected:
volatile LONG m_nRefCount;
char m_Buffer[BufferSize];
unsigned short m_Len;
bool m_bWrap;
public:
CPacket();
CPacket(unsigned short Len_In, unsigned char Cmd_In, unsigned short State_In, unsigned short Error_In);
CPacket(unsigned short Len_In, unsigned char Cmd_In, unsigned long Tick_In);
~CPacket();
WSABUF GetWSABuf() {
WSABUF WSABuf = { m_Len, m_Buffer };
return WSABuf;
}
char * GetBuf(void) { return m_Buffer; };
inline LONG AddRef() { return InterlockedIncrement(&m_nRefCount); }
inline LONG Release();
bool WrapPacket(bool Crypt_In);
static CMemoryPool ms_PacketPool;
static void* operator new(size_t size) { return ms_PacketPool.Alloc(size); }
static void operator delete(void *ptr) { ms_PacketPool.Free(ptr); }
};
typedef CPacket* LPCPacket;
inline LONG CPacket::Release()
{
LONG nRefCount = InterlockedDecrement(&m_nRefCount);
if(0 == nRefCount)
{
delete this;
}
return nRefCount;
}
#endif