Table of Contents

Class SceneServerSystem

Namespace
FishMMO.Server.Implementation.World.SceneServer
Assembly
FishMMO.Server.dll

Manages scene server node services, scene loading/unloading, and heartbeat updates to the world server. Tracks scene instances, handles connection events, and synchronizes scene state with the database. Game logic and Broadcasts run synchronously on the main thread. Database operations are async to avoid blocking the main thread. Results from async DB queries that require main-thread state changes are marshalled via ISceneServerSystemMainThreadQueueData.

[CreateAssetMenu(fileName = "SceneServerSystem", menuName = "FishMMO/Server/SceneServer/Scene Server System", order = 1)]
[RequiresDataContainer(typeof(SceneInstanceMappingData))]
[RequiresDataContainer(typeof(SceneServerRuntimeData))]
[RequiresDataContainer(typeof(SceneServerSystemMainThreadQueueData))]
[RequiresDataContainer(typeof(AsyncWorkerData))]
public class SceneServerSystem : ServerBehaviour, IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, ISceneServerSystem<NetworkConnection>, IServerBehaviour, IServerComponent
Inheritance
Object
ScriptableObject
SceneServerSystem
Implements
IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
ISceneServerSystem<NetworkConnection>
Inherited Members
ScriptableObject.SetDirty()
ScriptableObject.CreateInstance<T>()
Object.GetEntityId()
Object.MemberwiseClone()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.ToString()
Object.name
Object.hideFlags

Remarks

Configuration: NetworkSendInterval (this server's flush interval) and ClientNetworkSendInterval (its clients'), each 1 or 2, default 1 (FishNet's own every-tick behaviour). The queue depth follows the CLIENT interval and is applied before any client connects, so a client that has not yet been told (it is told on arrival, before anything else) only ever sends more often than the depth assumes, never less.

IdleNetworkSendInterval (0 = off, up to MaximumIdleInterval): a player who is nowhere near a fight has its unreliable data flushed this often instead (fewer packets, one tick later), while reliable data still leaves on the normal interval so replies are never slower. See IsEngaged(bool, bool).

Properties

IdleIntervalPlayerTicks

Ticks between an idle player's sends (the simulation tools report it).

public long IdleIntervalPlayerTicks { get; }

Property Value

long

PulseRate

Gets or sets the pulse rate for heartbeat updates.

public float PulseRate { get; set; }

Property Value

float

ScheduledPlayerTicks

Ticks between a scheduled player's sends, as this server runs them (the simulation tools report it).

public long ScheduledPlayerTicks { get; }

Property Value

long

WorldClock

The world clock, for the staff tools' clock report and controls. Null before start.

public WorldClockHost WorldClock { get; }

Property Value

WorldClockHost

WorldSceneDetailsCache

Cache of world scene details, including max clients per scene.

public WorldSceneDetailsCache WorldSceneDetailsCache { get; }

Property Value

WorldSceneDetailsCache

Methods

AdjustSceneCharacterCount(long, string, long, int)

Adjusts the character count for a specific scene instance.

public void AdjustSceneCharacterCount(long worldServerID, string sceneName, long sceneID, int amount)

Parameters

worldServerID long

World server ID.

sceneName string

Scene name.

sceneID long

Scene row ID identifying the instance.

amount int

Amount to adjust by (+1 or -1).

CloseInstance(long, string)

Returns an instance's occupants to the open world and unloads it.

public void CloseInstance(long sceneID, string reason)

Parameters

sceneID long

Scene row of the instance to close.

reason string

Why it is closing, for diagnostics.

Remarks

The only way an instance may be unloaded. UnloadScene(long) destroys the scene outright, which was safe while the sole caller was the stale sweep — that only ever picks empty scenes — but is not once an instance can be closed with people standing in it. Evicting first sends each of them through the ordinary leave-instance path, so their state is saved, their session claim released and their client re-routed, rather than having the ground removed from under them.

DescribeServerControl()

This scene server's lock and shutdown state, and every world's it has read, as report lines (what the staff tools' /admin server status prints): what the process is doing now, which after a control change is the question worth asking, because the row and the process agree only after the next pulse.

public IReadOnlyList<string> DescribeServerControl()

Returns

IReadOnlyList<string>

InitializeOnce()

Called once to initialize the scene server system. Registers the server in the database and subscribes to connection and scene events.

public override ServerComponentInitializationStatus InitializeOnce()

Returns

ServerComponentInitializationStatus

InitializeOnceAsync(CancellationToken)

Initializes the system and registers it in the database without blocking the Unity main thread.

public override Task<ServerComponentInitializationStatus> InitializeOnceAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task<ServerComponentInitializationStatus>

Remarks

Awaits here deliberately capture Unity's SynchronizationContext (no ConfigureAwait(false)), so execution resumes on the main thread and the Unity and FishNet APIs used below stay legal.

NoteDeliberateInstanceExit(long, string, long)

Records that an instance's occupant left by choice rather than by losing its connection.

public void NoteDeliberateInstanceExit(long worldServerID, string sceneName, long sceneID)

Parameters

worldServerID long

World server ID.

sceneName string

Instance scene name.

sceneID long

Scene row ID identifying the instance.

Remarks

Called after the departure has been debited from the instance's population, so if this was the last occupant the instance is already empty and the next pulse reclaims it immediately instead of holding it for the idle timeout. See VacatedDeliberately for why the two cases differ.

A missing instance is not an error here, unlike in AdjustSceneCharacterCount(long, string, long, int): the instance may already have been unloaded by the very departure being recorded, and the only consequence of not marking a scene that no longer exists is nothing at all.

OnDeinitialize()

Called when the system is being destroyed. Unsubscribes from events and deletes scene data from the database.

public override void OnDeinitialize()

OnUpdate(float)

Drains the main-thread queue each frame.

protected override void OnUpdate(float deltaTime)

Parameters

deltaTime float

SceneManager_OnUnloadEnd(SceneUnloadEndEventArgs)

Handles scene unload completion events, removing scene mappings and cleaning up. Uses the flat SceneInstanceByHandle map for O(1) lookup per unloaded scene, then removes from both the flat map and the nested WorldScenes hierarchy.

public void SceneManager_OnUnloadEnd(SceneUnloadEndEventArgs args)

Parameters

args SceneUnloadEndEventArgs

Scene unload end event arguments.

Service<T>()

The first running module service of a type, or null (the staff tools find the weather here).

public T Service<T>() where T : class, ISceneServerModuleService

Returns

T

Type Parameters

T

TryGetInstanceRemainingSeconds(long, out double)

How long an instance has left before it closes on its own, if it is time-bounded.

public bool TryGetInstanceRemainingSeconds(long sceneID, out double remainingSeconds)

Parameters

sceneID long

Scene row of the instance.

remainingSeconds double

Seconds until it closes; negative once it is overdue.

Returns

bool

false for a scene this server does not host or an open-world scene, neither of which has an expiry to report.

Remarks

The lifetime cap is configuration this system owns, so the answer is derived here rather than by making every caller read the key and repeat the arithmetic — which is how two places end up disagreeing about when a dungeon ends.

A duration, not an instant. The deadline is kept on the monotonic clock, and this used to hand it out re-expressed on the host's wall clock for the caller to subtract the wall clock from again: two reads of a clock that can step, to recover a number this already had.

TryGetSceneInstanceDetails(long, string, long, out ISceneInstanceDetails)

Attempts to get scene instance details for a given world server, scene name, and handle. Uses the flat SceneInstanceByHandle map for O(1) lookup, then validates the world server and scene name match as a correctness check.

public bool TryGetSceneInstanceDetails(long worldServerID, string sceneName, long sceneID, out ISceneInstanceDetails instanceDetails)

Parameters

worldServerID long

World server ID.

sceneName string

Scene name.

sceneID long
instanceDetails ISceneInstanceDetails

Output instance details.

Returns

bool

True if found, false otherwise.

TryLoadSceneForConnection(NetworkConnection, ISceneInstanceDetails)

Attempts to load a scene for a connection if it is valid and loaded.

public bool TryLoadSceneForConnection(NetworkConnection connection, ISceneInstanceDetails instance)

Parameters

connection NetworkConnection

Network connection.

instance ISceneInstanceDetails

Scene instance details.

Returns

bool

True if scene was loaded for the connection, false otherwise.

UnloadScene(long)

Unloads a scene by handle and removes its details from the database and server.

public void UnloadScene(long sceneID)

Parameters

sceneID long

Scene row to unload.

UnloadSceneForConnection(NetworkConnection, string)

Unloads a scene for a connection by scene name.

public void UnloadSceneForConnection(NetworkConnection connection, string sceneName)

Parameters

connection NetworkConnection

Network connection.

sceneName string

Name of the scene to unload.