From 7a1a10abf5f12d2f1c4b1bdc44bb2229242744a3 Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 5 Sep 2010 00:15:25 +0000 Subject: [PATCH] Block bad game names on server. --- docs/pokerth.asn1 | 3 +- src/config/configfile.cpp | 3 +- src/gui/qt/startwindow/startwindowimpl.cpp | 1 + src/net/common/serverbanmanager.cpp | 32 +++++++++++++++++++++- src/net/common/servergamestate.cpp | 12 ++++---- src/net/common/serverlobbythread.cpp | 6 ++++ src/net/serverbanmanager.h | 13 +++++++-- src/net/socket_msg.h | 3 +- 8 files changed, 60 insertions(+), 13 deletions(-) diff --git a/docs/pokerth.asn1 b/docs/pokerth.asn1 index f656266c..3140f679 100644 --- a/docs/pokerth.asn1 +++ b/docs/pokerth.asn1 @@ -310,7 +310,8 @@ JoinGameFailed ::= SEQUENCE { notAllowedAsGuest (5), notInvited (6), gameNameInUse (7), - invalidSettings (8) + badGameName (8), + invalidSettings (9) } } diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 9442b04a..97165375 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -50,7 +50,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) myConfigState = OK; // !!!! Revisionsnummer der Configdefaults !!!!! - configRev = 85; + configRev = 86; //standard defaults logOnOffDefault = "1"; @@ -280,6 +280,7 @@ ConfigFile::ConfigFile(char *argv0, bool readonly) : noWriteAccess(readonly) configList.push_back(ConfigInfo("DBServerPassword", CONFIG_TYPE_STRING, "")); configList.push_back(ConfigInfo("DBServerDatabaseName", CONFIG_TYPE_STRING, "pokerth")); configList.push_back(ConfigInfo("DBServerEncryptionKey", CONFIG_TYPE_STRING, "")); + configList.push_back(ConfigInfo("GameNameBadWordList", CONFIG_TYPE_STRING_LIST, "regex")); //fill tempList firstTime configBufferList = configList; diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index e5f4712e..0bae03c2 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -863,6 +863,7 @@ void startWindowImpl::networkNotification(int notificationId) QMessageBox::Close); } break; case NTF_NET_JOIN_GAME_NAME_IN_USE: + case NTF_NET_JOIN_GAME_BAD_NAME: { changeContentDialogImpl dialog(this, myConfig, CHANGE_INET_GAME_NAME); dialog.exec(); if(dialog.result() == QDialog::Accepted) { diff --git a/src/net/common/serverbanmanager.cpp b/src/net/common/serverbanmanager.cpp index 23ddd005..05493185 100644 --- a/src/net/common/serverbanmanager.cpp +++ b/src/net/common/serverbanmanager.cpp @@ -51,7 +51,7 @@ ServerBanManager::BanPlayerRegex(const string &playerRegex, unsigned durationHou TimedPlayerBan tmpBan; tmpBan.timer = InternalRegisterTimedBan(banId, durationHours); - tmpBan.nameRegex = boost::regex(playerRegex, boost::regex_constants::no_except); + tmpBan.nameRegex = boost::regex(playerRegex, boost::regex::extended | boost::regex::icase); m_banPlayerNameMap[banId] = tmpBan; } @@ -186,6 +186,36 @@ ServerBanManager::IsIPAddressBanned(const std::string &ipAddress) const return retVal; } +void +ServerBanManager::InitGameNameBadWordList(const std::list &badWordList) +{ + list::const_iterator i = badWordList.begin(); + list::const_iterator end = badWordList.end(); + while (i != end) + { + m_gameNameBadWordFilter.push_back(boost::regex(*i, boost::regex::extended | boost::regex::icase)); + ++i; + } +} + +bool +ServerBanManager::IsBadGameName(const std::string &name) const +{ + bool retVal = false; + RegexList::const_iterator i = m_gameNameBadWordFilter.begin(); + RegexList::const_iterator end = m_gameNameBadWordFilter.end(); + while (i != end) + { + if (regex_match(name, *i)) + { + retVal = true; + break; + } + ++i; + } + return retVal; +} + boost::shared_ptr ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours) { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index a8182efb..7318a3d7 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -145,23 +145,23 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptrsetMySet(bet); - // update minimumRaise and lastActionPlayer + // update minimumRaise and lastActionPlayer switch(action) { case PLAYER_ACTION_BET: { curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(bet); - curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); + curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); } break; case PLAYER_ACTION_RAISE: { curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); - curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); + curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); } break; case PLAYER_ACTION_ALLIN: { if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > curGame.getCurrentHand()->getCurrentBeRo()->getMinimumRaise()) { curGame.getCurrentHand()->getCurrentBeRo()->setMinimumRaise(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet()); } - if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > 0) { - curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); - } + if(player->getMySet() - curGame.getCurrentHand()->getCurrentBeRo()->getHighestSet() > 0) { + curGame.getCurrentHand()->setLastActionPlayer(player->getMyUniqueID()); + } } break; default: { } diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 8be1e804..7189f940 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -202,6 +202,8 @@ ServerLobbyThread::Init(const string &logDir) m_serverConfig->readConfigString("DBServerPassword"), m_serverConfig->readConfigString("DBServerDatabaseName"), m_serverConfig->readConfigString("DBServerEncryptionKey")); + + GetBanManager().InitGameNameBadWordList(m_serverConfig->readConfigStringList("GameNameBadWordList")); } void @@ -1335,6 +1337,10 @@ ServerLobbyThread::HandleNetPacketCreateGame(SessionWrapper session, const std:: { SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GAME_NAME_IN_USE); } + else if (GetBanManager().IsBadGameName(gameName)) + { + SendJoinGameFailed(session.sessionData, gameId, NTF_NET_JOIN_GAME_BAD_NAME); + } else if (session.playerData->GetRights() == PLAYER_RIGHTS_GUEST && tmpData.gameType != GAME_TYPE_NORMAL) { diff --git a/src/net/serverbanmanager.h b/src/net/serverbanmanager.h index 065d6332..07568f44 100644 --- a/src/net/serverbanmanager.h +++ b/src/net/serverbanmanager.h @@ -26,6 +26,7 @@ #include #include #include +#include #include class ServerBanManager : public boost::enable_shared_from_this @@ -44,7 +45,11 @@ public: bool IsPlayerBanned(const std::string &name) const; bool IsIPAddressBanned(const std::string &ipAddress) const; + void InitGameNameBadWordList(const std::list &badWordList); + bool IsBadGameName(const std::string &name) const; + protected: + struct TimedPlayerBan { boost::shared_ptr timer; @@ -57,18 +62,20 @@ protected: std::string ipAddress; }; + typedef std::map RegexMap; + typedef std::map IPAddressMap; + typedef std::list RegexList; + boost::shared_ptr InternalRegisterTimedBan(unsigned timerId, unsigned durationHours); void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr timer); boost::shared_ptr m_ioService; - typedef std::map RegexMap; - typedef std::map IPAddressMap; - unsigned GetNextBanId(); private: RegexMap m_banPlayerNameMap; + RegexList m_gameNameBadWordFilter; IPAddressMap m_banIPAddressMap; unsigned m_curBanId; mutable boost::mutex m_banMutex; diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index b57e65b6..a659f954 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -115,7 +115,8 @@ #define NTF_NET_JOIN_GUEST_FORBIDDEN 214 #define NTF_NET_JOIN_NOT_INVITED 215 #define NTF_NET_JOIN_GAME_NAME_IN_USE 216 -#define NTF_NET_JOIN_INVALID_SETTINGS 217 +#define NTF_NET_JOIN_GAME_BAD_NAME 217 +#define NTF_NET_JOIN_INVALID_SETTINGS 218 // Notifications - version #define NTF_NET_NEW_RELEASE_AVAILABLE 220