Search Unity

How do I get information from the server before the client connects?

Discussion in 'Multiplayer' started by Zefalcon, Jan 4, 2018.

  1. Zefalcon

    Zefalcon

    Joined:
    Jun 17, 2016
    Posts:
    7
    Hello. I've been working on improvements to the piece of software I've been working on for a while and was trying to figure out a way to prevent players from signing into the same "seats" (the program is being used in a classroom setting, so table and seat numbers are used for a lot of the internal connections and for saving). If possible, I would like to stop a player from connecting to the server at all if they've chosen a seat that is already occupied.

    I tried doing this by making simple edits to the NetworkManager and NetworkManagerHUD scripts that checks the list of seats that have already been signed into and skips running StartClient() if the seat is occupied, but since NetworkManager itself doesn't synchronize its variables across the network (at least as far as I can tell), I don't have a good way of seeing who has signed in already. Is there some way to access a script on the server before the client has actually signed in so that I can check whether the seat chosen is occupied or not? I can post bits of code if that would help, but the pieces I've written are fairly basic thus far.
     
  2. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    Just off the top of my head, you could have a connection that is pre-signin. From that spot, all they can see are "seats (occupied or free)". That could be updated with their connection (the not signed in one). Then, they can make their choice, and for good measure you do 1 last check to make sure someone didn't get there before it was updated (network latency..) and then if it's free, let them sign in?

    I have no idea about your code, so this is just an intellectual thought on the topic :)
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    This way would probably work. You could have the server run an additional NetworkServerSimple server, connect the client to it and have the client use UNET Messages to talk to the server, sign in, and reserve their seat. Once the seat is reserved successfully, you disconnect the client from the NetworkServerSimple server and load the client into the main classroom scene, which connects with NetworkManager as normal, and the client is assigned the seat they have previously reserved.