Class ScriptedTransport
A ValheimCLI transport that answers from a script, for testing scenarios without a game. Built in: strict pins
(cli_expect, holding unless PinsHold is false), the extension listing (cli_extensions) of
the extensions registered with Extension(string, string, Func<IReadOnlyList<string>, object>, bool, int, string), their commands, and confirmed saves (Saves(bool)).
Commands registered with On(string, Func<string, CommandResult>) or OnPrefix(string, Func<string, CommandResult>) are answered first. Anything unscripted throws, so
a scenario cannot silently issue a command its test did not expect. Commands records every command.
public sealed class ScriptedTransport : IGameTransport, IGameThreadStatusTransport
- Inheritance
-
objectScriptedTransport
- Implements
Properties
Access
The client test-access state ClientAccess(Func<bool>, Func<bool>?, bool) answers from.
public ScriptedAccess Access { get; }
Property Value
Commands
Every command received, in order, including the pin checks a GameActor sends before each command.
public IReadOnlyList<string> Commands { get; }
Property Value
- IReadOnlyList<string>
Disposed
public bool Disposed { get; }
Property Value
- bool
PinsHold
Whether cli_expect confirms the strict pins.
public bool PinsHold { get; set; }
Property Value
- bool
Methods
Actor(string, string)
A strictly pinned actor on this transport, as a verified session would return.
public GameActor Actor(string name = "test", string expectations = "cli_expect worlduid=1")
Parameters
namestringexpectationsstring
Returns
ArrivalSignals(Func<object>)
Answers Arrive(GameActor?, GameActor, HeightExpectation, TimeSpan, CancellationToken, bool, bool)'s in-game waits as a client whose player can be teleported at once:
cli_wait_teleportable, a trace per cli_teleport_trace_arm that completes with a ready floor, and
valheim.world/player-support-wait with landed (the player's support reading after the
server's teleport). Also lists valheim.session/teleport-signals. The server's cli_teleport_peer is the test's.
public ScriptedTransport ArrivalSignals(Func<object> landed)
Parameters
landedFunc<object>
Returns
ClientAccess(Func<bool>, Func<bool>?, bool)
Answers a game client's test access as ValheimCLI and the game do (TestAccess): cli_access from
the scripted state, devcommands toggling it and cli_acknowledge_local_cheats acknowledging cheats.
inWorld says whether the client has a local player (joined or hosting); hosting
whether it is the server of that world. Read Access to see or change the state. It replaces any handler
already registered for those three commands; register a different reply (a refusal, say) after it.
public ScriptedTransport ClientAccess(Func<bool> inWorld, Func<bool>? hosting = null, bool allowOnServerClients = true)
Parameters
inWorldFunc<bool>hostingFunc<bool>allowOnServerClientsbool
Returns
Count(string)
How many times command (exactly) or a command starting with it plus a space was received.
public int Count(string command)
Parameters
commandstring
Returns
- int
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Execute(string, TimeSpan)
Send one command and wait at most timeout for its reply. A completed refusal remains in the returned result.
public CommandResult Execute(string command, TimeSpan timeout)
Parameters
commandstringtimeoutTimeSpan
Returns
- CommandResult
Extension(string, string, Func<IReadOnlyList<string>, object>, bool, int, string)
Registers owner/name: listed by cli_extensions and answered with an EXTENSION_RESULT envelope around
data's result (serialized as JSON), given the command's arguments.
public ScriptedTransport Extension(string owner, string name, Func<IReadOnlyList<string>, object> data, bool readOnly = true, int resultVersion = 1, string instance = "fake")
Parameters
ownerstringnamestringdataFunc<IReadOnlyList<string>, object>readOnlyboolresultVersionintinstancestring
Returns
ExtensionResult(string, object, string)
The EXTENSION_RESULT line of a successful extension command.
public static string ExtensionResult(string owner, object data, string instance = "fake")
Parameters
ownerstringdataobjectinstancestring
Returns
- string
Failed(string)
public static CommandResult Failed(string line)
Parameters
linestring
Returns
- CommandResult
Ok(params string[])
public static CommandResult Ok(params string[] lines)
Parameters
linesstring[]
Returns
- CommandResult
On(string, Func<string, CommandResult>)
public ScriptedTransport On(string command, Func<string, CommandResult> reply)
Parameters
commandstringreplyFunc<string, CommandResult>
Returns
OnPrefix(string, Func<string, CommandResult>)
public ScriptedTransport OnPrefix(string prefix, Func<string, CommandResult> reply)
Parameters
prefixstringreplyFunc<string, CommandResult>
Returns
OnStatus(Func<IReadOnlyDictionary<string, string>>)
Answer an independent STATUS connection in tests of a busy game thread.
public ScriptedTransport OnStatus(Func<IReadOnlyDictionary<string, string>> reply)
Parameters
replyFunc<IReadOnlyDictionary<string, string>>
Returns
ReadStatus()
Read the live STATUS fields without queuing a game-thread command. Missing or invalid fields are judged by the caller.
public IReadOnlyDictionary<string, string> ReadStatus()
Returns
- IReadOnlyDictionary<string, string>
Saves(bool)
Answers cli_save: OK: SAVE saveNumber=N with a rising N when confirmed, otherwise a failed reply.
public ScriptedTransport Saves(bool confirmed = true)
Parameters
confirmedbool