Search Unity

Maintaining a session on a server

Discussion in 'Multiplayer' started by IroncladEarl, May 18, 2017.

  1. IroncladEarl

    IroncladEarl

    Joined:
    Jul 3, 2013
    Posts:
    87
    Good day everyone!

    I have quite a bit of experience with unity but I'm struggling a little bit regarding the networking/server side. So I apologize if this seems like a noob question.

    How would I maintain a session using PHP on the server side? If I understand correctly, when working in a web browser, the session is saved in the browser. But how would a session be saved when using Unity?

    To give some context: I am trying to create a multiplayer game. Unity will handle the "dumb" stuff for the game (animation, rendering grids, etc) and I want the handle the logic, database and authentication checks using PHP. Please correct me if this is the wrong approach.

    Thank you in advance. I look forward to your advice.
     
  2. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    If i understand your question correctly:
    On authentification, you should give them a token valid for x time. Then for every db call etc make them send the key. There is alot more to it that you need to research but roughly like that.

    If i've missunderstood then please elaborate on what you mean with session and what exactly you need to do.


    Edit: I think I see what you are trying to do. If you are running the full server on PHP and web requests. If it's a game where you send regular updates about movement etc (Usually refered to as Realtime) then don't do this. HTTP is text based and not designed for this really.

    But if it's a game such as Alphapet where every user sends a few messages a day this can work. You probably have to give every "room" some key. Then for every player have a list of the rooms they are in. Then when they send a message they supply the key or some secret key that links their account to that room.

    Atleast that's a starting point.
     
    Last edited: May 18, 2017
    IroncladEarl likes this.
  3. IroncladEarl

    IroncladEarl

    Joined:
    Jul 3, 2013
    Posts:
    87
    Thanks for the quick reply!

    I'm actually trying to create a grid-based click to move game. A player might have a certain amount of movement points and I want the server to check if the player does have enough before they can move. It needs to be persistent.

    So if I understand you correctly, there would be no "session" created per say. Just a hashed key that is stored in the database, while the player is logged in? If that's the case, would I have to create a cron job to see if the player hasn't queried after a certain amount of time and then nullify the session key?
     
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Ouch. Beyond my knowledge i'm afriad. I do Networking (realtime) and thats about it. I was just putting my idea out.

    But assosiated with your player data. I would have a list of rooms he is in or something like that.
    Then he sends "move to grid x on room/session y". You make sure he is logged in, check if he belongs to that session, verify his move, apply it!.

    As for auth, I don't know or dare to get into how to properly do it.