Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by justin-1 · May 21, 2021 at 01:21 AM · unity3dMatchmakingmultiplayer

[Unity3D] How to retrieve SessionId on Multiplayer Server after Matchmaking succeeded?

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.

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

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.

Comment
Mikhail Yefremov
Kaiwen Yu

People who like this

2 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image justin-1 · May 28, 2021 at 10:53 AM 1
Share

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.

avatar image Kaiwen Yu · Apr 11 at 02:13 AM 0
Share

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.

avatar image

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:

  • SessionId - The SessionId for the server will be equal to the MatchId for the match.
  • InitialPlayers - This value is set to the list of members in the match. The list of players can be read in the game by using the GSDK.
  • PreferredRegions - This field is set to the RegionPreferences field from the match. The game server service will choose an appropriate region for the server from this list.

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

Comment
Melissa Hanak

People who like this

1 Show 5 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image justin-1 · May 25, 2021 at 08:54 AM 0
Share

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?

avatar image Citrus Yan justin-1 · May 26, 2021 at 02:30 AM 0
Share

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?

avatar image justin-1 Citrus Yan · May 26, 2021 at 07:47 AM 0
Share

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.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    4 People are following this question.

    avatar image avatar image avatar image avatar image

    Related Questions

    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

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges