Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]

### Added

- Worlds can be reached over a WebSocket, as a browser client would. Browse worlds now lists a game's WebSocket
addresses and can connect to them, `/connect ws://host/path` (or `wss://` for an encrypted one) adds and dials one,
and F5 has a *websocket path* field: blank keeps the world on plain telnet. Everything else (triggers, GMCP, MXP,
logging) works the same over either.

- *Open log folder* shows the folder a character's logs are written to in your file manager (Explorer, Finder, or
whatever your desktop opens folders with). It is on the command palette (⌃P) for the character in front, on a
character's page in the desktop window's Worlds & Characters settings, and on F5 in the terminal (`o` on a
Expand Down Expand Up @@ -54,6 +59,10 @@ and a release's notes are its section. The procedure is in [`docs/RELEASING.md`]

### Changed

- Updated TelnetNegotiationCore to 4.13.3, MarkupString to 2.31.3 and Microsoft.Extensions.Logging.Abstractions to 11.0.0 (which 4.13.3
needs). Nothing a player does changes: the new library releases add WebSocket transports and connection hooks this
client does not use yet.

- The quick bar lists every key you have bound, not only function keys. Keypad and letter-chord bindings
(`Num8`, `Ctrl+E`) used to be left off it. Function keys come first, then other chords, then the keypad in the pad's
own order. When the bar is short of room it says `nw` for `northwest` and `Num 7 nw 8 n` for the keypad before it
Expand Down
14 changes: 14 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3567,6 +3567,20 @@ markup (`[bold #rrggbb on #rrggbb]…[/]`, `[[`/`]]` escaping, `[link=url]…[/]
What the jump *makes available* and is not yet used: a GMCP `Core` client session
(`UseGmcpClientSession`, `TelnetNegotiationCore.Gmcp`), typed GMCP packages, MSDP over GMCP,
`PuebloProtocol`, and MCP 2.1 (`MudClientProtocol`, now used — see below).
- **The read loop is the library's** (4.12+: `TelnetInterpreterBuilder.StartAsync(ITelnetTransport)` →
`TelnetConnection`). `TelnetSession` hands it `ITransport.ForTelnet(bufferSize)`: a `TransportBridge` over
`TcpTransport` (socket, TLS and the test fakes stay ours), or the library's own `TelnetTransport.WebSocket`
for `WebSocketTransport`. Seeding the encoding and wiring CHARSET is `OnStarting` (before the first read);
`ReceiveBatchEnded` and the encoding report run after each read through `OnInputProcessed` (4.13.3+: it awaits a signal; before that it polled with `Task.Delay(1)`, ~15 ms a read on Windows); the MSDP `DO` spotting is `WrapOutput`.
The bridge writes with `CancellationToken.None`, because the library passes its start token, which a
disconnect cancels before the socket closes. Disposing the connection disposes the interpreter, never the
transport. A read that faults after this side began stopping is a close, not a failure (`WatchReadLoopAsync`).
- **WebSocket worlds** (`WorldDefinition.WebSocketPath`, null = telnet; `WebSocketTransport`, `WebSocketAddress`,
Core; F5 ▸ `websocket path`; `/connect ws://…|wss://…`; Browse lists mu*index's `websocket` endpoints, `wss` where
TLS was measured, at the endpoint's optional `path`, else `/`). Dialled through `TelnetWebSocketClient`
(subprotocols `telnet.mudstandards.org`, then `telnet`), binary frames, telnet inside unchanged. A path is
refused, not tidied (`IsPath`: starts with `/`, ASCII address characters, 256 at most); an address with user
information or a fragment is refused. A `telnet://` link never matches a WebSocket world.
- **Never pin a version that is not on nuget.org, and never work around it with a local feed.** A
pin that only resolves from a local `nuget.config` builds here and fails `NU1101` everywhere else;
if a locally-built nupkg of that version is already in `~/.nuget/packages/`, the real package
Expand Down
14 changes: 7 additions & 7 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
Reading server output: ANSI/VT, MXP and Pueblo into MarkupText, which Core folds into StyledLine
(Text/MarkupLineParser). One version for the family.
-->
<PackageVersion Include="MarkupString" Version="2.31.0" />
<PackageVersion Include="MarkupString.Ansi" Version="2.31.0" />
<PackageVersion Include="MarkupString.Mxp" Version="2.31.0" />
<PackageVersion Include="MarkupString.Pueblo" Version="2.31.0" />
<PackageVersion Include="MarkupString" Version="2.31.3" />
<PackageVersion Include="MarkupString.Ansi" Version="2.31.3" />
<PackageVersion Include="MarkupString.Mxp" Version="2.31.3" />
<PackageVersion Include="MarkupString.Pueblo" Version="2.31.3" />

<!-- Telnet negotiation: TELOPT/NAWS/MTTS/EOR/CHARSET/MSSP/GMCP/MSDP/MCCP/MXP negotiation. -->
<PackageVersion Include="TelnetNegotiationCore" Version="4.11.0" />
<PackageVersion Include="TelnetNegotiationCore" Version="4.13.3" />

<!-- The version, from the git tag (see Directory.Build.props). Build-time only. -->
<PackageVersion Include="MinVer" Version="8.0.0" />
Expand Down Expand Up @@ -58,7 +58,7 @@
<PackageVersion Include="AngleSharp" Version="1.7.1" />

<!-- Logging abstractions (TelnetNegotiationCore takes an ILogger). -->
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.14" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="11.0.0" />

<!--
Client diagnostics: Serilog behind Microsoft.Extensions.Logging. Only the Tui's composition root
Expand Down Expand Up @@ -88,7 +88,7 @@
<PackageVersion Include="StbImageWriteSharp" Version="1.16.7" />

<!-- Keeps host decisions in Tui/Hosting: see src/SharpMUTerm.Tui/BannedSymbols.txt. -->
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="5.6.0" />

<!-- Test stack: TUnit (source-generated, runs on Microsoft.Testing.Platform). -->
<PackageVersion Include="TUnit" Version="1.61.38" />
Expand Down
5 changes: 4 additions & 1 deletion src/SharpMUTerm.Avalonia/WelcomeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,10 @@ private void DrawCommand()
var (lead, tail) = WelcomeModel.CommandWords;
_command.Inlines!.Clear();
_command.Inlines.Add(new Run(lead + " "));
_command.Inlines.Add(new Run(WelcomeModel.CommandFor(_host.Text ?? string.Empty, _port.Text ?? string.Empty, _tls.IsChecked == true))
// The path goes with the host Browse worlds filled in; a host typed over it is a telnet world, as the form saves it.
var host = _host.Text ?? string.Empty;
var path = string.Equals(host.Trim(), _model.Host, StringComparison.OrdinalIgnoreCase) ? _model.WebSocketPath : null;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
_command.Inlines.Add(new Run(WelcomeModel.CommandFor(host, _port.Text ?? string.Empty, _tls.IsChecked == true, path))
{
FontFamily = Mono,
Foreground = _colours.Brush(_colours.Text),
Expand Down
2 changes: 1 addition & 1 deletion src/SharpMUTerm.Client/Help/SlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class SlashCommands
[
new("/help", "/help [words]", "This help: keys, slash commands and short how-tos, searched for the words", "/help "),
new("/connect", "/connect <world>", "Open a configured world by name", "/connect "),
new("/connect", "/connect <host> [port] [tls]", "Add a world for a host and connect to it (port 4000 by default)", "/connect "),
new("/connect", "/connect <host> [port] [tls]", "Add a world for a host, or a ws:// or wss:// address, and connect to it (port 4000 by default)", "/connect "),
new("/welcome", "/welcome", "Show the first-run welcome again", "/welcome"),
new("/welcome", "/welcome layout roleplay|combat|suggested", "Choose the starting layout the welcome offers", "/welcome layout "),
new("/browse", "/browse [words]", "Browse worlds listed on mu*index, searched for the words; a pick fills in the connect form", "/browse "),
Expand Down
23 changes: 17 additions & 6 deletions src/SharpMUTerm.Client/Modals/WelcomeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public sealed record WelcomeModel(
string? Problem,
string? IndexProblem,
string? WorldName = null,
string? Encoding = null)
string? Encoding = null,
string? WebSocketPath = null)
{
/// <summary>The example the surface names, a host nobody owns (RFC 2606).</summary>
public const string ExampleCommand = "/connect mud.example.org 4201 tls";
Expand Down Expand Up @@ -95,9 +96,8 @@ public sealed record WelcomeModel(
/// </summary>
public string FormIntroLine => WorldName is null
? FormIntro
: Encoding is { } encoding
? $"{WorldName}, as listed on mu*index, saved with encoding {encoding}. Check it and press ⏎ to save and connect."
: $"{WorldName}, as listed on mu*index. Check it and press ⏎ to save and connect.";
: $"{WorldName}, as listed on mu*index{(WebSocketPath is null ? string.Empty : ", over a WebSocket")}"
+ $"{(Encoding is { } encoding ? $", saved with encoding {encoding}" : string.Empty)}. Check it and press ⏎ to save and connect.";

/// <summary>The TLS row's words when on; the window's check box carries these words.</summary>
public const string TlsOn = "On, encrypted";
Expand Down Expand Up @@ -209,14 +209,25 @@ public sealed record WelcomeModel(
/// <summary>
/// The command line that does what the form would with these fields: <c>/connect mud.example.org 4201 tls</c>. An
/// empty host or port reads as its placeholder, so the line always shows the shape; an IPv6 host is bracketed, as
/// <c>/connect</c> wants it.
/// <c>/connect</c> wants it. With a WebSocket <paramref name="path"/> (a world Browse worlds picked at a WebSocket
/// address) it is the <c>ws://</c> or <c>wss://</c> address instead, which is the only way <c>/connect</c> takes one.
/// </summary>
public static string CommandFor(string host, string port, bool tls)
public static string CommandFor(string host, string port, bool tls, string? path = null)
{
ArgumentNullException.ThrowIfNull(host);
ArgumentNullException.ThrowIfNull(port);
host = host.Trim();
port = port.Trim();
if (path is not null && port.Length == 0)
{
port = "4000";
}

if (path is not null && host.Length > 0 && int.TryParse(port, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out var number))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{
return "/connect " + Core.Transport.WebSocketAddress.Format(host.Trim('[', ']'), number, tls, path);
}

host = host.Length == 0 ? HostPlaceholder : host.Contains(':', StringComparison.Ordinal) && !host.StartsWith('[') ? $"[{host}]" : host;
port = port.Length == 0 ? "4000" : port;
return $"/connect {host} {port}" + (tls ? " tls" : string.Empty);
Expand Down
8 changes: 7 additions & 1 deletion src/SharpMUTerm.Client/Modals/WorldBrowseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ public static (string Address, string Security, string State) Endpoint(WorldEndp
{
ArgumentNullException.ThrowIfNull(endpoint);
var state = endpoint.Stale ? "stale · not reached lately" : "active";
return (endpoint.Address, endpoint.Tls ? "TLS" : "plain", endpoint.Connectable ? state : $"{state} · not connectable");
return (endpoint.Address, (endpoint.WebSocket, endpoint.Tls) switch
{
(true, true) => "WebSocket, TLS",
(true, false) => "WebSocket",
(false, true) => "TLS",
_ => "plain",
}, endpoint.Connectable ? state : $"{state} · not connectable");
}

/// <summary>An address as one line (<c>--plain</c>, a tooltip).</summary>
Expand Down
3 changes: 3 additions & 0 deletions src/SharpMUTerm.Client/Settings/BuiltInSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ public static WindowMode WindowStartFor(string? words)
Group = ConnectionGroup,
Binding = SettingBinding<int>.ForWorld((_, w) => w.Port, (_, w, v) => w.Port = v, resettable: false),
},
WorldText("websocket", "websocket path", TextRule.WebSocketPath, ConnectionGroup,
(_, w) => w.WebSocketPath, (_, w, v) => w.WebSocketPath = v,
"blank dials telnet; a path such as / dials a WebSocket there (wss:// with TLS)", "ws wss web socket browser"),
WorldFlag("tls", "TLS", ConnectionGroup, w => w.UseTls, (w, v) => w.UseTls = v,
"connect over an encrypted connection", "ssl secure encrypted"),
WorldFlag("invalid-certificates", "accept invalid certificates", ConnectionGroup,
Expand Down
8 changes: 8 additions & 0 deletions src/SharpMUTerm.Client/Settings/TextRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public enum TextRule
/// </summary>
Image,

/// <summary>
/// A world's WebSocket path (<see cref="Core.Transport.WebSocketAddress.IsPath"/>): blank for telnet, stored as null;
/// else starting with <c>/</c>; trimmed.
/// </summary>
WebSocketPath,

/// <summary>A split pane's live tail (<see cref="Core.Configuration.ScrollTail"/>): rows, or a share such as <c>25%</c>.</summary>
ScrollTail,
}
Expand Down Expand Up @@ -92,6 +98,8 @@ TextRule.Name or TextRule.Secret or TextRule.Defaulted when text.Any(char.IsCont
TextRule.Pattern when !string.IsNullOrWhiteSpace(text) => PatternError(text),
TextRule.Image => Core.Avatars.AvatarSource.Problem(text),
TextRule.ScrollTail => Core.Configuration.ScrollTail.Problem(text),
TextRule.WebSocketPath when !string.IsNullOrWhiteSpace(text) && !Core.Transport.WebSocketAddress.IsPath(text.Trim()) =>
$"{field.Label} starts with / and holds no spaces or characters past ASCII",
TextRule.NameHighlights => Core.Automation.NameHighlights.Parse(
text, colour => HighlightColours.Palette.Contains(colour) && colour != HighlightColours.None).Error,
_ => null,
Expand Down
9 changes: 9 additions & 0 deletions src/SharpMUTerm.Core/Configuration/WorldDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ public sealed class WorldDefinition

public bool AllowInvalidCertificates { get; set; }

/// <summary>
/// Null (the default) dials telnet over TCP. A path such as <c>/</c> or <c>/ws</c> dials a WebSocket at
/// <c>ws://host:port/path</c> instead (<c>wss://</c> with <see cref="UseTls"/>), speaking telnet inside it as the
/// mudstandards.org proposal writes it. Checked by <see cref="Transport.WebSocketAddress.IsPath"/>.
/// </summary>
public string? WebSocketPath { get; set; }

/// <summary>Echo typed commands locally into the output window.</summary>
public bool LocalEcho { get; set; } = true;

Expand Down Expand Up @@ -305,6 +312,7 @@ public sealed class WorldDefinition
Port = Port,
UseTls = UseTls,
AllowInvalidCertificates = AllowInvalidCertificates,
WebSocketPath = WebSocketPath,
LocalEcho = LocalEcho,
Encoding = Encoding,
KeepaliveSeconds = KeepaliveSeconds,
Expand Down Expand Up @@ -344,5 +352,6 @@ public sealed class WorldDefinition
Port = Port,
UseTls = UseTls,
AllowInvalidCertificates = AllowInvalidCertificates,
WebSocketPath = WebSocketPath,
};
}
8 changes: 5 additions & 3 deletions src/SharpMUTerm.Core/Session/WorldSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,11 +1634,13 @@ private async Task SendLeavingAsync()
{
foreach (var command in SplitCommands(character.OnDisconnect))
{
await SendRawAsync(command, timeout.Token).ConfigureAwait(false);
await SendRawAsync(command, timeout.Token).WaitAsync(timeout.Token).ConfigureAwait(false);
}
}
catch (Exception ex) when (ex is OperationCanceledException or IOException or ObjectDisposedException or InvalidOperationException)
catch (Exception ex) when (ex is OperationCanceledException or IOException or ObjectDisposedException or InvalidOperationException
or System.Net.WebSockets.WebSocketException)
{
// A WebSocket world's write fails with its own exception, not an IOException; either way the close goes on.
Logger.LogDebug(ex, "{World}: the on-disconnect commands were not all sent", World.Name);
}
}
Expand Down Expand Up @@ -1688,7 +1690,7 @@ private ITelnetSession DefaultSessionFactory(ConnectionOptions options)
TelnetSessionOptions.ResolveWorldEncoding(World.Encoding, _charsetOrder);

return new TelnetSession(
new TcpTransport(options),
options.WebSocketPath is null ? new TcpTransport(options) : new WebSocketTransport(options),
Logger,
options: new TelnetSessionOptions
{
Expand Down
Loading
Loading