From 9e1e38231f278fd8757aa893b009b819880b3fea Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:17:22 +0000 Subject: [PATCH 1/2] Stop typing INFO and VERSION at addresses that never answer them MsspSelfDescription only stops INFO and VERSION where an MSSP report already answers them, so a game with no MSSP was asked on every crawl. At fs.twkang.net:5555 and its siblings INFO is read as a character name and VERSION offers to create a character called "version" (#182). - crawl_target.login_commands_unanswered / _quiet_at (migration 0046) remember, per address, how many sessions running produced nothing a reader stands behind. LoginCommands.Ask/Learn own the rule: three such sessions silence the address, a retrial every 30 days can end it, and a submission still awaiting corroboration is always asked. - Only a session that typed INFO counts (ProbeResult.InfoAsked), so our silence is never recorded as theirs. mui-probe prints "not asked". - Within a session, INFO answered by a name prompt means VERSION is not sent. The name-prompt vocabulary moves out of WhoParser into NamePrompt and learns the ES2/MudOS family's Chinese prompts, so WHO at those games now reads as LoginPrompt rather than Unreadable. Closes #182 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Rqqt7TV49bXFnCQC3ZmM6c --- CLAUDE.md | 15 ++- docs/codebase-survey-2026-07-30.md | 5 +- migrations/0046_login_commands.sql | 37 ++++++ .../LoginFlow/LoginCommandReading.cs | 28 +++++ src/MUI.Crawl/LoginFlow/NamePrompt.cs | 45 +++++++ src/MUI.Crawl/Telnet/ProbeResult.cs | 16 +++ src/MUI.Crawl/Telnet/Probing.cs | 21 ++++ src/MUI.Crawl/Telnet/TelnetProbe.cs | 69 +++++++++- src/MUI.Crawl/Who/WhoParser.cs | 17 +-- src/MUI.Crawler/Crawl/CrawlCycle.cs | 21 ++++ .../NpgsqlCrawlTargetRepository.cs | 21 ++++ src/MUI.Discovery/Scheduling/CrawlTarget.cs | 12 ++ src/MUI.Discovery/Scheduling/LoginCommands.cs | 104 +++++++++++++++ src/MUI.Probe/Program.cs | 13 +- .../LoginFlow/LoginCommandReadingTests.cs | 24 ++++ .../LoginFlow/NamePromptTests.cs | 60 +++++++++ .../Telnet/ProbeSessionTests.cs | 89 +++++++++++++ .../Crawl/LoginCommandsPostgresTests.cs | 89 +++++++++++++ tests/MUI.Crawler.Tests/Support/FakeStores.cs | 2 + .../Scheduling/LoginCommandsTests.cs | 119 ++++++++++++++++++ .../Support/InMemoryCrawlTargetRepository.cs | 7 ++ .../MUI.Web.Tests/StoredCrawlerPulseTests.cs | 3 + 22 files changed, 787 insertions(+), 30 deletions(-) create mode 100644 migrations/0046_login_commands.sql create mode 100644 src/MUI.Crawl/LoginFlow/NamePrompt.cs create mode 100644 src/MUI.Discovery/Scheduling/LoginCommands.cs create mode 100644 tests/MUI.Crawl.Tests/LoginFlow/NamePromptTests.cs create mode 100644 tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs create mode 100644 tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs diff --git a/CLAUDE.md b/CLAUDE.md index b2d1466..fafc0b7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -96,10 +96,17 @@ our host is unreachable and perfectly alive. and a count. The engine clause is load-bearing and was measured — without it, two games lose the only reading that says what they run (`northern-crossroads-ncmud` declares `NC-7.0.357.7940b961`, `primal-darkness-ii` declares `PD/NM III`). `FAMILY` may **not** stand in for it: both of those - games declare one. **`INFO` and `VERSION` have no `AwaitingCorroboration` escape and are still - typed at the family above, every crawl** — issue #182 is where that is being thought about, and it - is not the same problem: there is nothing they would publish, so "not asking must imply publishing" - has nothing to hold on to. + games declare one. +- **Type `INFO` or `VERSION` at an address that has never answered them.** A game with no MSSP can + never pass `MsspSelfDescription`, so the family above was typed at every crawl: `INFO` read as a + character name, `VERSION` answered *create a new character called version? (y/n)* (issue #182). + `crawl_target.login_commands_*` (migration 0046) is the memory and `LoginCommands` the one place + that reads it: three sessions running in which `LoginCommandReading.Answered` finds nothing silence + the address, a retrial every thirty days can end the silence, and a submission still awaiting §7.8 + is always asked. **Only a session that typed `INFO` counts** (`ProbeResult.InfoAsked`): there is + nothing they would publish, so "not asking must imply publishing" has nothing to hold on to, and the + rule 5 hazard instead is our silence counted as theirs. Within a session, `INFO` answered by a name + prompt (`NamePrompt`) also spares the game our `VERSION`; a plain `Huh?` does not. - **Type `MSSP-REQUEST` at an address that has reported over option 70, or that left its trial unanswered.** The plaintext form is text at a login prompt, and eight of twenty surveyed games read it as a character name. `crawl_target.mssp_route` (migration 0042) remembers each address's answer diff --git a/docs/codebase-survey-2026-07-30.md b/docs/codebase-survey-2026-07-30.md index 306d896..d5ee18d 100644 --- a/docs/codebase-survey-2026-07-30.md +++ b/docs/codebase-survey-2026-07-30.md @@ -478,7 +478,10 @@ and `us.muds.net:4000` answer `negotiated (none observed)`, `mssp NotOffered`, a chain is `WHO` → *好吧﹐那麼請重新輸入您的英文名字﹕* → `INFO` → the same → `VERSION` → *使用 version 這個名字將會創造一個新的人物﹐您確定嗎(y/n)﹖*. `ProbeTarget.AwaitingCorroboration` stops the `WHO`, on the argument that §7.8's signals are read by exactly one caller and only for an -uncorroborated submission. `INFO` and `VERSION` are not stopped — see issue #182. +uncorroborated submission. `INFO` and `VERSION` were not stopped until issue #182: an address now +stops being asked them after three sessions in which nothing in either reply was readable +(`LoginCommands`, `crawl_target.login_commands_*`), and `VERSION` is not sent at all once `INFO` has +come back as this name prompt. ### Verified against live servers, 2026-08-20 diff --git a/migrations/0046_login_commands.sql b/migrations/0046_login_commands.sql new file mode 100644 index 0000000..564d504 --- /dev/null +++ b/migrations/0046_login_commands.sql @@ -0,0 +1,37 @@ +-- crawl_target.login_commands_*: whether INFO and VERSION are still worth typing at this address. +-- +-- Issue #182. MsspSelfDescription stops them only where an MSSP report already answers both, so a +-- game that publishes no MSSP was asked on every crawl, for ever, whatever it answered. At +-- fs.twkang.net:5555 and its siblings it answers nothing readable: INFO comes back as the name prompt +-- again and VERSION as "create a new character called version? (y/n)". A codebase that does not +-- answer INFO today almost certainly never will, so the decision is learned from the address's own +-- history rather than re-derived from one session (LoginCommands, in MUI.Discovery). +-- +-- login_commands_unanswered consecutive sessions in which INFO was typed here and nothing in +-- the replies was something a reader stands behind. Capped at the +-- threshold. Back to 0 on the first session that yields anything. +-- login_commands_quiet_at NULL: asked. Set: the run reached the threshold at this time, and +-- INFO and VERSION are not typed again until a retrial falls due. A +-- retrial that answers clears it; one that does not re-dates it. +-- +-- A session in which we did not type INFO is no evidence either way and changes neither column, so +-- our silence is never counted as theirs (rule 5). And none of this is a fact about the game on any +-- public surface: it is our note about which questions we have stopped asking, read only by the +-- crawl loop. +-- +-- No backfill: nothing persisted records what an INFO reply said, so every address starts asking +-- and earns its quiet in three sessions. +-- +-- No BEGIN/COMMIT: MigrationRunner opens its own transaction per script and writes the ledger entry +-- inside it. + +ALTER TABLE crawl_target + ADD COLUMN login_commands_unanswered smallint NOT NULL DEFAULT 0 + CHECK (login_commands_unanswered >= 0), + ADD COLUMN login_commands_quiet_at timestamptz; + +COMMENT ON COLUMN crawl_target.login_commands_unanswered IS + 'Consecutive sessions in which INFO was typed here and no reply was readable. Capped.'; + +COMMENT ON COLUMN crawl_target.login_commands_quiet_at IS + 'When INFO and VERSION stopped being typed here for want of an answer. NULL: still asked.'; diff --git a/src/MUI.Crawl/LoginFlow/LoginCommandReading.cs b/src/MUI.Crawl/LoginFlow/LoginCommandReading.cs index 556a70f..00a9969 100644 --- a/src/MUI.Crawl/LoginFlow/LoginCommandReading.cs +++ b/src/MUI.Crawl/LoginFlow/LoginCommandReading.cs @@ -85,6 +85,34 @@ public static partial class LoginCommandReading ?? FromUnlabelledVersion(version); } + /// + /// Whether these replies held anything a reader downstream would stand behind. + /// + /// + /// + /// The question LoginCommands.Learn asks of a session: was typing INFO and + /// VERSION at this login prompt worth it? Answered by the consumers themselves rather than + /// by the shape of the text, so it cannot say yes to a reply nothing reads or no to one something + /// does: a codebase or a name (FieldObservations, CatalogueBinder, + /// IdentityMatcher), a count (PresenceChoice), and the MUCK reading that both + /// replies feed (). + /// + /// + /// MuLikeness's vocabulary signal is not consulted. Its one consumer only reads it for a + /// submission still awaiting §7.8, and such a game is asked every session whatever this says. + /// + /// + /// A name prompt and a plain Huh? are the same answer here. Either way there was nothing to + /// read; the difference matters only within a session, where a name prompt to INFO also + /// spares the game our VERSION (). + /// + /// + public static bool Answered(string? info, string? version) => + MeaningfulCodebase(info, version) is not null + || MeaningfulName(info, version) is not null + || ConnectedPlayers(info) is not null + || MuckNaming.Assumed(info, version) is not null; + /// /// The game's own name as its INFO block gives it, or null. /// diff --git a/src/MUI.Crawl/LoginFlow/NamePrompt.cs b/src/MUI.Crawl/LoginFlow/NamePrompt.cs new file mode 100644 index 0000000..e1e4b34 --- /dev/null +++ b/src/MUI.Crawl/LoginFlow/NamePrompt.cs @@ -0,0 +1,45 @@ +using System.Text.RegularExpressions; + +namespace MUI.Crawl; + +/// +/// Whether a line is a login prompt that took what we typed for a character name. +/// +/// +/// +/// Read in two places, and one list so the two cannot drift: asks it of the +/// reply to WHO, where a match means the server never had a WHO to answer +/// (); and TelnetProbe asks it of the reply to +/// INFO, where a match means VERSION would be read the same way and is not sent. +/// +/// +/// The vocabulary is wider than one codebase: a game may ask for an account name rather than +/// a character's, print nothing but Name:, refuse a disliked name outright (Illegal name, +/// try again., That name is reserved for a senior member of the mud.), or ask us to +/// confirm the spelling (Did I get that right, Who (Y/N)?). +/// +/// +/// The Chinese forms are the ES2/MudOS family's, measured at fs.twkang.net:5555 (issue #182): +/// INFO came back 好吧﹐那麼請重新輸入您的英文名字﹕ ("re-enter your English name") and +/// VERSION 使用 version 這個名字將會創造一個新的人物﹐您確定嗎(y/n)﹖ ("the name version +/// will create a new character — are you sure?"). Both scripts, since the family runs in Big5 and +/// GBK alike. Readable only once the screen has been decoded as what it is, which for these games +/// means an operator's CHARSET; in the Latin-1 fallback they match nothing, and the probe +/// asks VERSION as it did before. +/// +/// +public static partial class NamePrompt +{ + /// Whether this one line is a login prompt reading our input as a name. + public static bool IsIn(string line) => Pattern().IsMatch(line); + + [GeneratedRegex( + @"no\s+character\s+by\s+that\s+name|enter\s+(?:the\s+|your\s+)?(?:\w+\s+)?name" + + @"|create\s+a\s+new\s+(?:character|account|player)" + + @"|what\s+is\s+your\s+name|password\s*:|type\s+'?new'?|\bname\s*:\s*$" + + @"|\billegal\s+name\b|\bno\s+record\s+found\s+for\b|\bname\s+is\s+reserved\b" + + @"|\bdid\s+i\s+get\s+that\s+right\b" + + @"|[輸输]入[^\n]{0,6}名字|[創创]造一[個个]新的?人物", + RegexOptions.IgnoreCase)] + private static partial Regex Pattern(); +} diff --git a/src/MUI.Crawl/Telnet/ProbeResult.cs b/src/MUI.Crawl/Telnet/ProbeResult.cs index d5dc4e4..efb23b6 100644 --- a/src/MUI.Crawl/Telnet/ProbeResult.cs +++ b/src/MUI.Crawl/Telnet/ProbeResult.cs @@ -100,6 +100,22 @@ public sealed record ProbeResult /// The reply to VERSION at the login screen, when one arrived. public string? Version { get; init; } + /// Whether INFO was typed at the login screen this session. + /// + /// The difference between "not asked" and "asked, and nothing came back", which a null + /// cannot carry: it is null for both. LoginCommands.Learn counts a + /// session against a game only when this is true, so a session in which we held our tongue is + /// never read as one in which the game said nothing (rule 5, the who_not_offered lesson). + /// + public bool InfoAsked { get; init; } + + /// Whether VERSION was typed at the login screen this session. + /// + /// Never without , and not always with it: a login prompt that took + /// INFO for a character name is not handed VERSION as a second one. + /// + public bool VersionAsked { get; init; } + /// /// Layer 4 — MSSP as the server reported it over telnet option 70. Every variable, every value, /// in wire order. diff --git a/src/MUI.Crawl/Telnet/Probing.cs b/src/MUI.Crawl/Telnet/Probing.cs index 607b23c..f31d12c 100644 --- a/src/MUI.Crawl/Telnet/Probing.cs +++ b/src/MUI.Crawl/Telnet/Probing.cs @@ -63,6 +63,27 @@ public sealed record ProbeTarget(string Host, int Port) /// public bool AwaitingCorroboration { get; init; } = true; + /// + /// Whether INFO and VERSION may be typed at this address's login prompt. + /// + /// + /// + /// False means this address has been asked both, session after session, and nothing in any reply + /// was something a reader here would stand behind — so it is not asked again until a retrial + /// falls due. A codebase that does not answer INFO today almost certainly never will, and + /// at fs.twkang.net:5555 each word is read as a character name: VERSION comes back + /// as create a new character called version? (y/n), every crawl (issue #182). + /// + /// + /// True by default, so a caller that cannot say keeps asking, as with + /// . Only the crawl loop answers it, from + /// crawl_target.login_commands_quiet_at (migration 0046, see LoginCommands). An MSSP + /// report that already answers both () stops them whatever this + /// says. + /// + /// + public bool AskLoginCommands { get; init; } = true; + /// Whether to open this dial with a TLS handshake rather than in the clear. /// /// diff --git a/src/MUI.Crawl/Telnet/TelnetProbe.cs b/src/MUI.Crawl/Telnet/TelnetProbe.cs index 36d2f3b..73ec7de 100644 --- a/src/MUI.Crawl/Telnet/TelnetProbe.cs +++ b/src/MUI.Crawl/Telnet/TelnetProbe.cs @@ -902,14 +902,26 @@ async Task AskAsync(string command, int baseline, TimeSpan grace, Action? s && MsspSelfDescription.AnswersTheLoginCommands( MsspReport.From(seen.Mssp, WireEncoding.Fallback)); - if (Live(connection) && !described) + // + // And an address that has been asked both, session after session, and never once said + // anything a reader here could use (ProbeTarget.AskLoginCommands, issue #182). Whether to + // stop is the crawl loop's call, made from this address's history; this only obeys it. + var ask = !described && target.AskLoginCommands; + + if (Live(connection) && ask) { - cursors.Info = cursors.Version = await AskAsync(InfoCommand, cursors.Who, _options.SilenceGrace); + cursors.Info = cursors.Version = await AskAsync( + InfoCommand, cursors.Who, _options.SilenceGrace, () => seen.InfoAsked = true); } - if (Live(connection) && !described) + // Within the session, too: a login prompt that took INFO for a character name will take + // VERSION for one, and at fs.twkang.net:5555 that is "create a new character called + // version? (y/n)". Only a name prompt stops it. A plain "Huh?" to INFO says nothing about + // VERSION, which some codebases answer without answering INFO. + if (Live(connection) && ask && !TookForAName(lines, cursors.Who, cursors.Info, seen, target)) { - cursors.Version = await AskAsync(VersionCommand, cursors.Info, _options.SilenceGrace); + cursors.Version = await AskAsync( + VersionCommand, cursors.Info, _options.SilenceGrace, () => seen.VersionAsked = true); } } catch (Exception error) when (HungUp(error) && Measured(lines, cursors.Banner, seen)) @@ -967,8 +979,8 @@ async Task AskAsync(string command, int baseline, TimeSpan grace, Action? s /// nothing, publish no MSSP, state their count on the screen in Chinese, and read every line we /// send as a character name: WHO comes back 請重新輸入您的英文名字 ("re-enter your /// English name"), reproducibly, on every crawl. See ChineseCount for the reading that - /// makes the screen answer, and issue #182 for INFO and VERSION, which are still - /// typed at the same prompt. + /// makes the screen answer, and for INFO and + /// VERSION at the same prompt (issue #182). /// /// private async Task PublishedCountAsync( @@ -1023,6 +1035,40 @@ async Task AskAsync(string command, int baseline, TimeSpan grace, Action? s return BannerCount.Find(PuebloSignal.IsPresent(banner) ? PuebloSignal.StripKnown(banner) : banner); } + /// + /// Whether the reply between these two cursors is a login prompt that read our command as a + /// character name, and offered nothing else. + /// + /// + /// Decoded the way decodes the connect screen, and for the same + /// reason: the session-wide charset decision is still ahead, and this has to be answered before + /// the next line is sent. A reply that a reader could use is never a name prompt here, whatever + /// else it contains: a real INFO block may well say Name:. + /// + private static bool TookForAName(List lines, int from, int to, Observations seen, ProbeTarget target) + { + if (to <= from) + { + return false; + } + + List reply; + lock (lines) + { + reply = [.. lines.Skip(from).Take(to - from)]; + } + + var text = string.Join( + "\n", + WireEncoding.Read(reply, target.Charset, MsspReport.RawValues(seen.Mssp), target.MsspCharset).Lines); + + return !LoginCommandReading.Answered(text, null) + && global::MarkupString.Ansi.AnsiEscapeParser.Parse(text).ToPlainText() + .Split('\n') + .Select(line => line.TrimEnd()) + .Any(NamePrompt.IsIn); + } + /// Builds the result from a completed session. private static ProbeResult BuildAnsweredResult( ProbeTarget target, @@ -1103,6 +1149,8 @@ private static ProbeResult BuildAnsweredResult( : (asked ? PayloadRedaction.Replayable(whoText) : null), Info = infoText.Length == 0 ? null : infoText, Version = versionText.Length == 0 ? null : versionText, + InfoAsked = seen.InfoAsked, + VersionAsked = seen.VersionAsked, // `published` is the count that bought this game its silence — see PublishedCountAsync for // why not asking must imply publishing. Second, not first: the session-wide charset // decision is made above and a screen this decode reads better is read better. @@ -1664,6 +1712,15 @@ private sealed class Observations /// Set while a plaintext MSSP-REQUEST waits for its reply. public volatile bool AskingPlaintext; public int? MsspRejectedBytes; + + /// + /// Whether INFO and VERSION left this session, each set between its write and + /// its wait. See . + /// + public bool InfoAsked; + + /// + public bool VersionAsked; public string? Charset; public bool Prompts; public int? CompressionVersion; diff --git a/src/MUI.Crawl/Who/WhoParser.cs b/src/MUI.Crawl/Who/WhoParser.cs index 051ace6..f46d9f9 100644 --- a/src/MUI.Crawl/Who/WhoParser.cs +++ b/src/MUI.Crawl/Who/WhoParser.cs @@ -347,7 +347,7 @@ private static bool IsTerminator(string line) => /// /// Whether the server answered the login prompt rather than the question. /// - private static bool LooksLikeLoginPrompt(string line) => LoginPromptPattern().IsMatch(line); + private static bool LooksLikeLoginPrompt(string line) => NamePrompt.IsIn(line); private static string StripAnsi(string text) => AnsiEscapeParser.Parse(text).ToPlainText(); @@ -560,19 +560,4 @@ private static bool IsTerminator(string line) => + @"\b[^.\n]{0,40}?\b" + Connectivity + @"\b", RegexOptions.IgnoreCase)] private static partial Regex WordedOutOfPattern(); - - // Login prompts that mean WHO was eaten as a character name. Vocabulary is wider than one - // codebase: a game may ask for an *account* name rather than a character's, print nothing but - // "Name:", refuse a disliked name outright ("Illegal name, try again.", "That name is reserved - // for a senior member of the mud."), or ask us to confirm the spelling ("Did I get that right, - // Who (Y/N)?"). - [GeneratedRegex( - @"no\s+character\s+by\s+that\s+name|enter\s+(?:the\s+|your\s+)?(?:\w+\s+)?name" - + @"|create\s+a\s+new\s+(?:character|account|player)" - + @"|what\s+is\s+your\s+name|password\s*:|type\s+'?new'?|\bname\s*:\s*$" - + @"|\billegal\s+name\b|\bno\s+record\s+found\s+for\b|\bname\s+is\s+reserved\b" - + @"|\bdid\s+i\s+get\s+that\s+right\b", - RegexOptions.IgnoreCase)] - private static partial Regex LoginPromptPattern(); - } diff --git a/src/MUI.Crawler/Crawl/CrawlCycle.cs b/src/MUI.Crawler/Crawl/CrawlCycle.cs index 68d991c..663575f 100644 --- a/src/MUI.Crawler/Crawl/CrawlCycle.cs +++ b/src/MUI.Crawler/Crawl/CrawlCycle.cs @@ -271,6 +271,10 @@ private async Task AttemptAsync(CrawlTarget target, CancellationToken c // Whether WHO is a working command here, so a stated count does not stand in for it. // See WhoAnswers for how the memory changes. WhoAnswers = target.WhoAnswersAt is not null, + + // Whether INFO and VERSION have been answering here. See LoginCommands for both + // halves of that memory (issue #182). + AskLoginCommands = LoginCommands.Ask(target, time.GetUtcNow()), }, budget.Token); @@ -540,6 +544,23 @@ await targets.RecordAttemptAsync( { await targets.RecordWhoAnswersAsync(target.Id, whoAnswers, cancellationToken); } + + // And whether INFO and VERSION are worth typing here, on the same terms. + if (LoginCommands.Learn(target.LoginCommands, result, now) is var loginCommands + && loginCommands != target.LoginCommands) + { + await targets.RecordLoginCommandsAsync(target.Id, loginCommands, cancellationToken); + + if (loginCommands.QuietAt is not null && target.LoginCommands.QuietAt is null) + { + logger?.LogInformation( + "{Host}:{Port} answered INFO and VERSION with nothing readable {Sessions} times running; not asking again for {Days} days", + target.Host, + target.Port, + LoginCommands.Patience, + LoginCommands.Retrial.TotalDays); + } + } } /// diff --git a/src/MUI.Crawler/Persistence/NpgsqlCrawlTargetRepository.cs b/src/MUI.Crawler/Persistence/NpgsqlCrawlTargetRepository.cs index 2e4affc..eb5f290 100644 --- a/src/MUI.Crawler/Persistence/NpgsqlCrawlTargetRepository.cs +++ b/src/MUI.Crawler/Persistence/NpgsqlCrawlTargetRepository.cs @@ -43,6 +43,7 @@ public sealed class NpgsqlCrawlTargetRepository(NpgsqlDataSource source) : ICraw discovered_from_game_id AS DiscoveredFromGameId, depth AS Depth, is_operator_seed AS IsOperatorSeed, submitted_at AS SubmittedAt, discovered_via AS DiscoveredVia, mssp_route AS MsspRoute, who_answers_at AS WhoAnswersAt, + login_commands_unanswered AS LoginCommandsUnanswered, login_commands_quiet_at AS LoginCommandsQuietAt, (SELECT f.value FROM game_field f WHERE f.game_id = crawl_target.game_id @@ -214,6 +215,21 @@ await connection.ExecuteAsync(new CommandDefinition( cancellationToken: ct)); } + public async Task RecordLoginCommandsAsync(Guid id, LoginCommandMemory memory, CancellationToken ct) + { + await using var connection = await source.OpenConnectionAsync(ct); + + await connection.ExecuteAsync(new CommandDefinition( + """ + UPDATE crawl_target + SET login_commands_unanswered = @unanswered, + login_commands_quiet_at = @quietAt + WHERE id = @id + """, + new { id, unanswered = (short)memory.Unanswered, quietAt = memory.QuietAt?.ToUniversalTime() }, + cancellationToken: ct)); + } + /// /// Attaches the game this address turned out to be. /// @@ -274,6 +290,10 @@ private sealed class Row public DateTimeOffset? WhoAnswersAt { get; init; } + public short LoginCommandsUnanswered { get; init; } + + public DateTimeOffset? LoginCommandsQuietAt { get; init; } + /// /// Nullable because the subquery has no row to read for a target not yet bound to a game, /// and null there means the same as true: an address that has proved nothing yet is asked @@ -304,6 +324,7 @@ private sealed class Row AwaitingCorroboration = AwaitingCorroboration ?? true, MsspRoute = MsspRouteSpelling.From(MsspRoute), WhoAnswersAt = WhoAnswersAt, + LoginCommands = new LoginCommandMemory(LoginCommandsUnanswered, LoginCommandsQuietAt), }; } } diff --git a/src/MUI.Discovery/Scheduling/CrawlTarget.cs b/src/MUI.Discovery/Scheduling/CrawlTarget.cs index 871e403..333739b 100644 --- a/src/MUI.Discovery/Scheduling/CrawlTarget.cs +++ b/src/MUI.Discovery/Scheduling/CrawlTarget.cs @@ -146,6 +146,12 @@ public sealed record CrawlTarget /// known to answer one (migration 0043). owns how it changes. /// public DateTimeOffset? WhoAnswersAt { get; init; } + + /// + /// Whether INFO and VERSION have been answering here (migration 0046). + /// owns both what it asks for and how it changes. + /// + public LoginCommandMemory LoginCommands { get; init; } } /// @@ -206,5 +212,11 @@ Task RecordAttemptAsync( /// Task RecordWhoAnswersAsync(Guid id, DateTimeOffset? at, CancellationToken ct); + /// + /// Records whether INFO and VERSION have been answering at this address. Written + /// only on a change, like . + /// + Task RecordLoginCommandsAsync(Guid id, LoginCommandMemory memory, CancellationToken ct); + Task AttachGameAsync(Guid id, Guid gameId, CancellationToken ct); } diff --git a/src/MUI.Discovery/Scheduling/LoginCommands.cs b/src/MUI.Discovery/Scheduling/LoginCommands.cs new file mode 100644 index 0000000..47cdec0 --- /dev/null +++ b/src/MUI.Discovery/Scheduling/LoginCommands.cs @@ -0,0 +1,104 @@ +using MUI.Crawl; + +namespace MUI.Discovery; + +/// +/// What the crawl loop remembers about INFO and VERSION at one address +/// (crawl_target.login_commands_*, migration 0046). +/// +/// +/// Consecutive sessions in which INFO was typed and nothing came back that a reader stands +/// behind, capped at . +/// +/// +/// When this address stopped being asked, or null while it is still asked. +/// +public readonly record struct LoginCommandMemory(int Unanswered, DateTimeOffset? QuietAt); + +/// +/// The two decisions exists for: whether to type INFO and +/// VERSION this time, and what a session teaches. Issue #182. +/// +/// +/// +/// MsspSelfDescription stops both where an MSSP report has already answered them, which a game +/// with no MSSP never can — so it was asked on every crawl, for ever. At fs.twkang.net:5555 and +/// its three siblings that means INFO read as a character name and VERSION answered with +/// create a new character called version? (y/n), every thirty minutes, from a server whose +/// answer has not changed since 1995. That is a question to settle from the address's own history, +/// not to re-derive in every session. +/// +/// +/// A pure function of a target's memory and a , as +/// and are, so it is testable without a socket or a database. +/// +/// +public static class LoginCommands +{ + /// + /// How many sessions in a row must come back with nothing readable before the address is left + /// alone. + /// + /// + /// More than one, so a single bad session — a reply cut off by a hang-up, a server mid-restart — + /// cannot silence a game whose INFO works. Not many more, because every one of them is two + /// lines at a stranger's login prompt. + /// + public const int Patience = 3; + + /// How long a quiet address goes before it is asked once more. + /// + /// A game can change codebase, and the readers here can learn a reply they could not read before; + /// neither happens often, so a monthly retrial is enough to notice either without being noise. + /// One retrial that still yields nothing re-dates the quiet; one that yields anything ends it. + /// + public static readonly TimeSpan Retrial = TimeSpan.FromDays(30); + + /// Whether this session may type INFO and VERSION. + /// + /// Always, for a game still awaiting §7.8: MuLikeness reads its vocabulary signal from + /// these replies, and for a game that negotiates nothing they may be the only evidence that it is + /// a game at all. The same escape WHO has (). + /// + public static bool Ask(CrawlTarget target, DateTimeOffset now) + { + ArgumentNullException.ThrowIfNull(target); + + return target.AwaitingCorroboration + || target.LoginCommands.QuietAt is not { } quiet + || now - quiet >= Retrial; + } + + /// + /// The memory after this probe, or when it taught nothing. + /// + /// + /// + /// Only a session that typed INFO teaches anything (). + /// A failed dial, a session cut short before INFO, and a session in which we chose not to + /// ask all leave the memory as it was: our silence is not their silence (rule 5). + /// + /// + /// "Answered" is judged by , the consumers' own readers, + /// so a name prompt and a plain Huh? count alike. One answer clears the whole run. + /// + /// + public static LoginCommandMemory Learn(LoginCommandMemory current, ProbeResult result, DateTimeOffset now) + { + ArgumentNullException.ThrowIfNull(result); + + if (result.Outcome is not ProbeOutcome.Answered || !result.InfoAsked) + { + return current; + } + + if (LoginCommandReading.Answered(result.Info, result.Version)) + { + return new LoginCommandMemory(0, null); + } + + var unanswered = Math.Min(current.Unanswered + 1, Patience); + + return new LoginCommandMemory(unanswered, unanswered >= Patience ? now : null); + } +} diff --git a/src/MUI.Probe/Program.cs b/src/MUI.Probe/Program.cs index a141e8c..1e604a6 100644 --- a/src/MUI.Probe/Program.cs +++ b/src/MUI.Probe/Program.cs @@ -132,11 +132,18 @@ Console.WriteLine($"info count {fromInfo} (declared in the INFO block)"); } -Reply("info", result.Info); -Reply("version", result.Version); +// "not asked" and "no reply" are different facts, and only the second is about the game. +Reply("info", result.Info, result.InfoAsked); +Reply("version", result.Version, result.VersionAsked); -static void Reply(string label, string? text) +static void Reply(string label, string? text, bool asked) { + if (!asked) + { + Console.WriteLine($"{label,-13} (not asked)"); + return; + } + var lines = (text ?? string.Empty) .Split('\n') .Select(line => line.TrimEnd()) diff --git a/tests/MUI.Crawl.Tests/LoginFlow/LoginCommandReadingTests.cs b/tests/MUI.Crawl.Tests/LoginFlow/LoginCommandReadingTests.cs index c04fb2a..0de69c2 100644 --- a/tests/MUI.Crawl.Tests/LoginFlow/LoginCommandReadingTests.cs +++ b/tests/MUI.Crawl.Tests/LoginFlow/LoginCommandReadingTests.cs @@ -4,6 +4,30 @@ namespace MUI.Crawl.Tests; public class LoginCommandReadingTests { + /// + /// Whether a session's INFO and VERSION held anything a reader stands behind — the + /// question that decides whether they keep being typed at an address (issue #182). + /// + [Test] + [Arguments("### Begin INFO 1\r\nName: Mortal Realms\r\nConnected: 7\r\n### End INFO\r\n", null)] + [Arguments(null, "PennMUSH version 1.8.8 patchlevel 0")] + [Arguments("Codebase: CorvidMUSH", null)] + [Arguments(null, "FooMUCK, a TinyMUCK descendant")] + public async Task AReplyAReaderUsesIsAnAnswer(string? info, string? version) + { + await Assert.That(LoginCommandReading.Answered(info, version)).IsTrue(); + } + + [Test] + [Arguments(null, null)] + [Arguments("", "")] + [Arguments("Huh? (Type \"help\" for help.)", "Huh? (Type \"help\" for help.)")] + [Arguments("好吧﹐那麼請重新輸入您的英文名字﹕", "使用 version 這個名字將會創造一個新的人物﹐您確定嗎(y/n)﹖")] + public async Task NothingAReaderUsesIsNotAnAnswer(string? info, string? version) + { + await Assert.That(LoginCommandReading.Answered(info, version)).IsFalse(); + } + /// /// The Dead Souls mudlib reads as the engine it is. /// diff --git a/tests/MUI.Crawl.Tests/LoginFlow/NamePromptTests.cs b/tests/MUI.Crawl.Tests/LoginFlow/NamePromptTests.cs new file mode 100644 index 0000000..67d3bfe --- /dev/null +++ b/tests/MUI.Crawl.Tests/LoginFlow/NamePromptTests.cs @@ -0,0 +1,60 @@ +using MUI.Crawl; + +namespace MUI.Crawl.Tests; + +/// +/// A login prompt that took what we typed for a character name, in the words games actually use. +/// +public class NamePromptTests +{ + /// + /// The ES2/MudOS family's answers, measured at fs.twkang.net:5555 (issue #182), and their + /// simplified-script spellings. + /// + [Test] + [Arguments("好吧﹐那麼請重新輸入您的英文名字﹕")] + [Arguments("使用 version 這個名字將會創造一個新的人物﹐您確定嗎(y/n)﹖")] + [Arguments("好吧,那么请重新输入您的英文名字:")] + [Arguments("使用 version 这个名字将会创造一个新的人物,您确定吗(y/n)?")] + public async Task TheChineseFamilysPromptsAreRead(string line) + { + await Assert.That(NamePrompt.IsIn(line)).IsTrue(); + } + + [Test] + [Arguments("No character by that name found.")] + [Arguments("By what name do you wish to be known? Please enter your name:")] + [Arguments("Name: ")] + [Arguments("Password:")] + [Arguments("Did I get that right, Info (Y/N)?")] + public async Task TheEnglishPromptsStillAre(string line) + { + await Assert.That(NamePrompt.IsIn(line)).IsTrue(); + } + + /// + /// What a game says when it did not understand us is not a name prompt, and neither is anything a + /// real answer contains. + /// + [Test] + [Arguments("Huh? (Type \"help\" for help.)")] + [Arguments("Name: ElendorMUSH")] + [Arguments("目前共有 0 位巫師、83 位玩家在線上,以及 1 位使用者嘗試連線中。")] + [Arguments("PennMUSH version 1.8.8 patchlevel 0 [2020-01-01]")] + public async Task OtherRepliesAreNot(string line) + { + await Assert.That(NamePrompt.IsIn(line)).IsFalse(); + } + + /// + /// WHO at the same family is now read as what it is — the login prompt — rather than as a + /// dialect our parser could not read, which would be our defect written down about their game. + /// + [Test] + public async Task AWhoTakenForANameInChineseIsALoginPrompt() + { + var reading = new WhoParser().Parse("好吧﹐那麼請重新輸入您的英文名字﹕"); + + await Assert.That(reading.Confidence).IsEqualTo(WhoConfidence.LoginPrompt); + } +} diff --git a/tests/MUI.Crawl.Tests/Telnet/ProbeSessionTests.cs b/tests/MUI.Crawl.Tests/Telnet/ProbeSessionTests.cs index 920f18a..a01a289 100644 --- a/tests/MUI.Crawl.Tests/Telnet/ProbeSessionTests.cs +++ b/tests/MUI.Crawl.Tests/Telnet/ProbeSessionTests.cs @@ -24,6 +24,95 @@ namespace MUI.Crawl.Tests; public class ProbeSessionTests { /// Short, so the suite settles in a moment rather than in the live defaults. + /// + /// An address the crawl loop has stopped asking is not typed at: neither word leaves, and the + /// result says we did not ask rather than that nothing came back (issue #182). + /// + [Test] + public async Task AnAddressNotToBeAskedIsNotTypedAt() + { + await using var game = new FakeGame + { + Banner = "Welcome to Mortal Realms\r\n", + BannerTail = "By what name do you wish to be known? ", + WhoReply = "7 Players logged in, 22 record, no maximum.\r\n", + InfoReply = "### Begin INFO 1\r\nName: Mortal Realms\r\nConnected: 7\r\n### End INFO\r\n", + VersionReply = "Version 1.2.3\r\n", + }; + + var result = await new TelnetProbe(Fast()) + .ProbeAsync(game.Target with { AskLoginCommands = false }); + + var received = game.Received.Select(line => line.Trim()).ToList(); + + await Assert.That(received).Contains(TelnetProbe.WhoCommand); + await Assert.That(received).DoesNotContain(TelnetProbe.InfoCommand); + await Assert.That(received).DoesNotContain(TelnetProbe.VersionCommand); + await Assert.That(result.InfoAsked).IsFalse(); + await Assert.That(result.VersionAsked).IsFalse(); + await Assert.That(result.Info).IsNull(); + } + + /// + /// A login prompt that took INFO for a character name is not handed VERSION as a + /// second one. + /// + /// + /// Measured at fs.twkang.net:5555: INFO came back as the name prompt again, and + /// VERSION as create a new character called version? (y/n). This fixture says the + /// same words, on the wire as UTF-8. + /// + [Test] + public async Task VersionIsNotSentWhereInfoWasTakenForAName() + { + static string OnTheWire(string text) => Encoding.Latin1.GetString(Encoding.UTF8.GetBytes(text)); + + await using var game = new FakeGame + { + Banner = OnTheWire("\u72C2\u60F3\u7A7A\u9593\r\n"), + BannerTail = OnTheWire("請輸入您的英文名字: "), + WhoReply = OnTheWire("好吧﹐那麼請重新輸入您的英文名字﹕\r\n"), + InfoReply = OnTheWire("好吧﹐那麼請重新輸入您的英文名字﹕\r\n"), + VersionReply = OnTheWire("使用 version 這個名字將會創造一個新的人物﹐您確定嗎(y/n)﹖\r\n"), + }; + + var result = await new TelnetProbe(Fast()).ProbeAsync(game.Target); + + var received = game.Received.Select(line => line.Trim()).ToList(); + + await Assert.That(received).Contains(TelnetProbe.InfoCommand); + await Assert.That(received).DoesNotContain(TelnetProbe.VersionCommand); + await Assert.That(result.InfoAsked).IsTrue(); + await Assert.That(result.VersionAsked).IsFalse(); + + // And WHO at the same prompt reads as what it is, not as a dialect we failed to parse. + await Assert.That(result.Who.Confidence).IsEqualTo(WhoConfidence.LoginPrompt); + } + + /// + /// A plain "Huh?" to INFO is not a name prompt and says nothing about VERSION, which + /// is still asked. + /// + [Test] + public async Task VersionIsStillSentWhereInfoWasMerelyNotUnderstood() + { + await using var game = new FakeGame + { + Banner = "Welcome to Mortal Realms\r\n", + BannerTail = "By what name do you wish to be known? ", + WhoReply = "7 Players logged in, 22 record, no maximum.\r\n", + InfoReply = "Huh? (Type \"help\" for help.)\r\n", + VersionReply = "PennMUSH version 1.8.8 patchlevel 0\r\n", + }; + + var result = await new TelnetProbe(Fast()).ProbeAsync(game.Target); + + await Assert.That(game.Received.Select(line => line.Trim())).Contains(TelnetProbe.VersionCommand); + await Assert.That(result.InfoAsked).IsTrue(); + await Assert.That(result.VersionAsked).IsTrue(); + await Assert.That(LoginCommandReading.MeaningfulCodebase(result.Info, result.Version)).IsNotNull(); + } + private static ProbeOptions Fast() => new() { QuietPeriod = TimeSpan.FromMilliseconds(120), diff --git a/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs b/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs new file mode 100644 index 0000000..a286e0a --- /dev/null +++ b/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs @@ -0,0 +1,89 @@ +using Dapper; + +using MUI.Crawl; +using MUI.Crawler.Tests.Support; +using MUI.Discovery; + +namespace MUI.Crawler.Tests; + +/// +/// What the crawl loop remembers about whether INFO and VERSION answer at an address +/// (crawl_target.login_commands_*, migration 0046), and that the next dial is told. +/// +public class LoginCommandsPostgresTests +{ + private const string Host = "fs.example.tw"; + private const int Port = 5555; + + /// What fs.twkang.net:5555 answers to INFO: its name prompt, again. + private static ProbeResult NamePrompt(ProbeTarget target) => Probes.Answered( + host: target.Host, + port: target.Port, + who: new WhoReading(WhoConfidence.Count, 12), + info: "好吧﹐那麼請重新輸入您的英文名字﹕") with { InfoAsked = target.AskLoginCommands }; + + [Test] + public async Task AnAddressThatNeverAnswersIsLeftAloneAfterThreeSessions() + { + await using var database = await PostgresFixture.MigratedAsync(); + var source = database.DataSource; + + await CrawlCycles.SeedAsync(source, new CrawlSeed(Host, Port)); + + await using var connection = await source.OpenConnectionAsync(); + + for (var session = 0; session < LoginCommands.Patience; session++) + { + var probe = new ScriptedProbe(NamePrompt); + await CrawlCycles.Build(source, probe, TimeProvider.System).RunAsync(); + + await Assert.That(probe.Asked.Single().AskLoginCommands).IsTrue(); + + await DueAgainAsync(connection); + } + + await Assert.That(await UnansweredAsync(connection)).IsEqualTo(LoginCommands.Patience); + await Assert.That(await QuietAsync(connection)).IsTrue(); + + var next = new ScriptedProbe(NamePrompt); + await CrawlCycles.Build(source, next, TimeProvider.System).RunAsync(); + + await Assert.That(next.Asked.Single().AskLoginCommands).IsFalse(); + + // Not asking is not a miss: the memory is exactly as it was. + await Assert.That(await UnansweredAsync(connection)).IsEqualTo(LoginCommands.Patience); + } + + [Test] + public async Task ARetrialThatAnswersEndsTheQuiet() + { + await using var database = await PostgresFixture.MigratedAsync(); + var source = database.DataSource; + + await CrawlCycles.SeedAsync(source, new CrawlSeed(Host, Port)); + + await using var connection = await source.OpenConnectionAsync(); + await connection.ExecuteAsync( + "UPDATE crawl_target SET login_commands_unanswered = 3, login_commands_quiet_at = now() - interval '31 days'"); + + var probe = new ScriptedProbe(target => Probes.Answered( + host: target.Host, + port: target.Port, + info: "### Begin INFO 1\r\nName: Mortal Realms\r\nConnected: 7\r\n### End INFO\r\n") + with { InfoAsked = target.AskLoginCommands }); + await CrawlCycles.Build(source, probe, TimeProvider.System).RunAsync(); + + await Assert.That(probe.Asked.Single().AskLoginCommands).IsTrue(); + await Assert.That(await UnansweredAsync(connection)).IsEqualTo(0); + await Assert.That(await QuietAsync(connection)).IsFalse(); + } + + private static Task UnansweredAsync(Npgsql.NpgsqlConnection connection) => + connection.ExecuteScalarAsync("SELECT login_commands_unanswered FROM crawl_target"); + + private static Task QuietAsync(Npgsql.NpgsqlConnection connection) => + connection.ExecuteScalarAsync("SELECT login_commands_quiet_at IS NOT NULL FROM crawl_target"); + + private static Task DueAgainAsync(Npgsql.NpgsqlConnection connection) => + connection.ExecuteAsync("UPDATE crawl_target SET next_probe_at = now() - interval '1 hour'"); +} diff --git a/tests/MUI.Crawler.Tests/Support/FakeStores.cs b/tests/MUI.Crawler.Tests/Support/FakeStores.cs index 8677e37..e2d3c63 100644 --- a/tests/MUI.Crawler.Tests/Support/FakeStores.cs +++ b/tests/MUI.Crawler.Tests/Support/FakeStores.cs @@ -68,6 +68,8 @@ public Task RecordMsspRouteAsync(Guid id, MsspRoute? route, DateTimeOffset at, C public Task RecordWhoAnswersAsync(Guid id, DateTimeOffset? at, CancellationToken ct) => Task.CompletedTask; + public Task RecordLoginCommandsAsync(Guid id, LoginCommandMemory memory, CancellationToken ct) => Task.CompletedTask; + public Task AttachGameAsync(Guid id, Guid gameId, CancellationToken ct) => Task.CompletedTask; } diff --git a/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs b/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs new file mode 100644 index 0000000..805148b --- /dev/null +++ b/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs @@ -0,0 +1,119 @@ +using MUI.Crawl; +using MUI.Discovery.Tests.Support; + +namespace MUI.Discovery.Tests; + +/// +/// Whether INFO and VERSION are still worth typing at an address, and what a session +/// teaches about it (issue #182). +/// +public class LoginCommandsTests +{ + private static readonly DateTimeOffset Now = new(2026, 11, 16, 5, 0, 0, TimeSpan.Zero); + + private static readonly LoginCommandMemory Fresh = default; + + /// What fs.twkang.net:5555 says to both, as text. + private static readonly ProbeResult NamePrompt = ProbeResults.Answered( + info: "好吧﹐那麼請重新輸入您的英文名字﹕") with { InfoAsked = true }; + + private static readonly ProbeResult Huh = ProbeResults.Answered( + info: "Huh? (Type \"help\" for help.)", + version: "Huh? (Type \"help\" for help.)") with { InfoAsked = true, VersionAsked = true }; + + private static readonly ProbeResult InfoBlock = ProbeResults.Answered( + info: "### Begin INFO 1\r\nName: Mortal Realms\r\nConnected: 7\r\n### End INFO\r\n") + with { InfoAsked = true, VersionAsked = true }; + + [Test] + public async Task ThreeSessionsWithNothingReadableRunningSilenceTheAddress() + { + var memory = Fresh; + + for (var session = 1; session < LoginCommands.Patience; session++) + { + memory = LoginCommands.Learn(memory, session % 2 == 0 ? Huh : NamePrompt, Now); + + await Assert.That(memory.QuietAt).IsNull(); + await Assert.That(LoginCommands.Ask(Listed(memory), Now)).IsTrue(); + } + + memory = LoginCommands.Learn(memory, NamePrompt, Now); + + await Assert.That(memory).IsEqualTo(new LoginCommandMemory(LoginCommands.Patience, Now)); + await Assert.That(LoginCommands.Ask(Listed(memory), Now.AddDays(1))).IsFalse(); + } + + [Test] + public async Task OneAnswerClearsTheRun() + { + var memory = new LoginCommandMemory(LoginCommands.Patience - 1, null); + + await Assert.That(LoginCommands.Learn(memory, InfoBlock, Now)).IsEqualTo(Fresh); + } + + /// + /// A quiet address is asked once a month, and what that one session finds decides the next month. + /// + [Test] + public async Task AQuietAddressIsRetriedAndTheRetrialDecides() + { + var quiet = new LoginCommandMemory(LoginCommands.Patience, Now); + var due = Now + LoginCommands.Retrial; + + await Assert.That(LoginCommands.Ask(Listed(quiet), due.AddMinutes(-1))).IsFalse(); + await Assert.That(LoginCommands.Ask(Listed(quiet), due)).IsTrue(); + + await Assert.That(LoginCommands.Learn(quiet, NamePrompt, due)) + .IsEqualTo(new LoginCommandMemory(LoginCommands.Patience, due)); + + await Assert.That(LoginCommands.Learn(quiet, InfoBlock, due)).IsEqualTo(Fresh); + } + + /// + /// Rule 5: our silence is not theirs. A session that did not type INFO — because we chose + /// not to, or because the dial never got that far — leaves the memory exactly as it was, even + /// though its Info is as empty as a game that answered nothing. + /// + [Test] + public async Task ASessionThatNeverAskedOrNeverConnectedTeachesNothing() + { + var memory = new LoginCommandMemory(1, null); + + await Assert.That(LoginCommands.Learn(memory, ProbeResults.Answered(), Now)).IsEqualTo(memory); + await Assert.That(LoginCommands.Learn(memory, ProbeResults.Failed(), Now)).IsEqualTo(memory); + + var quiet = new LoginCommandMemory(LoginCommands.Patience, Now.AddDays(-3)); + + await Assert.That(LoginCommands.Learn(quiet, ProbeResults.Answered(), Now)).IsEqualTo(quiet); + } + + /// + /// A submission still awaiting §7.8 is asked whatever its history says: for a game that + /// negotiates nothing, these replies may be the only evidence that it is a game at all. + /// + [Test] + public async Task ASubmissionAwaitingCorroborationIsAlwaysAsked() + { + var quiet = new LoginCommandMemory(LoginCommands.Patience, Now); + + await Assert.That(LoginCommands.Ask(Listed(quiet) with { AwaitingCorroboration = true }, Now)).IsTrue(); + } + + [Test] + public async Task AnAddressWithNoHistoryIsAsked() + { + await Assert.That(LoginCommands.Ask(Listed(Fresh), Now)).IsTrue(); + } + + private static CrawlTarget Listed(LoginCommandMemory memory) => new() + { + Id = Guid.NewGuid(), + Host = "fs.twkang.net", + Port = 5555, + NextProbeAt = Now, + FirstSeenAt = Now.AddYears(-1), + AwaitingCorroboration = false, + LoginCommands = memory, + }; +} diff --git a/tests/MUI.Discovery.Tests/Support/InMemoryCrawlTargetRepository.cs b/tests/MUI.Discovery.Tests/Support/InMemoryCrawlTargetRepository.cs index 907464d..1078271 100644 --- a/tests/MUI.Discovery.Tests/Support/InMemoryCrawlTargetRepository.cs +++ b/tests/MUI.Discovery.Tests/Support/InMemoryCrawlTargetRepository.cs @@ -85,6 +85,13 @@ public Task RecordWhoAnswersAsync(Guid id, DateTimeOffset? at, CancellationToken return Task.CompletedTask; } + public Task RecordLoginCommandsAsync(Guid id, LoginCommandMemory memory, CancellationToken ct) + { + Replace(id, target => target with { LoginCommands = memory }); + + return Task.CompletedTask; + } + public Task AttachGameAsync(Guid id, Guid gameId, CancellationToken ct) { Replace(id, target => target.GameId is null ? target with { GameId = gameId } : target); diff --git a/tests/MUI.Web.Tests/StoredCrawlerPulseTests.cs b/tests/MUI.Web.Tests/StoredCrawlerPulseTests.cs index 163d9a4..e643ccb 100644 --- a/tests/MUI.Web.Tests/StoredCrawlerPulseTests.cs +++ b/tests/MUI.Web.Tests/StoredCrawlerPulseTests.cs @@ -186,6 +186,9 @@ public Task RecordMsspRouteAsync(Guid id, MsspRoute? route, DateTimeOffset at, C public Task RecordWhoAnswersAsync(Guid id, DateTimeOffset? at, CancellationToken ct) => throw new NotSupportedException(); + public Task RecordLoginCommandsAsync(Guid id, LoginCommandMemory memory, CancellationToken ct) => + throw new NotSupportedException(); + public Task AttachGameAsync(Guid id, Guid gameId, CancellationToken ct) => throw new NotSupportedException(); } From 4ff120ff3b73d904e3aacc9c8b3a8b3ffbafa7c6 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 16 Nov 2026 05:26:12 +0000 Subject: [PATCH 2/2] Stop asking INFO and VERSION for good after three silent sessions Drop the 30-day retrial. Once an address has gone three sessions with nothing readable, it is not asked again; only a submission still awaiting corroboration is, and a miss there keeps the original date. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Rqqt7TV49bXFnCQC3ZmM6c --- CLAUDE.md | 4 +-- migrations/0046_login_commands.sql | 5 +-- src/MUI.Crawl/Telnet/Probing.cs | 3 +- src/MUI.Crawler/Crawl/CrawlCycle.cs | 7 ++-- src/MUI.Discovery/Scheduling/LoginCommands.cs | 34 +++++++++---------- .../Crawl/LoginCommandsPostgresTests.cs | 20 +++++------ .../Scheduling/LoginCommandsTests.cs | 33 +++++++++++------- 7 files changed, 56 insertions(+), 50 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index fafc0b7..03deb4c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -102,8 +102,8 @@ our host is unreachable and perfectly alive. character name, `VERSION` answered *create a new character called version? (y/n)* (issue #182). `crawl_target.login_commands_*` (migration 0046) is the memory and `LoginCommands` the one place that reads it: three sessions running in which `LoginCommandReading.Answered` finds nothing silence - the address, a retrial every thirty days can end the silence, and a submission still awaiting §7.8 - is always asked. **Only a session that typed `INFO` counts** (`ProbeResult.InfoAsked`): there is + the address **for good** (there is deliberately no retrial), and a submission still + awaiting §7.8 is always asked. **Only a session that typed `INFO` counts** (`ProbeResult.InfoAsked`): there is nothing they would publish, so "not asking must imply publishing" has nothing to hold on to, and the rule 5 hazard instead is our silence counted as theirs. Within a session, `INFO` answered by a name prompt (`NamePrompt`) also spares the game our `VERSION`; a plain `Huh?` does not. diff --git a/migrations/0046_login_commands.sql b/migrations/0046_login_commands.sql index 564d504..36fb765 100644 --- a/migrations/0046_login_commands.sql +++ b/migrations/0046_login_commands.sql @@ -11,8 +11,9 @@ -- the replies was something a reader stands behind. Capped at the -- threshold. Back to 0 on the first session that yields anything. -- login_commands_quiet_at NULL: asked. Set: the run reached the threshold at this time, and --- INFO and VERSION are not typed again until a retrial falls due. A --- retrial that answers clears it; one that does not re-dates it. +-- INFO and VERSION are not typed here again. There is no retrial. The +-- one exception is a submission still awaiting corroboration, which +-- is asked regardless; an answer from it clears both columns. -- -- A session in which we did not type INFO is no evidence either way and changes neither column, so -- our silence is never counted as theirs (rule 5). And none of this is a fact about the game on any diff --git a/src/MUI.Crawl/Telnet/Probing.cs b/src/MUI.Crawl/Telnet/Probing.cs index f31d12c..97c713a 100644 --- a/src/MUI.Crawl/Telnet/Probing.cs +++ b/src/MUI.Crawl/Telnet/Probing.cs @@ -69,8 +69,7 @@ public sealed record ProbeTarget(string Host, int Port) /// /// /// False means this address has been asked both, session after session, and nothing in any reply - /// was something a reader here would stand behind — so it is not asked again until a retrial - /// falls due. A codebase that does not answer INFO today almost certainly never will, and + /// was something a reader here would stand behind — so it is not asked again. A codebase that does not answer INFO today almost certainly never will, and /// at fs.twkang.net:5555 each word is read as a character name: VERSION comes back /// as create a new character called version? (y/n), every crawl (issue #182). /// diff --git a/src/MUI.Crawler/Crawl/CrawlCycle.cs b/src/MUI.Crawler/Crawl/CrawlCycle.cs index 663575f..4eb239e 100644 --- a/src/MUI.Crawler/Crawl/CrawlCycle.cs +++ b/src/MUI.Crawler/Crawl/CrawlCycle.cs @@ -274,7 +274,7 @@ private async Task AttemptAsync(CrawlTarget target, CancellationToken c // Whether INFO and VERSION have been answering here. See LoginCommands for both // halves of that memory (issue #182). - AskLoginCommands = LoginCommands.Ask(target, time.GetUtcNow()), + AskLoginCommands = LoginCommands.Ask(target), }, budget.Token); @@ -554,11 +554,10 @@ await targets.RecordAttemptAsync( if (loginCommands.QuietAt is not null && target.LoginCommands.QuietAt is null) { logger?.LogInformation( - "{Host}:{Port} answered INFO and VERSION with nothing readable {Sessions} times running; not asking again for {Days} days", + "{Host}:{Port} answered INFO and VERSION with nothing readable {Sessions} times running; not asking again", target.Host, target.Port, - LoginCommands.Patience, - LoginCommands.Retrial.TotalDays); + LoginCommands.Patience); } } } diff --git a/src/MUI.Discovery/Scheduling/LoginCommands.cs b/src/MUI.Discovery/Scheduling/LoginCommands.cs index 47cdec0..af21ee8 100644 --- a/src/MUI.Discovery/Scheduling/LoginCommands.cs +++ b/src/MUI.Discovery/Scheduling/LoginCommands.cs @@ -11,7 +11,7 @@ namespace MUI.Discovery; /// behind, capped at . /// /// -/// When this address stopped being asked, or null while it is still asked. +/// When this address stopped being asked, for good, or null while it is still asked. /// public readonly record struct LoginCommandMemory(int Unanswered, DateTimeOffset? QuietAt); @@ -46,27 +46,25 @@ public static class LoginCommands /// public const int Patience = 3; - /// How long a quiet address goes before it is asked once more. - /// - /// A game can change codebase, and the readers here can learn a reply they could not read before; - /// neither happens often, so a monthly retrial is enough to notice either without being noise. - /// One retrial that still yields nothing re-dates the quiet; one that yields anything ends it. - /// - public static readonly TimeSpan Retrial = TimeSpan.FromDays(30); - /// Whether this session may type INFO and VERSION. /// - /// Always, for a game still awaiting §7.8: MuLikeness reads its vocabulary signal from - /// these replies, and for a game that negotiates nothing they may be the only evidence that it is - /// a game at all. The same escape WHO has (). + /// + /// Never again, once an address has gone quiet. There is no retrial: a codebase that does not + /// answer INFO today almost certainly never will, and a monthly retrial would still be two + /// lines at a stranger's login prompt for an answer we already have. A game that changes codebase + /// is still read through its connect screen and MSSP, which are never gated by this. + /// + /// + /// The one exception is a game still awaiting §7.8: MuLikeness reads its vocabulary signal + /// from these replies, and for a game that negotiates nothing they may be the only evidence that it + /// is a game at all. The same escape WHO has (). + /// /// - public static bool Ask(CrawlTarget target, DateTimeOffset now) + public static bool Ask(CrawlTarget target) { ArgumentNullException.ThrowIfNull(target); - return target.AwaitingCorroboration - || target.LoginCommands.QuietAt is not { } quiet - || now - quiet >= Retrial; + return target.AwaitingCorroboration || target.LoginCommands.QuietAt is null; } /// @@ -99,6 +97,8 @@ public static LoginCommandMemory Learn(LoginCommandMemory current, ProbeResult r var unanswered = Math.Min(current.Unanswered + 1, Patience); - return new LoginCommandMemory(unanswered, unanswered >= Patience ? now : null); + // Dated once, when the address went quiet. A miss while quiet (only a submission awaiting + // §7.8 is asked then) leaves the date where it was. + return new LoginCommandMemory(unanswered, unanswered >= Patience ? current.QuietAt ?? now : null); } } diff --git a/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs b/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs index a286e0a..06ab0b6 100644 --- a/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs +++ b/tests/MUI.Crawler.Tests/Crawl/LoginCommandsPostgresTests.cs @@ -55,27 +55,27 @@ public async Task AnAddressThatNeverAnswersIsLeftAloneAfterThreeSessions() } [Test] - public async Task ARetrialThatAnswersEndsTheQuiet() + public async Task AQuietAddressIsNotAskedHoweverLongAgoItWentQuiet() { await using var database = await PostgresFixture.MigratedAsync(); var source = database.DataSource; await CrawlCycles.SeedAsync(source, new CrawlSeed(Host, Port)); + // Bound to a listed game first, so the §7.8 escape does not apply. + var first = new ScriptedProbe(NamePrompt); + await CrawlCycles.Build(source, first, TimeProvider.System).RunAsync(); + await using var connection = await source.OpenConnectionAsync(); await connection.ExecuteAsync( - "UPDATE crawl_target SET login_commands_unanswered = 3, login_commands_quiet_at = now() - interval '31 days'"); + "UPDATE crawl_target SET login_commands_unanswered = 3, login_commands_quiet_at = now() - interval '2 years'"); + await DueAgainAsync(connection); - var probe = new ScriptedProbe(target => Probes.Answered( - host: target.Host, - port: target.Port, - info: "### Begin INFO 1\r\nName: Mortal Realms\r\nConnected: 7\r\n### End INFO\r\n") - with { InfoAsked = target.AskLoginCommands }); + var probe = new ScriptedProbe(NamePrompt); await CrawlCycles.Build(source, probe, TimeProvider.System).RunAsync(); - await Assert.That(probe.Asked.Single().AskLoginCommands).IsTrue(); - await Assert.That(await UnansweredAsync(connection)).IsEqualTo(0); - await Assert.That(await QuietAsync(connection)).IsFalse(); + await Assert.That(probe.Asked.Single().AskLoginCommands).IsFalse(); + await Assert.That(await QuietAsync(connection)).IsTrue(); } private static Task UnansweredAsync(Npgsql.NpgsqlConnection connection) => diff --git a/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs b/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs index 805148b..89d53b5 100644 --- a/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs +++ b/tests/MUI.Discovery.Tests/Scheduling/LoginCommandsTests.cs @@ -35,13 +35,13 @@ public async Task ThreeSessionsWithNothingReadableRunningSilenceTheAddress() memory = LoginCommands.Learn(memory, session % 2 == 0 ? Huh : NamePrompt, Now); await Assert.That(memory.QuietAt).IsNull(); - await Assert.That(LoginCommands.Ask(Listed(memory), Now)).IsTrue(); + await Assert.That(LoginCommands.Ask(Listed(memory))).IsTrue(); } memory = LoginCommands.Learn(memory, NamePrompt, Now); await Assert.That(memory).IsEqualTo(new LoginCommandMemory(LoginCommands.Patience, Now)); - await Assert.That(LoginCommands.Ask(Listed(memory), Now.AddDays(1))).IsFalse(); + await Assert.That(LoginCommands.Ask(Listed(memory))).IsFalse(); } [Test] @@ -53,21 +53,28 @@ public async Task OneAnswerClearsTheRun() } /// - /// A quiet address is asked once a month, and what that one session finds decides the next month. + /// A quiet address stays quiet: there is no retrial, however long it has been. /// [Test] - public async Task AQuietAddressIsRetriedAndTheRetrialDecides() + public async Task AQuietAddressIsNeverAskedAgain() { - var quiet = new LoginCommandMemory(LoginCommands.Patience, Now); - var due = Now + LoginCommands.Retrial; + var quiet = new LoginCommandMemory(LoginCommands.Patience, Now.AddYears(-2)); - await Assert.That(LoginCommands.Ask(Listed(quiet), due.AddMinutes(-1))).IsFalse(); - await Assert.That(LoginCommands.Ask(Listed(quiet), due)).IsTrue(); + await Assert.That(LoginCommands.Ask(Listed(quiet))).IsFalse(); + } - await Assert.That(LoginCommands.Learn(quiet, NamePrompt, due)) - .IsEqualTo(new LoginCommandMemory(LoginCommands.Patience, due)); + /// + /// A submission awaiting §7.8 is the one session asked while quiet. A miss there keeps the date + /// the address went quiet; an answer clears the memory. + /// + [Test] + public async Task AQuietSubmissionsMissKeepsTheDateAndItsAnswerClearsIt() + { + var since = Now.AddDays(-40); + var quiet = new LoginCommandMemory(LoginCommands.Patience, since); - await Assert.That(LoginCommands.Learn(quiet, InfoBlock, due)).IsEqualTo(Fresh); + await Assert.That(LoginCommands.Learn(quiet, NamePrompt, Now)).IsEqualTo(quiet); + await Assert.That(LoginCommands.Learn(quiet, InfoBlock, Now)).IsEqualTo(Fresh); } /// @@ -97,13 +104,13 @@ public async Task ASubmissionAwaitingCorroborationIsAlwaysAsked() { var quiet = new LoginCommandMemory(LoginCommands.Patience, Now); - await Assert.That(LoginCommands.Ask(Listed(quiet) with { AwaitingCorroboration = true }, Now)).IsTrue(); + await Assert.That(LoginCommands.Ask(Listed(quiet) with { AwaitingCorroboration = true })).IsTrue(); } [Test] public async Task AnAddressWithNoHistoryIsAsked() { - await Assert.That(LoginCommands.Ask(Listed(Fresh), Now)).IsTrue(); + await Assert.That(LoginCommands.Ask(Listed(Fresh))).IsTrue(); } private static CrawlTarget Listed(LoginCommandMemory memory) => new()