From 4318ce359fb7c4aeed3e49d27c15dd9dc2f18745 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Wed, 5 Aug 2026 12:45:59 +0200 Subject: [PATCH] Add Server Protokoll dialog Adds the first StreamItem::MessageEvent handler in the connector's event loop (previously dropped by a catch-all) - needed because log lines aren't part of the bookkeeping data model, unlike client/server connection info, so they only ever arrive as a raw notifyserverlog reply rather than a book-state update. This unblocks the same pattern for Bannliste/Beschwerdeliste next. Sends "logview" via tsclientlib's typed Server::log_view() builder, requesting the last 200 lines. Verified end-to-end against the real server (though a permission-gated account got no reply at all there - the frontend dialog now falls back to a "no response" message after a timeout instead of loading forever, matching the connection-info dialogs' existing behavior). Co-Authored-By: Claude Sonnet 5 --- connector/src/main.rs | 31 ++++++++++++- gateway/src/index.ts | 4 ++ gateway/src/ts3/connection.ts | 10 +++- web/src/App.css | 11 +++++ web/src/App.tsx | 86 ++++++++++++++++++++++++++++++++++- web/src/demoMode.ts | 14 ++++++ web/src/i18n.tsx | 6 +++ 7 files changed, 157 insertions(+), 5 deletions(-) diff --git a/connector/src/main.rs b/connector/src/main.rs index bdc817b..a95f34a 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -16,8 +16,8 @@ use tsclientlib::messages::c2s::{OutClientPokeRequestPart, OutSendTextMessagePar use tsclientlib::prelude::*; use tsclientlib::{ data, ChannelId, ClientId, CodecEncryptionMode, Connection, DisconnectOptions, HostBannerMode, - HostMessageMode, Identity, MaxClients, MessageHandle, MessageTarget, Reason, StreamItem, - TextMessageTargetMode, + HostMessageMode, Identity, InMessage, MaxClients, MessageHandle, MessageTarget, Reason, + StreamItem, TextMessageTargetMode, }; use tsproto_packets::packets::{AudioData, CodecType, Direction, Flags, OutAudio, OutCommand, PacketType}; @@ -233,6 +233,11 @@ enum Event { bandwidth_sent_last_second: u64, bandwidth_received_last_second: u64, }, + /// Reply to a "serverlog" request - raw lines from the virtual server's + /// protocol log (distinct from `ServerLog` above, which is the synthesized + /// client-join/channel-edit/etc. feed for the Server tab). + #[serde(rename = "serverProtocolLog")] + ServerProtocolLog { lines: Vec }, } fn emit(event: &Event) { @@ -544,6 +549,10 @@ async fn run(args: Args) -> Result<()> { // batch, not as a direct command result) - checked and emitted below. let mut pending_client_conninfo: Option = None; let mut pending_server_conninfo = false; + // Set by "serverlog" while waiting for the notifyserverlog reply, which + // arrives as a StreamItem::MessageEvent (not a BookEvents batch, since log + // lines aren't part of the channel/client/server data model). + let mut pending_server_log = false; enum LoopOutcome { StdinLine(std::io::Result>), @@ -876,6 +885,15 @@ async fn run(args: Args) -> Result<()> { } Err(e) => emit(&Event::Error { message: e.to_string() }), } + } else if l == "serverlog" { + let part = con.get_state()?.server.log_view().set_lines(200); + match part.send_with_result(&mut con) { + Ok(handle) => { + pending_server_log = true; + pending_messages.insert(handle, "Server log".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } } else if let Some(b64) = l.strip_prefix("audio ") { match base64::engine::general_purpose::STANDARD.decode(b64.trim()) { Ok(bytes) => { @@ -1049,6 +1067,15 @@ async fn run(args: Args) -> Result<()> { } } } + Some(Ok(StreamItem::MessageEvent(msg))) => { + if pending_server_log { + if let InMessage::ServerLog(log) = &msg { + let lines: Vec = log.iter().map(|part| part.log.clone()).collect(); + emit(&Event::ServerProtocolLog { lines }); + pending_server_log = false; + } + } + } Some(Ok(_)) => {} Some(Err(e)) => { emit(&Event::Disconnected { reason: e.to_string() }); diff --git a/gateway/src/index.ts b/gateway/src/index.ts index 07e2d78..a29130e 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -146,6 +146,10 @@ wss.on("connection", (socket: WebSocket) => { await connection?.editServer(msg.payload ?? {}); break; } + case "getServerLog": { + await connection?.getServerLog(); + break; + } case "disconnect": { await connection?.disconnect(msg.message ?? ""); break; diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index caba0c7..45f79b2 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -90,7 +90,8 @@ export type Ts3ConnectionEvent = bytesReceivedTotal: number; bandwidthSentLastSecond: number; bandwidthReceivedLastSecond: number; - }; + } + | { type: "serverProtocolLog"; lines: string[] }; export interface Ts3ConnectOptions { host: string; @@ -205,7 +206,8 @@ export class Ts3Connection { bytes_received_total: number; bandwidth_sent_last_second: number; bandwidth_received_last_second: number; - }; + } + | { type: "serverProtocolLog"; lines: string[] }; if (event.type === "connected") { this.emit({ @@ -351,6 +353,10 @@ export class Ts3Connection { this.child?.stdin.write(`serveredit ${JSON.stringify(payload)}\n`); } + async getServerLog(): Promise { + this.child?.stdin.write(`serverlog\n`); + } + async sendChatMessage(message: string): Promise { const sanitized = message.replace(/[\r\n]+/g, " ").trim(); if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`); diff --git a/web/src/App.css b/web/src/App.css index b565178..1b1200e 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1054,6 +1054,17 @@ white-space: nowrap; } +.ts-server-protocol-log-dialog { + width: 640px; +} + +.ts-server-protocol-log-line { + padding: 0.15rem 0.4rem; + border-bottom: 1px solid var(--border-soft); + white-space: pre-wrap; + word-break: break-all; +} + .ts-log-time { color: var(--text-muted); flex-shrink: 0; diff --git a/web/src/App.tsx b/web/src/App.tsx index e697caf..e65364a 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1198,6 +1198,62 @@ function ClientLogDialog({ entries, onClose }: { entries: ClientLogEntry[]; onCl ); } +function ServerProtocolLogDialog({ + lines, + onClose, +}: { + lines: string[] | null; + onClose: () => void; +}) { + const t = useT(); + const backdrop = useBackdropDismiss(onClose); + // The server may silently decline (e.g. missing b_virtualserver_log_view + // permission) without ever replying - fall back to an error instead of + // spinning forever. + const [timedOut, setTimedOut] = useState(false); + useEffect(() => { + setTimedOut(false); + if (lines) return; + const id = window.setTimeout(() => setTimedOut(true), 6000); + return () => window.clearTimeout(id); + }, [lines]); + + return ( +
+
e.stopPropagation()}> +
+ {t("serverProtocolLog.title")} + +
+
+ {!lines ? ( +
+ {timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")} +
+ ) : lines.length === 0 ? ( +
{t("serverProtocolLog.empty")}
+ ) : ( +
+ {lines.map((line, i) => ( +
+ {line} +
+ ))} +
+ )} +
+
+
+ +
+
+
+
+ ); +} + function WhisperHistoryDialog({ serverName, entries, @@ -2618,6 +2674,8 @@ function AppInner() { const [serverBannerUrl, setServerBannerUrl] = useState(""); const [serverWelcomeMessage, setServerWelcomeMessage] = useState(""); const [serverEditOpen, setServerEditOpen] = useState(false); + const [serverProtocolLogOpen, setServerProtocolLogOpen] = useState(false); + const [serverProtocolLog, setServerProtocolLog] = useState(null); const [treeWidth, setTreeWidth] = useState(260); const [upperHeight, setUpperHeight] = useState(340); const [selected, setSelected] = useState(null); @@ -3179,6 +3237,9 @@ function AppInner() { bandwidthReceivedLastSecond: data.bandwidthReceivedLastSecond, }); break; + case "serverProtocolLog": + setServerProtocolLog(data.lines); + break; } }; @@ -3749,6 +3810,12 @@ function AppInner() { socketRef.current?.send(JSON.stringify({ type: "getServerConnectionInfo" })); }; + const handleShowServerProtocolLog = () => { + setServerProtocolLogOpen(true); + setServerProtocolLog(null); + socketRef.current?.send(JSON.stringify({ type: "getServerLog" })); + }; + const handleClientContextMenu = ( e: React.MouseEvent, clientId: number, @@ -4111,7 +4178,6 @@ function AppInner() { { icon: "🚫", label: t("menu.extras.banList"), shortcut: "Strg+Umschalt+B" }, { icon: "⚠️", label: t("menu.extras.complaintList"), shortcut: "Strg+Umschalt+C" }, { icon: "🔑", label: t("menu.extras.serverQueryLogin") }, - { icon: "📄", label: t("menu.extras.serverLog"), shortcut: "Strg+Umschalt+L" }, ].map((item) => ( ))} +