LethalNetworkAPI.LNetworkMessage<TData> Class
Used to send data between clients (and the server/host).
public sealed class LNetworkMessage<TData>
Type Parameters
Type | Description |
---|---|
TData | The type of data to send. |
Inheritance
↳ System.Object
↳ LNetworkMessage<TData>
Remarks
Will not interact with LNetworkEvent, LNetworkVariable<TData>,
nor with other mods - even if the identifier is not unique.
Methods
ClearSubscriptions()
Clear all subscriptions to all callbacks on this LNetworkMessage<TData>.
Declaration
public void ClearSubscriptions()
Connect(string, Action<TData,ulong>?, Action<TData>?, Action<TData,ulong>?)
Create a new LNetworkMessage<TData> if it doesn't already exist, otherwise return the existing message of the same identifier.
Declaration
public static LNetworkMessage<TData> Connect(string identifier, Action<TData, ulong>? onServerReceived = null, Action<TData>? onClientReceived = null, Action<TData, ulong>? onClientReceivedFromClient = null)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | The identifier of the LNetworkMessage<TData>. |
Action<TData, ulong>? | onServerReceived | [Opt.] The method to run when the server receives a message. |
Action<TData>? | onClientReceived | [Opt.] The method to run when the client receives a message. |
Action<TData, ulong>? | onClientReceivedFromClient | [Opt.] The method to run when the client receives a message from another client. |
Returns
Type | Description |
---|---|
LNetworkMessage<TData> | The LNetworkMessage<TData>. |
Create(string, Action<TData,ulong>, Action<TData>, Action<TData,ulong>)
Create a new LNetworkMessage<TData>. If it already exists, an exception will be thrown.
Declaration
public static LNetworkMessage<TData> Create(string identifier, Action<TData, ulong>? onServerReceived = null, Action<TData>? onClientReceived = null, Action<TData, ulong>? onClientReceivedFromClient = null)
Parameters
Type | Name | Description |
---|---|---|
string | identifier | The identifier of the LNetworkMessage<TData>. |
Action<TData, ulong>? | onServerReceived | [Opt.] The method to run when the server receives a message. |
Action<TData>? | onClientReceived | [Opt.] The method to run when the client receives a message. |
Action<TData, ulong>? | onClientReceivedFromClient | [Opt.] The method to run when the client receives a message from another client. |
Returns
Type | Description |
---|---|
LNetworkMessage<TData> | The LNetworkMessage<TData>. |
Exceptions
Type | Description |
---|---|
InvalidOperationException | Thrown if the LNetworkMessage<TData> already exists. |
SendClient(TData, int)
Server-only method to send data to a specific client.
Declaration
public void SendClient(TData data, int playerId)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
int | playerId | The in-game ids of the client to send the data to. |
SendClient(TData, ulong)
Server-only method to send data to a specific client.
Declaration
public void SendClient(TData data, ulong clientGuid)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
ulong | clientGuid | The NGO guid of the client to send the data to. |
SendClients(TData, int[])
Server-only method to send data to the specified clients.
Declaration
public void SendClients(TData data, int[] playerIdArray)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
int[] | playerIdArray | The in-game ids of the clients to send the data to. |
SendClients(TData, ulong[])
Server-only method to send data to the specified clients.
Declaration
public void SendClients(TData data, ulong[] clientGuidArray)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
ulong[] | clientGuidArray | The NGO guids of the clients to send the data to. |
SendClients(TData)
Server-only method to send data to all clients.
Declaration
public void SendClients(TData data)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
SendOtherClients(TData, int[])
Client method to send data to the specified clients.
Declaration
public void SendOtherClients(TData data, int[] playerIdArray)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
int[] | playerIdArray | The in-game ids of the clients to send the data to. |
SendOtherClients(TData, ulong[])
Client method to send data to the specified clients.
Declaration
public void SendOtherClients(TData data, ulong[] clientGuidArray)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
ulong[] | clientGuidArray | The NGO guids of the clients to send the data to. |
SendOtherClients(TData)
Client method to send data to all clients.
Declaration
public void SendOtherClients(TData data)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
SendServer(TData)
Client method to send data to the server/host.
Declaration
public void SendServer(TData data)
Parameters
Type | Name | Description |
---|---|---|
TData | data | The data to send. |
Events
OnClientReceived
A callback that runs when the client receives a message.
Declaration
public event Action<TData>? OnClientReceived;
Type Parameters
Type | Description |
---|---|
TData | The received data. |
OnClientReceivedFromClient
A callback that runs when the client receives a message from another client.
Declaration
public event Action<TData, ulong>? OnClientReceivedFromClient;
Type Parameters
Type | Description |
---|---|
TData | The received data. |
ulong | The origin client ID. |
OnServerReceived
A callback that runs when the server receives a message.
Declaration
public event Action<TData, ulong>? OnServerReceived;
Type Parameters
Type | Description |
---|---|
TData | The received data. |
ulong | The origin client ID. |