mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 07:45:32 +00:00
6a3fbf4e98
Previously, there was a confusing separation between script functions that had a "broadcast" argument and script functions that had a "toOthers" argument. Those with broadcast sent the packet to all players on the server when broadcast was true. Those with toOthers sent the packet to all players other than the packet's attached player. The former was based on the pattern of the original SendMessage() script function. The latter more closely resembled RakNet's own broadcast argument as seen here: https://github.com/TES3MP/CrabNet/blob/master/include/raknet/RakPeer.h#L219 This commit makes it so all sending functions have a sendToOtherPlayers argument that is false by default and a sendToAttachedPlayer that is true by default. This should simultaneously allow sending to be more intuitive, while not breaking previous existing scripts to a significant degree. Additionally, this commit also reduces some code repetition for all instances of packet-fetching in script functions.
158 lines
5.6 KiB
C++
158 lines
5.6 KiB
C++
#ifndef OPENMW_FACTIONAPI_HPP
|
|
#define OPENMW_FACTIONAPI_HPP
|
|
|
|
#define FACTIONAPI \
|
|
{"InitializeFactionChanges", FactionFunctions::InitializeFactionChanges},\
|
|
\
|
|
{"GetFactionChangesSize", FactionFunctions::GetFactionChangesSize},\
|
|
{"GetFactionChangesAction", FactionFunctions::GetFactionChangesAction},\
|
|
\
|
|
{"GetFactionId", FactionFunctions::GetFactionId},\
|
|
{"GetFactionRank", FactionFunctions::GetFactionRank},\
|
|
{"GetFactionExpulsionState", FactionFunctions::GetFactionExpulsionState},\
|
|
{"GetFactionReputation", FactionFunctions::GetFactionReputation},\
|
|
\
|
|
{"SetFactionChangesAction", FactionFunctions::SetFactionChangesAction},\
|
|
{"SetFactionId", FactionFunctions::SetFactionId},\
|
|
{"SetFactionRank", FactionFunctions::SetFactionRank},\
|
|
{"SetFactionExpulsionState", FactionFunctions::SetFactionExpulsionState},\
|
|
{"SetFactionReputation", FactionFunctions::SetFactionReputation},\
|
|
\
|
|
{"AddFaction", FactionFunctions::AddFaction},\
|
|
\
|
|
{"SendFactionChanges", FactionFunctions::SendFactionChanges}
|
|
|
|
class FactionFunctions
|
|
{
|
|
public:
|
|
|
|
/**
|
|
* \brief Clear the last recorded faction changes for a player.
|
|
*
|
|
* This is used to initialize the sending of new PlayerFaction packets.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \return void
|
|
*/
|
|
static void InitializeFactionChanges(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \brief Get the number of indexes in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \return The number of indexes.
|
|
*/
|
|
static unsigned int GetFactionChangesSize(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \brief Get the action type used in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \return The action type (0 for RANK, 1 for EXPULSION, 2 for REPUTATION).
|
|
*/
|
|
static unsigned char GetFactionChangesAction(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \brief Get the factionId at a certain index in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \param i The index of the faction.
|
|
* \return The factionId.
|
|
*/
|
|
static const char *GetFactionId(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \brief Get the rank at a certain index in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \param i The index of the faction.
|
|
* \return The rank.
|
|
*/
|
|
static int GetFactionRank(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \brief Get the expulsion state at a certain index in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \param i The index of the faction.
|
|
* \return The expulsion state.
|
|
*/
|
|
static bool GetFactionExpulsionState(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \brief Get the reputation at a certain index in a player's latest faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \param i The index of the faction.
|
|
* \return The reputation.
|
|
*/
|
|
static int GetFactionReputation(unsigned short pid, unsigned int i) noexcept;
|
|
|
|
/**
|
|
* \brief Set the action type in a player's faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \param action The action (0 for RANK, 1 for EXPULSION, 2 for REPUTATION).
|
|
* \return void
|
|
*/
|
|
static void SetFactionChangesAction(unsigned short pid, unsigned char action) noexcept;
|
|
|
|
/**
|
|
* \brief Set the factionId of the temporary faction stored on the server.
|
|
*
|
|
* \param factionId The factionId.
|
|
* \return void
|
|
*/
|
|
static void SetFactionId(const char* factionId) noexcept;
|
|
|
|
/**
|
|
* \brief Set the rank of the temporary faction stored on the server.
|
|
*
|
|
* \param rank The rank.
|
|
* \return void
|
|
*/
|
|
static void SetFactionRank(unsigned int rank) noexcept;
|
|
|
|
/**
|
|
* \brief Set the expulsion state of the temporary faction stored on the server.
|
|
*
|
|
* \param expulsionState The expulsion state.
|
|
* \return void
|
|
*/
|
|
static void SetFactionExpulsionState(bool expulsionState) noexcept;
|
|
|
|
/**
|
|
* \brief Set the reputation of the temporary faction stored on the server.
|
|
*
|
|
* \param reputation The reputation.
|
|
* \return void
|
|
*/
|
|
static void SetFactionReputation(int reputation) noexcept;
|
|
|
|
/**
|
|
* \brief Add the server's temporary faction to the faction changes for a player.
|
|
*
|
|
* In the process, the server's temporary faction will automatically be cleared so a new one
|
|
* can be set up.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \return void
|
|
*/
|
|
static void AddFaction(unsigned short pid) noexcept;
|
|
|
|
/**
|
|
* \brief Send a PlayerFaction packet with a player's recorded faction changes.
|
|
*
|
|
* \param pid The player ID whose faction changes should be used.
|
|
* \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 SendFactionChanges(unsigned short pid, bool sendToOtherPlayers = false, bool sendToAttachedPlayer = true) noexcept;
|
|
private:
|
|
|
|
};
|
|
|
|
#endif //OPENMW_FACTIONAPI_HPP
|