public static void JoinRoom(this PhotonClient client, string RoomID) { EnterRoomParams parms = new EnterRoomParams() { RoomName = RoomID, CreateIfNotExists = true, }; RoomOptions options = new RoomOptions() { IsOpen = true, IsVisible = true, MaxPlayers = Convert.ToByte(GetCapacityOfWorld(RoomID) * 2) }; Hashtable table = new Hashtable() { ["name"] = "name" }; options.CustomRoomProperties = table; parms.RoomOptions = options; string[] customroompropertiesforlobby = new string[] { "name" }; options.CustomRoomPropertiesForLobby = customroompropertiesforlobby; options.EmptyRoomTtl = 0; options.DeleteNullProperties = true; options.PublishUserId = false; client.OpJoinRoom(parms); }
public virtual bool OpCreateRoom(EnterRoomParams opParams) { if (this.DebugOut >= 3) { base.get_Listener().DebugReturn(3, "OpCreateRoom()"); } Dictionary <byte, object> dictionary = new Dictionary <byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { dictionary.set_Item(255, opParams.RoomName); } if (opParams.Lobby != null && !string.IsNullOrEmpty(opParams.Lobby.Name)) { dictionary.set_Item(213, opParams.Lobby.Name); dictionary.set_Item(212, (byte)opParams.Lobby.Type); } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length > 0) { dictionary.set_Item(238, opParams.ExpectedUsers); } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && opParams.PlayerProperties.get_Count() > 0) { dictionary.set_Item(249, opParams.PlayerProperties); dictionary.set_Item(250, true); } this.RoomOptionsToOpParameters(dictionary, opParams.RoomOptions); } return(this.OpCustom(227, dictionary, true)); }
// Token: 0x06003BBA RID: 15290 RVA: 0x0012C6A0 File Offset: 0x0012AAA0 public virtual bool OpCreateRoom(EnterRoomParams opParams) { if (this.DebugOut >= DebugLevel.INFO) { base.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()"); } Dictionary <byte, object> dictionary = new Dictionary <byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { dictionary[byte.MaxValue] = opParams.RoomName; } if (opParams.Lobby != null && !string.IsNullOrEmpty(opParams.Lobby.Name)) { dictionary[213] = opParams.Lobby.Name; dictionary[212] = (byte)opParams.Lobby.Type; } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length > 0) { dictionary[238] = opParams.ExpectedUsers; } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && opParams.PlayerProperties.Count > 0) { dictionary[249] = opParams.PlayerProperties; dictionary[250] = true; } this.RoomOptionsToOpParameters(dictionary, opParams.RoomOptions); } return(this.OpCustom(227, dictionary, true)); }
public void OnConnectedToMaster() { Debug.Log("OnConnectedToMaster"); if (DataObj.isJoin) { EnterRoomParams roomParams = new EnterRoomParams(); roomParams.RoomName = DataObj.roomNameString; DataObj.lbc.LocalPlayer.NickName = ParseUser.CurrentUser["nickName"] as string; DataObj.lbc.OpJoinRoom(roomParams); } else { DataObj.lbc.LocalPlayer.NickName = ParseUser.CurrentUser["nickName"] as string; EnterRoomParams p = new EnterRoomParams(); p.RoomName = DataObj.roomNameString; ExitGames.Client.Photon.Hashtable t = new ExitGames.Client.Photon.Hashtable(); t.Add("m", DataObj.MapName); p.RoomOptions = new RoomOptions() { MaxPlayers = 5, CustomRoomProperties = t }; DataObj.lbc.OpCreateRoom(p); //DataObj.lbc.OpJoinRandomRoom(); // joins any open room (no filter) } }
public virtual bool OpCreateRoom(EnterRoomParams opParams) { if (this.DebugOut >= 3) { this.get_Listener().DebugReturn((DebugLevel)3, "OpCreateRoom()"); } Dictionary <byte, object> op = new Dictionary <byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { op[byte.MaxValue] = (object)opParams.RoomName; } if (opParams.Lobby != null && !string.IsNullOrEmpty(opParams.Lobby.Name)) { op[(byte)213] = (object)opParams.Lobby.Name; op[(byte)212] = (object)opParams.Lobby.Type; } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length > 0) { op[(byte)238] = (object)opParams.ExpectedUsers; } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && ((Dictionary <object, object>)opParams.PlayerProperties).Count > 0) { op[(byte)249] = (object)opParams.PlayerProperties; op[(byte)250] = (object)true; } this.RoomOptionsToOpParameters(op, opParams.RoomOptions); } return(this.OpCustom((byte)227, op, true)); }
public void FindPlayers() { if (!PhotonNetwork.IsConnected) { RoomManager.Instance.Connect(); return; } else if (!PhotonNetwork.InLobby) { RoomManager.Instance.JoinLobby(); return; } Player.NickName = Panel.Find <PanelStart>().txtNickname.text; //*** MULTIPLAYER CODE //STEP 1: Setup basic information about your player: PhotonNetwork.NickName = Player.NickName; PhotonNetwork.LocalPlayer.CustomProperties["SelectedCharacter"] = Player.SelectedCharacter; //STEP 2: Define the settings used when looking for a matching Room: OpJoinRandomRoomParams joinRoomParams = new OpJoinRandomRoomParams(); joinRoomParams.ExpectedMaxPlayers = RoomManager.MaxPlayers; //STEP 3: Define the settings used when creating a Room: EnterRoomParams createRoomParams = new EnterRoomParams(); createRoomParams.RoomOptions = new RoomOptions(); createRoomParams.RoomOptions.MaxPlayers = RoomManager.MaxPlayers; //STEP 4: Find players. Photon will automatically join or create a room as needed: PhotonNetwork.NetworkingClient.OpJoinRandomOrCreateRoom(joinRoomParams, createRoomParams); }
public void CreateRoom() { EnterRoomParams roomParams = new EnterRoomParams(); roomParams.RoomOptions = new RoomOptions { MaxPlayers = 6, CleanupCacheOnLeave = false }; PhotonNetwork.NetworkingClient.OpJoinRandomOrCreateRoom(null, roomParams); }
/// <summary> /// Joins or Creates a room with the given name /// </summary> /// <param name="roomName">The name of the room that will be joined or created</param> void MyCreateRoom(string roomName) { //Create or join the room EnterRoomParams enterRoomParams = new EnterRoomParams(); enterRoomParams.RoomName = roomName; enterRoomParams.RoomOptions = new RoomOptions(); enterRoomParams.RoomOptions.MaxPlayers = 10; this.loadBalancingClient.OpJoinOrCreateRoom(enterRoomParams); }
private void CreateRoom() { RoomOptions roomOptions = new RoomOptions(); roomOptions.MaxPlayers = 2; EnterRoomParams enterRoomParams = new EnterRoomParams(); enterRoomParams.RoomOptions = roomOptions; loadBalancingClient.OpCreateRoom(enterRoomParams); }
public override void OnJoinedLobby() { if (!PhotonNetwork.InRoom) { Debug.Log("Joined Lobby"); SetupMyPlayer(); var joinRoomParams = new OpJoinRandomRoomParams(); var createRoomParams = new EnterRoomParams(); PhotonNetwork.NetworkingClient.OpJoinRandomOrCreateRoom(joinRoomParams, createRoomParams); } }
private void CallJoinOrCreateRoom() { var roomParams = new EnterRoomParams { RoomName = "someRoom", RoomOptions = new RoomOptions() { MaxPlayers = 2 }, Lobby = TypedLobby.Default, CreateIfNotExists = true }; OpJoinOrCreateRoom(roomParams); }
bool CallCreateRoom(string roomName, byte maxPlayers) { Debug.Log(string.Format("creating room")); EnterRoomParams roomParams = new EnterRoomParams { RoomName = roomName, RoomOptions = new RoomOptions() { MaxPlayers = maxPlayers }, Lobby = TypedLobby.Default, CreateIfNotExists = true }; return(this.OpCreateRoom(roomParams)); }
private void CreateRankedRoom(byte maxPlayerCount, byte rank, bool isOpen, bool isVisible) { RoomOptions roomOptions = new RoomOptions(); roomOptions.IsOpen = isOpen; roomOptions.IsVisible = isVisible; roomOptions.MaxPlayers = maxPlayerCount; roomOptions.PublishUserId = true; roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable { { "Ranked", rank } }; EnterRoomParams enterRoomParams = new EnterRoomParams(); enterRoomParams.RoomName = "Ranked Room" + Random.Range(0, 10000); enterRoomParams.RoomOptions = roomOptions; loadBalancingClient.OpCreateRoom(enterRoomParams); }
// Token: 0x060002EA RID: 746 RVA: 0x00012C58 File Offset: 0x00010E58 public virtual bool OpJoinRoom(EnterRoomParams opParams) { if (this.DebugOut >= DebugLevel.INFO) { base.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRoom()"); } Dictionary <byte, object> dictionary = new Dictionary <byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { dictionary[byte.MaxValue] = opParams.RoomName; } if (opParams.CreateIfNotExists) { dictionary[215] = 1; if (opParams.Lobby != null && !opParams.Lobby.IsDefault) { dictionary[213] = opParams.Lobby.Name; dictionary[212] = (byte)opParams.Lobby.Type; } } if (opParams.RejoinOnly) { dictionary[215] = 3; } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length != 0) { dictionary[238] = opParams.ExpectedUsers; } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && opParams.PlayerProperties.Count > 0) { dictionary[249] = opParams.PlayerProperties; dictionary[250] = true; } if (opParams.CreateIfNotExists) { this.RoomOptionsToOpParameters(dictionary, opParams.RoomOptions); } } return(this.SendOperation(226, dictionary, SendOptions.SendReliable)); }
/// <summary> /// Tells the server to create a new room, randomly named but with some default settings (properties). /// </summary> /// <remarks> /// This method shows how to create a room without assigning a name. /// Unless you want to show a list of rooms, this is the best workflow for random matchmaking. /// Showing a list of rooms to make users pick one is not always much more than a random picking, also. /// /// Note the maxPlayers being 0. This means "any number of players". In your game, you would set some value > 0 here. /// </remarks> /// <seealso cref="https://doc.photonengine.com/en/realtime/current/reference/matchmaking-and-lobby"/> /// <param name="maptype">Any value of CustomConstants.MapType</param> /// <param name="gridSize"></param> public void CreateGameRoom() { Debug.Log("CreateRoom"); // custom room properties to use when this client creates a room. Note: Not all are listed in the lobby. Hashtable roomPropsForCreation = new Hashtable() { }; EnterRoomParams enterRoomParams = new EnterRoomParams { RoomName = "Custom room", RoomOptions = new RoomOptions { CustomRoomProperties = roomPropsForCreation, CustomRoomPropertiesForLobby = RoomPropsInLobby } }; this.OpJoinOrCreateRoom(enterRoomParams); }
public void OnConnectedToMaster() { // Once the client does connect to the master immediately redirect to its room. var enterRoomParams = new EnterRoomParams() { RoomName = m_RoomName, RoomOptions = new RoomOptions() { MaxPlayers = m_MaxPlayers, } }; var success = m_IsHostOrServer ? m_Client.OpCreateRoom(enterRoomParams) : m_Client.OpJoinRoom(enterRoomParams); if (!success) { Debug.LogWarning("Unable to create or join room."); InvokeTransportEvent(NetworkEvent.Disconnect); } }
/// <summary> /// Tells the server to create a new room, randomly named but with some defult settings (properties). /// </summary> /// <remarks> /// This method shows how to create a room without assigning a name. /// Unless you want to show a list of rooms, this is the best workflow for random matchmaking. /// Showing a list of rooms to make users pick one is not always much more than a random picking, also. /// /// Note the maxPlayers being 0. This means "any number of players". In your game, you would set some value > 0 here. /// </remarks> /// <seealso cref="https://doc.photonengine.com/en/realtime/current/reference/matchmaking-and-lobby"/> /// <param name="maptype">Any value of DemoConstants.MapType</param> /// <param name="gridSize"></param> public void CreateParticleDemoRoom(DemoConstants.MapType maptype, int gridSize) { // custom room properties to use when this client creates a room. Note: Not all are listed in the lobby. Hashtable roomPropsForCreation = new Hashtable() { { DemoConstants.MapProp, maptype.ToString() }, { DemoConstants.GridSizeProp, gridSize } }; EnterRoomParams enterRoomParams = new EnterRoomParams { RoomName = "Demo", RoomOptions = new RoomOptions { CustomRoomProperties = roomPropsForCreation, CustomRoomPropertiesForLobby = RoomPropsInLobby } }; this.OpJoinOrCreateRoom(enterRoomParams); }
public void OnConnectedToMaster() { // Once the client does connect to the master immediately redirect to its room. var enterRoomParams = new EnterRoomParams() { RoomName = m_RoomName, RoomOptions = new RoomOptions() { MaxPlayers = m_MaxPlayers, } }; var success = m_IsHostOrServer ? m_Client.OpCreateRoom(enterRoomParams) : m_Client.OpJoinRoom(enterRoomParams); if (!success) { m_ConnectTask.IsDone = true; m_ConnectTask.Success = false; m_ConnectTask.TransportException = new InvalidOperationException("Unable to create or join room."); } }
public void EnableVoice() { if (!enableVoice) { return; } voiceConnection.Client.NickName = PhotonNetwork.NickName; string room = PhotonNetwork.CurrentRoom.Name + "_voice"; var roomParams = new EnterRoomParams { RoomName = room }; if (PhotonNetwork.IsMasterClient) { voiceConnection.Client.OpCreateRoom(roomParams); } else { voiceConnection.Client.OpJoinRoom(roomParams); } }
/// <summary> /// Creates a room (on either Master or Game Server). /// The OperationResponse depends on the server the peer is connected to: /// Master will return a Game Server to connect to. /// Game Server will return the joined Room's data. /// This is an async request which triggers a OnOperationResponse() call. /// </summary> /// <remarks> /// If the room is already existing, the OperationResponse will have a returnCode of ErrorCode.GameAlreadyExists. /// </remarks> public virtual bool OpCreateRoom(EnterRoomParams opParams) { if (this.DebugOut >= DebugLevel.INFO) { this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()"); } Dictionary<byte, object> op = new Dictionary<byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { op[ParameterCode.RoomName] = opParams.RoomName; } if (opParams.Lobby != null && !string.IsNullOrEmpty(opParams.Lobby.Name)) { op[ParameterCode.LobbyName] = opParams.Lobby.Name; op[ParameterCode.LobbyType] = (byte) opParams.Lobby.Type; } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length > 0) { op[ParameterCode.Add] = opParams.ExpectedUsers; } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && opParams.PlayerProperties.Count > 0) { op[ParameterCode.PlayerProperties] = opParams.PlayerProperties; op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties } this.RoomOptionsToOpParameters(op, opParams.RoomOptions); } //UnityEngine.Debug.Log("CreateGame: " + SupportClassPun.DictionaryToString(op)); return this.OpCustom(OperationCode.CreateGame, op, true); }
/// <summary> /// Joins a room by name or creates new room if room with given name not exists. /// The OperationResponse depends on the server the peer is connected to: /// Master will return a Game Server to connect to. /// Game Server will return the joined Room's data. /// This is an async request which triggers a OnOperationResponse() call. /// </summary> /// <remarks> /// If the room is not existing (anymore), the OperationResponse will have a returnCode of ErrorCode.GameDoesNotExist. /// Other possible ErrorCodes are: GameClosed, GameFull. /// </remarks> /// <returns>If the operation could be sent (requires connection).</returns> public virtual bool OpJoinRoom(EnterRoomParams opParams) { if (this.DebugOut >= DebugLevel.INFO) { this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRoom()"); } Dictionary<byte, object> op = new Dictionary<byte, object>(); if (!string.IsNullOrEmpty(opParams.RoomName)) { op[ParameterCode.RoomName] = opParams.RoomName; } if (opParams.CreateIfNotExists) { op[ParameterCode.JoinMode] = (byte)JoinMode.CreateIfNotExists; if (opParams.Lobby != null) { op[ParameterCode.LobbyName] = opParams.Lobby.Name; op[ParameterCode.LobbyType] = (byte)opParams.Lobby.Type; } } if (opParams.RejoinOnly) { op[ParameterCode.JoinMode] = (byte)JoinMode.RejoinOnly; // changed from JoinMode.JoinOrRejoin } if (opParams.ExpectedUsers != null && opParams.ExpectedUsers.Length > 0) { op[ParameterCode.Add] = opParams.ExpectedUsers; } if (opParams.OnGameServer) { if (opParams.PlayerProperties != null && opParams.PlayerProperties.Count > 0) { op[ParameterCode.PlayerProperties] = opParams.PlayerProperties; op[ParameterCode.Broadcast] = true; // broadcast actor properties } if (opParams.CreateIfNotExists) { this.RoomOptionsToOpParameters(op, opParams.RoomOptions); } } // UnityEngine.Debug.Log("JoinGame: " + SupportClassPun.DictionaryToString(op)); return this.OpCustom(OperationCode.JoinGame, op, true); }
/// <summary>NetworkingPeer.OpJoinRoom</summary> public override bool OpJoinRoom(EnterRoomParams opParams) { bool onGameServer = this.server == ServerConnection.GameServer; opParams.OnGameServer = onGameServer; if (!onGameServer) { enterRoomParamsCache = opParams; } this.mLastJoinType = (opParams.CreateIfNotExists) ? JoinType.JoinOrCreateOnDemand : JoinType.JoinGame; return base.OpJoinRoom(opParams); }
/// <summary>NetworkingPeer.OpJoinRandomRoom</summary> /// <remarks>this override just makes sure we have a mRoomToGetInto, even if it's blank (the properties provided in this method are filters. they are not set when we join the game)</remarks> public override bool OpJoinRandomRoom(OpJoinRandomRoomParams opJoinRandomRoomParams) { enterRoomParamsCache = new EnterRoomParams(); // this is used when the client arrives on the GS and joins the room enterRoomParamsCache.Lobby = opJoinRandomRoomParams.TypedLobby; this.mLastJoinType = JoinType.JoinRandomGame; return base.OpJoinRandomRoom(opJoinRandomRoomParams); }
/// <summary>NetworkingPeer.OpCreateGame</summary> public bool OpCreateGame(EnterRoomParams enterRoomParams) { bool onGameServer = this.server == ServerConnection.GameServer; enterRoomParams.OnGameServer = onGameServer; enterRoomParams.PlayerProperties = GetLocalActorProperties(); if (!onGameServer) { enterRoomParamsCache = enterRoomParams; } this.mLastJoinType = JoinType.CreateGame; return base.OpCreateRoom(enterRoomParams); }
/// <summary>Can be used to return to a room after a disconnect and reconnect.</summary> /// <remarks> /// After losing connection, you might be able to return to a room and continue playing, /// if the client is reconnecting fast enough. Use Reconnect() and this method. /// Cache the room name you're in and use ReJoin(roomname) to return to a game. /// /// Note: To be able to ReJoin any room, you need to use UserIDs! /// You also need to set RoomOptions.PlayerTtl. /// /// <b>Important: Instantiate() and use of RPCs is not yet supported.</b> /// The ownership rules of PhotonViews prevent a seamless return to a game. /// Use Custom Properties and RaiseEvent with event caching instead. /// /// Common use case: Press the Lock Button on a iOS device and you get disconnected immediately. /// </remarks> public static bool ReJoinRoom(string roomName) { if (offlineMode) { Debug.LogError("ReJoinRoom failed due to offline mode."); return false; } if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady) { Debug.LogError("ReJoinRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return false; } if (string.IsNullOrEmpty(roomName)) { Debug.LogError("ReJoinRoom failed. A roomname is required. If you don't know one, how will you join?"); return false; } EnterRoomParams opParams = new EnterRoomParams(); opParams.RoomName = roomName; opParams.RejoinOnly = true; opParams.PlayerProperties = player.customProperties; return networkingPeer.OpJoinRoom(opParams); }
/// <summary>Join room by roomname and on success calls OnJoinedRoom(). This is not affected by lobbies.</summary> /// <remarks> /// On success, the method OnJoinedRoom() is called on any script. You can implement it to react to joining a room. /// /// JoinRoom fails if the room is either full or no longer available (it might become empty while you attempt to join). /// Implement OnPhotonJoinRoomFailed() to get a callback in error case. /// /// To join a room from the lobby's listing, use RoomInfo.name as roomName here. /// Despite using multiple lobbies, a roomName is always "global" for your application and so you don't /// have to specify which lobby it's in. The Master Server will find the room. /// In the Photon Cloud, an application is defined by AppId, Game- and PUN-version. /// /// You can define an array of expectedUsers, to block player slots in the room for these users. /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages. /// </remarks> /// <see cref="PhotonNetworkingMessage.OnPhotonJoinRoomFailed"/> /// <see cref="PhotonNetworkingMessage.OnJoinedRoom"/> /// <param name="roomName">Unique name of the room to join.</param> /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param> /// <returns>If the operation got queued and will be sent.</returns> public static bool JoinRoom(string roomName, string[] expectedUsers) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("JoinRoom failed. In offline mode you still have to leave a room to enter another."); return false; } EnterOfflineRoom(roomName, null, true); return true; } if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady) { Debug.LogError("JoinRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return false; } if (string.IsNullOrEmpty(roomName)) { Debug.LogError("JoinRoom failed. A roomname is required. If you don't know one, how will you join?"); return false; } EnterRoomParams opParams = new EnterRoomParams(); opParams.RoomName = roomName; opParams.ExpectedUsers = expectedUsers; return networkingPeer.OpJoinRoom(opParams); }
/// <summary>Lets you either join a named room or create it on the fly - you don't have to know if someone created the room already.</summary> /// <remarks> /// This makes it easier for groups of players to get into the same room. Once the group /// exchanged a roomName, any player can call JoinOrCreateRoom and it doesn't matter who /// actually joins or creates the room. /// /// The parameters roomOptions and typedLobby are only used when the room actually gets created by this client. /// You know if this client created a room, if you get a callback OnCreatedRoom (before OnJoinedRoom gets called as well). /// /// You can define an array of expectedUsers, to block player slots in the room for these users. /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages. /// </remarks> /// <param name="roomName">Name of the room to join. Must be non null.</param> /// <param name="roomOptions">Options for the room, in case it does not exist yet. Else these values are ignored.</param> /// <param name="typedLobby">Lobby you want a new room to be listed in. Ignored if the room was existing and got joined.</param> /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param> /// <returns>If the operation got queued and will be sent.</returns> public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another."); return false; } EnterOfflineRoom(roomName, roomOptions, true); // in offline mode, JoinOrCreateRoom assumes you create the room return true; } if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady) { Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return false; } if (string.IsNullOrEmpty(roomName)) { Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?"); return false; } typedLobby = typedLobby ?? ((networkingPeer.insideLobby) ? networkingPeer.lobby : null); // use given lobby, or active lobby (if any active) or none EnterRoomParams opParams = new EnterRoomParams(); opParams.RoomName = roomName; opParams.RoomOptions = roomOptions; opParams.Lobby = typedLobby; opParams.CreateIfNotExists = true; opParams.PlayerProperties = player.customProperties; opParams.ExpectedUsers = expectedUsers; return networkingPeer.OpJoinRoom(opParams); }
/// <summary> /// Creates a room but fails if this room is existing already. Can only be called on Master Server. /// </summary> /// <remarks> /// When successful, this calls the callbacks OnCreatedRoom and OnJoinedRoom (the latter, cause you join as first player). /// If the room can't be created (because it exists already), OnPhotonCreateRoomFailed gets called. /// /// If you don't want to create a unique room-name, pass null or "" as name and the server will assign a roomName (a GUID as string). /// /// Rooms can be created in any number of lobbies. Those don't have to exist before you create a room in them (they get /// auto-created on demand). Lobbies can be useful to split room lists on the server-side already. That can help keep the room /// lists short and manageable. /// If you set a typedLobby parameter, the room will be created in that lobby (no matter if you are active in any). /// If you don't set a typedLobby, the room is automatically placed in the currently active lobby (if any) or the /// default-lobby. /// /// Call this only on the master server. /// Internally, the master will respond with a server-address (and roomName, if needed). Both are used internally /// to switch to the assigned game server and roomName. /// /// PhotonNetwork.autoCleanUpPlayerObjects will become this room's autoCleanUp property and that's used by all clients that join this room. /// /// You can define an array of expectedUsers, to block player slots in the room for these users. /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages. /// </remarks> /// <param name="roomName">Unique name of the room to create. Pass null or "" to make the server generate a name.</param> /// <param name="roomOptions">Common options for the room like MaxPlayers, initial custom room properties and similar. See RoomOptions type..</param> /// <param name="typedLobby">If null, the room is automatically created in the currently used lobby (which is "default" when you didn't join one explicitly).</param> /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param> /// <returns>If the operation got queued and will be sent.</returns> public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers) { if (offlineMode) { if (offlineModeRoom != null) { Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another."); return false; } EnterOfflineRoom(roomName, roomOptions, true); return true; } if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady) { Debug.LogError("CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster."); return false; } typedLobby = typedLobby ?? ((networkingPeer.insideLobby) ? networkingPeer.lobby : null); // use given lobby, or active lobby (if any active) or none EnterRoomParams opParams = new EnterRoomParams(); opParams.RoomName = roomName; opParams.RoomOptions = roomOptions; opParams.Lobby = typedLobby; opParams.ExpectedUsers = expectedUsers; return networkingPeer.OpCreateGame(opParams); }
//========== PRIVATE METHODS =================================================================================== private IEnumerator JoinGame_Coroutine(int profileID) { m_GameState = EGameState.Joining; m_MatchmakingState = EMatchmakingState.Joining; // Connect to Photon Cloud for matchmaking m_Client.AppId = BoltRuntimeSettings.instance.photonAppId; m_Client.ConnectToRegionMaster("eu"); BoltLog.Info("Connecting to " + m_Client.AppId); // Wait up to 5 seconds for connection float timeLimit = Time.realtimeSinceStartup + 5.0f; while (m_Client.IsConnectedAndReady == false && Time.realtimeSinceStartup < timeLimit) { yield return(null); } if (m_Client.IsConnectedAndReady == false) { BoltLog.Error("Failed to connect to Photon Cloud for matchmaking!"); DisconnectFromMatchmaking(); m_GameState = EGameState.Menu; yield break; } // Register delegates to receive info about dedicated game server // OnServerInfoReceived will be invoked when room is full and game server successfully reserved // If there is an error (services exhaustion, wrong setup, ...), OnServerNotAvailable is invoked m_Client.OnServerInfoReceived += OnServerInfoReceived; m_Client.OnServerNotAvailable += OnServerNotAvailable; m_ServerInfoReceived = false; // Get RoomOptions instance directly from ZeuzClient or fill mandatory room properties yourself // Following code is a demonstration of joining a room for players who selected same Game Profile within same Server Group // You will need to come up with your custom matchmaking algorithm which suits your game RoomOptions roomOptions; if (m_ConnectToCustomServer == true) { roomOptions = m_Client.GetRoomOptions(m_ZeuzServerGroupID, profileID, m_ServerIP, m_ServerPort); } else { roomOptions = m_Client.GetRoomOptions(m_ZeuzServerGroupID, profileID); } roomOptions.IsOpen = true; roomOptions.IsVisible = true; roomOptions.MaxPlayers = m_MaxPlayersInRoom; string roomName = string.Format("Room_{0}_{1}", m_ZeuzServerGroupID, profileID); BoltLog.Info("Connected! Joining room: {0}, max players: {1}, Server Group ID: {2}, Game Profile ID: {3}", roomName, m_MaxPlayersInRoom, m_ZeuzServerGroupID, profileID); EnterRoomParams enterParams = new EnterRoomParams() { RoomName = roomName, RoomOptions = roomOptions, Lobby = TypedLobby.Default }; m_Client.OpJoinOrCreateRoom(enterParams); // Wait up to 5 seconds and check if we're in the room timeLimit = Time.realtimeSinceStartup + 5.0f; while (m_Client.CurrentRoom == null && Time.realtimeSinceStartup < timeLimit) { yield return(null); } if (m_ServerInfoReceived == true) { // Server info received too fast, sometimes happen with local server and Max Players In Room set to 1 yield break; } if (m_Client.CurrentRoom == null) { BoltLog.Error("Failed to join room: {0}", roomName); DisconnectFromMatchmaking(); m_GameState = EGameState.Menu; yield break; } BoltLog.Info("Joined room {0}, waiting for players...", m_Client.CurrentRoom.Name); m_MatchmakingState = EMatchmakingState.Queued; }
public void JoinRoom(EnterRoomParams parameters) => OpJoinRoom(parameters);