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.2 KiB
C++
92 lines
2.2 KiB
C++
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// NetBase Class
|
|
//
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
#include "NetBase.h"
|
|
|
|
#include <Network/XORCrypt/XORCrypt.h>
|
|
|
|
NetBase::NetBase(void) :
|
|
m_TCPSocket(INVALID_SOCKET), m_UDPSocket(INVALID_SOCKET)
|
|
{
|
|
m_pSendDataBuffer.buf = m_pSendBuffer;
|
|
m_pSendDataBuffer.len = 0;
|
|
|
|
m_pRecvDataBuffer.buf = m_pRecvBuffer;
|
|
m_pRecvDataBuffer.len = 0;
|
|
|
|
m_pRecvUDPDataBuffer.buf = m_pRecvUDPBuffer;
|
|
m_pRecvUDPDataBuffer.len = 0;
|
|
}
|
|
|
|
NetBase::~NetBase(void)
|
|
{
|
|
SAFE_CLOSESOCK(m_TCPSocket);
|
|
SAFE_CLOSESOCK(m_UDPSocket);
|
|
}
|
|
|
|
int NetBase::Recv(void)
|
|
{
|
|
return SocketIO::Recv(m_TCPSocket, m_pRecvDataBuffer);
|
|
}
|
|
|
|
int NetBase::UDPRecv(LPSOCKADDR_IN Address_Out)
|
|
{
|
|
return SocketIO::RecvFrom(m_UDPSocket, m_pRecvUDPDataBuffer, Address_Out);
|
|
}
|
|
|
|
int NetBase::PutRecvBufferToPtBuffer(char *pBuffer_Out, int BufferSize_In)
|
|
{
|
|
return SocketIO::PutRecvBufferToPtBuffer(pBuffer_Out, BufferSize_In, m_pRecvDataBuffer, m_pRecvBuffer, 0, 0);
|
|
}
|
|
|
|
int NetBase::PutUDPRecvBufferToPtBuffer(char *pBuffer_Out, int BufferSize_In)
|
|
{
|
|
return SocketIO::PutRecvBufferToPtBuffer(pBuffer_Out, BufferSize_In, m_pRecvUDPDataBuffer, m_pRecvUDPBuffer, 0, 0);
|
|
}
|
|
|
|
void NetBase::PutSendBuffer(bool Crypt_In)
|
|
{
|
|
CXORCrypt& Crypt = CXORCrypt::GetInstance();
|
|
|
|
DWORD dwCodePage = Crypt.GetCodePage();
|
|
LPPktBase lpBasePt = (LPPktBase)m_pSendDataBuffer.buf;
|
|
int Len = lpBasePt->GetLen();
|
|
|
|
// ÀÎÄÚµù ÆÐŶ
|
|
if(Crypt_In)
|
|
{
|
|
Crypt.EncodePacket(m_pSendDataBuffer.buf + PktBaseSize, Len - PktBaseSize, dwCodePage);
|
|
|
|
lpBasePt->SetCodePage(dwCodePage);
|
|
lpBasePt->SetCrypt();
|
|
}
|
|
|
|
// ÀÎÄÚµù ÇØ´õ
|
|
Crypt.EncodeHeader(m_pSendDataBuffer.buf + 1, PktBaseSize - 1, 0, 0);
|
|
|
|
m_pSendDataBuffer.len += Len;
|
|
m_pSendDataBuffer.buf += Len;
|
|
}
|
|
|
|
bool NetBase::FlushSendBuffer(void)
|
|
{
|
|
WSABUF SendBuf = { m_pSendDataBuffer.len, m_pSendBuffer };
|
|
|
|
CheckServerState();
|
|
|
|
if(m_pSendDataBuffer.len <= 0)
|
|
return true;
|
|
|
|
if(!Send(m_TCPSocket, SendBuf))
|
|
{
|
|
m_pSendDataBuffer.buf = m_pSendBuffer;
|
|
m_pSendDataBuffer.len = 0;
|
|
return false;
|
|
}
|
|
|
|
m_pSendDataBuffer.buf = m_pSendBuffer;
|
|
m_pSendDataBuffer.len = 0;
|
|
return true;
|
|
} |