Esempio n. 1
0
        private void CheckAuth()
        {
            buEnter.Text    = "Проверка";
            buEnter.Enabled = false;
            Thread t = new Thread(() =>
            {
                string steamLogin = "";
                //Check
                if (Settings.Default.sessionid != "")
                {
                    HttpWebRequest request = RqstHelper.RequestCreate(SteamLinks.STEAM);
                    CookieCollection c     = new CookieCollection();
                    c.Add(new Cookie("sessionid", Settings.Default.sessionid));
                    c.Add(new Cookie("steamLogin", Settings.Default.steamLogin));
                    c.Add(new Cookie("steamCountry", Settings.Default.steamCountry));
                    request.CookieContainer.Add(new Uri(SteamLinks.STEAM), c);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    string html = RqstHelper.ResponseGetPage(response);
                    html        = html.Substring(html.IndexOf(">", html.IndexOf("pulldown global_action_link")) + 1);
                    steamLogin  = html.Substring(0, html.IndexOf("<"));
                }

                this.Invoke((MethodInvoker) delegate
                {
                    buEnter.Enabled = true;
                    if (steamLogin == "")
                    {
                        buEnter.Text            = "Войти в Steam";
                        buGetGames.Enabled      = false;
                        buGetItems.Enabled      = false;
                        buGetPrices.Enabled     = false;
                        buCalculateShow.Enabled = false;
                    }
                    else
                    {
                        laStatus.Text      = "Вход выполнен";
                        buEnter.Text       = steamLogin + " (перезайти)";
                        buGetGames.Enabled = true;
                        CheckGames();
                    }
                });
            });

            Threads.Add(t);
            t.Start();
        }         // Complite
Esempio n. 2
0
        }         // Complite

        private void buGetGames_Click(object sender, EventArgs e)
        {
            buGetGames.Text    = "Проверка";
            buEnter.Enabled    = false;
            buGetGames.Enabled = false;
            Thread t = new Thread(() =>
            {
                HttpWebRequest request = RqstHelper.RequestCreate(SteamLinks.BOOSTERCREATOR);
                CookieCollection c     = new CookieCollection();
                c.Add(new Cookie("sessionid", Settings.Default.sessionid));
                c.Add(new Cookie("steamLogin", Settings.Default.steamLogin));
                c.Add(new Cookie("steamCountry", Settings.Default.steamCountry));
                c.Add(new Cookie("steamparental", Settings.Default.steamparental));
                request.CookieContainer.Add(new Uri(SteamLinks.BOOSTERCREATOR), c);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                string html      = RqstHelper.ResponseGetPage(response);
                string gamesJson = "";
                try
                {
                    gamesJson = html.Substring(html.IndexOf("CBoosterCreatorPage.Init("));
                    gamesJson = gamesJson.Substring(gamesJson.IndexOf("["));
                    gamesJson = gamesJson.Substring(0, gamesJson.IndexOf("]"));
                }
                catch (Exception ex)
                {
                    File.AppendAllText("SCCC_log.txt",
                                       html + "\r\n" +
                                       gamesJson + "\r\n" +
                                       ex.Message + "\r\n");
                }
                Settings.Default.games           = gamesJson;
                Settings.Default.gamesLastUpdate = DateTime.Now;
                Settings.Default.Save();

                this.Invoke((MethodInvoker) delegate
                {
                    CheckGames();
                    buGetGames.Enabled = true;
                });
            });

            Threads.Add(t);
            t.Start();
        }
Esempio n. 3
0
        private void GetPriceThread(object obj)
        {
            (obj as Item).priceStatus = 1;
            Item it = obj as Item;

            try
            {
                HttpWebRequest requestC = RqstHelper.RequestCreate(
                    SteamLinks.PRICE.Replace("%HASHNAME%", it.hashname));
                HttpWebResponse responseC = (HttpWebResponse)requestC.GetResponse();
                string          hC        = RqstHelper.ResponseGetPage(responseC);

                string success = JsonHelper.GetValueFromJSON(hC, "success");
                if (success == "true")
                {
                    string lowestStr = JsonHelper.GetValueFromJSON(hC, "lowest_price", "0,0 p");
                    // 15 | 15,01 | 15,1
                    string medianStr = JsonHelper.GetValueFromJSON(hC, "median_price", "0,0 p");
                    string volumeStr = JsonHelper.GetValueFromJSON(hC, "volume", "0");

                    lowestStr = lowestStr.Substring(0, lowestStr.IndexOf(" p"));
                    medianStr = medianStr.Substring(0, medianStr.IndexOf(" p"));

                    int low = 0;
                    if (!lowestStr.Contains(","))
                    {
                        low = int.Parse(lowestStr) * 100;
                    }
                    else
                    {
                        if (lowestStr.Substring(lowestStr.IndexOf(",")).Length == 1)
                        {
                            low = int.Parse(lowestStr.Replace(",", "")) * 10;
                        }
                        else
                        {
                            low = int.Parse(lowestStr.Replace(",", ""));
                        }
                    }

                    int med = 0;
                    if (!medianStr.Contains(","))
                    {
                        med = int.Parse(medianStr) * 100;
                    }
                    else
                    {
                        if (medianStr.Substring(medianStr.IndexOf(",")).Length == 1)
                        {
                            med = int.Parse(medianStr.Replace(",", "")) * 10;
                        }
                        else
                        {
                            med = int.Parse(medianStr.Replace(",", ""));
                        }
                    }

                    int vol = int.Parse(volumeStr.Replace(",", ""));

                    it.lowest_price = low;
                    it.median_price = med;
                    it.volume       = vol;
                }

                //getted
                it.priceStatus = 2;

                this.Invoke((MethodInvoker) delegate
                {
                    SetGamePriceReceived(it.appid);
                    CheckReceivedPrices();
                });
            }
            catch (Exception ex)
            {
                try
                {
                    MarketReady = false;
                    this.Invoke((MethodInvoker) delegate
                    {
                        it.priceStatus      = 0;
                        tiGetPrices.Enabled = false;
                        tiGetPrices.Start();
                        tiBeforeGetPrices.Tag     = tiGetPrices.Interval / 1000;
                        tiBeforeGetPrices.Enabled = false;
                        tiBeforeGetPrices.Start();
                        laStatus.Text = "Загружены цены для " + Items.Count(f => f.priceStatus == 2)
                                        + " предметов(-а). \nСервер прекратил выдавать результаты с ошибкой:\n" + ex.Message
                                        + "\nДо возобновления получения предметов " + (tiGetItems.Interval / 1000) + " секунд.";
                    });
                }
                catch { }
            }
        }
Esempio n. 4
0
        private void GetItems()
        {
            Thread ti = new Thread(() =>
            {
                this.Invoke((MethodInvoker) delegate
                {
                    laStatus.Text = "Получение предметов";
                });
                if (MarketReady)
                {
                    Thread.Sleep(1000);
                    Thread t = new Thread((object obj) =>
                    {
                        (obj as Game).itemsStatus = 1;
                        Game g = obj as Game;

                        try
                        {
                            //get cards
                            {
                                HttpWebRequest request = RqstHelper.RequestCreate(SteamLinks.CARDS.Replace("%APPID%", g.appid.ToString()));
                                CookieCollection c     = new CookieCollection();
                                c.Add(new Cookie("sessionid", Settings.Default.sessionid));
                                c.Add(new Cookie("steamLogin", Settings.Default.steamLogin));
                                c.Add(new Cookie("steamCountry", Settings.Default.steamCountry));
                                request.CookieContainer.Add(new Uri(SteamLinks.CARDS.Replace("%APPID%", g.appid.ToString())), c);
                                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                                string html = RqstHelper.ResponseGetPage(response);

                                while (html.Contains(BeforeHashName))
                                {
                                    html            = html.Substring(html.IndexOf(BeforeHashName) + BeforeHashName.Length);
                                    string hashName = html.Substring(0, html.IndexOf("\\\""));
                                    Items.Add(new Item(g.appid, 0, hashName));
                                }
                            }
                            //get cardpack
                            {
                                HttpWebRequest request = RqstHelper.RequestCreate(SteamLinks.CARDPACK.Replace("%APPID%", g.appid.ToString()));
                                CookieCollection c     = new CookieCollection();
                                c.Add(new Cookie("sessionid", Settings.Default.sessionid));
                                c.Add(new Cookie("steamLogin", Settings.Default.steamLogin));
                                c.Add(new Cookie("steamCountry", Settings.Default.steamCountry));
                                request.CookieContainer.Add(new Uri(SteamLinks.CARDPACK.Replace("%APPID%", g.appid.ToString())), c);
                                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                                string html = RqstHelper.ResponseGetPage(response);

                                while (html.Contains(BeforeHashName))
                                {
                                    html            = html.Substring(html.IndexOf(BeforeHashName) + BeforeHashName.Length);
                                    string hashName = html.Substring(0, html.IndexOf("\\\""));
                                    Items.Add(new Item(g.appid, 1, hashName));
                                }
                            }

                            //getted
                            g.itemsStatus = 2;

                            this.Invoke((MethodInvoker) delegate
                            {
                                CheckReceivedItems();
                            });
                        }
                        catch (Exception ex)
                        {
                            if (ex is WebException)
                            {
                                MarketReady = false;
                                this.Invoke((MethodInvoker) delegate
                                {
                                    g.itemsStatus      = 0;
                                    tiGetItems.Enabled = false;
                                    tiGetItems.Start();
                                    tiBeforeGetItems.Tag     = tiGetItems.Interval / 1000;
                                    tiBeforeGetItems.Enabled = false;
                                    tiBeforeGetItems.Start();
                                    laStatus.Text = "Загружены карточки для " + Games.Count(f => f.itemsStatus == 2)
                                                    + " игр(-ы). \nСервер прекратил выдавать результаты с ошибкой:\n" + ex.Message
                                                    + "\nДо возобновления получения предметов " + (tiGetItems.Interval / 1000) + " секунд.";
                                });
                            }
                        }
                    });
                    Threads.Add(t);
                    if (Games.Count(f => f.itemsStatus == 0) > 0)
                    {
                        t.Start(Games.Where(f => f.itemsStatus == 0).First());
                    }

                    if (Games.Count(f => f.itemsStatus == 0) > 0)
                    {
                        GetItems();
                    }
                }
            });

            Threads.Add(ti);
            ti.Start();
        }