question

brendan avatar image
brendan asked

Is it ok?

Hodispk
started a topic on Tue, 25 August 2015 at 7:23 AM

Hi there,
I'm already working on a multiplayer game with "Photon Unity Network" and my question is: is it ok to keep my existing code implementation for PUN and just use PlayFab database, currency and leaderbords on top of 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

20 Comments
Brendan Vanous said on Mon, 31 August 2015 at 11:39 PM

Yes, there should be no issues with using PUN and PlayFab together. If you do run into any issue, please be sure to post your questions to our forums, so that we can assist.

Brendan


Hodispk said on Wed, 02 September 2015 at 2:06 AM

I dont know if it's the right place to ask questions for ideas, should i post here or in unity forum?
Or somewhere where the feedback is more quicker(i mean less than 7 days...), can you point me to the right direction?(no offense, i know it's vacation time)

And my question right now is: how can i disconnect a player if i login with his username and password? I think to do it with PUN, but i accept any opinions, or PlayFab has a method or smthing like that?


Brendan Vanous said on Wed, 02 September 2015 at 7:00 PM

We're in the process of updating our support site, to ensure that we're notified of follow-up posts - believe me, no one is more frustrated than me when a question goes unanswered for a few days.

To answer your question, assuming you mean logging out, "disconnecting" a player is as simple as removing the session ticket from the local client. There's more info on this in this forum thread: https://support.playfab.com/discussions/topics/1000049893. Basically, as a web-based API, there is no active connection to the player, so "logout" doesn't really make sense conceptually. But removing the session ticket from the client effectively disconnects the client from the session.

Brendan


Hodispk said on Thu, 03 September 2015 at 1:11 AM

I don't realy get the point between the session ticket and my connection to PUN, or in anyway to prevent the user to log in from multiple devices.

Sorry for bothering you.


Brendan Vanous said on Thu, 03 September 2015 at 1:17 AM

PUN and the session ticket aren't related. The session ticket can be used for authentication with the Photon Cloud.

And nothing about the session ticket or PUN is designed to prevent login from multiple devices. In point of fact, the PlayFab service is designed to allow that scenario, since there are titles we support which require simultaneous sign-in from multiple devices (for "companion" application experiences).

Brendan


Hodispk said on Fri, 04 September 2015 at 3:40 AM

Hi again, @tobiass from photon came with an idea.
Is it any method that i could "ping" PlayFab(every 5-10 sec), with my existing session ticket to check if is still alive, and when i try to log-in from another device to compare those 2 session tickets and if they doesn't match to d/c from Photon.


Brendan Vanous said on Fri, 04 September 2015 at 5:42 PM

The question is, why would you need to? Any call to PlayFab made after expiration will return the "expired" error message. Having a common handler for responses will provide with a simple way to reliably know when the ticket has expired, so that you can ask for a new one.

Could you elaborate on the second half of your question though? If you are saving the Session Ticket in the Photon Cloud Room (or elsewhere) for comparison, what happens if the player loses connection, or just turns off his current device, and then signs in from another device to continue his game?

Brendan


Hodispk said on Sat, 05 September 2015 at 3:49 AM

I thinked to save the session id locally and check every 10 sec if changed, if changed that means someone logged in from another place so i can d/c the existing session from photon. If the player lose connection he receive a d/c from photon too, if he close the device, before closing he receive a d/c from photon.

You said about the hanlder, you're right, when its "expired" i want to d/c the user from photon, can you provide me the api for that method? or i didnt understand it right.

Thank you


Brendan Vanous said on Sat, 05 September 2015 at 11:11 AM

I see - so your intent is to use this as a mechanism to end the current session if the player signs in from another device? If so, every 10 seconds is probably overkill. Services like PSN and Xbox Live have a "heartbeat" rate of once every 20 seconds, so that would likely be sufficient.

For info on the Photon Cloud API calls, I'd recommend working with the team at Exit Games. The short answer is that there is an API (disconnect) which shuts down the client's connection to the server. But again, I would recommend working with their team to ensure you're following their best practices.

Brendan


Hodispk said on Sat, 05 September 2015 at 11:16 AM

I know how to d/c the player, what i dont know is how i can keep trackin the session ticket. When i log in with playfab i receive one, how can i check if that is expired or not? Thx


Brendan Vanous said on Sat, 05 September 2015 at 11:24 AM

Could you describe more fully the reason you're attempting to determine if the ticket has expired? As I said, any call to PlayFab made after the ticket has expired will receive an error message telling you it has expired. You should always be handling any errors returned, and for an expiration error, you would either sign the user back in using existing credentials, or prompt the user to sign in. So the specific answer to your question is, make any call to the PlayFab service - the service will respond with an expired error if the ticket is no longer valid.

Brendan


Hodispk said on Sat, 05 September 2015 at 11:32 AM

You answered perfectly for what i expected, thank you Brendan, I didnt know that playfab respond me with that error, i thought i can always check my session ticket, like a request but just for the session ticket. But if you say that if the session ticket is changed, and the expired session ticket client can't make calls, its ok, i could put my d/c method in playfab's error callback. I will try it tomorrow. Thanks Brendan


Hodispk said on Sun, 06 September 2015 at 1:25 AM

Ok so I tried like this:

void Pulse()
    {
        GetUserCombinedInfoRequest gucir = new GetUserCombinedInfoRequest();
                name = gucir.Username;
        PlayFabClientAPI.GetUserCombinedInfo(gucir, onGetUserCombinedInfoSucces, onGetUserCombinedInfoFail);
    }

    void onGetUserCombinedInfoSucces(GetUserCombinedInfoResult result)
    {
        Debug.Log("Succes");
    }

    void onGetUserCombinedInfoFail(PlayFabError error)
    {
        Debug.Log(error.ErrorMessage.ToString());
        DC ();//d/c with photon
    }

I have that code in my script, so I login on Device1, waited a bit then logged on Device2 (with the same username/password, so i'm connected to both), i expect from Device1 after i login on Device2 to execute "onGetUserCombinedInfoFail" because Device1's session ticket expired. Or not?


Brendan Vanous said on Sun, 06 September 2015 at 2:53 PM

No, it wouldn't. Session Tickets are valid for 24 hours. They are not automatically expired when the user signs into another device. Our system was designed to allow for multiple sign-ins, since quite a few games require that capability these days (companion apps, etc.). There's an existing thread discussing this here: https://community.playfab.com/hc/communities/public/questions/206721757-How-to-prevent-duplicate-login-.

Brendan


Hodispk said on Sun, 06 September 2015 at 11:08 PM

I'm sorry to hear that, so PlayFab is not what I need.
Maybe your future sdk's will include that, till then, thank you for your patience Brendan.

Keep up the good work :).


Brendan Vanous said on Mon, 07 September 2015 at 1:19 AM

So to be clear, the one feature you feel is most critical to your title is making sure the user cannot sign in simultaneously from multiple devices?

Brendan


Hodispk said on Mon, 07 September 2015 at 1:45 AM

Not critical but could be an option, mmo's will need that for sure, in my opinion, but if want only to monitor the player it's ok like this how its now.
I think how PlayFab will grow with Photon(and non-photon) it would be nice to have a sign-in system (one that accepts multiple devices and one which dont), since Photon doesn't have a logged in players tracker. (i don't think they will implement one)

Something like that, maybe if you already have the server response to "expired session", maybe somehow to modify the session expire time.

Btw i managed somehow to have a virtual curency "LS" "Login System" that have initial value of 0.
When the player is logged in modifies the value with "AddUserVirtualCurrencyRequest", stores it in a local variable.
I set a method "Pulse" to check every "x"seconds if "LS" changed, i make it with "GetUserCombinedInfoRequest".
If "LS" changed(so the player logged in from other device), when "Pulse" its executed it will d/c the player from photon, kicking back to login screen.

What's your opinion about this?
What's the good "x" value?


Brendan Vanous said on Mon, 07 September 2015 at 11:27 AM

It sounds like there may be some confusion, so to be clear: PlayFab does have an authentication system which allows for sign from any device that can make a web call. It's integrated with a range of device-specific and service-specific authentication systems, to allow for the most flexibility. It does not block people from signing in on more than one device simultaneously, partly because some titles specifically require that functionality. We have a backlog item to add this as an option later, but we do prioritize based in part on the community's overall needs, and very few people have asked for this to date.

And yes, what I was going to suggest was that you use a "heartbeat" mechanic to do what you need, except virtual currencies aren't needed. The way I would recommend doing this is:

  • When you sign in, record the login time on the local client

  • Call GetAccountInfo, and store the LastLogin from TitleInfo locally

  • Periodically (every 20 seconds or so) call GetAccountInfo (https://api.playfab.com/Documentation/Client/method/GetAccountInfo) and check that LastLogin matches

  • If it doesn't, delete the local Session Ticket and leave the Room in Photon

Brendan


Hodispk said on Tue, 08 September 2015 at 2:22 AM

Ok, thank's, i will do it with last login time.
Every 20 sec it's ok? For an android device.


Brendan Vanous said on Tue, 08 September 2015 at 12:17 PM

A poll rate of 20 seconds should be fine. The idea is that on average over the course of a player session, you should only be making a call every 2-3 seconds, at most. Bursts of calls (such as when a level is finished, and you need to do a few things) are fine - it's just that the average should be reasonable. So regardless of whatever else you're doing in your game, I can't see one extra call every 20 seconds being burdensome. :)

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.