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
|
void
|
||||||
ServerBanManager::BanPlayerRegex(const string &playerRegex, unsigned durationHours)
|
ServerBanManager::BanPlayerRegex(const string &playerRegex, unsigned durationHours)
|
||||||
{
|
{
|
||||||
@@ -91,7 +103,11 @@ ServerBanManager::GetBanList(list<string> &list) const
|
|||||||
while (i_nick != end_nick)
|
while (i_nick != end_nick)
|
||||||
{
|
{
|
||||||
ostringstream banText;
|
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)
|
if ((*i_nick).second.timer)
|
||||||
banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h";
|
banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h";
|
||||||
list.push_back(banText.str());
|
list.push_back(banText.str());
|
||||||
@@ -127,10 +143,22 @@ ServerBanManager::IsPlayerBanned(const std::string &name) const
|
|||||||
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
||||||
while (i != 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;
|
if (regex_match(name, (*i).second.nameRegex))
|
||||||
break;
|
{
|
||||||
|
retVal = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (name == (*i).second.nameStr)
|
||||||
|
{
|
||||||
|
retVal = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public:
|
|||||||
string playerName(m_server.GetPlayerNameFromId(playerId));
|
string playerName(m_server.GetPlayerNameFromId(playerId));
|
||||||
if (!playerName.empty())
|
if (!playerName.empty())
|
||||||
{
|
{
|
||||||
m_server.GetBanManager().BanPlayerRegex(playerName, 1);
|
m_server.GetBanManager().BanPlayerName(playerName, 1);
|
||||||
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
|
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public:
|
|||||||
ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService);
|
ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService);
|
||||||
virtual ~ServerBanManager();
|
virtual ~ServerBanManager();
|
||||||
|
|
||||||
|
void BanPlayerName(const std::string &playerName, unsigned durationHours = 0);
|
||||||
void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0);
|
void BanPlayerRegex(const std::string &playerRegex, unsigned durationHours = 0);
|
||||||
void BanIPAddress(const std::string &ipAddress, unsigned durationHours);
|
void BanIPAddress(const std::string &ipAddress, unsigned durationHours);
|
||||||
bool UnBan(unsigned banId);
|
bool UnBan(unsigned banId);
|
||||||
@@ -47,6 +48,7 @@ protected:
|
|||||||
struct TimedPlayerBan
|
struct TimedPlayerBan
|
||||||
{
|
{
|
||||||
boost::shared_ptr<boost::asio::deadline_timer> timer;
|
boost::shared_ptr<boost::asio::deadline_timer> timer;
|
||||||
|
std::string nameStr;
|
||||||
boost::regex nameRegex;
|
boost::regex nameRegex;
|
||||||
};
|
};
|
||||||
struct TimedIPBan
|
struct TimedIPBan
|
||||||
|
|||||||
Reference in New Issue
Block a user