using System; using OWML.Common; using UnityEngine.Events; public interface IQSBAPI { #region General /// /// If called, all players connected to YOUR hosted game must have this mod installed. /// void RegisterRequiredForAllPlayers(IModBehaviour mod); /// /// Returns if the current player is the host. /// bool GetIsHost(); /// /// Returns if the current player is in multiplayer. /// bool GetIsInMultiplayer(); #endregion #region Player /// /// Returns the player ID of the current player. /// uint GetLocalPlayerID(); /// /// Returns the name of a given player. /// /// The ID of the player you want the name of. string GetPlayerName(uint playerID); /// /// Returns the list of IDs of all connected players. /// /// The first player in the list is the host. /// uint[] GetPlayerIDs(); /// /// Invoked when any player (local or remote) joins the game. /// UnityEvent OnPlayerJoin(); /// /// Invoked when any player (local or remote) leaves the game. /// UnityEvent OnPlayerLeave(); /// /// Sets some arbitrary data for a given player. /// /// The type of the data. If not serializable, data will not be synced. /// The ID of the player. /// The unique key to access this data by. /// The data to set. void SetCustomData(uint playerId, string key, T data); /// /// Returns some arbitrary data from a given player. /// /// The type of the data. /// The ID of the player. /// The unique key of the data you want to access. /// The data requested. If key is not valid, returns default. T GetCustomData(uint playerId, string key); #endregion #region Messaging /// /// Sends a message containing arbitrary data to every player. /// /// Keep your messages under around 1100 bytes. /// /// The type of the data being sent. This type must be serializable. /// The unique key of the message. /// The data to send. /// The player to send this message to. (0 is the host, uint.MaxValue means every player) /// If true, the action given to will also be called on the same client that is sending the message. void SendMessage(string messageType, T data, uint to = uint.MaxValue, bool receiveLocally = false); /// /// Registers an action to be called when a message is received. /// /// The type of the data in the message. /// The unique key of the message. /// The action to be ran when the message is received. The uint is the player ID that sent the messsage. void RegisterHandler(string messageType, Action handler); #endregion }