Use human readable ip for ban list
And update MapUserConfigParam to use initializer_list default value
This commit is contained in:
parent
e5c66d541b
commit
52dc38d03b
@ -334,26 +334,12 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||||
const char* comment,
|
const char* comment, std::map<T, U> default_value)
|
||||||
int nb_elements,
|
|
||||||
...)
|
|
||||||
{
|
{
|
||||||
m_param_name = param_name;
|
m_param_name = param_name;
|
||||||
all_params.push_back(this);
|
all_params.push_back(this);
|
||||||
if (comment != NULL) m_comment = comment;
|
if (comment != NULL) m_comment = comment;
|
||||||
|
m_elements = default_value;
|
||||||
// add the default list
|
|
||||||
va_list arguments;
|
|
||||||
va_start(arguments, nb_elements);
|
|
||||||
|
|
||||||
struct pair_type { T key; U value; };
|
|
||||||
|
|
||||||
for (int i = 0; i < nb_elements; i++)
|
|
||||||
{
|
|
||||||
pair_type key_value_pair = va_arg(arguments, pair_type);
|
|
||||||
m_elements.insert(std::pair<T, U>(key_value_pair.key, key_value_pair.value));
|
|
||||||
}
|
|
||||||
va_end(arguments); // Cleans up the list
|
|
||||||
} // MapUserConfigParam
|
} // MapUserConfigParam
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -370,27 +356,14 @@ MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
MapUserConfigParam<T, U>::MapUserConfigParam(const char* param_name,
|
||||||
GroupUserConfigParam* group,
|
GroupUserConfigParam* group, const char* comment,
|
||||||
const char* comment,
|
std::map<T, U> default_value)
|
||||||
int nb_elements,
|
|
||||||
...)
|
|
||||||
{
|
{
|
||||||
m_param_name = param_name;
|
m_param_name = param_name;
|
||||||
group->addChild(this);
|
group->addChild(this);
|
||||||
if (comment != NULL) m_comment = comment;
|
if (comment != NULL) m_comment = comment;
|
||||||
|
|
||||||
// add the default list
|
m_elements = default_value;
|
||||||
va_list arguments;
|
|
||||||
va_start(arguments, nb_elements);
|
|
||||||
|
|
||||||
struct pair_type { T key; U value; };
|
|
||||||
|
|
||||||
for (int i = 0; i < nb_elements; i++)
|
|
||||||
{
|
|
||||||
pair_type key_value_pair = va_arg(arguments, pair_type);
|
|
||||||
m_elements.insert(std::pair<T, U>(key_value_pair.key, key_value_pair.value));
|
|
||||||
}
|
|
||||||
va_end(arguments); // Cleans up the list
|
|
||||||
} // MapUserConfigParam
|
} // MapUserConfigParam
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -146,16 +146,14 @@ public:
|
|||||||
const char* comment = NULL);
|
const char* comment = NULL);
|
||||||
MapUserConfigParam(const char* param_name,
|
MapUserConfigParam(const char* param_name,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int nb_elts,
|
std::map<T, U> default_value);
|
||||||
...);
|
|
||||||
MapUserConfigParam(const char* param_name,
|
MapUserConfigParam(const char* param_name,
|
||||||
GroupUserConfigParam* group,
|
GroupUserConfigParam* group,
|
||||||
const char* comment = NULL);
|
const char* comment = NULL);
|
||||||
MapUserConfigParam(const char* param_name,
|
MapUserConfigParam(const char* param_name,
|
||||||
GroupUserConfigParam* group,
|
GroupUserConfigParam* group,
|
||||||
const char* comment,
|
const char* comment,
|
||||||
int nb_elts,
|
std::map<T, U> default_value);
|
||||||
...);
|
|
||||||
|
|
||||||
void write(std::ofstream& stream) const;
|
void write(std::ofstream& stream) const;
|
||||||
void findYourDataInAChildOf(const XMLNode* node);
|
void findYourDataInAChildOf(const XMLNode* node);
|
||||||
@ -185,6 +183,7 @@ public:
|
|||||||
}
|
}
|
||||||
}; // ListUserConfigParam
|
}; // ListUserConfigParam
|
||||||
typedef MapUserConfigParam<uint32_t, uint32_t> UIntToUIntUserConfigParam;
|
typedef MapUserConfigParam<uint32_t, uint32_t> UIntToUIntUserConfigParam;
|
||||||
|
typedef MapUserConfigParam<std::string, uint32_t> StringToUIntUserConfigParam;
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
class IntUserConfigParam : public UserConfigParam
|
class IntUserConfigParam : public UserConfigParam
|
||||||
{
|
{
|
||||||
@ -735,8 +734,14 @@ namespace UserConfigParams
|
|||||||
PARAM_PREFIX UIntToUIntUserConfigParam m_num_karts_per_gamemode
|
PARAM_PREFIX UIntToUIntUserConfigParam m_num_karts_per_gamemode
|
||||||
PARAM_DEFAULT(UIntToUIntUserConfigParam("num_karts_per_gamemode",
|
PARAM_DEFAULT(UIntToUIntUserConfigParam("num_karts_per_gamemode",
|
||||||
"The Number of karts per gamemode.",
|
"The Number of karts per gamemode.",
|
||||||
1,
|
{
|
||||||
std::make_pair(1100u, 4u)
|
{ 0u, 4u },
|
||||||
|
{ 1002u, 5u },
|
||||||
|
{ 1100u, 4u },
|
||||||
|
{ 1101u, 4u },
|
||||||
|
{ 2000u, 4u },
|
||||||
|
{ 2001u, 4u },
|
||||||
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
// ---- Network
|
// ---- Network
|
||||||
@ -756,12 +761,11 @@ namespace UserConfigParams
|
|||||||
PARAM_DEFAULT(FloatUserConfigParam(10.0f, "voting-timeout",
|
PARAM_DEFAULT(FloatUserConfigParam(10.0f, "voting-timeout",
|
||||||
&m_network_group, "Timeout in seconds for voting tracks in server."));
|
&m_network_group, "Timeout in seconds for voting tracks in server."));
|
||||||
// ---- Gamemode setup
|
// ---- Gamemode setup
|
||||||
PARAM_PREFIX UIntToUIntUserConfigParam m_server_ban_list
|
PARAM_PREFIX StringToUIntUserConfigParam m_server_ban_list
|
||||||
PARAM_DEFAULT(UIntToUIntUserConfigParam("server_ban_list",
|
PARAM_DEFAULT(StringToUIntUserConfigParam("server_ban_list",
|
||||||
"LHS: IP in 32bit format, RHS: online id, if 0 than all players "
|
"LHS: IP in x.x.x.x format, RHS: online id, if 0 than all players "
|
||||||
"from this IP will be banned.",
|
"from this IP will be banned.",
|
||||||
1,
|
{ { "0.0.0.0", 0u } }
|
||||||
std::make_pair(0u, 0u)
|
|
||||||
));
|
));
|
||||||
|
|
||||||
// ---- Graphic Quality
|
// ---- Graphic Quality
|
||||||
@ -769,18 +773,6 @@ namespace UserConfigParams
|
|||||||
PARAM_DEFAULT( GroupUserConfigParam("GFX",
|
PARAM_DEFAULT( GroupUserConfigParam("GFX",
|
||||||
"Graphics Quality Settings") );
|
"Graphics Quality Settings") );
|
||||||
|
|
||||||
// On OSX 10.4 and before there may be driver issues with FBOs, so to be
|
|
||||||
// safe disable them by default
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
|
|
||||||
#define FBO_DEFAULT false
|
|
||||||
#else
|
|
||||||
#define FBO_DEFAULT true
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#define FBO_DEFAULT true
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PARAM_PREFIX IntUserConfigParam m_particles_effects
|
PARAM_PREFIX IntUserConfigParam m_particles_effects
|
||||||
PARAM_DEFAULT( IntUserConfigParam(2, "particles-effecs",
|
PARAM_DEFAULT( IntUserConfigParam(2, "particles-effecs",
|
||||||
&m_graphics_quality, "Particles effects: 0 disabled, 1 only important, 2 enabled") );
|
&m_graphics_quality, "Particles effects: 0 disabled, 1 only important, 2 enabled") );
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "network/network_player_profile.hpp"
|
#include "network/network_player_profile.hpp"
|
||||||
#include "network/stk_host.hpp"
|
#include "network/stk_host.hpp"
|
||||||
#include "network/stk_peer.hpp"
|
#include "network/stk_peer.hpp"
|
||||||
|
#include "network/protocols/server_lobby.hpp"
|
||||||
#include "utils/time.hpp"
|
#include "utils/time.hpp"
|
||||||
#include "utils/vs.hpp"
|
#include "utils/vs.hpp"
|
||||||
#include "main_loop.hpp"
|
#include "main_loop.hpp"
|
||||||
@ -87,7 +88,8 @@ void mainLoop(STKHost* host)
|
|||||||
{
|
{
|
||||||
peer->kick();
|
peer->kick();
|
||||||
UserConfigParams::m_server_ban_list
|
UserConfigParams::m_server_ban_list
|
||||||
[peer->getAddress().getIP()] = 0;
|
[peer->getAddress().toString(false/*show_port*/)] = 0;
|
||||||
|
LobbyProtocol::get<ServerLobby>()->updateBanList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
std::cout << "Unknown host id: " << number << std::endl;
|
std::cout << "Unknown host id: " << number << std::endl;
|
||||||
@ -105,15 +107,13 @@ void mainLoop(STKHost* host)
|
|||||||
}
|
}
|
||||||
else if (str == "listban")
|
else if (str == "listban")
|
||||||
{
|
{
|
||||||
std::map<uint32_t, uint32_t> ban_list =
|
std::map<std::string, uint32_t> ban_list =
|
||||||
UserConfigParams::m_server_ban_list;
|
UserConfigParams::m_server_ban_list;
|
||||||
for (auto& ban : ban_list)
|
for (auto& ban : ban_list)
|
||||||
{
|
{
|
||||||
if (ban.first == 0)
|
if (ban.first == "0.0.0.0")
|
||||||
continue;
|
continue;
|
||||||
TransportAddress a;
|
std::cout << "IP: " << ban.first << " online id: " <<
|
||||||
a.setIP(ban.first);
|
|
||||||
std::cout << "IP: " << a.toString(false) << " online id: " <<
|
|
||||||
ban.second << std::endl;
|
ban.second << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,7 @@ ServerLobby::ServerLobby() : LobbyProtocol(NULL)
|
|||||||
m_has_created_server_id_file = false;
|
m_has_created_server_id_file = false;
|
||||||
setHandleDisconnections(true);
|
setHandleDisconnections(true);
|
||||||
m_state = SET_PUBLIC_ADDRESS;
|
m_state = SET_PUBLIC_ADDRESS;
|
||||||
|
updateBanList();
|
||||||
} // ServerLobby
|
} // ServerLobby
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -821,7 +822,29 @@ void ServerLobby::connectionRequested(Event* event)
|
|||||||
per_player_difficulty));
|
per_player_difficulty));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer->isBanned())
|
bool is_banned = false;
|
||||||
|
auto ret = m_ban_list.find(peer->getAddress().getIP());
|
||||||
|
if (ret != m_ban_list.end())
|
||||||
|
{
|
||||||
|
// Ban all players
|
||||||
|
if (ret->second == 0)
|
||||||
|
{
|
||||||
|
is_banned = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto& p : peer->getPlayerProfiles())
|
||||||
|
{
|
||||||
|
if (ret->second == p->getOnlineId())
|
||||||
|
{
|
||||||
|
is_banned = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_banned)
|
||||||
{
|
{
|
||||||
NetworkString *message = getNetworkString(2);
|
NetworkString *message = getNetworkString(2);
|
||||||
message->addUInt8(LE_CONNECTION_REFUSED).addUInt8(RR_BANNED);
|
message->addUInt8(LE_CONNECTION_REFUSED).addUInt8(RR_BANNED);
|
||||||
@ -1215,3 +1238,12 @@ void ServerLobby::playerFinishedResult(Event *event)
|
|||||||
} // playerFinishedResult
|
} // playerFinishedResult
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
void ServerLobby::updateBanList()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_connection_mutex);
|
||||||
|
m_ban_list.clear();
|
||||||
|
std::map<std::string, uint32_t> ban_list =
|
||||||
|
UserConfigParams::m_server_ban_list;
|
||||||
|
for (auto& ban : ban_list)
|
||||||
|
m_ban_list[TransportAddress(ban.first).getIP()] = ban.second;
|
||||||
|
} // updateBanList
|
||||||
|
@ -75,6 +75,9 @@ private:
|
|||||||
* starting race. */
|
* starting race. */
|
||||||
std::mutex m_connection_mutex;
|
std::mutex m_connection_mutex;
|
||||||
|
|
||||||
|
/** Ban list ip (in decimal) with online user id. */
|
||||||
|
std::map<uint32_t, uint32_t> m_ban_list;
|
||||||
|
|
||||||
// connection management
|
// connection management
|
||||||
void clientDisconnected(Event* event);
|
void clientDisconnected(Event* event);
|
||||||
void connectionRequested(Event* event);
|
void connectionRequested(Event* event);
|
||||||
@ -111,6 +114,7 @@ public:
|
|||||||
void checkRaceFinished();
|
void checkRaceFinished();
|
||||||
void finishedLoadingWorld() OVERRIDE;
|
void finishedLoadingWorld() OVERRIDE;
|
||||||
ServerState getCurrentState() const { return m_state.load(); }
|
ServerState getCurrentState() const { return m_state.load(); }
|
||||||
|
void updateBanList();
|
||||||
virtual bool waitingForPlayers() const OVERRIDE
|
virtual bool waitingForPlayers() const OVERRIDE
|
||||||
{ return m_state.load() == ACCEPTING_CLIENTS; }
|
{ return m_state.load() == ACCEPTING_CLIENTS; }
|
||||||
|
|
||||||
|
@ -121,30 +121,3 @@ bool STKPeer::isSamePeer(const ENetPeer* peer) const
|
|||||||
{
|
{
|
||||||
return peer==m_enet_peer;
|
return peer==m_enet_peer;
|
||||||
} // isSamePeer
|
} // isSamePeer
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
/** Returns true if this peer should be banned.
|
|
||||||
*/
|
|
||||||
bool STKPeer::isBanned() const
|
|
||||||
{
|
|
||||||
if (m_players.empty())
|
|
||||||
{
|
|
||||||
Log::warn("STKPeer", "Missing player info to check for online id ban");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<uint32_t, uint32_t> ban_list =
|
|
||||||
UserConfigParams::m_server_ban_list;
|
|
||||||
auto ret = ban_list.find(m_peer_address.getIP());
|
|
||||||
if (ret != ban_list.end())
|
|
||||||
{
|
|
||||||
// Ban all players
|
|
||||||
if (ret->second == 0)
|
|
||||||
return true;
|
|
||||||
for (auto p : m_players)
|
|
||||||
{
|
|
||||||
if (ret->second == p->getOnlineId())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
} // isBanned
|
|
||||||
|
@ -96,8 +96,6 @@ public:
|
|||||||
void addPlayer(std::shared_ptr<NetworkPlayerProfile> p)
|
void addPlayer(std::shared_ptr<NetworkPlayerProfile> p)
|
||||||
{ m_players.push_back(p); }
|
{ m_players.push_back(p); }
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
bool isBanned() const;
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
/** Sets the token for this client. */
|
/** Sets the token for this client. */
|
||||||
void setClientServerToken(const uint32_t& token)
|
void setClientServerToken(const uint32_t& token)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user