2023-07-31 21:49:32 +00:00
using System ;
using OWML.Common ;
2023-07-31 19:51:20 +00:00
using UnityEngine.Events ;
2023-07-31 18:55:17 +00:00
public interface IQSBAPI
{
2023-08-02 19:01:30 +00:00
#region General
2023-07-31 20:22:54 +00:00
/// <summary>
/// If called, all players connected to YOUR hosted game must have this mod installed.
/// </summary>
void RegisterRequiredForAllPlayers ( IModBehaviour mod ) ;
2023-07-31 19:51:20 +00:00
/// <summary>
2023-08-02 03:42:27 +00:00
/// Returns if the current player is the host.
2023-07-31 19:51:20 +00:00
/// </summary>
2023-08-02 03:42:27 +00:00
bool GetIsHost ( ) ;
2023-07-31 18:55:17 +00:00
2023-08-02 01:08:09 +00:00
/// <summary>
2023-08-02 03:42:27 +00:00
/// Returns if the current player is in multiplayer.
2023-08-02 01:08:09 +00:00
/// </summary>
2023-08-02 03:42:27 +00:00
bool GetIsInMultiplayer ( ) ;
2023-08-02 19:01:30 +00:00
#endregion
#region Player
2023-08-02 03:42:27 +00:00
/// <summary>
/// Returns the player ID of the current player.
/// </summary>
uint GetLocalPlayerID ( ) ;
2023-08-02 01:08:09 +00:00
2023-07-31 19:51:20 +00:00
/// <summary>
/// Returns the name of a given player.
/// </summary>
/// <param name="playerID">The ID of the player you want the name of.</param>
string GetPlayerName ( uint playerID ) ;
/// <summary>
/// Returns the list of IDs of all connected players.
2023-08-02 10:36:30 +00:00
///
/// The first player in the list is the host.
2023-07-31 19:51:20 +00:00
/// </summary>
uint [ ] GetPlayerIDs ( ) ;
/// <summary>
2023-08-02 10:36:30 +00:00
/// Invoked when any player (local or remote) joins the game.
2023-07-31 19:51:20 +00:00
/// </summary>
UnityEvent < uint > OnPlayerJoin ( ) ;
/// <summary>
2023-08-02 10:36:30 +00:00
/// Invoked when any player (local or remote) leaves the game.
2023-07-31 19:51:20 +00:00
/// </summary>
UnityEvent < uint > OnPlayerLeave ( ) ;
2023-08-02 10:36:30 +00:00
/// <summary>
2023-07-31 19:51:20 +00:00
/// Sets some arbitrary data for a given player.
/// </summary>
2023-08-09 03:16:18 +00:00
/// <typeparam name="T">The type of the data. If not serializable, data will not be synced.</typeparam>
2023-07-31 19:51:20 +00:00
/// <param name="playerId">The ID of the player.</param>
/// <param name="key">The unique key to access this data by.</param>
/// <param name="data">The data to set.</param>
2023-07-31 18:55:17 +00:00
void SetCustomData < T > ( uint playerId , string key , T data ) ;
2023-07-31 19:51:20 +00:00
/// <summary>
/// Returns some arbitrary data from a given player.
/// </summary>
/// <typeparam name="T">The type of the data.</typeparam>
/// <param name="playerId">The ID of the player.</param>
/// <param name="key">The unique key of the data you want to access.</param>
/// <returns>The data requested. If key is not valid, returns default.</returns>
2023-07-31 18:55:17 +00:00
T GetCustomData < T > ( uint playerId , string key ) ;
2023-08-02 19:01:30 +00:00
#endregion
#region Messaging
2023-07-31 19:51:20 +00:00
/// <summary>
/// Sends a message containing arbitrary data to every player.
2023-08-02 10:36:30 +00:00
///
/// Keep your messages under around 1100 bytes.
2023-07-31 19:51:20 +00:00
/// </summary>
/// <typeparam name="T">The type of the data being sent. This type must be serializable.</typeparam>
/// <param name="messageType">The unique key of the message.</param>
/// <param name="data">The data to send.</param>
2023-07-31 21:49:32 +00:00
/// <param name="to">The player to send this message to. (0 is the host, uint.MaxValue means every player)</param>
2023-07-31 19:51:20 +00:00
/// <param name="receiveLocally">If true, the action given to <see cref="RegisterHandler{T}"/> will also be called on the same client that is sending the message.</param>
2023-07-31 21:49:32 +00:00
void SendMessage < T > ( string messageType , T data , uint to = uint . MaxValue , bool receiveLocally = false ) ;
2023-07-31 19:51:20 +00:00
/// <summary>
/// Registers an action to be called when a message is received.
/// </summary>
/// <typeparam name="T">The type of the data in the message.</typeparam>
/// <param name="messageType">The unique key of the message.</param>
/// <param name="handler">The action to be ran when the message is received. The uint is the player ID that sent the messsage.</param>
2023-07-31 18:55:17 +00:00
void RegisterHandler < T > ( string messageType , Action < uint , T > handler ) ;
2023-08-02 19:01:30 +00:00
#endregion
2023-07-31 20:22:54 +00:00
}