Make uLink_OnPlayerApproval() approving automatically optional
  • Vote Up0Vote Down lazalonglazalong
    Member
    335 Points
    Hi all,

    The uLink documentation says "If you don't implement the uLink.Network.uLink_OnPlayerApproval() callback, or if you implement it but don't call either Approve() or Deny(), the client is automatically approved.".

    Because of this I don't see how I can use this callback to send an asynchronous request from a game Server to the Lobby - sitting in another server - to verify if the player is correctly authenticated. In my code extract below, the approval will be send automatically at the end of the uLink_OnPlayerApproval callback. With this code, the player is approved twice with the correct SessionID and with an incorrect SessionID the player is automatically approved even if my coroutine tries afterwards to deny him!

    The workaround I have is to approve the connection and if the authentication fails to disconnect the player. But as you can imagine this isn't very good.

    I would have imagined that if we implement uLink_OnPlayerApproval then we take the responsibility to Approve/Deny - or at least it should be Deny by default!

    Any better way?

    Thanks

    void uLink_OnPlayerApproval(uLink.NetworkPlayerApproval approval)
    {
    if (approval.loginData == null)
    {
    approval.Deny();
    return;
    }

    StartCoroutine(OnPlayerApprovalCoroutine(approval));
    } < ---------- approved automatically!!!!

    private IEnumerator OnPlayerConnectedCoroutine(uLink.NetworkPlayerApproval approval)
    {
    string sessionID = "";
    string username = "";

    if (approval.loginData.TryRead(out sessionID)
    && approval.loginData.TryRead(out username))
    {
    // Ask lobby if account with name taken from approval is logged in
    var getSessionInfo = _sessionManager.GetSessionInfo(sessionID, username);
    yield return getSessionInfo.WaitUntilDone();

    bool sessionIDMatch = getSessionInfo.DoesSessionIDsMatch();

    if (!sessionIDMatch)
    {
    Debug.LogWarning("SessionIDs missmatch for " + approval.ToString());
    approval.Deny();
    yield break;
    }

    approval.Approve(_levelName);
    }
    yield break;
    }


  • 2 Comments sorted by
  • Vote Up0Vote Down silentneedlesilentneedle
    Member
    795 Points
    Accepted Answer
    Use approval.Wait() before StartCoroutine(OnPlayerApprovalCoroutine(approval));
    Thanked by 1lazalong
  • Vote Up0Vote Down lazalonglazalong
    Member
    335 Points
    Thanks Silentneedle it works now perfectly.

    I should improve in reading api documentation.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tagged