How to check if a user is online?

Options
Pikker
edited October 2012 in Photon Server
Currently i have my own server logic(standalone and authoritative) and i have all of the functionality i need for logging in and out etc except for one issue, i cannot identify who is sending requests and who has disconnected using the standard OnDisconnect function and the standard OnOperationRequest function. Does anyone know how i could integrate a user account system into these 2 functions?

I can add users to a list or dictionary when they connect but cant remove them when they disconnect as the only variables used in the OnDisconnect function are the reason code and the reason detail.

Comments

  • Sergiy
    Options
    PeerBase class has 'Connected' property. As for dictionary, you can use PeerBase's 'ConnectionID' property as key to identify any particular peer
  • Tobias
    Options
    The peer that's passed into those methods is identifying the client. You will need to store the associated account with that and then you can also track users who disconnect.
  • the Method Signature only takes in operationrequest and sendparameters. When a connection is made it uses an irpcprotocol and iphotonpeer to register the connection but i do not see anything that takes in a peerbase type. How do i access that information?
  • Philip
    Options
    Add a method your clients call right after they connect to set a userid.

    You could have a look at how Loadbalancing does it, check the code in the MasterClientPeer:

    [code2=csharp]public class MasterClientPeer : PeerBase, ILobbyPeer
    {
    ...
    public string UserId { get; set; }

    private OperationResponse HandleAuthenticate(OperationRequest operationRequest)
    {
    OperationResponse response;

    var request = new AuthenticateRequest(this.Protocol, operationRequest);
    if (!OperationHelper.ValidateOperation(request, log, out response))
    {
    return response;
    }

    this.UserId = request.UserId;

    // publish operation response
    var responseObject = new AuthenticateResponse { QueuePosition = 0 };
    return new OperationResponse(operationRequest.OperationCode, responseObject);
    }[/code2]

    Once the peer.UserId is set you can use it in OnDisconnect().

    You could of course get OnDisconnects where it is not set - but that means
    either your client is bogus not calling Authenticate. (you can enforce
    that not allowing your clients to do anything before they set the UserId).

    Or the client disconnected before making the authenticate call - a case that always can happen.