Пример #1
0
        public static PublishedFileDetailsResponse GetSteamModDetails(List <string> modIdList)
        {
            const int MAX_IDS = 20;

            PublishedFileDetailsResponse response = null;

            try
            {
                if (modIdList.Count == 0)
                {
                    return(new PublishedFileDetailsResponse());
                }

                modIdList = ModUtils.ValidateModList(modIdList);

                int remainder;
                var totalRequests = Math.DivRem(modIdList.Count, MAX_IDS, out remainder);
                if (remainder > 0)
                {
                    totalRequests++;
                }

                var requestIndex = 0;
                while (requestIndex < totalRequests)
                {
                    var count    = 0;
                    var postData = "";
                    for (var index = requestIndex * MAX_IDS; count < MAX_IDS && index < modIdList.Count; index++)
                    {
                        postData += $"&publishedfileids[{count}]={modIdList[index]}";
                        count++;
                    }

                    postData = $"key={SteamWebApiKey}&format=json&itemcount={count}{postData}";

                    var data = Encoding.ASCII.GetBytes(postData);

                    var httpRequest = WebRequest.Create("https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/");
                    httpRequest.Timeout       = 30000;
                    httpRequest.Method        = "POST";
                    httpRequest.ContentType   = "application/x-www-form-urlencoded";
                    httpRequest.ContentLength = data.Length;

                    using (var stream = httpRequest.GetRequestStream())
                    {
                        stream.Write(data, 0, data.Length);
                    }

                    var httpResponse   = (HttpWebResponse)httpRequest.GetResponse();
                    var responseString = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();

                    var result = JsonUtils.Deserialize <PublishedFileDetailsResult>(responseString);
                    if (result != null && result.response != null)
                    {
                        if (response == null)
                        {
                            response = result.response;
                        }
                        else
                        {
                            response.resultcount += result.response.resultcount;
                            response.publishedfiledetails.AddRange(result.response.publishedfiledetails);
                        }
                    }

                    requestIndex++;
                }
                ;

                return(response ?? new PublishedFileDetailsResponse());
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"ERROR: {nameof(GetSteamModDetails)}\r\n{ex.Message}");
                return(null);
            }
        }
Пример #2
0
        public static SteamUserDetailResponse GetSteamUserDetails(List <string> steamIdList)
        {
            const int MAX_IDS = 100;

            SteamUserDetailResponse response = null;

            try
            {
                if (steamIdList.Count == 0)
                {
                    return(new SteamUserDetailResponse());
                }

                steamIdList = steamIdList.Distinct().ToList();

                int remainder;
                var totalRequests = Math.DivRem(steamIdList.Count, MAX_IDS, out remainder);
                if (remainder > 0)
                {
                    totalRequests++;
                }

                var requestIndex = 0;
                while (requestIndex < totalRequests)
                {
                    var count     = 0;
                    var postData  = "";
                    var delimiter = "";
                    for (var index = requestIndex * MAX_IDS; count < MAX_IDS && index < steamIdList.Count; index++)
                    {
                        postData += $"{delimiter}{steamIdList[index]}";
                        delimiter = ",";
                        count++;
                    }

                    var httpRequest = WebRequest.Create($"https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key={SteamWebApiKey}&format=json&steamids={postData}");
                    httpRequest.Timeout = 30000;
                    var httpResponse   = (HttpWebResponse)httpRequest.GetResponse();
                    var responseString = new StreamReader(httpResponse.GetResponseStream()).ReadToEnd();

                    var result = JsonUtils.Deserialize <SteamUserDetailResult>(responseString);
                    if (result != null && result.response != null)
                    {
                        if (response == null)
                        {
                            response = result.response;
                        }
                        else
                        {
                            response.players.AddRange(result.response.players);
                        }
                    }

                    requestIndex++;
                }

                return(response ?? new SteamUserDetailResponse());
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"ERROR: {nameof(GetSteamUserDetails)}\r\n{ex.Message}");
                return(null);
            }
        }