I'm pretty new to hosting multiplayer games on dedicated servers. I've been trying to figure out how to use PlayFab Matchmaking to launch a Multiplayer Server. Our multiplayer game is using Photon Bolt with Unity3D. Once the server is launched, I want to use the SessionId from PlayFab Matchmaking to start a Photon Bolt session with the same session ID. The clients can then use the returned MatchId from PlayFab to join the correct Photon Bolt session.
My main question is: how do I retrieve the SessionId (and InitialPlayers and PreferredRegions) on the server? I tried using the event PlayFabMultiplayerAgentAPI.OnSessionConfigUpdateEvent, but everything inside the SessionConfig callback is always null. Also, the callback is sometimes called twice, which is not what I want.
Answer by justin-1 · May 28, 2021 at 10:35 AM
I figured out what went wrong. I was using this Photon Bolt tutorial with PlayFab Servers as a base.
But you need to make an important change for matchmaking to work. In PlayFabHeadlessServer.cs, you need to remove the following lines in Start():
// Run Bolt Server OnServerActive();
These lines caused my server to immediately launch instead of waiting for the callback of PlayFab.
The session/match ID can then be retrieved after the 'PlayFabMultiplayerAgentAPI.OnServerActiveCallback' event is called with the following code:
string sessionId = PlayFabMultiplayerAgentAPI.GetConfigSettings()[PlayFabMultiplayerAgentAPI.SessionIdKey];
So you don't need to use 'PlayFabMultiplayerAgentAPI.OnSessionConfigUpdateEvent' for this.
This is super useful. It took me a lot of effort to know the session id is empty. And this is the root cause of it.
Answer by Citrus Yan · May 21, 2021 at 02:03 AM
If you integrate Matchmaking with PlayFab Multiplayer Servers following this tutorial: Integrating with PlayFab Multiplayer Servers - PlayFab | Microsoft Docs, your server will receive the following information passed by matchmaking:
Therefore, you should be able to use the GSDK to retrieve such info once the server is launched, here is a sample code showing how to do that in C#:
// Get all the configuration values IDictionary<string, string> config = GameserverSDK.getConfigSettings(); // Retrieve a particular configuration value if (config.TryGetValue(GameserverSDK.SessionCookieKey, out string sessionCookie)) { // sessionCookie contains the value }
For more details please check out: https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/integrating-game-servers-with-gsdk#getting-configuration-settings-within-your-game-server
Thank you for your response.
I've followed the tutorial. I think I'm not understanding the build configuration properly. In your response, it sounds as if matchmaking is supposed to launch a server once a match is found. So I tried setting the 'Target standby' to 0, and 'Maximum' to 1 in the build config for my region. But then, a server never gets launched. Polling 'GetMatchmakingTicket' every 7 seconds will keep returning 'WaitingForServer' after a couple of polls, until the timeout is finally reached.
If I set the 'Target standby' to 1 in the build config, my server build is immediately launched, even though no match is queued in the matchmaking. 'GetMatchmakingTicket' will then succeed with a match ID, but the server never receives this match ID, since it was already started before the match was made.
So how am I supposed to set up the server build configuration so I can receive a match ID on the server once matchmaking has succeeded? Or am I doing something else wrong?
The "SessionId" passed to the server is equal to the "MatchId" received from "GetMatchmakingTicket". What do you mean by "but the server never receives this match ID", do you mean you cannot get the MatchId (SessionId) using GSDK once matchmaking has succeeded?
Yeah, that's what I mean. I've tried listening to 'PlayFabMultiplayerAgentAPI.OnServerActiveCallback', but that gets called as soon as the server is launched if 'Standby servers' is set to something above 0, even though matchmaking hasn't created a match yet. Thus, it doesn't have a MatchId.
I'm using this code to try to get the session/match ID:
Debug.Log(JsonConvert.SerializeObject(PlayFabMultiplayerAgentAPI.GetConfigSettings())); string sessionId = PlayFabMultiplayerAgentAPI.GetConfigSettings()[PlayFabMultiplayerAgentAPI.SessionIdKey];
The log then contains the following JSON:
{ "heartbeatEndpoint": "[...]:56001", "logFolder": "[...]", "game_server1": "5056", "fullyQualifiedDomainName": "[...]", "game_server2": "27002", "vmId": "xcloudneu4[...]:NorthEurope:[...]:tvmps_[...]_d", "publicIpV4Address": "20.[...]", "bolt_server": "60001", "buildId": "[...]", "master_server1": "5055", "master_server2": "27001", "region": "NorthEurope", "serverId": "[...]", "name_server1": "5058", "certificateFolder": "[...]", "sharedContentFolder": "[...]", "name_server2": "27000", "titleId": "[...]" }
So no key for 'sessionId', thus the next line generates a KeyNotFoundException.
How to pass data from one player to another in matchmaking? 1 Answer
PlayFab + Unity + Mirror - Some guidance would be awesome! 1 Answer
[VERY URGENT] Unity Matchmaking with Mirror cannot connect to server 2 Answers
Unity+Mirror Cant connect to allocated gameserver, cant RDP either! 2 Answers
Where can I find an Android/Unity compatible version of Multiplayer SDK ? 2 Answers