[Server] Move Chat functions to new ChatFunctions class

0.6.3
David Cernat 7 years ago
parent 6a3fbf4e98
commit 6041425122

@ -1,8 +1,12 @@
#include "Chat.hpp"
#include <components/openmw-mp/NetworkMessages.hpp>
#include <components/openmw-mp/Log.hpp>
#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
void ChatFunctions::SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers, bool sendToAttachedPlayer) noexcept
{
Player *player;
GET_PLAYER(pid, player,);
@ -20,7 +24,7 @@ void ScriptFunctions::SendMessage(unsigned short pid, const char *message, bool
packet->Send(true);
}
void ScriptFunctions::CleanChatForPid(unsigned short pid)
void ChatFunctions::CleanChatForPid(unsigned short pid)
{
Player *player;
GET_PLAYER(pid, player,);
@ -33,7 +37,7 @@ void ScriptFunctions::CleanChatForPid(unsigned short pid)
packet->Send(false);
}
void ScriptFunctions::CleanChat()
void ChatFunctions::CleanChat()
{
for (auto player : *Players::getPlayers())
{

@ -0,0 +1,44 @@
#ifndef OPENMW_CHATAPI_HPP
#define OPENMW_CHATAPI_HPP
#include "../Types.hpp"
#define CHATAPI \
{"SendMessage", ChatFunctions::SendMessage},\
{"CleanChatForPid", ChatFunctions::CleanChat},\
{"CleanChat", ChatFunctions::CleanChatForPid}
class ChatFunctions
{
public:
/**
* \brief Send a message to a certain player.
*
* \param pid The player ID.
* \param message The contents of the message.
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
* player attached to the packet (false by default).
* \param sendToAttachedPlayer Whether the packet should be sent to the player attached
* to the packet (true by default).
* \return void
*/
static void SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept;
/**
* \brief Remove all messages from chat for a certain player.
*
* \param pid The player ID.
* \return void
*/
static void CleanChatForPid(unsigned short pid);
/**
* \brief Remove all messages from chat for everyone on the server.
*
* \return void
*/
static void CleanChat();
};
#endif //OPENMW_CHATAPI_HPP

@ -1,7 +1,3 @@
//
// Created by koncord on 24.01.16.
//
#ifndef SCRIPTFUNCTIONS_HPP
#define SCRIPTFUNCTIONS_HPP
@ -9,6 +5,7 @@
#include <Script/Functions/Books.hpp>
#include <Script/Functions/Cells.hpp>
#include <Script/Functions/CharClass.hpp>
#include <Script/Functions/Chat.hpp>
#include <Script/Functions/Dialogue.hpp>
#include <Script/Functions/Factions.hpp>
#include <Script/Functions/GUI.hpp>
@ -56,34 +53,6 @@ public:
*/
static void StopServer(int code) noexcept;
/**
* \brief Send a message to a certain player.
*
* \param pid The player ID.
* \param message The contents of the message.
* \param sendToOtherPlayers Whether this packet should be sent to players other than the
* player attached to the packet (false by default).
* \param sendToAttachedPlayer Whether the packet should be sent to the player attached
* to the packet (true by default).
* \return void
*/
static void SendMessage(unsigned short pid, const char *message, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept;
/**
* \brief Remove all messages from chat for a certain player.
*
* \param pid The player ID.
* \return void
*/
static void CleanChatForPid(unsigned short pid);
/**
* \brief Remove all messages from chat for everyone on the server.
*
* \return void
*/
static void CleanChat();
/**
* \brief Create a timer that will run a script function after a certain interval.
*
@ -260,8 +229,6 @@ public:
{"StopServer", ScriptFunctions::StopServer},
{"SendMessage", ScriptFunctions::SendMessage},
{"Kick", ScriptFunctions::Kick},
{"BanAddress", ScriptFunctions::BanAddress},
{"UnbanAddress", ScriptFunctions::UnbanAddress},
@ -274,14 +241,13 @@ public:
{"SetServerPassword", ScriptFunctions::SetServerPassword},
{"SetRuleString", ScriptFunctions::SetRuleString},
{"SetRuleValue", ScriptFunctions::SetRuleValue},
{"CleanChatForPid", ScriptFunctions::CleanChatForPid},
{"CleanChat", ScriptFunctions::CleanChat},
{"GetIP", ScriptFunctions::GetIP},
ACTORAPI,
BOOKAPI,
CELLAPI,
CHARCLASSAPI,
CHATAPI,
DIALOGUEAPI,
FACTIONAPI,
GUIAPI,

Loading…
Cancel
Save