Trying to Create a Server Browser Using PhotonCloud

I implemented the code from the sample folder to create a server browser in my game but I have a few questions about how to add the features that I want.

1. How do I update the SethostInfo so that I could add a player count to the ArbitraryData?

2. I noticed that you cant make a session with the same host name, is there any way to do this? If not is there a way to check if a session is already running with the same name.

3. How do I remove a session from the list with out shutting down the server? Once a player connects to the server I want them to be in a type of lobby that the host can change settings in and wait for players before starting the game, when host starts the game I want to remove the session so that other players cant join a game in progress.

Comments

  • stanchionstanchion mod
    edited June 2
    1. Info here https://doc.photonengine.com/en-us/bolt/current/in-depth/photon-cloud

    Add this to PhotonPoller then you can just call

    PhotonPoller.UpdateHostInfo(new BoltPhotonInit.RoomProtocolToken { ArbitraryData ="new data"});

    static public void UpdateHostInfo(System.Object protocolToken) {
            Instance.StartCoroutine(Instance.UpdateHostInfoRoutine(protocolToken));
        }
        IEnumerator UpdateHostInfoRoutine(System.Object protocolToken) {
            var t = new Timer(ROOM_CREATE_TIMEOUT);
            while(_lbClient.State != ClientState.JoinedLobby && t.Waiting) {
                yield return null;
            }
            //if(_lbClient.State != ClientState.JoinedLobby) {
            //    BoltLog.Error("Can't call BoltNetwork.SetHostInfo when not in lobby");
            //    //yield break;
            //}
            // 
            //var maxPlayers = dedicated ? BoltNetwork.maxConnections : BoltNetwork.maxConnections + 1;
            var customRoomProperties = default(ExitGames.Client.Photon.Hashtable);
            // check for old host info token
            var hostInfoToken = protocolToken as PhotonHostInfoToken;
            if(hostInfoToken != null) {
                customRoomProperties = hostInfoToken.CustomRoomProperties;
            }
            // check for new interface based version
            var boltPhotonCloudRoomProperties = protocolToken as IBoltPhotonCloudRoomProperties;
            if(boltPhotonCloudRoomProperties != null) {
                customRoomProperties = boltPhotonCloudRoomProperties.CustomRoomProperties;
            }
            // last resort, create a new empty tble
            if(customRoomProperties == null) {
                customRoomProperties = new ExitGames.Client.Photon.Hashtable();
            }
            // if we have a protocol token, and it's not PhotonHostInfoToken package it into the room properties as Byte[]
            if(protocolToken  != null && !(protocolToken is PhotonHostInfoToken)) {
                customRoomProperties["UserToken"] = ProtocolTokenUtils.ToByteArray((IProtocolToken)protocolToken);
            }
            // session id
            //customRoomProperties["UdpSessionId"] = Guid.NewGuid().ToString();
            // if we allow punch
            //if(_config.UsePunchThrough) {
            //    customRoomProperties["SocketPeerId"] = BoltNetwork.UdpSocket.SocketPeerId.ToString();
            //}
            // 
            _lbClient.OpSetCustomPropertiesOfRoom(customRoomProperties);
            BoltConsole.Write("Updating room properties");
        }


    2. You can use a GUID or something instead so you do not get duplicate names, then put the name and other data in the token

    3. This will be added to our examples
  • stanchion said:

    1. Info here https://doc.photonengine.com/en-us/bolt/current/in-depth/photon-cloud

    Add this to PhotonPoller then you can just call PhotonPoller.UpdateHostInfo(new BoltPhotonInit.RoomProtocolToken { ArbitraryData ="new data"});




    static public void UpdateHostInfo(System.Object protocolToken) {
    Instance.StartCoroutine(Instance.UpdateHostInfoRoutine(protocolToken));
    }
    IEnumerator UpdateHostInfoRoutine(System.Object protocolToken) {
    var t = new Timer(ROOM_CREATE_TIMEOUT);
    while(_lbClient.State != ClientState.JoinedLobby && t.Waiting) {
    yield return null;
    }
    //if(_lbClient.State != ClientState.JoinedLobby) {
    // BoltLog.Error("Can't call BoltNetwork.SetHostInfo when not in lobby");
    // //yield break;
    //}
    //
    //var maxPlayers = dedicated ? BoltNetwork.maxConnections : BoltNetwork.maxConnections + 1;
    var customRoomProperties = default(ExitGames.Client.Photon.Hashtable);
    // check for old host info token
    var hostInfoToken = protocolToken as PhotonHostInfoToken;
    if(hostInfoToken != null) {
    customRoomProperties = hostInfoToken.CustomRoomProperties;
    }
    // check for new interface based version
    var boltPhotonCloudRoomProperties = protocolToken as IBoltPhotonCloudRoomProperties;
    if(boltPhotonCloudRoomProperties != null) {
    customRoomProperties = boltPhotonCloudRoomProperties.CustomRoomProperties;
    }
    // last resort, create a new empty tble
    if(customRoomProperties == null) {
    customRoomProperties = new ExitGames.Client.Photon.Hashtable();
    }
    // if we have a protocol token, and it's not PhotonHostInfoToken package it into the room properties as Byte[]
    if(protocolToken != null && !(protocolToken is PhotonHostInfoToken)) {
    customRoomProperties["UserToken"] = ProtocolTokenUtils.ToByteArray((IProtocolToken)protocolToken);
    }
    // session id
    //customRoomProperties["UdpSessionId"] = Guid.NewGuid().ToString();
    // if we allow punch
    //if(_config.UsePunchThrough) {
    // customRoomProperties["SocketPeerId"] = BoltNetwork.UdpSocket.SocketPeerId.ToString();
    //}
    //
    _lbClient.OpSetCustomPropertiesOfRoom(customRoomProperties);
    BoltConsole.Write("Updating room properties");
    }

    2. You can use a GUID or something instead so you do not get duplicate names, then put the name and other data in the token

    3. This will be added to our examples

    "3. This will be added to our examples"

    Any ETA on this?
Sign In or Register to comment.