コード例 #1
0
        public void OnFindLobbies(bool result)
        {
            if (result)
            {
                Console.WriteLine("Failure during lobby search.");
                return;
            }

            var obj = new Dict();

            int num_lobbies = SteamMatches.NumLobbies();

            Console.WriteLine("Found {0} lobbies", num_lobbies);
            obj["NumLobbies"] = num_lobbies;

            var lobby_list  = new List <Dict>(num_lobbies);
            var lobby_names = new List <String>(num_lobbies);

            for (int i = 0; i < num_lobbies; i++)
            {
                string lobby_name        = SteamMatches.GetLobbyData(i, "name");
                string game_started      = SteamMatches.GetLobbyData(i, "GameStarted");
                string countdown_started = SteamMatches.GetLobbyData(i, "CountDownStarted");
                if (!lobby_names.Contains(lobby_name) && !(countdown_started == "true" && game_started != "true"))
                {
                    int member_count = SteamMatches.GetLobbyMemberCount(i);
                    int capacity     = SteamMatches.GetLobbyCapacity(i);

                    // Console.WriteLine("lobby {0} name: {1} members: {2}/{3}", i, lobby_name, member_count, capacity);

                    if (capacity <= 0)
                    {
                        continue;
                    }

                    var lobby = new Dict();
                    lobby["Name"]        = lobby_name;
                    lobby["Index"]       = i;
                    lobby["MemberCount"] = member_count;
                    lobby["Capacity"]    = capacity;
                    lobby["GameStarted"] = game_started;

                    lobby["NumPlayers"]    = SteamMatches.GetLobbyData(i, "NumPlayers").MaybeInt();
                    lobby["NumSpectators"] = SteamMatches.GetLobbyData(i, "NumSpectators").MaybeInt();
                    lobby["MaxPlayers"]    = SteamMatches.GetLobbyData(i, "MaxPlayers").MaybeInt();

                    lobby_names.Add(lobby_name);
                    lobby_list.Add(lobby);
                }
            }

            obj["Lobbies"] = lobby_list;
            obj["Online"]  = true;

            Send("lobbies", obj);
        }
コード例 #2
0
ファイル: Lobby.cs プロジェクト: JordanFisher/WAL
        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();
        }