public void OnJoinLobby(JoinLobby joinLobby) { _log.Output($"Player [{joinLobby.ClientId}] joining lobby [{joinLobby.LobbyId}]"); LobbyState state = GetLobbyById(joinLobby.LobbyId); if (state == null) { // try geting lobby by name, will return the first match state = GetLobbyByName(joinLobby.LobbyId); if (state == null) { // TODO - need to send feed back to player that cannot connect return; } } // Add player if not already added if (!state.ContainsPlayerId(joinLobby.ClientId)) { state.AddPlayer(joinLobby.ClientId, joinLobby.PlayerDisplayName); } // send all players connected to this lobby a lobby update Broadcast(state, new UpdateLobbyState(state)); }
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); }); } }
void Given(JoinLobby e) { if (LobbyExists(e.LobbyId)) { SelectLobby(e.LobbyId).Users.Add(e.UserId); } }
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; } } } }
void When(JoinLobby e) { if (LobbyExists(e.LobbyId)) { SelectLobby(e.LobbyId).Users.Add(e.UserId); Then(new UserJoined(e.LobbyId, e.UserId)); } }
public MenuManager(ContentManager Content, BannerManager bannerManager, NetworkingManager networkingManager) { this.bannerManager = bannerManager; this.networkingManager = networkingManager; BackgroundTexture = Content.Load <Texture2D>(@"menuBackground"); mainMenu = new MainMenu(Content); profile = new Profile(Content); play = new Play(Content); joinLobby = new JoinLobby(Content); createLobby = new CreateLobby(Content); about = new About(Content); expansionLobby = new ExpansionLobby(Content); quitGame = new QuitGame(Content); MenuState = MenuStates.MainMenu; activeMenu = mainMenu; ExitGame = false; }
public void ButtonClicked(int LobbyID) { // passing the lobby id to the Join lobby script so that it can set the text in canvas joinLobby = GameObject.FindObjectOfType <JoinLobby>(); joinLobby.SetLobbyID(LobbyID); }