Change PhotonNetwork.AuthValues after connection.

Hi,

I'm trying to create a player session verification to avoid players can join the game with the same account from multiple instances/devices, and I'm trying to use Photon for this, I have my own authentication system, I just need to know when a player is online, I have figured out a way to do this using PhotonNetwork.FindFriends but I encounter the issue that the PhotonNetwork.AuthValues which is required to set the UserID, can only be sent before establishing connection with the Master Server.

So my question is if there's any way to change the AuthValues or UserID of the local player after connecting to the server?

Any help will be appreciated, thanks in advance.

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭

    Hi @BrinerLovo,

    Thank you for choosing Photon!

    You can't change UserId or AuthValues once connected: you need to disconnect, update those and connect again.

    Otherwise, to achieve what you want I would also approach it differently: make use of Webhooks' PathLeave to know when a player disconnects unexpectedly (see Type/Cause arg, this is from GameServer only so we need another way for MasterServer, continue reading to get this) and another heartbeat periodic HTTP requests (optionally use WebRPC) from client to your custom backend to tell that client is still connected...after a while, if no heartbeat request received, timeout and consider client disconnected. In your backend, each client can have a state per UserId: connected or not (you can also send deviceId, IP, etc. from client on auth + heartbeat). So on custom auth you can check if client is already connected or not. Also when explicitly disconnecting client can send a HTTP request to your backend to update status.