diff --git a/src/net/common/serverbanmanager.cpp b/src/net/common/serverbanmanager.cpp index 09e0b9b4..23ddd005 100644 --- a/src/net/common/serverbanmanager.cpp +++ b/src/net/common/serverbanmanager.cpp @@ -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 &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; } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 4b45e390..4a38cdf7 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -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); } } diff --git a/src/net/serverbanmanager.h b/src/net/serverbanmanager.h index 3421623d..065d6332 100644 --- a/src/net/serverbanmanager.h +++ b/src/net/serverbanmanager.h @@ -34,6 +34,7 @@ public: ServerBanManager(boost::shared_ptr 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 timer; + std::string nameStr; boost::regex nameRegex; }; struct TimedIPBan