question

Gabriel Dechichi avatar image
Gabriel Dechichi asked

[GSDK] Proper way to end session in a MultiplayerServer

I just wanted to confirm the life cycle for a Multiplayer Server deployed using the new GSDK, and couldn't find any documentation on the subject.

So is the life cycle something like:

- Server is deployed and starts. GameState is Initializing
- Once server loads the level and is ready to receive player it sets GameState to StandingBy
- Matchmaking (or the game) requests a server. Playfab finds an available one and send Operation::Activate. Server GameState changes to Active

- Match ends, and here's the question: What happens then? Should the server go back to StandingBy, or should the game code call MultiplayerServer/ShutdownMultiplayerServer and force the server to terminate?

Thanks,

Gabriel

sdks
10 |1200

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

Seth Du avatar image
Seth Du answered

Basically when a match is done and all the necessary processes like recording logs are finished, you can call Application.Quit() in the server instance to shut down, which is the most common scenario. MultiplayerServer/ShutdownMultiplayerServer is also feasible but it is shutting down the server externally. It depends on your requirement.

Here is how it is handled from the official sample:

private void OnShutdown()
{
      Debug.Log("Server is Shutting down");
      foreach (UnityNetworkConnection conn in UNetServer.Connections)
      {
      conn.Connection.Send(CustomGameServerMessageTypes.ShutdownMessage, new ShutdownMessage());
      }


      StartCoroutine(Shutdown());
}


private IEnumerator Shutdown()
{
      yield return new WaitForSeconds(5f);
      Application.Quit();
}

In terms of standby, it won’t be necessary for the developer to monitor state for the multiplayer server as it is an automatic feature. You may also refer to the technical documentation about Standby feature: https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/dynamic-standby

10 |1200

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

scottadams avatar image
scottadams answered

I had the same issue. NO documentation on life cycle that I could find.

What I ended up doing was having the server just exit. I could not find a way in the API to go back to the standby state. Once it's heart beat stopped the agent recycled the server and brought another into standby mode.

10 |1200

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

Jorge Mendez avatar image
Jorge Mendez answered

In my side the server never gets to Active state.. even when im playing the game with the .exe running in the server.

2 comments
10 |1200

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

Seth Du avatar image Seth Du ♦ commented ·

May I ask how do you implement the server build? Which platform are you using? Usually there will be a delegate for onActive action, when an instance is requested, the server will start to listen connections on the port.

0 Likes 0 ·
jack-2 avatar image jack-2 commented ·

May I ask are you able to fix that problem? I am having the same issue here.

0 Likes 0 ·

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.