Do not use regex for chat bot bans.

This commit is contained in:
lotodore
2010-07-14 17:55:49 +00:00
parent 6c997ca21a
commit b4d02f4cb0
3 changed files with 35 additions and 5 deletions
+32 -4
View File
@@ -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;
}