Ejemplo n.º 1
0
        public void BuildLobbyInfo(ulong joining_player_id = 0)
        {
            if (!SteamMatches.IsLobbyOwner())
            {
                return;
            }

            PlayerLobbyInfo joining_player = null;

            var PrevInfo = LobbyInfo;

            LobbyInfo = new LobbyInfo(Program.MaxPlayers);

            int members = SteamMatches.GetLobbyMemberCount();

            for (int i = 0; i < members; i++)
            {
                ulong           SteamID = SteamMatches.GetMemberId(i);
                PlayerLobbyInfo player  = new PlayerLobbyInfo();
                player.Spectator = true;

                int index = 0;
                foreach (var prev_player in PrevInfo.Players)
                {
                    if (prev_player.SteamID == SteamID)
                    {
                        player           = LobbyInfo.Players[index] = prev_player;
                        player.Spectator = false;
                    }

                    index++;
                }

                player.Name = SteamMatches.GetMemberName(i);

                if (player.Spectator)
                {
                    player.SteamID = SteamMatches.GetMemberId(i);
                    LobbyInfo.Spectators.Add(player);
                }

                if (player.SteamID == joining_player_id)
                {
                    joining_player = player;
                }
            }

            // For every player that doesn't have a kingdom/team set,
            // choose an available initial value.
            foreach (var player in LobbyInfo.Players)
            {
                if (player.GamePlayer <= 0 || player.GamePlayer > Program.MaxPlayers)
                {
                    player.GamePlayer = FirstKingdomAvailableTo(player);
                }

                if (player.GameTeam <= 0 || player.GameTeam > Program.MaxTeams)
                {
                    player.GameTeam      = FirstTeamAvailableTo(player);
                    player.HasPickedTeam = true;
                }
            }

            // Set the current player to be the host.
            LobbyInfo.Players.ForEach(player => player.Host    = player.SteamID == SteamCore.PlayerId());
            LobbyInfo.Spectators.ForEach(player => player.Host = player.SteamID == SteamCore.PlayerId());

            // If there is a joinging player try to add them and then rebuild.
            if (joining_player_id != 0 && joining_player != null)
            {
                TryToJoin(joining_player.Name, joining_player);
                BuildLobbyInfo();
                return;
            }

            BuildArgs();
            SetLobbyInfo();
        }