|
| 1 | +using OWML.Common; |
| 2 | +using UnityEngine.Events; |
| 3 | + |
| 4 | +public interface IQSBAPI |
| 5 | +{ |
| 6 | + /// <summary> |
| 7 | + /// If called, all players connected to YOUR hosted game must have this mod installed. |
| 8 | + /// </summary> |
| 9 | + void RegisterRequiredForAllPlayers(IModBehaviour mod); |
| 10 | + |
| 11 | + /// <summary> |
| 12 | + /// Returns the player ID of the current player. |
| 13 | + /// </summary> |
| 14 | + uint GetLocalPlayerID(); |
| 15 | + |
| 16 | + /// <summary> |
| 17 | + /// Returns the name of a given player. |
| 18 | + /// </summary> |
| 19 | + /// <param name="playerID">The ID of the player you want the name of.</param> |
| 20 | + string GetPlayerName(uint playerID); |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Returns the list of IDs of all connected players. |
| 24 | + /// </summary> |
| 25 | + uint[] GetPlayerIDs(); |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// Invoked when a player joins the game. |
| 29 | + /// </summary> |
| 30 | + UnityEvent<uint> OnPlayerJoin(); |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Invoked when a player leaves the game. |
| 34 | + /// </summary> |
| 35 | + UnityEvent<uint> OnPlayerLeave(); |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Sets some arbitrary data for a given player. |
| 39 | + /// </summary> |
| 40 | + /// <typeparam name="T">The type of the data.</typeparam> |
| 41 | + /// <param name="playerId">The ID of the player.</param> |
| 42 | + /// <param name="key">The unique key to access this data by.</param> |
| 43 | + /// <param name="data">The data to set.</param> |
| 44 | + void SetCustomData<T>(uint playerId, string key, T data); |
| 45 | + |
| 46 | + /// <summary> |
| 47 | + /// Returns some arbitrary data from a given player. |
| 48 | + /// </summary> |
| 49 | + /// <typeparam name="T">The type of the data.</typeparam> |
| 50 | + /// <param name="playerId">The ID of the player.</param> |
| 51 | + /// <param name="key">The unique key of the data you want to access.</param> |
| 52 | + /// <returns>The data requested. If key is not valid, returns default.</returns> |
| 53 | + T GetCustomData<T>(uint playerId, string key); |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Sends a message containing arbitrary data to every player. |
| 57 | + /// </summary> |
| 58 | + /// <typeparam name="T">The type of the data being sent. This type must be serializable.</typeparam> |
| 59 | + /// <param name="messageType">The unique key of the message.</param> |
| 60 | + /// <param name="data">The data to send.</param> |
| 61 | + /// <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> |
| 62 | + void SendMessage<T>(string messageType, T data, bool receiveLocally = false); |
| 63 | + |
| 64 | + /// <summary> |
| 65 | + /// Registers an action to be called when a message is received. |
| 66 | + /// </summary> |
| 67 | + /// <typeparam name="T">The type of the data in the message.</typeparam> |
| 68 | + /// <param name="messageType">The unique key of the message.</param> |
| 69 | + /// <param name="handler">The action to be ran when the message is received. The uint is the player ID that sent the messsage.</param> |
| 70 | + void RegisterHandler<T>(string messageType, Action<uint, T> handler); |
| 71 | +} |
0 commit comments