Skip to content

Commit f7d822b

Browse files
committed
Add support for steam wallet keys, #239
1 parent e7cda0f commit f7d822b

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

ArchiSteamFarm/ArchiHandler.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,22 @@ internal PlayingSessionStateCallback(JobID jobID, CMsgClientPlayingSessionState
120120
internal sealed class PurchaseResponseCallback : CallbackMsg {
121121
internal enum EPurchaseResult : sbyte {
122122
[SuppressMessage("ReSharper", "UnusedMember.Global")]
123-
Unknown = -1,
123+
Unknown = -2,
124+
Timeout = -1,
124125
OK = 0,
125126
AlreadyOwned = 9,
126127
RegionLocked = 13,
127128
InvalidKey = 14,
128129
DuplicatedKey = 15,
129130
BaseGameRequired = 24,
131+
SteamWalletCode = 50,
130132
OnCooldown = 53
131133
}
132134

133-
internal readonly EPurchaseResult PurchaseResult;
134135
internal readonly Dictionary<uint, string> Items;
135136

137+
internal EPurchaseResult PurchaseResult { get; set; }
138+
136139
internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
137140
if ((jobID == null) || (msg == null)) {
138141
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));

ArchiSteamFarm/ArchiWebHandler.cs

+19
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,25 @@ internal uint GetServerTime() {
554554
return null;
555555
}
556556

557+
internal async Task<ArchiHandler.PurchaseResponseCallback.EPurchaseResult> RedeemWalletKey(string key) {
558+
if (string.IsNullOrEmpty(key)) {
559+
Logging.LogNullError(nameof(key), Bot.BotName);
560+
return ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Unknown;
561+
}
562+
563+
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
564+
return ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout;
565+
}
566+
567+
string request = SteamStoreURL + "/account/validatewalletcode";
568+
Dictionary<string, string> data = new Dictionary<string, string>(1) {
569+
{ "wallet_code", key }
570+
};
571+
572+
Steam.RedeemWalletResponse response = await WebBrowser.UrlPostToJsonResultRetry<Steam.RedeemWalletResponse>(request, data).ConfigureAwait(false);
573+
return response?.PurchaseResult ?? ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout;
574+
}
575+
557576
internal HashSet<Steam.TradeOffer> GetActiveTradeOffers() {
558577
if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
559578
Logging.LogNullError(nameof(Bot.BotConfig.SteamApiKey), Bot.BotName);

ArchiSteamFarm/Bot.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1186,13 +1186,22 @@ private async Task<string> ResponseRedeem(ulong steamID, string message, bool va
11861186
} else {
11871187
ArchiHandler.PurchaseResponseCallback result = await currentBot.ArchiHandler.RedeemKey(key).ConfigureAwait(false);
11881188
if (result == null) {
1189-
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: Timeout!");
1189+
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: " + ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout);
11901190
currentBot = null; // Either bot will be changed, or loop aborted
11911191
} else {
11921192
switch (result.PurchaseResult) {
11931193
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.DuplicatedKey:
11941194
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.InvalidKey:
11951195
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK:
1196+
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.SteamWalletCode:
1197+
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout:
1198+
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Unknown:
1199+
if (result.PurchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.SteamWalletCode) {
1200+
// If it's a wallet code, try to redeem it, and forward the result
1201+
// The result is final, there is no place for forwarding
1202+
result.PurchaseResult = await currentBot.ArchiWebHandler.RedeemWalletKey(key).ConfigureAwait(false);
1203+
}
1204+
11961205
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: " + result.PurchaseResult + ((result.Items != null) && (result.Items.Count > 0) ? " | Items: " + string.Join("", result.Items) : ""));
11971206

11981207
key = reader.ReadLine(); // Next key

ArchiSteamFarm/JSON/Steam.cs

+11
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ internal bool IsFairTypesExchange() {
311311
}
312312
}
313313

314+
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
315+
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
316+
internal sealed class RedeemWalletResponse { // Deserialized from JSON
317+
#pragma warning disable 649
318+
[JsonProperty(PropertyName = "detail", Required = Required.Always)]
319+
internal readonly ArchiHandler.PurchaseResponseCallback.EPurchaseResult PurchaseResult;
320+
#pragma warning restore 649
321+
322+
private RedeemWalletResponse() { }
323+
}
324+
314325
[SuppressMessage("ReSharper", "UnusedMember.Global")]
315326
internal sealed class TradeOfferRequest { // Constructed from code
316327
internal sealed class ItemList {

0 commit comments

Comments
 (0)