Speak telnet properly to the cluster node

The old client read the socket with a StreamReader, so the option negotiation a
node sends on connect landed in the text as control bytes and made a mess of
the first lines. TelnetStream now answers it: it agrees to ECHO and
SUPPRESS-GO-AHEAD, refuses everything else, swallows subnegotiations, and
tracks what it already answered so the two ends do not reply to each other for
ever. A command split across two reads is still understood, because a socket
hands over whatever has turned up rather than whole messages.

LineAssembler keeps the tail that has no line ending yet. Nodes write their
login prompt as "login: " with nothing after it, so the old ReadLineAsync sat
waiting for a line that never came and only got through because the greeting
happened to mention a matching word.

Login now follows N1MM: it looks for LOGON, ENTER CALL, LOG IN and the rest,
and sends the callsign anyway after ten seconds if no prompt turns up. A
password is sent when the node asks for one and the operator configured one.
The commands go out after that, not straight after the call. A connection that
has heard nothing for four minutes gets a blank line so the node does not drop
it as idle.

The old prompt check matched "call" anywhere in a line, which any spot comment
could trigger.

SendSpotAsync sends the node's dx command. Alt+P, or Edit / Spot It, spots the
call being typed at the current frequency, or the last contact logged when
nothing is typed, and puts it on our own bandmap without waiting for it to come
back round from the node.

The spot parser now takes a line with no colon after the spotter, and finds the
time when DXSpider has put the spotter's grid after it.

The cluster tests run over a real socket against a node fake that sends the
negotiation, the prompt and spot lines.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-27 15:46:19 +00:00
parent b355b9b6bf
commit 2b8033ccdd
19 changed files with 918 additions and 66 deletions

View File

@@ -19,37 +19,55 @@ public static class SpotLine
}
string body = line[(start + Marker.Length)..];
int colon = body.IndexOf(':');
if (colon < 0)
{
return null;
}
string spotter = body[..colon].Trim();
string[] parts = body[(colon + 1)..].Split(' ', StringSplitOptions.RemoveEmptyEntries);
string[] parts = (colon < 0 ? body : body[(colon + 1)..])
.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
{
return null;
}
if (!double.TryParse(parts[0], NumberStyles.Float, CultureInfo.InvariantCulture, out double kilohertz))
// without a colon the spotter is the first word and the frequency follows
string spotter = colon >= 0 ? body[..colon].Trim() : parts[0];
string[] fields = colon >= 0 ? parts : parts[1..];
if (fields.Length < 2
|| !double.TryParse(fields[0], NumberStyles.Float, CultureInfo.InvariantCulture, out double kilohertz))
{
return null;
}
string comment = string.Join(' ', parts.Skip(2)).Trim();
string[] tail = fields[2..];
int stamp = LastTimeStamp(tail);
return new Spot(
Callsign.Parse(parts[1]),
Callsign.Parse(fields[1]),
Frequency.FromKilohertz(kilohertz),
ParseTime(comment, nowUtc),
stamp < 0 ? nowUtc : TimeOf(tail[stamp], nowUtc),
SpotSource.Cluster,
spotter,
TrimTime(comment));
string.Join(' ', stamp < 0 ? tail : tail[..stamp]).Trim());
}
/// The node puts the spot's time at the end as `1234Z`.
private static DateTime ParseTime(string comment, DateTime nowUtc)
/// The node writes the spot's time as `1234Z`. It is usually the last word,
/// but DXSpider puts the spotter's grid or country after it.
private static int LastTimeStamp(IReadOnlyList<string> words)
{
string? stamp = TimeStamp(comment);
if (stamp is null ||
!int.TryParse(stamp[..2], out int hour) ||
!int.TryParse(stamp[2..4], out int minute))
for (int at = words.Count - 1; at >= 0; at--)
{
if (IsTimeStamp(words[at]))
{
return at;
}
}
return -1;
}
private static bool IsTimeStamp(string word) =>
word.Length == 5
&& char.ToUpperInvariant(word[4]) == 'Z'
&& word[..4].All(char.IsAsciiDigit);
private static DateTime TimeOf(string stamp, DateTime nowUtc)
{
int hour = int.Parse(stamp[..2], CultureInfo.InvariantCulture);
int minute = int.Parse(stamp[2..4], CultureInfo.InvariantCulture);
if (hour > 23 || minute > 59)
{
return nowUtc;
}
@@ -57,21 +75,4 @@ public static class SpotLine
// a spot timed later than now came in just before midnight
return at > nowUtc.AddMinutes(5) ? at.AddDays(-1) : at;
}
private static string TrimTime(string comment)
{
string? stamp = TimeStamp(comment);
return stamp is null ? comment : comment[..^stamp.Length].TrimEnd();
}
private static string? TimeStamp(string comment)
{
string trimmed = comment.TrimEnd();
if (trimmed.Length < 5 || char.ToUpperInvariant(trimmed[^1]) != 'Z')
{
return null;
}
string candidate = trimmed[^5..];
return candidate[..4].All(char.IsAsciiDigit) ? candidate : null;
}
}