Adding support for listing and removing single bans.
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include <core/openssl_wrapper.h>
|
#include <core/openssl_wrapper.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/lambda/lambda.hpp>
|
#include <boost/lambda/lambda.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
@@ -80,7 +81,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager)
|
ServerLobbyThread::ServerLobbyThread(GuiInterface &gui, ConfigFile *playerConfig, AvatarManager &avatarManager)
|
||||||
: m_gui(gui), m_avatarManager(avatarManager), m_playerConfig(playerConfig),
|
: m_curBanId(0), m_gui(gui), m_avatarManager(avatarManager), m_playerConfig(playerConfig),
|
||||||
m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
m_curGameId(0), m_curUniquePlayerId(0), m_curSessionId(INVALID_SESSION + 1),
|
||||||
m_statDataChanged(false), m_startTime(boost::posix_time::second_clock::local_time())
|
m_statDataChanged(false), m_startTime(boost::posix_time::second_clock::local_time())
|
||||||
{
|
{
|
||||||
@@ -258,17 +259,46 @@ ServerLobbyThread::KickPlayerByName(const std::string &playerName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerLobbyThread::BanPlayerRegex(const std::string &playerRegex)
|
ServerLobbyThread::BanPlayerRegex(const string &playerRegex)
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
boost::mutex::scoped_lock lock(m_banMutex);
|
||||||
m_banPlayerNameList.push_back(boost::regex(playerRegex, boost::regex_constants::no_except));
|
m_banPlayerNameMap[++m_curBanId] = boost::regex(playerRegex, boost::regex_constants::no_except);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
ServerLobbyThread::UnBanPlayerRegex(unsigned banId)
|
||||||
|
{
|
||||||
|
bool retVal = false;
|
||||||
|
boost::mutex::scoped_lock lock(m_banMutex);
|
||||||
|
RegexMap::iterator pos = m_banPlayerNameMap.find(banId);
|
||||||
|
if (pos != m_banPlayerNameMap.end())
|
||||||
|
{
|
||||||
|
m_banPlayerNameMap.erase(pos);
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ServerLobbyThread::ClearBanList()
|
ServerLobbyThread::GetBanPlayerList(list<string> &list) const
|
||||||
{
|
{
|
||||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
boost::mutex::scoped_lock lock(m_banMutex);
|
||||||
m_banPlayerNameList.clear();
|
RegexMap::const_iterator i = m_banPlayerNameMap.begin();
|
||||||
|
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
ostringstream banText;
|
||||||
|
banText << (*i).first << ": " << (*i).second.str();
|
||||||
|
list.push_back(banText.str());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerLobbyThread::ClearBanPlayerList()
|
||||||
|
{
|
||||||
|
boost::mutex::scoped_lock lock(m_banMutex);
|
||||||
|
m_banPlayerNameMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -1381,12 +1411,12 @@ bool
|
|||||||
ServerLobbyThread::IsPlayerBanned(const std::string &name) const
|
ServerLobbyThread::IsPlayerBanned(const std::string &name) const
|
||||||
{
|
{
|
||||||
bool retVal = false;
|
bool retVal = false;
|
||||||
boost::mutex::scoped_lock lock(m_banPlayerNameListMutex);
|
boost::mutex::scoped_lock lock(m_banMutex);
|
||||||
RegexList::const_iterator i = m_banPlayerNameList.begin();
|
RegexMap::const_iterator i = m_banPlayerNameMap.begin();
|
||||||
RegexList::const_iterator end = m_banPlayerNameList.end();
|
RegexMap::const_iterator end = m_banPlayerNameMap.end();
|
||||||
while (i != end)
|
while (i != end)
|
||||||
{
|
{
|
||||||
if (regex_match(name, *i))
|
if (regex_match(name, (*i).second))
|
||||||
{
|
{
|
||||||
retVal = true;
|
retVal = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ void
|
|||||||
ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &msg)
|
ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &msg)
|
||||||
{
|
{
|
||||||
if (m_ircThread)
|
if (m_ircThread)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
istringstream msgStream(msg);
|
istringstream msgStream(msg);
|
||||||
string target;
|
string target;
|
||||||
@@ -110,7 +112,7 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &
|
|||||||
m_ircThread->SendChatMessage(nickName + ": Player \"" + playerName + "\" was not found on the server.");
|
m_ircThread->SendChatMessage(nickName + ": Player \"" + playerName + "\" was not found on the server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "ban")
|
else if (command == "nickban")
|
||||||
{
|
{
|
||||||
while (msgStream.peek() == ' ')
|
while (msgStream.peek() == ' ')
|
||||||
msgStream.get();
|
msgStream.get();
|
||||||
@@ -121,9 +123,30 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &
|
|||||||
m_ircThread->SendChatMessage(nickName + ": The regex \"" + playerRegex + "\" was added to the player ban list.");
|
m_ircThread->SendChatMessage(nickName + ": The regex \"" + playerRegex + "\" was added to the player ban list.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "clearban")
|
else if (command == "listnickban")
|
||||||
{
|
{
|
||||||
GetLobbyThread().ClearBanList();
|
list<string> banList;
|
||||||
|
GetLobbyThread().GetBanPlayerList(banList);
|
||||||
|
list<string>::const_iterator i = banList.begin();
|
||||||
|
list<string>::const_iterator end = banList.end();
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
m_ircThread->SendChatMessage(*i);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (command == "removenickban")
|
||||||
|
{
|
||||||
|
unsigned banId = 0;
|
||||||
|
msgStream >> banId;
|
||||||
|
if (GetLobbyThread().UnBanPlayerRegex(banId))
|
||||||
|
m_ircThread->SendChatMessage(nickName + ": The nick ban was successfully removed.");
|
||||||
|
else
|
||||||
|
m_ircThread->SendChatMessage(nickName + ": This nick ban does not exist.");
|
||||||
|
}
|
||||||
|
else if (command == "clearnickban")
|
||||||
|
{
|
||||||
|
GetLobbyThread().ClearBanPlayerList();
|
||||||
m_ircThread->SendChatMessage(nickName + ": The player ban list was cleared.");
|
m_ircThread->SendChatMessage(nickName + ": The player ban list was cleared.");
|
||||||
}
|
}
|
||||||
else if (command == "stat")
|
else if (command == "stat")
|
||||||
@@ -192,6 +215,10 @@ ServerManager::SignalIrcChatMsg(const std::string &nickName, const std::string &
|
|||||||
else
|
else
|
||||||
m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
m_ircThread->SendChatMessage(nickName + ": Invalid command \"" + command + "\".");
|
||||||
}
|
}
|
||||||
|
} catch (...)
|
||||||
|
{
|
||||||
|
m_ircThread->SendChatMessage(nickName + ": Syntax error. Please check the command.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,9 @@ public:
|
|||||||
|
|
||||||
bool KickPlayerByName(const std::string &playerName);
|
bool KickPlayerByName(const std::string &playerName);
|
||||||
void BanPlayerRegex(const std::string &playerRegex);
|
void BanPlayerRegex(const std::string &playerRegex);
|
||||||
void ClearBanList();
|
bool UnBanPlayerRegex(unsigned banId);
|
||||||
|
void GetBanPlayerList(std::list<std::string> &list) const;
|
||||||
|
void ClearBanPlayerList();
|
||||||
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
void RemovePlayer(unsigned playerId, unsigned errorCode);
|
||||||
|
|
||||||
void SendGlobalChat(const std::string &message);
|
void SendGlobalChat(const std::string &message);
|
||||||
@@ -102,7 +104,7 @@ protected:
|
|||||||
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
|
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
|
||||||
typedef std::map<std::string, boost::timers::portable::microsec_timer> TimerClientAddressMap;
|
typedef std::map<std::string, boost::timers::portable::microsec_timer> TimerClientAddressMap;
|
||||||
typedef std::list<unsigned> RemoveGameList;
|
typedef std::list<unsigned> RemoveGameList;
|
||||||
typedef std::list<boost::regex> RegexList;
|
typedef std::map<unsigned, boost::regex> RegexMap;
|
||||||
|
|
||||||
// Main function of the thread.
|
// Main function of the thread.
|
||||||
virtual void Main();
|
virtual void Main();
|
||||||
@@ -192,8 +194,9 @@ private:
|
|||||||
SessionIdList m_resubscribeList;
|
SessionIdList m_resubscribeList;
|
||||||
mutable boost::mutex m_resubscribeListMutex;
|
mutable boost::mutex m_resubscribeListMutex;
|
||||||
|
|
||||||
RegexList m_banPlayerNameList;
|
RegexMap m_banPlayerNameMap;
|
||||||
mutable boost::mutex m_banPlayerNameListMutex;
|
unsigned m_curBanId;
|
||||||
|
mutable boost::mutex m_banMutex;
|
||||||
|
|
||||||
GameMap m_gameMap;
|
GameMap m_gameMap;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user