mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Add support for steam wallet keys, #239
This commit is contained in:
@@ -120,19 +120,22 @@ namespace ArchiSteamFarm {
|
||||
internal sealed class PurchaseResponseCallback : CallbackMsg {
|
||||
internal enum EPurchaseResult : sbyte {
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
Unknown = -1,
|
||||
Unknown = -2,
|
||||
Timeout = -1,
|
||||
OK = 0,
|
||||
AlreadyOwned = 9,
|
||||
RegionLocked = 13,
|
||||
InvalidKey = 14,
|
||||
DuplicatedKey = 15,
|
||||
BaseGameRequired = 24,
|
||||
SteamWalletCode = 50,
|
||||
OnCooldown = 53
|
||||
}
|
||||
|
||||
internal readonly EPurchaseResult PurchaseResult;
|
||||
internal readonly Dictionary<uint, string> Items;
|
||||
|
||||
internal EPurchaseResult PurchaseResult { get; set; }
|
||||
|
||||
internal PurchaseResponseCallback(JobID jobID, CMsgClientPurchaseResponse msg) {
|
||||
if ((jobID == null) || (msg == null)) {
|
||||
throw new ArgumentNullException(nameof(jobID) + " || " + nameof(msg));
|
||||
|
||||
@@ -554,6 +554,25 @@ namespace ArchiSteamFarm {
|
||||
return null;
|
||||
}
|
||||
|
||||
internal async Task<ArchiHandler.PurchaseResponseCallback.EPurchaseResult> RedeemWalletKey(string key) {
|
||||
if (string.IsNullOrEmpty(key)) {
|
||||
Logging.LogNullError(nameof(key), Bot.BotName);
|
||||
return ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Unknown;
|
||||
}
|
||||
|
||||
if (!await RefreshSessionIfNeeded().ConfigureAwait(false)) {
|
||||
return ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout;
|
||||
}
|
||||
|
||||
string request = SteamStoreURL + "/account/validatewalletcode";
|
||||
Dictionary<string, string> data = new Dictionary<string, string>(1) {
|
||||
{ "wallet_code", key }
|
||||
};
|
||||
|
||||
Steam.RedeemWalletResponse response = await WebBrowser.UrlPostToJsonResultRetry<Steam.RedeemWalletResponse>(request, data).ConfigureAwait(false);
|
||||
return response?.PurchaseResult ?? ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout;
|
||||
}
|
||||
|
||||
internal HashSet<Steam.TradeOffer> GetActiveTradeOffers() {
|
||||
if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
|
||||
Logging.LogNullError(nameof(Bot.BotConfig.SteamApiKey), Bot.BotName);
|
||||
|
||||
@@ -1186,13 +1186,22 @@ namespace ArchiSteamFarm {
|
||||
} else {
|
||||
ArchiHandler.PurchaseResponseCallback result = await currentBot.ArchiHandler.RedeemKey(key).ConfigureAwait(false);
|
||||
if (result == null) {
|
||||
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: Timeout!");
|
||||
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: " + ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout);
|
||||
currentBot = null; // Either bot will be changed, or loop aborted
|
||||
} else {
|
||||
switch (result.PurchaseResult) {
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.DuplicatedKey:
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.InvalidKey:
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.OK:
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.SteamWalletCode:
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Timeout:
|
||||
case ArchiHandler.PurchaseResponseCallback.EPurchaseResult.Unknown:
|
||||
if (result.PurchaseResult == ArchiHandler.PurchaseResponseCallback.EPurchaseResult.SteamWalletCode) {
|
||||
// If it's a wallet code, try to redeem it, and forward the result
|
||||
// The result is final, there is no place for forwarding
|
||||
result.PurchaseResult = await currentBot.ArchiWebHandler.RedeemWalletKey(key).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
response.Append(Environment.NewLine + "<" + currentBot.BotName + "> Key: " + key + " | Status: " + result.PurchaseResult + ((result.Items != null) && (result.Items.Count > 0) ? " | Items: " + string.Join("", result.Items) : ""));
|
||||
|
||||
key = reader.ReadLine(); // Next key
|
||||
|
||||
@@ -311,6 +311,17 @@ namespace ArchiSteamFarm.JSON {
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "ClassCannotBeInstantiated")]
|
||||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
|
||||
internal sealed class RedeemWalletResponse { // Deserialized from JSON
|
||||
#pragma warning disable 649
|
||||
[JsonProperty(PropertyName = "detail", Required = Required.Always)]
|
||||
internal readonly ArchiHandler.PurchaseResponseCallback.EPurchaseResult PurchaseResult;
|
||||
#pragma warning restore 649
|
||||
|
||||
private RedeemWalletResponse() { }
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Global")]
|
||||
internal sealed class TradeOfferRequest { // Constructed from code
|
||||
internal sealed class ItemList {
|
||||
|
||||
Reference in New Issue
Block a user