Changes to allow regex bans. Might need updating of pro-files due to boost::regex dependency.
This commit is contained in:
@@ -257,6 +257,20 @@ ServerLobbyThread::KickPlayerByName(const std::string &playerName)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::BanPlayerRegex(const std::string &playerRegex)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
||||
m_banPlayerNameList.push_back(boost::regex(playerRegex));
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::ClearBanList()
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
||||
m_banPlayerNameList.clear();
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode)
|
||||
{
|
||||
@@ -511,6 +525,13 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const NetPacketIn
|
||||
return;
|
||||
}
|
||||
|
||||
// Check whether the player name is banned.
|
||||
if (IsPlayerBanned(initData.playerName))
|
||||
{
|
||||
SessionError(session, ERR_NET_PLAYER_BANNED);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create player data object.
|
||||
boost::shared_ptr<PlayerData> tmpPlayerData(
|
||||
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL));
|
||||
@@ -1344,7 +1365,7 @@ ServerLobbyThread::GetGui()
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::IsPlayerConnected(const string &name)
|
||||
ServerLobbyThread::IsPlayerConnected(const string &name) const
|
||||
{
|
||||
bool retVal = false;
|
||||
|
||||
@@ -1356,6 +1377,24 @@ ServerLobbyThread::IsPlayerConnected(const string &name)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
bool
|
||||
ServerLobbyThread::IsPlayerBanned(const std::string &name) const
|
||||
{
|
||||
bool retVal = false;
|
||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
||||
RegExList::const_iterator i = m_banPlayerNameList.begin();
|
||||
RegExList::const_iterator end = m_banPlayerNameList.end();
|
||||
while (i != end)
|
||||
{
|
||||
if (regex_match(name, *i))
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||
{
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <deque>
|
||||
#include <list>
|
||||
#include <boost/regex.hpp>
|
||||
#include <third_party/boost/timers.hpp>
|
||||
|
||||
#define NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC 20000
|
||||
@@ -68,6 +69,8 @@ public:
|
||||
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
|
||||
|
||||
bool KickPlayerByName(const std::string &playerName);
|
||||
void BanPlayerRegex(const std::string &playerRegex);
|
||||
void ClearBanList();
|
||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||
|
||||
void SendGlobalChat(const std::string &message);
|
||||
@@ -156,7 +159,8 @@ protected:
|
||||
ServerSenderCallback &GetSenderCallback();
|
||||
GuiInterface &GetGui();
|
||||
|
||||
bool IsPlayerConnected(const std::string &name);
|
||||
bool IsPlayerConnected(const std::string &name) const;
|
||||
bool IsPlayerBanned(const std::string &name) const;
|
||||
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode);
|
||||
@@ -187,6 +191,9 @@ private:
|
||||
SessionIdList m_resubscribeList;
|
||||
mutable boost::mutex m_resubscribeListMutex;
|
||||
|
||||
RegExList m_banPlayerNameList;
|
||||
mutable boost::mutex m_banPlayerNameListMutex;
|
||||
|
||||
GameMap m_gameMap;
|
||||
|
||||
boost::shared_ptr<SenderInterface> m_sender;
|
||||
|
||||
Reference in New Issue
Block a user