Implement chat bot mute on server side (#1).

This commit is contained in:
lotodore
2012-01-08 13:02:29 +00:00
parent c3dc99620e
commit 03a1a1dc55
13 changed files with 108 additions and 28 deletions
+2 -3
View File
@@ -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
+11 -1
View File
@@ -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<unsigned> playerNeedToShowCardsList = currentHand->getBoard()->getPlayerNeedToShowCards();
+3
View File
@@ -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;
};
+15 -1
View File
@@ -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);
+3
View File
@@ -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
+2
View File
@@ -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;
+1
View File
@@ -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
+2
View File
@@ -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;
+21
View File
@@ -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<PlayerInterface> 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<PlayerInterface>
ServerGame::GetPlayerInterfaceFromGame(unsigned playerId)
{
boost::shared_ptr<PlayerInterface> tmpPlayer;
if (m_game) {
tmpPlayer = m_game->getPlayerByUniqueId(playerId);
}
return tmpPlayer;
}
bool
ServerGame::IsRunning() const
{
+16 -13
View File
@@ -266,19 +266,22 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
chatSent = true;
}
} else if (netChatRequest->chatRequestType.present == chatRequestType_PR_chatRequestTypeGame) {
boost::shared_ptr<NetPacket> 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<PlayerInterface> tmpPlayer (server->GetPlayerInterfaceFromGame(session->GetPlayerData()->GetUniqueId()));
if (tmpPlayer && !tmpPlayer->isMuted()) {
boost::shared_ptr<NetPacket> 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)
+28 -10
View File
@@ -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<SessionData> 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<ServerGame> tmpGame = i->second;
if (tmpGame->GetPlayerDataByUniqueId(playerId)) {
// Remove player from game.
boost::shared_ptr<SessionData> session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
if (session) {
boost::shared_ptr<ServerGame> tmpGame = session->GetGame();
if (tmpGame) {
tmpGame->RemovePlayer(playerId, errorCode);
break;
}
++i;
}
}
}
void
ServerLobbyThread::InternalMutePlayerInGame(unsigned playerId)
{
boost::shared_ptr<SessionData> session = m_gameSessionManager.GetSessionByUniquePlayerId(playerId);
if (session) {
boost::shared_ptr<ServerGame> tmpGame = session->GetGame();
if (tmpGame) {
tmpGame->MutePlayer(playerId, true);
}
}
}
+2
View File
@@ -53,6 +53,7 @@ public:
void AddSession(boost::shared_ptr<SessionData> 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<PlayerInterface> GetPlayerInterfaceFromGame(const std::string &playerName);
boost::shared_ptr<PlayerInterface> GetPlayerInterfaceFromGame(unsigned playerId);
bool IsRunning() const;
+2
View File
@@ -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<ServerGame> game);
void InternalRemoveGame(boost::shared_ptr<ServerGame> game);
void InternalRemovePlayer(unsigned playerId, unsigned errorCode);
void InternalMutePlayerInGame(unsigned playerId);
void InternalResubscribeMsg(boost::shared_ptr<SessionData> session);
void HandleReAddedSession(boost::shared_ptr<SessionData> session);