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>
240 lines
5.6 KiB
C++
240 lines
5.6 KiB
C++
// BillingAsyncSocket.cpp : 구현 파일입니다.
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "BillingTestModule.h"
|
|
#include "BillingAsyncSocket.h"
|
|
#include ".\billingasyncsocket.h"
|
|
|
|
|
|
// CBillingAsyncSocket
|
|
|
|
CBillingAsyncSocket::CBillingAsyncSocket()
|
|
: m_eConnectionMode(ACTIVE_CONNECTION),
|
|
m_nAddressLen(0),
|
|
m_nRefCount(1),
|
|
m_nSendBytesFirstPacket(0),
|
|
m_nBufferUsed(0)
|
|
{
|
|
memset(&m_PeerAddress, 0, sizeof(SOCKADDR));
|
|
}
|
|
|
|
CBillingAsyncSocket::~CBillingAsyncSocket()
|
|
{
|
|
}
|
|
|
|
|
|
// CBillingAsyncSocket 멤버 함수입니다.
|
|
|
|
CBillingAsyncSocket* CBillingAsyncSocket::CreateBillingSocket(int nSocketType, UINT nSocketPort)
|
|
{
|
|
CBillingAsyncSocket* lpSocket = new CBillingAsyncSocket;
|
|
if(0 != lpSocket)
|
|
{
|
|
if(!lpSocket->Create(nSocketPort, nSocketType))
|
|
{
|
|
delete lpSocket;
|
|
lpSocket = 0;
|
|
}
|
|
}
|
|
return lpSocket;
|
|
}
|
|
|
|
void CBillingAsyncSocket::OnAccept(int nErrorCode)
|
|
{
|
|
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
|
|
|
|
if(0 == nErrorCode)
|
|
{
|
|
CBillingAsyncSocket* lpSocket = new CBillingAsyncSocket;
|
|
|
|
if(0 != lpSocket)
|
|
{
|
|
lpSocket->m_nAddressLen = sizeof(SOCKADDR_IN);
|
|
|
|
if(Accept(*lpSocket, &lpSocket->m_PeerAddress, &lpSocket->m_nAddressLen))
|
|
{
|
|
lpSocket->m_eConnectionMode = PASSIVE_CONNECTION;
|
|
theApp.RegisterSocket(*lpSocket);
|
|
|
|
lpSocket->OnReceive(0);
|
|
}
|
|
else
|
|
{
|
|
lpSocket->Release();
|
|
lpSocket = 0;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// TODO : Make log here
|
|
Close();
|
|
}
|
|
|
|
CAsyncSocket::OnAccept(nErrorCode);
|
|
}
|
|
|
|
|
|
void CBillingAsyncSocket::OnReceive(int nErrorCode)
|
|
{
|
|
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
|
|
|
|
if(0 == nErrorCode)
|
|
{
|
|
while(true)
|
|
{
|
|
int nReceived = Receive(m_szRecvBuffer + m_nBufferUsed,
|
|
MAX_RECV_BUFFER - m_nBufferUsed);
|
|
|
|
if(SOCKET_ERROR != nReceived)
|
|
{
|
|
m_nBufferUsed += nReceived;
|
|
|
|
size_t nBufferPos = 0;
|
|
while(sizeof(unsigned short) + nBufferPos <= m_nBufferUsed)
|
|
{
|
|
unsigned short usPacketSize = ntohs(*reinterpret_cast<unsigned short*>(m_szRecvBuffer + nBufferPos))
|
|
+ sizeof(unsigned short) + sizeof(unsigned short) + sizeof(unsigned long);
|
|
|
|
if(m_nBufferUsed < usPacketSize + nBufferPos)
|
|
{
|
|
break;
|
|
}
|
|
|
|
theApp.AddRecvPacket(*this, m_szRecvBuffer, usPacketSize);
|
|
nBufferPos += usPacketSize;
|
|
}
|
|
|
|
if(0 != nBufferPos)
|
|
{
|
|
memmove(m_szRecvBuffer, m_szRecvBuffer + nBufferPos,
|
|
m_nBufferUsed - nBufferPos);
|
|
|
|
m_nBufferUsed -= nBufferPos;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(GetLastError() != WSAEWOULDBLOCK)
|
|
{
|
|
// TODO : Make Log here
|
|
Close();
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// TODO : Make Log here
|
|
Close();
|
|
}
|
|
|
|
CAsyncSocket::OnReceive(nErrorCode);
|
|
}
|
|
|
|
|
|
void CBillingAsyncSocket::OnSend(int nErrorCode)
|
|
{
|
|
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
|
|
|
|
if(0 == nErrorCode || WSAEWOULDBLOCK == nErrorCode)
|
|
{
|
|
SendPacket();
|
|
}
|
|
else
|
|
{
|
|
// TODO : Make Log here
|
|
Close();
|
|
}
|
|
|
|
CAsyncSocket::OnSend(nErrorCode);
|
|
}
|
|
|
|
|
|
void CBillingAsyncSocket::OnClose(int nErrorCode)
|
|
{
|
|
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
|
|
|
|
theApp.RemoveSocket(*this);
|
|
|
|
CAsyncSocket::OnClose(nErrorCode);
|
|
|
|
if(m_eConnectionMode == PASSIVE_CONNECTION)
|
|
{
|
|
// 세션 삭제.
|
|
Release();
|
|
}
|
|
}
|
|
|
|
void CBillingAsyncSocket::OnConnect(int nErrorCode)
|
|
{
|
|
// TODO: 여기에 특수화된 코드를 추가 및/또는 기본 클래스를 호출합니다.
|
|
|
|
m_eConnectionMode = ACTIVE_CONNECTION;
|
|
CAsyncSocket::OnConnect(nErrorCode);
|
|
}
|
|
|
|
LONG CBillingAsyncSocket::AddRef()
|
|
{
|
|
return ++m_nRefCount;
|
|
}
|
|
|
|
LONG CBillingAsyncSocket::Release()
|
|
{
|
|
LONG nRefCount = --m_nRefCount;
|
|
|
|
if(0 == nRefCount)
|
|
{
|
|
delete this;
|
|
}
|
|
|
|
return nRefCount;
|
|
}
|
|
|
|
|
|
void CBillingAsyncSocket::SendPending(const HanUnitedBilling::GLTransStruct& glTransStruct)
|
|
{
|
|
m_SendPacketList.push_back(glTransStruct);
|
|
SendPacket();
|
|
}
|
|
|
|
void CBillingAsyncSocket::SendPacket()
|
|
{
|
|
while(!m_SendPacketList.empty())
|
|
{
|
|
HanUnitedBilling::GLTransStruct& sendTransStruct = m_SendPacketList.front();
|
|
|
|
int nTotalBytes = ntohs(sendTransStruct.DataSize) + sizeof(sendTransStruct.DataSize)
|
|
+ sizeof(sendTransStruct.HeaderMsg) + sizeof(sendTransStruct.SeqID);
|
|
|
|
int nSendLen = Send(
|
|
reinterpret_cast<char*>(&sendTransStruct) + m_nSendBytesFirstPacket,
|
|
nTotalBytes - m_nSendBytesFirstPacket);
|
|
|
|
if(SOCKET_ERROR != nSendLen)
|
|
{
|
|
m_nSendBytesFirstPacket += nSendLen;
|
|
|
|
if(m_nSendBytesFirstPacket == nTotalBytes)
|
|
{
|
|
m_SendPacketList.pop_front();
|
|
m_nSendBytesFirstPacket = 0;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(GetLastError() != WSAEWOULDBLOCK)
|
|
{
|
|
// TODO : Make Log here
|
|
Close();
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
} |