question

charlielange avatar image
charlielange asked

How do you properly shut down a game server running in ThunderHead?

void Start()
{
	GameserverSDK.RegisterShutdownCallback(OnShutdown);
}

public override void OnServerDisconnect(NetworkConnection conn)
    {
        base.OnServerDisconnect(conn);
        players.Remove(players.Find(i => i.PlayerId == conn.connectionId.ToString()));
        GameserverSDK.UpdateConnectedPlayers(players);


        if (numPlayers <= 0)
            shutDownCoroutine = StartCoroutine(ShutDownCo());
            
    }


    protected virtual IEnumerator ShutDownCo()
    {
        yield return new WaitForSeconds(secondsToShutdown);
        var request = new ShutdownMultiplayerServerRequest()
        {
            BuildId = GameserverSDK.getConfigSettings()[GameserverSDK.BuildIdKey],
            Region = (AzureRegion)Enum.Parse(typeof(AzureRegion), GameserverSDK.getConfigSettings()[GameserverSDK.RegionKey]),
            SessionId = GameserverSDK.getConfigSettings()[GameserverSDK.SessionIdKey]
        };


        PlayFabMultiplayerAPI.ShutdownMultiplayerServer(request, OnShutdownResponse, OnPlayFabError);
    }


    void OnShutdown()
    {
        LogMessage("Shutting down...");
        NetworkManager.singleton.StopServer();
        Application.Quit();
        //_listener.Close();
    }

Am I supposed to make the call to shut down the server as shown above, or does ThunderHead do it automatically when the GameserverSDK.UpdateConnectedPlayers(players) is 0? All of the above logic is within the Game Server that is running on ThunderHead. This is in Unity using the PlayFabSDK and GameServerSDK.

unity3dsdks
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

We just call Application.Quit when the server player count becomes 0. The GSDK's OnShutdown() call is only performed if a ShutdownMultiplayerServer request is made by the Multiplayer API (by you, in an external application) or if the GSDK receives a shutdown through some other means (maintenance / build removal from region / etc).

I don't think having that request being made by the server itself is a good idea (nor should it be necessary). If your container is set up properly, when Application.Quit() is called, the server instance should stop and switch from Active to StandBy within a few seconds.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.