question

alexmerza avatar image
alexmerza asked

Server Get Character Entity

I have just started looking into entities and I'm trying to figure out the best way of going about this.

Currently, a player is able to save and load level information to a local file, problem is we need this file to be available for the headless server to load. We wanted to push the data to the specific Character entity that invokes the save method.

As far as I can tell, the entity system relies on an entity token that you pass forward with the login credentials. When a player logs in though, they login with the client API. The server API doesn't have access to more than just the Player ID's that are currently logged in.

How do we go about requesting an entity of a particular character in game from the server?

10 |1200

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

brendan avatar image
brendan answered

Aha! Okay, upon review, this is actually much simpler than originally stated, so I'll enter this as the correct answer. What you should do in the case of a server is to have the server only act as a Title Entity. So, call GetEntityToken with no body, so that you get the Title Entity token, and then use that in the X-EntityToken header in order to make the Entity API call you need. The key thing to note is that the Entity ID you're querying does need to be sent to the server, so that it can provide that in the call.

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

claytoniousmojo avatar image claytoniousmojo commented ·

Well, I'll be darned - that did, indeed work. From the C# SDK from the server, I'm now just doing this:

awaitPlayFabAuthenticationAPI.GetEntityTokenAsync(newGetEntityTokenRequest())

(so it's an empty GetEntityTokenRequest) and that works. I can then follow it successfully with a call to PlayFabDataAPI.GetFilesAsync() with a filled in EntityKey. But this makes me wonder: what kind of internal state is the C# SDK storing in order for this to work? And what are the ramifications of that since I'm doing this on a server where many different clients might be running requests concurrently?

Thanks for this updated info!

0 Likes 0 ·
brendan avatar image brendan claytoniousmojo commented ·

The number of players isn't really important. The server is authenticating as the title in the entity calls, which is why they'll work regardless - that's specifically how the SDK code is set up.

0 Likes 0 ·
brendan avatar image
brendan answered

[Edit: Ignore this - there was some confusion around token usage when this was originally posted]

You should be able to simply get the EntityToken for the character using GetEntityToken, if your policy is set correctly. No login credentials are needed, since you'd be making this call from a server (and so, using a Secret Key). Are you running into any issues with that process and, if so, what are the details?

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

alexmerza avatar image alexmerza commented ·

Well, I suppose the problem lies with the policy being set properly. I get access denied when attempting to GetEntityToken(). Since by default all requests are denied, what permission needs to be set into effect?

0 Likes 0 ·
brendan avatar image brendan alexmerza commented ·

Apologies for the delay - we're working on a full tutorial for Entity Policies which we hope to have posted this week. But the default Entity policies actually enable what you describe - read/write of the Character Entity Objects/Files by the player who owns the Character (but not by any other player), and read/write by a server. What are the details of the API call as you're making it, and what is the specific response you get back?

0 Likes 0 ·
alexmerza avatar image alexmerza brendan commented ·

Sure thing, this is the request:

Request: {
    "Entity":
    {
        "Id": "F2B0E2AE82371914",
        "TypeString": "character"
    }
}<br>

and this is the response:

Response : {"code":403,"status":"Forbidden","error":"NotAuthorized","errorCode":1089,"errorMessage":"The claim was not allowed to perform the requested action based on the entity's access policy. Policy comment: By default, all requests are denied. If you expected this request to succeed, you may be missing a policy. See the permissions APIs in P
layFab's Admin Api to add a permission.","errorDetails":{}}
<br>

The request was passed to the GetEntityToken() function.

0 Likes 0 ·
alexmerza avatar image alexmerza commented ·

Still waiting for a reply on this.

0 Likes 0 ·
claytoniousmojo avatar image claytoniousmojo commented ·

Having the same problem here: "The claim was not allowed to perform the requested action based on the entity's access policy". How do we configure this to allow accessing of entities from our servers?

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.