forked from metin2/server
Removed country blocking (and exceptions)
This commit is contained in:
@ -1,214 +0,0 @@
|
||||
// vim:ts=4 sw=4
|
||||
/*********************************************************************
|
||||
* date : 2007.05.31
|
||||
* file : BlockCountry.cpp
|
||||
* author : mhh
|
||||
* description :
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "BlockCountry.h"
|
||||
|
||||
#include "DBManager.h"
|
||||
|
||||
#define DO_ALL_BLOCK_IP(iter) \
|
||||
for ((iter) = m_block_ip.begin(); (iter) != m_block_ip.end(); ++(iter))
|
||||
|
||||
#define DO_ALL_BLOCK_EXCEPTION(iter) \
|
||||
for ((iter) = m_block_exception.begin(); (iter) != m_block_exception.end(); ++(iter))
|
||||
|
||||
CBlockCountry::CBlockCountry()
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
CBlockCountry::~CBlockCountry()
|
||||
{
|
||||
BLOCK_IP *block_ip;
|
||||
BLOCK_IP_VECTOR::iterator iter;
|
||||
|
||||
DO_ALL_BLOCK_IP(iter)
|
||||
{
|
||||
block_ip = *iter;
|
||||
delete block_ip;
|
||||
}
|
||||
|
||||
m_block_ip.clear();
|
||||
}
|
||||
|
||||
|
||||
bool CBlockCountry::Load()
|
||||
{
|
||||
// load blocked ip
|
||||
{
|
||||
char szQuery[256];
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT IP_FROM, IP_TO, COUNTRY_NAME FROM iptocountry");
|
||||
SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_ACCOUNT);
|
||||
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
SPDLOG_ERROR(" DirectQuery failed({})", szQuery);
|
||||
delete pMsg;
|
||||
return false;
|
||||
}
|
||||
|
||||
MYSQL_ROW row;
|
||||
for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
|
||||
{
|
||||
BLOCK_IP *block_ip = new BLOCK_IP;
|
||||
block_ip->ip_from = strtoul(row[0], NULL, 10);
|
||||
block_ip->ip_to = strtoul(row[1], NULL, 10);
|
||||
strlcpy(block_ip->country, row[2], sizeof(block_ip->country));
|
||||
|
||||
m_block_ip.push_back(block_ip);
|
||||
SPDLOG_DEBUG("BLOCKED_IP : {} - {}", block_ip->ip_from, block_ip->ip_to);
|
||||
|
||||
}
|
||||
delete pMsg;
|
||||
}
|
||||
|
||||
|
||||
// load block exception account
|
||||
{
|
||||
char szQuery[256];
|
||||
snprintf(szQuery, sizeof(szQuery), "SELECT login FROM block_exception");
|
||||
SQLMsg * pMsg = CDBManager::instance().DirectQuery(szQuery, SQL_ACCOUNT);
|
||||
|
||||
if (pMsg->Get()->uiNumRows == 0)
|
||||
{
|
||||
SPDLOG_ERROR(" DirectQuery failed({})", szQuery);
|
||||
delete pMsg;
|
||||
return true;
|
||||
}
|
||||
|
||||
MYSQL_ROW row;
|
||||
for (int n = 0; (row = mysql_fetch_row(pMsg->Get()->pSQLResult)) != NULL; ++n)
|
||||
{
|
||||
const char *login = row[0];
|
||||
|
||||
m_block_exception.push_back(strdup(login));
|
||||
|
||||
SPDLOG_DEBUG("BLOCK_EXCEPTION = {}", login);
|
||||
|
||||
}
|
||||
delete pMsg;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBlockCountry::IsBlockedCountryIp(const char *user_ip)
|
||||
{
|
||||
BLOCK_IP* block_ip;
|
||||
BLOCK_IP_VECTOR::iterator iter;
|
||||
struct in_addr st_addr;
|
||||
|
||||
#ifndef __WIN32__
|
||||
if (0 == inet_aton(user_ip, &st_addr))
|
||||
#else
|
||||
unsigned int in_address;
|
||||
in_address = inet_addr(user_ip);
|
||||
st_addr.s_addr = in_address;
|
||||
if (INADDR_NONE == in_address)
|
||||
#endif
|
||||
return true; // <20><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>ó<EFBFBD><C3B3>
|
||||
|
||||
DO_ALL_BLOCK_IP(iter)
|
||||
{
|
||||
block_ip = *iter;
|
||||
|
||||
if (st_addr.s_addr >= block_ip->ip_from && st_addr.s_addr <= block_ip->ip_to)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CBlockCountry::SendBlockedCountryIp(CPeer *peer)
|
||||
{
|
||||
SPDLOG_DEBUG("SendBlockedCountryIp start");
|
||||
BLOCK_IP *block_ip;
|
||||
BLOCK_IP_VECTOR::iterator iter;
|
||||
TPacketBlockCountryIp packet;
|
||||
|
||||
DO_ALL_BLOCK_IP(iter)
|
||||
{
|
||||
block_ip = *iter;
|
||||
|
||||
packet.ip_from = block_ip->ip_from;
|
||||
packet.ip_to = block_ip->ip_to;
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_BLOCK_COUNTRY_IP, 0, sizeof(TPacketBlockCountryIp));
|
||||
peer->Encode(&packet, sizeof(packet));
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("[DONE] CBlockCountry::SendBlockedCountryIp() : count = {}",
|
||||
m_block_ip.size());
|
||||
SPDLOG_DEBUG("SendBlockedCountryIp end");
|
||||
} /* end of CBlockCountry::SendBlockedCountryIp() */
|
||||
|
||||
|
||||
void CBlockCountry::SendBlockException(CPeer *peer)
|
||||
{
|
||||
BLOCK_EXCEPTION_VECTOR::iterator iter;
|
||||
|
||||
DO_ALL_BLOCK_EXCEPTION(iter)
|
||||
{
|
||||
const char *login = *iter;
|
||||
|
||||
this->SendBlockExceptionOne(peer, login, BLOCK_EXCEPTION_CMD_ADD);
|
||||
}
|
||||
} /* end of CBlockCountry::SendBlockException() */
|
||||
|
||||
void CBlockCountry::SendBlockExceptionOne(CPeer *peer, const char *login, BYTE cmd)
|
||||
{
|
||||
if (NULL == peer || NULL == login)
|
||||
return;
|
||||
|
||||
if (BLOCK_EXCEPTION_CMD_ADD != cmd && BLOCK_EXCEPTION_CMD_DEL != cmd)
|
||||
return;
|
||||
|
||||
TPacketBlockException packet;
|
||||
|
||||
packet.cmd = cmd;
|
||||
strlcpy(packet.login, login, sizeof(packet.login));
|
||||
|
||||
peer->EncodeHeader(HEADER_DG_BLOCK_EXCEPTION, 0, sizeof(TPacketBlockException));
|
||||
peer->Encode(&packet, sizeof(packet));
|
||||
}
|
||||
|
||||
void CBlockCountry::AddBlockException(const char *login)
|
||||
{
|
||||
BLOCK_EXCEPTION_VECTOR::iterator iter;
|
||||
DO_ALL_BLOCK_EXCEPTION(iter)
|
||||
{
|
||||
const char *saved_login = *iter;
|
||||
|
||||
if (!strcmp(saved_login, login))
|
||||
return;
|
||||
}
|
||||
|
||||
m_block_exception.push_back(strdup(login));
|
||||
return;
|
||||
}
|
||||
|
||||
void CBlockCountry::DelBlockException(const char *login)
|
||||
{
|
||||
BLOCK_EXCEPTION_VECTOR::iterator iter;
|
||||
DO_ALL_BLOCK_EXCEPTION(iter)
|
||||
{
|
||||
const char *saved_login = *iter;
|
||||
|
||||
if (!strcmp(saved_login, login))
|
||||
{
|
||||
::free((void*)saved_login);
|
||||
m_block_exception.erase(iter);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
// vim: ts=4 sw=4
|
||||
// Date : 2007.05.31
|
||||
// File : BlockCountry.h
|
||||
// Author : mhh
|
||||
// Description :
|
||||
|
||||
#ifndef __INC_METIN_II_BLOCKCOUNTRY_H__
|
||||
#define __INC_METIN_II_BLOCKCOUNTRY_H__
|
||||
|
||||
#include "Peer.h"
|
||||
|
||||
#define MAX_COUNTRY_NAME_LENGTH 50
|
||||
|
||||
class CBlockCountry : public singleton<CBlockCountry>
|
||||
{
|
||||
private:
|
||||
struct BLOCK_IP
|
||||
{
|
||||
DWORD ip_from;
|
||||
DWORD ip_to;
|
||||
char country[MAX_COUNTRY_NAME_LENGTH + 1];
|
||||
};
|
||||
|
||||
typedef std::vector<BLOCK_IP*> BLOCK_IP_VECTOR;
|
||||
BLOCK_IP_VECTOR m_block_ip;
|
||||
|
||||
typedef std::vector<const char*> BLOCK_EXCEPTION_VECTOR;
|
||||
BLOCK_EXCEPTION_VECTOR m_block_exception;
|
||||
|
||||
public:
|
||||
CBlockCountry();
|
||||
~CBlockCountry();
|
||||
|
||||
public:
|
||||
bool Load();
|
||||
bool IsBlockedCountryIp(const char *user_ip);
|
||||
void SendBlockedCountryIp(CPeer *peer);
|
||||
void SendBlockException(CPeer *peer);
|
||||
void SendBlockExceptionOne(CPeer *peer, const char *login, BYTE cmd);
|
||||
void AddBlockException(const char *login);
|
||||
void DelBlockException(const char *login);
|
||||
};
|
||||
|
||||
#endif
|
@ -17,7 +17,6 @@
|
||||
#include "ItemAwardManager.h"
|
||||
#include "Marriage.h"
|
||||
#include "Monarch.h"
|
||||
#include "BlockCountry.h"
|
||||
#include "ItemIDRangeManager.h"
|
||||
#include "Cache.h"
|
||||
#ifdef __AUCTION__
|
||||
@ -2672,17 +2671,6 @@ void CClientManager::ProcessPackets(CPeer * peer)
|
||||
ChangeMonarchLord(peer, dwHandle, (TPacketChangeMonarchLord*)data);
|
||||
break;
|
||||
|
||||
case HEADER_GD_BLOCK_COUNTRY_IP:
|
||||
SPDLOG_DEBUG("HEADER_GD_BLOCK_COUNTRY_IP received");
|
||||
CBlockCountry::instance().SendBlockedCountryIp(peer);
|
||||
CBlockCountry::instance().SendBlockException(peer);
|
||||
break;
|
||||
|
||||
case HEADER_GD_BLOCK_EXCEPTION:
|
||||
SPDLOG_DEBUG("HEADER_GD_BLOCK_EXCEPTION received");
|
||||
BlockException((TPacketBlockException*) data);
|
||||
break;
|
||||
|
||||
case HEADER_GD_REQ_SPARE_ITEM_ID_RANGE :
|
||||
SendSpareItemIDRange(peer);
|
||||
break;
|
||||
@ -4190,43 +4178,6 @@ void CClientManager::ChangeMonarchLord(CPeer * peer, DWORD dwHandle, TPacketChan
|
||||
delete pMsg;
|
||||
}
|
||||
|
||||
void CClientManager::BlockException(TPacketBlockException *data)
|
||||
{
|
||||
SPDLOG_DEBUG("[BLOCK_EXCEPTION] CMD({}) login({})", data->cmd, data->login);
|
||||
|
||||
// save sql
|
||||
{
|
||||
char buf[1024];
|
||||
|
||||
switch (data->cmd)
|
||||
{
|
||||
case BLOCK_EXCEPTION_CMD_ADD:
|
||||
snprintf(buf, sizeof(buf), "INSERT INTO block_exception VALUES('%s')", data->login);
|
||||
CDBManager::instance().AsyncQuery(buf, SQL_ACCOUNT);
|
||||
CBlockCountry::instance().AddBlockException(data->login);
|
||||
break;
|
||||
case BLOCK_EXCEPTION_CMD_DEL:
|
||||
snprintf(buf, sizeof(buf), "DELETE FROM block_exception VALUES('%s')", data->login);
|
||||
CDBManager::instance().AsyncQuery(buf, SQL_ACCOUNT);
|
||||
CBlockCountry::instance().DelBlockException(data->login);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (itertype(m_peerList) it = m_peerList.begin(); it != m_peerList.end(); ++it)
|
||||
{
|
||||
CPeer *peer = *it;
|
||||
|
||||
if (!peer->GetChannel())
|
||||
continue;
|
||||
|
||||
CBlockCountry::instance().SendBlockExceptionOne(peer, data->login, data->cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void CClientManager::SendSpareItemIDRange(CPeer* peer)
|
||||
{
|
||||
peer->SendSpareItemIDRange();
|
||||
|
@ -545,7 +545,6 @@ class CClientManager : public singleton<CClientManager>
|
||||
//END_MONARCH
|
||||
|
||||
void ChangeMonarchLord(CPeer* peer, DWORD dwHandle, TPacketChangeMonarchLord* info);
|
||||
void BlockException(TPacketBlockException *data);
|
||||
|
||||
void SendSpareItemIDRange(CPeer* peer);
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "MoneyLog.h"
|
||||
#include "Marriage.h"
|
||||
#include "Monarch.h"
|
||||
#include "BlockCountry.h"
|
||||
#include "ItemIDRangeManager.h"
|
||||
#include <version.h>
|
||||
#ifdef __AUCTION__
|
||||
@ -74,7 +73,6 @@ int main()
|
||||
ItemAwardManager ItemAwardManager;
|
||||
marriage::CManager MarriageManager;
|
||||
CMonarch Monarch;
|
||||
CBlockCountry BlockCountry;
|
||||
CItemIDRangeManager ItemIDRangeManager;
|
||||
#ifdef __AUCTION__
|
||||
AuctionManager auctionManager;
|
||||
@ -84,7 +82,6 @@ int main()
|
||||
|
||||
GuildManager.Initialize();
|
||||
MarriageManager.Initialize();
|
||||
BlockCountry.Load();
|
||||
ItemIDRangeManager.Build();
|
||||
#ifdef __AUCTION__
|
||||
AuctionManager::instance().Initialize();
|
||||
|
Reference in New Issue
Block a user