Skip to content

Commit

Permalink
Continue with spectre
Browse files Browse the repository at this point in the history
  • Loading branch information
xPaw committed May 21, 2024
1 parent ce07406 commit 1d15305
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 150 deletions.
63 changes: 34 additions & 29 deletions ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public async Task<bool> SendTokens(Payload payload, Configuration config)
{
if (config.DumpPayload)
{
AnsiConsole.WriteLine();

var payloadDump = new PayloadDump(payload);
var file = Path.Combine(Program.AppPath, "SteamTokenDumper.payload.json");

Expand All @@ -58,14 +56,18 @@ public async Task<bool> SendTokens(Payload payload, Configuration config)
}
catch (Exception e)
{
AnsiConsole.WriteLine($"Failed to write payload dump: {e}");
AnsiConsole.Write(
new Panel(new Text($"Failed to write payload dump: {e}", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);
}

AnsiConsole.WriteLine();
}

if (config.VerifyBeforeSubmit)
{
AnsiConsole.WriteLine();

// Read any buffered keys so it doesn't auto submit
while (Console.KeyAvailable)
{
Expand All @@ -78,7 +80,6 @@ public async Task<bool> SendTokens(Payload payload, Configuration config)

AnsiConsole.WriteLine();
AnsiConsole.WriteLine("Submitting tokens to SteamDB...");
AnsiConsole.WriteLine();

var postData = JsonSerializer.Serialize(payload, PayloadJsonContext.Default.Payload);

Expand All @@ -89,10 +90,11 @@ public async Task<bool> SendTokens(Payload payload, Configuration config)
var output = await result.Content.ReadAsStringAsync();
output = output.Trim();

Console.ForegroundColor = result.IsSuccessStatusCode ? ConsoleColor.Blue : ConsoleColor.Red;
Console.WriteLine(output);
Console.ResetColor();
Console.WriteLine();
AnsiConsole.Write(
new Panel(new Text(output, new Style(result.IsSuccessStatusCode ? Color.CadetBlue : Color.Red)))
.BorderColor(result.IsSuccessStatusCode ? Color.Blue : Color.Red)
.RoundedBorder()
);

try
{
Expand All @@ -112,16 +114,18 @@ public async Task<bool> SendTokens(Payload payload, Configuration config)

result.EnsureSuccessStatusCode();

Console.WriteLine();
Console.WriteLine();
AnsiConsole.WriteLine();
AnsiConsole.WriteLine();

return true;
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
await Console.Error.WriteLineAsync($"Whoops, failed to submit tokens to SteamDB: {e}");
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text($"Failed to submit tokens to SteamDB: {e}", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);
}

return false;
Expand All @@ -146,22 +150,22 @@ public async Task<bool> IsUpToDate()

if (versionInt != Version)
{
Console.ForegroundColor = ConsoleColor.Green;
await Console.Error.WriteLineAsync("[!] There is a new version of token dumper available.");
await Console.Error.WriteLineAsync("[!] Please download the new version.");
await Console.Error.WriteLineAsync();
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text("There is a new version of the token dumper available.\nPlease download the new version.", new Style(Color.Green)))
.BorderColor(Color.GreenYellow)
.RoundedBorder()
);

return false;
}
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
await Console.Error.WriteLineAsync($"[!] Update check failed: {e}");
await Console.Error.WriteLineAsync("[!] Your submission will most likely fail.");
await Console.Error.WriteLineAsync();
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text($"Update check failed: {e}\n\nYour submission will most likely fail.", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);

return false;
}
Expand Down Expand Up @@ -197,10 +201,11 @@ public async Task<ImmutableHashSet<uint>> GetBackendKnownDepotIds()
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
await Console.Error.WriteLineAsync($"[!] Failed to get list of depots to skip: {e}");
await Console.Error.WriteLineAsync();
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text($"Failed to get list of depots to skip: {e}", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);
}

return [];
Expand Down
42 changes: 42 additions & 0 deletions ConsoleAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Threading.Tasks;
using Spectre.Console;
using SteamKit2.Authentication;

namespace SteamTokenDumper;

internal class ConsoleAuthenticator : IAuthenticator

Check warning on line 7 in ConsoleAuthenticator.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Type 'ConsoleAuthenticator' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check warning on line 7 in ConsoleAuthenticator.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Type 'ConsoleAuthenticator' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
{
/// <inheritdoc />
public Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
{
if (previousCodeWasIncorrect)
{
AnsiConsole.MarkupLine("[red]The previous two-factor auth code you have provided is incorrect.[/]");
}

var code = AnsiConsole.Ask<string>("[green][bold]STEAM GUARD![/][/] Enter your two-factor code from your authenticator app:").Trim();

return Task.FromResult(code);
}

/// <inheritdoc />
public Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
{
if (previousCodeWasIncorrect)
{
AnsiConsole.MarkupLine("[red]The previous two-factor auth code you have provided is incorrect.[/]");
}

var code = AnsiConsole.Ask<string>($"[green][bold]STEAM GUARD![/][/] Please enter the auth code sent to the email at {Markup.Escape(email)}:").Trim();

return Task.FromResult(code);
}

/// <inheritdoc />
public Task<bool> AcceptDeviceConfirmationAsync()
{
AnsiConsole.MarkupLine("[green][bold]STEAM GUARD![/][/] Use the Steam Mobile App to confirm your sign in...");

return Task.FromResult(true);
}
}
29 changes: 29 additions & 0 deletions IntValueProgressColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using Spectre.Console;
using Spectre.Console.Rendering;

namespace SteamTokenDumper;

internal class IntValueProgressColumn : ProgressColumn

Check warning on line 7 in IntValueProgressColumn.cs

View workflow job for this annotation

GitHub Actions / ubuntu-latest

Type 'IntValueProgressColumn' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)

Check warning on line 7 in IntValueProgressColumn.cs

View workflow job for this annotation

GitHub Actions / windows-latest

Type 'IntValueProgressColumn' can be sealed because it has no subtypes in its containing assembly and is not externally visible (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1852)
{
/// <inheritdoc/>
public override IRenderable Render(RenderOptions options, ProgressTask task, TimeSpan deltaTime)
{
var total = (int)task.MaxValue;

if (task.IsFinished)
{
return new Markup($"[green]{total}[/] ").RightJustified();
}

var current = (int)task.Value;

return new Markup($"[green]{current}[/][grey]/{total}[/] ").RightJustified();
}

/// <inheritdoc/>
public override int? GetColumnWidth(RenderOptions options)
{
return 16;
}
}
21 changes: 13 additions & 8 deletions KnownDepotIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spectre.Console;

#pragma warning disable CA1031 // Do not catch general exception types
namespace SteamTokenDumper;
Expand All @@ -22,7 +23,7 @@ public async Task Load(ApiClient apiClient)

Server = await apiClient.GetBackendKnownDepotIds();

Console.WriteLine($"Got {Server.Count} depot ids from the backend to skip.");
AnsiConsole.WriteLine($"Got {Server.Count} depot ids from the backend to skip.");
}

private async Task LoadKnownDepotIds()
Expand All @@ -44,13 +45,15 @@ private async Task LoadKnownDepotIds()
PreviouslySent.Add(uint.Parse(line, CultureInfo.InvariantCulture));
}

Console.WriteLine($"You have sent {PreviouslySent.Count} depot keys before, they will be skipped.");
AnsiConsole.WriteLine($"You have sent {PreviouslySent.Count} depot keys before, they will be skipped.");
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
await Console.Error.WriteLineAsync($"[!] Failed to load known depot ids: {e.Message}");
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text($"Failed to load known depot ids: {e.Message}", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);
}
}

Expand Down Expand Up @@ -78,9 +81,11 @@ public async Task SaveKnownDepotIds()
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
await Console.Error.WriteLineAsync($"[!] Failed to save known depot ids: {e.Message}");
Console.ResetColor();
AnsiConsole.Write(
new Panel(new Text($"Failed to save known depot ids: {e.Message}", new Style(Color.Red)))
.BorderColor(Color.Red)
.RoundedBorder()
);
}
}
}
Loading

0 comments on commit 1d15305

Please sign in to comment.