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>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#include "stdafx.h"
|
||||
#include "Dispatch.h"
|
||||
|
||||
#include "../Session/Session.h"
|
||||
#include "../../Stream/Buffer/Buffer.h"
|
||||
#include "../../Stream/Buffer/BufferFactory.h"
|
||||
|
||||
#include "PoolDispatchFactory.h"
|
||||
|
||||
#include "../../Log/ServerLog.h"
|
||||
|
||||
void CEchoDispatch::Connected()
|
||||
{
|
||||
DETLOG1(g_Log, "this:0x%p Connected", this);
|
||||
}
|
||||
|
||||
void CEchoDispatch::Disconnected()
|
||||
{
|
||||
DETLOG1(g_Log, "this:0x%p Disconnected", this);
|
||||
}
|
||||
|
||||
bool CEchoDispatch::ParsePacket (char* const lpStream_In, unsigned long* dwStreamSIze_InOut)
|
||||
{
|
||||
unsigned long dwReceived = *dwStreamSIze_InOut;
|
||||
|
||||
CBuffer* lpEchoBuffer = CREATE_BUFFER(m_Session.GetPolicy().GetBufferFactory(), dwReceived);
|
||||
memcpy(lpEchoBuffer->wr_ptr(), lpStream_In, dwReceived);
|
||||
lpEchoBuffer->wr_ptr(dwReceived);
|
||||
|
||||
return m_Session.SendPending(lpEchoBuffer);
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
#ifndef _GAMA_SERVER_NETWORK_DISPATCH_H_
|
||||
#define _GAMA_SERVER_NETWORK_DISPATCH_H_
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
class CSession;
|
||||
|
||||
// Session<6F><6E><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> DispatchŬ<68><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̽<EFBFBD>.
|
||||
class CPacketDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
CPacketDispatch(CSession& Session) : m_Session(Session) { }
|
||||
virtual ~CPacketDispatch() { }
|
||||
|
||||
// In : char* const lpStream_In <20><><EFBFBD><EFBFBD> <20><>Ʈ<EFBFBD><C6AE>
|
||||
// unsigned long* dwStreamSize_InOut <20><><EFBFBD><EFBFBD> <20><>Ʈ<EFBFBD><C6AE> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// out : Return <20><>Ŷ <20>Ľ<EFBFBD> <20><><EFBFBD><EFBFBD> / <20><><EFBFBD><EFBFBD>(<28><><EFBFBD>н<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>)
|
||||
// unsigned long* dwStreamSize_InOut <20>Ľ<EFBFBD><C4BD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
virtual bool ParsePacket(char* const lpStream_In, unsigned long* dwStreamSize_InOut) = 0;
|
||||
virtual bool Dispatch() = 0;
|
||||
|
||||
virtual void Connected() { }
|
||||
virtual void Disconnected() { }
|
||||
|
||||
CSession& GetSession() { return m_Session; }
|
||||
|
||||
protected:
|
||||
|
||||
CSession& m_Session;
|
||||
};
|
||||
|
||||
|
||||
class CDispatchFactory
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~CDispatchFactory() = 0;
|
||||
|
||||
virtual CPacketDispatch* CreateDispatch(CSession& Session) = 0;
|
||||
virtual void DeleteDispatch(CPacketDispatch* lpDispatch) = 0;
|
||||
};
|
||||
|
||||
inline CDispatchFactory::~CDispatchFactory() { }
|
||||
|
||||
|
||||
template<typename DispatchType>
|
||||
class CDefaultDispatchFactory : public CDispatchFactory
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~CDefaultDispatchFactory() { }
|
||||
|
||||
virtual CPacketDispatch* CreateDispatch(CSession& Session) { return new DispatchType(Session); }
|
||||
virtual void DeleteDispatch(CPacketDispatch* lpDispatch) { delete lpDispatch; }
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// <20><EFBFBD>Ʈ<EFBFBD><C6AE> Sample Dispatchers....
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><>Ŷ<EFBFBD><C5B6> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʴ´<CAB4>.
|
||||
class CNullDispatch : public CPacketDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
CNullDispatch(CSession& Session) : CPacketDispatch(Session) { }
|
||||
virtual ~CNullDispatch() { }
|
||||
|
||||
virtual bool ParsePacket (char* const lpStream_In, unsigned long* dwStreamSIze_InOut) { return true; }
|
||||
virtual bool Dispatch() { return true; }
|
||||
};
|
||||
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20><>Ŷ<EFBFBD><C5B6> <20>״<EFBFBD><D7B4><EFBFBD> <20>ٽ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ش<EFBFBD>.
|
||||
class CEchoDispatch : public CPacketDispatch
|
||||
{
|
||||
public:
|
||||
|
||||
CEchoDispatch(CSession& Session) : CPacketDispatch(Session) { }
|
||||
virtual ~CEchoDispatch() { }
|
||||
|
||||
virtual void Connected();
|
||||
virtual void Disconnected();
|
||||
|
||||
virtual bool ParsePacket (char* const lpStream_In, unsigned long* dwStreamSIze_InOut);
|
||||
virtual bool Dispatch() { return true; }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef _GAMA_SERVER_NETWORK_POOL_DISPATCH_FACTORY_H_
|
||||
#define _GAMA_SERVER_NETWORK_POOL_DISPATCH_FACTORY_H_
|
||||
|
||||
#include "Dispatch.h"
|
||||
#include <boost/pool/pool.hpp>
|
||||
|
||||
template<typename DispatchType>
|
||||
class CPoolDispatchFactory : public CDispatchFactory
|
||||
{
|
||||
public:
|
||||
|
||||
CPoolDispatchFactory() : m_DispatchPool(sizeof(DispatchType)) { }
|
||||
virtual ~CPoolDispatchFactory() { }
|
||||
|
||||
virtual CPacketDispatch* CreateDispatch(CSession& Session)
|
||||
{
|
||||
void* ptr = m_DispatchPool.malloc();
|
||||
return new (ptr) DispatchType(Session);
|
||||
}
|
||||
|
||||
virtual void DeleteDispatch(CPacketDispatch* lpDispatch)
|
||||
{
|
||||
lpDispatch->~CPacketDispatch();
|
||||
m_DispatchPool.free(lpDispatch);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
typedef boost::pool<> DispatchPool;
|
||||
|
||||
DispatchPool m_DispatchPool;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,272 @@
|
||||
#include "stdafx.h"
|
||||
#include "ServerRequest.h"
|
||||
|
||||
#include <Network/Session/Session.h>
|
||||
#include <Network/Dispatch/Dispatch.h>
|
||||
|
||||
#include <Log/ServerLog.h>
|
||||
|
||||
|
||||
#define REQUEST_LOG(x) x
|
||||
|
||||
|
||||
enum RequestConst
|
||||
{
|
||||
CANNOT_ADD_REQUEST = (1 << 0)
|
||||
};
|
||||
|
||||
|
||||
CServerRequest& CServerRequest::GetInstance()
|
||||
{
|
||||
static CServerRequest serverRequest;
|
||||
return serverRequest;
|
||||
}
|
||||
|
||||
|
||||
CServerRequest::Result::Result(unsigned long dwRequestKey, bool bRemove)
|
||||
: m_bRemove(bRemove)
|
||||
{
|
||||
m_lpSrcDispatch = bRemove
|
||||
// Request<73><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
? CServerRequest::GetInstance().PopRequest(dwRequestKey)
|
||||
|
||||
// Request<73><74> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʴ´<CAB4>.
|
||||
: CServerRequest::GetInstance().GetRequest(dwRequestKey);
|
||||
}
|
||||
|
||||
|
||||
CServerRequest::Result::~Result()
|
||||
{
|
||||
if(0 != m_lpSrcDispatch && m_bRemove)
|
||||
{
|
||||
m_lpSrcDispatch->GetSession().Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CSession* CServerRequest::Result::GetSession()
|
||||
{
|
||||
return (0 != m_lpSrcDispatch) ? &m_lpSrcDispatch->GetSession() : 0;
|
||||
}
|
||||
|
||||
|
||||
void CServerRequest::RequestInfo::ProcessRemove()
|
||||
{
|
||||
if(m_lpSrcDispatch)
|
||||
{
|
||||
if(m_lpTimeoutRequest)
|
||||
{
|
||||
m_lpTimeoutRequest(m_lpSrcDispatch);
|
||||
}
|
||||
|
||||
m_lpSrcDispatch->GetSession().Release();
|
||||
}
|
||||
|
||||
if(m_lpDstDispatch)
|
||||
{
|
||||
m_lpDstDispatch->GetSession().Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// return value : RequestKey
|
||||
unsigned long CServerRequest::AddRequest(CPacketDispatch* lpSrcDispatch,
|
||||
CPacketDispatch* lpDstDispatch,
|
||||
unsigned long dwDurationSec,
|
||||
TimeoutRequest lpTimeoutRequest)
|
||||
{
|
||||
if( 0 != lpSrcDispatch &&
|
||||
0 != lpDstDispatch &&
|
||||
0 != dwDurationSec)
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
if(!(m_dwRequestFlags & CANNOT_ADD_REQUEST))
|
||||
{
|
||||
CSession& SrcSession = lpSrcDispatch->GetSession();
|
||||
CSession& DstSession = lpDstDispatch->GetSession();
|
||||
|
||||
if(0 == m_dwRequestCounter)
|
||||
{
|
||||
++m_dwRequestCounter;
|
||||
}
|
||||
|
||||
unsigned long dwRequestCounter = m_dwRequestCounter++;
|
||||
|
||||
if(m_RequestMap.insert(std::make_pair(dwRequestCounter,
|
||||
RequestInfo(lpSrcDispatch, lpDstDispatch, dwDurationSec, lpTimeoutRequest))).second)
|
||||
{
|
||||
SrcSession.AddRef();
|
||||
DstSession.AddRef();
|
||||
|
||||
REQUEST_LOG(DETLOG5(g_Log, "SS:0x%p/DP:0x%p/IP:%15s/Request:%d/DstDP:0x%p/Request Added",
|
||||
&lpSrcDispatch->GetSession(), lpSrcDispatch,
|
||||
lpSrcDispatch->GetSession().GetRemoteAddr().get_addr_string(),
|
||||
dwRequestCounter, lpDstDispatch));
|
||||
|
||||
return dwRequestCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CServerRequest::RemoveRequest(unsigned long dwRequestKey)
|
||||
{
|
||||
m_RequestLock.Lock();
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.find(dwRequestKey);
|
||||
RequestMap::iterator end = m_RequestMap.end();
|
||||
|
||||
RequestInfo info;
|
||||
|
||||
if(pos != end)
|
||||
{
|
||||
info = pos->second;
|
||||
|
||||
REQUEST_LOG(DETLOG5(g_Log, "SS:0x%p/DP:0x%p/IP:%15s/Request:%d/DstDP:0x%p/Request Removed(By RequestKey)",
|
||||
&info.m_lpSrcDispatch->GetSession(), info.m_lpSrcDispatch,
|
||||
info.m_lpSrcDispatch->GetSession().GetRemoteAddr().get_addr_string(),
|
||||
pos->first, info.m_lpDstDispatch));
|
||||
|
||||
pos = m_RequestMap.erase(pos);
|
||||
}
|
||||
|
||||
m_RequestLock.Unlock();
|
||||
|
||||
info.ProcessRemove();
|
||||
}
|
||||
|
||||
void CServerRequest::RemoveRequest(CPacketDispatch* lpDispatch)
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.begin();
|
||||
RequestMap::iterator end = m_RequestMap.end();
|
||||
|
||||
for(; pos != end;)
|
||||
{
|
||||
RequestInfo& info = pos->second;
|
||||
|
||||
if(lpDispatch == info.m_lpSrcDispatch ||
|
||||
lpDispatch == info.m_lpDstDispatch)
|
||||
{
|
||||
REQUEST_LOG(DETLOG5(g_Log, "SS:0x%p/DP:0x%p/IP:%15s/Request:%d/DstDP:0x%p/Request Removed(By TargetPtr)",
|
||||
&info.m_lpSrcDispatch->GetSession(), info.m_lpSrcDispatch,
|
||||
info.m_lpSrcDispatch->GetSession().GetRemoteAddr().get_addr_string(),
|
||||
pos->first, info.m_lpDstDispatch));
|
||||
|
||||
info.ProcessRemove();
|
||||
pos = m_RequestMap.erase(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CServerRequest::RemoveTimeoutRequest()
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.begin();
|
||||
RequestMap::iterator end = m_RequestMap.end();
|
||||
|
||||
for(; pos != end;)
|
||||
{
|
||||
RequestInfo& info = pos->second;
|
||||
|
||||
if(0 == --(info.m_dwDurationSec))
|
||||
{
|
||||
REQUEST_LOG(DETLOG5(g_Log, "SS:0x%p/DP:0x%p/IP:%15s/Request:%d/DstDP:0x%p/Request Removed(By Timeout)",
|
||||
&info.m_lpSrcDispatch->GetSession(), info.m_lpSrcDispatch,
|
||||
info.m_lpSrcDispatch->GetSession().GetRemoteAddr().get_addr_string(),
|
||||
pos->first, info.m_lpDstDispatch));
|
||||
|
||||
info.ProcessRemove();
|
||||
pos = m_RequestMap.erase(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CServerRequest::RemoveAllRequest()
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.begin();
|
||||
RequestMap::iterator end = m_RequestMap.end();
|
||||
|
||||
for(; pos != end; ++pos)
|
||||
{
|
||||
pos->second.ProcessRemove();
|
||||
}
|
||||
|
||||
m_RequestMap.clear();
|
||||
}
|
||||
|
||||
|
||||
void CServerRequest::RequestOn()
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
m_dwRequestFlags &= ~CANNOT_ADD_REQUEST;
|
||||
}
|
||||
|
||||
void CServerRequest::RequestOff()
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
m_dwRequestFlags |= CANNOT_ADD_REQUEST;
|
||||
}
|
||||
|
||||
|
||||
CServerRequest::CServerRequest()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
CServerRequest::~CServerRequest()
|
||||
{
|
||||
RequestOff();
|
||||
RemoveAllRequest();
|
||||
}
|
||||
|
||||
|
||||
CPacketDispatch* CServerRequest::GetRequest(unsigned long dwRequestKey)
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.find(dwRequestKey);
|
||||
return (pos != m_RequestMap.end()) ? pos->second.m_lpSrcDispatch : 0;
|
||||
}
|
||||
|
||||
|
||||
CPacketDispatch* CServerRequest::PopRequest(unsigned long dwRequestKey)
|
||||
{
|
||||
LockType::Syncronize sync(m_RequestLock);
|
||||
|
||||
RequestMap::iterator pos = m_RequestMap.find(dwRequestKey);
|
||||
|
||||
if(pos != m_RequestMap.end())
|
||||
{
|
||||
RequestInfo info = pos->second;
|
||||
|
||||
REQUEST_LOG(DETLOG5(g_Log, "SS:0x%p/DP:0x%p/IP:%15s/Request:%d/DstDP:0x%p/Request Removed(By Pop Request)",
|
||||
&info.m_lpSrcDispatch->GetSession(), info.m_lpSrcDispatch,
|
||||
info.m_lpSrcDispatch->GetSession().GetRemoteAddr().get_addr_string(),
|
||||
pos->first, info.m_lpDstDispatch));
|
||||
|
||||
m_RequestMap.erase(pos);
|
||||
return info.m_lpSrcDispatch;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
#ifndef _SERVER_REQUEST_H_
|
||||
#define _SERVER_REQUEST_H_
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <Thread/Lock.h>
|
||||
|
||||
class CSession;
|
||||
class CPacketDispatch;
|
||||
|
||||
class CServerRequest
|
||||
{
|
||||
public:
|
||||
|
||||
typedef void (*TimeoutRequest)(CPacketDispatch* lpSrcDispatch);
|
||||
|
||||
static CServerRequest& GetInstance();
|
||||
|
||||
// return value : RequestKey
|
||||
unsigned long AddRequest(CPacketDispatch* lpSrcDispatch, CPacketDispatch* lpDstDispatch,
|
||||
unsigned long dwDurationSec, TimeoutRequest lpTimeoutRequest = 0);
|
||||
|
||||
void RemoveRequest(unsigned long dwRequestKey);
|
||||
void RemoveRequest(CPacketDispatch* lpDispatch);
|
||||
|
||||
void RemoveTimeoutRequest();
|
||||
void RemoveAllRequest();
|
||||
|
||||
void RequestOn();
|
||||
void RequestOff();
|
||||
|
||||
class Result
|
||||
{
|
||||
public:
|
||||
|
||||
explicit Result(unsigned long dwRequestKey, bool bRemove = true);
|
||||
~Result();
|
||||
|
||||
CPacketDispatch* GetDispatch() { return m_lpSrcDispatch; }
|
||||
CSession* GetSession();
|
||||
|
||||
private:
|
||||
|
||||
// new <20><> delete<74><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><>.
|
||||
void* operator new (size_t size);
|
||||
void operator delete (void* ptr);
|
||||
|
||||
CPacketDispatch* m_lpSrcDispatch;
|
||||
bool m_bRemove;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
CServerRequest();
|
||||
~CServerRequest();
|
||||
|
||||
// return value : SrcRequest
|
||||
CPacketDispatch* GetRequest(unsigned long dwRequestKey);
|
||||
CPacketDispatch* PopRequest(unsigned long dwRequestKey);
|
||||
|
||||
struct RequestInfo
|
||||
{
|
||||
CPacketDispatch* m_lpSrcDispatch;
|
||||
CPacketDispatch* m_lpDstDispatch;
|
||||
unsigned long m_dwDurationSec;
|
||||
TimeoutRequest m_lpTimeoutRequest;
|
||||
|
||||
RequestInfo()
|
||||
: m_lpSrcDispatch(0),
|
||||
m_lpDstDispatch(0),
|
||||
m_dwDurationSec(0),
|
||||
m_lpTimeoutRequest(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RequestInfo(CPacketDispatch* lpSrcDispatch, CPacketDispatch* lpDstDispatch,
|
||||
unsigned long dwDurationSec, TimeoutRequest lpTimeoutRequest)
|
||||
: m_lpSrcDispatch(lpSrcDispatch),
|
||||
m_lpDstDispatch(lpDstDispatch),
|
||||
m_dwDurationSec(dwDurationSec),
|
||||
m_lpTimeoutRequest(lpTimeoutRequest)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ProcessRemove();
|
||||
};
|
||||
|
||||
typedef CCSLock LockType;
|
||||
typedef std::map<unsigned long, RequestInfo> RequestMap;
|
||||
|
||||
LockType m_RequestLock;
|
||||
CACHE_PAD(RequestLock, sizeof(LockType));
|
||||
|
||||
RequestMap m_RequestMap;
|
||||
unsigned long m_dwRequestCounter;
|
||||
unsigned long m_dwRequestFlags;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user