Class ServerManager
A container for server data and actions.
Inheritance
Inherited Members
Namespace: FishNet.Managing.Server
Assembly: FishNet.Runtime.dll
Syntax
[DisallowMultipleComponent]
[AddComponentMenu("FishNet/Manager/ServerManager")]
public sealed class ServerManager : MonoBehaviour
Fields
Clients
Authenticated and non-authenticated connected clients.
Declaration
[HideInInspector]
public Dictionary<int, NetworkConnection> Clients
Field Value
Type | Description |
---|---|
System.Collections.Generic.Dictionary<System.Int32, NetworkConnection> |
MAXIMUM_REMOTE_CLIENT_TIMEOUT_DURATION
Maximum value the remote client timeout can be set to.
Declaration
public const ushort MAXIMUM_REMOTE_CLIENT_TIMEOUT_DURATION = 1500
Field Value
Type | Description |
---|---|
System.UInt16 |
Properties
NetworkManager
NetworkManager for server.
Declaration
[HideInInspector]
public NetworkManager NetworkManager { get; }
Property Value
Type | Description |
---|---|
NetworkManager |
Objects
Handling and information for objects on the server.
Declaration
public ServerObjects Objects { get; }
Property Value
Type | Description |
---|---|
ServerObjects |
ShareIds
True to share the Ids of clients and the objects they own with other clients. No sensitive information is shared.
Declaration
public bool ShareIds { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Started
True if the server connection has started.
Declaration
public bool Started { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
AnyServerStarted(Nullable<Int32>)
Returns true if any server socket is in the started state.
Declaration
public bool AnyServerStarted(int? excludedIndex = null)
Parameters
Type | Name | Description |
---|---|---|
System.Nullable<System.Int32> | excludedIndex | When set the transport on this index will be ignored. This value is only used with Multipass. |
Returns
Type | Description |
---|---|
System.Boolean |
Broadcast<T>(T, Boolean, Channel)
Sends a broadcast to all clients.
Declaration
public void Broadcast<T>(T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
Broadcast<T>(NetworkConnection, T, Boolean, Channel)
Sends a broadcast to a connection.
Declaration
public void Broadcast<T>(NetworkConnection connection, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | connection | Connection to send to. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the client must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
Broadcast<T>(NetworkObject, T, Boolean, Channel)
Sends a broadcast to observers.
Declaration
public void Broadcast<T>(NetworkObject networkObject, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | NetworkObject to use Observers from. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
Broadcast<T>(HashSet<NetworkConnection>, T, Boolean, Channel)
Sends a broadcast to connections.
Declaration
public void Broadcast<T>(HashSet<NetworkConnection> connections, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.HashSet<NetworkConnection> | connections | Connections to send to. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
BroadcastExcept<T>(NetworkConnection, T, Boolean, Channel)
Sends a broadcast to all connections except excluded.
Declaration
public void BroadcastExcept<T>(NetworkConnection excludedConnection, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | excludedConnection | Connection to exclude. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
BroadcastExcept<T>(HashSet<NetworkConnection>, T, Boolean, Channel)
Sends a broadcast to all connections except excluded.
Declaration
public void BroadcastExcept<T>(HashSet<NetworkConnection> excludedConnections, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.HashSet<NetworkConnection> | excludedConnections | Connections to send to. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
BroadcastExcept<T>(HashSet<NetworkConnection>, NetworkConnection, T, Boolean, Channel)
Sends a broadcast to connections except excluded.
Declaration
public void BroadcastExcept<T>(HashSet<NetworkConnection> connections, NetworkConnection excludedConnection, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.HashSet<NetworkConnection> | connections | Connections to send to. |
NetworkConnection | excludedConnection | Connection to exclude. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
BroadcastExcept<T>(HashSet<NetworkConnection>, HashSet<NetworkConnection>, T, Boolean, Channel)
Sends a broadcast to connections except excluded.
Declaration
public void BroadcastExcept<T>(HashSet<NetworkConnection> connections, HashSet<NetworkConnection> excludedConnections, T message, bool requireAuthenticated = true, Channel channel = Channel.Reliable)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.HashSet<NetworkConnection> | connections | Connections to send to. |
System.Collections.Generic.HashSet<NetworkConnection> | excludedConnections | Connections to exclude. |
T | message | Broadcast data being sent; for example: an instance of your broadcast type. |
System.Boolean | requireAuthenticated | True if the clients must be authenticated for this broadcast to send. |
Channel | channel | Channel to send on. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast to send. |
Despawn(NetworkObject, Nullable<DespawnType>)
Despawns an object over the network. Can only be called on the server.
Declaration
public void Despawn(NetworkObject networkObject, DespawnType? despawnType = null)
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | networkObject | NetworkObject instance to despawn. |
System.Nullable<DespawnType> | despawnType | Despawn override type. |
Despawn(GameObject, Nullable<DespawnType>)
Despawns an object over the network. Can only be called on the server.
Declaration
public void Despawn(GameObject go, DespawnType? despawnType = null)
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | go | GameObject instance to despawn. |
System.Nullable<DespawnType> | despawnType |
GetAuthenticator()
Gets the Authenticator for this manager.
Declaration
public Authenticator GetAuthenticator()
Returns
Type | Description |
---|---|
Authenticator |
GetStartOnHeadless()
Gets StartOnHeadless value.
Declaration
public bool GetStartOnHeadless()
Returns
Type | Description |
---|---|
System.Boolean |
Kick(NetworkConnection, KickReason, LoggingType, String)
Kicks a connection immediately while invoking OnClientKick.
Declaration
public void Kick(NetworkConnection conn, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | Client to kick. |
KickReason | kickReason | Reason client is being kicked. |
LoggingType | loggingType | How to print logging as. |
System.String | log | Optional message to be debug logged. |
Kick(NetworkConnection, Reader, KickReason, LoggingType, String)
Kicks a connection immediately while invoking OnClientKick.
Declaration
public void Kick(NetworkConnection conn, Reader reader, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
Parameters
Type | Name | Description |
---|---|---|
NetworkConnection | conn | Client to kick. |
Reader | reader | Reader to clear before kicking. |
KickReason | kickReason | Reason client is being kicked. |
LoggingType | loggingType | How to print logging as. |
System.String | log | Optional message to be debug logged. |
Kick(Int32, KickReason, LoggingType, String)
Kicks a connection immediately while invoking OnClientKick.
Declaration
public void Kick(int clientId, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | clientId | ClientId to kick. |
KickReason | kickReason | Reason client is being kicked. |
LoggingType | loggingType | How to print logging as. |
System.String | log | Optional message to be debug logged. |
OneServerStarted()
Returns true if only one server is started.
Declaration
public bool OneServerStarted()
Returns
Type | Description |
---|---|
System.Boolean |
RegisterBroadcast<T>(Action<NetworkConnection, T, Channel>, Boolean)
Registers a method to call when a Broadcast arrives.
Declaration
public void RegisterBroadcast<T>(Action<NetworkConnection, T, Channel> handler, bool requireAuthentication = true)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Action<NetworkConnection, T, Channel> | handler | Method to call. |
System.Boolean | requireAuthentication | True if the client must be authenticated for the method to call. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast being registered. |
SetAuthenticator(Authenticator)
Gets the Authenticator for this manager, and initializes it.
Declaration
public void SetAuthenticator(Authenticator value)
Parameters
Type | Name | Description |
---|---|---|
Authenticator | value |
SetFrameRate(UInt16)
Declaration
public void SetFrameRate(ushort value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | value |
SetRemoteClientTimeout(RemoteTimeoutType, UInt16)
Sets timeout settings. Can be used at runtime.
Declaration
public void SetRemoteClientTimeout(RemoteTimeoutType timeoutType, ushort duration)
Parameters
Type | Name | Description |
---|---|---|
RemoteTimeoutType | timeoutType | |
System.UInt16 | duration |
SetStartOnHeadless(Boolean)
Sets StartOnHeadless value.
Declaration
public void SetStartOnHeadless(bool value)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | value | New value to use. |
Spawn(NetworkObject, NetworkConnection, Scene)
Spawns an object over the network. Can only be called on the server.
Declaration
public void Spawn(NetworkObject nob, NetworkConnection ownerConnection = null, Scene scene = default(Scene))
Parameters
Type | Name | Description |
---|---|---|
NetworkObject | nob | MetworkObject instance to spawn. |
NetworkConnection | ownerConnection | Connection to give ownership to. |
UnityEngine.SceneManagement.Scene | scene |
Spawn(GameObject, NetworkConnection, Scene)
Spawns an object over the network. Can only be called on the server.
Declaration
public void Spawn(GameObject go, NetworkConnection ownerConnection = null, Scene scene = default(Scene))
Parameters
Type | Name | Description |
---|---|---|
UnityEngine.GameObject | go | GameObject instance to spawn. |
NetworkConnection | ownerConnection | Connection to give ownership to. |
UnityEngine.SceneManagement.Scene | scene |
StartConnection()
Starts the local server connection.
Declaration
public bool StartConnection()
Returns
Type | Description |
---|---|
System.Boolean |
StartConnection(UInt16)
Starts the local server using port.
Declaration
public bool StartConnection(ushort port)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | port | Port to start on. |
Returns
Type | Description |
---|---|
System.Boolean |
StopConnection(Boolean)
Stops the local server connection.
Declaration
public bool StopConnection(bool sendDisconnectMessage)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | sendDisconnectMessage | True to send a disconnect message to all clients first. |
Returns
Type | Description |
---|---|
System.Boolean |
UnregisterBroadcast<T>(Action<NetworkConnection, T, Channel>)
Unregisters a method call from a Broadcast type.
Declaration
public void UnregisterBroadcast<T>(Action<NetworkConnection, T, Channel> handler)
where T : struct, IBroadcast
Parameters
Type | Name | Description |
---|---|---|
System.Action<NetworkConnection, T, Channel> | handler | Method to unregister. |
Type Parameters
Name | Description |
---|---|
T | Type of broadcast being unregistered. |
Events
OnAuthenticationResult
Called when authenticator has concluded a result for a connection. Boolean is true if authentication passed, false if failed.
Declaration
public event Action<NetworkConnection, bool> OnAuthenticationResult
Event Type
Type | Description |
---|---|
System.Action<NetworkConnection, System.Boolean> |
OnClientKick
Called when a client is removed from the server using Kick. This is invoked before the client is disconnected. NetworkConnection when available, clientId, and KickReason are provided.
Declaration
public event Action<NetworkConnection, int, KickReason> OnClientKick
Event Type
Type | Description |
---|---|
System.Action<NetworkConnection, System.Int32, KickReason> |
OnRemoteConnectionState
Called when a remote client state changes with the server.
Declaration
public event Action<NetworkConnection, RemoteConnectionStateArgs> OnRemoteConnectionState
Event Type
Type | Description |
---|---|
System.Action<NetworkConnection, RemoteConnectionStateArgs> |
OnServerConnectionState
Called after the local server connection state changes.
Declaration
public event Action<ServerConnectionStateArgs> OnServerConnectionState
Event Type
Type | Description |
---|---|
System.Action<ServerConnectionStateArgs> |