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;
}
+1 -1
View File
@@ -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);
}
}
+2
View File
@@ -34,6 +34,7 @@ public:
ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService);
virtual ~ServerBanManager();
void BanPlayerName(const std::string &playerName, unsigned durationHours = 0);
void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0);
void BanIPAddress(const std::string &ipAddress, unsigned durationHours);
bool UnBan(unsigned banId);
@@ -47,6 +48,7 @@ protected:
struct TimedPlayerBan
{
boost::shared_ptr<boost::asio::deadline_timer> timer;
std::string nameStr;
boost::regex nameRegex;
};
struct TimedIPBan