Compare commits

...

17 Commits

Author SHA1 Message Date
JustArchi
fea76a3dda Derp 2016-06-20 13:18:06 +02:00
JustArchi
1087c01a2c And don't you dare to break again 2016-06-20 13:15:35 +02:00
JustArchi
fd49ff5483 Thanks GabeN 2016-06-20 13:09:27 +02:00
JustArchi
0f5d9a665c Bump 2016-06-20 13:01:42 +02:00
JustArchi
ad63432645 I must stop forgetting about bot identifiers 2016-06-20 12:53:17 +02:00
JustArchi
f36681ea18 Be more verbose on progress 2016-06-20 12:52:28 +02:00
JustArchi
ce94035d98 Bump 2016-06-20 08:37:31 +02:00
JustArchi
7583e50cf3 Bump 2016-06-20 08:35:47 +02:00
JustArchi
687de60476 Final performance improvements of new ASF 2FA 2016-06-20 06:51:42 +02:00
JustArchi
e181eb354b Revert "Closes #253"
This reverts commit 4e5ddefac9.

I didn't like the new format.
2016-06-20 06:32:40 +02:00
JustArchi
4e5ddefac9 Closes #253 2016-06-19 22:25:53 +02:00
JustArchi
e588ba3d2c Misc 2016-06-19 15:03:42 +02:00
JustArchi
6d087a9ac9 Misc 2016-06-19 13:59:56 +02:00
JustArchi
529d366b6c Revert "Try to fix Travis"
This reverts commit 4657d00d11.
2016-06-19 12:53:04 +02:00
JustArchi
4657d00d11 Try to fix Travis 2016-06-19 12:47:27 +02:00
JustArchi
3a5edab651 Code review 2016-06-19 12:20:12 +02:00
JustArchi
d662d9dd6a Misc 2016-06-19 09:34:09 +02:00
10 changed files with 133 additions and 136 deletions

View File

@@ -171,7 +171,6 @@ namespace ArchiSteamFarm {
Logging.LogGenericInfo("Success!", Bot.BotName);
WebBrowser.CookieContainer.Add(new Cookie("steamid", SteamID.ToString(), "/", "." + SteamCommunityHost)); // TODO: Check if needed for mobile auth
WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost));
string steamLogin = authResult["token"].Value;
@@ -239,7 +238,7 @@ namespace ArchiSteamFarm {
internal async Task<HtmlDocument> GetConfirmations(string deviceID, string confirmationHash, uint time) {
if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0)) {
Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time));
Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time), Bot.BotName);
return null;
}
@@ -247,7 +246,7 @@ namespace ArchiSteamFarm {
return null;
}
string request = SteamCommunityURL + "/mobileconf/conf?p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf";
string request = SteamCommunityURL + "/mobileconf/conf?l=english&p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf";
return await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
}
@@ -257,6 +256,10 @@ namespace ArchiSteamFarm {
return null;
}
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
return null;
}
string request = SteamCommunityURL + "/mobileconf/details/" + confirmationID + "?p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf";
string json = await WebBrowser.UrlGetToContentRetry(request).ConfigureAwait(false);
@@ -273,20 +276,25 @@ namespace ArchiSteamFarm {
return null;
}
if (response != null) {
return response;
}
if (response == null) {
Logging.LogNullError(nameof(response), Bot.BotName);
return null;
}
response.ConfirmationID = confirmationID;
return response;
}
internal async Task<bool> HandleConfirmation(string deviceID, string confirmationHash, uint time, uint confirmationID, ulong confirmationKey, bool accept) {
if (string.IsNullOrEmpty(deviceID) || string.IsNullOrEmpty(confirmationHash) || (time == 0) || (confirmationID == 0) || (confirmationKey == 0)) {
Logging.LogNullError(nameof(deviceID) + " || " + nameof(confirmationHash) + " || " + nameof(time) + " || " + nameof(confirmationID) + " || " + nameof(confirmationKey), Bot.BotName);
return false;
}
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
return false;
}
string request = SteamCommunityURL + "/mobileconf/ajaxop?op=" + (accept ? "allow" : "cancel") + "&p=" + deviceID + "&a=" + SteamID + "&k=" + WebUtility.UrlEncode(confirmationHash) + "&t=" + time + "&m=android&tag=conf&cid=" + confirmationID + "&ck=" + confirmationKey;
string json = await WebBrowser.UrlGetToContentRetry(request).ConfigureAwait(false);
@@ -386,7 +394,7 @@ namespace ArchiSteamFarm {
foreach (KeyValue game in response["games"].Children) {
uint appID = (uint) game["appid"].AsUnsignedLong();
if (appID == 0) {
Logging.LogNullError(nameof(appID));
Logging.LogNullError(nameof(appID), Bot.BotName);
continue;
}
@@ -398,7 +406,7 @@ namespace ArchiSteamFarm {
internal uint GetServerTime() {
KeyValue response = null;
using (dynamic iTwoFactorService = WebAPI.GetInterface("ITwoFactorService", Bot.BotConfig.SteamApiKey)) {
using (dynamic iTwoFactorService = WebAPI.GetInterface("ITwoFactorService")) {
iTwoFactorService.Timeout = Timeout;
for (byte i = 0; (i < WebBrowser.MaxRetries) && (response == null); i++) {
@@ -427,7 +435,7 @@ namespace ArchiSteamFarm {
return null;
}
string request = SteamCommunityURL + "/tradeoffer/" + tradeID;
string request = SteamCommunityURL + "/tradeoffer/" + tradeID + "?l=english";
HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
if (htmlDocument == null) {
@@ -829,7 +837,7 @@ namespace ArchiSteamFarm {
return null;
}
string request = SteamCommunityURL + "/my/badges?p=" + page;
string request = SteamCommunityURL + "/my/badges?l=english&p=" + page;
return await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
}
@@ -844,7 +852,7 @@ namespace ArchiSteamFarm {
return null;
}
string request = SteamCommunityURL + "/my/gamecards/" + appID;
string request = SteamCommunityURL + "/my/gamecards/" + appID + "?l=english";
return await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
}

View File

@@ -151,10 +151,10 @@ namespace ArchiSteamFarm {
// TODO: Converter code will be removed soon
if (BotDatabase.SteamGuardAccount != null) {
Logging.LogGenericWarning("Converting old ASF 2FA V2.0 format into new ASF 2FA V2.1 format...");
Logging.LogGenericWarning("Converting old ASF 2FA V2.0 format into new ASF 2FA V2.1 format...", botName);
BotDatabase.MobileAuthenticator = MobileAuthenticator.LoadFromSteamGuardAccount(BotDatabase.SteamGuardAccount);
Logging.LogGenericInfo("Done! If you didn't make a copy of your revocation code yet, then it's a good moment to do so: " + BotDatabase.SteamGuardAccount.RevocationCode);
Logging.LogGenericWarning("ASF will not keep this code anymore!");
Logging.LogGenericInfo("Done! If you didn't make a copy of your revocation code yet, then it's a good moment to do so: " + BotDatabase.SteamGuardAccount.RevocationCode, botName);
Logging.LogGenericWarning("ASF will not keep this code anymore!", botName);
BotDatabase.SteamGuardAccount = null;
}
@@ -261,34 +261,29 @@ namespace ArchiSteamFarm {
}
if ((acceptedSteamID != 0) || ((acceptedTradeIDs != null) && (acceptedTradeIDs.Count > 0))) {
HashSet<MobileAuthenticator.Confirmation> ignoredConfirmations = new HashSet<MobileAuthenticator.Confirmation>();
// TODO: This could be potentially multi-threaded like below
foreach (MobileAuthenticator.Confirmation confirmation in confirmations) {
Steam.ConfirmationDetails details = await BotDatabase.MobileAuthenticator.GetConfirmationDetails(confirmation).ConfigureAwait(false);
if (details == null) {
ignoredConfirmations.Add(confirmation);
continue;
List<Task<Steam.ConfirmationDetails>> detailsTasks = confirmations.Select(BotDatabase.MobileAuthenticator.GetConfirmationDetails).ToList();
Steam.ConfirmationDetails[] detailsResults = await Task.WhenAll(detailsTasks).ConfigureAwait(false);
HashSet<uint> ignoredConfirmationIDs = new HashSet<uint>();
foreach (Steam.ConfirmationDetails details in detailsResults.Where(details => (details != null) && (
((acceptedSteamID != 0) && (details.OtherSteamID64 != 0) && (acceptedSteamID != details.OtherSteamID64)) ||
((acceptedTradeIDs != null) && (details.TradeOfferID != 0) && !acceptedTradeIDs.Contains(details.TradeOfferID))
))) {
ignoredConfirmationIDs.Add(details.ConfirmationID);
}
if ((acceptedSteamID != 0) && (acceptedSteamID != details.OtherSteamID64)) {
ignoredConfirmations.Add(confirmation);
continue;
}
if ((acceptedTradeIDs != null) && !acceptedTradeIDs.Contains(details.TradeOfferID)) {
ignoredConfirmations.Add(confirmation);
}
}
confirmations.ExceptWith(ignoredConfirmations);
if (ignoredConfirmationIDs.Count > 0) {
if (confirmations.RemoveWhere(confirmation => ignoredConfirmationIDs.Contains(confirmation.ID)) > 0) {
confirmations.TrimExcess();
if (confirmations.Count == 0) {
return;
}
}
}
}
await confirmations.ForEachAsync(async confirmation => await BotDatabase.MobileAuthenticator.HandleConfirmation(confirmation, accept).ConfigureAwait(false)).ConfigureAwait(false);
List<Task<bool>> tasks = confirmations.Select(confirmation => BotDatabase.MobileAuthenticator.HandleConfirmation(confirmation, accept)).ToList();
await Task.WhenAll(tasks).ConfigureAwait(false);
}
internal async Task<bool> RefreshSession() {
@@ -485,7 +480,7 @@ namespace ArchiSteamFarm {
}
if (BotDatabase.MobileAuthenticator == null) {
Logging.LogNullError(nameof(BotDatabase.MobileAuthenticator));
Logging.LogNullError(nameof(BotDatabase.MobileAuthenticator), BotName);
return;
}
@@ -507,7 +502,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponsePause(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -544,7 +539,7 @@ namespace ArchiSteamFarm {
private string ResponseStatus(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -615,7 +610,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseSendTrade(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -674,7 +669,7 @@ namespace ArchiSteamFarm {
private async Task<string> Response2FA(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -710,7 +705,7 @@ namespace ArchiSteamFarm {
private async Task<string> Response2FAConfirm(ulong steamID, bool confirm) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -765,7 +760,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseFarm(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -802,7 +797,7 @@ namespace ArchiSteamFarm {
private string ResponseHelp(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -815,7 +810,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseRedeem(ulong steamID, string message, bool validate) {
if ((steamID == 0) || string.IsNullOrEmpty(message)) {
Logging.LogNullError(nameof(steamID) + " || " + nameof(message));
Logging.LogNullError(nameof(steamID) + " || " + nameof(message), BotName);
return null;
}
@@ -967,7 +962,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseAddLicense(ulong steamID, ICollection<uint> gameIDs) {
if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) {
Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count));
Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count), BotName);
return null;
}
@@ -1024,7 +1019,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseOwns(ulong steamID, string query) {
if ((steamID == 0) || string.IsNullOrEmpty(query)) {
Logging.LogNullError(nameof(steamID) + " || " + nameof(query));
Logging.LogNullError(nameof(steamID) + " || " + nameof(query), BotName);
return null;
}
@@ -1093,7 +1088,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponsePlay(ulong steamID, HashSet<uint> gameIDs) {
if ((steamID == 0) || (gameIDs == null) || (gameIDs.Count == 0)) {
Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count));
Logging.LogNullError(nameof(steamID) + " || " + nameof(gameIDs) + " || " + nameof(gameIDs.Count), BotName);
return null;
}
@@ -1154,7 +1149,7 @@ namespace ArchiSteamFarm {
private async Task<string> ResponseStart(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -1191,7 +1186,7 @@ namespace ArchiSteamFarm {
private string ResponseStop(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -1250,7 +1245,7 @@ namespace ArchiSteamFarm {
private string ResponseVersion(ulong steamID) {
if (steamID == 0) {
Logging.LogNullError(nameof(steamID));
Logging.LogNullError(nameof(steamID), BotName);
return null;
}
@@ -1840,7 +1835,7 @@ namespace ArchiSteamFarm {
private void OnPlayingSessionState(ArchiHandler.PlayingSessionStateCallback callback) {
if (callback == null) {
Logging.LogNullError(nameof(callback));
Logging.LogNullError(nameof(callback), BotName);
return;
}

View File

@@ -102,7 +102,7 @@ namespace ArchiSteamFarm {
// This is the last moment for final check if we can farm
if (Bot.PlayingBlocked) {
Logging.LogGenericInfo("But account is currently occupied, so farming is stopped!");
Logging.LogGenericInfo("But account is currently occupied, so farming is stopped!", Bot.BotName);
FarmingSemaphore.Release(); // We have nothing to do, don't forget to release semaphore
return;
}
@@ -377,14 +377,21 @@ namespace ArchiSteamFarm {
}
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//span[@class='progress_info_bold']");
if (htmlNode != null) {
return !htmlNode.InnerText.Contains("No card drops");
}
if (htmlNode == null) {
Logging.LogNullError(nameof(htmlNode), Bot.BotName);
return null;
}
string progress = htmlNode.InnerText;
if (string.IsNullOrEmpty(progress)) {
Logging.LogNullError(nameof(progress), Bot.BotName);
return null;
}
Logging.LogGenericInfo("Status for " + appID + ": " + progress, Bot.BotName);
return !progress.Equals("No card drops remaining");
}
private bool FarmMultiple() {
if (GamesToFarm.Count == 0) {
return true;

View File

@@ -348,6 +348,8 @@ namespace ArchiSteamFarm.JSON {
Other
}
internal uint ConfirmationID { get; set; }
[JsonProperty(PropertyName = "success", Required = Required.Always)]
internal bool Success { get; private set; }
@@ -359,7 +361,6 @@ namespace ArchiSteamFarm.JSON {
}
if (HtmlDocument == null) {
Logging.LogNullError(nameof(HtmlDocument));
return EType.Unknown;
}
@@ -387,12 +388,7 @@ namespace ArchiSteamFarm.JSON {
return _TradeOfferID;
}
if (Type != EType.Trade) {
return 0;
}
if (HtmlDocument == null) {
Logging.LogNullError(nameof(HtmlDocument));
if ((Type != EType.Trade) || (HtmlDocument == null)) {
return 0;
}
@@ -437,12 +433,7 @@ namespace ArchiSteamFarm.JSON {
return _OtherSteamID64;
}
if (Type != EType.Trade) {
return 0;
}
if (OtherSteamID3 == 0) {
Logging.LogNullError(nameof(OtherSteamID3));
if ((Type != EType.Trade) || (OtherSteamID3 == 0)) {
return 0;
}
@@ -451,7 +442,7 @@ namespace ArchiSteamFarm.JSON {
}
}
[JsonProperty(PropertyName = "html", Required = Required.Always)]
[JsonProperty(PropertyName = "html")]
private string HTML;
private uint _OtherSteamID3;
@@ -461,12 +452,7 @@ namespace ArchiSteamFarm.JSON {
return _OtherSteamID3;
}
if (Type != EType.Trade) {
return 0;
}
if (HtmlDocument == null) {
Logging.LogNullError(nameof(HtmlDocument));
if ((Type != EType.Trade) || (HtmlDocument == null)) {
return 0;
}
@@ -499,7 +485,6 @@ namespace ArchiSteamFarm.JSON {
}
if (string.IsNullOrEmpty(HTML)) {
Logging.LogNullError(nameof(HTML));
return null;
}

View File

@@ -23,6 +23,7 @@
*/
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Runtime.CompilerServices;
@@ -79,9 +80,7 @@ namespace ArchiSteamFarm {
return;
}
Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message);
Log("[!] StackTrace:" + Environment.NewLine + exception.StackTrace);
Log("[!] EXCEPTION: " + previousMethodName + "() <" + botName + "> " + exception.Message + Environment.NewLine + "StackTrace:" + Environment.NewLine + exception.StackTrace);
if (exception.InnerException != null) {
exception = exception.InnerException;
continue;
@@ -122,6 +121,7 @@ namespace ArchiSteamFarm {
}
}
[Conditional("DEBUG")]
[SuppressMessage("ReSharper", "UnusedMember.Global")]
internal static void LogGenericDebug(string message, string botName = "Main", [CallerMemberName] string previousMethodName = null) {
if (string.IsNullOrEmpty(message)) {

View File

@@ -92,7 +92,7 @@ namespace ArchiSteamFarm {
string confirmationHash = GenerateConfirmationKey(time, "conf");
if (!string.IsNullOrEmpty(confirmationHash)) {
return await Bot.ArchiWebHandler.HandleConfirmation(DeviceID, confirmationHash, time, confirmation.ID, confirmation.Key, accept);
return await Bot.ArchiWebHandler.HandleConfirmation(DeviceID, confirmationHash, time, confirmation.ID, confirmation.Key, accept).ConfigureAwait(false);
}
Logging.LogNullError(nameof(confirmationHash), Bot.BotName);
@@ -112,14 +112,19 @@ namespace ArchiSteamFarm {
}
string confirmationHash = GenerateConfirmationKey(time, "conf");
if (!string.IsNullOrEmpty(confirmationHash)) {
return await Bot.ArchiWebHandler.GetConfirmationDetails(DeviceID, confirmationHash, time, confirmation.ID);
}
if (string.IsNullOrEmpty(confirmationHash)) {
Logging.LogNullError(nameof(confirmationHash), Bot.BotName);
return null;
}
Steam.ConfirmationDetails response = await Bot.ArchiWebHandler.GetConfirmationDetails(DeviceID, confirmationHash, time, confirmation.ID).ConfigureAwait(false);
if ((response == null) || !response.Success) {
return null;
}
return response;
}
internal async Task<string> GenerateToken() {
uint time = await GetSteamTime().ConfigureAwait(false);
if (time != 0) {
@@ -143,7 +148,7 @@ namespace ArchiSteamFarm {
return null;
}
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetConfirmations(DeviceID, confirmationHash, time);
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetConfirmations(DeviceID, confirmationHash, time).ConfigureAwait(false);
if (htmlDocument == null) {
return null;
}

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.1.0.0")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyVersion("2.1.0.3")]
[assembly: AssemblyFileVersion("2.1.0.3")]

View File

@@ -86,40 +86,44 @@ namespace ArchiSteamFarm {
return;
}
tradeOffers.RemoveWhere(tradeoffer => tradeoffer.State != Steam.TradeOffer.ETradeOfferState.Active);
if (tradeOffers.RemoveWhere(tradeoffer => tradeoffer.State != Steam.TradeOffer.ETradeOfferState.Active) > 0) {
tradeOffers.TrimExcess();
if (tradeOffers.Count == 0) {
return;
}
}
await tradeOffers.ForEachAsync(ParseTrade).ConfigureAwait(false);
List<Task<bool>> tasks = tradeOffers.Select(ParseTrade).ToList();
bool[] results = await Task.WhenAll(tasks).ConfigureAwait(false);
if (tradeOffers.Any(tradeoffer => tradeoffer.ItemsToGive.Count > 0)) {
if (results.Any(result => result)) {
HashSet<ulong> tradeIDs = new HashSet<ulong>(tradeOffers.Select(tradeOffer => tradeOffer.TradeOfferID));
await Bot.AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, 0, tradeIDs).ConfigureAwait(false);
}
}
private async Task ParseTrade(Steam.TradeOffer tradeOffer) {
private async Task<bool> ParseTrade(Steam.TradeOffer tradeOffer) {
if (tradeOffer == null) {
Logging.LogNullError(nameof(tradeOffer), Bot.BotName);
return;
return false;
}
if (tradeOffer.State != Steam.TradeOffer.ETradeOfferState.Active) {
return;
return false;
}
if (await ShouldAcceptTrade(tradeOffer).ConfigureAwait(false)) {
Logging.LogGenericInfo("Accepting trade: " + tradeOffer.TradeOfferID, Bot.BotName);
await Bot.ArchiWebHandler.AcceptTradeOffer(tradeOffer.TradeOfferID).ConfigureAwait(false);
} else if (Bot.BotConfig.IsBotAccount) {
Logging.LogGenericInfo("Rejecting trade: " + tradeOffer.TradeOfferID, Bot.BotName);
Bot.ArchiWebHandler.DeclineTradeOffer(tradeOffer.TradeOfferID);
} else {
Logging.LogGenericInfo("Ignoring trade: " + tradeOffer.TradeOfferID, Bot.BotName);
return await Bot.ArchiWebHandler.AcceptTradeOffer(tradeOffer.TradeOfferID).ConfigureAwait(false);
}
if (Bot.BotConfig.IsBotAccount) {
Logging.LogGenericInfo("Rejecting trade: " + tradeOffer.TradeOfferID, Bot.BotName);
return Bot.ArchiWebHandler.DeclineTradeOffer(tradeOffer.TradeOfferID);
}
Logging.LogGenericInfo("Ignoring trade: " + tradeOffer.TradeOfferID, Bot.BotName);
return false;
}
private async Task<bool> ShouldAcceptTrade(Steam.TradeOffer tradeOffer) {

View File

@@ -23,7 +23,6 @@
*/
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net;
@@ -34,15 +33,6 @@ namespace ArchiSteamFarm {
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
internal static void Forget(this Task task) { }
internal static Task ForEachAsync<T>(this IEnumerable<T> sequence, Func<T, Task> action) {
if (action != null) {
return Task.WhenAll(sequence.Select(action));
}
Logging.LogNullError(nameof(action));
return Task.FromResult(true);
}
internal static string GetCookieValue(this CookieContainer cookieContainer, string url, string name) {
if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(name)) {
Logging.LogNullError(nameof(url) + " || " + nameof(name));

View File

@@ -80,11 +80,14 @@ namespace ArchiSteamFarm {
// Most web services expect that UserAgent is set, so we declare it globally
HttpClient.DefaultRequestHeaders.UserAgent.ParseAdd(DefaultUserAgent);
// We should always operate in English language, declare it globally
HttpClient.DefaultRequestHeaders.AcceptLanguage.ParseAdd("en-US,en;q=0.8,en-GB;q=0.6");
}
internal async Task<bool> UrlHeadRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return false;
}
@@ -103,7 +106,7 @@ namespace ArchiSteamFarm {
internal async Task<Uri> UrlHeadToUriRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -122,7 +125,7 @@ namespace ArchiSteamFarm {
internal async Task<byte[]> UrlGetToBytesRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -141,7 +144,7 @@ namespace ArchiSteamFarm {
internal async Task<string> UrlGetToContentRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -160,7 +163,7 @@ namespace ArchiSteamFarm {
internal async Task<HtmlDocument> UrlGetToHtmlDocumentRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -179,7 +182,7 @@ namespace ArchiSteamFarm {
internal async Task<JObject> UrlGetToJObjectRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -198,7 +201,7 @@ namespace ArchiSteamFarm {
internal async Task<XmlDocument> UrlGetToXMLRetry(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -217,7 +220,7 @@ namespace ArchiSteamFarm {
internal async Task<bool> UrlPostRetry(string request, Dictionary<string, string> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return false;
}
@@ -236,7 +239,7 @@ namespace ArchiSteamFarm {
private async Task<byte[]> UrlGetToBytes(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -251,7 +254,7 @@ namespace ArchiSteamFarm {
private async Task<string> UrlGetToContent(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -266,7 +269,7 @@ namespace ArchiSteamFarm {
private async Task<HtmlDocument> UrlGetToHtmlDocument(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -282,7 +285,7 @@ namespace ArchiSteamFarm {
private async Task<JObject> UrlGetToJObject(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -308,13 +311,13 @@ namespace ArchiSteamFarm {
return await UrlRequest(request, HttpMethod.Get, null, referer).ConfigureAwait(false);
}
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
private async Task<XmlDocument> UrlGetToXML(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -337,7 +340,7 @@ namespace ArchiSteamFarm {
private async Task<bool> UrlHead(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return false;
}
@@ -351,13 +354,13 @@ namespace ArchiSteamFarm {
return await UrlRequest(request, HttpMethod.Head, null, referer).ConfigureAwait(false);
}
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
private async Task<Uri> UrlHeadToUri(string request, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
@@ -368,7 +371,7 @@ namespace ArchiSteamFarm {
private async Task<bool> UrlPost(string request, Dictionary<string, string> data = null, string referer = null) {
if (string.IsNullOrEmpty(request)) {
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return false;
}
@@ -382,13 +385,13 @@ namespace ArchiSteamFarm {
return await UrlRequest(request, HttpMethod.Post, data, referer).ConfigureAwait(false);
}
Logging.LogNullError(nameof(request));
Logging.LogNullError(nameof(request), Identifier);
return null;
}
private async Task<HttpResponseMessage> UrlRequest(string request, HttpMethod httpMethod, Dictionary<string, string> data = null, string referer = null) {
if (string.IsNullOrEmpty(request) || (httpMethod == null)) {
Logging.LogNullError(nameof(request) + " || " + nameof(httpMethod));
Logging.LogNullError(nameof(request) + " || " + nameof(httpMethod), Identifier);
return null;
}