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:
@@ -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()),
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user