Make loginserver intelligently determine if the client is requesting from a RFC 1918 network instead of using a config string match

This commit is contained in:
Akkadius
2019-07-05 03:38:12 -05:00
parent 2c922876a9
commit feea52f79e
8 changed files with 155 additions and 52 deletions
+2
View File
@@ -35,6 +35,7 @@ SET(common_sources
inventory_profile.cpp
inventory_slot.cpp
ipc_mutex.cpp
ip_util.cpp
item_data.cpp
item_instance.cpp
json_config.cpp
@@ -159,6 +160,7 @@ SET(common_headers
inventory_profile.h
inventory_slot.h
ipc_mutex.h
ip_util.h
item_data.h
item_fieldlist.h
item_instance.h
+36 -32
View File
@@ -1,53 +1,57 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2016 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#pragma once
#include <algorithm>
#include <cmath>
namespace EQEmu
{
template <typename T>
T Clamp(const T& value, const T& lower, const T& upper) {
namespace EQEmu {
template<typename T>
T Clamp(const T &value, const T &lower, const T &upper)
{
return std::max(lower, std::min(value, upper));
}
template <typename T>
T ClampLower(const T& value, const T& lower) {
template<typename T>
T ClampLower(const T &value, const T &lower)
{
return std::max(lower, value);
}
template <typename T>
T ClampUpper(const T& value, const T& upper) {
template<typename T>
T ClampUpper(const T &value, const T &upper)
{
return std::min(value, upper);
}
template <typename T>
bool ValueWithin(const T& value, const T& lower, const T& upper) {
template<typename T>
bool ValueWithin(const T &value, const T &lower, const T &upper)
{
return value >= lower && value <= upper;
}
template <typename T1, typename T2, typename T3>
bool ValueWithin(const T1& value, const T2& lower, const T3& upper) {
return value >= (T1)lower && value <= (T1)upper;
template<typename T1, typename T2, typename T3>
bool ValueWithin(const T1 &value, const T2 &lower, const T3 &upper)
{
return value >= (T1) lower && value <= (T1) upper;
}
} /*EQEmu*/
+72
View File
@@ -0,0 +1,72 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "ip_util.h"
/**
* @param ip
* @return
*/
uint32_t IpUtil::IPToUInt(const std::string &ip)
{
int a, b, c, d;
uint32_t addr = 0;
if (sscanf(ip.c_str(), "%d.%d.%d.%d", &a, &b, &c, &d) != 4) {
return 0;
}
addr = a << 24;
addr |= b << 16;
addr |= c << 8;
addr |= d;
return addr;
}
/**
* @param ip
* @param network
* @param mask
* @return
*/
bool IpUtil::IsIpInRange(const std::string &ip, const std::string &network, const std::string &mask)
{
uint32_t ip_addr = IpUtil::IPToUInt(ip);
uint32_t network_addr = IpUtil::IPToUInt(network);
uint32_t mask_addr = IpUtil::IPToUInt(mask);
uint32_t net_lower = (network_addr & mask_addr);
uint32_t net_upper = (net_lower | (~mask_addr));
return ip_addr >= net_lower && ip_addr <= net_upper;
}
/**
* @param ip
* @return
*/
bool IpUtil::IsIpInPrivateRfc1918(const std::string &ip)
{
return (
IpUtil::IsIpInRange(ip, "10.0.0.0", "255.0.0.0") ||
IpUtil::IsIpInRange(ip, "172.16.0.0", "255.240.0.0") ||
IpUtil::IsIpInRange(ip, "192.168.0.0", "255.255.0.0")
);
}
+36
View File
@@ -0,0 +1,36 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_IP_UTIL_H
#define EQEMU_IP_UTIL_H
#include "types.h"
#include "iostream"
class IpUtil {
public:
static uint32_t IPToUInt(const std::string &ip);
static bool IsIpInRange(const std::string &ip, const std::string &network, const std::string &mask);
static bool IsIpInPrivateRfc1918(const std::string &ip);
};
#endif //EQEMU_IP_UTIL_H