Class NetworkServer
The NetworkServer.
Inheritance
Syntax
public class NetworkServer : MonoBehaviour
Fields
EnablePeerMetrics
Declaration
public bool EnablePeerMetrics
MetricsSize
Declaration
public int MetricsSize
MaxConnections
The maximum number of concurrent network connections to support. Excluding the host player. This field is only used if the property is null
Declaration
public int MaxConnections
DisconnectOnException
Declaration
public bool DisconnectOnException
RethrowException
Declaration
public bool RethrowException
RunInBackground
Declaration
public bool RunInBackground
Listening
Declaration
public bool Listening
SocketFactory
Declaration
public SocketFactory SocketFactory
ObjectManager
Declaration
public ServerObjectManager ObjectManager
Authenticator
Declaration
public AuthenticatorSettings Authenticator
ManualUpdate
Set to true if you want to manually call and and stop mirage from automatically calling them
Declaration
public bool ManualUpdate
Properties
Metrics
Declaration
public Metrics Metrics { get; }
PeerConfig
Config for peer, if not set will use default settings
Declaration
public Config PeerConfig { get; set; }
PeerPoolMetrics
Declaration
public PoolMetrics? PeerPoolMetrics { get; }
Started
This is invoked when a server is started - including when a host is started.
Declaration
public IAddLateEventUnity Started { get; }
Connected
Declaration
public NetworkPlayerEvent Connected { get; }
Authenticated
Declaration
public NetworkPlayerEvent Authenticated { get; }
Disconnected
Declaration
public NetworkPlayerEvent Disconnected { get; }
Stopped
Declaration
public IAddLateEventUnity Stopped { get; }
OnStartHost
Declaration
public IAddLateEventUnity OnStartHost { get; }
OnStopHost
Declaration
public IAddLateEventUnity OnStopHost { get; }
LocalPlayer
The connection to the host mode client (if any).
Declaration
public INetworkPlayer LocalPlayer { get; }
LocalClient
The host client for this server
Declaration
public NetworkClient LocalClient { get; }
LocalClientActive
True if there is a local client connected to this server (host mode)
Declaration
[Obsolete("use IsHost instead")]
public bool LocalClientActive { get; }
IsHost
True if there is a local client connected to this server (host mode)
Declaration
public bool IsHost { get; }
AllPlayers
All players on server (including unauthenticated players)
Declaration
public IReadOnlyCollection<INetworkPlayer> AllPlayers { get; }
Players
Declaration
[Obsolete("Use AllPlayers or AuthenticatedPlayers instead")]
public IReadOnlyCollection<INetworkPlayer> Players { get; }
AuthenticatedPlayers
List of players that have Authenticated with server
Declaration
public IReadOnlyList<INetworkPlayer> AuthenticatedPlayers { get; }
Active
Checks if the server has been started. This will be true after NetworkServer.Listen() has been called.
Declaration
public bool Active { get; }
World
Declaration
public NetworkWorld World { get; }
SyncVarSender
Declaration
public SyncVarSender SyncVarSender { get; }
MessageHandler
Declaration
public MessageHandler MessageHandler { get; }
Methods
Stop()
This shuts down the server and disconnects all clients. If In host mode, this will also stop the local client
Declaration
public void Stop()
StartServer(NetworkClient)
Start the server If localClient is given then will start in host mode
Declaration
public void StartServer(NetworkClient localClient = null)
Parameters
Type | Name | Description |
---|---|---|
Mirage.NetworkClient | localClient | if not null then start the server and client in hostmode |
UpdateReceive()
Declaration
public void UpdateReceive()
UpdateSent()
Declaration
public void UpdateSent()
SetAuthenticationFailedCallback(Action<INetworkPlayer, AuthenticationResult>)
Declaration
public void SetAuthenticationFailedCallback(Action<INetworkPlayer, AuthenticationResult> callback)
Parameters
Type | Name | Description |
---|---|---|
System.Action<Mirage.INetworkPlayer, Mirage.Authentication.AuthenticationResult> | callback |
SendToAll<T>(T, Boolean, Channel)
Declaration
[Obsolete("Use SendToAll(msg, authenticatedOnly, excludeLocalPlayer, channelId) instead")]
public void SendToAll<T>(T msg, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
T | msg | |
System.Boolean | excludeLocalPlayer | |
Mirage.Channel | channelId |
SendToAll<T>(T, Boolean, Boolean, Channel)
Declaration
public void SendToAll<T>(T msg, bool authenticatedOnly, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
T | msg | |
System.Boolean | authenticatedOnly | |
System.Boolean | excludeLocalPlayer | |
Mirage.Channel | channelId |
SendToMany<T>(IReadOnlyList<INetworkPlayer>, T, Boolean, Channel)
Declaration
public void SendToMany<T>(IReadOnlyList<INetworkPlayer> players, T msg, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IReadOnlyList<Mirage.INetworkPlayer> | players | |
T | msg | |
System.Boolean | excludeLocalPlayer | |
Mirage.Channel | channelId |
SendToMany<T>(IEnumerable<INetworkPlayer>, T, Boolean, Channel)
Warning: this will allocate, Use or instead
Declaration
public void SendToMany<T>(IEnumerable<INetworkPlayer> players, T msg, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Mirage.INetworkPlayer> | players | |
T | msg | |
System.Boolean | excludeLocalPlayer | |
Mirage.Channel | channelId |
SendToMany<T, TEnumerator>(TEnumerator, T, Boolean, Channel)
use to avoid allocation of IEnumerator
Declaration
public void SendToMany<T, TEnumerator>(TEnumerator playerEnumerator, T msg, bool excludeLocalPlayer, Channel channelId = Channel.Reliable)
where TEnumerator : struct, IEnumerator<INetworkPlayer>
Parameters
Type | Name | Description |
---|---|---|
TEnumerator | playerEnumerator | |
T | msg | |
System.Boolean | excludeLocalPlayer | |
Mirage.Channel | channelId |
SendToObservers<T>(NetworkIdentity, T, Boolean, Boolean, Channel)
Declaration
public void SendToObservers<T>(NetworkIdentity identity, T msg, bool excludeLocalPlayer, bool excludeOwner, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
Mirage.NetworkIdentity | identity | |
T | msg | |
System.Boolean | excludeLocalPlayer | |
System.Boolean | excludeOwner | |
Mirage.Channel | channelId |
SendToMany<T>(List<INetworkPlayer>, T, Channel)
Sends to list of players. All other SendTo... functions call this, it dooes not do any extra checks, just serializes message if not empty, then sends it
Declaration
public static void SendToMany<T>(List<INetworkPlayer> players, T msg, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<Mirage.INetworkPlayer> | players | |
T | msg | |
Mirage.Channel | channelId |
SendToMany<T>(IReadOnlyList<INetworkPlayer>, T, Channel)
Sends to list of players. All other SendTo... functions call this, it dooes not do any extra checks, just serializes message if not empty, then sends it
Declaration
public static void SendToMany<T>(IReadOnlyList<INetworkPlayer> players, T msg, Channel channelId = Channel.Reliable)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IReadOnlyList<Mirage.INetworkPlayer> | players | |
T | msg | |
Mirage.Channel | channelId |