2018-07-07 16:20:25 +00:00
|
|
|
#include "Chat.hpp"
|
|
|
|
|
|
|
|
#include <components/openmw-mp/NetworkMessages.hpp>
|
|
|
|
#include <components/openmw-mp/Log.hpp>
|
|
|
|
|
2016-01-12 03:41:44 +00:00
|
|
|
#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
|
|
|
|
#include <apps/openmw-mp/Networking.hpp>
|
|
|
|
|
2018-07-07 17:08:59 +00:00
|
|
|
void ChatFunctions::SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers, bool skipAttachedPlayer) noexcept
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
2017-01-25 15:19:53 +00:00
|
|
|
player->chatMessage = message;
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2016-11-17 16:35:30 +00:00
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "System: %s", message);
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE);
|
|
|
|
packet->setPlayer(player);
|
2017-12-30 19:52:30 +00:00
|
|
|
|
2018-07-07 17:08:59 +00:00
|
|
|
if (!skipAttachedPlayer)
|
2018-07-07 15:29:31 +00:00
|
|
|
packet->Send(false);
|
|
|
|
if (sendToOtherPlayers)
|
|
|
|
packet->Send(true);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 16:20:25 +00:00
|
|
|
void ChatFunctions::CleanChatForPid(unsigned short pid)
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-06-12 00:01:23 +00:00
|
|
|
Player *player;
|
|
|
|
GET_PLAYER(pid, player,);
|
|
|
|
|
|
|
|
player->chatMessage.clear();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE);
|
|
|
|
packet->setPlayer(player);
|
2017-06-12 00:01:23 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
packet->Send(false);
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|
|
|
|
|
2018-07-07 16:20:25 +00:00
|
|
|
void ChatFunctions::CleanChat()
|
2016-01-12 03:41:44 +00:00
|
|
|
{
|
2017-06-12 00:01:23 +00:00
|
|
|
for (auto player : *Players::getPlayers())
|
|
|
|
{
|
|
|
|
player.second->chatMessage.clear();
|
2016-01-12 03:41:44 +00:00
|
|
|
|
2018-07-07 15:29:31 +00:00
|
|
|
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE);
|
|
|
|
packet->setPlayer(player.second);
|
|
|
|
|
|
|
|
packet->Send(false);
|
2017-06-12 00:01:23 +00:00
|
|
|
}
|
2016-01-12 03:41:44 +00:00
|
|
|
}
|