question

kfboelterbotl avatar image
kfboelterbotl asked

CloudScript Handler to get player IDs from segment often returns Internal Server Error

We have this CloudScript to get all the PlayFab Ids from player in a segment:

handlers.onGetOnlinePlayers = function(args, context)
{
  var onlineList = {};
  
  onlineList = server.GetPlayersInSegment({
    "SegmentId": "DF433C53264DE4EF"
  })
  
  var playerListIDs = {"onlinePlayers":[]};
  
  for(i =0; i < onlineList.ProfilesInSegment; i++)
  {
      playerListIDs.onlinePlayers.push(onlineList.PlayerProfiles[i].PlayerId);
  }
  
  return playerListIDs;
  
};

It works exactly how it should sometimes and finds all the players in the segment, however, this message is often received when executing it from the dashboard

{
    "FunctionResult": null,
    "Logs": [
        {
            "Level": "Error",
            "Message": "PlayFab API request failure",
            "Data": [
                [
                    []
                ],
                [
                    [
                        [
                            []
                        ]
                    ]
                ],
                [
                    []
                ]
            ]
        }
    ],
    "ExecutionTimeSeconds": 7.0001722,
    "MemoryConsumedBytes": 108888,
    "APIRequestsIssued": 1,
    "HttpRequestsIssued": 0,
    "Error": {
        "Error": "InternalServerError",
        "Message": "InternalServerError",
        "StackTrace": "Error\n    at handlers.onGetOnlinePlayers (9BBE-main.js:416:23)"
    }
}
apisCloudScript
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

·
brendan avatar image
brendan answered

Can we start with a high level overview of what you're attempting to accomplish? It looks like you're attempting to track on all online players. If so, that's not going to work for a few reasons:

1. Segment evaluation, which is an expensive operation, occurs on a call to GetPlayersInSegment. For that reason, you can't call it at high frequency, and certainly not based on a client-driven action.

2. Since we don't use a socket-based connection (we will provide this in a future release), you'd be tracking on this by updating some value on the player account. That's fine if you're doing it every minute or two, but if you're attempting to do this at high frequency, that runs the risk of exceeding our fair use terms.

3. For any game with a good user population, you'll exceed the limit on how many profiles can be returned in a single call to GetPlayersInSegment. Using the ContinuationToken in a Cloud Script isn't really an option because it would push the script to excessive API calls and processing time.

We will be providing a "presence" system of our own in a future release. For now, I would recommend using the player last login time (which you can get from the profile information in leaderboards, for example) as a way to get information on active players. Alternately, if your game is realtime gameplay focused, you may need to consider using a custom game server, so that you can have players connect to it for shared realtime information on others playing.

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.

chorustempo avatar image chorustempo commented ·

@Brendan Sorry to necro this thread, but is there an update on the presence system you mentioned? I'm trying to do the same thing (get player data for a segment via the client), albeit with a smaller number of players in the segment as is only dealing with a small section of the total online players and they only remain in the segment for 20 mins max. And the request from the client won't be very often.

In your point 3. can you give a rough estimate of what would be the upper limit on the number of profiles returned using the above method? Are we talking 10, 100, 1000?

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.