forked from metin2/server
Removed country blocking (and exceptions)
This commit is contained in:
@ -1,150 +0,0 @@
|
||||
/*********************************************************************
|
||||
* date : 2007.05.31
|
||||
* file : block_country.cpp
|
||||
* author : mhh
|
||||
* description :
|
||||
*/
|
||||
|
||||
#define _block_country_cpp_
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "constants.h"
|
||||
#include "block_country.h"
|
||||
|
||||
#define DEC_ITER(iter) std::vector<T_BLOCK_IP*>::iterator iter
|
||||
#define DO_ALL_BLOCKED_IP(iter) for ((iter)=s_blocked_ip.begin(); (iter)!=s_blocked_ip.end(); ++(iter))
|
||||
|
||||
#define DEC_EXCEPTION_ITER(iter) std::set<std::string>::iterator iter
|
||||
|
||||
|
||||
typedef struct {
|
||||
DWORD ip_from;
|
||||
DWORD ip_to;
|
||||
} T_BLOCK_IP;
|
||||
|
||||
//--------------------------------------
|
||||
// static variables
|
||||
std::vector<T_BLOCK_IP*> s_blocked_ip;
|
||||
std::set<std::string> s_block_exception;
|
||||
// static variables
|
||||
//--------------------------------------
|
||||
|
||||
|
||||
|
||||
//--------------------------------------
|
||||
// static functions
|
||||
static void __add_block_exception(const char *login)
|
||||
{
|
||||
SPDLOG_TRACE("BLOCK_EXCEPTION_ADD : {}", login);
|
||||
|
||||
DEC_EXCEPTION_ITER(iter);
|
||||
std::string string_login(login);
|
||||
|
||||
iter = s_block_exception.find(string_login);
|
||||
|
||||
// can not find
|
||||
if (iter==s_block_exception.end())
|
||||
{
|
||||
s_block_exception.insert(string_login);
|
||||
}
|
||||
}
|
||||
|
||||
static void __del_block_exception(const char *login)
|
||||
{
|
||||
SPDLOG_TRACE("BLOCK_EXCEPTION_DEL : {}", login);
|
||||
|
||||
DEC_EXCEPTION_ITER(iter);
|
||||
std::string string_login(login);
|
||||
|
||||
iter = s_block_exception.find(string_login);
|
||||
|
||||
// ok : find
|
||||
if (iter!=s_block_exception.end())
|
||||
{
|
||||
s_block_exception.erase(iter);
|
||||
}
|
||||
}
|
||||
// static functions
|
||||
//--------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
void add_blocked_country_ip(TPacketBlockCountryIp *data)
|
||||
{
|
||||
T_BLOCK_IP *block_ip = M2_NEW T_BLOCK_IP;
|
||||
|
||||
block_ip->ip_from = data->ip_from;
|
||||
block_ip->ip_to = data->ip_to;
|
||||
|
||||
s_blocked_ip.push_back(block_ip);
|
||||
|
||||
SPDLOG_TRACE("BLOCKED_IP = {} - {}", block_ip->ip_from, block_ip->ip_to);
|
||||
}
|
||||
|
||||
|
||||
void block_exception(TPacketBlockException *data)
|
||||
{
|
||||
if (NULL==data) return;
|
||||
|
||||
if (BLOCK_EXCEPTION_CMD_ADD!=data->cmd && BLOCK_EXCEPTION_CMD_DEL!=data->cmd)
|
||||
return;
|
||||
|
||||
|
||||
switch (data->cmd)
|
||||
{
|
||||
case BLOCK_EXCEPTION_CMD_ADD:
|
||||
__add_block_exception(data->login);
|
||||
break;
|
||||
case BLOCK_EXCEPTION_CMD_DEL:
|
||||
__del_block_exception(data->login);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_blocked_country_ip(const char *user_ip)
|
||||
{
|
||||
DEC_ITER(iter);
|
||||
T_BLOCK_IP *block_ip;
|
||||
DWORD ip_number;
|
||||
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
|
||||
{
|
||||
SPDLOG_INFO("BLOCKED_COUNTRY_IP ({}) : YES", user_ip);
|
||||
return true; // <20><><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD> <20>ϴ<EFBFBD> <20><><EFBFBD><EFBFBD>ó<EFBFBD><C3B3>
|
||||
}
|
||||
ip_number = htonl(st_addr.s_addr);
|
||||
|
||||
DO_ALL_BLOCKED_IP(iter)
|
||||
{
|
||||
block_ip = *iter;
|
||||
if ( block_ip->ip_from <= ip_number && ip_number <= block_ip->ip_to )
|
||||
{
|
||||
SPDLOG_INFO("BLOCKED_COUNTRY_IP ({}) : YES", user_ip);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("BLOCKED_COUNTRY_IP ({}) : NO", user_ip);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_block_exception(const char *login)
|
||||
{
|
||||
std::string login_string(login);
|
||||
std::set<std::string>::iterator iter;
|
||||
|
||||
iter = s_block_exception.find(login_string);
|
||||
if (iter != s_block_exception.end())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
/*********************************************************************
|
||||
* date : 2007.05.31
|
||||
* file : block_country.h
|
||||
* author : mhh
|
||||
* description :
|
||||
*/
|
||||
|
||||
#ifndef _block_country_h_
|
||||
#define _block_country_h_
|
||||
|
||||
|
||||
void add_blocked_country_ip(TPacketBlockCountryIp *data);
|
||||
void block_exception(TPacketBlockException *data);
|
||||
bool is_blocked_country_ip(const char *user_ip);
|
||||
bool is_block_exception(const char *login);
|
||||
|
||||
#endif // _block_country_h_
|
||||
|
@ -1198,15 +1198,6 @@ void DBManager::StopAllBilling()
|
||||
}
|
||||
}
|
||||
|
||||
void DBManager::RequestBlockException(const char *login, int cmd)
|
||||
{
|
||||
TPacketBlockException packet;
|
||||
|
||||
packet.cmd = cmd;
|
||||
strlcpy(packet.login, login, sizeof(packet.login));
|
||||
db_clientdesc->DBPacket(HEADER_GD_BLOCK_EXCEPTION, 0, &packet, sizeof(packet));
|
||||
}
|
||||
|
||||
size_t DBManager::EscapeString(char* dst, size_t dstSize, const char *src, size_t srcSize)
|
||||
{
|
||||
return m_sql_direct.EscapeString(dst, dstSize, src, srcSize);
|
||||
|
@ -111,10 +111,6 @@ class DBManager : public singleton<DBManager>
|
||||
DWORD CountQueryResult() { return m_sql.CountResult(); }
|
||||
void ResetQueryResult() { m_sql.ResetQueryFinished(); }
|
||||
|
||||
// BLOCK EXCEPTION
|
||||
void RequestBlockException(const char *login, int cmd);
|
||||
// BLOCK EXCEPTION
|
||||
|
||||
void LoadDBString();
|
||||
const std::string & GetDBString(const std::string& key);
|
||||
const std::vector<std::string> & GetGreetMessage();
|
||||
|
@ -543,20 +543,6 @@ int CInputHandshake::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!stBuf.compare(0, 15, "BLOCK_EXCEPTION"))
|
||||
{
|
||||
// BLOCK_EXCEPTION cmd(add=1, del=2) login
|
||||
std::istringstream is(stBuf);
|
||||
std::string dummy_string;
|
||||
std::string login_string;
|
||||
int cmd;
|
||||
|
||||
is >> dummy_string >> cmd >> login_string;
|
||||
|
||||
SPDLOG_DEBUG("block_exception {}:{}", login_string.c_str(), cmd);
|
||||
DBManager::instance().RequestBlockException(login_string.c_str(), cmd);
|
||||
stResult = "BLOCK_EXCEPTION_YES";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,8 +268,6 @@ protected:
|
||||
|
||||
void ChangeMonarchLord(TPacketChangeMonarchLordACK* data);
|
||||
void UpdateMonarchInfo(TMonarchInfo* data);
|
||||
void AddBlockCountryIp(TPacketBlockCountryIp * data);
|
||||
void BlockException(TPacketBlockException * data);
|
||||
|
||||
// MYSHOP_PRICE_LIST
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ <20><>û<EFBFBD><C3BB> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>Ŷ(HEADER_DG_MYSHOP_PRICELIST_RES) ó<><C3B3><EFBFBD>Լ<EFBFBD>
|
||||
|
@ -32,7 +32,6 @@
|
||||
#include "monarch.h"
|
||||
#include "affect.h"
|
||||
#include "castle.h"
|
||||
#include "block_country.h"
|
||||
#include "motion.h"
|
||||
|
||||
|
||||
@ -1002,12 +1001,6 @@ void CInputDB::Boot(const char* data)
|
||||
|
||||
// castle_boot
|
||||
castle_boot();
|
||||
|
||||
// request blocked_country_ip
|
||||
{
|
||||
db_clientdesc->DBPacket(HEADER_GD_BLOCK_COUNTRY_IP, 0, NULL, 0);
|
||||
SPDLOG_TRACE("<sent HEADER_GD_BLOCK_COUNTRY_IP>");
|
||||
}
|
||||
}
|
||||
|
||||
EVENTINFO(quest_login_event_info)
|
||||
@ -2426,13 +2419,6 @@ int CInputDB::Analyze(LPDESC d, BYTE bHeader, const char * c_pData)
|
||||
UpdateMonarchInfo((TMonarchInfo*)c_pData);
|
||||
break;
|
||||
|
||||
case HEADER_DG_BLOCK_COUNTRY_IP:
|
||||
this->AddBlockCountryIp((TPacketBlockCountryIp *) c_pData);
|
||||
break;
|
||||
case HEADER_DG_BLOCK_EXCEPTION:
|
||||
this->BlockException((TPacketBlockException *) c_pData);
|
||||
break;
|
||||
|
||||
case HEADER_DG_ACK_CHANGE_GUILD_MASTER :
|
||||
this->GuildChangeMaster((TPacketChangeGuildMaster*) c_pData);
|
||||
break;
|
||||
@ -2588,16 +2574,6 @@ void CInputDB::UpdateMonarchInfo(TMonarchInfo* info)
|
||||
SPDLOG_INFO("MONARCH INFO UPDATED");
|
||||
}
|
||||
|
||||
void CInputDB::AddBlockCountryIp(TPacketBlockCountryIp * data)
|
||||
{
|
||||
add_blocked_country_ip(data);
|
||||
}
|
||||
|
||||
void CInputDB::BlockException(TPacketBlockException *data)
|
||||
{
|
||||
block_exception(data);
|
||||
}
|
||||
|
||||
void CInputDB::GuildChangeMaster(TPacketChangeGuildMaster* p)
|
||||
{
|
||||
CGuildManager::instance().ChangeMaster(p->dwGuildID);
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "arena.h"
|
||||
#include "OXEvent.h"
|
||||
#include "priv_manager.h"
|
||||
#include "block_country.h"
|
||||
#include "log.h"
|
||||
#include "horsename_manager.h"
|
||||
#include "MarkManager.h"
|
||||
@ -140,20 +139,6 @@ void CInputLogin::LoginByKey(LPDESC d, const char * data)
|
||||
char login[LOGIN_MAX_LEN + 1];
|
||||
trim_and_lower(pinfo->login, login, sizeof(login));
|
||||
|
||||
// is blocked ip?
|
||||
{
|
||||
SPDLOG_TRACE("check_blocked_country_start");
|
||||
|
||||
if (!is_block_exception(login) && is_blocked_country_ip(d->GetHostName()))
|
||||
{
|
||||
SPDLOG_DEBUG("BLOCK_COUNTRY_IP ({})", d->GetHostName());
|
||||
d->SetPhase(PHASE_CLOSE);
|
||||
return;
|
||||
}
|
||||
|
||||
SPDLOG_TRACE("check_blocked_country_end");
|
||||
}
|
||||
|
||||
if (g_bNoMoreClient)
|
||||
{
|
||||
TPacketGCLoginFailure failurePacket;
|
||||
|
@ -303,7 +303,6 @@ enum
|
||||
HEADER_GG_CHECK_CLIENT_VERSION = 21,
|
||||
HEADER_GG_BLOCK_CHAT = 22,
|
||||
|
||||
HEADER_GG_BLOCK_EXCEPTION = 24,
|
||||
HEADER_GG_SIEGE = 25,
|
||||
HEADER_GG_MONARCH_NOTICE = 26,
|
||||
HEADER_GG_MONARCH_TRANSFER = 27,
|
||||
|
Reference in New Issue
Block a user