Skip to content

Commit

Permalink
Add workaround for SteamRE/SteamKit#992
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed May 29, 2021
1 parent 5175fad commit 4a9c8b5
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,14 @@ public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint a
return null;
}

// Extra entry for format
Dictionary<string, object> arguments = new(5, StringComparer.Ordinal) {
{ "include_appinfo", 1 },
{ "key", steamApiKey! },
{ "skip_unvetted_apps", "0" },
{ "steamid", steamID }
};

KeyValue? response = null;

for (byte i = 0; (i < WebBrowser.MaxTries) && (response == null); i++) {
Expand All @@ -319,15 +327,9 @@ public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint a
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,

// TODO: Remove this ToDictionary() call after https://github.com/SteamRE/SteamKit/pull/992 is released
// ReSharper disable once AccessToDisposedClosure
async () => await playerService.CallAsync(
HttpMethod.Get, "GetOwnedGames", args: new Dictionary<string, object>(4, StringComparer.Ordinal) {
{ "include_appinfo", 1 },
{ "key", steamApiKey! },
{ "skip_unvetted_apps", "0" },
{ "steamid", steamID }
}
).ConfigureAwait(false)
async () => await playerService.CallAsync(HttpMethod.Get, "GetOwnedGames", args: arguments.ToDictionary(kv => kv.Key, kv => kv.Value)).ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
Expand Down Expand Up @@ -1423,6 +1425,12 @@ internal async Task<bool> DeclineTradeOffer(ulong tradeID) {
return false;
}

// Extra entry for format
Dictionary<string, object> arguments = new(3, StringComparer.Ordinal) {
{ "key", steamApiKey! },
{ "tradeofferid", tradeID }
};

KeyValue? response = null;

for (byte i = 0; (i < WebBrowser.MaxTries) && (response == null); i++) {
Expand All @@ -1434,13 +1442,9 @@ internal async Task<bool> DeclineTradeOffer(ulong tradeID) {
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,

// TODO: Remove this ToDictionary() call after https://github.com/SteamRE/SteamKit/pull/992 is released
// ReSharper disable once AccessToDisposedClosure
async () => await econService.CallAsync(
HttpMethod.Post, "DeclineTradeOffer", args: new Dictionary<string, object>(2, StringComparer.Ordinal) {
{ "key", steamApiKey! },
{ "tradeofferid", tradeID }
}
).ConfigureAwait(false)
async () => await econService.CallAsync(HttpMethod.Post, "DeclineTradeOffer", args: arguments.ToDictionary(kv => kv.Key, kv => kv.Value)).ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
Expand Down Expand Up @@ -1478,6 +1482,15 @@ internal async Task<bool> DeclineTradeOffer(ulong tradeID) {
return null;
}

// Extra entry for format
Dictionary<string, object> arguments = new(6, StringComparer.Ordinal) {
{ "active_only", 1 },
{ "get_descriptions", 1 },
{ "get_received_offers", 1 },
{ "key", steamApiKey! },
{ "time_historical_cutoff", uint.MaxValue }
};

KeyValue? response = null;

for (byte i = 0; (i < WebBrowser.MaxTries) && (response == null); i++) {
Expand All @@ -1489,16 +1502,9 @@ internal async Task<bool> DeclineTradeOffer(ulong tradeID) {
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,

// TODO: Remove this ToDictionary() call after https://github.com/SteamRE/SteamKit/pull/992 is released
// ReSharper disable once AccessToDisposedClosure
async () => await econService.CallAsync(
HttpMethod.Get, "GetTradeOffers", args: new Dictionary<string, object>(5, StringComparer.Ordinal) {
{ "active_only", 1 },
{ "get_descriptions", 1 },
{ "get_received_offers", 1 },
{ "key", steamApiKey! },
{ "time_historical_cutoff", uint.MaxValue }
}
).ConfigureAwait(false)
async () => await econService.CallAsync(HttpMethod.Get, "GetTradeOffers", args: arguments).ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
Expand Down Expand Up @@ -1964,7 +1970,8 @@ internal async Task<uint> GetServerTime() {
return null;
}

Dictionary<string, object> arguments = new(!string.IsNullOrEmpty(tradeToken) ? 3 : 2, StringComparer.Ordinal) {
// Extra entry for format
Dictionary<string, object> arguments = new(!string.IsNullOrEmpty(tradeToken) ? 4 : 3, StringComparer.Ordinal) {
{ "key", steamApiKey! },
{ "steamid_target", steamID }
};
Expand All @@ -1984,8 +1991,9 @@ internal async Task<uint> GetServerTime() {
response = await WebLimitRequest(
WebAPI.DefaultBaseAddress,

// TODO: Remove this ToDictionary() call after https://github.com/SteamRE/SteamKit/pull/992 is released
// ReSharper disable once AccessToDisposedClosure
async () => await econService.CallAsync(HttpMethod.Get, "GetTradeHoldDurations", args: arguments).ConfigureAwait(false)
async () => await econService.CallAsync(HttpMethod.Get, "GetTradeHoldDurations", args: arguments.ToDictionary(kv => kv.Key, kv => kv.Value)).ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
Expand Down Expand Up @@ -2144,6 +2152,13 @@ internal async Task<bool> Init(ulong steamID, EUniverse universe, string webAPIU
// AES encrypt our login key with our session key
byte[] encryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);

// Extra entry for format
Dictionary<string, object> arguments = new(4, StringComparer.Ordinal) {
{ "encrypted_loginkey", encryptedLoginKey },
{ "sessionkey", encryptedSessionKey },
{ "steamid", steamID }
};

// We're now ready to send the data to Steam API
Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.LoggingIn, SteamUserAuthService));

Expand All @@ -2160,13 +2175,7 @@ internal async Task<bool> Init(ulong steamID, EUniverse universe, string webAPIU
WebAPI.DefaultBaseAddress,

// ReSharper disable once AccessToDisposedClosure
async () => await steamUserAuthService.CallAsync(
HttpMethod.Post, "AuthenticateUser", args: new Dictionary<string, object>(3, StringComparer.Ordinal) {
{ "encrypted_loginkey", encryptedLoginKey },
{ "sessionkey", encryptedSessionKey },
{ "steamid", steamID }
}
).ConfigureAwait(false)
async () => await steamUserAuthService.CallAsync(HttpMethod.Post, "AuthenticateUser", args: arguments).ConfigureAwait(false)
).ConfigureAwait(false);
} catch (TaskCanceledException e) {
Bot.ArchiLogger.LogGenericDebuggingException(e);
Expand Down

8 comments on commit 4a9c8b5

@Abrynos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mentioned merge request has been merged on June 13th and the latest pre-release of SteamKit2 (which we are using) was released 26 days ago (which was July 30th). We should be able to revert this commit now.

@JustArchi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send a PR.

@Abrynos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I'm not sure I want to pull the whole history of a fork that's going to get deleted 5 minutes after merging, considering how unstable my internet is lately.

@JustArchi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--depth 1 exists.

@Abrynos
Copy link
Member

@Abrynos Abrynos commented on 4a9c8b5 Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that before I wrote the first comment. It won't work, because my local copy of the repo doesn't know about the commit.

fatal: bad object 4a9c8b59d6f62fce8958cca3fae233525af61d4b

I might be a lazy idiot at times, but I'm not THAT lazy.

@JustArchi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excuses, you can do a clean clone with that depth.

@Abrynos
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Let me just click Older a few times on GitHub and count how many commits it has been, when for you it literally would be

cd /path/to/ASF
git revert 4a9c8b59d6f62fce8958cca3fae233525af61d4b
git push

@JustArchi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because there were other changes since then that also need to be taken into account.

Commit, not a revert.

Please sign in to comment.