Block bad game names on server.

This commit is contained in:
lotodore
2010-09-05 00:15:25 +00:00
parent 03be7c2f16
commit 7a1a10abf5
8 changed files with 60 additions and 13 deletions
+2 -1
View File
@@ -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;
@@ -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) {
+31 -1
View File
@@ -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<string> &badWordList)
{
list<string>::const_iterator i = badWordList.begin();
list<string>::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<boost::asio::deadline_timer>
ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours)
{
+6 -6
View File
@@ -145,23 +145,23 @@ static void PerformPlayerAction(ServerGame &server, boost::shared_ptr<PlayerInte
player->setMySet(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: {
}
+6
View File
@@ -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)
{
+10 -3
View File
@@ -26,6 +26,7 @@
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <map>
#include <list>
#include <string>
class ServerBanManager : public boost::enable_shared_from_this<ServerBanManager>
@@ -44,7 +45,11 @@ public:
bool IsPlayerBanned(const std::string &name) const;
bool IsIPAddressBanned(const std::string &ipAddress) const;
void InitGameNameBadWordList(const std::list<std::string> &badWordList);
bool IsBadGameName(const std::string &name) const;
protected:
struct TimedPlayerBan
{
boost::shared_ptr<boost::asio::deadline_timer> timer;
@@ -57,18 +62,20 @@ protected:
std::string ipAddress;
};
typedef std::map<unsigned, TimedPlayerBan> RegexMap;
typedef std::map<unsigned, TimedIPBan> IPAddressMap;
typedef std::list<boost::regex> RegexList;
boost::shared_ptr<boost::asio::deadline_timer> InternalRegisterTimedBan(unsigned timerId, unsigned durationHours);
void TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::deadline_timer> timer);
boost::shared_ptr<boost::asio::io_service> m_ioService;
typedef std::map<unsigned, TimedPlayerBan> RegexMap;
typedef std::map<unsigned, TimedIPBan> IPAddressMap;
unsigned GetNextBanId();
private:
RegexMap m_banPlayerNameMap;
RegexList m_gameNameBadWordFilter;
IPAddressMap m_banIPAddressMap;
unsigned m_curBanId;
mutable boost::mutex m_banMutex;
+2 -1
View File
@@ -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