public MarketClient(SteamMarketHandler steam)
 {
     this.steam      = steam;
     this.Games      = new AvailableGames(this.steam);
     this.Currencies =
         JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties.Resources.Currencies);
 }
Example #2
0
        public SteamManager(
            string login,
            string password,
            SteamGuardAccount mafile,
            string apiKey,
            bool forceSessionRefresh = false)
        {
            this.Guard       = mafile;
            this.SteamClient = new UserLogin(login, password)
            {
                TwoFactorCode = this.GenerateSteamGuardCode()
            };
            this.Guard.DeviceID = this.GetDeviceId();
            var isSessionRefreshed = this.Guard.RefreshSession();

            if (isSessionRefreshed == false || forceSessionRefresh)
            {
                Logger.Debug($"Saved steam session for {login} is expired. Refreshing session.");
                LoginResult loginResult;
                var         tryCount = 0;
                do
                {
                    loginResult = this.SteamClient.DoLogin();
                    if (loginResult == LoginResult.LoginOkay)
                    {
                        continue;
                    }

                    Logger.Warning($"Login status is - {loginResult}");

                    if (++tryCount == 3)
                    {
                        throw new WebException("Login failed after 3 attempts!");
                    }

                    Thread.Sleep(3000);
                }while (loginResult != LoginResult.LoginOkay);

                this.Guard.Session = this.SteamClient.Session;
                this.SaveAccount(this.Guard);
            }

            this.ApiKey = apiKey;

            this.TradeOfferWeb = new TradeOfferWebApi(apiKey);
            this.OfferSession  = new OfferSession(this.TradeOfferWeb, this.Cookies, this.Guard.Session.SessionID);
            this.Guard.Session.AddCookies(this.Cookies);
            var market = new SteamMarketHandler(ELanguage.English, "user-agent");
            var auth   = new Auth(market, this.Cookies)
            {
                IsAuthorized = true
            };

            this.FetchTradeToken();
            market.Auth       = auth;
            this.MarketClient = new MarketClient(market);
            this.Inventory    = new Inventory();
        }
 public CounterStrikeGlobalOffensive(SteamMarketHandler steam)
 {
     _steam = steam;
 }
 public MarketClient(SteamMarketHandler steam, WebProxy proxy = null)
 {
     this.steam = steam;
     this.Games = new AvailableGames(this.steam);
     this.Proxy = proxy;
 }
 public AvailableGames(SteamMarketHandler steam)
 {
     this.CounterStrikeGlobalOffensive = new CounterStrikeGlobalOffensive(steam);
 }
Example #6
0
        public SteamManager(
            string login,
            string password,
            SteamGuardAccount mafile,
            string apiKey            = null,
            string tradeToken        = null,
            int?currency             = null,
            string userAgent         = "",
            bool forceSessionRefresh = false,
            string proxyString       = null)
        {
            if (!File.Exists("license.txt"))
            {
                throw new UnauthorizedAccessException("Cant get required info");
            }

            if (proxyString != null)
            {
                this.Proxy = WebUtils.ParseProxy(proxyString);
            }

            LicenseKey = File.ReadAllText("license.txt").Trim('\n', '\r', ' ');
            HwId       = GetHwid();

            this.Login       = login;
            this.Password    = password;
            this.Guard       = mafile;
            this.Guard.Proxy = this.Proxy;
            this.SteamId     = new SteamID(this.Guard.Session.SteamID);

            Logger.Log.Debug("Fetching two factor token..");
            var twoFactorCode = this.GenerateSteamGuardCode();

            Logger.Log.Debug($"Two factor token is - {twoFactorCode}");

            this.SteamClient = new UserLogin(login, password)
            {
                TwoFactorCode = twoFactorCode
            };

            Logger.Log.Debug("Checking session status..");
            var isSessionRefreshed = this.Guard.RefreshSession();

            if (isSessionRefreshed == false || forceSessionRefresh)
            {
                this.UpdateSteamSession();
            }

            this.Guard.Session.AddCookies(this.Cookies);

            if (forceSessionRefresh)
            {
                this.ApiKey     = this.FetchApiKey();
                this.TradeToken = this.FetchTradeToken();
            }
            else
            {
                this.ApiKey     = apiKey ?? this.FetchApiKey();
                this.TradeToken = tradeToken ?? this.FetchTradeToken();
            }

            this.Inventory = new Inventory(this.Proxy);

            Logger.Log.Debug("Initializing TradeOfferWebApi..");
            this.TradeOfferWeb = new TradeOfferWebApi(this.ApiKey, this.Proxy);

            Logger.Log.Debug("Initializing OfferSession..");
            this.OfferSession = new OfferSession(
                this.TradeOfferWeb,
                this.Cookies,
                this.Guard.Session.SessionID,
                this.Proxy);

            Logger.Log.Debug("Initializing SteamMarketHandler..");
            var market = new SteamMarketHandler(ELanguage.English, userAgent);
            var auth   = new Market.Auth(market, this.Cookies)
            {
                IsAuthorized = true
            };

            market.Auth = auth;

            Logger.Log.Debug("Initializing SteamMarketHandler..");
            this.MarketClient = new MarketClient(market, this.Proxy);

            if (forceSessionRefresh)
            {
                this.Currency = this.FetchCurrency();
            }
            else
            {
                this.Currency = currency ?? this.FetchCurrency();
            }

            this.MarketClient.CurrentCurrency = this.Currency;

            Logger.Log.Debug("SteamManager was successfully initialized");
        }