From 0a6843e46ac1e4c068dd02ee9ac30d1623c04924 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 25 Aug 2016 15:27:40 -0400 Subject: [PATCH 1/9] Added --trade to list all trade confirmations --- Program.cs | 60 +++++++++++++++++++++++++++++++++++++++++++ steamguard-cli.csproj | 5 +++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index c058c33..2f057d8 100644 --- a/Program.cs +++ b/Program.cs @@ -39,6 +39,8 @@ public static class Program Console.WriteLine("--generate-code Generate a Steam Guard code and exit. (default)"); Console.WriteLine("--encrypt Encrypt your maFiles or change your encryption passkey."); Console.WriteLine("--decrypt Remove encryption from your maFiles."); + Console.WriteLine("--trade List all trade confirmations across all accounts, or of the user\n" + + " specified with --user"); return; } Verbose = args.Contains("-v") || args.Contains("--verbose"); @@ -58,6 +60,10 @@ public static class Program else if (args.Contains("--setup")) { action = "setup"; + } + else if (args.Contains("--trade")) + { + action = "trade"; } // Misc if (args.Contains("--user") || args.Contains("-u")) @@ -112,6 +118,9 @@ public static class Program case "setup": throw new NotSupportedException(); break; + case "trade": + TradeList(user); + break; default: Console.WriteLine("error: Unknown action: {0}", action); return; @@ -220,4 +229,55 @@ public static class Program } return true; } + + static void TradeList(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()) + { + showTradeConfirmations(account); + break; + } + } + else + { + showTradeConfirmations(account); + } + } + } + + static void showTradeConfirmations(SteamGuardAccount account) + { + Console.WriteLine($"Checking trade confirmations for {account.AccountName}..."); + if (Verbose) Console.WriteLine("Refeshing Session..."); + account.RefreshSession(); + + Confirmation[] trades = account.FetchConfirmations(); + foreach (var trade in trades) + { + Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}"); + } + } } diff --git a/steamguard-cli.csproj b/steamguard-cli.csproj index b540346..bd94864 100644 --- a/steamguard-cli.csproj +++ b/steamguard-cli.csproj @@ -52,6 +52,9 @@ .\build\SteamAuth.dll + + ..\..\..\..\..\usr\lib\mono\4.5\System.dll + - + \ No newline at end of file From 11ff450c25552814cb5c0750d270a88b95b781f8 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 25 Aug 2016 15:44:16 -0400 Subject: [PATCH 2/9] added --accept-all --- Program.cs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 2f057d8..12c38b1 100644 --- a/Program.cs +++ b/Program.cs @@ -41,7 +41,9 @@ public static class Program Console.WriteLine("--decrypt Remove encryption from your maFiles."); Console.WriteLine("--trade List all trade confirmations across all accounts, or of the user\n" + " specified with --user"); - return; + Console.WriteLine("--accept-all Accept all trade confirmations on all accounts, or all confirmations of\n" + + " the user specified with --user."); + return; } Verbose = args.Contains("-v") || args.Contains("--verbose"); // Actions @@ -64,6 +66,10 @@ public static class Program else if (args.Contains("--trade")) { action = "trade"; + } + else if (args.Contains("--accept-all")) + { + action = "accept-all"; } // Misc if (args.Contains("--user") || args.Contains("-u")) @@ -121,6 +127,9 @@ public static class Program case "trade": TradeList(user); break; + case "accept-all": + AcceptAllTrades(user); + break; default: Console.WriteLine("error: Unknown action: {0}", action); return; @@ -280,4 +289,54 @@ public static class Program Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}"); } } + + 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); + } + } + } } From 872cfb50c15d1001316c4bd65aec906818548d4a Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 25 Aug 2016 15:27:40 -0400 Subject: [PATCH 3/9] Added --trade to list all trade confirmations --- Program.cs | 55 +++++++++++++++++++++++++++++++++++++++++++ steamguard-cli.csproj | 5 +++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 381c7b9..babf177 100644 --- a/Program.cs +++ b/Program.cs @@ -103,6 +103,7 @@ public static class Program return; } } + if (Verbose) Console.WriteLine("maFiles path: {0}", SteamGuardPath); if (Verbose) Console.WriteLine($"Action: {action}"); if (Verbose) Console.WriteLine($"User: {user}"); @@ -123,6 +124,9 @@ public static class Program case "setup": throw new NotSupportedException(); break; + case "trade": + TradeList(user); + break; default: Console.WriteLine("error: Unknown action: {0}", action); return; @@ -296,4 +300,55 @@ public static class Program } return true; } + + static void TradeList(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()) + { + showTradeConfirmations(account); + break; + } + } + else + { + showTradeConfirmations(account); + } + } + } + + static void showTradeConfirmations(SteamGuardAccount account) + { + Console.WriteLine($"Checking trade confirmations for {account.AccountName}..."); + if (Verbose) Console.WriteLine("Refeshing Session..."); + account.RefreshSession(); + + Confirmation[] trades = account.FetchConfirmations(); + foreach (var trade in trades) + { + Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}"); + } + } } diff --git a/steamguard-cli.csproj b/steamguard-cli.csproj index b540346..bd94864 100644 --- a/steamguard-cli.csproj +++ b/steamguard-cli.csproj @@ -52,6 +52,9 @@ .\build\SteamAuth.dll + + ..\..\..\..\..\usr\lib\mono\4.5\System.dll + - + \ No newline at end of file From bc46eeba18d7602be9341418a9876beeaea6dbd6 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Thu, 25 Aug 2016 15:44:16 -0400 Subject: [PATCH 4/9] added --accept-all --- Program.cs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index babf177..c43f529 100644 --- a/Program.cs +++ b/Program.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -127,6 +126,9 @@ public static class Program case "trade": TradeList(user); break; + case "accept-all": + AcceptAllTrades(user); + break; default: Console.WriteLine("error: Unknown action: {0}", action); return; @@ -351,4 +353,54 @@ public static class Program Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}"); } } + + 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); + } + } + } } From 3055a27288249661637db5868c46135946be3e7f Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 26 Aug 2016 09:34:28 -0400 Subject: [PATCH 5/9] added a menu to decide what to do with trade confirmations --- Program.cs | 128 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 107 insertions(+), 21 deletions(-) diff --git a/Program.cs b/Program.cs index c43f529..544c4db 100644 --- a/Program.cs +++ b/Program.cs @@ -60,6 +60,10 @@ public static class Program { action = "setup"; } + else if (args[i] == "trade") + { + action = "trade"; + } else if (args[i] == "encrypt") { action = "encrypt"; @@ -124,7 +128,7 @@ public static class Program throw new NotSupportedException(); break; case "trade": - TradeList(user); + Trade(user); break; case "accept-all": AcceptAllTrades(user); @@ -303,14 +307,14 @@ public static class Program return true; } - static void TradeList(string user = "") + static void Trade(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(); + var passkey = Manifest.PromptForPassKey(); SteamGuardAccounts = Manifest.GetAllAccounts(passkey); } else @@ -323,35 +327,117 @@ public static class Program return; } - for (int i = 0; i < SteamGuardAccounts.Length; i++) + foreach (var account in SteamGuardAccounts) { - SteamGuardAccount account = SteamGuardAccounts[i]; if (user != "") - { - if (account.AccountName.ToLower() == user.ToLower()) - { - showTradeConfirmations(account); + if (!string.Equals(account.AccountName, user, StringComparison.CurrentCultureIgnoreCase)) break; - } - } - else - { - showTradeConfirmations(account); - } + + processConfirmations(account); } } - static void showTradeConfirmations(SteamGuardAccount account) + enum TradeAction + { + Accept = 1, + Deny = 0, + Ignore = -1 + } + + static void processConfirmations(SteamGuardAccount account) { - Console.WriteLine($"Checking trade confirmations for {account.AccountName}..."); if (Verbose) Console.WriteLine("Refeshing Session..."); account.RefreshSession(); - - Confirmation[] trades = account.FetchConfirmations(); - foreach (var trade in trades) + Console.WriteLine("Retrieving trade confirmations..."); + var trades = account.FetchConfirmations(); + var tradeActions = new TradeAction[trades.Length]; + for (var i = 0; i < tradeActions.Length; i++) { - Console.WriteLine($"ID: {trade.ID} Key: {trade.Key} Description: {trade.Description}"); + tradeActions[i] = TradeAction.Ignore; } + 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; + + var colorBackground = Console.BackgroundColor; + 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."); + Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm"); // accept = 1, deny = 0, ignore = -1 + 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(); + } + + if (t == selected) + { + Console.BackgroundColor = itemColor; + Console.ForegroundColor = colorBackground; + } + else + { + Console.ForegroundColor = itemColor; + Console.BackgroundColor = colorBackground; + } + + 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; + default: + break; + } + } while (!confirm); + + } static void AcceptAllTrades(string user = "") From f6b11f4975815172b8ccdc9bd9b2ccd18f6bb719 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 26 Aug 2016 09:38:41 -0400 Subject: [PATCH 6/9] added a quit key to the trade menu --- Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Program.cs b/Program.cs index 544c4db..fd03a31 100644 --- a/Program.cs +++ b/Program.cs @@ -378,7 +378,7 @@ public static class Program Console.ResetColor(); Console.WriteLine($"Trade confirmations for {account.AccountName}..."); Console.WriteLine("No action will be made without your confirmation."); - Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm"); // accept = 1, deny = 0, ignore = -1 + Console.WriteLine("[a]ccept [d]eny [i]gnore [enter] Confirm [q]uit"); // accept = 1, deny = 0, ignore = -1 Console.WriteLine(); for (var t = 0; t < trades.Length; t++) @@ -432,6 +432,10 @@ public static class Program case ConsoleKey.I: tradeActions[selected] = TradeAction.Ignore; break; + case ConsoleKey.Escape: + case ConsoleKey.Q: + Console.WriteLine("Quitting..."); + return; default: break; } From 52175ef6425de3f0fbe83c59d7a22bf6f040f16e Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 26 Aug 2016 18:11:44 -0400 Subject: [PATCH 7/9] fixed weird coloring issues and added confirm key to trade menu --- Program.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Program.cs b/Program.cs index fd03a31..6fbac53 100644 --- a/Program.cs +++ b/Program.cs @@ -364,8 +364,7 @@ public static class Program var colorAccept = ConsoleColor.Green; var colorDeny = ConsoleColor.Red; var colorIgnore = ConsoleColor.Gray; - - var colorBackground = Console.BackgroundColor; + var colorSelected = ConsoleColor.Yellow; var confirm = false; do @@ -399,16 +398,7 @@ public static class Program throw new ArgumentOutOfRangeException(); } - if (t == selected) - { - Console.BackgroundColor = itemColor; - Console.ForegroundColor = colorBackground; - } - else - { - Console.ForegroundColor = itemColor; - Console.BackgroundColor = colorBackground; - } + Console.ForegroundColor = t == selected ? colorSelected : itemColor; Console.WriteLine($" [{t}] [{tradeActions[t]}] {trades[t].Description}"); } @@ -432,14 +422,19 @@ public static class Program case ConsoleKey.I: tradeActions[selected] = TradeAction.Ignore; break; + case ConsoleKey.Enter: + confirm = true; + break; case ConsoleKey.Escape: case ConsoleKey.Q: + Console.ResetColor(); Console.WriteLine("Quitting..."); return; default: break; } } while (!confirm); + Console.ResetColor(); } From f1e9c672e1d738d8d76902b04e96f81df62d1fe5 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 26 Aug 2016 20:07:15 -0400 Subject: [PATCH 8/9] trades are now processed when confirmed --- Program.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 6fbac53..b8e6621 100644 --- a/Program.cs +++ b/Program.cs @@ -435,8 +435,28 @@ public static class Program } } while (!confirm); Console.ResetColor(); - - + 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."); } static void AcceptAllTrades(string user = "") From 18af4d37146b6deecff6ff8f9227b29f5630be49 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 27 Aug 2016 17:34:21 -0400 Subject: [PATCH 9/9] added success indicator when processing trades --- Program.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Program.cs b/Program.cs index b8e6621..cb5d3e9 100644 --- a/Program.cs +++ b/Program.cs @@ -439,22 +439,25 @@ public static class Program Console.WriteLine("Processing..."); for (var t = 0; t < trades.Length; t++) { + bool success = false; switch (tradeActions[t]) { case TradeAction.Accept: - if (Verbose) Console.WriteLine($"Accepting {trades[t].Description}..."); - account.AcceptConfirmation(trades[t]); + if (Verbose) Console.Write($"Accepting {trades[t].Description}..."); + success = account.AcceptConfirmation(trades[t]); break; case TradeAction.Deny: - if (Verbose) Console.WriteLine($"Denying {trades[t].Description}..."); - account.AcceptConfirmation(trades[t]); + if (Verbose) Console.Write($"Denying {trades[t].Description}..."); + success = account.AcceptConfirmation(trades[t]); break; case TradeAction.Ignore: - if (Verbose) Console.WriteLine($"Ignoring {trades[t].Description}..."); + if (Verbose) Console.Write($"Ignoring {trades[t].Description}..."); + success = true; break; default: throw new ArgumentOutOfRangeException(); } + if (Verbose) Console.WriteLine(success); } Console.WriteLine("Done."); }