Moving server ban code to a separate class, in order to prepare time-limited bans.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <net/serverlobbythread.h>
|
||||
#include <net/servergame.h>
|
||||
#include <net/serverbanmanager.h>
|
||||
#include <net/serverexception.h>
|
||||
#include <net/senderhelper.h>
|
||||
#include <net/sendercallback.h>
|
||||
@@ -89,7 +90,7 @@ private:
|
||||
|
||||
ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager,
|
||||
boost::shared_ptr<boost::asio::io_service> ioService)
|
||||
: m_ioService(ioService), m_curBanId(0), m_gui(gui), m_avatarManager(avatarManager),
|
||||
: m_ioService(ioService), m_gui(gui), m_avatarManager(avatarManager),
|
||||
m_playerConfig(playerConfig), m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
||||
m_statDataChanged(false), m_removeGameTimer(*ioService), m_removePlayerTimer(*ioService),
|
||||
m_sessionTimeoutTimer(*ioService), m_avatarCleanupTimer(*ioService),
|
||||
@@ -99,6 +100,7 @@ ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig
|
||||
m_senderCallback.reset(new ServerSenderCallback(*this));
|
||||
m_sender.reset(new SenderHelper(*m_senderCallback, m_ioService));
|
||||
m_receiver.reset(new ReceiverHelper);
|
||||
m_banManager.reset(new ServerBanManager);
|
||||
}
|
||||
|
||||
ServerLobbyThread::~ServerLobbyThread()
|
||||
@@ -327,75 +329,6 @@ ServerLobbyThread::KickPlayerByName(const std::string &playerName)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::BanPlayerRegex(const string &playerRegex)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
m_banPlayerNameMap[++m_curBanId] = boost::regex(playerRegex, boost::regex_constants::no_except);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::BanIPAddress(const string &ipAddress)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
m_banIPAddressMap[++m_curBanId] = ipAddress;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::UnBan(unsigned banId)
|
||||
{
|
||||
bool retVal = false;
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
RegexMap::iterator posNick = m_banPlayerNameMap.find(banId);
|
||||
if (posNick != m_banPlayerNameMap.end())
|
||||
{
|
||||
m_banPlayerNameMap.erase(posNick);
|
||||
retVal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
IPAddressMap::iterator posIP = m_banIPAddressMap.find(banId);
|
||||
if (posIP != m_banIPAddressMap.end())
|
||||
{
|
||||
m_banIPAddressMap.erase(posIP);
|
||||
retVal = true;
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::GetBanList(list<string> &list) const
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
RegexMap::const_iterator i_nick = m_banPlayerNameMap.begin();
|
||||
RegexMap::const_iterator end_nick = m_banPlayerNameMap.end();
|
||||
while (i_nick != end_nick)
|
||||
{
|
||||
ostringstream banText;
|
||||
banText << (*i_nick).first << ": (nick) - " << (*i_nick).second.str();
|
||||
list.push_back(banText.str());
|
||||
++i_nick;
|
||||
}
|
||||
IPAddressMap::const_iterator i_ip = m_banIPAddressMap.begin();
|
||||
IPAddressMap::const_iterator end_ip = m_banIPAddressMap.end();
|
||||
while (i_ip != end_ip)
|
||||
{
|
||||
ostringstream banText;
|
||||
banText << (*i_ip).first << ": (IP) - " << (*i_ip).second;
|
||||
list.push_back(banText.str());
|
||||
++i_ip;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::ClearBanList()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
m_banPlayerNameMap.clear();
|
||||
m_banIPAddressMap.clear();
|
||||
}
|
||||
|
||||
string
|
||||
ServerLobbyThread::GetPlayerIPAddress(const std::string &playerName) const
|
||||
{
|
||||
@@ -485,6 +418,13 @@ ServerLobbyThread::GetIOService()
|
||||
return *m_ioService;
|
||||
}
|
||||
|
||||
ServerBanManager &
|
||||
ServerLobbyThread::GetBanManager()
|
||||
{
|
||||
assert(m_banManager);
|
||||
return *m_banManager;
|
||||
}
|
||||
|
||||
u_int32_t
|
||||
ServerLobbyThread::GetNextUniquePlayerId()
|
||||
{
|
||||
@@ -733,13 +673,13 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const NetPacketIn
|
||||
}
|
||||
|
||||
// Check whether the player name is banned.
|
||||
if (IsPlayerBanned(initData.playerName))
|
||||
if (GetBanManager().IsPlayerBanned(initData.playerName))
|
||||
{
|
||||
SessionError(session, ERR_NET_PLAYER_BANNED);
|
||||
return;
|
||||
}
|
||||
// Check whether the peer IP address is banned.
|
||||
if (IsIPAddressBanned(session.sessionData->GetClientAddr()))
|
||||
if (GetBanManager().IsIPAddressBanned(session.sessionData->GetClientAddr()))
|
||||
{
|
||||
SessionError(session, ERR_NET_PLAYER_BANNED);
|
||||
return;
|
||||
@@ -1517,46 +1457,6 @@ ServerLobbyThread::IsPlayerConnected(const string &name) const
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::IsPlayerBanned(const std::string &name) const
|
||||
{
|
||||
bool retVal = false;
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
RegexMap::const_iterator i = m_banPlayerNameMap.begin();
|
||||
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
||||
while (i != end)
|
||||
{
|
||||
if (regex_match(name, (*i).second))
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::IsIPAddressBanned(const std::string &ipAddress) const
|
||||
{
|
||||
bool retVal = false;
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
IPAddressMap::const_iterator i = m_banIPAddressMap.begin();
|
||||
IPAddressMap::const_iterator end = m_banIPAddressMap.end();
|
||||
while (i != end)
|
||||
{
|
||||
if (ipAddress == (*i).second)
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
ServerLobbyThread::CreateNetPacketGameListNew(const ServerGame &game)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user