openmw-tes3coop/apps/openmw-mp/Script/Functions/Chat.cpp

48 lines
1.3 KiB
C++
Raw Normal View History

#include <apps/openmw-mp/Script/ScriptFunctions.hpp>
#include <apps/openmw-mp/Networking.hpp>
#include <components/openmw-mp/NetworkMessages.hpp>
void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
player->chatMessage = message;
2016-11-17 16:35:30 +00:00
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "System: %s", message);
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE);
packet->setPlayer(player);
if (sendToAttachedPlayer)
packet->Send(false);
if (sendToOtherPlayers)
packet->Send(true);
}
void ScriptFunctions::CleanChatForPid(unsigned short pid)
{
2017-06-12 00:01:23 +00:00
Player *player;
GET_PLAYER(pid, player,);
player->chatMessage.clear();
mwmp::PlayerPacket *packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_CHAT_MESSAGE);
packet->setPlayer(player);
2017-06-12 00:01:23 +00:00
packet->Send(false);
}
void ScriptFunctions::CleanChat()
{
2017-06-12 00:01:23 +00:00
for (auto player : *Players::getPlayers())
{
player.second->chatMessage.clear();
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
}
}