Network tab: Join/Leave bar and the join status

ChatNetwork.Classify reads the Dereth.Network mod's own status lines
(on as Name@world, already on, not on, off), only on system-type lines
(Broadcast 0, System 5), so a player saying them is never a status.
The first view of a network tab per character session sends
/<command> and keeps that one answer out of the scrollback (the status
line within 10 s, and a "Your directory page:" line within 2 s after
it); every later status line is shown and moves On. Login and logout
reset the session (unknown is still sent as on; off blocks Global).

The main window shows a bar under the header on that tab: "Join the
Dereth Network", or "On the network as <address>" and Leave. Join sends
/<command> on and turns on Hear <room> Chat (AcCharacterOptions) for the
discovered Global room, else the entry's fallback, remembering per
server/character (networkJoinRooms, absent while empty) only when it
was off before; Leave sends /<command> off and turns that room off only
if Join turned it on. A refusal is shown in the bar. The work runs on
AC's main thread on a fresh posted message (WM_RYNTHCORE_NETWORK), as a
typed line's send does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-15 10:48:41 -08:00
commit cb06e5f065
6 changed files with 482 additions and 4 deletions

View file

@ -59,6 +59,7 @@ internal static class Program
ServerTabPlans();
PinBookkeeping();
NetworkRewrite();
NetworkStatusLines();
SharedFileReload();
LineColorTags();
LineColorKinds();
@ -1638,6 +1639,105 @@ internal static class Program
Check(ChatNetwork.On == null, "reset to unknown");
}
// 2026-11-15 (Task 11): the Dereth.Network mod's status lines (texts verbatim from
// third_party/dereth/network/ace-mod/Dereth.Network/Core/NetworkWorld.Commands.cs, sent as
// ChatMessageType.Broadcast = 0), the answer eater, and the session state.
private static void NetworkStatusLines()
{
const int Broadcast = 0, System = 5, Speech = 2, Tell = 3, Channel = 8;
Case("Classify_OnTexts");
var on1 = ChatNetwork.Classify("You are on the Dereth Network as Ann@alpha. Anyone on the network can see when you are online, send you tells and find your profile in its directory. Type @derethnetwork help for the commands.", Broadcast);
Check(on1 is { On: true, Address: "Ann@alpha" }, "the join line: on, as Ann@alpha");
var on2 = ChatNetwork.Classify("You are on the Dereth Network already, as Ann@alpha.", Broadcast);
Check(on2 is { On: true, Address: "Ann@alpha" }, "already on: on, as Ann@alpha");
var on3 = ChatNetwork.Classify("You are on the Dereth Network as Ann@alpha. The hub is connected. You have no friends on other worlds.", Broadcast);
Check(on3 is { On: true, Address: "Ann@alpha" }, "the status line: on, as Ann@alpha");
var on4 = ChatNetwork.Classify("You are on the Dereth Network as Mary Ann@dreamweave-stage. The hub is not connected. You have 2 friends on other worlds.", System);
Check(on4 is { On: true, Address: "Mary Ann@dreamweave-stage" }, "a spaced name and a hyphenated world, System type too");
Case("Classify_OffTexts");
Check(ChatNetwork.Classify("You are not on the Dereth Network.", Broadcast) is { On: false, Address: null }, "off already");
Check(ChatNetwork.Classify("You are not on the Dereth Network. Type @derethnetwork on to join it.", Broadcast) is { On: false }, "off, with the hint");
Check(ChatNetwork.Classify("You are not on the Dereth Network. Type @derethnetwork on to join it as Ann@alpha.", Broadcast) is { On: false, Address: null }, "the status line when off: off, no address");
Check(ChatNetwork.Classify("You are off the Dereth Network. Nobody on another world can see you or tell you, and your profile is out of its directory.", Broadcast) is { On: false }, "the leave line: off");
Case("Classify_LookAlikes");
string said = "You are on the Dereth Network as Bob@alpha. The hub is connected.";
Check(ChatNetwork.Classify(said, Speech) == null, "a player saying it in Local is not a status");
Check(ChatNetwork.Classify(said, Tell) == null, "nor in a tell");
Check(ChatNetwork.Classify(said, Channel) == null, "nor on a channel");
Check(ChatNetwork.Classify("You are not on the Dereth Network.", Speech) == null, "an off text said in Local is not a status");
Check(ChatNetwork.Classify("This world is not on the Dereth Network.", Broadcast) == null, "the world's own state is not the character's");
Check(ChatNetwork.Classify("You have entered the Roleplay channel.", Broadcast) == null, "room feedback is not a status");
Check(ChatNetwork.Classify("You are on the Dereth Network as nobody.", Broadcast) == null, "an on line without an address is not taken");
Check(ChatNetwork.Classify("", Broadcast) == null, "empty");
Check(ChatNetwork.IsDirectoryLine("Your directory page: https://example.org/directory/character/", Broadcast), "the directory line");
Check(!ChatNetwork.IsDirectoryLine("Your directory page: https://example.org/x", Speech), "a directory line said in Local is not one");
Case("Eater_EatsTheAnswerOnly");
var eater = new NetworkReplyEater();
string status = "You are on the Dereth Network as Ann@alpha. The hub is connected. You have no friends on other worlds.";
string page = "Your directory page: https://example.org/directory/character/";
var st = ChatNetwork.Classify(status, Broadcast);
Check(!eater.Take(st, status, Broadcast, 1000), "a status line nobody asked for is shown");
Check(!eater.Take(null, page, Broadcast, 1100), "and so is its directory line");
eater.Query(2000);
Check(!eater.Take(null, "You have entered the Roleplay channel.", Broadcast, 2100), "an unrelated line while asking is shown");
Check(eater.Take(st, status, Broadcast, 2500), "the answer is eaten");
Check(eater.Take(null, page, Broadcast, 3000), "its directory line within 2 s is eaten");
Check(!eater.Take(null, page, Broadcast, 3100), "a second directory line is shown");
Check(!eater.Take(st, status, Broadcast, 3200), "a second status line is shown (one question, one answer)");
Case("Eater_Windows");
eater.Query(10_000);
Check(!eater.Take(st, status, Broadcast, 10_000 + NetworkReplyEater.StatusWindowMs + 1), "an answer after the window is shown");
eater.Query(30_000);
Check(eater.Take(st, status, Broadcast, 30_500), "in time: eaten");
Check(!eater.Take(null, page, Broadcast, 30_500 + NetworkReplyEater.DirectoryWindowMs + 1), "a directory line after 2 s is shown");
eater.Query(40_000);
var off = ChatNetwork.Classify("You are not on the Dereth Network. Type @derethnetwork on to join it as Ann@alpha.", Broadcast);
Check(eater.Take(off, "x", Broadcast, 40_100), "an off answer is eaten");
Check(!eater.Take(null, page, Broadcast, 40_200), "an off answer has no directory line to eat");
eater.Query(50_000);
eater.Clear();
Check(!eater.Take(st, status, Broadcast, 50_100), "a cleared question eats nothing");
Case("Observe_MovesOnAndAddress");
ChatNetwork.ResetSession();
Check(ChatNetwork.On == null && ChatNetwork.Address == null, "a new session knows nothing");
Check(ChatNetwork.TryBeginQuery() && !ChatNetwork.TryBeginQuery(), "one question per session");
ChatNetwork.Eater.Query(100);
Check(ChatNetwork.Observe(status, Broadcast, 200), "the session's answer is eaten");
Check(ChatNetwork.On == true && ChatNetwork.Address == "Ann@alpha", "and puts the character on, as Ann@alpha");
Check(ChatNetwork.OnOrUnknown && ChatNetwork.Rewrite("hi", "dn", ChatNetwork.OnOrUnknown) == "/dn global hi", "on: Global lines are sent");
Check(!ChatNetwork.Observe(said, Speech, 300) && ChatNetwork.On == true, "a player's look-alike changes nothing");
Check(!ChatNetwork.Observe("You are off the Dereth Network. Nobody on another world can see you or tell you, and your profile is out of its directory.", Broadcast, 400),
"a later leave line is shown");
Check(ChatNetwork.On == false && ChatNetwork.Address == null, "and puts the character off");
Check(ChatNetwork.Rewrite("hi", "dn", ChatNetwork.OnOrUnknown) == null, "off: Global lines are blocked");
ChatNetwork.JoinProblem = "x";
ChatNetwork.ResetSession();
Check(ChatNetwork.On == null && ChatNetwork.OnOrUnknown && ChatNetwork.JoinProblem == null, "logout/login: unknown again (sent as on), no problem shown");
Check(ChatNetwork.Rewrite("hi", "dn", ChatNetwork.OnOrUnknown) == "/dn global hi", "unknown: Global lines are sent");
Check(ChatNetwork.TryBeginQuery(), "and the next view asks again");
ChatNetwork.ResetSession();
Case("JoinKey");
Check(ChatNetwork.JoinKey(" DreamWeave ", " Ann ") == "dreamweave/Ann", "server lower-cased, both trimmed, the name kept");
Case("Settings_NetworkJoinRooms");
var opts = RynthChatJsonContext.Default.RynthChatSettingsDto;
string none = JsonSerializer.Serialize(new RynthChatSettingsDto(), opts);
Check(!none.Contains("networkJoinRooms", StringComparison.Ordinal), "absent while unset");
var withRoom = new RynthChatSettingsDto { NetworkJoinRooms = new Dictionary<string, string> { ["dreamweave/Ann"] = "Roleplay" } };
string json = JsonSerializer.Serialize(withRoom, opts);
RynthChatSettingsDto back = JsonSerializer.Deserialize(json, opts)!;
Check(json.Contains("\"networkJoinRooms\":{\"dreamweave/Ann\":\"Roleplay\"}", StringComparison.Ordinal), "written as server/character -> room");
Check(back.NetworkJoinRooms is { } m && m.TryGetValue("dreamweave/Ann", out string? r) && r == "Roleplay", "and read back");
Check(JsonSerializer.Deserialize(OldFile, opts)!.NetworkJoinRooms == null, "an older file has none");
}
private static void PinBookkeeping()
{
Case("Toggle_AddsAtEndAndRemoves");