question

Martin K avatar image
Martin K asked

Trying to get a list of sessions to join?

I am trying to implement what I thought was the simplest, default way of joining multiplayer games:
1. client connects, if there are no multiplayer sessions running it creates one
2. if one already exists it joins that

- no consideration to stats, teams, skills or any kind of advanced matchmaking are required.


- the official playfab sample doesn't do this, as every time it runs it attempts to create a new server:
https://github.com/PlayFab/gsdkSamples/tree/master/WindowsRunnerCSharp

So after searching the forums I found this thread:
https://community.playfab.com/questions/39583/mutliplayer-how-to-get-servers-to-join-to.html

- here, someone recommended that I make the following 3 consecutive calls:
1. Call ListBuildSummaries
2. Call ListMultiplayerServers
3. Call RequestMultiplayerServer

- I tried this, but ListMultiplayerServers cannot be called from the client. One of the PlayFab techs in another thread:
https://community.playfab.com/questions/39941/how-to-use-listmultiplayerservers-in-a-game-client.html

- suggested that I use Cloudscript for this. So I am off to the Cloudscript tutorial. On the page "Writing custom cloudscript":
https://docs.microsoft.com/en-us/gaming/playfab/features/automation/cloudscript/writing-custom-cloudscript

- it says that the 'server' object "Has access to all server-side API calls listed in the PlayFab API reference documentation."

Great! I head over to that page to look for ways how to call ListMultiplayerServers, but there is no documentation for Javascript, only for REST web requests. I tried to guess the correct function name and the object hierarchy to call:

I tried calling server.ListMultiplayerServers(). This returned an error informing me that 'server.ListBuildSummaries is not a function'.

Please help. And please write documentation for your software, as I am literally spending my time guessing how to call remote javascript functions...

apissdkssupport
10 |1200

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

Martin K avatar image
Martin K answered

Thanks for the quick reply @SethDu.

However, I got the following error now:

TypeError: entity.ListBuildSummaries is not a function  at handlers.getServers (A382B-main.js:42:29)  at Object.invokeFunction (Script:116:33)

I feel like I am missing some fundamental understanding of how this is supposed to work. The problem is that the documentation of how to call these javascript functions is simply not available, so I feel like I am coding blindfolded.

Can you help me out? This is my full cloudscript code (buildid and region are sent from the client):

handlers.getServers = function (args, context) {
  var build = null;  

var region = null;  

if (args && args.build && args.region)  {
	build = args.build;  
	region = args.region;    
}
request = {BuildId: build, Region: region }    

var serverList = entity.ListBuildSummaries(request);    

if(serverList)  {  log.info(serverList);  }  else  {  log.error(serverList);  }
  return { messageValue: serverList };

};
1 comment
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 ·

Sorry for the confusion.

I have spent more time to testify it. Even though those APIs belong to entity model, we may use multiplayer.xxxx to execute them on Cloud Script function. I have written codes for your reference.

handlers.getbuildsum = function (context) {
    var request = {};
    var result = multiplayer.ListBuildSummaries(request);
    return result;
}
handlers.listservers= function (context) {
    var request = {
  "BuildId": "dc08f676-cc20-4872-bdc4-944564502c66",
  "Region": "WestUS"
};
    var result = multiplayer.ListMultiplayerServers(request);
    return result;
}

1 Like 1 ·
Seth Du avatar image
Seth Du answered

Short answer for your question is that to call ListBuildSummariesAPI on Cloud Script, you need to use multiplayer.ListBuildSummaries (request).

Basically there are 2 types APIs on PlayFab. The Classic Client/Server/Admin API and the new entity API. The “client” API means Client API in classic model and those who requires title_player_account entity token in Entity Model. What you have mentioned the ‘Server’ is simply including those API that requires a title_level entity token or secret key. However, in Cloud Script, multiplayer related API should be called via multiplayer.xxxxx.

If you refer to the index of API reference: https://docs.microsoft.com/en-us/gaming/playfab/api-references/, you may see a list of folders where all the APIs are classified well. Among them, only the admin, client, matchmaker and server folders contain the classic APIs. Meanwhile, the rest of them are basically all entity APIs, where an Entity Token is required for the request header.

Nevertheless, a title_player_account entity token has very limited permission, just like classic client API calls.


10 |1200

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

Kris Akins avatar image
Kris Akins answered

I'm still trying to understand the reasoning behind restricting access to basic server/game info via the SDK. I get that we don't want users manipulating the infrastructure. But what security risk is there for the client to simply request from PlayFab a list of servers to connect to?

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.