From 03a1a1dc550cc88d4a8b61864ea775df04b7b51e Mon Sep 17 00:00:00 2001 From: lotodore Date: Sun, 8 Jan 2012 13:02:29 +0000 Subject: [PATCH] Implement chat bot mute on server side (#1). --- src/chatcleaner/messagefilter.cpp | 5 ++- src/engine/local_engine/localplayer.cpp | 12 ++++++- src/engine/local_engine/localplayer.h | 3 ++ src/engine/network_engine/clientplayer.cpp | 16 ++++++++- src/engine/network_engine/clientplayer.h | 3 ++ src/engine/playerinterface.h | 2 ++ src/net/chatcleanercallback.h | 1 + src/net/common/chatcleanermanager.cpp | 2 ++ src/net/common/servergame.cpp | 21 ++++++++++++ src/net/common/servergamestate.cpp | 29 +++++++++-------- src/net/common/serverlobbythread.cpp | 38 ++++++++++++++++------ src/net/servergame.h | 2 ++ src/net/serverlobbythread.h | 2 ++ 13 files changed, 108 insertions(+), 28 deletions(-) diff --git a/src/chatcleaner/messagefilter.cpp b/src/chatcleaner/messagefilter.cpp index fdb36dfc..fbcb573e 100644 --- a/src/chatcleaner/messagefilter.cpp +++ b/src/chatcleaner/messagefilter.cpp @@ -79,10 +79,9 @@ QStringList MessageFilter::check(unsigned gameId, unsigned playerId, QString nic } else { if(i.value().warnLevel == warnLevelToKick || i.value().lastWarnType == offence) { if(gameId) { - //check for ingame to do not kick but mute + //check for ingame to do not kick but mute action = MUTE; - } - else { + } else { // Kick Command action = KICK; //remove playerId from all lists and as LAST from myClientWarnLevelList diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index bf9325d9..34340e59 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -849,7 +849,7 @@ LocalPlayer::LocalPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType ty : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(PLAYER_ACTION_NONE), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(0), myCardsFlip(0), myRoundStartCash(0), lastMoneyWon(0), - sBluff(0), sBluffStatus(false), m_actionTimeoutCounter(0), m_isSessionActive(false), m_isKicked(false) + sBluff(0), sBluffStatus(false), m_actionTimeoutCounter(0), m_isSessionActive(false), m_isKicked(false), m_isMuted(false) { // !!!!!!!!!!!!!!!!!!!!!!!! testing !!!!!!!!!!!!!!!!!!!!!!!! @@ -5114,6 +5114,16 @@ bool LocalPlayer::isKicked() const return m_isKicked; } +void LocalPlayer::setIsMuted(bool muted) +{ + m_isMuted = muted; +} + +bool LocalPlayer::isMuted() const +{ + return m_isMuted; +} + bool LocalPlayer::checkIfINeedToShowCards() { std::list playerNeedToShowCardsList = currentHand->getBoard()->getPlayerNeedToShowCards(); diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index dc0e7837..a37c3fe7 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -284,6 +284,8 @@ public: bool isSessionActive() const; void setIsKicked(bool kicked); bool isKicked() const; + void setIsMuted(bool muted); + bool isMuted() const; bool checkIfINeedToShowCards(); @@ -335,6 +337,7 @@ private: unsigned m_actionTimeoutCounter; bool m_isSessionActive; bool m_isKicked; + bool m_isMuted; boost::timers::portable::microsec_timer m_lastRemoteActionTimer; }; diff --git a/src/engine/network_engine/clientplayer.cpp b/src/engine/network_engine/clientplayer.cpp index dc6ec745..ba42368b 100644 --- a/src/engine/network_engine/clientplayer.cpp +++ b/src/engine/network_engine/clientplayer.cpp @@ -26,7 +26,7 @@ ClientPlayer::ClientPlayer(ConfigFile *c, int id, unsigned uniqueId, PlayerType : PlayerInterface(), myConfig(c), currentHand(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), logHoleCardsDone(false), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(PLAYER_ACTION_NONE), myButton(mB), myActiveStatus(aS), myStayOnTableStatus(sotS), myTurn(false), myCardsFlip(false), myRoundStartCash(0), - lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_isSessionActive(false), m_isKicked(false) + lastMoneyWon(0), sBluff(0), sBluffStatus(false), m_isSessionActive(false), m_isKicked(false), m_isMuted(false) { myBestHandPosition[0] = myBestHandPosition[1] = myBestHandPosition[2] = myBestHandPosition[3] = myBestHandPosition[4] = 0; myNiveau[0] = myNiveau[1] = myNiveau[2] = 0; @@ -563,6 +563,20 @@ ClientPlayer::isKicked() const return m_isKicked; } +void +ClientPlayer::setIsMuted(bool muted) +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + m_isMuted = muted; +} + +bool +ClientPlayer::isMuted() const +{ + boost::recursive_mutex::scoped_lock lock(m_syncMutex); + return m_isMuted; +} + bool ClientPlayer::checkIfINeedToShowCards() { boost::recursive_mutex::scoped_lock lock(m_syncMutex); diff --git a/src/engine/network_engine/clientplayer.h b/src/engine/network_engine/clientplayer.h index b02b8e1d..1ccdc7a7 100644 --- a/src/engine/network_engine/clientplayer.h +++ b/src/engine/network_engine/clientplayer.h @@ -137,6 +137,8 @@ public: bool isSessionActive() const; void setIsKicked(bool kicked); bool isKicked() const; + void setIsMuted(bool muted); + bool isMuted() const; bool checkIfINeedToShowCards(); @@ -190,6 +192,7 @@ private: bool m_isSessionActive; bool m_isKicked; + bool m_isMuted; }; #endif diff --git a/src/engine/playerinterface.h b/src/engine/playerinterface.h index a6d0fa9a..533fc394 100644 --- a/src/engine/playerinterface.h +++ b/src/engine/playerinterface.h @@ -122,6 +122,8 @@ public: virtual bool isSessionActive() const=0; virtual void setIsKicked(bool kicked) =0; virtual bool isKicked() const=0; + virtual void setIsMuted(bool muted) =0; + virtual bool isMuted() const=0; virtual bool checkIfINeedToShowCards() =0; diff --git a/src/net/chatcleanercallback.h b/src/net/chatcleanercallback.h index 13a7c36b..0adc56d6 100644 --- a/src/net/chatcleanercallback.h +++ b/src/net/chatcleanercallback.h @@ -32,6 +32,7 @@ public: virtual void SignalChatBotMessage(unsigned gameId, const std::string &msg) = 0; virtual void SignalKickPlayer(unsigned playerId) = 0; virtual void SignalBanPlayer(unsigned playerId) = 0; + virtual void SignalMutePlayer(unsigned playerId) = 0; }; #endif diff --git a/src/net/common/chatcleanermanager.cpp b/src/net/common/chatcleanermanager.cpp index 469b79fb..d50193fc 100644 --- a/src/net/common/chatcleanermanager.cpp +++ b/src/net/common/chatcleanermanager.cpp @@ -239,6 +239,8 @@ ChatCleanerManager::HandleMessage(InternalChatCleanerPacket &msg) m_callback.SignalKickPlayer(netReply->playerId); else if (netReply->cleanerActionType == cleanerActionType_cleanerActionBan) m_callback.SignalBanPlayer(netReply->playerId); + else if (netReply->cleanerActionType == cleanerActionType_cleanerActionMute) + m_callback.SignalMutePlayer(netReply->playerId); error = false; } return error; diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index 0e947c36..ee52a812 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -102,6 +102,17 @@ ServerGame::RemovePlayer(unsigned playerId, unsigned errorCode) SessionError(tmpSession, errorCode); } +void +ServerGame::MutePlayer(unsigned playerId, bool mute) +{ + if (m_game) { + boost::shared_ptr tmpPlayer(m_game->getPlayerByUniqueId(playerId)); + if (tmpPlayer) { + tmpPlayer->setIsMuted(mute); + } + } +} + void ServerGame::MarkPlayerAsInactive(unsigned playerId) { @@ -612,6 +623,16 @@ ServerGame::GetPlayerInterfaceFromGame(const std::string &playerName) return tmpPlayer; } +boost::shared_ptr +ServerGame::GetPlayerInterfaceFromGame(unsigned playerId) +{ + boost::shared_ptr tmpPlayer; + if (m_game) { + tmpPlayer = m_game->getPlayerByUniqueId(playerId); + } + return tmpPlayer; +} + bool ServerGame::IsRunning() const { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index c50ba18a..3bb7e5c6 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -266,19 +266,22 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr se chatSent = true; } } else if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeGame) { - boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); - packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; - ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; - netChat->chatType.present = chatType_PR_chatTypeGame; - ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame; - netGameChat->gameId = server->GetId(); - netGameChat->playerId = session->GetPlayerData()->GetUniqueId(); - OCTET_STRING_fromBuf( - &netChat->chatText, - (char *)netChatRequest->chatText.buf, - netChatRequest->chatText.size); - server->SendToAllPlayers(packet, SessionData::Game); - chatSent = true; + boost::shared_ptr tmpPlayer (server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetUniqueId())); + if (tmpPlayer && !tmpPlayer->isMuted()) { + boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); + packet->GetMsg()->present = PokerTHMessage_PR_chatMessage; + ChatMessage_t *netChat = &packet->GetMsg()->choice.chatMessage; + netChat->chatType.present = chatType_PR_chatTypeGame; + ChatTypeGame_t *netGameChat = &netChat->chatType.choice.chatTypeGame; + netGameChat->gameId = server->GetId(); + netGameChat->playerId = session->GetPlayerData()->GetUniqueId(); + OCTET_STRING_fromBuf( + &netChat->chatText, + (char *)netChatRequest->chatText.buf, + netChatRequest->chatText.size); + server->SendToAllPlayers(packet, SessionData::Game); + chatSent = true; + } // Send the message to the chat cleaner bot for ranking games. //if (server->GetGameData().gameType == GAME_TYPE_RANKING) diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 949bece7..242c5b15 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -125,6 +125,10 @@ public: } } + virtual void SignalMutePlayer(unsigned playerId) { + m_server.MutePlayerInGame(playerId); + } + virtual void ConnectSuccess() { LOG_MSG("Successfully connected to database."); } @@ -539,6 +543,12 @@ ServerLobbyThread::RemovePlayer(unsigned playerId, unsigned errorCode) m_ioService->post(boost::bind(&ServerLobbyThread::InternalRemovePlayer, shared_from_this(), playerId, errorCode)); } +void +ServerLobbyThread::MutePlayerInGame(unsigned playerId) +{ + m_ioService->post(boost::bind(&ServerLobbyThread::InternalMutePlayerInGame, shared_from_this(), playerId)); +} + void ServerLobbyThread::SendGlobalChat(const string &message) { @@ -881,7 +891,7 @@ ServerLobbyThread::HandlePacket(boost::shared_ptr session, boost::s else if (packet->GetMsg()->present == PokerTHMessage_PR_avatarRequestMessage) HandleNetPacketRetrieveAvatar(session, packet->GetMsg()->choice.avatarRequestMessage); else if (packet->GetMsg()->present == PokerTHMessage_PR_resetTimeoutMessage) - {} + {} else if (packet->GetMsg()->present == PokerTHMessage_PR_subscriptionRequestMessage) { SubscriptionRequestMessage_t *subscriptionRequest = &packet->GetMsg()->choice.subscriptionRequestMessage; if (subscriptionRequest->subscriptionAction == subscriptionAction_resubscribeGameList) @@ -1744,17 +1754,25 @@ ServerLobbyThread::InternalRemovePlayer(unsigned playerId, unsigned errorCode) if (session) SessionError(session, errorCode); else { - // Scan games for the player. - GameMap::iterator i = m_gameMap.begin(); - GameMap::iterator end = m_gameMap.end(); - - while (i != end) { - boost::shared_ptr tmpGame = i->second; - if (tmpGame->GetPlayerDataByUniqueId(playerId)) { + // Remove player from game. + boost::shared_ptr session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId); + if (session) { + boost::shared_ptr tmpGame = session->GetGame(); + if (tmpGame) { tmpGame->RemovePlayer(playerId, errorCode); - break; } - ++i; + } + } +} + +void +ServerLobbyThread::InternalMutePlayerInGame(unsigned playerId) +{ + boost::shared_ptr session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId); + if (session) { + boost::shared_ptr tmpGame = session->GetGame(); + if (tmpGame) { + tmpGame->MutePlayer(playerId, true); } } } diff --git a/src/net/servergame.h b/src/net/servergame.h index cb8a982c..5d95aaca 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -53,6 +53,7 @@ public: void AddSession(boost::shared_ptr session); void RemovePlayer(unsigned playerId, unsigned errorCode); + void MutePlayer(unsigned playerId, bool mute); void MarkPlayerAsInactive(unsigned playerId); void MarkPlayerAsKicked(unsigned playerId); @@ -76,6 +77,7 @@ public: bool IsPlayerConnected(unsigned playerId) const; bool IsClientAddressConnected(const std::string &clientAddress) const; boost::shared_ptr GetPlayerInterfaceFromGame(const std::string &playerName); + boost::shared_ptr GetPlayerInterfaceFromGame(unsigned playerId); bool IsRunning() const; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index c737336f..cecfec5f 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -79,6 +79,7 @@ public: std::string GetPlayerIPAddress(const std::string &playerName) const; std::string GetPlayerNameFromId(unsigned playerId) const; void RemovePlayer(unsigned playerId, unsigned errorCode); + void MutePlayerInGame(unsigned playerId); void SendGlobalChat(const std::string &message); void SendGlobalMsgBox(const std::string &message); @@ -163,6 +164,7 @@ protected: void InternalAddGame(boost::shared_ptr game); void InternalRemoveGame(boost::shared_ptr game); void InternalRemovePlayer(unsigned playerId, unsigned errorCode); + void InternalMutePlayerInGame(unsigned playerId); void InternalResubscribeMsg(boost::shared_ptr session); void HandleReAddedSession(boost::shared_ptr session);