The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Hw to check if user is connected from multiple devices?

avinash
2014-08-05 05:59:25

Hi,

I am developing a mobile game. I want to make sure that user can not connect from multiple devices using same user name. I am setting player name in Photon. Is there a way to check if this user is already connected from other device?

I am using PUN+. One option i can think of is whenever i connect to photon before setting my user name to PhotonNetwork.playerName. I can do a FindFriend() with my user name. If photon returns me offline then i'll set playerName otherwise i can assume that this user name is online from other device.

Is this the correct way to check this?

Comments

Tobias
2014-08-05 09:18:15

Preventing a user from logging in multiple times is currently not easy. We don't have sessions, so the server does not track if a user is staying online or not. Users might disconnect deliberately or get disconnected, time out and might want to re-connect. Maybe it's the same user but a re-connect is needed?

You could setup custom authentication and in your own auth service, you can possibly store some device ID per user and a timestamp. A user might login only from one device within 5 minutes or so.

See this page and related ones: http://doc.exitgames.com/en/pun/current ... entication

avinash
2014-08-06 10:18:42

Thanks Tobias for your quick reply.

There can be many scenarios for this. We were able to do it using our server. I will explain in case anyone else is looking for some solution for this.

We implemented session on our server which is a simple guid. When a device connects to our server it asks to create a session. Server creates a session and returns. Device uses this session ID with every server side request. If server detects that sent session ID doesn't match with current ID then it returns error code which indicates that session has been created from other device. It worked for our needs because every action in our game requires server communication.

Tobias
2014-08-08 15:55:59

Thanks for updating us. The solution seems to be solid and maybe it helps other to know this. Good luck with your game!

Pain
2017-03-31 08:46:23

@avinash wrote:

Thanks Tobias for your quick reply.



There can be many scenarios for this. We were able to do it using our server. I will explain in case anyone else is looking for some solution for this.



We implemented session on our server which is a simple guid. When a device connects to our server it asks to create a session. Server creates a session and returns. Device uses this session ID with every server side request. If server detects that sent session ID doesn't match with current ID then it returns error code which indicates that session has been created from other device. It worked for our needs because every action in our game requires server communication.

Thank you very much for your solution ! i'm looking for this, could you please give me a tutorial to implement this ?

avinash
2017-05-16 06:52:55

Hi Pain, Sorry for late reply. wasn't active on this forum from few months.

This is a standard session implementation technique. I will explain this in steps of how it works in our games.

  1. First Request from Client (Mobile game) to our server => API.Status()
    This tells whether our api is up and general health check of server.

  2. Second Request: API.GetSession(playerID)

Our Server maintains list of key value pair of session id and player id in cache. There can be only one session id for a player ID.

  1. With every request client sends this session id with player id to server. Server checks the cache if this session id and player id combination matches with one in cache. If it doesn't it means that same player has made a new session from other device or client. In this case server sends error code of session mismatch.

So in general a new client will always get a valid session which will invalidate all existing sessions. As soon as user connects from new device, all other active devices API calls will start failing with session mismatch error.

Hope this helps

Sarath
2022-07-13 18:42:45

Hello, can any one please help me in finding how to disconnect the existing user when he login from another device with the same credentials.

Tobias
2022-07-14 13:42:01

That would be a topic for authentication. You could create your own Custom Authentication, which disallows users to login within a certain time frame. You'd need some way to identify the device, though.

Back to top