void Start() { GameObject go = GameObject.Find("SocketIO"); socket = go.GetComponent <SocketIOComponent>(); setupEvents(); // the script is being called twice idk why and I dont want to investigate bcs I spent too much time on it if (!started) { started = true; startbutton = GameObject.Find("Start"); startbutton.SetActive(false); RestClient.Get <AllLobbies>("https://catan-connectivity.herokuapp.com/lobby/all").Then(ReceivedLobby => // find a lobby with a user extension if found and it has a place join else add a lobby { allLobbies.lobbies = ReceivedLobby.lobbies; if (allLobbies.lobbies.Length != 0) { bool found_free_lobby = false; for (int i = 0; i < allLobbies.lobbies.Length; i++) { if (allLobbies.lobbies[i].extension == LoginScript.CurrentUserExtension && (allLobbies.lobbies[i].first == "-" || allLobbies.lobbies[i].second == "-" || allLobbies.lobbies[i].third == "-")) { JoinLobby jl = new JoinLobby(LoginScript.CurrentUser, allLobbies.lobbies[i].lobbyid); found_free_lobby = true; // JoinLobby jl = new JoinLobby("mmoruz", allLobbies.lobbies[i].lobbyid); RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/join", jl).Then(joined_lobby => { LoginScript.CurrentUserGameId = allLobbies.lobbies[i].gameid; LoginScript.CurrentUserLobbyId = allLobbies.lobbies[i].lobbyid; }).Catch(err => { Debug.Log(err); }); break; } } if (!found_free_lobby) { UnityConnectivityCommand command = new UnityConnectivityCommand(); //command.username = "******"; command.username = LoginScript.CurrentUser; RestClient.Post <LobbyConnectivityJson>("https://catan-connectivity.herokuapp.com/lobby/add", command).Then(added_Lobby => { LoginScript.CurrentUserGameId = added_Lobby.gameid; LoginScript.CurrentUserLobbyId = added_Lobby.lobbyid; }).Catch(err => { Debug.Log(err); }); } } else { UnityConnectivityCommand command = new UnityConnectivityCommand(); //command.username = "******"; command.username = LoginScript.CurrentUser; RestClient.Post <LobbyConnectivityJson>("https://catan-connectivity.herokuapp.com/lobby/add", command).Then(added_Lobby => { LoginScript.CurrentUserGameId = added_Lobby.gameid; LoginScript.CurrentUserLobbyId = added_Lobby.lobbyid; }).Catch(err => { Debug.Log(err); }); } }).Catch(err => { Debug.Log(err); }); } }
public void createLobby() // in case there are no lobby change the button from connect to create and call that function { if (ok == false) { ok = true; UnityConnectivityCommand command = new UnityConnectivityCommand(); //command.username = "******"; command.username = LoginScript.CurrentUser; RestClient.Post <LobbyConnectivityJson>("https://catan-connectivity.herokuapp.com/lobby/add", command).Then(added_Lobby => { LoginScript.CurrentUserGameId = added_Lobby.gameid; LoginScript.CurrentUserLobbyId = added_Lobby.lobbyid; UnityConnectivityCommand getgeid = new UnityConnectivityCommand(); //getgeid.username = "******"; getgeid.username = LoginScript.CurrentUser; RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/geid", getgeid).Then(response => { LoginScript.CurrentUserGEId = response.Text; LoginScript.CurrentLobby = new Lobby(LoginScript.CurrentUserExtension, "-", "-", "-", LoginScript.CurrentUser, LoginScript.CurrentUserGameId, LoginScript.CurrentUserLobbyId); SceneChanger scene = new SceneChanger(); scene.goToWaitingRoom(); }).Catch(err => { Debug.Log(err); }); }).Catch(err => { Debug.Log(err); }); } }
public void joinLobby(Text txt) // identify a lobby by its lobbyid { if (okJoin == false) { string lobbyid = txt.text; print(lobbyid); for (int i = 0; i < lobbies.Count; i++) { if (lobbies[i].lobbyid == lobbyid && lobbies[i].extension == LoginScript.CurrentUserExtension && (countPlayers(lobbies[i]) != 4)) { okJoin = true; JoinLobby jl = new JoinLobby(LoginScript.CurrentUser, lobbies[i].lobbyid); RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/join", jl).Then(joined_lobby => { LoginScript.CurrentUserGameId = lobbies[i].gameid; LoginScript.CurrentUserLobbyId = lobbies[i].lobbyid; UnityConnectivityCommand getgeid = new UnityConnectivityCommand(); //getgeid.username = "******"; getgeid.username = LoginScript.CurrentUser; RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/geid", getgeid).Then(response => { LoginScript.CurrentUserGEId = response.Text; LoginScript.CurrentLobby = lobbies[i]; SceneChanger scene = new SceneChanger(); scene.goToWaitingRoom(); }).Catch(err => { Debug.Log(err); }); }).Catch(err => { Debug.Log(err); }); break; } } } }
public void LeaveLobby() { UnityConnectivityCommand command = new UnityConnectivityCommand(); command.lobbyid = LoginScript.CurrentUserLobbyId; command.username = LoginScript.CurrentUser; RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/leaveLobby", command).Then(res => { Debug.Log(res.Text); }).Catch(err => { Debug.Log(err); }); }
public void RequestLobbyidAndGameid() { UnityConnectivityCommand command = new UnityConnectivityCommand(); command.username = LoginScript.CurrentUser; RestClient.Post <LobbyConnectivityJson>("https://catan-connectivity.herokuapp.com/lobby/add", command).Then(ReceivedLobby => { LoginScript.CurrentUserGameId = ReceivedLobby.gameid; LoginScript.CurrentUserLobbyId = ReceivedLobby.lobbyid; getGameBoard(ReceivedLobby.gameid); }).Catch(err => { Debug.Log(err); }); }
public void LeaveGame() { UnityConnectivityCommand command = new UnityConnectivityCommand(); command.active = false; command.playerId = LoginScript.CurrentUserGEId; command.gameId = LoginScript.CurrentUserGameId; Debug.Log(LoginScript.CurrentUserGEId); RestClient.Post("https://catan-connectivity.herokuapp.com/lobby/leaveGame", command).Then(res => { //ChangeTexture.setDone(false); Debug.Log(res.Text); ReceiveBoardScript.ReceivedBoard.board[0] = null; }).Catch(err => { Debug.Log(err); }); }