Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for new Steam authentication #401

Merged
merged 5 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions DepotDownloader/AccountSettingsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ class AccountSettingsStore
[ProtoMember(2, IsRequired = false)]
public ConcurrentDictionary<string, int> ContentServerPenalty { get; private set; }

[ProtoMember(3, IsRequired = false)]
public Dictionary<string, string> LoginKeys { get; private set; }
// Member 3 was a Dictionary<string, string> for LoginKeys.

[ProtoMember(4, IsRequired = false)]
public Dictionary<string, string> LoginTokens { get; private set; }

string FileName;

AccountSettingsStore()
{
SentryData = new Dictionary<string, byte[]>();
ContentServerPenalty = new ConcurrentDictionary<string, int>();
LoginKeys = new Dictionary<string, string>();
LoginTokens = new Dictionary<string, string>();
}

static bool Loaded
Expand Down
9 changes: 4 additions & 5 deletions DepotDownloader/ContentDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,20 +341,20 @@ static string GetAppOrDepotName(uint depotId, uint appId)

public static bool InitializeSteam3(string username, string password)
{
string loginKey = null;
string loginToken = null;

if (username != null && Config.RememberPassword)
{
_ = AccountSettingsStore.Instance.LoginKeys.TryGetValue(username, out loginKey);
_ = AccountSettingsStore.Instance.LoginTokens.TryGetValue(username, out loginToken);
}

steam3 = new Steam3Session(
new SteamUser.LogOnDetails
{
Username = username,
Password = loginKey == null ? password : null,
Password = loginToken == null ? password : null,
ShouldRememberPassword = Config.RememberPassword,
LoginKey = loginKey,
AccessToken = loginToken,
LoginID = Config.LoginID ?? 0x534B32, // "SK2"
}
);
Expand All @@ -381,7 +381,6 @@ public static void ShutdownSteam3()
if (steam3 == null)
return;

steam3.TryWaitForLoginKey();
steam3.Disconnect();
}

Expand Down
3 changes: 2 additions & 1 deletion DepotDownloader/DepotDownloader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="protobuf-net" Version="3.2.16" />
<PackageReference Include="SteamKit2" Version="2.4.1" />
<PackageReference Include="QRCoder" Version="1.4.3" />
<PackageReference Include="SteamKit2" Version="2.5.0-Beta.1" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion DepotDownloader/DownloadConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ class DownloadConfig
public int MaxServers { get; set; }
public int MaxDownloads { get; set; }

public string SuppliedPassword { get; set; }
public bool RememberPassword { get; set; }

// A Steam LoginID to allow multiple concurrent connections
public uint? LoginID { get; set; }

public bool UseQrCode { get; set; }
}
}
41 changes: 21 additions & 20 deletions DepotDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static async Task<int> MainAsync(string[] args)
var username = GetParameter<string>(args, "-username") ?? GetParameter<string>(args, "-user");
var password = GetParameter<string>(args, "-password") ?? GetParameter<string>(args, "-pass");
ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");
ContentDownloader.Config.UseQrCode = HasParameter(args, "-qr");

ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

Expand Down Expand Up @@ -268,32 +269,32 @@ ex is ContentDownloaderException

static bool InitializeSteam(string username, string password)
{
if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !AccountSettingsStore.Instance.LoginKeys.ContainsKey(username)))
if (!ContentDownloader.Config.UseQrCode)
{
do
if (username != null && password == null && (!ContentDownloader.Config.RememberPassword || !AccountSettingsStore.Instance.LoginTokens.ContainsKey(username)))
{
Console.Write("Enter account password for \"{0}\": ", username);
if (Console.IsInputRedirected)
do
{
password = Console.ReadLine();
}
else
{
// Avoid console echoing of password
password = Util.ReadPassword();
}
Console.Write("Enter account password for \"{0}\": ", username);
if (Console.IsInputRedirected)
{
password = Console.ReadLine();
}
else
{
// Avoid console echoing of password
password = Util.ReadPassword();
}

Console.WriteLine();
} while (string.Empty == password);
}
else if (username == null)
{
Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
Console.WriteLine();
} while (string.Empty == password);
}
else if (username == null)
{
Console.WriteLine("No username given. Using anonymous account with dedicated server subscription.");
}
}

// capture the supplied password in case we need to re-use it after checking the login key
ContentDownloader.Config.SuppliedPassword = password;

return ContentDownloader.InitializeSteam3(username, password);
}

Expand Down
Loading