question

brendan avatar image
brendan asked

PlayFab or PlayFab + Photon Turnbased for turnbased game

alandyshev
started a topic on Fri, 18 September 2015 at 2:55 PM

I'm developing a turnbased multiplayer game and I've decided to use PlayFab as a backend for it.

Now I'm working on matchmaking and I was going to use Photon Turnbased for it first. But then I saw a Cloud Script example for asynchronous matchmaking here: https://github.com/PlayFab/CloudScriptSamples/tree/master/AsynchronousMatchmaker

So now I'm thinking: is Photon Turnbased at all needed? May I use only PlayFab and have all the required functionality? What are the benefits of using Photon Turnbased together with PlayFab over using only PlayFab? Are there any things that require the use of Photon Turnbased? Or any things that are easier to implement using Photon Turnbased?

Thanks. You'll help me a lot if you shed a light on it.

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

14 Comments
Brendan Vanous said on Fri, 18 September 2015 at 3:27 PM

The key is, if you have a need for any real-time connected multiplayer or chat between users, that would be the place where Photon Cloud is an outstanding choice for your title. If you don't have any need for that, you can indeed manage your asynchronous gameplay using PlayFab. If there are special features of your game that you're not sure how they would be managed in the PlayFab services, feel free to send us the details and we can work with you on the best approach.

Brendan


alandyshev said on Sat, 19 September 2015 at 1:54 AM

Why is there an option to use Photon Turnbased with PlayFab then? According to what you said it's not needed. Only Photon Cloud can be helpful. Am I right?

Also, in PlayFab itself there are 2 ways to implement matchmaking:

  1. There's API for matchmaking described in documentation.
  2. There's an example of asynchronous matchmaking implemented using CloudScript.

How to decide which one should I use?

Thanks.


Brendan Vanous said on Sat, 19 September 2015 at 12:38 PM

Actually, the confusion here stems from the term "Turnbased". Photon Turnbased is actually a real-time connection between players. The difference between it and Photon Realtime is that Photon Turnbased has a lower messages per second limit.

With PlayFab matchmaking, the API (Matchmake) is for use with hosted custom game servers.

Brendan


alandyshev said on Sun, 20 September 2015 at 9:57 AM

Brendan, thanks for your answer.

As I understand Photon Cloud and Photon Turnbased give me ability to establish P2P connection between players when one device is firing an event and another device receives it immediately.

And PlayFab gives me ability to implement authoritative server logic when player events are handled in Cloud Scripts in backend and resulting game state is stored there.

However as I've seen in the AsyncMatchmaker example you need to poll the state of server to get it. And in that examples the requests are sent each 60 seconds. However I'd like my player to know immediately when opponent ends turn. So I need to send requests to server every second, for example. Is that possible? Or is it better to use Photon Turnbased together with PlayFab to have ability to notify player when his turn starts?

Thanks again for your help.


alandyshev said on Sun, 20 September 2015 at 10:24 AM

And one more question is about Photon Turnbased and PlayFab integration via WebHooks.
I need to implement authoritative server logic for my game in Cloud Script, to protect the game from cheating. However I may want to use Photon Turnbased as well, and my client will send requests with moves as Photon Events.

As I understand it, here's how things work:

  1. 1st player fires Photon Event.
  2. WebHook for Photon Event is fired and handled by PlayFab CloudScript.
  3. Move result is calculated by CloudScript and the new game state is saved somewhere in UserReadonlyData or SharedGroupData on backend.
  4. 2nd player device receives Photon Event.
  5. 2nd player sends request to PlayFab in order to get updated game state.

Is the workflow right? Will it work? Is there a guarantee that the game state on PlayFab will be updated earlier than 2nd player will handle Photon Event?

Thanks.


Brendan Vanous said on Sun, 20 September 2015 at 4:26 PM

Hi again,

Generally speaking, the only time you need that level of precision (knowing to the second when it's your turn) is in a realtime connected experience. If the idea is that the users are playing in realtime, taking moves immediately after the other user, then yes, I would suggest using Photon Turnbased. If not, and you want to signal the user as soon as his turn is ready, you could use Push Notifications, though bear in mind that the user must agree to accept Push messages, and can turn them off in the device operating system without the title being aware of the change. If you use a polling system, it should only query the data in the PlayFab service periodically, the same as the "presence" system in Xbox Live and Playstation Network (they poll about every 20 seconds). Hitting us with calls every second (or more, given that you'd be making other game calls, in addition to the polling) would result in your title getting throttled, as that's not a sustainable calling pattern.

For your webhooks question, it depends upon the specifics. In your description, is the event raised by player 1 both the trigger for the webhook and the signal to player 2? If so, then no, there's no way to guarantee that the event will reach the PlayFab service as a webhook call before player 2 receives it. Due to the potential of packet loss, there's actually no way to guarantee that one or the other will receive it at all on the first attempt, In general, you should have the logic of the move processing control when player 2 is told that it's his turn. Alternately, if you plan to use Photon, you could have player 1 make his move and, once it is complete, set a property in the Photon Room to indicate that it's the other player's turn.

Brendan


alandyshev said on Mon, 21 September 2015 at 1:02 AM

Hi Brendan. Thanks for another helpful answer.

In fact, my game will have Fast mode when players can take turns no longer than 2 minutes, and slow mode when player has about 2 days to take turn. So, for Fast mode I really need that level of precision.

And for Slow mode I need turnbased functionality for asynchronous gameplay. Since Push Notifications are not reliable and can be disabled I think I'll proceed with Photon Turnbased + PlayFab solution. I'll notify players about their turn via Photon.

Regarding the webhooks question, I got it that they're not reliable as well, due to possible packet loss. As I understand it the problem here is that we don't receive callback from the WebHook and don't know whether it's handled successfully.

So I guess it's better to call Cloud Script methods straight from the client, without WebHooks, in order to receive response, right?

Then the workflow will be the following:

  1. Player 1 taps End Turn button. The Cloud Script method is called and player's moves are passed there as parameters.

  2. The move results are handled in Cloud Scripts, on backend. The game state is updated in UserReadonlyData or SharedGroupData on server side. The move results, or game state changes are returned to Player 1 as Cloud Script call response then.

  3. Once Player 1 handles callback he sets a property in Photon Room Properties to indicate that it's the other player's turn.

  4. Player 2 handles the change of Photon Room Properties and knows that it's his turn now. He makes request to PlayFab to get current game state.

  5. After Player 2 receives current game state the Player 2 turn starts.

Is this workflow fine? Or is there a better way?
Any best practices on how to implement anti-cheating solution using Photon Turnbased + PlayFab?

Thanks.


johntube said on Mon, 21 September 2015 at 5:07 AM

Hi alandyshev,

I wouldn't say Photon webhooks are unreliable. If the webhook fails: request timeout or returns response with a HTTP "error code" or with "ResultCode != 0" then operation that triggered the webhook should fail. Best thing is to try it yourself to make sure.

Hamza


Brendan Vanous said on Mon, 21 September 2015 at 8:48 AM

Correct - as Hamza says, Photon and the webhooks aren't unreliable, it's just that you should always plan for the failure case, even if the chance of it is small. Your flow for gameplay looks good - for the cheat protection aspect, it's going to be down to the specifics of your game's design. What are the things a player can affect, and what are the valid ranges for those things? Are there items the players have in inventory they can use (so you'd want to check that they have the thing they say they're using)? Is it card-based, with a pre-created deck that you can check, to make sure the player actually has the cards he's using in his current deck (and hasn't already used them)?

Brendan


alandyshev said on Mon, 21 September 2015 at 8:58 AM

Thanks.
One more question I have, maybe unrelated to the topic is how to debug Cloud Scripts?
I've seen log.debug and log.error methods in examples. But I haven't found where I can look for the logs.


alandyshev said on Mon, 21 September 2015 at 9:01 AM

I've read that there should be Logs tab under Servers section in Game Manager. However I have no Logs tab for my account.


Brendan Vanous said on Mon, 21 September 2015 at 11:49 AM

Right now, Cloud Script debugging is done via the log call - the information you put in them is all returned from the calls themselves, so that you can debug directly in the client. We are working to add better debugging options, and we'll be making sure to message that broadly when it's ready.

The statement in the in-line docs about the logs being available in the logs tab was in error (specifically, it was us getting ahead of ourselves). We do plan to offer that later, but it's not the case at the moment. I've updated the script in GitHub so that any new titles will have the correct documentation - apologies for the confusion.

Brendan


alandyshev said on Mon, 21 September 2015 at 12:39 PM

I suppose that works for PlayFab Cloud Script handlers that are called from client. But what about Photon WebHooks handlers? I tried to put logs to RoomCreated handler and I don't see them in Photon Log that I receive in OnOperationResponse.


Brendan Vanous said on Tue, 22 September 2015 at 11:08 PM

Correct, and we'll be improving the debugging options for Cloud Script as soon as we can. Right now, I would have to recommend either running the Cloud Scripts as client-triggered actions, so that the returned log data is sent back to you directly, or writing your error messages to Title Data, so that you can easily review it in the Game Manager.

Brendan

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.