Skip to main content

JoinedServerGameMode

A class in Root.Township, the global namespace.

Client game mode for joining a game server: connects with retries, loads the server's scene and tells the server it's ready to spawn. Goes back to the main menu if it fails.

Constructors​

MemberWhat it is
JoinedServerGameMode(GameServerInfo server)Creates a JoinedServerGameMode from server.

Fields​

5 private and internal fields
MemberWhat it is
private bool isDeepLinkSet when the join came from a deep link.
private const int JoinRetries24 connection attempts.
private const int JoinRetryDelayMs5000 ms between connection attempts.
private const int LostConnectionDelayMs2000 ms wait after losing the connection before leaving.
private readonly GameServerInfo serverThe server being joined.

Methods​

MemberWhat it is
override async Task<bool> ActivateAsync()Shows the loading scene and tries to connect. On failure, returns to the main menu and returns false.
static JoinedServerGameMode CreateDeeplinkJoinGameMode(GameServerInfo server)Makes the mode for a deep link join, which shows a deep link error message if joining fails.
override void OnStartSucceeded()Starts listening for the connection dropping.
override async Task StopModeAsync(string reason)Fades to black, disconnects from the server and shuts down networking.
5 private and internal methods
MemberWhat it is
private async Task<JoinResult> ConnectToServer()Tries to connect up to 24 times, 5 seconds apart. Stops early on a failure that can't be recovered.
private async Task<JoinResult> LoadGameScene(JoinResult result)Loads the server's scene, sets up the client scene and sends ClientIsReadyToSpawn.
private static async void LostConnection(Connection connection)Shows "Lost connection to server", waits 2 seconds, then stops the current game mode.
private async Task ReturnToMainMenuOnFailure(JoinResult result)Logs the error, loads the main menu, shows the error and shuts down networking.
private static async Task SetupLoadingScene()Creates the loading scene and fades the screen back in.