Class FishNetNetworkWrapper
- Namespace
- FishMMO.Server.Implementation
- Assembly
- FishMMO.Server.dll
Wraps FishNet NetworkManager with a clean abstraction for server orchestration.
public class FishNetNetworkWrapper : INetworkManagerWrapper, IDisposable
- Inheritance
-
FishNetNetworkWrapper
- Implements
- Inherited Members
Constructors
FishNetNetworkWrapper(NetworkManager, IServerConfiguration, MonoBehaviour)
Initializes a new instance of the FishNetNetworkWrapper class.
public FishNetNetworkWrapper(NetworkManager networkManager, IServerConfiguration config, MonoBehaviour coroutineHost)
Parameters
networkManagerNetworkManagerThe FishNet NetworkManager instance.
configIServerConfigurationThe server configuration provider.
coroutineHostMonoBehaviourMonoBehaviour to host coroutines (usually the Server MonoBehaviour).
Properties
NetworkManager
Gets the network manager wrapper instance.
public NetworkManager NetworkManager { get; }
Property Value
- NetworkManager
Methods
ApplyTransportConfiguration(string, ushort?)
Applies transport configuration values from IServerConfiguration. WebTransport (QUIC/HTTP3) for all platforms. Each game server terminates its own TLS — NGINX forwards raw UDP at Layer 4.
Certificate path defaults by platform (overridable via config):
| Platform | Default cert path |
|---|---|
| Linux | /etc/fishmmo/certs/fullchain.pem |
| Windows | C:\ProgramData\FishMMO\certs\fullchain.pem |
| macOS | /usr/local/share/fishmmo/certs/fullchain.pem |
| Other | certs/fullchain.pem (relative to working directory) |
When addressOverride or portOverride
are supplied they take precedence over the .cfg file values, allowing the
Server component's Inspector overrides to control the actual transport bind
address and port.
public void ApplyTransportConfiguration(string addressOverride = null, ushort? portOverride = null)
Parameters
AttachLoginAuthenticator(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>)
Attaches a login authenticator, assigns server references, and initializes async workers.
public void AttachLoginAuthenticator(IServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour> server)
Parameters
serverIServer<INetworkManagerWrapper, NetworkConnection, IServerBehaviour>The server instance providing infrastructure access.
BroadcastToScene<T>(Scene, T, bool, Channel)
Broadcasts one message to every connection FishNet has in a scene, serialising it once.
public bool BroadcastToScene<T>(Scene scene, T broadcast, bool requireAuthentication = true, Channel channel = Channel.Reliable) where T : struct, IBroadcast
Parameters
sceneSceneThe scene whose connections receive the message.
broadcastTThe message to broadcast.
requireAuthenticationboolWhether each recipient must be authenticated.
channelChannelThe channel to use for broadcasting (default is Reliable).
Returns
- bool
True if the scene had at least one connection.
Type Parameters
TThe broadcast type.
Remarks
Reads SceneManager.SceneConnections, which FishNet keeps per loaded scene, so no
caller needs to walk the server's characters asking each for its scene.
Broadcast<T>(NetworkConnection, T, bool, Channel)
Broadcasts a message to a network connection.
public void Broadcast<T>(NetworkConnection conn, T broadcast, bool requireAuthentication = true, Channel channel = Channel.Reliable) where T : struct, IBroadcast
Parameters
connNetworkConnectionThe network connection.
broadcastTThe broadcast message.
requireAuthenticationboolWhether authentication is required.
channelChannelThe channel to use for broadcasting.
Type Parameters
TType of broadcast struct.
Remarks
A null or inactive connection is a no-op rather than a throw. Server-side characters are no longer guaranteed to have an owner: a combat-logout body stays spawned and keeps taking damage, firing the same achievement, quest and status events a played character does — every one of which would otherwise dereference a null connection somewhere deep in a gameplay system and abort whatever was in progress.
Broadcast<T>(HashSet<NetworkConnection>, T, bool, Channel)
Broadcasts one message to every connection in a set, serialising it once.
public void Broadcast<T>(HashSet<NetworkConnection> connections, T broadcast, bool requireAuthentication = true, Channel channel = Channel.Reliable) where T : struct, IBroadcast
Parameters
connectionsHashSet<NetworkConnection>The recipients.
broadcastTThe message to broadcast.
requireAuthenticationboolWhether each recipient must be authenticated.
channelChannelThe channel to use for broadcasting (default is Reliable).
Type Parameters
TThe broadcast type.
Remarks
The single-connection overload serialises per call, so a loop over it pays the serialisation once per recipient. Use this for any fan-out: a scene's connections, a match's team, a party's local members. The set is read, never kept; an empty or null set is a no-op.
Dispose()
public void Dispose()
RegisterBroadcast<T>(Action<NetworkConnection, T, Channel>, bool)
Registers a broadcast handler for the given type.
public void RegisterBroadcast<T>(Action<NetworkConnection, T, Channel> handler, bool requireAuthentication = true) where T : struct, IBroadcast
Parameters
handlerAction<NetworkConnection, T, Channel>The handler to register.
requireAuthenticationboolWhether authentication is required for the broadcast.
Type Parameters
TThe broadcast type.
RegisterServerConnectionStateEventHandler(Action<ServerConnectionStateArgs>)
Subscribes to server connection state changes.
public void RegisterServerConnectionStateEventHandler(Action<ServerConnectionStateArgs> handler)
Parameters
handlerAction<ServerConnectionStateArgs>The handler to invoke on connection state changes.
SetMaximumClients(int)
Sets the maximum number of clients manually.
public void SetMaximumClients(int clients)
Parameters
clientsintThe maximum number of clients allowed.
SetTransportAddress(string, IPAddressType)
Sets the transport bind address manually.
public void SetTransportAddress(string address, IPAddressType addressType)
Parameters
addressstringThe address to bind the transport to.
addressTypeIPAddressTypeThe type of IP address (IPv4 or IPv6).
SetTransportPort(ushort)
Sets the transport port manually.
public void SetTransportPort(ushort port)
Parameters
portushortThe port number to use for the transport.
StartServer()
Starts the server, subscribes to connection state, and starts coroutine to await readiness.
public void StartServer()
StopServer()
Stops the server.
public void StopServer()
TryGetSceneConnections(Scene, out HashSet<NetworkConnection>)
Gets FishNet's live connection set for a scene. The set belongs to FishNet: read it on the main thread and never modify or keep it.
public bool TryGetSceneConnections(Scene scene, out HashSet<NetworkConnection> connections)
Parameters
sceneSceneThe scene.
connectionsHashSet<NetworkConnection>The scene's connections, or null.
Returns
- bool
True if the scene has at least one connection.
UnregisterBroadcast<T>(Action<NetworkConnection, T, Channel>)
Unregisters a broadcast handler for the given type.
public void UnregisterBroadcast<T>(Action<NetworkConnection, T, Channel> handler) where T : struct, IBroadcast
Parameters
handlerAction<NetworkConnection, T, Channel>The handler to unregister.
Type Parameters
TThe broadcast type.
UnregisterServerConnectionStateEventHandler(Action<ServerConnectionStateArgs>)
Unsubscribes from server connection state changes.
public void UnregisterServerConnectionStateEventHandler(Action<ServerConnectionStateArgs> handler)
Parameters
handlerAction<ServerConnectionStateArgs>The handler to unsubscribe from connection state changes.