Chat cleaner now active within ranking games (for testing it is also active in normal games). New protocol version for chat cleaner.

This commit is contained in:
lotodore
2011-01-30 18:28:44 +00:00
parent e041153b09
commit e55e39a979
9 changed files with 217 additions and 143 deletions
+1
View File
@@ -30,6 +30,7 @@ public:
virtual ~ChatCleanerCallback();
virtual void SignalChatBotMessage(const std::string &msg) = 0;
virtual void SignalChatBotMessage(unsigned gameId, const std::string &msg) = 0;
virtual void SignalKickPlayer(unsigned playerId) = 0;
virtual void SignalBanPlayer(unsigned playerId) = 0;
};
+2 -1
View File
@@ -38,7 +38,8 @@ public:
void Init(const std::string &serverAddr, int port, bool ipv6,
const std::string &clientSecret, const std::string &serverSecret);
void ReInit();
void HandleChatText(unsigned playerId, const std::string &name, const std::string &text);
void HandleLobbyChatText(unsigned playerId, const std::string &name, const std::string &text);
void HandleGameChatText(unsigned gameId, unsigned playerId, const std::string &name, const std::string &text);
protected:
+28 -2
View File
@@ -74,7 +74,13 @@ ChatCleanerManager::ReInit()
}
void
ChatCleanerManager::HandleChatText(unsigned playerId, const std::string &name, const std::string &text)
ChatCleanerManager::HandleLobbyChatText(unsigned playerId, const std::string &name, const std::string &text)
{
HandleGameChatText(0, playerId, name, text);
}
void
ChatCleanerManager::HandleGameChatText(unsigned gameId, unsigned playerId, const std::string &name, const std::string &text)
{
if (m_connected)
{
@@ -82,6 +88,15 @@ ChatCleanerManager::HandleChatText(unsigned playerId, const std::string &name, c
tmpChat.GetMsg()->present = ChatCleanerMessage_PR_cleanerChatRequestMessage;
CleanerChatRequestMessage_t *netRequest = &tmpChat.GetMsg()->choice.cleanerChatRequestMessage;
netRequest->requestId = GetNextRequestId();
if (gameId)
{
netRequest->cleanerChatType.present = CleanerChatType_PR_cleanerChatTypeGame;
netRequest->cleanerChatType.choice.cleanerChatTypeGame.gameId = gameId;
}
else
{
netRequest->cleanerChatType.present = CleanerChatType_PR_cleanerChatTypeLobby;
}
netRequest->playerId = playerId;
OCTET_STRING_fromBuf(&netRequest->playerName,
name.c_str(),
@@ -252,7 +267,16 @@ ChatCleanerManager::HandleMessage(InternalChatCleanerPacket &msg)
{
CleanerChatReplyMessage_t *netReply = &msg.GetMsg()->choice.cleanerChatReplyMessage;
if (netReply->cleanerText)
m_callback.SignalChatBotMessage(string((const char *)netReply->cleanerText->buf, netReply->cleanerText->size));
{
if (netReply->cleanerChatType.present == CleanerChatType_PR_cleanerChatTypeLobby)
{
m_callback.SignalChatBotMessage(string((const char *)netReply->cleanerText->buf, netReply->cleanerText->size));
}
else if (netReply->cleanerChatType.present == CleanerChatType_PR_cleanerChatTypeGame)
{
m_callback.SignalChatBotMessage(netReply->cleanerChatType.choice.cleanerChatTypeGame.gameId, string((const char *)netReply->cleanerText->buf, netReply->cleanerText->size));
}
}
if (netReply->cleanerActionType == cleanerActionType_cleanerActionKick)
m_callback.SignalKickPlayer(netReply->playerId);
else if (netReply->cleanerActionType == cleanerActionType_cleanerActionBan)
@@ -273,6 +297,8 @@ ChatCleanerManager::SendMessageToServer(InternalChatCleanerPacket &msg)
else
{
boost::shared_ptr<EncodedPacket> tmpPacket(new EncodedPacket(buf, e.encoded));
// Actually, this should not be done (parallel async_write calls might break data).
// But we do not want to create additional buffers here.
boost::asio::async_write(
*m_socket,
boost::asio::buffer(tmpPacket->GetData(), tmpPacket->GetSize()),
+1
View File
@@ -767,6 +767,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
}
else if (netMessage->chatType.present == chatType_PR_chatTypeBot)
{
client->GetCallback().SignalNetClientGameChatMsg("(chat bot)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
client->GetCallback().SignalNetClientLobbyChatMsg("(chat bot)", STL_STRING_FROM_OCTET_STRING(netMessage->chatText));
}
else if (netMessage->chatType.present == chatType_PR_chatTypeGame)
+11
View File
@@ -26,6 +26,7 @@
#include <net/socket_msg.h>
#include <net/serverexception.h>
#include <net/net_helper.h>
#include <net/chatcleanermanager.h>
#include <db/serverdbinterface.h>
#include <core/loghelper.h>
#include <core/avatarmanager.h>
@@ -291,6 +292,16 @@ AbstractServerGameStateReceiving::ProcessPacket(boost::shared_ptr<ServerGame> se
(char *)netChatRequest->chatText.buf,
netChatRequest->chatText.size);
server->SendToAllPlayers(packet, SessionData::Game);
// Send the message to the chat cleaner bot for ranking games.
//if (server->GetGameData().gameType == GAME_TYPE_RANKING)
//{
server->GetLobbyThread().GetChatCleaner().HandleGameChatText(
server->GetId(),
session.playerData->GetUniqueId(),
session.playerData->GetName(),
string((char *)netChatRequest->chatText.buf, netChatRequest->chatText.size));
//}
}
}
}
+32 -1
View File
@@ -103,6 +103,11 @@ public:
m_server.SendChatBotMsg(msg);
}
virtual void SignalChatBotMessage(unsigned gameId, const std::string &msg)
{
m_server.SendChatBotMsg(gameId, msg);
}
virtual void SignalKickPlayer(unsigned playerId)
{
m_server.RemovePlayer(playerId, ERR_NET_PLAYER_KICKED);
@@ -611,6 +616,25 @@ ServerLobbyThread::SendChatBotMsg(const std::string &message)
message);
}
void
ServerLobbyThread::SendChatBotMsg(unsigned gameId, const std::string &message)
{
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_chatTypeBot;
OCTET_STRING_fromBuf(
&netChat->chatText,
message.c_str(),
message.length());
GameMap::const_iterator pos = m_gameMap.find(gameId);
if (pos != m_gameMap.end())
{
pos->second->SendToAllPlayers(packet, SessionData::Game);
}
}
void
ServerLobbyThread::ReconnectChatBot()
{
@@ -650,6 +674,13 @@ ServerLobbyThread::GetAvatarManager()
return m_avatarManager;
}
ChatCleanerManager &
ServerLobbyThread::GetChatCleaner()
{
assert(m_chatCleanerManager);
return *m_chatCleanerManager;
}
ServerStats
ServerLobbyThread::GetStats() const
{
@@ -1466,7 +1497,7 @@ ServerLobbyThread::HandleNetPacketChatRequest(SessionWrapper session, const Chat
string chatMsg = STL_STRING_FROM_OCTET_STRING(chatRequest.chatText);
// Send the message to the chat cleaner bot.
m_chatCleanerManager->HandleChatText(
m_chatCleanerManager->HandleLobbyChatText(
session.playerData->GetUniqueId(),
session.playerData->GetName(),
chatMsg);
+1 -1
View File
@@ -21,7 +21,7 @@
#ifndef _INTERNALCHATCLEANERPACKET_H_
#define _INTERNALCHATCLEANERPACKET_H_
#define CLEANER_PROTOCOL_VERSION 1
#define CLEANER_PROTOCOL_VERSION 2
#define MAX_CLEANER_PACKET_SIZE 384
typedef struct ChatCleanerMessage ChatCleanerMessage_t;
+2 -1
View File
@@ -83,10 +83,10 @@ public:
std::string GetPlayerNameFromId(unsigned playerId) const;
void RemovePlayer(unsigned playerId, unsigned errorCode);
void SendGlobalChat(const std::string &message);
void SendGlobalMsgBox(const std::string &message);
void SendChatBotMsg(const std::string &message);
void SendChatBotMsg(unsigned gameId, const std::string &message);
void ReconnectChatBot();
void AddComputerPlayer(boost::shared_ptr<PlayerData> player);
@@ -101,6 +101,7 @@ public:
void SetGameDBId(u_int32_t gameId, DB_id gameDBId);
AvatarManager &GetAvatarManager();
ChatCleanerManager &GetChatCleaner();
ServerStats GetStats() const;
boost::posix_time::ptime GetStartTime() const;