Snapshot for release 2026.10.21.2 (internal dd171ba)
This commit is contained in:
parent
5defb009a6
commit
b059db4ca2
8 changed files with 181 additions and 41 deletions
|
|
@ -53,6 +53,7 @@
|
|||
<Compile Include="..\RynthCore.App\DecalBridgeCheck.cs" Link="Shared\DecalBridgeCheck.cs" />
|
||||
<Compile Include="..\RynthCore.App\RealDecalCheckHost.cs" Link="Shared\RealDecalCheckHost.cs" />
|
||||
<Compile Include="..\RynthCore.App\AcLaunchArgumentBuilder.cs" Link="Shared\AcLaunchArgumentBuilder.cs" />
|
||||
<Compile Include="..\RynthCore.App\AcClientCommandLine.cs" Link="Shared\AcClientCommandLine.cs" />
|
||||
<Compile Include="..\RynthCore.App\FirstLoginRules.cs" Link="Shared\FirstLoginRules.cs" />
|
||||
<Compile Include="..\RynthCore.App\CrashDumpWriterRule.cs" Link="Shared\CrashDumpWriterRule.cs" />
|
||||
<Compile Include="..\RynthCore.App\AcClientLaunchSettingsService.cs" Link="Shared\AcClientLaunchSettingsService.cs" />
|
||||
|
|
|
|||
75
src/RynthCore.App/AcClientCommandLine.cs
Normal file
75
src/RynthCore.App/AcClientCommandLine.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace RynthCore.App;
|
||||
|
||||
/// <summary>
|
||||
/// acclient.exe's own command-line rules, and how to write a value so the client reads it back.
|
||||
///
|
||||
/// The client splits its command line itself (ConvertCommandLineToArgList, 0x004098F0, called from
|
||||
/// WinMain; ArgumentParser::ParseCommandLine uses the same template), not with the C runtime's rules:
|
||||
/// * arguments are split on spaces (only ' ') outside quotes;
|
||||
/// * a " switches quoting on or off and is dropped; it is never part of an argument;
|
||||
/// * nothing is escaped: a backslash is an ordinary character;
|
||||
/// * a quote left open refuses the whole command line ("Unmatched quote"), so the client starts
|
||||
/// without the account, password or host.
|
||||
/// The launcher used to write the C runtime's form ("\"" around the value, \\ for \, \" for ") for a
|
||||
/// value with a space or a quote; the client kept the backslashes, so a password with a quote mark
|
||||
/// reached the server changed and the login failed (2026-10-21, a 30-character password with most
|
||||
/// special characters on Conquest; ThwargLauncher, which passes the password as it is, worked).
|
||||
/// </summary>
|
||||
internal static class AcClientCommandLine
|
||||
{
|
||||
/// <summary>
|
||||
/// <paramref name="value"/> as one argument the client reads back as <see cref="ClientValue"/> of it:
|
||||
/// as it is when it has no space (what ThwargLauncher passes), else in quotes. Quote marks in it are
|
||||
/// left out, as the client would drop them anyway; that also keeps the quotes balanced.
|
||||
/// </summary>
|
||||
public static string Token(string? value)
|
||||
{
|
||||
string v = ClientValue(value);
|
||||
if (v.Length == 0)
|
||||
return "\"\"";
|
||||
return v.IndexOf(' ') >= 0 ? "\"" + v + "\"" : v;
|
||||
}
|
||||
|
||||
/// <summary>What the client can receive of <paramref name="value"/>: everything but its quote marks.</summary>
|
||||
public static string ClientValue(string? value) => (value ?? string.Empty).Replace("\"", string.Empty);
|
||||
|
||||
/// <summary>True when the client can't receive <paramref name="value"/> as it is (it has a quote mark).</summary>
|
||||
public static bool LosesCharacters(string? value) => !string.IsNullOrEmpty(value) && value.IndexOf('"') >= 0;
|
||||
|
||||
/// <summary>
|
||||
/// The arguments the client reads from <paramref name="commandLine"/>, by its own rules; null when it
|
||||
/// refuses the line (a quote left open). For tests, and for reading the client's -h the way it does.
|
||||
/// </summary>
|
||||
public static List<string>? Split(string? commandLine)
|
||||
{
|
||||
var args = new List<string>();
|
||||
if (commandLine == null)
|
||||
return null;
|
||||
var cur = new StringBuilder();
|
||||
bool inArg = false, quoted = false;
|
||||
foreach (char c in commandLine)
|
||||
{
|
||||
if (c == ' ' && !quoted)
|
||||
{
|
||||
if (inArg) { args.Add(cur.ToString()); cur.Clear(); inArg = false; }
|
||||
}
|
||||
else if (c == '"')
|
||||
{
|
||||
quoted = !quoted;
|
||||
}
|
||||
else
|
||||
{
|
||||
inArg = true;
|
||||
cur.Append(c);
|
||||
}
|
||||
}
|
||||
if (quoted)
|
||||
return null;
|
||||
if (inArg)
|
||||
args.Add(cur.ToString());
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
|
@ -128,27 +128,6 @@ internal sealed class AcLaunchArgumentBuilder
|
|||
return null;
|
||||
}
|
||||
|
||||
private static string Quote(string value)
|
||||
{
|
||||
value ??= string.Empty;
|
||||
|
||||
if (value.Length == 0)
|
||||
return "\"\"";
|
||||
|
||||
if (!NeedsQuoting(value))
|
||||
return value;
|
||||
|
||||
return "\"" + value.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
|
||||
private static bool NeedsQuoting(string value)
|
||||
{
|
||||
foreach (char ch in value)
|
||||
{
|
||||
if (char.IsWhiteSpace(ch) || ch == '"')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/// <summary>One argument by acclient's own rules (AcClientCommandLine), not the C runtime's.</summary>
|
||||
private static string Quote(string value) => AcClientCommandLine.Token(value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,18 +95,21 @@ internal static class ServerDetect
|
|||
return host.Length > 0;
|
||||
}
|
||||
|
||||
/// <summary>Windows command-line splitting, enough for the launchers' quoting (quotes group, \" is a quote).</summary>
|
||||
/// <summary>
|
||||
/// acclient's own splitting (ConvertCommandLineToArgList, 0x004098F0; the launcher's
|
||||
/// AcClientCommandLine), so -h is the host the client itself reads: spaces split outside quotes,
|
||||
/// a quote only toggles and is dropped, a backslash is ordinary. An open quote (the client refuses
|
||||
/// the whole line) still yields what was read.
|
||||
/// </summary>
|
||||
private static List<string> SplitArgs(string s)
|
||||
{
|
||||
var list = new List<string>();
|
||||
var cur = new System.Text.StringBuilder();
|
||||
bool inQuotes = false, any = false;
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
foreach (char c in s)
|
||||
{
|
||||
char c = s[i];
|
||||
if (c == '\\' && i + 1 < s.Length && s[i + 1] == '"') { cur.Append('"'); i++; any = true; continue; }
|
||||
if (c == '"') { inQuotes = !inQuotes; any = true; continue; }
|
||||
if (!inQuotes && char.IsWhiteSpace(c))
|
||||
if (c == '"') { inQuotes = !inQuotes; continue; }
|
||||
if (c == ' ' && !inQuotes)
|
||||
{
|
||||
if (any) { list.Add(cur.ToString()); cur.Clear(); any = false; }
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -260,6 +260,8 @@ internal static class LaunchCommand
|
|||
Log($"No password is saved for account '{acct}'. Launch it once from the launcher to enter it, or edit the account.");
|
||||
return 2;
|
||||
}
|
||||
if (RynthCore.App.AcClientCommandLine.LosesCharacters(pwd))
|
||||
Log("Note: the password has a quote mark (\"). The AC client can't receive one on its command line, so it logs in with the password less its quote marks.");
|
||||
|
||||
string arguments = server.Emulator == EmulatorKind.Gdle
|
||||
? string.Join(" ",
|
||||
|
|
@ -384,16 +386,8 @@ internal static class LaunchCommand
|
|||
|
||||
// Mirrors AcLaunchArgumentBuilder.Quote — only quote when needed, escape
|
||||
// backslashes + quotes inside.
|
||||
private static string Quote(string value)
|
||||
{
|
||||
value ??= string.Empty;
|
||||
if (value.Length == 0)
|
||||
return "\"\"";
|
||||
bool needs = value.Any(ch => char.IsWhiteSpace(ch) || ch == '"');
|
||||
if (!needs)
|
||||
return value;
|
||||
return "\"" + value.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
/// <summary>One argument by acclient's own rules (AcClientCommandLine), as the launcher writes it.</summary>
|
||||
private static string Quote(string value) => RynthCore.App.AcClientCommandLine.Token(value);
|
||||
|
||||
private static string? GetOpt(string[] args, string name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<Compile Include="..\RynthCore.App\DecalAccountModes.cs" Link="Shared\DecalAccountModes.cs" />
|
||||
<!-- Saved account passwords are DPAPI-encrypted (PasswordProtected in appsettings.json). -->
|
||||
<Compile Include="..\RynthCore.App\AccountPasswordProtection.cs" Link="Shared\AccountPasswordProtection.cs" />
|
||||
<Compile Include="..\RynthCore.App\AcClientCommandLine.cs" Link="Shared\AcClientCommandLine.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
<Compile Include="..\..\src\RynthCore.App\LaunchServerProfile.cs" Link="App\LaunchServerProfile.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\KnownServerCatalog.cs" Link="App\KnownServerCatalog.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\AcLaunchArgumentBuilder.cs" Link="App\AcLaunchArgumentBuilder.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\AcClientCommandLine.cs" Link="App\AcClientCommandLine.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\FirstLoginRules.cs" Link="App\FirstLoginRules.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\UserPrefsSwapRecovery.cs" Link="App\UserPrefsSwapRecovery.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.App\CrashDumpWriterRule.cs" Link="App\CrashDumpWriterRule.cs" />
|
||||
|
|
|
|||
|
|
@ -174,8 +174,14 @@ internal static class Program
|
|||
|
||||
var builder = new AcLaunchArgumentBuilder();
|
||||
LaunchServerProfile ace = Server(AcEmulatorKind.Ace), gdle = Server(AcEmulatorKind.Gdle);
|
||||
Check(builder.BuildArguments(ace, a).Contains("-v \"t3st pw \\\"quoted\\\" ü\""), "ACE args carry the password (-v)");
|
||||
Check(builder.BuildArguments(gdle, a).Contains("-a \"A:t3st pw \\\"quoted\\\" ü\""), "GDLE args carry account:password (-a)");
|
||||
// Read back the way acclient reads its command line (AcClientCommandLine.Split): the password
|
||||
// as typed, less its quote marks (the client can't receive one), and the host after it intact.
|
||||
List<string>? aceArgs = AcClientCommandLine.Split(builder.BuildArguments(ace, a));
|
||||
Check(ArgAfter(aceArgs, "-v") == "t3st pw quoted ü" && ArgAfter(aceArgs, "-h") == "127.0.0.1:9000",
|
||||
"ACE: the client reads the password (-v) and the host after it");
|
||||
List<string>? gdleArgs = AcClientCommandLine.Split(builder.BuildArguments(gdle, a));
|
||||
Check(ArgAfter(gdleArgs, "-a") == "A:t3st pw quoted ü" && ArgAfter(gdleArgs, "-p") == "9000",
|
||||
"GDLE: the client reads account:password (-a) and the port");
|
||||
string preview = builder.BuildMaskedArguments(ace, a);
|
||||
Check(!preview.Contains("t3st") && preview.Contains("-v " + AcLaunchArgumentBuilder.PasswordMask), "preview masked: " + preview);
|
||||
LaunchAccountProfile noPw = loaded.AccountProfiles.First(x => x.Id == "b");
|
||||
|
|
@ -457,12 +463,92 @@ internal static class Program
|
|||
try { Directory.Delete(root, recursive: true); } catch { }
|
||||
}
|
||||
|
||||
ClientCommandLineChecks();
|
||||
|
||||
Console.WriteLine(_failed == 0
|
||||
? $"PASS: {_checks} checks"
|
||||
: $"FAIL: {_failed} of {_checks} checks failed");
|
||||
return _failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
// ── acclient's command line ──────────────────────────────────────────────
|
||||
// Passwords with special characters failed to log in (2026-10-21, Conquest; ThwargLauncher, which
|
||||
// passes the password as it is, worked): the launcher wrote the C runtime's escapes (\\ and \"),
|
||||
// which acclient's own splitter keeps as typed. AcClientCommandLine.Split is that splitter
|
||||
// (ConvertCommandLineToArgList, 0x004098F0); everything the launcher writes is read back with it.
|
||||
private static void ClientCommandLineChecks()
|
||||
{
|
||||
Console.WriteLine("-- acclient's command line");
|
||||
|
||||
// The splitter itself, as decompiled: spaces split outside quotes, a quote toggles and is dropped,
|
||||
// a backslash is ordinary, an open quote refuses the line.
|
||||
Check(Same(AcClientCommandLine.Split("\"C:\\Turbine\\Asheron's Call\\acclient.exe\" -a x -v y"),
|
||||
"C:\\Turbine\\Asheron's Call\\acclient.exe", "-a", "x", "-v", "y"), "the exe path in quotes, double spaces");
|
||||
Check(Same(AcClientCommandLine.Split("a\"\"b c\\\"d e\""), "ab", "c\\d e"), "quotes dropped, a backslash kept as it is");
|
||||
Check(AcClientCommandLine.Split("-v \"a b") == null, "an open quote refuses the line");
|
||||
Check(Same(AcClientCommandLine.Split("-v a\tb"), "-v", "a\tb"), "only a space splits (a tab is part of the argument)");
|
||||
|
||||
// A long password with nearly every special character and no space (the report): written as it is,
|
||||
// exactly as ThwargLauncher writes it.
|
||||
string special = "Aa1!@#$%^&*()_+-=[]{}|\\:;'<>,.?/~`" + "Zz9\\\\end\\";
|
||||
Check(AcClientCommandLine.Token(special) == special, "no space, no quote: the password as it is");
|
||||
Check(ReadsBack(special, special), "and the client reads it back");
|
||||
|
||||
// Quote marks: the client drops them whatever the launcher does; with them left out the rest
|
||||
// reaches the server as typed, and the line can't end on an open quote.
|
||||
// Negative control: the old C-runtime form reads back wrong, so the checks here mean something.
|
||||
static string OldQuote(string v) => "\"" + v.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\"";
|
||||
Check(ArgAfter(AcClientCommandLine.Split("-v " + OldQuote("x\"y\"z\\") + " -h h"), "-v") is string old && old != "xyz\\",
|
||||
"negative control: the old escapes reach the client changed");
|
||||
Check(ReadsBack("p\"ss\\word", "pss\\word"), "one quote mark: left out, the backslash kept (was \\\\ before)");
|
||||
Check(ReadsBack("x\"y\"z\\", "xyz\\"), "two quote marks");
|
||||
Check(AcClientCommandLine.LosesCharacters("a\"b") && !AcClientCommandLine.LosesCharacters(special), "LosesCharacters: only a quote mark");
|
||||
Check(ReadsBack("pa ss \\ word\\", "pa ss \\ word\\"), "spaces: in quotes, a trailing backslash kept");
|
||||
Check(ReadsBack("ü€£§°´ ä", "ü€£§°´ ä"), "non-ASCII and a space");
|
||||
|
||||
// Every password ThwargLauncher can log in with (no space: it doesn't quote) reads back the same
|
||||
// through ours; and ours reads back every password, quotes left out.
|
||||
const string Alphabet = "ab\\\" !@#$%^&*()-_=+[]{};:',.<>/?|`~ü";
|
||||
var rng = new Random(20261021);
|
||||
int thwargSame = 0, ours = 0;
|
||||
for (int n = 0; n < 4000; n++)
|
||||
{
|
||||
var sb = new System.Text.StringBuilder();
|
||||
int len = 1 + rng.Next(40);
|
||||
for (int i = 0; i < len; i++) sb.Append(Alphabet[rng.Next(Alphabet.Length)]);
|
||||
string pw = sb.ToString();
|
||||
string expected = AcClientCommandLine.ClientValue(pw);
|
||||
if (expected.Length == 0) continue;
|
||||
if (ReadsBack(pw, expected)) ours++;
|
||||
else { Check(false, "reads back: " + pw); break; }
|
||||
List<string>? thwarg = AcClientCommandLine.Split("-a acct -v " + pw + " -h host:9000");
|
||||
if (pw.IndexOf(' ') < 0 && thwarg != null && thwarg.Count == 6)
|
||||
{
|
||||
if (ArgAfter(thwarg, "-v") == expected) thwargSame++;
|
||||
else { Check(false, "same as ThwargLauncher: " + pw); break; }
|
||||
}
|
||||
}
|
||||
Check(ours > 3500 && thwargSame > 100, $"random passwords: {ours} read back, {thwargSame} the same as ThwargLauncher's");
|
||||
}
|
||||
|
||||
/// <summary>The launcher's ACE line for <paramref name="password"/>, read back by acclient's rules.</summary>
|
||||
private static bool ReadsBack(string password, string expected)
|
||||
{
|
||||
string line = "-a " + AcClientCommandLine.Token("acct") + " -v " + AcClientCommandLine.Token(password)
|
||||
+ " -h " + AcClientCommandLine.Token("host:9000") + " -rodat off";
|
||||
List<string>? args = AcClientCommandLine.Split(line);
|
||||
return args != null && args.Count == 8 && ArgAfter(args, "-v") == expected && ArgAfter(args, "-h") == "host:9000";
|
||||
}
|
||||
|
||||
private static string? ArgAfter(List<string>? args, string name)
|
||||
{
|
||||
if (args == null) return null;
|
||||
int i = args.IndexOf(name);
|
||||
return i >= 0 && i + 1 < args.Count ? args[i + 1] : null;
|
||||
}
|
||||
|
||||
private static bool Same(List<string>? got, params string[] want) => got != null && got.SequenceEqual(want);
|
||||
|
||||
// ── helpers ──────────────────────────────────────────────────────────────
|
||||
|
||||
private static void Scenario(string name, string root, Action body)
|
||||
|
|
|
|||
Loading…
Reference in a new issue