Info
- Interactive terminal for dedicated (headless) servers: see what the server does and control it with commands
- Module
Polis.Core.Console, needs Spectre.Console and the SPECTRE_CONSOLE define
- Starts by itself when the app runs headless (
UNITY_SERVER build or no graphics device). Desktop and VR builds are not affected
Running a server
- Build with a server platform config in the Build Tool (
ServerWindows_Release or ServerLinux_Release)
- Put
Configs/ServerConfig.json next to the build to set the server name, port and max players, see Local Configuration
- Start the executable in a terminal (Windows: double click the
.exe, Linux: ./<App>.x86_64)
- When the server is up, the window title shows the app and server name, e.g.
My App [Lab A]
- Headless players run at 60 FPS at most, the App Loader sets the target frame rate when the load starts
Using the terminal
- Type a command after the
> prompt and press Enter
- Up / Down - previous commands
- Esc - clear the line
- Logs from the app scroll above the prompt in color (info, warning, error)
Adding commands
ConsoleCommandHandler.RegisterCommand(new ConsoleCommand("kick", "kick a player by id", async args =>
{
if (args.Length == 0)
{
ConsoleCommandHandler.AppendLog("[red]Usage:[/] kick <id>");
return;
}
await UniTask.SwitchToMainThread();
// kick the player
ConsoleCommandHandler.AppendLog($"[green]Kicked[/] {args[0]}");
}));
- Console only commands. A command that other callers (launch arguments) should run too goes to
CommandRegistry, it runs on the main thread
- Commands run off the main thread. Call
await UniTask.SwitchToMainThread() before touching Unity objects
- Output uses Spectre markup:
[green]text[/], [yellow], [red], [cyan]...