/// <summary>
/// Don't use this method directly, unless you know how to cache and apply customActorProperties.
/// The PhotonNetwork methods will handle player and room properties for you and call this method.
/// </summary>
public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
{
if (this.DebugOut >= DebugLevel.INFO)
{
this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
}
Dictionary<byte, object> op = new Dictionary<byte, object>();
if (!string.IsNullOrEmpty(roomName))
{
op[ParameterCode.RoomName] = roomName;
}
if (lobby != null)
{
op[ParameterCode.LobbyName] = lobby.Name;
op[ParameterCode.LobbyType] = (byte)lobby.Type;
}
if (onGameServer)
{
if (playerProperties != null && playerProperties.Count > 0)
{
op[ParameterCode.PlayerProperties] = playerProperties;
op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
}
if (roomOptions == null)
{
roomOptions = new RoomOptions();
}
Hashtable gameProperties = new Hashtable();
op[ParameterCode.GameProperties] = gameProperties;
gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
if (roomOptions.maxPlayers > 0)
{
gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
}
if (roomOptions.cleanupCacheOnLeave)
{
op[ParameterCode.CleanupCacheOnLeave] = true; // this is actually setting the room's config
gameProperties[GameProperties.CleanupCacheOnLeave] = true; // this is only informational for the clients which join
}
}
// UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
return this.OpCustom(OperationCode.CreateGame, op, true);
}
/// <summary>
/// Joins the lobby on the Master Server, where you get a list of RoomInfos of currently open rooms.
/// This is an async request which triggers a OnOperationResponse() call.
/// </summary>
/// <returns>If the operation could be sent (has to be connected).</returns>
public virtual bool OpJoinLobby(TypedLobby lobby)
{
if (this.DebugOut >= DebugLevel.INFO)
{
this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
}
Dictionary<byte, object> parameters = null;
if (lobby != null && !lobby.IsDefault)
{
parameters = new Dictionary<byte, object>();
parameters[(byte)ParameterCode.LobbyName] = lobby.Name;
parameters[(byte)ParameterCode.LobbyType] = (byte)lobby.Type;
}
return this.OpCustom(OperationCode.JoinLobby, parameters, true);
}
/// <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).
/// </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>
/// <returns>If the operation got queued and will be sent.</returns>
public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
{
if (offlineMode)
{
if (offlineModeRoom != null)
{
Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another.");
return false;
}
offlineModeRoom = new Room(roomName, roomOptions);
offlineModeRoom.masterClientId = 1;
NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom); // in offline mode you create, too for JoinOrCreateRoom
NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
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;
}
return networkingPeer.OpJoinRoom(roomName, roomOptions, typedLobby, true);
}
/// <summary>On a Master Server you can join a lobby to get lists of available rooms.</summary>
/// <remarks>
/// The room list is sent and refreshed by the server. You can access this cached list by
/// PhotonNetwork.GetRoomList().
///
/// Any client can "make up" any lobby on the fly. Splitting rooms into multiple lobbies will
/// keep each list shorter. However, having too many lists might ruin the matchmaking experience.
///
/// In best case, you create a limited number of lobbies. For example, create a lobby per
/// game-mode: "koth" for king of the hill and "ffa" for free for all, etc.
///
/// There is no listing of lobbies at the moment.
///
/// Sql-typed lobbies offer a different filtering model for random matchmaking. This might be more
/// suited for skillbased-games. However, you will also need to follow the conventions for naming
/// filterable properties in sql-lobbies! Both is explained in the matchmaking doc linked below.
///
/// In best case, you make your clients join random games, as described here:
/// http://confluence.exitgames.com/display/PTN/Op+JoinRandomGame
///
///
/// Per room you should check if it's full or not before joining. Photon does list rooms that are
/// full, unless you close and hide them (room.open = false and room.visible = false).
///
/// You can show your games current players and room count without joining a lobby (but you must
/// be on the master server). Use: countOfPlayers, countOfPlayersOnMaster, countOfPlayersInRooms and
/// countOfRooms.
///
/// When creating new rooms, they will be "attached" to the currently used lobby or the default lobby.
///
/// You can use JoinRandomRoom without being in a lobby!
/// Set autoJoinLobby = false before you connect, to not join a lobby. In that case, the
/// connect-workflow will call OnConnectedToMaster (if you implement it) when it's done.
/// </remarks>
/// <param name="typedLobby">A typed lobby to join (must have name and type).</param>
public static bool JoinLobby(TypedLobby typedLobby)
{
if (PhotonNetwork.connected && PhotonNetwork.Server == ServerConnection.MasterServer)
{
if (typedLobby == null)
{
typedLobby = TypedLobby.Default;
}
bool sending = networkingPeer.OpJoinLobby(typedLobby);
if (sending)
{
networkingPeer.lobby = typedLobby;
}
return sending;
}
return false;
}
/// <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.
/// </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>
public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
{
if (offlineMode)
{
if (offlineModeRoom != null)
{
Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another.");
return false;
}
offlineModeRoom = new Room(roomName, roomOptions);
offlineModeRoom.masterClientId = 1;
NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);
NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
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;
}
return networkingPeer.OpCreateGame(roomName, roomOptions, typedLobby);
}
/// <summary>
/// Operation to join a random, available room. Overloads take additional player properties.
/// This is an async request which triggers a OnOperationResponse() call.
/// If all rooms are closed or full, the OperationResponse will have a returnCode of ErrorCode.NoRandomMatchFound.
/// If successful, the OperationResponse contains a gameserver address and the name of some room.
/// </summary>
/// <param name="expectedCustomRoomProperties">Optional. A room will only be joined, if it matches these custom properties (with string keys).</param>
/// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
/// <param name="playerProperties">This player's properties (custom and well known).</param>
/// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
/// <returns>If the operation could be sent currently (requires connection).</returns>
public virtual bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
{
if (this.DebugOut >= DebugLevel.INFO)
{
this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
}
Hashtable expectedRoomProperties = new Hashtable();
expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
if (expectedMaxPlayers > 0)
{
expectedRoomProperties[GameProperties.MaxPlayers] = expectedMaxPlayers;
}
Dictionary<byte, object> opParameters = new Dictionary<byte, object>();
if (expectedRoomProperties.Count > 0)
{
opParameters[ParameterCode.GameProperties] = expectedRoomProperties;
}
if (playerProperties != null && playerProperties.Count > 0)
{
opParameters[ParameterCode.PlayerProperties] = playerProperties;
}
if (matchingType != MatchmakingMode.FillRoom)
{
opParameters[ParameterCode.MatchMakingType] = (byte)matchingType;
}
if (typedLobby != null)
{
opParameters[ParameterCode.LobbyName] = typedLobby.Name;
opParameters[ParameterCode.LobbyType] = (byte)typedLobby.Type;
}
if (!string.IsNullOrEmpty(sqlLobbyFilter))
{
opParameters[ParameterCode.Data] = sqlLobbyFilter;
}
// UnityEngine.Debug.LogWarning("OpJoinRandom: " + opParameters.ToStringFull());
return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
}
/// <summary>
/// Method to be called when the user wants to create a new room.
/// </summary>
public void CreateNewRoom(int numberOfPlayers,ProjectDelegates.RoomInfoCallback RoomCreatedCallback, int level)
{
OnJoinedRoomCallback = RoomCreatedCallback;
ExitGames.Client.Photon.Hashtable customParams = new ExitGames.Client.Photon.Hashtable();
customParams.Add("C0", level);
RoomOptions options = new RoomOptions();
options.maxPlayers = numberOfPlayers;
TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);
//PhotonNetwork.CreateRoom ("",options,typedLobby);
//PhotonNetwork.CreateRoom ("", true, true, numberOfPlayers);
// testing this to git rid of the build warning
PhotonNetwork.CreateRoom("", options, typedLobby);
}
/// <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);
}
void OnGUI() // da alte GUI haben wir dies im Projekt nicht verwendet, war nur zu testzwecken
{
//zeigt Details über den derzeitigen Status im Photonnetzwerk an
GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
//GUILayout.Label (PhotonNetwork.GetPing ().ToString ());
//überprüft ob ich im Netzwerk und Lobby bin
if (PhotonNetwork.insideLobby == true)
{
//Zeigt die Lobby Room-List und gestattet es Räume selbst zu erstellen
GUI.Box(new Rect(Screen.width / 2.5f, Screen.height / 3, 400, 550), "");
GUILayout.BeginArea(new Rect(Screen.width / 2.5f, Screen.height / 3f, 400, 500));
GUI.color = Color.red;
GUILayout.Box("Lobby");
GUI.color = Color.white;
GUILayout.Label("Room Name:");
roomName = GUILayout.TextField(roomName); //hier kann man seinen Raumnamen eintragen
GUILayout.Label("Max Amount of player 1-20:");
maxPlayerString = GUILayout.TextField(maxPlayerString, 2); //Eingabe der max. SPieleranzahl in dem Raum
//überprüft ob im maxplayerstring etwas eingetragen wurde
if (maxPlayerString != "")
{
maxPlayer = int.Parse(maxPlayerString); // wandelt den maxPlayerString in ein Int um es folgend auszuwerten
if (maxPlayer % 2 == 1) maxPlayer += 1; // wenn ungleiche Zahl dann +1 maxplayer
if (maxPlayer > 20) maxPlayer = 20; // es können nicht mehr als 20 Spieler in den Raum
if (maxPlayer == 0) maxPlayer = 2; // das Minimum an SPielern beträgt immer 2
}
else
{
maxPlayer = 2; // wenn nichts eingetragen wurde setzt es Standartwert von 2 Spielern
}
if (GUILayout.Button("Create Room"))
{
if (roomName != "" && maxPlayer > 0) //überprüft ob es einen Raumnamen gibt und ob die max Player Anzahl stimmt
{
RoomOptions options = new RoomOptions(); ;
options.isOpen = true;
options.isVisible = true;
options.maxPlayers = maxPlayer;
TypedLobby lobby = new TypedLobby();
lobby.Type = LobbyType.Default;
PhotonNetwork.CreateRoom(roomName,options, lobby); // erstellt den Photonraum mit derzeitigen einstellungen
}
}
GUILayout.Space(20);
GUI.color = Color.red;
GUILayout.Box("Game Rooms");
GUI.color = Color.white;
GUILayout.Space(20);
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Width(400), GUILayout.Height(300));
foreach (RoomInfo game in PhotonNetwork.GetRoomList()) // geht durch die anzahl an vorhandenen und offenen Räume
{
GUI.color = Color.green;
GUILayout.Box(game.name + " " + game.playerCount + "/" + game.maxPlayers); //zeigt für jeden Raum Spieleranzahl und Name des RAums an
GUI.color = Color.white;
if (GUILayout.Button("Join Room"))
{
PhotonNetwork.JoinRoom(game.name); //neben jedem Raum ist ein Button um diesem zu joinen
}
}
GUILayout.EndScrollView();
GUILayout.EndArea();
}
}
/// <summary>
/// Method to be called when the user wants to try to connect to an existing room.
/// </summary>
public void JoinRoom(byte maxPlayers, int level, ProjectDelegates.RoomInfoCallback JoinedRoomCallback)
{
this.maxPlayers = maxPlayers;
this.level = level;
OnJoinedRoomCallback = JoinedRoomCallback;
string sqlFilter = "C0 > " + (level-3) + " AND C0 < " + (level+3);
Debug.Log (sqlFilter);
TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);
PhotonNetwork.JoinRandomRoom(null,maxPlayers,MatchmakingMode.FillRoom,typedLobby,"");
//PhotonNetwork.JoinRandomRoom (, MatchmakingMode.FillRoom, typedLobby, sqlFilter);
}
/// <summary>
/// Attempts to join an open room with fitting, custom properties but fails if none is currently available.
/// </summary>
/// <remarks>
/// Rooms can be created in arbitrary lobbies which get created on demand.
/// You can join rooms from any lobby without actually joining the lobby with this overload.
///
/// This method will only match rooms attached to one lobby! If you use many lobbies, you
/// might have to repeat JoinRandomRoom, to find some fitting room.
/// This method looks up a room in the specified lobby or the currently active lobby (if none specified)
/// or in the default lobby (if none active).
///
/// If this fails, you can still create a room (and make this available for the next who uses JoinRandomRoom).
/// Alternatively, try again in a moment.
///
/// In offlineMode, a room will be created but no properties will be set and all parameters of this
/// JoinRandomRoom call are ignored. The event/callback OnJoinedRoom gets called (see enum PhotonNetworkingMessage).
/// </remarks>
/// <param name="expectedCustomRoomProperties">Filters for rooms that match these custom properties (string keys and values). To ignore, pass null.</param>
/// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
/// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
/// <param name="typedLobby">The lobby in which you want to lookup a room. Pass null, to use the default lobby. This does not join that lobby and neither sets the lobby property.</param>
/// <param name="sqlLobbyFilter">A filter-string for SQL-typed lobbies.</param>
public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
{
if (offlineMode)
{
if (offlineModeRoom != null)
{
Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
return false;
}
offlineModeRoom = new Room("offline room", null);
offlineModeRoom.masterClientId = 1;
NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
return true;
}
if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
{
Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
return false;
}
return networkingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, null, matchingType, typedLobby, sqlLobbyFilter);
}
/// <summary>
/// Attempts to join an open room with fitting, custom properties but fails if none is currently available.
/// </summary>
/// <remarks>
/// Rooms can be created in arbitrary lobbies which get created on demand.
/// You can join rooms from any lobby without actually joining the lobby with this overload.
///
/// This method will only match rooms attached to one lobby! If you use many lobbies, you
/// might have to repeat JoinRandomRoom, to find some fitting room.
/// This method looks up a room in the specified lobby or the currently active lobby (if none specified)
/// or in the default lobby (if none active).
///
/// If this fails, you can still create a room (and make this available for the next who uses JoinRandomRoom).
/// Alternatively, try again in a moment.
///
/// In offlineMode, a room will be created but no properties will be set and all parameters of this
/// JoinRandomRoom call are ignored. The event/callback OnJoinedRoom gets called (see enum PhotonNetworkingMessage).
///
/// 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="expectedCustomRoomProperties">Filters for rooms that match these custom properties (string keys and values). To ignore, pass null.</param>
/// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
/// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
/// <param name="typedLobby">The lobby in which you want to lookup a room. Pass null, to use the default lobby. This does not join that lobby and neither sets the lobby property.</param>
/// <param name="sqlLobbyFilter">A filter-string for SQL-typed lobbies.</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 JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter, string[] expectedUsers = null)
{
if (offlineMode)
{
if (offlineModeRoom != null)
{
Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
return false;
}
EnterOfflineRoom("offline room", null, true);
return true;
}
if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady)
{
Debug.LogError("JoinRandomRoom 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
OpJoinRandomRoomParams opParams = new OpJoinRandomRoomParams();
opParams.ExpectedCustomRoomProperties = expectedCustomRoomProperties;
opParams.ExpectedMaxPlayers = expectedMaxPlayers;
opParams.MatchingType = matchingType;
opParams.TypedLobby = typedLobby;
opParams.SqlLobbyFilter = sqlLobbyFilter;
opParams.ExpectedUsers = expectedUsers;
return networkingPeer.OpJoinRandomRoom(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(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
{
this.mRoomToGetInto = new Room(null, null);
this.mRoomToEnterLobby = null; // join random never stores the lobby. the following join will not affect the room lobby
// if typedLobby is null, the server will automatically use the active lobby or default, which is what we want anyways
this.mLastJoinType = JoinType.JoinRandomGame;
return base.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerProperties, matchingType, typedLobby, sqlLobbyFilter);
}
请发表评论