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:
40
Server/RylServerProject/BaseLibrary/Pattern/Command.cpp
Normal file
40
Server/RylServerProject/BaseLibrary/Pattern/Command.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "stdafx.h"
|
||||
#include "Command.h"
|
||||
|
||||
|
||||
CCommandProcess::CCommandProcess()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCommandProcess::~CCommandProcess()
|
||||
{
|
||||
ClearAll();
|
||||
}
|
||||
|
||||
|
||||
void CCommandProcess::ProcessAll()
|
||||
{
|
||||
CMDList ProcessList;
|
||||
|
||||
m_CMDLock.Lock();
|
||||
ProcessList.splice(ProcessList.end(), m_CMDList);
|
||||
m_CMDLock.Unlock();
|
||||
|
||||
std::for_each(ProcessList.begin(), ProcessList.end(), std::mem_fun(&CCommand::DoProcess));
|
||||
std::for_each(ProcessList.begin(), ProcessList.end(), std::mem_fun(&CCommand::Destroy));
|
||||
}
|
||||
|
||||
|
||||
void CCommandProcess::ClearAll()
|
||||
{
|
||||
CMDLock::Syncronize sync(m_CMDLock);
|
||||
if(m_CMDList.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::for_each(m_CMDList.begin(), m_CMDList.end(), std::mem_fun(&CCommand::Destroy));
|
||||
m_CMDList.clear();
|
||||
}
|
||||
|
||||
53
Server/RylServerProject/BaseLibrary/Pattern/Command.h
Normal file
53
Server/RylServerProject/BaseLibrary/Pattern/Command.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef _PATTERN_COMMAND_H_
|
||||
#define _PATTERN_COMMAND_H_
|
||||
|
||||
#include <list>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
|
||||
#include "../Thread/Lock.h"
|
||||
|
||||
|
||||
class CCommand
|
||||
{
|
||||
public:
|
||||
|
||||
virtual bool DoProcess() = 0;
|
||||
virtual bool Destroy() = 0; // <20><>ü<EFBFBD><C3BC> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
// stack<63><6B><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> <20>ƹ<EFBFBD> <20>ϵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20>ʰ<EFBFBD>, Heap<61><70><EFBFBD><EFBFBD> <20><>ü<EFBFBD><C3BC> delete this<69><73> <20><> <20><> <20><>.
|
||||
};
|
||||
|
||||
|
||||
class CCommandProcess
|
||||
{
|
||||
public:
|
||||
|
||||
typedef CCSLock CMDLock;
|
||||
typedef std::list<CCommand*> CMDList;
|
||||
|
||||
CCommandProcess();
|
||||
~CCommandProcess();
|
||||
|
||||
inline void Add(CCommand* lpNewCMD);
|
||||
void ProcessAll();
|
||||
|
||||
protected:
|
||||
|
||||
void ClearAll();
|
||||
|
||||
CMDLock m_CMDLock;
|
||||
CMDList m_CMDList;
|
||||
};
|
||||
|
||||
|
||||
inline void CCommandProcess::Add(CCommand* lpNewCMD)
|
||||
{
|
||||
if(NULL != lpNewCMD)
|
||||
{
|
||||
CMDLock::Syncronize sync(m_CMDLock);
|
||||
m_CMDList.push_back(lpNewCMD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
106
Server/RylServerProject/BaseLibrary/Pattern/CommandQueue.cpp
Normal file
106
Server/RylServerProject/BaseLibrary/Pattern/CommandQueue.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "stdafx.h"
|
||||
#include "CommandQueue.h"
|
||||
|
||||
#include "Command.h"
|
||||
#include <Thread/ThreadMgr.h>
|
||||
#include <Log/ServerLog.h>
|
||||
|
||||
CCommandQueueThread::CCommandQueueThread(long nMaxQueueSize)
|
||||
{
|
||||
MsgQueueLock::Syncronize sync(m_Lock);
|
||||
|
||||
m_hHandles[StopperIndex] = CreateEvent(0, TRUE, FALSE, 0);
|
||||
m_hHandles[SemaphoreIndex] = CreateSemaphore(0, 0, nMaxQueueSize, 0);
|
||||
}
|
||||
|
||||
CCommandQueueThread::~CCommandQueueThread()
|
||||
{
|
||||
CThreadMgr::Stop(this);
|
||||
|
||||
MsgQueueLock::Syncronize sync(m_Lock);
|
||||
|
||||
CommandList::iterator pos = m_CommandList.begin();
|
||||
CommandList::iterator end = m_CommandList.end();
|
||||
|
||||
for(;pos != end; ++pos)
|
||||
{
|
||||
(*pos)->Destroy();
|
||||
}
|
||||
|
||||
m_CommandList.clear();
|
||||
|
||||
CloseHandle(m_hHandles[StopperIndex]);
|
||||
CloseHandle(m_hHandles[SemaphoreIndex]);
|
||||
}
|
||||
|
||||
bool CCommandQueueThread::IsValid()
|
||||
{
|
||||
MsgQueueLock::Syncronize sync(m_Lock);
|
||||
|
||||
return INVALID_HANDLE_VALUE != m_hHandles[StopperIndex] &&
|
||||
INVALID_HANDLE_VALUE != m_hHandles[SemaphoreIndex];
|
||||
}
|
||||
|
||||
|
||||
bool CCommandQueueThread::Add(CCommand* lpCommand)
|
||||
{
|
||||
MsgQueueLock::Syncronize sync(m_Lock);
|
||||
|
||||
m_CommandList.push_back(lpCommand);
|
||||
BOOL bResult = ReleaseSemaphore(m_hHandles[SemaphoreIndex], 1, 0);
|
||||
if(!bResult)
|
||||
{
|
||||
m_CommandList.pop_back();
|
||||
}
|
||||
|
||||
return 0 != bResult;
|
||||
}
|
||||
|
||||
unsigned int CCommandQueueThread::Run()
|
||||
{
|
||||
bool bExit = false;
|
||||
|
||||
while(!bExit)
|
||||
{
|
||||
CCommand* lpCommand = 0;
|
||||
|
||||
switch(WaitForMultipleObjects(MaxIndex, m_hHandles, FALSE, INFINITE))
|
||||
{
|
||||
case StopperIndex:
|
||||
bExit = true;
|
||||
break;
|
||||
|
||||
case SemaphoreIndex:
|
||||
{
|
||||
MsgQueueLock::Syncronize sync(m_Lock);
|
||||
|
||||
if(!m_CommandList.empty())
|
||||
{
|
||||
lpCommand = m_CommandList.front();
|
||||
m_CommandList.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
if(0 != lpCommand)
|
||||
{
|
||||
lpCommand->DoProcess();
|
||||
lpCommand->Destroy();
|
||||
lpCommand = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case WAIT_FAILED:
|
||||
|
||||
ERRLOG1(g_Log, "Err:%d/Error from WaitForMultipleObject", GetLastError());
|
||||
bExit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL CCommandQueueThread::End()
|
||||
{
|
||||
return SetEvent(m_hHandles[StopperIndex]);
|
||||
}
|
||||
50
Server/RylServerProject/BaseLibrary/Pattern/CommandQueue.h
Normal file
50
Server/RylServerProject/BaseLibrary/Pattern/CommandQueue.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef _SYNCRONIZED_COMMAND_QUEUE_
|
||||
#define _SYNCRONIZED_COMMAND_QUEUE_
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <Thread/Lock.h>
|
||||
#include <Thread/Thread.h>
|
||||
|
||||
#include <list>
|
||||
|
||||
// forward decl.
|
||||
class CCommand;
|
||||
|
||||
|
||||
// <20><EFBFBD><DEBD><EFBFBD> ť <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
||||
class CCommandQueueThread : public CThread
|
||||
{
|
||||
public:
|
||||
|
||||
CCommandQueueThread(long nMaxQueueSize = LONG_MAX);
|
||||
virtual ~CCommandQueueThread();
|
||||
|
||||
bool Add(CCommand* lpCommand);
|
||||
bool IsValid();
|
||||
|
||||
protected:
|
||||
|
||||
enum Const
|
||||
{
|
||||
StopperIndex,
|
||||
SemaphoreIndex,
|
||||
MaxIndex
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
virtual unsigned int Run();
|
||||
virtual BOOL End();
|
||||
|
||||
typedef CCSLock MsgQueueLock;
|
||||
typedef std::list<CCommand*> CommandList;
|
||||
|
||||
HANDLE m_hHandles[MaxIndex];
|
||||
MsgQueueLock m_Lock;
|
||||
CACHE_PAD(MsgQueueLockPad, sizeof(CCSLock));
|
||||
|
||||
CommandList m_CommandList;
|
||||
};
|
||||
|
||||
#endif
|
||||
124
Server/RylServerProject/BaseLibrary/Pattern/Singleton.h
Normal file
124
Server/RylServerProject/BaseLibrary/Pattern/Singleton.h
Normal file
@@ -0,0 +1,124 @@
|
||||
#ifndef _CSINGLETON_H_
|
||||
#define _CSINGLETON_H_
|
||||
|
||||
#include <cassert>
|
||||
|
||||
template<typename Derived>
|
||||
class CSingleton
|
||||
{
|
||||
private:
|
||||
|
||||
static Derived* ms_pSingleton;
|
||||
|
||||
protected:
|
||||
|
||||
CSingleton();
|
||||
~CSingleton();
|
||||
|
||||
public:
|
||||
|
||||
static Derived& GetInstance();
|
||||
static Derived* GetInstancePtr();
|
||||
};
|
||||
|
||||
|
||||
template<typename Derived>
|
||||
CSingleton<Derived>::CSingleton()
|
||||
{
|
||||
assert(!ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>̹<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ǿ<EFBFBD> <20>ֽ<EFBFBD><D6BD>ϴ<EFBFBD>.");
|
||||
size_t nOffset = (size_t)(Derived*) 1 - (size_t)(CSingleton<Derived>*)(Derived*) 1;
|
||||
ms_pSingleton = (Derived*)((size_t)this + nOffset);
|
||||
}
|
||||
|
||||
|
||||
template<typename Derived>
|
||||
CSingleton<Derived>::~CSingleton()
|
||||
{
|
||||
assert(ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
ms_pSingleton = 0;
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
inline Derived& CSingleton<Derived>::GetInstance()
|
||||
{
|
||||
assert(ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
return (*ms_pSingleton);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
inline Derived* CSingleton<Derived>::GetInstancePtr()
|
||||
{
|
||||
assert(ms_pSingleton && "Singleton Ŭ<><C5AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʾҽ<CABE><D2BD>ϴ<EFBFBD>");
|
||||
return (ms_pSingleton);
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
Derived* CSingleton<Derived>::ms_pSingleton = 0;
|
||||
|
||||
|
||||
|
||||
// Scotte Meyer's Implementation
|
||||
template<typename Derived>
|
||||
class CStaticSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
inline static Derived& GetInstance()
|
||||
{
|
||||
static Derived Instance;
|
||||
return Instance;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Derived>
|
||||
class CLeakStaticSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
inline static Derived& GetInstance()
|
||||
{
|
||||
static Derived* lpInstance = new Derived;
|
||||
return *lpInstance;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
// C++ FAQ's Implementation
|
||||
template<typename T>
|
||||
class CNiftyCounterSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
CNiftyCounterSingleton() { ++nifty_count_; }
|
||||
~CNiftyCounterSingleton() { if ( 0 == --nifty_count_ && pInstance_ ) { delete pInstance_; } }
|
||||
|
||||
static T& GetInstance()
|
||||
{
|
||||
if (NULL == pInstance_) { pInstance_ = new T; }
|
||||
return *pInstance_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static int nifty_count_;
|
||||
static T* pInstance_;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
int CNiftyCounterSingleton<T>::nifty_count_ = 0;
|
||||
|
||||
template<typename T>
|
||||
T* CNiftyCounterSingleton<T>::pInstance_ = 0;
|
||||
|
||||
/*
|
||||
Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>.
|
||||
Ŭ<><C5AC><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20>Ҹ<EFBFBD><D2B8>ڴ<EFBFBD> private<74>̰<EFBFBD>, CNiftyCounterSingleton<6F><6E> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>.
|
||||
|
||||
namespace
|
||||
{
|
||||
CNiftyCounterSingleton<T> TNiftyCounter;
|
||||
}
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user