internal ArchiWebHandler(Bot bot) {
			if (bot == null) {
				throw new ArgumentNullException(nameof(bot));
			}

			Bot = bot;

			WebBrowser = new WebBrowser(bot.ArchiLogger);
		}
		internal ArchiWebHandler(Bot bot) {
			if (bot == null) {
				throw new ArgumentNullException("bot");
			}

			Bot = bot;

			WebBrowser = new WebBrowser(bot.BotName);
		}
示例#3
0
		private static void InitServices() {
			GlobalConfig = GlobalConfig.Load(Path.Combine(ConfigDirectory, GlobalConfigFile));
			if (GlobalConfig == null) {
				Logging.LogGenericError("Global config could not be loaded, please make sure that ASF.json exists and is valid!");
				Thread.Sleep(5000);
				Exit(1);
			}

			GlobalDatabase = GlobalDatabase.Load(Path.Combine(ConfigDirectory, GlobalDatabaseFile));
			if (GlobalDatabase == null) {
				Logging.LogGenericError("Global database could not be loaded!");
				Thread.Sleep(5000);
				Exit(1);
			}

			ArchiWebHandler.Init();
			WebBrowser.Init();
			WCF.Init();

			WebBrowser = new WebBrowser("Main");
		}
示例#4
0
		private static void InitServices() {
			string globalConfigFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalConfigFileName);

			GlobalConfig = GlobalConfig.Load(globalConfigFile);
			if (GlobalConfig == null) {
				Logging.LogGenericError("Global config could not be loaded, please make sure that " + globalConfigFile + " exists and is valid!");
				Thread.Sleep(5000);
				Exit(1);
			}

			string globalDatabaseFile = Path.Combine(SharedInfo.ConfigDirectory, SharedInfo.GlobalDatabaseFileName);

			GlobalDatabase = GlobalDatabase.Load(globalDatabaseFile);
			if (GlobalDatabase == null) {
				Logging.LogGenericError("Global database could not be loaded, if issue persists, please remove " + globalDatabaseFile + " in order to recreate database!");
				Thread.Sleep(5000);
				Exit(1);
			}

			ArchiWebHandler.Init();
			WebBrowser.Init();
			WCF.Init();

			WebBrowser = new WebBrowser(SharedInfo.ASF);
		}
示例#5
0
        internal async Task <bool> SendTradeOffer(List <SteamItem> inventory, ulong partnerID, string token = null)
        {
            if (inventory == null || inventory.Count == 0 || partnerID == 0)
            {
                return(false);
            }

            string sessionID;

            if (!Cookie.TryGetValue("sessionid", out sessionID))
            {
                return(false);
            }

            List <SteamTradeOfferRequest> trades = new List <SteamTradeOfferRequest>(1 + inventory.Count / Trading.MaxItemsPerTrade);

            SteamTradeOfferRequest singleTrade = null;

            for (ushort i = 0; i < inventory.Count; i++)
            {
                if (i % Trading.MaxItemsPerTrade == 0)
                {
                    if (trades.Count >= Trading.MaxTradesPerAccount)
                    {
                        break;
                    }

                    singleTrade = new SteamTradeOfferRequest();
                    trades.Add(singleTrade);
                }

                SteamItem item = inventory[i];
                singleTrade.me.assets.Add(new SteamItem()
                {
                    appid     = "753",
                    contextid = "6",
                    amount    = item.amount,
                    assetid   = item.id
                });
            }

            string referer = "https://steamcommunity.com/tradeoffer/new";
            string request = referer + "/send";

            foreach (SteamTradeOfferRequest trade in trades)
            {
                Dictionary <string, string> data = new Dictionary <string, string>(6)
                {
                    { "sessionid", sessionID },
                    { "serverid", "1" },
                    { "partner", partnerID.ToString() },
                    { "tradeoffermessage", "Sent by ASF" },
                    { "json_tradeoffer", JsonConvert.SerializeObject(trade) },
                    { "trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : string.Format("{{ \"trade_offer_access_token\":\"{0}\" }}", token) }                   // TODO: This should be rewrote
                };

                HttpResponseMessage response = null;
                for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
                {
                    response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
                }

                if (response == null)
                {
                    Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                    return(false);
                }
            }

            return(true);
        }
示例#6
0
        private static async Task InitGlobalDatabaseAndServices()
        {
            string globalDatabaseFile = ASF.GetFilePath(ASF.EFileType.Database);

            if (string.IsNullOrEmpty(globalDatabaseFile))
            {
                ASF.ArchiLogger.LogNullError(nameof(globalDatabaseFile));

                return;
            }

            if (!File.Exists(globalDatabaseFile))
            {
                ASF.ArchiLogger.LogGenericInfo(Strings.Welcome);
                await Task.Delay(10 * 1000).ConfigureAwait(false);

                ASF.ArchiLogger.LogGenericWarning(Strings.WarningPrivacyPolicy);
                await Task.Delay(5 * 1000).ConfigureAwait(false);
            }

            GlobalDatabase globalDatabase = await GlobalDatabase.CreateOrLoad(globalDatabaseFile).ConfigureAwait(false);

            if (globalDatabase == null)
            {
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.ErrorDatabaseInvalid, globalDatabaseFile));
                await Task.Delay(5 * 1000).ConfigureAwait(false);
                await Exit(1).ConfigureAwait(false);

                return;
            }

            ASF.InitGlobalDatabase(globalDatabase);

            // If debugging is on, we prepare debug directory prior to running
            if (Debugging.IsUserDebugging)
            {
                if (Debugging.IsDebugConfigured)
                {
                    ASF.ArchiLogger.LogGenericDebug(globalDatabaseFile + ": " + JsonConvert.SerializeObject(ASF.GlobalDatabase, Formatting.Indented));
                }

                Logging.EnableTraceLogging();

                if (Debugging.IsDebugConfigured)
                {
                    DebugLog.AddListener(new Debugging.DebugListener());
                    DebugLog.Enabled = true;

                    if (Directory.Exists(SharedInfo.DebugDirectory))
                    {
                        try {
                            Directory.Delete(SharedInfo.DebugDirectory, true);
                            await Task.Delay(1000).ConfigureAwait(false);                             // Dirty workaround giving Windows some time to sync
                        } catch (Exception e) {
                            ASF.ArchiLogger.LogGenericException(e);
                        }
                    }
                }

                try {
                    Directory.CreateDirectory(SharedInfo.DebugDirectory);
                } catch (Exception e) {
                    ASF.ArchiLogger.LogGenericException(e);
                }
            }

            WebBrowser.Init();
        }