mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 00:42:49 +08:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
181b0fc43b
commit
4318ce359f
7 files changed
+157
-5
No files matched your search
+29
-2
@@ -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<String> },
|
||||
}
|
||||
|
||||
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<ClientId> = 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<Option<String>>),
|
||||
@@ -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<String> = 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() });
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<void> {
|
||||
this.child?.stdin.write(`serverlog\n`);
|
||||
}
|
||||
|
||||
async sendChatMessage(message: string): Promise<void> {
|
||||
const sanitized = message.replace(/[\r\n]+/g, " ").trim();
|
||||
if (sanitized) this.child?.stdin.write(`chat ${sanitized}\n`);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+85
-1
@@ -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 (
|
||||
<div className="ts-dialog-backdrop" {...backdrop}>
|
||||
<div className="ts-dialog ts-server-protocol-log-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="ts-dialog-titlebar">
|
||||
<span>{t("serverProtocolLog.title")}</span>
|
||||
<button onClick={onClose} title={t("dialog.close")}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ts-dialog-body">
|
||||
{!lines ? (
|
||||
<div className="ts-connection-info-loading">
|
||||
{timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")}
|
||||
</div>
|
||||
) : lines.length === 0 ? (
|
||||
<div className="ts-connection-info-loading">{t("serverProtocolLog.empty")}</div>
|
||||
) : (
|
||||
<div className="ts-log-list">
|
||||
{lines.map((line, i) => (
|
||||
<div key={i} className="ts-server-protocol-log-line">
|
||||
{line}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="ts-dialog-buttons">
|
||||
<div className="ts-dialog-buttons-right">
|
||||
<button onClick={onClose}>{t("dialog.close")}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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<string[] | null>(null);
|
||||
const [treeWidth, setTreeWidth] = useState(260);
|
||||
const [upperHeight, setUpperHeight] = useState(340);
|
||||
const [selected, setSelected] = useState<SelectedItem | null>(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) => (
|
||||
<button key={item.label} className="ts-menu-item" disabled>
|
||||
<span className="ts-menu-item-icon">{item.icon}</span>
|
||||
@@ -4119,6 +4185,17 @@ function AppInner() {
|
||||
{item.shortcut && <span className="ts-menu-item-shortcut">{item.shortcut}</span>}
|
||||
</button>
|
||||
))}
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
onClick={() => {
|
||||
handleShowServerProtocolLog();
|
||||
setExtrasMenuOpen(false);
|
||||
}}
|
||||
>
|
||||
<span className="ts-menu-item-icon">📄</span>
|
||||
<span className="ts-menu-item-label">{t("menu.extras.serverLog")}</span>
|
||||
<span className="ts-menu-item-shortcut">Strg+Umschalt+L</span>
|
||||
</button>
|
||||
<div className="ts-menu-separator" />
|
||||
<button
|
||||
className="ts-menu-item"
|
||||
@@ -4461,6 +4538,13 @@ function AppInner() {
|
||||
/>
|
||||
)}
|
||||
|
||||
{serverProtocolLogOpen && (
|
||||
<ServerProtocolLogDialog
|
||||
lines={serverProtocolLog}
|
||||
onClose={() => setServerProtocolLogOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{contactsOpen && (
|
||||
<ContactsDialog
|
||||
contacts={contacts}
|
||||
|
||||
@@ -201,6 +201,20 @@ export class DemoSocket {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "getServerLog": {
|
||||
this.after(400, () =>
|
||||
this.emit({
|
||||
type: "serverProtocolLog",
|
||||
lines: [
|
||||
"2026-08-05 10:12:03.421128|INFO |VirtualServerBase|1 |connect to server successful, connection accepted",
|
||||
"2026-08-05 10:12:04.001912|INFO |VirtualServerBase|1 |client 'Guest'(id:101) connected",
|
||||
"2026-08-05 10:14:19.552031|INFO |VirtualServerBase|1 |client 'Sam'(id:103) connected",
|
||||
"2026-08-05 10:15:02.884120|INFO |VirtualServerBase|1 |client 'Jordan'(id:104) switched channel",
|
||||
],
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
// "disconnect" is intentionally unhandled here: handleDisconnect() in
|
||||
// App.tsx always calls socket.close() right after sending it, and
|
||||
// close() already emits the "disconnected" event below.
|
||||
|
||||
@@ -356,6 +356,9 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"serverEdit.save": "Speichern",
|
||||
"serverEdit.cancel": "Abbrechen",
|
||||
|
||||
"serverProtocolLog.title": "Server Protokoll",
|
||||
"serverProtocolLog.empty": "Keine Protokolleinträge vorhanden.",
|
||||
|
||||
"clientContext.privateChat": "Privater Chat",
|
||||
"clientContext.poke": "Anstupsen",
|
||||
"clientContext.copyName": "Namen kopieren",
|
||||
@@ -749,6 +752,9 @@ const translations: Record<Lang, Record<string, string>> = {
|
||||
"serverEdit.save": "Save",
|
||||
"serverEdit.cancel": "Cancel",
|
||||
|
||||
"serverProtocolLog.title": "Server Log",
|
||||
"serverProtocolLog.empty": "No log entries.",
|
||||
|
||||
"clientContext.privateChat": "Private chat",
|
||||
"clientContext.poke": "Poke",
|
||||
"clientContext.copyName": "Copy name",
|
||||
|
||||
Reference in new issue
Block a user