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;
|
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
|
void
|
||||||
ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode)
|
ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode)
|
||||||
{
|
{
|
||||||
@@ -511,6 +525,13 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const NetPacketIn
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check whether the player name is banned.
|
||||||
|
if (IsPlayerBanned(initData.playerName))
|
||||||
|
{
|
||||||
|
SessionError(session, ERR_NET_PLAYER_BANNED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Create player data object.
|
// Create player data object.
|
||||||
boost::shared_ptr<PlayerData> tmpPlayerData(
|
boost::shared_ptr<PlayerData> tmpPlayerData(
|
||||||
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL));
|
new PlayerData(GetNextUniquePlayerId(), 0, PLAYER_TYPE_HUMAN, PLAYER_RIGHTS_NORMAL));
|
||||||
@@ -1344,7 +1365,7 @@ ServerLobbyThread::GetGui()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ServerLobbyThread::IsPlayerConnected(const string &name)
|
ServerLobbyThread::IsPlayerConnected(const string &name) const
|
||||||
{
|
{
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
|
|
||||||
@@ -1356,6 +1377,24 @@ ServerLobbyThread::IsPlayerConnected(const string &name)
|
|||||||
return retVal;
|
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>
|
boost::shared_ptr<NetPacket>
|
||||||
ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <boost/regex.hpp>
|
||||||
#include <third_party/boost/timers.hpp>
|
#include <third_party/boost/timers.hpp>
|
||||||
|
|
||||||
#define NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC 20000
|
#define NET_LOBBY_THREAD_TERMINATE_TIMEOUT_MSEC 20000
|
||||||
@@ -68,6 +69,8 @@ public:
|
|||||||
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
|
void HandleGameRetrieveAvatar(SessionWrapper session, const NetPacketRetrieveAvatar &tmpPacket);
|
||||||
|
|
||||||
bool KickPlayerByName(const std::string &playerName);
|
bool KickPlayerByName(const std::string &playerName);
|
||||||
|
void BanPlayerRegex(const std::string &playerRegex);
|
||||||
|
void ClearBanList();
|
||||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||||
|
|
||||||
void SendGlobalChat(const std::string &message);
|
void SendGlobalChat(const std::string &message);
|
||||||
@@ -156,7 +159,8 @@ protected:
|
|||||||
ServerSenderCallback &GetSenderCallback();
|
ServerSenderCallback &GetSenderCallback();
|
||||||
GuiInterface &GetGui();
|
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> CreateNetPacketGameListNew(const ServerGameThread &game);
|
||||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode);
|
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode);
|
||||||
@@ -187,6 +191,9 @@ private:
|
|||||||
SessionIdList m_resubscribeList;
|
SessionIdList m_resubscribeList;
|
||||||
mutable boost::mutex m_resubscribeListMutex;
|
mutable boost::mutex m_resubscribeListMutex;
|
||||||
|
|
||||||
|
RegExList m_banPlayerNameList;
|
||||||
|
mutable boost::mutex m_banPlayerNameListMutex;
|
||||||
|
|
||||||
GameMap m_gameMap;
|
GameMap m_gameMap;
|
||||||
|
|
||||||
boost::shared_ptr<SenderInterface> m_sender;
|
boost::shared_ptr<SenderInterface> m_sender;
|
||||||
|
|||||||
Reference in New Issue
Block a user