コード例 #1
0
        /// <summary>
        /// Updates the names of games
        /// </summary>
        /// <param name="listOfIds">A list of the ids of the game</param>
        /// <returns>Were there any games that need to be updated</returns>
        public static bool UpdateGameNames(List <ulong> listOfIds)
        {
            if (Program.HostId == 0)
            {
                Console.Clear();
                UpdateHostId();
                Thread.Sleep(1000);

                Console.Clear();
                Console.WriteLine("Server IP: " + Program.IpAddress + "      Port: " + Program.Port + "       HostId: " +
                                  Program.HostId);
                Console.WriteLine();
            }

            if (Program.SteamToken == null)
            {
                UpdateSteamToken();
            }

            // If we have not been given any ids then get some from the server
            if (listOfIds == null)
            {
                Console.WriteLine("Getting the game ids we need to check from the server");
                listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2007).Data)).List;
            }

            // Exit if we have no id's
            if (listOfIds.Count == 0)
            {
                Console.WriteLine("No games to update");
                return(false);
            }

            Console.WriteLine("List received of length " + listOfIds.Count);

            var list = new List <GameHistory>();

            foreach (var listOfId in listOfIds)
            {
                var uri =
                    "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + Program.SteamToken +
                    "&steamid=" + listOfId
                    + "&include_played_free_games=1&include_appinfo=1&format=xml";

                Console.WriteLine("Getting the information from steam");
                try
                {
                    var s = new XmlReaderSettings {
                        DtdProcessing = DtdProcessing.Ignore
                    };
                    var r = XmlReader.Create(uri, s);

                    var temp = new GameHistory();

                    while (r.Read())
                    {
                        switch (r.NodeType)
                        {
                        case XmlNodeType.Element:
                            switch (r.Name)
                            {
                            case "appid":
                                r.Read();
                                temp       = new GameHistory();
                                temp.AppId = Convert.ToInt32(r.Value);
                                break;

                            case "name":
                                r.Read();
                                temp.Name = r.Value;
                                list.Add(temp);
                                continue;
                            }
                            break;
                        }
                    }

                    list.Add(temp);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.WriteLine("Sending the information back to the server");

            CustomSocket.StartClient(new ListOfGames(list, Program.HostId, 3007).Data);

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Get the steam ids from the server then check their summaries
        /// </summary>
        public static bool UpdatePlayerSum(List <ulong> listOfIds)
        {
            if (Program.HostId == 0)
            {
                Console.Clear();
                UpdateHostId();
                Thread.Sleep(1000);

                Console.Clear();
                Console.WriteLine("Server IP: " + Program.IpAddress + "      Port: " + Program.Port + "       HostId: " +
                                  Program.HostId);
                Console.WriteLine();
            }

            if (Program.SteamToken == null)
            {
                UpdateSteamToken();
            }

            // If we have not been given any ids then get some from the server
            if (listOfIds == null)
            {
                Console.WriteLine("Getting the steam ids we need to check from the server");
                listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2003).Data)).List;
            }

            // Exit if we have no id's
            if (listOfIds.Count == 0)
            {
                Console.WriteLine("No summaries to update");
                return(false);
            }

            Console.WriteLine("List received of length " + listOfIds.Count);
            var uri =
                "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=" + Program.SteamToken +
                "&steamids=" + listOfIds[0];

            for (var i = 1; i < listOfIds.Count; i++)
            {
                uri += "," + listOfIds[i];
            }
            uri += "&format=xml";

            Console.WriteLine("Getting the information from steam");

            var people = new List <User>();

            try
            {
                var s = new XmlReaderSettings {
                    DtdProcessing = DtdProcessing.Ignore
                };
                var r = XmlReader.Create(uri, s);
                while (r.Read())
                {
                    switch (r.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (r.Name)
                        {
                        case "player":
                            r.Read();
                            people.Add(new User());
                            people[people.Count - 1].LastSummaryUpdate = DateTime.Now;
                            break;

                        case "steamid":
                            r.Read();
                            people[people.Count - 1].SteamId = UInt64.Parse(r.Value);
                            break;

                        case "communityvisibilitystate":
                            r.Read();
                            var v = r.Value == "3";
                            people[people.Count - 1].VisibilityState = v;
                            break;

                        case "personaname":
                            r.Read();
                            people[people.Count - 1].UserName = r.Value;
                            break;

                        case "lastlogoff":
                            r.Read();
                            people[people.Count - 1].LastLogOff =
                                new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value));
                            break;

                        case "profileurl":
                            r.Read();
                            people[people.Count - 1].CustomUrl = r.Value.Split('/')[3] == "id"
                                        ? r.Value.Split('/')[4]
                                        : "/";
                            break;

                        case "realname":
                            r.Read();
                            people[people.Count - 1].RealName = r.Value;
                            break;

                        case "primaryclanid":
                            r.Read();
                            people[people.Count - 1].PrimaryClanId = UInt64.Parse(r.Value);
                            break;

                        case "timecreated":
                            r.Read();
                            people[people.Count - 1].MemberSince =
                                new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value));
                            break;

                        case "loccountrycode":
                            r.Read();
                            people[people.Count - 1].Location = r.Value;
                            break;
                        }
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                people.RemoveAt(people.Count - 1);
            }

            Console.WriteLine("Sending the information back to the server");

            CustomSocket.StartClient(new ListOfUsers(people, Program.HostId, 3003).Data);

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// Updates a list of players friends
        /// </summary>
        /// <param name="listOfIds">A list of players, can be null</param>
        /// <returns>Were there any from the server</returns>
        public static bool UpdatePlayerFriends(List <ulong> listOfIds)
        {
            if (Program.HostId == 0)
            {
                Console.Clear();
                UpdateHostId();
                Thread.Sleep(1000);

                Console.Clear();
                Console.WriteLine("Server IP: " + Program.IpAddress + "      Port: " + Program.Port + "       HostId: " +
                                  Program.HostId);
                Console.WriteLine();
            }

            if (Program.SteamToken == null)
            {
                UpdateSteamToken();
            }

            // If we have not been given any ids then get some from the server
            if (listOfIds == null)
            {
                Console.WriteLine("Getting the steam ids we need to check from the server");
                listOfIds = new ListOfId(CustomSocket.StartClient(new StdData("", Program.HostId, 2006).Data)).List;
            }

            // Exit if we have no id's
            if (listOfIds.Count == 0)
            {
                Console.WriteLine("No users to update");
                return(false);
            }

            Console.WriteLine("List received of length " + listOfIds.Count);

            var list = new List <User>();

            foreach (var listOfId in listOfIds)
            {
                var uri =
                    "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key=" + Program.SteamToken +
                    "&steamid=" + listOfId
                    + "&relationship=friend&format=xml";

                Console.WriteLine("Getting the information from steam");
                try
                {
                    var s = new XmlReaderSettings {
                        DtdProcessing = DtdProcessing.Ignore
                    };
                    var r = XmlReader.Create(uri, s);

                    var temp = new User {
                        SteamId = listOfId, LastFriendUpdate = DateTime.Now
                    };

                    var tempFriend = new Friend();

                    while (r.Read())
                    {
                        switch (r.NodeType)
                        {
                        case XmlNodeType.Element:
                            switch (r.Name)
                            {
                            case "steamid":
                                r.Read();
                                tempFriend = new Friend {
                                    SteamId = Convert.ToUInt64(r.Value)
                                };
                                break;

                            case "friend_since":
                                r.Read();
                                tempFriend.TimeStamp = new DateTime(1970, 1, 1).AddSeconds(double.Parse(r.Value));
                                break;
                            }
                            break;

                        case XmlNodeType.EndElement:
                            switch (r.Name)
                            {
                            case "friend":
                                temp.ListOfFriends.Add(tempFriend);
                                break;
                            }
                            break;
                        }
                    }

                    list.Add(temp);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.WriteLine("Sending the information back to the server");

            CustomSocket.StartClient(new ListOfUsers(list, Program.HostId, 3006).Data);

            return(true);
        }