コード例 #1
0
        public async Task <Confirmation[]> FetchConfirmationsAsync()
        {
            string url = this.GenerateConfirmationURL();

            CookieContainer cookies = new CookieContainer();

            this.Session.AddCookies(cookies);

            string response = await SteamWeb.RequestAsync(url, "GET", null, cookies);

            /*So you're going to see this abomination and you're going to be upset.
             * It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library.
             * And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings.
             * I'm sorry. */

            Regex confIDKeyRegex = new Regex("<div class=\"mobileconf_list_entry\" id=\"conf\\d+\" data-confid=\"(\\d+)\" data-key=\"(\\d+)\"");
            Regex confDescRegex  = new Regex("<div>((Confirm|Trade with|Sell -) .+)</div>");

            if (response == null || !(confIDKeyRegex.IsMatch(response) && confDescRegex.IsMatch(response)))
            {
                if (response == null || !response.Contains("<div>Nothing to confirm</div>"))
                {
                    throw new WGTokenInvalidException();
                }

                return(new Confirmation[0]);
            }

            MatchCollection confIDKeys = confIDKeyRegex.Matches(response);
            MatchCollection confDescs  = confDescRegex.Matches(response);

            List <Confirmation> ret = new List <Confirmation>();

            for (int i = 0; i < confIDKeys.Count; i++)
            {
                string       confID   = confIDKeys[i].Groups[1].Value;
                string       confKey  = confIDKeys[i].Groups[2].Value;
                string       confDesc = confDescs[i].Groups[1].Value;
                Confirmation conf     = new Confirmation()
                {
                    Description = confDesc,
                    ID          = confID,
                    Key         = confKey
                };
                ret.Add(conf);
            }

            return(ret.ToArray());
        }
コード例 #2
0
        private void listAccounts_SelectedValueChanged(object sender, EventArgs e)
        {
            mCurrentConfirmation = null;

            if (listConfirmations.SelectedIndex == -1) return;

            // Triggered when list item is clicked
            for (int i = 0; i < Confirmations.Length; i++)
            {
                if (Confirmations[i].ConfirmationDescription == (string)listConfirmations.Items[listConfirmations.SelectedIndex])
                {
                    mCurrentConfirmation = Confirmations[i];
                }
            }
            btnDenyConfirmation.Enabled = btnAcceptConfirmation.Enabled = mCurrentConfirmation != null;
        }
コード例 #3
0
        public long GetConfirmationTradeOfferID(Confirmation conf)
        {
            var confDetails = _getConfirmationDetails(conf);

            if (confDetails == null || !confDetails.Success)
            {
                return(-1);
            }

            Regex tradeOfferIDRegex = new Regex("<div class=\"tradeoffer\" id=\"tradeofferid_(\\d+)\" >");

            if (!tradeOfferIDRegex.IsMatch(confDetails.HTML))
            {
                return(-1);
            }
            return(long.Parse(tradeOfferIDRegex.Match(confDetails.HTML).Groups[1].Value));
        }
コード例 #4
0
ファイル: SteamGuardAccount.cs プロジェクト: geri43/SteamAuth
        public Confirmation[] FetchConfirmations()
        {
            string url = this._generateConfirmationURL();

            CookieContainer cookies = new CookieContainer();

            this.Session.AddCookies(cookies);

            string response = SteamWeb.Request(url, "GET", null, cookies);

            /*So you're going to see this abomination and you're going to be upset.
             * It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library.
             * And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings.
             * I'm sorry. */

            Regex confIDRegex   = new Regex("data-confid=\"(\\d+)\"");
            Regex confKeyRegex  = new Regex("data-key=\"(\\d+)\"");
            Regex confDescRegex = new Regex("<div>((Confirm|Trade with|Sell -) .+)</div>");

            if (!(confIDRegex.IsMatch(response) && confKeyRegex.IsMatch(response) && confDescRegex.IsMatch(response)))
            {
                return(new Confirmation[0]);
            }

            MatchCollection confIDs   = confIDRegex.Matches(response);
            MatchCollection confKeys  = confKeyRegex.Matches(response);
            MatchCollection confDescs = confDescRegex.Matches(response);

            List <Confirmation> ret = new List <Confirmation>();

            for (int i = 0; i < confIDs.Count; i++)
            {
                string       confID   = confIDs[i].Groups[1].Value;
                string       confKey  = confKeys[i].Groups[1].Value;
                string       confDesc = confDescs[i].Groups[1].Value;
                Confirmation conf     = new Confirmation()
                {
                    ConfirmationDescription = confDesc,
                    ConfirmationID          = confID,
                    ConfirmationKey         = confKey
                };
                ret.Add(conf);
            }

            return(ret.ToArray());
        }
コード例 #5
0
        private bool _sendConfirmationAjax(Confirmation conf, string op)
        {
            string url         = APIEndpoints.COMMUNITY_BASE + "/mobileconf/ajaxop";
            string queryString = "?op=" + op + "&";

            queryString += _generateConfirmationQueryParams(op);
            queryString += "&cid=" + conf.ConfirmationID + "&ck=" + conf.ConfirmationKey;
            url         += queryString;

            CookieContainer cookies = new CookieContainer();

            this.Session.AddCookies(cookies);
            string referer = _generateConfirmationURL();

            string response = SteamWeb.Request(url + queryString, "GET", null, cookies, null);
            SendConfirmationResponse confResponse = JsonConvert.DeserializeObject <SendConfirmationResponse>(response);

            return(confResponse.Success);
        }
コード例 #6
0
        private bool _sendConfirmationAjax(Confirmation conf, string op)
        {
            string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/ajaxop";
            string queryString = "?op=" + op + "&";
            queryString += GenerateConfirmationQueryParams(op);
            queryString += "&cid=" + conf.ConfirmationID + "&ck=" + conf.ConfirmationKey;
            url += queryString;

            CookieContainer cookies = new CookieContainer();
            this.Session.AddCookies(cookies);
            string referer = GenerateConfirmationURL();

            string response = SteamWeb.Request(url, "GET", null, cookies, null);
            if (response == null) return false;

            SendConfirmationResponse confResponse = JsonConvert.DeserializeObject<SendConfirmationResponse>(response);
            return confResponse.Success;
        }
コード例 #7
0
        private ConfirmationDetailsResponse _getConfirmationDetails(Confirmation conf)
        {
            string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/details/" + conf.ConfirmationID + "?";
            string queryString = GenerateConfirmationQueryParams("details");
            url += queryString;

            CookieContainer cookies = new CookieContainer();
            this.Session.AddCookies(cookies);
            string referer = GenerateConfirmationURL();

            string response = SteamWeb.Request(url, "GET", null, cookies, null);
            if (String.IsNullOrEmpty(response)) return null;

            var confResponse = JsonConvert.DeserializeObject<ConfirmationDetailsResponse>(response);
            if (confResponse == null) return null;
            return confResponse;
        }
コード例 #8
0
 public bool DenyConfirmation(Confirmation conf)
 {
     return _sendConfirmationAjax(conf, "cancel");
 }
コード例 #9
0
 public bool AcceptConfirmation(Confirmation conf)
 {
     return _sendConfirmationAjax(conf, "allow");
 }
コード例 #10
0
        public long GetConfirmationTradeOfferID(Confirmation conf)
        {
            var confDetails = _getConfirmationDetails(conf);
            if (confDetails == null || !confDetails.Success) return -1;

            Regex tradeOfferIDRegex = new Regex("<div class=\"tradeoffer\" id=\"tradeofferid_(\\d+)\" >");
            if(!tradeOfferIDRegex.IsMatch(confDetails.HTML)) return -1;
            return long.Parse(tradeOfferIDRegex.Match(confDetails.HTML).Groups[1].Value);
        }
コード例 #11
0
        private bool _sendMultiConfirmationAjax(Confirmation[] confs, string op)
        {
            string url = APIEndpoints.COMMUNITY_BASE + "/mobileconf/multiajaxop";

            string query = "op=" + op + "&" + GenerateConfirmationQueryParams(op);
            foreach (var conf in confs)
            {
                query += "&cid[]=" + conf.ID + "&ck[]=" + conf.Key;
            }

            CookieContainer cookies = new CookieContainer();
            this.Session.AddCookies(cookies);
            string referer = GenerateConfirmationURL();

            string response = SteamWeb.Request(url, "POST", query, cookies, null);
            if (response == null) return false;

            SendConfirmationResponse confResponse = JsonConvert.DeserializeObject<SendConfirmationResponse>(response);
            return confResponse.Success;
        }
コード例 #12
0
 public bool DenyMultipleConfirmations(Confirmation[] confs)
 {
     return _sendMultiConfirmationAjax(confs, "cancel");
 }
コード例 #13
0
 public bool AcceptMultipleConfirmations(Confirmation[] confs)
 {
     return _sendMultiConfirmationAjax(confs, "allow");
 }
コード例 #14
0
        public List<Confirmation> FetchConfirmations()
        {
            string url = this._generateConfirmationURL();

            CookieContainer cookies = new CookieContainer();
            this.Session.AddCookies(cookies);

            string response = SteamWeb.Request(url, "GET", null, cookies);

            /*So you're going to see this abomination and you're going to be upset.
              It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library.
              And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings.
              I'm sorry. */

            Regex confIDRegex = new Regex("data-confid=\"(\\d+)\"");
            Regex confKeyRegex = new Regex("data-key=\"(\\d+)\"");
            Regex confDescRegex = new Regex("<div>((Confirm|Trade with) .+)</div>");

            if (!(confIDRegex.IsMatch(response) && confKeyRegex.IsMatch(response) && confDescRegex.IsMatch(response)))
            {
                return new List<Confirmation>();
            }

            MatchCollection confIDs = confIDRegex.Matches(response);
            MatchCollection confKeys = confKeyRegex.Matches(response);
            MatchCollection confDescs = confDescRegex.Matches(response);

            List<Confirmation> ret = new List<Confirmation>();
            for (int i = 0; i < confIDs.Count; i++)
            {
                string confID = confIDs[i].Groups[1].Value;
                string confKey = confKeys[i].Groups[1].Value;
                string confDesc = confDescs[i].Groups[1].Value;
                Confirmation conf = new Confirmation(confID, confKey, confDesc);
                ret.Add(conf);
            }

            return ret;
        }
コード例 #15
0
 public bool AcceptConfirmation(Confirmation conf)
 {
     return(_sendConfirmationAjax(conf, "allow"));
 }
コード例 #16
0
        public async Task<Confirmation[]> FetchConfirmationsAsync()
        {
            string url = this.GenerateConfirmationURL();

            CookieContainer cookies = new CookieContainer();
            this.Session.AddCookies(cookies);

            string response = await SteamWeb.RequestAsync(url, "GET", null, cookies);

            /*So you're going to see this abomination and you're going to be upset.
              It's understandable. But the thing is, regex for HTML -- while awful -- makes this way faster than parsing a DOM, plus we don't need another library.
              And because the data is always in the same place and same format... It's not as if we're trying to naturally understand HTML here. Just extract strings.
              I'm sorry. */

            Regex confIDRegex = new Regex("data-confid=\"(\\d+)\"");
            Regex confKeyRegex = new Regex("data-key=\"(\\d+)\"");
            Regex confDescRegex = new Regex("<div>((Confirm|Trade with|Sell -) .+)</div>");

            if (response == null || !(confIDRegex.IsMatch(response) && confKeyRegex.IsMatch(response) && confDescRegex.IsMatch(response)))
            {
                if (response == null || !response.Contains("<div>Nothing to confirm</div>"))
                {
                    throw new WGTokenInvalidException();
                }

                return new Confirmation[0];
            }

            MatchCollection confIDs = confIDRegex.Matches(response);
            MatchCollection confKeys = confKeyRegex.Matches(response);
            MatchCollection confDescs = confDescRegex.Matches(response);

            List<Confirmation> ret = new List<Confirmation>();
            for (int i = 0; i < confIDs.Count; i++)
            {
                string confID = confIDs[i].Groups[1].Value;
                string confKey = confKeys[i].Groups[1].Value;
                string confDesc = confDescs[i].Groups[1].Value;
                Confirmation conf = new Confirmation()
                {
                    ConfirmationDescription = confDesc,
                    ConfirmationID = confID,
                    ConfirmationKey = confKey
                };
                ret.Add(conf);
            }

            return ret.ToArray();
        }
コード例 #17
0
 public bool DenyConfirmation(Confirmation conf)
 {
     return(_sendConfirmationAjax(conf, "cancel"));
 }
コード例 #18
0
ファイル: Bot.cs プロジェクト: Ryzhehvost/ArchiSteamFarm
		internal async Task AcceptConfirmations(bool confirm, Confirmation.ConfirmationType allowedConfirmationType = Confirmation.ConfirmationType.Unknown) {
			if (BotDatabase.SteamGuardAccount == null) {
				return;
			}

			try {
				if (!await BotDatabase.SteamGuardAccount.RefreshSessionAsync().ConfigureAwait(false)) {
					return;
				}

				Confirmation[] confirmations = await BotDatabase.SteamGuardAccount.FetchConfirmationsAsync().ConfigureAwait(false);
				if (confirmations == null) {
					return;
				}

				foreach (Confirmation confirmation in confirmations) {
					if (allowedConfirmationType != Confirmation.ConfirmationType.Unknown && confirmation.ConfType != allowedConfirmationType) {
						continue;
					}

					if (confirm) {
						BotDatabase.SteamGuardAccount.AcceptConfirmation(confirmation);
					} else {
						BotDatabase.SteamGuardAccount.DenyConfirmation(confirmation);
					}
				}
			} catch (SteamGuardAccount.WGTokenInvalidException) {
				Logging.LogGenericWarning("Handling confirmation: Failed!", BotName);
				Logging.LogGenericWarning("Confirmation could not be accepted because of invalid token exception", BotName);
				Logging.LogGenericWarning("If issue persists, consider removing and readding ASF 2FA", BotName);
			} catch (Exception e) {
				Logging.LogGenericException(e, BotName);
			}
		}