Do not use regex for chat bot bans.
This commit is contained in:
@@ -31,6 +31,18 @@ ServerBanManager::~ServerBanManager()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerBanManager::BanPlayerName(const std::string &playerName, unsigned durationHours)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_banMutex);
|
||||
unsigned banId = GetNextBanId();
|
||||
|
||||
TimedPlayerBan tmpBan;
|
||||
tmpBan.timer = InternalRegisterTimedBan(banId, durationHours);
|
||||
tmpBan.nameStr = playerName;
|
||||
m_banPlayerNameMap[banId] = tmpBan;
|
||||
}
|
||||
|
||||
void
|
||||
ServerBanManager::BanPlayerRegex(const string &playerRegex, unsigned durationHours)
|
||||
{
|
||||
@@ -91,7 +103,11 @@ ServerBanManager::GetBanList(list<string> &list) const
|
||||
while (i_nick != end_nick)
|
||||
{
|
||||
ostringstream banText;
|
||||
banText << (*i_nick).first << ": (nick) - " << (*i_nick).second.nameRegex.str();
|
||||
if ((*i_nick).second.nameStr.empty())
|
||||
banText << (*i_nick).first << ": (nickRegex) - " << (*i_nick).second.nameRegex.str();
|
||||
else
|
||||
banText << (*i_nick).first << ": (nickStr) - " << (*i_nick).second.nameStr;
|
||||
|
||||
if ((*i_nick).second.timer)
|
||||
banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h";
|
||||
list.push_back(banText.str());
|
||||
@@ -127,10 +143,22 @@ ServerBanManager::IsPlayerBanned(const std::string &name) const
|
||||
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
||||
while (i != end)
|
||||
{
|
||||
if (regex_match(name, (*i).second.nameRegex))
|
||||
// Use regex only if name not set.
|
||||
if ((*i).second.nameStr.empty())
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
if (regex_match(name, (*i).second.nameRegex))
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (name == (*i).second.nameStr)
|
||||
{
|
||||
retVal = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
string playerName(m_server.GetPlayerNameFromId(playerId));
|
||||
if (!playerName.empty())
|
||||
{
|
||||
m_server.GetBanManager().BanPlayerRegex(playerName, 1);
|
||||
m_server.GetBanManager().BanPlayerName(playerName, 1);
|
||||
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user