Exemple #1
0
        public void SendLobbyData()
        {
            var obj = new Dict();

            obj["SteamID"] = SteamCore.PlayerId();
            obj["Maps"]    = Maps;

            string lobby_name = SteamMatches.GetLobbyData("name");
            //string lobby_info = SteamMatches.GetLobbyData("LobbyInfo");
            string lobby_info = Jsonify(GetLobbyInfo());

            if (lobby_info != null && lobby_info.Length > 0 && lobby_name.Length > 0)
            {
                obj["LobbyInfo"]        = lobby_info;
                obj["LobbyName"]        = lobby_name;
                obj["LobbyLoading"]     = false;
                obj["CountDownStarted"] = SteamMatches.GetLobbyData("CountDownStarted");
            }
            else
            {
                obj["LobbyLoading"] = true;
            }

            Send("lobby", obj);
        }
Exemple #2
0
        public void _StartGame()
        {
            //var lobby_data = SteamMatches.GetLobbyData("LobbyInfo");
            //var lobby = JsonConvert.DeserializeObject(lobby_data, typeof(LobbyInfo));
            //LobbyInfo = (LobbyInfo)lobby;

            LobbyInfo = GetLobbyInfo();

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

            if (game_started == "true")
            {
                var player = LobbyInfo.Players.Where(match => match.SteamID != 0).First();
                var args   = player.Args + ' ' + LobbyInfo.CommonArgs;

                Program.ParseOptions(args);
                Program.Spectate            = true;
                Program.Server              = false;
                Program.Client              = true;
                Program.StartupPlayerNumber = 0;
            }
            else
            {
                var args = ThisPlayer.Args + ' ' + LobbyInfo.CommonArgs;

                Program.ParseOptions(args);
            }

            SetScenarioToLoad(Program.StartupMap);
            Networking.Start();

            SteamMatches.SetLobbyData("GameStarted", "true");
        }
Exemple #3
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);
        }
Exemple #4
0
        public void OnLobbyDataUpdate()
        {
            Console.WriteLine("lobby data updated");

            if (Program.GameStarted)
            {
                return;
            }

            string map = SteamMatches.GetLobbyData("MapName");

            if (map != null && map.Length > 0)
            {
                SetMap(map);
            }

            SendLobbyData();
        }
Exemple #5
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();
            }
        }
Exemple #6
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);
        }
Exemple #7
0
        void Test_OnFindLobbies(bool result)
        {
            Console.WriteLine(result);

            if (result)
            {
                Console.WriteLine("Failure during lobby search.");
                return;
            }

            int n = SteamMatches.NumLobbies();

            Console.WriteLine("Found {0} lobbies", n);

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(SteamMatches.GetLobbyData(i, "name"));
            }

            SteamMatches.JoinCreatedLobby(Test_OnJoinLobby, Test_OnLobbyChatUpdate, Test_OnLobbyChatMsg, Test_OnLobbyDataUpdate);
        }
Exemple #8
0
        public void SetMap(string map_name)
        {
            Console.WriteLine("set map to {0}", map_name);

            string full_name = map_name + ".m3n";

            bool skip = false;

            if ((SetMapThread == null || !SetMapThread.IsAlive) && GameMapName == full_name)
            {
                skip = true;
            }

            if (!skip)
            {
                GameMapName = full_name;

                PrevMapThread         = SetMapThread;
                SetMapThread          = new Thread(() => SetMapThreadFunc(GameMapName));
                SetMapThread.Priority = ThreadPriority.Highest;
                SetMapThread.Start();
            }

            if (SteamMatches.IsLobbyOwner())
            {
                string current = SteamMatches.GetLobbyData("MapName");
                string name    = map_name;

                if (name.Length > 0 && name.Contains(".m3n"))
                {
                    name = name.Substring(0, name.Length - 4);
                }

                if (current != map_name)
                {
                    SteamMatches.SetLobbyData("MapName", name);
                    SetLobbyInfo();
                }
            }
        }
Exemple #9
0
        void Test_OnJoinLobby(bool result)
        {
            Console.WriteLine(result);

            Console.WriteLine(SteamMatches.GetLobbyData("name"));
        }