Handling logins and disconnects

Options
eyewitness4560
edited August 2013 in Photon Server
Hi (again)!
We'd like some of your insight regarding user login and verification.
Currently in our demo verification works like this: you connect to the lobby where you get a username and password field. Click the enter button, the fields get sent to the Master Server, wich verifies it. If the credentitals are valid, it tells the client everythings OK, you can connect to the game, if they're not, we simply say unsuccessful attempt, and ask for the credentials again.

After the client recieves the response of the verification, it relays a request to the server to connect to a room, with an ID key. When the GameServer gets the request (with the game client peer alredy reated), the server retrieves character data based on the given ID.

We would like to alter this code, because it is a bit too redundant. First off, we retrieve data for the verification on the MasterServer, and if is OK, then send a response to the client, telling it to connect to a room, where the GameServer retrieves the player data again. We're trying to combine this into a one step procedure, where the MasterServer upon verifying the data, automatically connects the client to a GameServer, and only relays the successful connection to the client.

Any idea on how to pull this off neatly?

Our second question is:
We only allow one login per user (for obvious reasons), and set a flag in the DB that prevents further logins until it's revoked when the user disconnects. It would be better if we could store the logged in users in a hash table on the MasterServer instead, rather than digging in the DB for the reccord. If the user's in the hash table then it's in one of the rooms. The problem here is that once the player disconnects, how will the MasterServer know that the peer of the user disconnected, and it needs removing from the hash table?
Any ideas?

Thanks in advance!

Andrew

Comments

  • Hi!

    I think both of your questions are related. You are using our Loadbalancing app as a starting point, right? First, I propose that you have a(nother) look at doc.exitgames.com/photon-server/LoadBalancing - especially the parts where the communication between Master & GS is described ("Master: Handling Game Server Peers" and "Game Server: Reporting Game States to the Master").

    Basically, you need to extend that code.

    You probably need:

    For #1:
    - a "UserAuthenticated" event, which contains all the player data. You can push that event from the Master to the correct GS whenever a user is authenticated & got a game ID (call SendEvent() on the correct incoming game server peer).

    For #2:
    - a "User / Game cache" on the Master server - where you store information about logged on clients (as you said)
    - a "UserStateChanged" operation on the Master server, that is called by the GS whenever a client connects or disconnects (call something like SendOperation((byte)MyOperationCodes.UserStateChanged), with username + state as parameters, on the OutgoingMasterServerPeer)

    You need the "connected" flag as well because you probably want to know if a client indeed connected or got "lost" during transition - in that case, you should schedule a check that removes all players from the hashtable if they did not connect to the GS in a certain time.

    Remember that you also need to synchronize the data between Master & GS when the connection between Master & GS is interrupted, or one of the servers restarted. There are examples for that in our loadbalancing code as well.

    Sorry that my answer is quite high-level, but I think you get the idea - and it sounds like you are already on a good way. Let me know if you need more precise help on anything and we can discuss things in more detail then.
  • We'll try it like you said, when we're done with fiddling around in the demo, and start the actual development on the finished product. (but there will be quite some fiddling beforehand, since we just switched databases from MySQL to DB4O :D )
    I'll check back if we hit a snag along the way.
    By the way, we'll have to make you an honorary member of the dev team if you keep helping us this much :D
    Thanks again :)
  • Hehe. Thanks for the feedback & good luck with the DB migration.

    We wouldn't object if you mention Photon in your game's credits. :D
  • Well, we're still unsure if we want a splash screen while loading, or a credits page, but rest assured, you have realestate there... I believe in giving credit where credit is due, and we are building the entire game on your software :)

    EDIT:
    BTW, we finished modifying the login like you suggested, and as usual, it works like a charm. Thanks ;)