Class OwnedServerSession
public sealed class OwnedServerSession : IOwnedServer
- Inheritance
-
objectOwnedServerSession
- Implements
Constructors
OwnedServerSession(Func<string, IOwnedProcess>, Func<IGameTransport>, string, string, string, TimeSpan, TimeSpan, TimeSpan?, CancellationToken)
public OwnedServerSession(Func<string, IOwnedProcess> launch, Func<IGameTransport> connect, string saveRoot, string expectations, string sessionCapability, TimeSpan startup, TimeSpan command, TimeSpan? poll = null, CancellationToken cancellation = default)
Parameters
launchFunc<string, IOwnedProcess>connectFunc<IGameTransport>saveRootstringexpectationsstringsessionCapabilitystringstartupTimeSpancommandTimeSpanpollTimeSpan?cancellationCancellationToken
Properties
EnsureTestAccess
Establishes test access (Ensure(GameActor, TestActorRole, bool) as DedicatedServer: devcommands, then
confirmcheats, each verified through ValheimCLI's cli_access) on every boot this session starts, before
Start() returns: the first and each Restart(), since a new server process has neither gate.
PinnedServerRun sets it for every owned server it starts; false only for a session a caller drives itself
that issues no test commands.
public bool EnsureTestAccess { get; set; }
Property Value
- bool
Events
Events startup waits on; null keeps bounded connection retries. The process exit is watched either way.
public StartupEvents? Events { get; init; }
Property Value
QuitTimeout
How long a stop or restart waits for the server to quit after asking it (its world save and shutdown) before it kills it. Default two minutes.
public TimeSpan QuitTimeout { get; init; }
Property Value
- TimeSpan
StartedProcesses
public List<int> StartedProcesses { get; }
Property Value
- List<int>
Stops
How each owned process ended, in launch order: one entry per stop, including restarts.
public List<ProcessStop> Stops { get; }
Property Value
- List<ProcessStop>
Methods
CheckIdentity(JsonElement, string, int, string, string)
public static bool CheckIdentity(JsonElement result, string token, int pid, string saveRoot, string expectedExtension)
Parameters
resultJsonElementtokenstringpidintsaveRootstringexpectedExtensionstring
Returns
- bool
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Restart()
Restarts only this server and returns its new actor.
public GameActor Restart()
Returns
Start()
public GameActor Start()
Returns
StartAsync()
Launches one owned server and returns its strictly pinned actor. Every stage races the process exit, which ends startup at once with the exit code and the last log line. With Events, the first connection waits for ValheimCLI's listening line and, optionally, a world-loaded state push. The adapter's own readiness has no event: an unregistered or incomplete session observation is re-probed, read-only, every poll interval until the deadline. The startup deadline bounds everything, including connecting and the final pin verification, which gets only the time left (at most the command timeout). Then, with EnsureTestAccess, the boot's test access is established (two console mutations, each issued once, under the command timeout); its failure fails the start.
public Task<GameActor> StartAsync()
Returns
- Task<GameActor>
StartupUnavailable(CommandResult)
public static bool StartupUnavailable(CommandResult reply)
Parameters
replyCommandResult
Returns
- bool
Stop()
public void Stop()
WaitUntilJoinable(GameActor)
Waits until server accepts game connections, through this session's own session capability,
within its startup deadline (WaitUntilJoinable(GameActor, string, TimeSpan, CancellationToken)).
public void WaitUntilJoinable(GameActor server)
Parameters
serverGameActor
WaitUntilJoinable(GameActor, string, TimeSpan, CancellationToken)
Waits until an owned dedicated server accepts game connections, as its adapter's sessionCapability
reports in acceptingConnections (Valheim.Testing.Adapter). The game opens its socket when world generation
finishes, which on a first boot comes well after the world has loaded, so a join before it times out. Call it just
before the first join rather than at startup, so the wait overlaps other work. The game offers no event for it: the
read-only observation is repeated until the timeout (less the last 25 ms, too little to start another read), which reports the last reading. A CLI command
that expired before the game thread started it is retried; a failed pin or started command is not.
public static void WaitUntilJoinable(GameActor server, string sessionCapability, TimeSpan timeout, CancellationToken cancellation = default)
Parameters
serverGameActorsessionCapabilitystringtimeoutTimeSpancancellationCancellationToken