Skip to content

Commit dda8e30

Browse files
committed
Adds Swift MTHClient to match Kotlin mth-client
1 parent 4d9002d commit dda8e30

8 files changed

Lines changed: 898 additions & 6 deletions

File tree

Package.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PackageDescription
33

44
var products: [Product] = [
55
.library(name: "MTH", targets: ["MTH"]),
6+
.library(name: "MTHClient", targets: ["MTHClient"]),
67
.library(name: "MTHColor", targets: ["MTHColor"]),
78
]
89

@@ -15,14 +16,26 @@ var targets: [Target] = [
1516
publicHeadersPath: "include",
1617
linkerSettings: [.linkedLibrary("z")]
1718
),
18-
// New Swift targets
19+
// Shared telnet constants, compression, and MTTS flags used by both server and client.
1920
.target(
20-
name: "MTH",
21+
name: "MTHCore",
2122
dependencies: [
22-
.target(name: "CZlib", condition: .when(platforms: [.macOS, .linux])),
23+
.target(name: "CZlib", condition: .when(platforms: [.macOS, .linux, .iOS, .visionOS])),
2324
],
25+
path: "Sources/SwiftMTHCore"
26+
),
27+
// Server-side telnet session, MSDP, MSSP, and related protocols.
28+
.target(
29+
name: "MTH",
30+
dependencies: ["MTHCore"],
2431
path: "Sources/SwiftMTH"
2532
),
33+
// Client-side telnet session for MUD clients.
34+
.target(
35+
name: "MTHClient",
36+
dependencies: ["MTHCore"],
37+
path: "Sources/SwiftMTHClient"
38+
),
2639
.target(
2740
name: "MTHColor",
2841
dependencies: [],
@@ -55,7 +68,7 @@ targets += [
5568
),
5669
.testTarget(
5770
name: "MTHTests",
58-
dependencies: ["MTH", "Cmth"]
71+
dependencies: ["MTH", "MTHClient", "Cmth"]
5972
),
6073
.testTarget(
6174
name: "MTHColorTests",
@@ -66,7 +79,7 @@ targets += [
6679
targets += [
6780
.testTarget(
6881
name: "MTHTests",
69-
dependencies: ["MTH"]
82+
dependencies: ["MTH", "MTHClient"]
7083
),
7184
.testTarget(
7285
name: "MTHColorTests",

Sources/SwiftMTH/MTH.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// MTH — Mud Telopt Handler (Swift)
2-
// All phases complete.
2+
@_exported import MTHCore
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
public protocol TelnetClientDelegate: AnyObject {
2+
/// Write raw bytes to the server connection.
3+
func write(data: [UInt8])
4+
5+
/// Called when the server changes echo mode.
6+
/// When `enabled` is true, the client should echo locally.
7+
/// When false, the server is echoing (password mode).
8+
func onLocalEchoChanged(enabled: Bool)
9+
10+
/// Called when GMCP subnegotiation completes.
11+
func onGMCPNegotiated()
12+
13+
/// Called when a GMCP message is received from the server.
14+
func onGMCPReceived(module: String, json: String)
15+
16+
/// Called when an MSDP variable is received from the server.
17+
func onMSDPVariable(name: String, value: String)
18+
19+
/// Called when a prompt marker (GA or EOR) is received.
20+
func onPromptReceived()
21+
22+
/// Called when a BEL character is received.
23+
func onBellReceived()
24+
25+
/// Log a diagnostic message.
26+
func log(message: String)
27+
}
28+
29+
public extension TelnetClientDelegate {
30+
func onGMCPNegotiated() {}
31+
func onBellReceived() {}
32+
func log(message: String) {}
33+
}

0 commit comments

Comments
 (0)