Table of Contents

Class CharacterSystem

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

The character save and load, as the host of every CharacterPersistenceParticipant.

[CreateAssetMenu(fileName = "CharacterSystem", menuName = "FishMMO/Server/SceneServer/Character System", order = 1)]
[RequiresDataContainer(typeof(CharacterMappingData))]
[RequiresDataContainer(typeof(CharacterSystemRuntimeData))]
[RequiresDataContainer(typeof(CharacterSystemMainThreadQueueData))]
[RequiresDataContainer(typeof(AsyncWorkerData))]
public class CharacterSystem : ServerBehaviour, IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>, ICharacterPersistenceHost, ICharacterSystem<NetworkConnection, Scene>, IServerBehaviour, IServerComponent
Inheritance
Object
ScriptableObject
CharacterSystem
Implements
IServerBehaviour<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
IServerComponent<INetworkManagerWrapper, ServerManager, NetworkConnection, IServerBehaviour>
ICharacterSystem<NetworkConnection, Scene>
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

An ordinary death. A character found below DeathAltitude is killed through Kill(ICharacter) with no killer, which is the whole death path every other death takes: the dead flag, the death pose for observers, the OnKilled subscribers (this system's own, which sends a player its death dialog; the pet, arena and aggression systems), the ECA triggers and the cooldown reset. Nobody is credited, the same as an operator's kill: there is no one to give the standing, quests or achievements to. The player then respawns from the death dialog as from any death.

A walk, not a trigger. One height comparison per character a few times a second, and none at all while no cloud world is loaded. A trigger volume under the islands would need a collider as wide as the scene in every cloud world and would fire only on entry, so a body that arrived below the line any other way (a load, a teleport, a revive) would never be told.

The body stays where the deck took it. KCCController holds a character that nobody is steering once it is below the line, so a corpse does not fall for as long as its player sits at the death dialog (at terminal velocity it would leave the range network positions are written in within minutes).

Nothing is left in the void. An NPC lost to the deck goes straight back to its spawner instead of becoming a corpse nobody can reach, and a revive of a body the deck holds (a resurrect accepted, an operator's revive) puts the character on the nearest island ground that will hold it (CloudWorldLanding). A bind point that is open air in a cloud world is passed over the same way, so a respawn cannot drop the character straight back in.

Properties

LingeringCharacterCount

Number of characters whose bodies remain in the world after a combat logout.

public int LingeringCharacterCount { get; }

Property Value

int

Remarks

These have no connection, so they are absent from the connection maps population counts are normally derived from — but they are still resident and still hold a session claim, so anything reporting load or deciding whether a scene is empty has to account for them.

Methods

BeginChannelTransfer(NetworkConnection, long)

Moves a character to another channel (another instance of the same scene) by releasing it here, bound to targetSceneHandle, and dropping the connection so the client re-routes through the world server.

public bool BeginChannelTransfer(NetworkConnection connection, long targetSceneHandle)

Parameters

connection NetworkConnection

Connection whose character is switching channel.

targetSceneHandle long

Scene row ID of the destination channel.

Returns

bool

true when the transfer was started; false if the connection has no character.

Remarks

The ordering this performs is the whole point of the method, and it is why callers must not simply rewrite SceneHandle and disconnect. Scene population is credited and debited by handle, and the disconnect pipeline debits the handle the character carries at that moment — so a handle rewritten first debits the destination instance, which this server may not even host, while the source instance keeps a resident it no longer has. Neither error self-corrects: the source's phantom population makes it advertise capacity it does not have, keeps it from ever being recognised as empty and unloaded, and eventually makes it look full, at which point players queue for a scene instance that is in fact deserted.

The character is released promptly (no combat-logout linger) because the destination scene server has to be able to claim it, exactly as for a teleport.

CollectLingeringCharacters(List<IPlayerCharacter>)

Appends every spawned combat-logout body to results.

public void CollectLingeringCharacters(List<IPlayerCharacter> results)

Parameters

results List<IPlayerCharacter>

Remarks

For systems that keep their own per-character state current on a timer — the item snapshot, its reconcile drain — and would otherwise skip a body that is still resident, still holds its claim and can still be changed by the world.

IPlayerCharacter_OnTeleport(IPlayerCharacter)

Handles character teleport events, validates teleporter and scene, updates position, and saves state.

public void IPlayerCharacter_OnTeleport(IPlayerCharacter character)

Parameters

character IPlayerCharacter

Player character to teleport.

InitializeOnce()

Initializes the character system, registers event handlers, and sets up character authentication and broadcast handling.

public override ServerComponentInitializationStatus InitializeOnce()

Returns

ServerComponentInitializationStatus

IsPersistedBuff(BaseBuffTemplate)

Whether a buff is written to the database with its owner. Pure.

public static bool IsPersistedBuff(BaseBuffTemplate template)

Parameters

template BaseBuffTemplate

The buff's template; null is never persisted.

Returns

bool

True when the buff is saved and restored with its owner.

Remarks

Permanent buffs are not. They are the weather-exposure buffs, and they belong to the environment rather than the character: WeatherExposureController (and a buff volume) applies and removes them every tick from where the character is standing, so after a login they come back on their own within a tick. A saved one could only come back wrong: a permanent buff has no expiry (ExpiryTick is UNSET_TICK), so it was captured with no time remaining and restored as a buff that expires on its first tick — an icon that flickers, an apply and a remove, and an exposure system that briefly thinks it already has the buff on.

Leaving them out of the set is also what deletes the rows saved before this rule: the set replaces everything the database holds for the character (see CaptureBuffSet(IPlayerCharacter, long)), so the first save afterwards drops them. The load skips any it still finds until then.

IsPetOut(float, bool)

Whether a captured pet row says the pet is out, restored at the owner's next login. Pure.

public static bool IsPetOut(float petHealth, bool ownerDead)

Parameters

petHealth float

The pet's current health.

ownerDead bool

Whether the owner is dead.

Returns

bool

True when the pet should come back with its owner.

Remarks

A pet at zero health is dead and not out. A pet whose owner is dead is not out either: death dismisses it — see the capture in AppendPetData(IPlayerCharacter, List<PetSnapshot>) for why the rule has to be stated here as well as in the dismissal.

OnDeinitialize()

Cleans up the character system, unregisters event handlers, and saves all characters to the database before shutdown.

public override void OnDeinitialize()

OnRemoteConnectionStopped(NetworkConnection)

When a connection disconnects the server removes all known instances of the character and saves it to the database.

protected override void OnRemoteConnectionStopped(NetworkConnection conn)

Parameters

conn NetworkConnection

OnUpdate(float)

Drains the main-thread queue each frame.

protected override void OnUpdate(float deltaTime)

Parameters

deltaTime float

ReturnInstanceOccupantsToWorld(long, string)

Returns everyone standing in an instance to the open world, so the instance can be unloaded without stranding them.

public int ReturnInstanceOccupantsToWorld(long instanceSceneID, string reason)

Parameters

instanceSceneID long

Scene row ID of the instance being closed.

reason string

Why it is closing, for diagnostics.

Returns

int

How many connected characters were moved.

Remarks

An instance is normally emptied by its occupants leaving; this is the path for an instance that ends on the server's terms — a lifetime cap expiring, or a leader closing it — where the characters inside have not asked to go anywhere.

Each character takes the ordinary leave-instance route: announced while it still belongs to the instance so the population is debited correctly, put back at the open-world position it entered from, saved, released, and disconnected to be re-routed. It is not gated on combat or death, because the scene is going away regardless and refusing would leave the character in a scene that is about to be destroyed.

Combat-logout bodies in the instance are finalised as well. They have no connection, so nothing else would notice them — and destroying the scene under one strands that character's session claim until its lease expires, locking the player out of every scene server in the meantime.

SendBroadcastToCharacter<T>(long, T)

Allows sending a broadcast to a specific character by their character ID. Returns true if the broadcast was sent successfully, false otherwise.

public bool SendBroadcastToCharacter<T>(long characterID, T msg) where T : struct, IBroadcast

Parameters

characterID long

ID of the character to send to.

msg T

Broadcast message to send.

Returns

bool

Type Parameters

T

Type of broadcast message.

SendBroadcastToCharacter<T>(string, T)

Allows sending a broadcast to a specific character by their character name. Returns true if the broadcast was sent successfully, false otherwise.

public bool SendBroadcastToCharacter<T>(string characterName, T msg) where T : struct, IBroadcast

Parameters

characterName string

Name of the character to send to.

msg T

Broadcast message to send.

Returns

bool

Type Parameters

T

Type of broadcast message.

SuppressCombatLingerOnDisconnect(NetworkConnection)

Declares that the next disconnect on connection is something the server is doing on purpose, not a player walking out of a fight.

public void SuppressCombatLingerOnDisconnect(NetworkConnection connection)

Parameters

connection NetworkConnection

Connection the server is about to disconnect on purpose.

Remarks

Combat-logout linger exists to stop a player escaping a losing fight by closing the client, so it triggers on a dropped connection — and the server itself drops connections for reasons that have nothing to do with the player quitting.

  • A hand-off to another scene server is implemented as a dropped connection. One that lingered would leave the body — and its session claim — on the source server while the client arrives at the destination, which then cannot claim the character and kicks it, repeatedly, until the linger expires.
  • An administrative kick is the operator removing the player, so there is no escape to deny. Lingering there keeps the kicked player's body in the world and holds their character claim for the length of the linger — which makes a kick the opposite of a remedy for a character that is stuck.

The teleport and bind-point-respawn paths avoid this by releasing the character themselves before disconnecting. Callers that instead rely on the ordinary disconnect pipeline must announce the intent here first. The marker is consumed by that disconnect, so it cannot leak onto a later session on a recycled connection id.

TryEndCombatLingerForAccount(string, string)

Ends the combat-logout linger held for accountName, if there is one, saving the body and handing its session claim back.

public bool TryEndCombatLingerForAccount(string accountName, string reason)

Parameters

accountName string

Account whose lingering body should be removed.

reason string

Why the linger is being ended, for diagnostics.

Returns

bool

true when a lingering body was found and removed.

Remarks

A lingering body has no connection, so it is invisible to everything that acts on a player by finding their connection — including the administrative kick, which therefore did nothing at all to a character that had combat-logged. That is the opposite of what a kick is for: the body stays in the world, still targetable, and goes on holding the character's session claim, so the operator's remedy for a stuck character is precisely the case where it has no effect.

This is the ordinary end of a linger, not a special teardown: the body is persisted and despawned and the claim released, exactly as when its timer runs out. The character keeps whatever happened to it while it stood there.

Events

OnAfterLoadCharacter

public event Action<NetworkConnection, IPlayerCharacter> OnAfterLoadCharacter

Event Type

Action<NetworkConnection, IPlayerCharacter>

OnBeforeLoadCharacter

public event Action<NetworkConnection, long> OnBeforeLoadCharacter

Event Type

Action<NetworkConnection, long>

OnConnect

Triggered immediately after a character is added to their respective cache.

public event Action<NetworkConnection, IPlayerCharacter> OnConnect

Event Type

Action<NetworkConnection, IPlayerCharacter>

OnDespawnCharacter

Triggered immediately after a character is despawned from the scene.

public event Action<NetworkConnection, IPlayerCharacter> OnDespawnCharacter

Event Type

Action<NetworkConnection, IPlayerCharacter>

OnDisconnect

Triggered immediately after a character is removed from their respective cache.

public event Action<NetworkConnection, IPlayerCharacter> OnDisconnect

Event Type

Action<NetworkConnection, IPlayerCharacter>

OnPetKilled

Triggered immediately after a pet is killed: the owner's connection, the owner, and the pet.

public event Action<NetworkConnection, IPlayerCharacter, ICharacter> OnPetKilled

Event Type

Action<NetworkConnection, IPlayerCharacter, ICharacter>

OnSpawnCharacter

Triggered immediately after a character is spawned in the scene.

public event Action<NetworkConnection, IPlayerCharacter, Scene> OnSpawnCharacter

Event Type

Action<NetworkConnection, IPlayerCharacter, Scene>