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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user