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
+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);