Sign In Register

How can we help you today?

Start a new topic
Answered

Preventing concurrent login II

I understand there are other forum entries handling the same topic, but they are all marked as answered without giving me a satisfying way on how to actually achieve this. 


Like multiple users stated here, it is necessary for many other people as well to prevent users from logging in with the same account (on same or different device) at the same time. Sure, we could adept our backend code to sync all connected devices, but for us that just means allot of more work, trouble, risk and time without having a real benefit for our game vision. 


Like other users stated, it would be best for us as well to just set a flag somewhere in the backend and - bang - multiple loggins are just forbidden globally.


Or can you please give us an idea on how to handle it on our own: In the AuthenticationRequest cloud code script, how can I load a player by name and password to check if he is already online to let the request fail?


Best Answer

Hi Fiete,


Apologies that no one has got back to you sooner about this. Spark.getPlayer().disconnect(true) in the AuthenticationResponse would be the correct way to handle this. As Roman mentions above, this will log the player out on all of the other devices and the latest one will be able to Authenticate and continue on in the game. You can't avoid having both instances of the players logged in at some stage, it has to happen if you want to disconnect the older sessions.


Roman if you don't want the latest player to authenticate you could place a check in scriptData if Spark.getPlayer().getScriptData(userLoggedIn) is 'true', you could set this in a successful AuthenticationResponse then check it each time after. If userLoggedIn = true you could throw an error to prevent authentication from continuing or prompt the user to disconnect all of the other instances of that player with Spark.getPlayer().disconnect(true). Hope this helps.


Thanks,

Liam


4 people have this question

Thanks both for advice :)

Well, what I am currently doing when there is a concurrent login, is to call disconnect() in cloud every time player authenticates. This sends SessionTerminatedMessage to the currently logged in player, and new one is authenticated. The old player's code handles the message and notifies player about concurrent login and "logs him out". Problem with this is now I have to go through all the possible game states and try to handle that message gracefully.

Ideally, when authenticating, I would like SPARKS to check if there this account is logged in already and send message back that login is currently not allowed.

Hamlet Archer, have you solved this issue?


It's because GameSparks use authTokens to authenticate. It is possible to force other (offline) clients to re-login using this Spark.getPlayer().resetAuthTokens() . So,

         Spark.getPlayer().disconnect(true) - to disconnect connected clients

         Spark.getPlayer().resetAuthTokens() - remove all tokens, therefor when client A return to the App he will be forced to re-login.

But same will happen to client B because his authToken will be removed too.


Would be good to add feature to remove auth tokens with boolean value excludeCurrent (same as Spark.getPlayer().disconnect(true)).



Hi Fiete,


Have you considered the SessesionTerminatedMessage suggested by Sean in that linked thread?

Might be the best way to go about it currently.


Oisin

Hi guys, I have another question(or 2) to this thread:
-is it possible to terminate current device? I mean Spark.getPlayer().disconnect(true) terminate other devices with same login, Spark.getPlayer().disconnect(false) terminates all devices(including current). But how terminate only this single one?
 

 

Oisin, the rest of the customer service!

Why don't you answer? I see other post getting a response, what is going on here? Do we have to collect signatures? Bribes..?

At least tell us you don't know or you gonna ask somebody, but letting us wait like this, in my opinion, is quite rude and unprofessional.

I am sorry, but until now I actually had a very good experience with the GameSparks' customer service, please don't make me change my good impression.

Thanks, Fiete

 

@Customer Support,
Any update?
We just want it works just as Clash Royale, which uses approach 1 - logout previous device.
In previous device, even the app is at background, the logout message still pops up after going back to game.

 

Answer

Hi Fiete,


Apologies that no one has got back to you sooner about this. Spark.getPlayer().disconnect(true) in the AuthenticationResponse would be the correct way to handle this. As Roman mentions above, this will log the player out on all of the other devices and the latest one will be able to Authenticate and continue on in the game. You can't avoid having both instances of the players logged in at some stage, it has to happen if you want to disconnect the older sessions.


Roman if you don't want the latest player to authenticate you could place a check in scriptData if Spark.getPlayer().getScriptData(userLoggedIn) is 'true', you could set this in a successful AuthenticationResponse then check it each time after. If userLoggedIn = true you could throw an error to prevent authentication from continuing or prompt the user to disconnect all of the other instances of that player with Spark.getPlayer().disconnect(true). Hope this helps.


Thanks,

Liam

Bump..


Customer support, please react!


As you can see here this is a big problem for many gamesparks users!


Login to post a comment