question

foot@globz.com avatar image
foot@globz.com asked

Photon connect with Flash SDK

Hi,

I'm new to PlayFab, and I try to use PlayFab/Photon with Flash.

Here is my starting point :
http://api.playfab.com/docs/using-photon-with-playfab/

The first steps are ok and I get my PhotonAuthenticationToken with PlayFabClientAPI.GetPhotonAuthenticationToken.

Then, according to Photon sdk for for flash, I try to connect to the photon server, but I couldn't find the server url.

I tried PlayFabClientAPI.GetCloudScriptUrl to get a server url, but I can't connect. Here is some code : 

var lReq:GetCloudScriptUrlRequest = new GetCloudScriptUrlRequest({ "Version":1, "Testing":false });
PlayFabClientAPI.GetCloudScriptUrl( lReq, onCloudScriptUrl, onError);

(...)

private function onCloudScriptUrl(e:GetCloudScriptUrlResult):void {
vCloudUrl = e.Url;
vClient = new LoadBalancingClient(vCloudUrl, vPhotonApplicationId, "1.0");
//vClient.setCustomAuthentication(vToken); // vToken from PlayFabClientAPI.GetPhotonAuthenticationToken
vClient.connect();

Here is the error trace : 

[error] Master: PhotonPeer[_onError] - Connection error:
[info] LoadBalancingClient: State: ConnectingToMasterserver -> Error
[error] LoadBalancingClient: Load Balancing Client Error 1001 Master peer error

Thanks for your help !

Fabien

 

 

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

Cloud Script is actually hosted JavaScript handlers which you load into PlayFab so that you can call them from the client. Have a look at the Servers->Cloud Scripts tab in the Game Manager, to see what I mean (there's a default script there that all new titles get).

After you've retrieved a Photon authentication token using our API, the next step is to set that as your authentication parameters (SetAuthParameters), so that your subsequent calls to the Photon Cloud API methods to matchmake, create and join room, etc., all work as expected. The next section of the walkthrough ("Create and join a Photon Room") shows how to do this.

Now, this assumed you're using the Photon Cloud (Photon Turnbased, Realtime, Chat). Since you mentioned Photon Server, I should highlight the difference in their offerings:

Photon Cloud includes all of the cloud-based functionality that Exit Games offers as a pre-existing set of servers that you can use to connect players to each other and exchange packets. It's a very popular and very powerful service which powers a number of games that need this sort of quick and easy connectivity.

Photon Server is a pre-built server core that you can download from Exit Games and use as the central component of your own custom game server, with your logic built onto it (for games requiring complex logic with tight latency, such as multiplayer actions games like shooters). We can host Photon Server as part of our custom game server hosting - you can read more about that here: http://api.playfab.com/docs/custom-game-servers/

10 |1200

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

foot@globz.com avatar image
foot@globz.com answered

"After you've retrieved a Photon authentication token using our API, the next step is to set that as your authentication parameters (SetAuthParameters), so that your subsequent calls to the Photon Cloud API methods to matchmake, create and join room, etc., all work as expected."

This is the exact step where I'm stuck :

1. I have the Photon Application Id

2. I have the Photon authentication token 

3. I have the Cloud Script Url

But I can't find how I can use SetAuthParameters.

I define the LoadBalancingClient (from photon sdk for flash) :

   var vClient:LoadBalancingClient = new LoadBalancingClient(vCloudUrl, vPhotonApplicationId, "1.0");

I tried to set custon auth, but doesn't seem to work : 

   vClient.setCustomAuthentication(vToken, 1); 

And get error when I try to connect : 

  vClient.connect();

 

I'm supposed to use Cloud Script for the initial connect ? 

 

Notice that the link https://playfab.com/cloud-script is dead

PS : indeed, I want to use the Photon Cloud (and I have the correct Photon Application IDs)

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

Where did you find a link to the old Cloud Script URL? I'll get that fixed. The correct one is: https://api.playfab.com/docs/using-cloud-script/

But no, Cloud Script is used in one of two ways:

1. The Client makes a call to run a Cloud Script handler.

2. A callback from Photon Cloud (webhook) triggers a Cloud Script handler, as described in the Using Photon with PlayFab tutorial. In this case, you would already have authenticated the user with Photon - the callback is as a result of creating a room, joining one, etc.

For setCustomAuthentication, you're setting the auth type to 1. As shown in the Exit Games docs for their Flash SDK, this should be left as the default, which is the Custom auth you need:

http://doc-api.photonengine.com/en/flash/current/exitgames/photon/loadbalancing/LoadBalancingClient.html#setCustomAuthentication()

10 |1200

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

foot@globz.com avatar image
foot@globz.com answered


Tanks for your answers, but I stil can't connect to Photon.

What I have :
- Photon Application ID for Turnbased
- Photo token (with PlayFabClientAPI.GetPhotonAuthenticationToken)
- Flash sdk from Photo with a LoadBalancingClient

What i can't do :
- LoadBalancingClient.connect returns a "Master peer error"

My questions :
- what is this masterServerAddress I should use for Photon Cloud ?
- what are the "authParameters" expected for LoadBalancingClient.setCustomAuthentication(authParameters:String, authType:int = -1) ? I couldnt find any doc about this. (I tried 'token=[MYPHOTONTOKEN]' with no success)


Note : I found 'old' Cloud Script URL in "Revision 1" Cloud Script (line 13).

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

The required query string parameters to authenticate a PlayFab user with Photon are:

  1. "username": PlayFabId
  2. "token": Photon token retrieved using "GetPhotonAuthenticationToken" API call

I'm not familiar with the Flash SDK but you can try:

vClient.setCustomAuthentication("username=" + userId + "&token=" + vToken)

or

vClient.setCustomAuthentication("?username=" + userId + "&token=" + vToken)

10 |1200

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

foot@globz.com avatar image
foot@globz.com answered

I finally could connect to the server, thanks for your help :)

Here are the points I needed : 

1. MasterServerUrl = "app-eu.exitgamescloud.com:4530"

2. vClient.setCustomAuthentication("username=" + PlayFabUserId + "&token=" + PhotonAuthenticationToken)

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.