question

stefanos2004 avatar image
stefanos2004 asked

Get MatchID from server in Unreal Engine 4

How do I get the MatchID from the server once launched in Unreal Engine 4? I can see its passed in the session id and so, but how do I actually retrieve that? Thanks!

sdksunrealsupport
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

·
Citrus Yan avatar image
Citrus Yan answered

Assuming that you integrated the GSDK within your server, please refer to this section to learn about getting configuration settings within your game server:

https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/integrating-game-servers-with-gsdk#getting-configuration-settings-within-your-game-server

For instance, to retrieve the session id, you can do the following:

auto it = config.find(Microsoft::Azure::Gaming::GSDK::SESSION_ID_KEY);
if (it != config.end())
{
std::string sessionId = config[Microsoft::Azure::Gaming::GSDK::SESSION_ID_KEY];
}

Please note that it’s only available after allocation (once readyForPlayers returns true).

3 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.

stefanos2004 avatar image stefanos2004 commented ·

Thank you! How can I know on the server when ready for players returns true? I want to get the info once I get the players joining the server as I want to know the final number of players going to the server.

0 Likes 0 ·
stefanos2004 avatar image stefanos2004 commented ·

Seems like I can call "getInitialPlayers();" on "playerConnected()", is this the correct way?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan stefanos2004 commented ·

ReadyForPlayers will return true if the game server was allocated (clients are about to connect), please see the implementation here:

https://github.com/PlayFab/gsdk/blob/0aa520a76b680d482eceb9a5dcfd11ceb36dd063/csharp/GSDK_CSharp_Standard/GameserverSDK.cs#L56

GetInitialPlayers is used to returns a list of the initial players that have access to this game server, used by PlayFab's Matchmaking offering after server allocation. To get the actual list of players connected to the server, you can use the following mechnism to add connected players into a list, and access it later on:

static private List<ConnectedPlayer> players = new List<ConnectedPlayer>();


static void OnPlayerConnected()
{
    // When a new player connects, you can let PlayFab know by adding it to the vector of players and calling updateConnectedPlayers
    players.Add(new ConnectedPlayer("player_tag"));
    GameserverSDK.UpdateConnectedPlayers(players);
}

https://docs.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/integrating-game-servers-with-gsdk#csharp-3

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.