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,30 @@
|
||||
#ifndef _GM_NETWORK_CREATE_POLICY_
|
||||
#define _GM_NETWORK_CREATE_POLICY_
|
||||
|
||||
#include <Network/Session/SessionPolicy.h>
|
||||
#include <Network/Winsock/SocketFactory.h>
|
||||
#include <Network/Dispatch/Dispatch.h>
|
||||
#include <Network/Dispatch/PoolDispatchFactory.h>
|
||||
#include <Network/IOCP/Overlapped.h>
|
||||
#include <Stream/Buffer/BufferFactory.h>
|
||||
|
||||
|
||||
namespace SessionPolicy
|
||||
{
|
||||
template<typename DispatchType>
|
||||
CSessionPolicy* CreateTCPPolicy()
|
||||
{
|
||||
return CSessionPolicy::Create<CTCPFactory, CPoolBufferFactory,
|
||||
CPoolDispatchFactory<DispatchType>, CStreamOverlappedFactory>();
|
||||
}
|
||||
|
||||
template<typename DispatchType>
|
||||
CSessionPolicy* CreateUDPPolicy()
|
||||
{
|
||||
return CSessionPolicy::Create<CUDPFactory, CPoolBufferFactory,
|
||||
CPoolDispatchFactory<DispatchType>, CDatagramOverlappedFactory>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,140 @@
|
||||
#include "stdafx.h"
|
||||
#include "LimitUserByIP.h"
|
||||
|
||||
|
||||
|
||||
CLimitUserByIP::CLimitUserByIP(const char* szFileName)
|
||||
: m_eAllowMode(ALLOW_ALL)
|
||||
{
|
||||
if(0 != szFileName && LoadAllowIPList(szFileName))
|
||||
{
|
||||
m_eAllowMode = ALLOW_SOME;
|
||||
}
|
||||
}
|
||||
|
||||
CLimitUserByIP::~CLimitUserByIP()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::operator () (INET_Addr& localAddr, INET_Addr& remoteAddr)
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
|
||||
switch(m_eAllowMode)
|
||||
{
|
||||
case ALLOW_ALL: return true;
|
||||
case DENY_ALL: return false;
|
||||
case ALLOW_SOME:
|
||||
|
||||
return std::binary_search(m_AllowIPList.begin(), m_AllowIPList.end(),
|
||||
remoteAddr.get_addr_in().sin_addr.s_addr);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::LoadAllowIPList(const char* szFileName)
|
||||
{
|
||||
FILE* lpFile = fopen(szFileName, "rt");
|
||||
|
||||
if(0 != lpFile)
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
|
||||
m_AllowIPList.clear();
|
||||
m_AllowIPList.reserve(256);
|
||||
|
||||
const int MAX_BUFFER = 512;
|
||||
char szBuffer[MAX_BUFFER];
|
||||
|
||||
while(fgets(szBuffer, MAX_BUFFER - 1, lpFile))
|
||||
{
|
||||
szBuffer[MAX_BUFFER - 1] = 0;
|
||||
|
||||
unsigned long dwAddr = inet_addr(szBuffer);
|
||||
if(0 != dwAddr)
|
||||
{
|
||||
m_AllowIPList.push_back(dwAddr);
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(m_AllowIPList.begin(), m_AllowIPList.end());
|
||||
|
||||
fclose(lpFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CLimitUserByIP::OperateMode(AllowMode_t eAllowMode)
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
m_eAllowMode = eAllowMode;
|
||||
}
|
||||
|
||||
CLimitUserByIP::AllowMode_t CLimitUserByIP::OperateMode()
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
return m_eAllowMode;
|
||||
}
|
||||
|
||||
void CLimitUserByIP::ClearIPList()
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
m_AllowIPList.clear();
|
||||
}
|
||||
|
||||
|
||||
bool CLimitUserByIP::AddAllowIP(unsigned long dwIP)
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
|
||||
IPList::iterator end = m_AllowIPList.end();
|
||||
IPList::iterator pos = std::lower_bound(m_AllowIPList.begin(), end, dwIP);
|
||||
|
||||
if(pos == end || *pos != dwIP)
|
||||
{
|
||||
m_AllowIPList.insert(pos, dwIP);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::AddAllowIP(INET_Addr& address)
|
||||
{
|
||||
return AddAllowIP(address.get_addr_in().sin_addr.S_un.S_addr);
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::AddAllowIP(in_addr addr)
|
||||
{
|
||||
return AddAllowIP(addr.S_un.S_addr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool CLimitUserByIP::RemoveAllowIP(unsigned long dwIP)
|
||||
{
|
||||
LimitLock::Syncronize sync(m_LimitLock);
|
||||
|
||||
IPList::iterator end = m_AllowIPList.end();
|
||||
IPList::iterator pos = std::lower_bound(m_AllowIPList.begin(), end, dwIP);
|
||||
|
||||
if(pos != end && *pos == dwIP)
|
||||
{
|
||||
m_AllowIPList.erase(pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::RemoveAllowIP(INET_Addr& address)
|
||||
{
|
||||
return RemoveAllowIP(address.get_addr_in().sin_addr.S_un.S_addr);
|
||||
}
|
||||
|
||||
bool CLimitUserByIP::RemoveAddAllowIP(in_addr addr)
|
||||
{
|
||||
return RemoveAllowIP(addr.S_un.S_addr);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#ifndef _GM_NETWORK_LIMIT_SESSION_BY_IP_
|
||||
#define _GM_NETWORK_LIMIT_SESSION_BY_IP_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <Thread/Lock.h>
|
||||
#include <Network/Listener/Listener.h>
|
||||
|
||||
class CLimitUserByIP : public CValidateConnection
|
||||
{
|
||||
public:
|
||||
|
||||
enum AllowMode_t
|
||||
{
|
||||
ALLOW_ALL,
|
||||
DENY_ALL,
|
||||
ALLOW_SOME,
|
||||
};
|
||||
|
||||
CLimitUserByIP(const char* szFileName);
|
||||
virtual ~CLimitUserByIP();
|
||||
virtual bool operator () (INET_Addr& localAddr, INET_Addr& remoteAddr);
|
||||
|
||||
bool LoadAllowIPList(const char* szFileName);
|
||||
void ClearIPList();
|
||||
|
||||
void OperateMode(AllowMode_t eAllowMode);
|
||||
AllowMode_t OperateMode();
|
||||
|
||||
void ReserveAllowIP(size_t nAllowIPNum) { m_AllowIPList.reserve(nAllowIPNum); }
|
||||
|
||||
bool AddAllowIP(unsigned long dwIP);
|
||||
bool AddAllowIP(INET_Addr& address);
|
||||
bool AddAllowIP(in_addr addr);
|
||||
|
||||
bool RemoveAllowIP(unsigned long dwIP);
|
||||
bool RemoveAllowIP(INET_Addr& address);
|
||||
bool RemoveAddAllowIP(in_addr addr);
|
||||
|
||||
private:
|
||||
|
||||
typedef CCSLock LimitLock;
|
||||
typedef std::vector<unsigned long> IPList;
|
||||
|
||||
LimitLock m_LimitLock;
|
||||
IPList m_AllowIPList;
|
||||
AllowMode_t m_eAllowMode;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user