private void ReceiveOtherClientStatus(Protocol.BaseProtocol protocol) { Protocol.StatusProtocol status = protocol as Protocol.StatusProtocol; if (status.IsType(Protocol.StatusProtocol.Type.Client)) { if (status.ok) { currentGamePlayers.Add(nextLobbyId, new Client(status.from_client)); ++nextLobbyId; } else { foreach (KeyValuePair <int, Client> kp in currentGamePlayers) { if (kp.Value.nickname == status.from_client) { currentGamePlayers.Remove(kp.Key); PlayerDisconnected?.Invoke(kp.Key); break; } } } } GameInfoUpdated?.Invoke(); }
private void ChangePlayer(Protocol.BaseProtocol protocol) { Protocol.ChangePlayerProtocol changePlayer = protocol as Protocol.ChangePlayerProtocol; currentPlayerID = changePlayer.player_id; GameInfoUpdated?.Invoke(); }
private void StartGame(Protocol.BaseProtocol protocol) { Protocol.StartGameProtocol startgame = protocol as Protocol.StartGameProtocol; if (startgame.ok) { gameActive = true; } // else // about the game // TODO: above GameInfoUpdated?.Invoke(); GameActiveStateChanged?.Invoke(gameActive); }
private void ReceiveGameInfo(Protocol.BaseProtocol protocol) { Protocol.GameInfoProtocol gameInfo = protocol as Protocol.GameInfoProtocol; gameName = gameInfo.game_name; minPlayers = gameInfo.min_players; maxPlayers = gameInfo.max_players; gameStartsAt = Time.time + gameInfo.starts_in; currentGamePlayers.Clear(); nextLobbyId = 0; foreach (string player in gameInfo.players) { currentGamePlayers.Add(nextLobbyId, new Client(player)); ++nextLobbyId; } GameInfoUpdated?.Invoke(); }