Problems Joining and creating Room? SQLLobby
Options
Tubbly
✭✭
Hey guys,
For the past few days I've been trying to sort out matchmaking based on skill level and a map mode (either 2v2 or 3v3).
I have no problem joining the lobby. However when matchmaking begins, the search correctly doesn't find any rooms (as there are none) so it attempts to create a new room. Once it creates a new room, It then searches for a room again however doesn't find the room it just created and instead tries to create a room again. It does this at least 3 times before finally being able to join one of its rooms created. This isn't the main problem. The main problem is that when I open a new client, and attempt to join a room, it doesn't find any of the rooms again and then creates a room for itself with now two separate rooms each player in their rooms. Here is the code of the process:
For the past few days I've been trying to sort out matchmaking based on skill level and a map mode (either 2v2 or 3v3).
I have no problem joining the lobby. However when matchmaking begins, the search correctly doesn't find any rooms (as there are none) so it attempts to create a new room. Once it creates a new room, It then searches for a room again however doesn't find the room it just created and instead tries to create a room again. It does this at least 3 times before finally being able to join one of its rooms created. This isn't the main problem. The main problem is that when I open a new client, and attempt to join a room, it doesn't find any of the rooms again and then creates a room for itself with now two separate rooms each player in their rooms. Here is the code of the process:
using UnityEngine; using System.Collections; using System.Collections.Generic; using ExitGames.Client.Photon.Chat; public class NetworkManager : Photon.MonoBehaviour { TypedLobby LobbyEU = new TypedLobby ("ChampionBrawlLobbyEU", LobbyType.SqlLobby); // Use this for initialization void Start () { PhotonNetwork.ConnectUsingSettings("alpha 0.1"); PhotonNetwork.autoJoinLobby = false; modeSelection.Add ("2v2", true); modeSelection.Add ("3v3", true); modeSelection.Add ("5v5", true); } void Update() { StartMatchmaking (); } void OnGUI() { GUI.Label (new Rect (0, Screen.height * 0.95f, 200, 200), PhotonNetwork.connectionStateDetailed.ToString ()); } void OnConnectedToMaster() { TypedLobby LobbyUS = new TypedLobby ("ChampionBrawlLobbyUS", LobbyType.SqlLobby); PhotonNetwork.JoinLobby (LobbyEU); } public void Connect() { } void OnJoinedLobby() { Debug.Log ("JOINED LOBBY " + LobbyEU.Name); } void OnJoinedRoom() { Debug.Log ("OnJOinedRoom. Loading map: " + "Temp"); Application.LoadLevel (6); } #region Variables Dictionary<string, bool> modeSelection = new Dictionary<string, bool> (); public int joinAttempt; public int MaximumSkillDeviationInSqlMatchmaking; int playerSkill; //List<MapQueueEntry> matchmakingMapQueue = new List<MapQueueEntry>(); const int MaxSkillDeviationInSqlMatchmaking = 3; ExitGames.Client.Photon.Hashtable newSqlProperties = new ExitGames.Client.Photon.Hashtable (); #endregion #region StartMatchmaking public void StartMatchmaking() { if (GetComponent<displayMenu> ().isMatchMakingStarted == false) { return; Debug.LogError("matchmaking hasnt started."); } else { Debug.Log ("Matchmaking started."); joinAttempt = 0; playerSkill = 5; Debug.Log ("Join Attempt started."); MakeSqlMatchmakingJoinAttempt (); } } #endregion void SetSqlRoomPropertiesDemonstrration() { ExitGames.Client.Photon.Hashtable newSqlProps = new ExitGames.Client.Photon.Hashtable (); //Creating a new lobby now that no available room is found to join. //C1 is used for the currently played gamemode //RoomProperty.Mode = "C0" newSqlProps.Add (RoomProperty.Mode, "2v2"); //C2 is used for an arbirtirarily selected skill level the player has //RoomProperty.SkillLevel = "C1" newSqlProps.Add (RoomProperty.SkillLevel, 5); string[] lobbyProperties = new string[] { "C0", "C1"}; PhotonNetwork.CreateRoom ("My Sql Room", true, true, 4,newSqlProps, lobbyProperties); } string CreateSqlSearchString() { string possibleSqlSearchResult = "( C0 = \"Greenlands\" OR C0 = \"City\" ) AND " + "( C1 = 0 OR C1 = 1 OR C1 = 2 ) AND " + "C2 > 3 AND C2 < 7"; //Create all search segments used to look for modes List<string> possibleModes = new List<string>(); foreach(KeyValuePair<string, bool> modePair in modeSelection) if (modePair.Value == true) possibleModes.Add (RoomProperty.Mode + " = " + modePair.Key); int skillDeviation = joinAttempt + 1; return "( " + string.Join ( " OR ", possibleModes.ToArray() ) + " ) AND (" + RoomProperty.SkillLevel + " > " + ( playerSkill - skillDeviation) + " AND " + RoomProperty.SkillLevel + " < " + ( playerSkill + skillDeviation) + " )"; } void OnPhotonRandomJoinFailed() { Debug.Log ("No Games available."); Debug.Log ("Attempt failed. Trying again..."); Invoke ("MakeSqlMatchmakingJoinAttempt", 1f); } public void SetPlayerSkill(int newSkill) { playerSkill = Mathf.Clamp(newSkill, 1, 10); } public int GetPlayerSkill() { return playerSkill; } #region SetModeSelection public void SetModeSelection(string mode, bool value) { if (modeSelection.ContainsKey (mode) == false) { return; } modeSelection [mode] = value; } #endregion #region GetMatchmakingInfo public string GetMatchmakingInfo() { return "Join attempt: " + joinAttempt; } #endregion #region CancelMatchmaking public void CancelMatchmaking() { GetComponent<displayMenu>().isMatchMakingStarted = false; StopAllCoroutines (); } #endregion void MakeSqlMatchmakingJoinAttempt() { if (joinAttempt < MaxSkillDeviationInSqlMatchmaking) { string sqlLobbyFilter = CreateSqlSearchString (); Debug.Log("Lobby filter search: " + sqlLobbyFilter); //looks for room with "sqlLobbyfilder" criteria which is held in a string (its a SQL command) PhotonNetwork.JoinRandomRoom (null, 8, MatchmakingMode.FillRoom, LobbyEU, sqlLobbyFilter); Debug.Log ("Room searching..."); joinAttempt++; Debug.Log (GetMatchmakingInfo()); } else { Debug.Log ("Join Attempt is more than Max Skill Deviation. Creating new matchmaking server"); GetComponent<displayMenu> ().isMatchMakingStarted = false; CreateSqlMatchmakingServer(); } } void CreateSqlMatchmakingServer() { SetSqlRoomPropertiesDemonstrration (); } }
0
Comments
-
if this helps, this is a weird error I'm getting:
0 -
Once it creates a new room, It then searches for a room again
After last client leaves the room, room is destroyed (may be after some timeout). So you need rooms with at least one player inside to be able search them.0 -
vadim wrote:Once it creates a new room, It then searches for a room again
After last client leaves the room, room is destroyed (may be after some timeout). So you need rooms with at least one player inside to be able search them.
At the moment, there is currently one room with one player in it. The other client cannot find this room at all.0 -
Does it work for plain lobby (not sql)?
If so then you need to check list of created room properties and sql expression (which is quite complicated as i see).0