Snapshot for release 2026.10.15.2 (internal 9094d68)

This commit is contained in:
Tom Bohar 2026-10-15 20:32:34 -04:00
commit 516ad2bdf2
121 changed files with 6486 additions and 781 deletions

View file

@ -28,38 +28,45 @@ internal sealed class AcClientLaunchSettingsService
/// My Documents\Asheron's Call, then re-applies the ComputeUniquePort flag.
/// If <paramref name="stashPath"/> is empty or missing, no swap is performed
/// and the live file is left as-is.
/// Returns what was swapped (null when nothing was), so a client that quits at
/// startup can be traced back to the stash and the swap undone
/// (<see cref="UserPrefsSwapRecovery"/>).
/// </summary>
public bool SwapUserPreferences(string? stashPath, bool allowMultipleClients, Action<string>? log = null)
public UserPrefsSwap? SwapUserPreferences(string? stashPath, bool allowMultipleClients, Action<string>? log = null)
{
if (string.IsNullOrWhiteSpace(stashPath))
return false;
return null;
if (!File.Exists(stashPath))
{
log?.Invoke($"User prefs swap skipped: stash file not found at {stashPath}.");
return false;
return null;
}
string documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string prefsDirectory = Path.Combine(documentsDirectory, "Asheron's Call");
string prefsPath = Path.Combine(prefsDirectory, UserPreferencesFileName);
byte[] stashBytes;
byte[]? previousLiveBytes;
try
{
Directory.CreateDirectory(prefsDirectory);
stashBytes = File.ReadAllBytes(stashPath);
previousLiveBytes = File.Exists(prefsPath) ? File.ReadAllBytes(prefsPath) : null;
File.Copy(stashPath, prefsPath, overwrite: true);
}
catch (Exception ex)
{
log?.Invoke($"User prefs swap failed copying {stashPath}: {ex.Message}");
return false;
return null;
}
// Re-apply the ComputeUniquePort flag — the stash may have it set to
// the wrong value (e.g. user set it up before enabling multi-client).
UpdateUserPreferences(allowMultipleClients, log: null);
log?.Invoke($"User prefs swap: applied stash {Path.GetFileName(stashPath)}.");
return true;
return new UserPrefsSwap(stashPath, prefsPath, stashBytes, previousLiveBytes);
}
private static void UpdateUserPreferences(bool allowMultipleClients, Action<string>? log)

View file

@ -9,10 +9,28 @@ internal sealed class AcLaunchArgumentBuilder
/// <summary>Text shown in place of the password in previews.</summary>
public const string PasswordMask = "********";
/// <summary>
/// True when <paramref name="account"/> can't be launched until a password is entered: none
/// is saved, or the saved one can't be decrypted on this Windows user. Every supported
/// emulator logs on with a password, and the client refuses an empty one before it connects
/// ("You can only run the game from the launcher program").
/// </summary>
public static bool NeedsPassword(LaunchAccountProfile account)
{
ArgumentNullException.ThrowIfNull(account);
return account.PasswordNeedsReentry || !account.HasSavedPassword;
}
/// <summary>Why an account without a password can't be launched (no secrets in it).</summary>
public static string MissingPasswordMessage(string? accountName) =>
$"No password is saved for account '{accountName}'. The AC client won't start without one " +
"(\"You can only run the game from the launcher program\"). Launch it by hand to enter it, or edit the account.";
/// <summary>
/// The client's command line, with the saved password decrypted now. The result carries the
/// password: hand it to the process and never log, display or keep it. Throws when the saved
/// password can't be decrypted on this Windows user (never launches with an empty one instead).
/// password: hand it to the process and never log, display or keep it. Throws when no password
/// is saved or the saved one can't be decrypted on this Windows user (never launches with an
/// empty one instead).
/// </summary>
public string BuildArguments(LaunchServerProfile server, LaunchAccountProfile account)
{
@ -23,6 +41,8 @@ internal sealed class AcLaunchArgumentBuilder
if (!account.TryGetPasswordForLaunch(out string password, out string problem))
throw new InvalidOperationException(problem);
if (password.Length == 0)
throw new InvalidOperationException(MissingPasswordMessage(account.AccountName));
return Build(server, account, password);
}
@ -40,8 +60,10 @@ internal sealed class AcLaunchArgumentBuilder
if (account.PasswordNeedsReentry)
return LaunchAccountProfile.PasswordNeedsReentryMessage(account.AccountName);
if (!account.HasSavedPassword)
return MissingPasswordMessage(account.AccountName);
return Build(server, account, account.HasSavedPassword ? PasswordMask : string.Empty);
return Build(server, account, PasswordMask);
}
private static string Build(LaunchServerProfile server, LaunchAccountProfile account, string password)
@ -79,11 +101,33 @@ internal sealed class AcLaunchArgumentBuilder
errors.Add("Server port must be greater than zero.");
if (string.IsNullOrWhiteSpace(account.AccountName))
errors.Add("Account name is required.");
else if (AccountNameProblem(account.AccountName, server.Emulator) is string nameProblem)
errors.Add(nameProblem);
if (errors.Count > 0)
throw new InvalidOperationException(string.Join(" ", errors));
}
/// <summary>Longest account name ACE accepts (AuthenticationHandler rejects longer ones).</summary>
public const int MaxAccountNameLength = 50;
/// <summary>
/// Why <paramref name="accountName"/> can't log on to a server of <paramref name="emulator"/>
/// (null = fine). GDLE takes "account:password" in one argument, so a colon in the name would
/// split it in the wrong place.
/// </summary>
public static string? AccountNameProblem(string? accountName, AcEmulatorKind emulator)
{
string name = accountName?.Trim() ?? string.Empty;
if (name.Length == 0)
return "Account name is required.";
if (name.Length > MaxAccountNameLength)
return $"Account name is longer than {MaxAccountNameLength} characters.";
if (emulator == AcEmulatorKind.Gdle && name.Contains(':'))
return "Account names can't contain ':' on GDLE servers.";
return null;
}
private static string Quote(string value)
{
value ??= string.Empty;

View file

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace RynthCore.App;
/// <summary>
/// The rules behind the launcher's "First login" dialog, shown when an account is launched with no
/// usable password (a new server, or a profile added without one). Pure: no UI, no files.
///
/// The client refuses an empty password before it connects ("You can only run the game from the
/// launcher program"), so a password is always required. ACE creates an account the first time a
/// new name logs on with a password (AllowAutoAccountCreation), so a new name here is how an
/// account is created. With no character known yet the client stops at character select, where
/// characters are created; the engine saves the account's character list from there.
/// </summary>
internal static class FirstLoginRules
{
/// <summary>The "Log in as" entry that stops at character select.</summary>
public const string StopAtCharacterSelect = "Stop at character select (create or pick a character there)";
/// <summary>
/// Account names from the other profiles, distinct (case-insensitive) and sorted, for picking
/// an account you already use elsewhere.
/// </summary>
internal static List<string> KnownAccountNames(IEnumerable<LaunchAccountProfile> profiles, string excludeProfileId)
{
return profiles
.Where(p => !string.Equals(p.Id, excludeProfileId, StringComparison.OrdinalIgnoreCase))
.Select(p => p.AccountName?.Trim() ?? string.Empty)
.Where(n => n.Length > 0)
.Distinct(StringComparer.OrdinalIgnoreCase)
.OrderBy(n => n, StringComparer.OrdinalIgnoreCase)
.ToList();
}
/// <summary>
/// Another profile with the same account name and a password readable on this Windows user,
/// whose saved password can be reused (null = none). The same name on another server is a
/// different account, so the caller offers this as a choice, never silently.
/// </summary>
internal static LaunchAccountProfile? SavedPasswordSource(
IEnumerable<LaunchAccountProfile> profiles, string accountName, string excludeProfileId)
{
string name = accountName?.Trim() ?? string.Empty;
if (name.Length == 0)
return null;
return profiles.FirstOrDefault(p =>
!string.Equals(p.Id, excludeProfileId, StringComparison.OrdinalIgnoreCase)
&& string.Equals(p.AccountName?.Trim(), name, StringComparison.OrdinalIgnoreCase)
&& p.HasSavedPassword
&& !p.PasswordNeedsReentry);
}
/// <summary>
/// The "Log in as" choices: stop at character select, then the account's known characters
/// (the saved one first if the list hasn't seen it yet).
/// </summary>
internal static List<string> LoginChoices(IReadOnlyList<string> knownCharacters, string? savedCharacter)
{
var choices = new List<string> { StopAtCharacterSelect };
if (!string.IsNullOrWhiteSpace(savedCharacter)
&& savedCharacter != LaunchAccountProfile.NoneOption
&& !knownCharacters.Contains(savedCharacter, StringComparer.OrdinalIgnoreCase))
{
choices.Add(savedCharacter);
}
choices.AddRange(knownCharacters.Where(c => !string.IsNullOrWhiteSpace(c)));
return choices;
}
/// <summary>
/// The CharacterName to save for <paramref name="choice"/>. Stopping at character select with
/// no character known yet saves "" rather than the explicit "(None)": once the first character
/// is created and it is the only one, the launcher picks it for the next launch.
/// </summary>
internal static string CharacterNameFor(string? choice, IReadOnlyList<string> knownCharacters)
{
if (string.IsNullOrWhiteSpace(choice) || choice == StopAtCharacterSelect)
return knownCharacters.Count == 0 ? string.Empty : LaunchAccountProfile.NoneOption;
return choice;
}
/// <summary>What's wrong with the entries (null = ready to log in).</summary>
internal static string? Problem(string? accountName, string? password, string? confirm, bool reuseSavedPassword, AcEmulatorKind emulator)
{
if (AcLaunchArgumentBuilder.AccountNameProblem(accountName, emulator) is string nameProblem)
return nameProblem;
if (reuseSavedPassword)
return null;
if (string.IsNullOrEmpty(password))
return "Enter the password. The client won't start without one; for a new account it becomes the account's password.";
if (!string.Equals(password, confirm, StringComparison.Ordinal))
return "The two passwords don't match.";
return null;
}
}

View file

@ -130,6 +130,24 @@ internal sealed class LaunchAccountProfile
PasswordNeedsReentry = false;
}
/// <summary>
/// Reuses <paramref name="source"/>'s saved password (the same account name on another server).
/// The encrypted blob is copied as it is, so the plain text is never handled; it is readable
/// here because both profiles belong to the same Windows user's settings.
/// </summary>
public void CopyPasswordFrom(LaunchAccountProfile source)
{
ArgumentNullException.ThrowIfNull(source);
if (!string.IsNullOrEmpty(source.LegacyPlainPassword))
{
SetPassword(source.LegacyPlainPassword);
return;
}
PasswordProtected = source.PasswordProtected;
LegacyPlainPassword = null;
PasswordNeedsReentry = source.PasswordNeedsReentry;
}
public void ClearPassword()
{
PasswordProtected = string.Empty;

View file

@ -0,0 +1,87 @@
using System;
using System.IO;
namespace RynthCore.App;
/// <summary>
/// One launch's swap of a saved UserPreferences.ini over the live file in
/// My Documents\Asheron's Call: the saved copy it came from, and the live file as it was before.
/// <paramref name="PreviousLiveBytes"/> is null when there was no live file.
/// </summary>
internal sealed record UserPrefsSwap(
string StashPath,
string LivePath,
byte[] StashBytes,
byte[]? PreviousLiveBytes);
/// <summary>What <see cref="UserPrefsSwapRecovery.Recover"/> did. Null paths mean that file was left alone.</summary>
internal sealed record UserPrefsRecoveryResult(
string? QuarantinedStashPath,
string? QuarantinedLegacyPath,
bool LiveRestored);
/// <summary>
/// Undoes a UserPreferences.ini swap whose client quit at startup. The game reads its
/// resolution and full-screen mode from that file, so a saved copy with a display mode the PC
/// can't use stops every launch with "Could not initialize Direct3D". The saved copy is only
/// refreshed after a normal session, so without this it would be restored on every launch.
/// Pure file work: no UI, no launcher state.
/// </summary>
internal static class UserPrefsSwapRecovery
{
/// <summary>Where a failed saved copy is kept: next to it, renamed so it is never swapped in again.</summary>
internal static string QuarantinePath(string stashPath, DateTime nowLocal) =>
$"{stashPath}.failed-{nowLocal:yyyyMMdd-HHmmss}";
/// <summary>
/// True when the swap changed the live file. When the saved copy matched the live file, the
/// swap can't have caused the failure, so nothing is undone.
/// </summary>
internal static bool SwapChangedPrefs(UserPrefsSwap swap) =>
swap.PreviousLiveBytes == null || !swap.StashBytes.AsSpan().SequenceEqual(swap.PreviousLiveBytes);
/// <summary>
/// Sets the failed saved copy aside (when <paramref name="quarantineStash"/>) and puts the
/// previous live file back (when <paramref name="restoreLive"/>).
/// <paramref name="legacyStashPath"/> is the account's name-only copy: it seeds a missing
/// per-server copy, so it is set aside too when it holds the same failed settings.
/// </summary>
internal static UserPrefsRecoveryResult Recover(
UserPrefsSwap swap,
bool quarantineStash,
bool restoreLive,
string? legacyStashPath,
DateTime nowLocal)
{
string? quarantined = null;
string? quarantinedLegacy = null;
if (quarantineStash && File.Exists(swap.StashPath))
{
quarantined = QuarantinePath(swap.StashPath, nowLocal);
File.Move(swap.StashPath, quarantined, overwrite: true);
if (!string.IsNullOrWhiteSpace(legacyStashPath)
&& !string.Equals(Path.GetFullPath(legacyStashPath), Path.GetFullPath(swap.StashPath), StringComparison.OrdinalIgnoreCase)
&& File.Exists(legacyStashPath)
&& File.ReadAllBytes(legacyStashPath).AsSpan().SequenceEqual(swap.StashBytes))
{
quarantinedLegacy = QuarantinePath(legacyStashPath, nowLocal);
File.Move(legacyStashPath, quarantinedLegacy, overwrite: true);
}
}
bool restored = false;
if (restoreLive)
{
// No live file before the swap: remove it so the game writes its own defaults.
if (swap.PreviousLiveBytes != null)
File.WriteAllBytes(swap.LivePath, swap.PreviousLiveBytes);
else if (File.Exists(swap.LivePath))
File.Delete(swap.LivePath);
restored = true;
}
return new UserPrefsRecoveryResult(quarantined, quarantinedLegacy, restored);
}
}