Search Unity

How to return errors to players trying to connect?

Discussion in 'Multiplayer' started by FStar, Nov 30, 2015.

  1. FStar

    FStar

    Joined:
    Sep 11, 2015
    Posts:
    50
    Hi,

    I'm currently trying to use the HL API. Is there some good way of telling the client that he's not allowed to log in because he doesn't have an account? I check account info against a database in the background.

    I use:

    Code (csharp):
    1. public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader extraMessageReader)
    The account info is sent in the extra message. But OnServerAddPlayer can not return any result in case of bad account info or some other reason. Should I send another message back to the client telling what is the problem or what is the best way to handle this?

    I guess it could be done something like:

    Client:

    ClientScene.AddPlayer(manager.client.connection, 0, new ConnectMessage() { --- accountInfo stuff --- });

    Display "Connecting... " message and wait for acknowledge call from the server.

    Server:

    Check account info, add player if ok and make an acknowledge call to the client.
    If something goes wrong, send error code in acknowledge call.

    Client:
    Recieves acknowlege call or times out. Display error or "successful connect" message.


    BUT, is there some built in less cumbersome way?
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  3. FStar

    FStar

    Joined:
    Sep 11, 2015
    Posts:
    50
    Yes I think that was what I said :). I was wondering if there was some more direct approach to return a value or error code that was built into the framework.

    But I guess my described way would be correct then.

    Thanks for the answer.