Esempio n. 1
0
        public void SetLobbyInfo()
        {
            if (!SteamMatches.IsLobbyOwner())
            {
                return;
            }

            // This ensures the lobby info changes and forces and update,
            // even if no relevant values changed.
            LobbyInfo.MarkAsChanged();

            // Assign unused teams/player spots to non-gamer players. (SteamID == 0).
            foreach (var player in LobbyInfo.Players)
            {
                if (player.SteamID != 0)
                {
                    continue;
                }
                player.GamePlayer    = FirstKingdomAvailableTo(player);
                player.GameTeam      = FirstTeamAvailableTo(player);
                player.HasPickedTeam = true;
            }

            SetLobbyName();
            BuildArgs();

            SteamMatches.SetLobbyData("Players", Jsonify(LobbyInfo.Players));
            SteamMatches.SetLobbyData("Spectators", Jsonify(LobbyInfo.Spectators));
            SteamMatches.SetLobbyData("Params", Jsonify(LobbyInfo.Params));
            SteamMatches.SetLobbyData("CommonArgs", LobbyInfo.CommonArgs);

            SteamMatches.SetLobbyData("NumPlayers", LobbyInfo.Players.Count(_player => _player.SteamID != 0).ToString());
            SteamMatches.SetLobbyData("NumSpectators", LobbyInfo.Spectators.Count.ToString());
            SteamMatches.SetLobbyData("MaxPlayers", Program.MaxPlayers.ToString());
        }
Esempio n. 2
0
        public void OnJoinLobby(bool result)
        {
            LobbyInfo = new LobbyInfo(Program.MaxPlayers);

            if (result)
            {
                Console.WriteLine("Failure joining the lobby.");

                Send("joinFailed");
                SteamMatches.SetLobbyCallbacks(null, null, null, null);

                return;
            }

            BuildMapList();

            if (SteamMatches.IsLobbyOwner())
            {
                GameMapName = null;
                MapLoading  = true;
                SetMap(Maps[0]);
            }

            string lobbyName = SteamMatches.GetLobbyData("name");

            Console.WriteLine("joined lobby {0}", lobbyName);

            IsHost = SteamMatches.IsLobbyOwner();

            SendLobbyData();
            BuildLobbyInfo(joining_player_id: SteamCore.PlayerId());

            SteamP2P.SetOnP2PSessionRequest(OnP2PSessionRequest);
            SteamP2P.SetOnP2PSessionConnectFail(OnP2PSessionConnectFail);

            string game_started = SteamMatches.GetLobbyData("GameStarted");

            if (game_started == "true")
            {
                _StartGame();
            }
        }
Esempio n. 3
0
        public LobbyInfo GetLobbyInfo()
        {
            LobbyInfo info = new LobbyInfo();

            var players = SteamMatches.GetLobbyData("Players");

            info.Players = (List <PlayerLobbyInfo>)JsonConvert.DeserializeObject(players, typeof(List <PlayerLobbyInfo>));

            var spectators = SteamMatches.GetLobbyData("Spectators");

            info.Spectators = (List <PlayerLobbyInfo>)JsonConvert.DeserializeObject(spectators, typeof(List <PlayerLobbyInfo>));

            var game_params = SteamMatches.GetLobbyData("Params");

            info.Params = (GameParameters)JsonConvert.DeserializeObject(game_params, typeof(GameParameters));

            info.CommonArgs = SteamMatches.GetLobbyData("CommonArgs");

            return(info);
        }
Esempio n. 4
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();
        }