2024-03-18 19:52:53 +02:00
|
|
|
/*
|
|
|
|
* GameChatHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
|
|
|
|
#include "GameChatHandler.h"
|
|
|
|
#include "CServerHandler.h"
|
|
|
|
#include "CPlayerInterface.h"
|
|
|
|
#include "PlayerLocalState.h"
|
2024-03-20 18:40:37 +02:00
|
|
|
#include "globalLobby/GlobalLobbyClient.h"
|
2024-03-18 19:52:53 +02:00
|
|
|
#include "lobby/CLobbyScreen.h"
|
|
|
|
|
|
|
|
#include "adventureMap/CInGameConsole.h"
|
|
|
|
|
|
|
|
#include "../CCallback.h"
|
|
|
|
|
|
|
|
#include "../lib/networkPacks/PacksForLobby.h"
|
|
|
|
#include "../lib/mapObjects/CArmedInstance.h"
|
|
|
|
#include "../lib/CConfigHandler.h"
|
2024-05-01 15:00:36 +02:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../lib/texts/CGeneralTextHandler.h"
|
|
|
|
#include "../lib/texts/TextOperations.h"
|
2024-03-18 19:52:53 +02:00
|
|
|
|
2024-03-20 19:49:28 +02:00
|
|
|
const std::vector<GameChatMessage> & GameChatHandler::getChatHistory() const
|
2024-03-18 19:52:53 +02:00
|
|
|
{
|
|
|
|
return chatHistory;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::resetMatchState()
|
|
|
|
{
|
|
|
|
chatHistory.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::sendMessageGameplay(const std::string & messageText)
|
|
|
|
{
|
|
|
|
LOCPLINT->cb->sendMessage(messageText, LOCPLINT->localState->getCurrentArmy());
|
2024-03-20 18:40:37 +02:00
|
|
|
CSH->getGlobalLobby().sendMatchChatMessage(messageText);
|
2024-03-18 19:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::sendMessageLobby(const std::string & senderName, const std::string & messageText)
|
|
|
|
{
|
|
|
|
LobbyChatMessage lcm;
|
2024-05-02 21:03:23 +02:00
|
|
|
MetaString txt;
|
|
|
|
txt.appendRawString(messageText);
|
|
|
|
lcm.message = txt;
|
2024-03-18 19:52:53 +02:00
|
|
|
lcm.playerName = senderName;
|
|
|
|
CSH->sendLobbyPack(lcm);
|
2024-03-20 18:40:37 +02:00
|
|
|
CSH->getGlobalLobby().sendMatchChatMessage(messageText);
|
2024-03-18 19:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::onNewLobbyMessageReceived(const std::string & senderName, const std::string & messageText)
|
|
|
|
{
|
2024-03-20 18:40:37 +02:00
|
|
|
if (!SEL)
|
|
|
|
{
|
|
|
|
logGlobal->debug("Received chat message for lobby but lobby not yet exists!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto * lobby = dynamic_cast<CLobbyScreen*>(SEL);
|
|
|
|
|
|
|
|
// FIXME: when can this happen?
|
|
|
|
assert(lobby);
|
|
|
|
assert(lobby->card);
|
2024-03-18 19:52:53 +02:00
|
|
|
|
|
|
|
if(lobby && lobby->card)
|
|
|
|
{
|
|
|
|
MetaString formatted = MetaString::createFromRawString("[%s] %s: %s");
|
2024-03-27 13:08:41 +02:00
|
|
|
formatted.replaceRawString(TextOperations::getCurrentFormattedTimeLocal());
|
2024-03-18 19:52:53 +02:00
|
|
|
formatted.replaceRawString(senderName);
|
2024-05-02 21:03:23 +02:00
|
|
|
formatted.replaceRawString(messageText);
|
2024-03-18 19:52:53 +02:00
|
|
|
|
|
|
|
lobby->card->chat->addNewMessage(formatted.toString());
|
2024-04-30 21:52:04 +02:00
|
|
|
if (!lobby->card->showChat)
|
|
|
|
lobby->toggleChat();
|
2024-03-18 19:52:53 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
chatHistory.push_back({senderName, messageText, TextOperations::getCurrentFormattedTimeLocal()});
|
2024-03-18 19:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::onNewGameMessageReceived(PlayerColor sender, const std::string & messageText)
|
|
|
|
{
|
2024-03-27 13:08:41 +02:00
|
|
|
|
|
|
|
std::string timeFormatted = TextOperations::getCurrentFormattedTimeLocal();
|
|
|
|
std::string playerName = "<UNKNOWN>";
|
|
|
|
|
|
|
|
if (sender.isValidPlayer())
|
|
|
|
playerName = LOCPLINT->cb->getStartInfo()->playerInfos.at(sender).name;
|
|
|
|
|
|
|
|
if (sender.isSpectator())
|
2024-12-01 20:00:24 +02:00
|
|
|
playerName = VLC->generaltexth->translate("vcmi.lobby.login.spectator");
|
2024-03-18 19:52:53 +02:00
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
chatHistory.push_back({playerName, messageText, timeFormatted});
|
2024-03-18 19:52:53 +02:00
|
|
|
|
2024-05-02 21:03:23 +02:00
|
|
|
LOCPLINT->cingconsole->addMessage(timeFormatted, playerName, messageText);
|
2024-03-18 19:52:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameChatHandler::onNewSystemMessageReceived(const std::string & messageText)
|
|
|
|
{
|
2024-05-02 21:03:23 +02:00
|
|
|
chatHistory.push_back({"System", messageText, TextOperations::getCurrentFormattedTimeLocal()});
|
2024-03-18 19:52:53 +02:00
|
|
|
|
|
|
|
if(LOCPLINT && !settings["session"]["hideSystemMessages"].Bool())
|
2024-05-02 21:03:23 +02:00
|
|
|
LOCPLINT->cingconsole->addMessage(TextOperations::getCurrentFormattedTimeLocal(), "System", messageText);
|
2024-05-01 15:00:36 +02:00
|
|
|
}
|