add To to api messages

This commit is contained in:
_nebula 2023-07-31 22:44:42 +01:00
parent b2962e19ca
commit ad218e82e2
2 changed files with 5 additions and 4 deletions

View File

@ -59,8 +59,9 @@ public interface IQSBAPI
/// <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>
/// <param name="to">The player to send this message to. (0 is the host, uint.MaxValue means every player)</param>
/// <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>
void SendMessage<T>(string messageType, T data, bool receiveLocally = false);
void SendMessage<T>(string messageType, T data, uint to = uint.MaxValue, bool receiveLocally = false);
/// <summary>
/// Registers an action to be called when a message is received.

View File

@ -27,8 +27,8 @@ public class QSBAPI : IQSBAPI
public void SetCustomData<T>(uint playerId, string key, T data) => QSBPlayerManager.GetPlayer(playerId).SetCustomData(key, data);
public T GetCustomData<T>(uint playerId, string key) => QSBPlayerManager.GetPlayer(playerId).GetCustomData<T>(key);
public void SendMessage<T>(string messageType, T data, bool receiveLocally = false)
=> new AddonDataMessage(messageType, data, receiveLocally).Send();
public void SendMessage<T>(string messageType, T data, uint to = uint.MaxValue, bool receiveLocally = false)
=> new AddonDataMessage(messageType, data, receiveLocally) {To = to} .Send();
public void RegisterHandler<T>(string messageType, Action<uint, T> handler)
=> AddonDataManager.RegisterHandler(messageType, handler);