chore: unused ip ban removed
This commit is contained in:
@@ -12,7 +12,6 @@
|
|||||||
#include "item_manager.h"
|
#include "item_manager.h"
|
||||||
#include "p2p.h"
|
#include "p2p.h"
|
||||||
#include "char.h"
|
#include "char.h"
|
||||||
#include "ip_ban.h"
|
|
||||||
#include "war_map.h"
|
#include "war_map.h"
|
||||||
#include "locale_service.h"
|
#include "locale_service.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
@@ -827,8 +826,6 @@ void config_init(const string& st_localeServiceName)
|
|||||||
|
|
||||||
g_bAuthServer = true;
|
g_bAuthServer = true;
|
||||||
|
|
||||||
LoadBanIP("BANIP");
|
|
||||||
|
|
||||||
if (!strcasecmp(szIP, "master"))
|
if (!strcasecmp(szIP, "master"))
|
||||||
fprintf(stdout, "AUTH_SERVER: I am the master\n");
|
fprintf(stdout, "AUTH_SERVER: I am the master\n");
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#include <pcg_random.hpp>
|
#include <pcg_random.hpp>
|
||||||
|
|
||||||
#define SEQUENCE_SEED 0
|
#define SEQUENCE_SEED 0
|
||||||
#define MAX_ALLOW_USER 4096
|
|
||||||
//#define MAX_INPUT_LEN 2048
|
//#define MAX_INPUT_LEN 2048
|
||||||
#define MAX_INPUT_LEN 65536
|
#define MAX_INPUT_LEN 65536
|
||||||
|
|
||||||
|
|||||||
@@ -10,48 +10,9 @@
|
|||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "messenger_manager.h"
|
#include "messenger_manager.h"
|
||||||
#include "p2p.h"
|
#include "p2p.h"
|
||||||
#include "ip_ban.h"
|
|
||||||
#include "dev_log.h"
|
#include "dev_log.h"
|
||||||
#include "ClientPackageCryptInfo.h"
|
#include "ClientPackageCryptInfo.h"
|
||||||
|
|
||||||
struct valid_ip
|
|
||||||
{
|
|
||||||
const char * ip;
|
|
||||||
BYTE network;
|
|
||||||
BYTE mask;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct valid_ip admin_ip[] =
|
|
||||||
{
|
|
||||||
{ "210.123.10", 128, 128 },
|
|
||||||
{ "\n", 0, 0 }
|
|
||||||
};
|
|
||||||
|
|
||||||
int IsValidIP(struct valid_ip* ip_table, const char *host)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
char ip_addr[256];
|
|
||||||
|
|
||||||
for (i = 0; *(ip_table + i)->ip != '\n'; ++i)
|
|
||||||
{
|
|
||||||
j = 255 - (ip_table + i)->mask;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
snprintf(ip_addr, sizeof(ip_addr), "%s.%d", (ip_table + i)->ip, (ip_table + i)->network + j);
|
|
||||||
|
|
||||||
if (!strcmp(ip_addr, host))
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
if (!j)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
while (j--);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
DESC_MANAGER::DESC_MANAGER() : m_bDestroyed(false)
|
DESC_MANAGER::DESC_MANAGER() : m_bDestroyed(false)
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
@@ -158,26 +119,6 @@ LPDESC DESC_MANAGER::AcceptDesc(LPFDWATCH fdw, socket_t s)
|
|||||||
|
|
||||||
strlcpy(host, inet_ntoa(peer.sin_addr), sizeof(host));
|
strlcpy(host, inet_ntoa(peer.sin_addr), sizeof(host));
|
||||||
|
|
||||||
if (g_bAuthServer)
|
|
||||||
{
|
|
||||||
if (IsBanIP(peer.sin_addr))
|
|
||||||
{
|
|
||||||
sys_log(0, "connection from %s was banned.", host);
|
|
||||||
socket_close(desc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsValidIP(admin_ip, host)) // admin_ip 에 등록된 IP 는 최대 사용자 수에 구애받지 않는다.
|
|
||||||
{
|
|
||||||
if (m_iSocketsConnected >= MAX_ALLOW_USER)
|
|
||||||
{
|
|
||||||
sys_err("max connection reached. MAX_ALLOW_USER = %d", MAX_ALLOW_USER);
|
|
||||||
socket_close(desc);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newd = M2_NEW DESC;
|
newd = M2_NEW DESC;
|
||||||
crc_t handshake = CreateHandshake();
|
crc_t handshake = CreateHandshake();
|
||||||
|
|
||||||
|
|||||||
@@ -1,372 +0,0 @@
|
|||||||
//#define __MAIN__
|
|
||||||
#ifdef __MAIN__
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
typedef unsigned char BYTE;
|
|
||||||
typedef unsigned long DWORD;
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include "stdafx.h"
|
|
||||||
#include "ip_ban.h"
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class IP
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IP()
|
|
||||||
: dwStart(0), dwEnd(0), dwMask(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
IP(const IP & r)
|
|
||||||
{
|
|
||||||
dwStart = r.dwStart;
|
|
||||||
dwEnd = r.dwEnd;
|
|
||||||
dwMask = r.dwMask;
|
|
||||||
}
|
|
||||||
|
|
||||||
IP(const char * c_pszStart, const char * c_pszEnd = NULL)
|
|
||||||
{
|
|
||||||
BYTE start[4];
|
|
||||||
BYTE end[4];
|
|
||||||
BYTE mask[4];
|
|
||||||
|
|
||||||
Read(c_pszStart, start);
|
|
||||||
|
|
||||||
if (c_pszEnd && *c_pszEnd)
|
|
||||||
Read(c_pszEnd, end);
|
|
||||||
else
|
|
||||||
memcpy(end, start, sizeof(BYTE) * 4);
|
|
||||||
|
|
||||||
mask[0] = 255 - (start[0] ^ end[0]);
|
|
||||||
mask[1] = 255 - (start[1] ^ end[1]);
|
|
||||||
mask[2] = 255 - (start[2] ^ end[2]);
|
|
||||||
mask[3] = 255 - (start[3] ^ end[3]);
|
|
||||||
|
|
||||||
dwStart = (start[3] << 24) | (start[2] << 16) | (start[1] << 8) | start[0];
|
|
||||||
dwEnd = (end[3] << 24) | (end[2] << 16) | (end[1] << 8) | end[0];
|
|
||||||
dwMask = (mask[3] << 24) | (mask[2] << 16) | (mask[1] << 8) | mask[0];
|
|
||||||
|
|
||||||
Print();
|
|
||||||
}
|
|
||||||
|
|
||||||
IP(struct in_addr in)
|
|
||||||
{
|
|
||||||
dwStart = in.s_addr;
|
|
||||||
dwEnd = dwStart;
|
|
||||||
dwMask = 4294967295UL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsEqual(const IP & r) const
|
|
||||||
{
|
|
||||||
return (dwStart == r.dwStart && dwEnd == r.dwEnd && dwMask == r.dwMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsChildOf(IP & r)
|
|
||||||
{
|
|
||||||
if ((r.dwStart & r.dwMask) != (dwStart & r.dwMask))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
DWORD m = r.dwMask | dwMask;
|
|
||||||
|
|
||||||
return (dwStart & ~m) == (dwStart & ~dwMask) && (dwEnd & ~m) == (dwEnd & ~dwMask);
|
|
||||||
}
|
|
||||||
|
|
||||||
int hash()
|
|
||||||
{
|
|
||||||
return (dwStart & 0x000000FF);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Print()
|
|
||||||
{
|
|
||||||
struct in_addr in_ip, in_mask, in_end;
|
|
||||||
|
|
||||||
in_ip.s_addr = dwStart;
|
|
||||||
in_mask.s_addr = dwMask;
|
|
||||||
in_end.s_addr = dwEnd;
|
|
||||||
|
|
||||||
fprintf(stderr, "\t%s", inet_ntoa(in_ip));
|
|
||||||
fprintf(stderr, "\t%s", inet_ntoa(in_end));
|
|
||||||
fprintf(stderr, "\t%s\tfirst %d\n", inet_ntoa(in_mask), hash());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool Read(const char * s, BYTE * dest)
|
|
||||||
{
|
|
||||||
BYTE bClass = 0;
|
|
||||||
const char * p = s;
|
|
||||||
|
|
||||||
while (bClass < 3)
|
|
||||||
{
|
|
||||||
char szNum[4];
|
|
||||||
char * pDot = const_cast<char*>(strchr(p, '.'));
|
|
||||||
|
|
||||||
if (!pDot)
|
|
||||||
break;
|
|
||||||
|
|
||||||
strlcpy(szNum, p, sizeof(szNum));
|
|
||||||
|
|
||||||
str_to_number(dest[bClass++], szNum);
|
|
||||||
p = pDot + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bClass != 3)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "error reading start %s\n", s);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
str_to_number(dest[bClass], p);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DWORD dwStart;
|
|
||||||
DWORD dwEnd;
|
|
||||||
DWORD dwMask;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::map<int, std::vector<IP> > mapBanIP;
|
|
||||||
|
|
||||||
bool LoadBanIP(const char * filename)
|
|
||||||
{
|
|
||||||
FILE * fp = fopen(filename, "r");
|
|
||||||
|
|
||||||
if (!fp)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char buf[256];
|
|
||||||
char start[256];
|
|
||||||
char end[256];
|
|
||||||
|
|
||||||
fprintf(stderr, "LOADING BANNED IP LIST\n");
|
|
||||||
|
|
||||||
while (fgets(buf, 256, fp))
|
|
||||||
{
|
|
||||||
*strchr(buf, '\n') = '\0';
|
|
||||||
char * p = strchr(buf, '\t');
|
|
||||||
|
|
||||||
if (!p)
|
|
||||||
{
|
|
||||||
strlcpy(start, buf, sizeof(start));
|
|
||||||
*end = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char * p2 = strchr(p + 1, '\t');
|
|
||||||
|
|
||||||
if (p2)
|
|
||||||
*p2 = '\0';
|
|
||||||
|
|
||||||
strlcpy(end, p + 1, sizeof(end));
|
|
||||||
|
|
||||||
*p = '\0';
|
|
||||||
strlcpy(start, buf, sizeof(start));
|
|
||||||
}
|
|
||||||
|
|
||||||
IP ip(start, end);
|
|
||||||
|
|
||||||
itertype(mapBanIP) it = mapBanIP.find(ip.hash());
|
|
||||||
|
|
||||||
if (it == mapBanIP.end())
|
|
||||||
{
|
|
||||||
std::vector<IP> v;
|
|
||||||
v.push_back(ip);
|
|
||||||
mapBanIP.insert(std::map<DWORD, std::vector<IP> >::value_type(ip.hash(), v));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
it->second.push_back(ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsBanIP(struct in_addr in)
|
|
||||||
{
|
|
||||||
IP ip(in);
|
|
||||||
|
|
||||||
itertype(mapBanIP) it = mapBanIP.find(ip.hash());
|
|
||||||
|
|
||||||
if (it == mapBanIP.end())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
itertype(it->second) it2 = it->second.begin();
|
|
||||||
|
|
||||||
while (it2 != it->second.end())
|
|
||||||
if (ip.IsChildOf(*(it2++)))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __MAIN__
|
|
||||||
void UniqueIP(std::vector<IP> & v)
|
|
||||||
{
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
bool found;
|
|
||||||
vector<IP>::iterator it1;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
vector<IP> o;
|
|
||||||
it1 = v.begin();
|
|
||||||
|
|
||||||
while (it1 != v.end())
|
|
||||||
{
|
|
||||||
IP & ip1 = *(it1++);
|
|
||||||
|
|
||||||
found = false;
|
|
||||||
|
|
||||||
if (it1 != v.end())
|
|
||||||
{
|
|
||||||
vector<IP>::iterator it2 = it1;
|
|
||||||
|
|
||||||
while (it2 != v.end())
|
|
||||||
{
|
|
||||||
IP & ip2 = *(it2++);
|
|
||||||
|
|
||||||
if (ip1.IsEqual(ip2))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
o.push_back(ip1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (o.size() == v.size())
|
|
||||||
break;
|
|
||||||
|
|
||||||
v.clear();
|
|
||||||
it1 = o.begin();
|
|
||||||
|
|
||||||
while (it1 != o.end())
|
|
||||||
v.push_back(*(it1++));
|
|
||||||
}
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FilterIP(std::vector<IP> & v)
|
|
||||||
{
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
bool found;
|
|
||||||
vector<IP>::iterator it1;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
vector<IP> o;
|
|
||||||
it1 = v.begin();
|
|
||||||
|
|
||||||
while (it1 != v.end())
|
|
||||||
{
|
|
||||||
IP & ip1 = *(it1++);
|
|
||||||
|
|
||||||
found = false;
|
|
||||||
|
|
||||||
vector<IP>::iterator it2 = v.begin();
|
|
||||||
|
|
||||||
while (it2 != v.end())
|
|
||||||
{
|
|
||||||
IP & ip2 = *(it2++);
|
|
||||||
|
|
||||||
if (ip1.IsEqual(ip2))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ip1.IsChildOf(ip2))
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found)
|
|
||||||
o.push_back(ip1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (o.size() == v.size())
|
|
||||||
break;
|
|
||||||
|
|
||||||
v.clear();
|
|
||||||
it1 = o.begin();
|
|
||||||
|
|
||||||
while (it1 != o.end())
|
|
||||||
v.push_back(*(it1++));
|
|
||||||
}
|
|
||||||
while (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
if (argc != 2)
|
|
||||||
{
|
|
||||||
printf("Syntax: %s <filename>\n", *argv);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
argc--, argv++;
|
|
||||||
|
|
||||||
FILE * fp = fopen(*argv, "r");
|
|
||||||
|
|
||||||
if (!fp)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
vector<IP> v;
|
|
||||||
char buf[256];
|
|
||||||
char start[32];
|
|
||||||
char end[32];
|
|
||||||
|
|
||||||
while (fgets(buf, 256, fp))
|
|
||||||
{
|
|
||||||
*strchr(buf, '\n') = '\0';
|
|
||||||
char * p = strchr(buf, '\t');
|
|
||||||
|
|
||||||
if (!p)
|
|
||||||
{
|
|
||||||
strlcpy(start, buf, sizeof(start));
|
|
||||||
*end = '\0';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strlcpy(end, p + 1, sizeof(end));
|
|
||||||
*p = '\0';
|
|
||||||
strlcpy(start, buf, sizeof(start));
|
|
||||||
}
|
|
||||||
|
|
||||||
v.push_back(IP(start, end));
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
|
||||||
|
|
||||||
printf("size %d\n", v.size());
|
|
||||||
UniqueIP(v);
|
|
||||||
printf("result1 %d\n", v.size());
|
|
||||||
FilterIP(v);
|
|
||||||
printf("result2 %d\n", v.size());
|
|
||||||
|
|
||||||
vector<IP>::iterator it = v.begin();
|
|
||||||
|
|
||||||
while (it != v.end())
|
|
||||||
(*(it++)).Print();
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
#ifndef __INC_METIN_II_GAME_BAN_IP_H__
|
|
||||||
#define __INC_METIN_II_GAME_BAN_IP_H__
|
|
||||||
|
|
||||||
extern bool LoadBanIP(const char * filename);
|
|
||||||
extern bool IsBanIP(struct in_addr in);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user