2016-08-23 16:38:53 +02:00
|
|
|
|
using Newtonsoft.Json;
|
2016-08-21 20:17:04 +02:00
|
|
|
|
using SteamAuth;
|
2016-08-21 17:29:27 +02:00
|
|
|
|
using System;
|
2016-08-21 20:17:04 +02:00
|
|
|
|
using System.Collections.Generic;
|
2016-08-21 19:03:43 +02:00
|
|
|
|
using System.IO;
|
2016-08-21 20:17:04 +02:00
|
|
|
|
using System.Linq;
|
2016-08-24 19:01:49 +02:00
|
|
|
|
using System.Reflection;
|
2016-08-21 20:17:04 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-08-21 17:29:27 +02:00
|
|
|
|
|
2016-08-21 17:38:03 +02:00
|
|
|
|
public static class Program
|
2016-08-21 17:29:27 +02:00
|
|
|
|
{
|
2016-08-26 03:52:21 +02:00
|
|
|
|
public const string defaultSteamGuardPath = "~/maFiles";
|
2016-08-21 19:03:43 +02:00
|
|
|
|
|
|
|
|
|
public static string SteamGuardPath { get; set; } = defaultSteamGuardPath;
|
2016-08-21 23:02:17 +02:00
|
|
|
|
public static Manifest Manifest { get; set; }
|
|
|
|
|
public static SteamGuardAccount[] SteamGuardAccounts { get; set; }
|
2016-08-22 01:24:23 +02:00
|
|
|
|
public static bool Verbose { get; set; } = false;
|
2016-08-21 19:03:43 +02:00
|
|
|
|
|
2016-08-21 17:38:03 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
public static void Main(string[] args)
|
2016-08-21 17:34:48 +02:00
|
|
|
|
{
|
2016-08-26 01:21:34 +02:00
|
|
|
|
string action = "";
|
2016-08-22 01:24:23 +02:00
|
|
|
|
string user = "";
|
|
|
|
|
|
2016-08-26 01:21:34 +02:00
|
|
|
|
// Parse cli arguments
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (args[i].StartsWith("-"))
|
|
|
|
|
{
|
|
|
|
|
if (args[i] == "-v" || args[i] == "--verbose")
|
|
|
|
|
{
|
|
|
|
|
Verbose = true;
|
|
|
|
|
}
|
|
|
|
|
else if (args[i] == "-m" || args[i] == "--mafiles-path")
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
if (i < args.Length)
|
|
|
|
|
SteamGuardPath = args[i];
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Expected path after {args[i-1]}");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (args[i] == "--help" || args[i] == "-h")
|
|
|
|
|
{
|
|
|
|
|
ShowHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else // Parse as action or username
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(action))
|
|
|
|
|
{
|
2016-08-26 03:25:14 +02:00
|
|
|
|
if (args[i] == "add" || args[i] == "setup")
|
2016-08-26 01:21:34 +02:00
|
|
|
|
{
|
|
|
|
|
action = "setup";
|
|
|
|
|
}
|
2016-08-26 15:34:28 +02:00
|
|
|
|
else if (args[i] == "trade")
|
|
|
|
|
{
|
|
|
|
|
action = "trade";
|
|
|
|
|
}
|
2016-08-26 01:21:34 +02:00
|
|
|
|
else if (args[i] == "encrypt")
|
|
|
|
|
{
|
|
|
|
|
action = "encrypt";
|
|
|
|
|
}
|
|
|
|
|
else if (args[i] == "decrypt")
|
|
|
|
|
{
|
|
|
|
|
action = "decrypt";
|
|
|
|
|
}
|
|
|
|
|
else if (args[i] == "remove")
|
|
|
|
|
{
|
|
|
|
|
action = "remove";
|
|
|
|
|
}
|
|
|
|
|
else if (args[i] == "2fa" || args[i] == "code" || args[i] == "generate-code")
|
|
|
|
|
{
|
|
|
|
|
action = "generate-code";
|
|
|
|
|
}
|
2016-08-26 03:21:06 +02:00
|
|
|
|
else if (string.IsNullOrEmpty(user))
|
|
|
|
|
user = args[i];
|
2016-08-26 01:21:34 +02:00
|
|
|
|
}
|
2016-08-26 03:21:06 +02:00
|
|
|
|
else if (string.IsNullOrEmpty(user))
|
2016-08-26 01:21:34 +02:00
|
|
|
|
user = args[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-21 19:03:43 +02:00
|
|
|
|
|
2016-08-26 01:21:34 +02:00
|
|
|
|
if (string.IsNullOrEmpty(action))
|
|
|
|
|
action = "generate-code";
|
|
|
|
|
|
|
|
|
|
// Do some configuring
|
2016-08-21 19:03:43 +02:00
|
|
|
|
SteamGuardPath = SteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME"));
|
|
|
|
|
if (!Directory.Exists(SteamGuardPath))
|
|
|
|
|
{
|
|
|
|
|
if (SteamGuardPath == defaultSteamGuardPath.Replace("~", Environment.GetEnvironmentVariable("HOME")))
|
|
|
|
|
{
|
2016-08-22 01:24:23 +02:00
|
|
|
|
if (Verbose) Console.WriteLine("warn: {0} does not exist, creating...", SteamGuardPath);
|
2016-08-21 19:03:43 +02:00
|
|
|
|
Directory.CreateDirectory(SteamGuardPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("error: {0} does not exist.", SteamGuardPath);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-21 17:38:03 +02:00
|
|
|
|
}
|
2016-08-25 21:27:40 +02:00
|
|
|
|
if (Verbose) Console.WriteLine("maFiles path: {0}", SteamGuardPath);
|
2016-08-22 01:24:23 +02:00
|
|
|
|
|
2016-08-26 01:21:34 +02:00
|
|
|
|
if (Verbose) Console.WriteLine($"Action: {action}");
|
|
|
|
|
if (Verbose) Console.WriteLine($"User: {user}");
|
|
|
|
|
if (Verbose) Console.WriteLine($"maFiles path: {SteamGuardPath}");
|
|
|
|
|
|
2016-08-23 01:16:43 +02:00
|
|
|
|
// Perform desired action
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case "generate-code":
|
|
|
|
|
GenerateCode(user);
|
|
|
|
|
break;
|
2016-08-23 03:12:48 +02:00
|
|
|
|
case "encrypt": // Can also be used to change passkey
|
2016-08-23 19:58:00 +02:00
|
|
|
|
Console.WriteLine(Encrypt());
|
2016-08-23 01:16:43 +02:00
|
|
|
|
break;
|
|
|
|
|
case "decrypt":
|
2016-08-23 19:58:00 +02:00
|
|
|
|
Console.WriteLine(Decrypt());
|
2016-08-23 01:16:43 +02:00
|
|
|
|
break;
|
|
|
|
|
case "setup":
|
2016-08-23 03:20:55 +02:00
|
|
|
|
throw new NotSupportedException();
|
2016-08-23 01:16:43 +02:00
|
|
|
|
break;
|
2016-08-25 21:27:40 +02:00
|
|
|
|
case "trade":
|
2016-08-26 15:34:28 +02:00
|
|
|
|
Trade(user);
|
2016-08-25 21:27:40 +02:00
|
|
|
|
break;
|
2016-08-25 21:44:16 +02:00
|
|
|
|
case "accept-all":
|
|
|
|
|
AcceptAllTrades(user);
|
|
|
|
|
break;
|
2016-08-23 01:16:43 +02:00
|
|
|
|
default:
|
|
|
|
|
Console.WriteLine("error: Unknown action: {0}", action);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-25 23:23:16 +02:00
|
|
|
|
static void ShowHelp()
|
|
|
|
|
{
|
2016-08-26 02:11:56 +02:00
|
|
|
|
var descPadding = 26;
|
2016-08-26 03:15:47 +02:00
|
|
|
|
var descWidth = Console.BufferWidth - descPadding;
|
|
|
|
|
if (descWidth < 20)
|
|
|
|
|
descWidth = 20;
|
|
|
|
|
else if (descWidth > 56)
|
|
|
|
|
descWidth = 56;
|
|
|
|
|
|
2016-08-26 02:11:56 +02:00
|
|
|
|
var flags = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "-h, --help", "Display this help message." },
|
|
|
|
|
{ "-v, --verbose", "Display some extra information when the program is running." },
|
|
|
|
|
{ "-m, --mafiles", "Specify which folder your maFiles are in. Ex: ~/maFiles" },
|
|
|
|
|
};
|
|
|
|
|
var actions = new Dictionary<string, string>
|
|
|
|
|
{
|
|
|
|
|
{ "generate-code", "Generate a Steam Guard code for the specified user (if any) and exit. (default)" },
|
|
|
|
|
{ "encrypt", "Encrypt your maFiles or change your encryption passkey." },
|
|
|
|
|
{ "decrypt", "Remove encryption from your maFiles." },
|
|
|
|
|
{ "code", "Same as generate-code" },
|
|
|
|
|
{ "2fa", "Same as generate-code" },
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-25 23:23:16 +02:00
|
|
|
|
Console.WriteLine($"steamguard-cli - v{Assembly.GetExecutingAssembly().GetName().Version}");
|
2016-08-26 02:11:56 +02:00
|
|
|
|
Console.WriteLine("usage: steamguard (action) (steam username) -v -h");
|
|
|
|
|
Console.WriteLine();
|
|
|
|
|
foreach (var flag in flags)
|
|
|
|
|
{
|
2016-08-26 03:15:47 +02:00
|
|
|
|
// word wrap the descriptions, if needed
|
|
|
|
|
var desc = flag.Value;
|
|
|
|
|
if (desc.Length > descWidth)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < desc.Length; i += descWidth)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0)
|
|
|
|
|
sb.Append("".PadLeft((flag.Key.StartsWith("--") ? 5 : 2) + descPadding));
|
|
|
|
|
sb.AppendLine(desc.Substring(i, i + descWidth > desc.Length ? desc.Length - i : descWidth).Trim());
|
|
|
|
|
}
|
|
|
|
|
desc = sb.ToString().TrimEnd('\n');
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine($"{(flag.Key.StartsWith("--") ? " " : " " )}{flag.Key.PadRight(descPadding)}{desc}");
|
2016-08-26 02:11:56 +02:00
|
|
|
|
}
|
2016-08-25 23:23:16 +02:00
|
|
|
|
Console.WriteLine();
|
2016-08-26 02:11:56 +02:00
|
|
|
|
Console.WriteLine("Actions:");
|
|
|
|
|
foreach (var action in actions)
|
|
|
|
|
{
|
2016-08-26 03:15:47 +02:00
|
|
|
|
// word wrap the descriptions, if needed
|
|
|
|
|
var desc = action.Value;
|
|
|
|
|
if (desc.Length > descWidth)
|
|
|
|
|
{
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
for (int i = 0; i < desc.Length; i += descWidth)
|
|
|
|
|
{
|
|
|
|
|
if (i > 0)
|
|
|
|
|
sb.Append("".PadLeft(descPadding + 2));
|
|
|
|
|
sb.AppendLine(desc.Substring(i, i + descWidth > desc.Length ? desc.Length - i : descWidth).Trim());
|
|
|
|
|
}
|
|
|
|
|
desc = sb.ToString().TrimEnd('\n');
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine($" {action.Key.PadRight(descPadding)}{desc}");
|
2016-08-26 02:11:56 +02:00
|
|
|
|
}
|
2016-08-25 23:23:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 01:16:43 +02:00
|
|
|
|
static void GenerateCode(string user = "")
|
|
|
|
|
{
|
2016-08-22 01:24:23 +02:00
|
|
|
|
if (Verbose) Console.WriteLine("Aligning time...");
|
|
|
|
|
TimeAligner.AlignTime();
|
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
2016-08-22 21:51:37 +02:00
|
|
|
|
if (Manifest.Encrypted)
|
|
|
|
|
{
|
|
|
|
|
string passkey = Manifest.PromptForPassKey();
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts();
|
|
|
|
|
}
|
2016-08-22 01:24:23 +02:00
|
|
|
|
if (SteamGuardAccounts.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("error: No accounts read.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Verbose) Console.WriteLine("Selecting account...");
|
|
|
|
|
string code = "";
|
|
|
|
|
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccount account = SteamGuardAccounts[i];
|
|
|
|
|
if (user != "")
|
|
|
|
|
{
|
|
|
|
|
if (account.AccountName.ToLower() == user.ToLower())
|
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Generating Code...");
|
|
|
|
|
code = account.GenerateSteamGuardCode();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Generating Code for {0}...", account.AccountName);
|
|
|
|
|
code = account.GenerateSteamGuardCode();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (code != "")
|
|
|
|
|
Console.WriteLine(code);
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine("error: No Steam accounts found in {0}", SteamGuardAccounts);
|
2016-08-21 17:34:48 +02:00
|
|
|
|
}
|
2016-08-23 03:12:48 +02:00
|
|
|
|
|
2016-08-23 19:58:00 +02:00
|
|
|
|
static bool Encrypt()
|
2016-08-23 03:12:48 +02:00
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
|
|
|
|
if (Manifest.Encrypted)
|
|
|
|
|
{
|
|
|
|
|
string passkey = Manifest.PromptForPassKey();
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string newPassKey = Manifest.PromptSetupPassKey();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var account = SteamGuardAccounts[i];
|
2016-08-23 19:49:52 +02:00
|
|
|
|
var salt = Manifest.GetRandomSalt();
|
|
|
|
|
var iv = Manifest.GetInitializationVector();
|
|
|
|
|
bool success = Manifest.SaveAccount(account, true, newPassKey, salt, iv);
|
2016-08-23 03:12:48 +02:00
|
|
|
|
if (Verbose) Console.WriteLine("Encrypted {0}: {1}", account.AccountName, success);
|
2016-08-23 19:58:00 +02:00
|
|
|
|
if (!success) return false;
|
2016-08-23 03:12:48 +02:00
|
|
|
|
}
|
2016-08-23 19:58:00 +02:00
|
|
|
|
return true;
|
2016-08-23 03:12:48 +02:00
|
|
|
|
}
|
2016-08-23 04:16:47 +02:00
|
|
|
|
|
2016-08-23 19:58:00 +02:00
|
|
|
|
static bool Decrypt()
|
2016-08-23 04:16:47 +02:00
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
|
|
|
|
if (Manifest.Encrypted)
|
|
|
|
|
{
|
|
|
|
|
string passkey = Manifest.PromptForPassKey();
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Decryption not required.");
|
2016-08-23 19:58:00 +02:00
|
|
|
|
return true;
|
2016-08-23 04:16:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var account = SteamGuardAccounts[i];
|
|
|
|
|
bool success = Manifest.SaveAccount(account, false);
|
|
|
|
|
if (Verbose) Console.WriteLine("Decrypted {0}: {1}", account.AccountName, success);
|
2016-08-23 19:58:00 +02:00
|
|
|
|
if (!success) return false;
|
2016-08-23 04:16:47 +02:00
|
|
|
|
}
|
2016-08-23 19:58:00 +02:00
|
|
|
|
return true;
|
2016-08-23 04:16:47 +02:00
|
|
|
|
}
|
2016-08-25 21:27:40 +02:00
|
|
|
|
|
2016-08-26 15:34:28 +02:00
|
|
|
|
static void Trade(string user = "")
|
2016-08-25 21:27:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
|
|
|
|
if (Manifest.Encrypted)
|
|
|
|
|
{
|
2016-08-26 15:34:28 +02:00
|
|
|
|
var passkey = Manifest.PromptForPassKey();
|
2016-08-25 21:27:40 +02:00
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts();
|
|
|
|
|
}
|
|
|
|
|
if (SteamGuardAccounts.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("error: No accounts read.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 15:34:28 +02:00
|
|
|
|
foreach (var account in SteamGuardAccounts)
|
2016-08-25 21:27:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (user != "")
|
2016-08-26 15:34:28 +02:00
|
|
|
|
if (!string.Equals(account.AccountName, user, StringComparison.CurrentCultureIgnoreCase))
|
2016-08-25 21:27:40 +02:00
|
|
|
|
break;
|
2016-08-26 15:34:28 +02:00
|
|
|
|
|
|
|
|
|
processConfirmations(account);
|
2016-08-25 21:27:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-26 15:34:28 +02:00
|
|
|
|
enum TradeAction
|
|
|
|
|
{
|
|
|
|
|
Accept = 1,
|
|
|
|
|
Deny = 0,
|
|
|
|
|
Ignore = -1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void processConfirmations(SteamGuardAccount account)
|
2016-08-25 21:27:40 +02:00
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Refeshing Session...");
|
|
|
|
|
account.RefreshSession();
|
2016-08-26 15:34:28 +02:00
|
|
|
|
Console.WriteLine("Retrieving trade confirmations...");
|
|
|
|
|
var trades = account.FetchConfirmations();
|
|
|
|
|
var tradeActions = new TradeAction[trades.Length];
|
|
|
|
|
for (var i = 0; i < tradeActions.Length; i++)
|
2016-08-25 21:27:40 +02:00
|
|
|
|
{
|
2016-08-26 15:34:28 +02:00
|
|
|
|
tradeActions[i] = TradeAction.Ignore;
|
2016-08-25 21:27:40 +02:00
|
|
|
|
}
|
2016-08-26 15:34:28 +02:00
|
|
|
|
if (trades.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"No trade confirmations for {account.AccountName}.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var selected = 0;
|
|
|
|
|
var colorAccept = ConsoleColor.Green;
|
|
|
|
|
var colorDeny = ConsoleColor.Red;
|
|
|
|
|
var colorIgnore = ConsoleColor.Gray;
|
2016-08-27 00:11:44 +02:00
|
|
|
|
var colorSelected = ConsoleColor.Yellow;
|
2016-08-26 15:34:28 +02:00
|
|
|
|
var confirm = false;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
Console.Clear();
|
|
|
|
|
if (selected >= trades.Length)
|
|
|
|
|
selected = trades.Length - 1;
|
|
|
|
|
else if (selected < 0)
|
|
|
|
|
selected = 0;
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
Console.WriteLine($"Trade confirmations for {account.AccountName}...");
|
|
|
|
|
Console.WriteLine("No action will be made without your confirmation.");
|
2016-08-26 15:38:41 +02:00
|
|
|
|
Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm [q]uit"); // accept = 1, deny = 0, ignore = -1
|
2016-08-26 15:34:28 +02:00
|
|
|
|
Console.WriteLine();
|
|
|
|
|
|
|
|
|
|
for (var t = 0; t < trades.Length; t++)
|
|
|
|
|
{
|
|
|
|
|
ConsoleColor itemColor;
|
|
|
|
|
switch (tradeActions[t])
|
|
|
|
|
{
|
|
|
|
|
case TradeAction.Accept:
|
|
|
|
|
itemColor = colorAccept;
|
|
|
|
|
break;
|
|
|
|
|
case TradeAction.Deny:
|
|
|
|
|
itemColor = colorDeny;
|
|
|
|
|
break;
|
|
|
|
|
case TradeAction.Ignore:
|
|
|
|
|
itemColor = colorIgnore;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-27 00:11:44 +02:00
|
|
|
|
Console.ForegroundColor = t == selected ? colorSelected : itemColor;
|
2016-08-26 15:34:28 +02:00
|
|
|
|
|
|
|
|
|
Console.WriteLine($" [{t}] [{tradeActions[t]}] {trades[t].Description}");
|
|
|
|
|
}
|
|
|
|
|
var key = Console.ReadKey();
|
|
|
|
|
switch (key.Key)
|
|
|
|
|
{
|
|
|
|
|
case ConsoleKey.UpArrow:
|
|
|
|
|
case ConsoleKey.W:
|
|
|
|
|
selected--;
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.DownArrow:
|
|
|
|
|
case ConsoleKey.S:
|
|
|
|
|
selected++;
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.A:
|
|
|
|
|
tradeActions[selected] = TradeAction.Accept;
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.D:
|
|
|
|
|
tradeActions[selected] = TradeAction.Deny;
|
|
|
|
|
break;
|
|
|
|
|
case ConsoleKey.I:
|
|
|
|
|
tradeActions[selected] = TradeAction.Ignore;
|
|
|
|
|
break;
|
2016-08-27 00:11:44 +02:00
|
|
|
|
case ConsoleKey.Enter:
|
|
|
|
|
confirm = true;
|
|
|
|
|
break;
|
2016-08-26 15:38:41 +02:00
|
|
|
|
case ConsoleKey.Escape:
|
|
|
|
|
case ConsoleKey.Q:
|
2016-08-27 00:11:44 +02:00
|
|
|
|
Console.ResetColor();
|
2016-08-26 15:38:41 +02:00
|
|
|
|
Console.WriteLine("Quitting...");
|
|
|
|
|
return;
|
2016-08-26 15:34:28 +02:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} while (!confirm);
|
2016-08-27 00:11:44 +02:00
|
|
|
|
Console.ResetColor();
|
2016-08-27 02:07:15 +02:00
|
|
|
|
Console.WriteLine();
|
|
|
|
|
Console.WriteLine("Processing...");
|
|
|
|
|
for (var t = 0; t < trades.Length; t++)
|
|
|
|
|
{
|
|
|
|
|
switch (tradeActions[t])
|
|
|
|
|
{
|
|
|
|
|
case TradeAction.Accept:
|
|
|
|
|
if (Verbose) Console.WriteLine($"Accepting {trades[t].Description}...");
|
|
|
|
|
account.AcceptConfirmation(trades[t]);
|
|
|
|
|
break;
|
|
|
|
|
case TradeAction.Deny:
|
|
|
|
|
if (Verbose) Console.WriteLine($"Denying {trades[t].Description}...");
|
|
|
|
|
account.AcceptConfirmation(trades[t]);
|
|
|
|
|
break;
|
|
|
|
|
case TradeAction.Ignore:
|
|
|
|
|
if (Verbose) Console.WriteLine($"Ignoring {trades[t].Description}...");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new ArgumentOutOfRangeException();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.WriteLine("Done.");
|
2016-08-25 21:27:40 +02:00
|
|
|
|
}
|
2016-08-25 21:44:16 +02:00
|
|
|
|
|
|
|
|
|
static void AcceptAllTrades(string user = "")
|
|
|
|
|
{
|
|
|
|
|
if (Verbose) Console.WriteLine("Opening manifest...");
|
|
|
|
|
Manifest = Manifest.GetManifest(true);
|
|
|
|
|
if (Verbose) Console.WriteLine("Reading accounts from manifest...");
|
|
|
|
|
if (Manifest.Encrypted)
|
|
|
|
|
{
|
|
|
|
|
string passkey = Manifest.PromptForPassKey();
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts(passkey);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccounts = Manifest.GetAllAccounts();
|
|
|
|
|
}
|
|
|
|
|
if (SteamGuardAccounts.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("error: No accounts read.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < SteamGuardAccounts.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
SteamGuardAccount account = SteamGuardAccounts[i];
|
|
|
|
|
if (user != "")
|
|
|
|
|
{
|
|
|
|
|
if (account.AccountName.ToLower() == user.ToLower())
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Accepting Confirmations on {account.AccountName}");
|
|
|
|
|
if (Verbose) Console.WriteLine("Refeshing Session...");
|
|
|
|
|
account.RefreshSession();
|
|
|
|
|
if (Verbose) Console.WriteLine("Fetching Confirmations...");
|
|
|
|
|
Confirmation[] confirmations = account.FetchConfirmations();
|
|
|
|
|
if (Verbose) Console.WriteLine("Accepting Confirmations...");
|
|
|
|
|
account.AcceptMultipleConfirmations(confirmations);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Accepting Confirmations on {account.AccountName}");
|
|
|
|
|
if (Verbose) Console.WriteLine("Refeshing Session...");
|
|
|
|
|
account.RefreshSession();
|
|
|
|
|
if (Verbose) Console.WriteLine("Fetching Confirmations...");
|
|
|
|
|
Confirmation[] confirmations = account.FetchConfirmations();
|
|
|
|
|
if (Verbose) Console.WriteLine("Accepting Confirmations...");
|
|
|
|
|
account.AcceptMultipleConfirmations(confirmations);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-21 17:29:27 +02:00
|
|
|
|
}
|