Skip to main content

ServerHostingGameMode

A class in Root.Township, the global namespace.

Game mode for running as the server: loads the server's scene and starts it here, or launches a separate headless process.

Constructors​

MemberWhat it is
ServerHostingGameMode(IServerAccess server, bool isHeadless, bool isExternalLaunch = false, int port = 1757, bool isRunningLocally = true)Creates a ServerHostingGameMode from server, isHeadless, isExternalLaunch, port and isRunningLocally.

Fields​

5 private and internal fields
MemberWhat it is
private bool isExternalLaunchLaunch a separate server process instead of starting here.
private bool isHeadlessRun the server without graphics.
private bool isRunningLocallyPassed to the server start as whether it runs locally. Default true.
private int portPort to host on. Default 1757.
private IServerAccess serverAccess to the server being hosted.

Properties​

MemberWhat it is
override bool IsClient { get; }Always false.
static bool IsRelaunchingTheGame { get; set; }Static flag for relaunching the game. Not set in this class.
override bool IsServer { get; }Always true.

Methods​

MemberWhat it is
override async Task<bool> ActivateAsync()Loads the scene and starts the server (headless or not), or launches an external server. Goes back to the main menu on failure.
override void OnStartSucceeded()Stops the active VR or desktop platform once the server is up.
override async Task StopModeAsync(string reason)Stops the mode, then shuts down the ServerHandler with an expected shutdown reason.
4 private and internal methods
MemberWhat it is
private void RestartAsHeadless()Launches a headless server process and quits this one. Needs /login or /login_hash on the command line.
private void StartExternalServer()Starts a new game process in batch mode with /start_server, the port and the user's tokens on the command line, logging to the server's logs folder.
private async Task<bool> StartHeadlessServer()Starts the server here if already headless, otherwise restarts as a headless process.
private async Task<bool> StartServer()Starts the server through ServerLifetimePipeline.AttemptToStartServer.