IEnumerator SetHostInfoRoutine(String servername, Boolean dedicated, Bolt.IProtocolToken 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; // check for null token and create one var token = protocolToken as PhotonHostInfoToken; if (token == null) { token = new PhotonHostInfoToken(); } if (token.CustomRoomProperties == null) { token.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable(); } token.CustomRoomProperties ["UdpSessionId"] = Guid.NewGuid().ToString(); if (_config.UsePunchThrough) { token.CustomRoomProperties ["SocketPeerId"] = BoltNetwork.UdpSocket.SocketPeerId.ToString(); } // _lbClient.OpCreateRoom(servername, new RoomOptions() { CustomRoomProperties = token.CustomRoomProperties, CustomRoomPropertiesForLobby = new string[] { "UdpSessionId", "SocketPeerId" }, MaxPlayers = (byte)maxPlayers, }, null); }
IEnumerator SetHostInfoRoutine(System.Object protocolToken, String servername = null, Boolean dedicated = false, bool create = true) { var t = new Timer(ROOM_CREATE_TIMEOUT); while (_lbClient == null || _lbClient.State != ClientState.JoinedLobby && t.Waiting) { yield return(null); } if (create) { if (_lbClient == null || _lbClient.State != ClientState.JoinedLobby) { BoltLog.Error("Can't call BoltNetwork.SetHostInfo when not in lobby"); yield break; } } else { if (_lbClient == null || _lbClient.State != ClientState.Joined) { BoltLog.Error("Can't call BoltNetwork.SetHostInfo while not in a room"); yield break; } } var maxPlayers = dedicated ? BoltNetwork.maxConnections : BoltNetwork.maxConnections + 1; var customRoomProperties = default(ExitGames.Client.Photon.Hashtable); RoomOptions roomOptions = new RoomOptions(); // properties for lobby List <string> publicPropertyListName = new List <string>(new string[] { "UdpSessionId", "UserToken" }); // check for new interface based version var boltPhotonCloudRoomProperties = protocolToken as PhotonCloudRoomProperties; if (boltPhotonCloudRoomProperties != null) { customRoomProperties = boltPhotonCloudRoomProperties.CustomRoomProperties; publicPropertyListName.AddRange(boltPhotonCloudRoomProperties.CustomRoomPropertiesInLobby); roomOptions.IsOpen = boltPhotonCloudRoomProperties.IsOpen; roomOptions.IsVisible = boltPhotonCloudRoomProperties.IsVisible; } // last resort, create a new empty tble if (customRoomProperties == null) { customRoomProperties = new ExitGames.Client.Photon.Hashtable(); } // if we have a protocol token, package it into the room properties as Byte[] if (protocolToken != null && protocolToken is IProtocolToken) { customRoomProperties["UserToken"] = ProtocolTokenUtils.ToByteArray((IProtocolToken)protocolToken); } // session id if (create) { customRoomProperties["UdpSessionId"] = Guid.NewGuid().ToString(); } // Setup Room Options roomOptions.CustomRoomProperties = customRoomProperties; roomOptions.CustomRoomPropertiesForLobby = publicPropertyListName.ToArray(); if (create) { roomOptions.MaxPlayers = (byte)maxPlayers; } if (create) { // create the room with all settings _lbClient.OpCreateRoom(servername, roomOptions, null); } else { // update the room with all settings _lbClient.OpSetCustomPropertiesOfRoom(customRoomProperties); BoltLog.Info("Updating room properties"); } }
IEnumerator SetHostInfoRoutine(String servername, Boolean dedicated, 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.OpCreateRoom(servername, new RoomOptions() { CustomRoomProperties = customRoomProperties, CustomRoomPropertiesForLobby = new string[] { "UdpSessionId", "SocketPeerId", "UserToken" }, MaxPlayers = (byte)maxPlayers, }, null); }