Restrict multi login

Options
atworld
atworld
edited October 2017 in Photon Server
Hi
I set a unique id with my custom login system for each player that wants to enter into my game and join to SqlLobby.but the player still could connect to my photon server in other devices by the same id.
Is there any way that to restrict joining to lobby by unique id?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2017
    Options
    Hi @atworld,

    Thank you for choosing Photon!

    We already restrict one actor per UserID inside rooms using RoomOptions.CheckUserOnJoin = true.
    To allow only one client per UserID on Master Server you need to:
    - use custom authentication and implement a session system on your web server (tricky for unexpected disconnects) or
    - modify LoadBalancing server code
  • chvetsov
    chvetsov mod
    edited October 2017
    Options
    Hi, @atworld

    UPDATE:
    our web hooks are limited. so you could not implement this using your own plugin. or WebRPC for instance together with WebHooks. WebHooks will mark player as online somewhere in your backend. and webrpc may as your backend and block player if it is already online

    but be very carryfull to not block just reconnecting players. you will need to use some kind of session id.



    best,
    ilya
  • SnowCat
    Options
    Hi @atworld,
    I have some modification to LoadBalancer to block more than 1 connect per user with CustomAuthentication.

    1. function DoCustomAuthenticationResult In the MasterClientPeer.cs

    case CustomAuthenticationResultCode.Ok:
    //apply user id from custom auth result
    if (!string.IsNullOrEmpty(customAuthResult.UserId))
    {
    // SnowCat check whether user is online. disconnect if it is.
    var app = (MasterApplication)ApplicationBase.Instance;

    if (app.DefaultApplication.PlayerOnlineCache != null && app.DefaultApplication.PlayerOnlineCache.IsPlayerCached(customAuthResult.UserId) )
    {
    operationResponse.ReturnCode = (short)Photon.Common.ErrorCode.CustomAuthenticationFailed;
    operationResponse.DebugMessage = "Player already online";
    this.SendOperationResponse(operationResponse, sendParameters);
    this.SetCurrentOperationHandler(OperationHandlerInitial.Instance);
    return;
    }
    // SnowCat Change End
    this.UserId = customAuthResult.UserId;
    }
    else if (!string.IsNullOrEmpty(authRequest.UserId))
    {
    this.UserId = authRequest.UserId;
    }
    else
    {
    this.UserId = Guid.NewGuid().ToString();
    }


    2. Add a funtion to class PlayerCache in PlayerCache.cs

    // SnowCat add some support to query player with id
    public bool IsPlayerCached(string playerId)
    {
    return this.playerDict.ContainsKey(playerId);
    }
    // SnowCat change end


    Those codes will block user with SAME UserID connect more than once.