From bd0122812d4d3e9e44b998b1d1aa51113bb718c6 Mon Sep 17 00:00:00 2001 From: Moepchi Date: Wed, 5 Aug 2026 13:08:01 +0200 Subject: [PATCH] Add Bannliste and Beschwerdeliste management dialogs Implements #91 (ban list) and #92 (complaint list), reusing the StreamItem::MessageEvent handling infrastructure added for #94. Connector: - New raw commands: banlist, bandel, bandelall, complainlist, complaindel, complaindelall (no typed builders exist for these). - New pending_ban_list/pending_complain_list flags + MessageEvent match arms parsing InMessage::BanList/ComplainList replies into BanListEntry/ComplainListEntry structs, emitted as banList/ complainList events. - Unlike serverlog/serverconninfo, the test server actually replies with an error return code for these (surfaced as a "permission error" Server-tab log line) rather than staying silent - the connector already handles that path via the existing pending message result matching. Gateway: getBanList/deleteBan/deleteAllBans/getComplainList/ deleteComplaint/deleteAllComplaintsFor methods and message cases, plus camelCase remapping for the two new event types. Frontend: BanListDialog and ComplainListDialog components (table view, per-row delete + delete-all for bans, optimistic local removal on delete), wired into the Extras menu (previously disabled placeholders), with the same 6s timeout-to-"unavailable" fallback pattern used by the other async-reply dialogs. Demo mode gets fake ban/complaint entries. Co-Authored-By: Claude Sonnet 5 --- connector/src/main.rs | 158 +++++++++++++++++++ gateway/src/index.ts | 24 +++ gateway/src/ts3/connection.ts | 106 ++++++++++++- web/src/App.css | 29 ++++ web/src/App.tsx | 280 ++++++++++++++++++++++++++++++++-- web/src/demoMode.ts | 60 ++++++++ web/src/i18n.tsx | 34 +++++ 7 files changed, 678 insertions(+), 13 deletions(-) diff --git a/connector/src/main.rs b/connector/src/main.rs index a95f34a..cf8f40c 100644 --- a/connector/src/main.rs +++ b/connector/src/main.rs @@ -238,6 +238,38 @@ enum Event { /// client-join/channel-edit/etc. feed for the Server tab). #[serde(rename = "serverProtocolLog")] ServerProtocolLog { lines: Vec }, + /// Reply to a "banlist" request. + #[serde(rename = "banList")] + BanList { entries: Vec }, + /// Reply to a "complainlist" request. + #[serde(rename = "complainList")] + ComplainList { entries: Vec }, +} + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +struct BanListEntry { + ban_id: u32, + ip: String, + name: String, + uid: String, + last_nickname: String, + created: String, + duration_secs: i64, + invoker_name: String, + reason: String, + enforcements: u32, +} + +#[derive(Serialize)] +#[serde(rename_all = "camelCase")] +struct ComplainListEntry { + target_client_db_id: u64, + target_name: String, + from_client_db_id: u64, + from_name: String, + message: String, + timestamp: String, } fn emit(event: &Event) { @@ -553,6 +585,8 @@ async fn run(args: Args) -> Result<()> { // 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; + let mut pending_ban_list = false; + let mut pending_complain_list = false; enum LoopOutcome { StdinLine(std::io::Result>), @@ -894,6 +928,92 @@ async fn run(args: Args) -> Result<()> { } Err(e) => emit(&Event::Error { message: e.to_string() }), } + } else if l == "banlist" { + // No typed builder exists for banlist, so this is built as a raw + // command; the reply arrives via StreamItem::MessageEvent (see below). + let packet = OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "banlist"); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_ban_list = true; + pending_messages.insert(handle, "Ban list".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } else if let Some(rest) = l.strip_prefix("bandel ") { + match rest.trim().parse::() { + Ok(ban_id) => { + let mut packet = + OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "bandel"); + packet.write_arg("banid", &ban_id); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_messages.insert(handle, "Delete ban".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } + Err(_) => emit(&Event::Error { message: format!("Invalid ban id: {rest}") }), + } + } else if l == "bandelall" { + let packet = OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "bandelall"); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_messages.insert(handle, "Delete all bans".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } else if l == "complainlist" { + let packet = + OutCommand::new(Direction::C2S, Flags::empty(), PacketType::Command, "complainlist"); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_complain_list = true; + pending_messages.insert(handle, "Complain list".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } else if let Some(rest) = l.strip_prefix("complaindel ") { + let mut parts = rest.trim().splitn(2, ' '); + let target_str = parts.next().unwrap_or(""); + let from_str = parts.next().unwrap_or(""); + match (target_str.parse::(), from_str.parse::()) { + (Ok(tcldbid), Ok(fcldbid)) => { + let mut packet = OutCommand::new( + Direction::C2S, + Flags::empty(), + PacketType::Command, + "complaindel", + ); + packet.write_arg("tcldbid", &tcldbid); + packet.write_arg("fcldbid", &fcldbid); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_messages.insert(handle, "Delete complaint".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } + _ => emit(&Event::Error { message: format!("Invalid complaindel args: {rest}") }), + } + } else if let Some(rest) = l.strip_prefix("complaindelall ") { + match rest.trim().parse::() { + Ok(tcldbid) => { + let mut packet = OutCommand::new( + Direction::C2S, + Flags::empty(), + PacketType::Command, + "complaindelall", + ); + packet.write_arg("tcldbid", &tcldbid); + match packet.send_with_result(&mut con) { + Ok(handle) => { + pending_messages.insert(handle, "Delete all complaints for client".into()); + } + Err(e) => emit(&Event::Error { message: e.to_string() }), + } + } + Err(_) => emit(&Event::Error { message: format!("Invalid client db id: {rest}") }), + } } else if let Some(b64) = l.strip_prefix("audio ") { match base64::engine::general_purpose::STANDARD.decode(b64.trim()) { Ok(bytes) => { @@ -1075,6 +1195,44 @@ async fn run(args: Args) -> Result<()> { pending_server_log = false; } } + if pending_ban_list { + if let InMessage::BanList(list) = &msg { + let entries: Vec = list + .iter() + .map(|part| BanListEntry { + ban_id: part.ban_id, + ip: part.ip.to_string(), + name: part.name.clone(), + uid: part.uid.to_string(), + last_nickname: part.last_nickname.clone(), + created: part.created.to_string(), + duration_secs: part.duration.whole_seconds(), + invoker_name: part.invoker_name.clone(), + reason: part.reason.clone(), + enforcements: part.enforcements, + }) + .collect(); + emit(&Event::BanList { entries }); + pending_ban_list = false; + } + } + if pending_complain_list { + if let InMessage::ComplainList(list) = &msg { + let entries: Vec = list + .iter() + .map(|part| ComplainListEntry { + target_client_db_id: part.target_client_db_id.0, + target_name: part.target_name.clone(), + from_client_db_id: part.from_client_db_id.0, + from_name: part.from_name.clone(), + message: part.message.clone(), + timestamp: part.timestamp.to_string(), + }) + .collect(); + emit(&Event::ComplainList { entries }); + pending_complain_list = false; + } + } } Some(Ok(_)) => {} Some(Err(e)) => { diff --git a/gateway/src/index.ts b/gateway/src/index.ts index a29130e..f387ea2 100644 --- a/gateway/src/index.ts +++ b/gateway/src/index.ts @@ -150,6 +150,30 @@ wss.on("connection", (socket: WebSocket) => { await connection?.getServerLog(); break; } + case "getBanList": { + await connection?.getBanList(); + break; + } + case "deleteBan": { + await connection?.deleteBan(msg.banId); + break; + } + case "deleteAllBans": { + await connection?.deleteAllBans(); + break; + } + case "getComplainList": { + await connection?.getComplainList(); + break; + } + case "deleteComplaint": { + await connection?.deleteComplaint(msg.targetClientDbId, msg.fromClientDbId); + break; + } + case "deleteAllComplaintsFor": { + await connection?.deleteAllComplaintsFor(msg.targetClientDbId); + break; + } case "disconnect": { await connection?.disconnect(msg.message ?? ""); break; diff --git a/gateway/src/ts3/connection.ts b/gateway/src/ts3/connection.ts index 45f79b2..a8db7b2 100644 --- a/gateway/src/ts3/connection.ts +++ b/gateway/src/ts3/connection.ts @@ -35,6 +35,28 @@ export interface ClientInfo { uid: string; } +export interface BanListEntry { + banId: number; + ip: string; + name: string; + uid: string; + lastNickname: string; + created: string; + durationSecs: number; + invokerName: string; + reason: string; + enforcements: number; +} + +export interface ComplainListEntry { + targetClientDbId: number; + targetName: string; + fromClientDbId: number; + fromName: string; + message: string; + timestamp: string; +} + export type ServerLogEntry = | { kind: "clientJoin"; client: string; channel: string } | { kind: "clientLeave"; client: string } @@ -91,7 +113,9 @@ export type Ts3ConnectionEvent = bandwidthSentLastSecond: number; bandwidthReceivedLastSecond: number; } - | { type: "serverProtocolLog"; lines: string[] }; + | { type: "serverProtocolLog"; lines: string[] } + | { type: "banList"; entries: BanListEntry[] } + | { type: "complainList"; entries: ComplainListEntry[] }; export interface Ts3ConnectOptions { host: string; @@ -207,7 +231,33 @@ export class Ts3Connection { bandwidth_sent_last_second: number; bandwidth_received_last_second: number; } - | { type: "serverProtocolLog"; lines: string[] }; + | { type: "serverProtocolLog"; lines: string[] } + | { + type: "banList"; + entries: { + ban_id: number; + ip: string; + name: string; + uid: string; + last_nickname: string; + created: string; + duration_secs: number; + invoker_name: string; + reason: string; + enforcements: number; + }[]; + } + | { + type: "complainList"; + entries: { + target_client_db_id: number; + target_name: string; + from_client_db_id: number; + from_name: string; + message: string; + timestamp: string; + }[]; + }; if (event.type === "connected") { this.emit({ @@ -281,6 +331,34 @@ export class Ts3Connection { bandwidthSentLastSecond: event.bandwidth_sent_last_second, bandwidthReceivedLastSecond: event.bandwidth_received_last_second, }); + } else if (event.type === "banList") { + this.emit({ + type: "banList", + entries: event.entries.map((e) => ({ + banId: e.ban_id, + ip: e.ip, + name: e.name, + uid: e.uid, + lastNickname: e.last_nickname, + created: e.created, + durationSecs: e.duration_secs, + invokerName: e.invoker_name, + reason: e.reason, + enforcements: e.enforcements, + })), + }); + } else if (event.type === "complainList") { + this.emit({ + type: "complainList", + entries: event.entries.map((e) => ({ + targetClientDbId: e.target_client_db_id, + targetName: e.target_name, + fromClientDbId: e.from_client_db_id, + fromName: e.from_name, + message: e.message, + timestamp: e.timestamp, + })), + }); } else { this.emit(event); } @@ -357,6 +435,30 @@ export class Ts3Connection { this.child?.stdin.write(`serverlog\n`); } + async getBanList(): Promise { + this.child?.stdin.write(`banlist\n`); + } + + async deleteBan(banId: number): Promise { + this.child?.stdin.write(`bandel ${banId}\n`); + } + + async deleteAllBans(): Promise { + this.child?.stdin.write(`bandelall\n`); + } + + async getComplainList(): Promise { + this.child?.stdin.write(`complainlist\n`); + } + + async deleteComplaint(targetClientDbId: number, fromClientDbId: number): Promise { + this.child?.stdin.write(`complaindel ${targetClientDbId} ${fromClientDbId}\n`); + } + + async deleteAllComplaintsFor(targetClientDbId: number): Promise { + this.child?.stdin.write(`complaindelall ${targetClientDbId}\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 1b1200e..568468a 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -1058,6 +1058,35 @@ width: 640px; } +.ts-ban-list-dialog, +.ts-complain-list-dialog { + width: 720px; +} + +.ts-ban-list-table { + width: 100%; + border-collapse: collapse; + font-size: 12px; +} + +.ts-ban-list-table th, +.ts-ban-list-table td { + text-align: left; + padding: 0.25rem 0.5rem; + border-bottom: 1px solid var(--border-soft); + vertical-align: top; +} + +.ts-ban-list-table th { + color: var(--text-muted); + font-weight: 600; +} + +.ts-dialog-buttons-left { + display: flex; + gap: 0.5rem; +} + .ts-server-protocol-log-line { padding: 0.15rem 0.4rem; border-bottom: 1px solid var(--border-soft); diff --git a/web/src/App.tsx b/web/src/App.tsx index e65364a..a1875aa 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -181,6 +181,28 @@ interface WhisperLogEntry { description: string; } +interface BanListEntry { + banId: number; + ip: string; + name: string; + uid: string; + lastNickname: string; + created: string; + durationSecs: number; + invokerName: string; + reason: string; + enforcements: number; +} + +interface ComplainListEntry { + targetClientDbId: number; + targetName: string; + fromClientDbId: number; + fromName: string; + message: string; + timestamp: string; +} + type ContactCategory = "acquaintance" | "blocked" | "friend"; interface Contact { @@ -1198,6 +1220,165 @@ function ClientLogDialog({ entries, onClose }: { entries: ClientLogEntry[]; onCl ); } +function BanListDialog({ + entries, + onDelete, + onDeleteAll, + onClose, +}: { + entries: BanListEntry[] | null; + onDelete: (banId: number) => void; + onDeleteAll: () => void; + onClose: () => void; +}) { + const t = useT(); + const backdrop = useBackdropDismiss(onClose); + // Same silent-decline story as connection-info/server-log: a guest account + // without b_virtualserver_client_dblist/banlist permission never gets a reply. + const [timedOut, setTimedOut] = useState(false); + useEffect(() => { + setTimedOut(false); + if (entries) return; + const id = window.setTimeout(() => setTimedOut(true), 6000); + return () => window.clearTimeout(id); + }, [entries]); + + return ( +
+
e.stopPropagation()}> +
+ {t("banList.title")} + +
+
+ {!entries ? ( +
+ {timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")} +
+ ) : entries.length === 0 ? ( +
{t("banList.empty")}
+ ) : ( + + + + + + + + + + + + + + {entries.map((e) => ( + + + + + + + + + + ))} + +
{t("banList.name")}{t("banList.ip")}{t("banList.created")}{t("banList.duration")}{t("banList.invoker")}{t("banList.reason")}
{e.name || e.lastNickname || "-"}{e.ip || "-"}{e.created}{e.durationSecs === 0 ? t("banList.permanent") : `${e.durationSecs}s`}{e.invokerName}{e.reason} + +
+ )} +
+
+
+ {entries && entries.length > 0 && ( + + )} +
+
+ +
+
+
+
+ ); +} + +function ComplainListDialog({ + entries, + onDelete, + onClose, +}: { + entries: ComplainListEntry[] | null; + onDelete: (targetClientDbId: number, fromClientDbId: number) => void; + onClose: () => void; +}) { + const t = useT(); + const backdrop = useBackdropDismiss(onClose); + const [timedOut, setTimedOut] = useState(false); + useEffect(() => { + setTimedOut(false); + if (entries) return; + const id = window.setTimeout(() => setTimedOut(true), 6000); + return () => window.clearTimeout(id); + }, [entries]); + + return ( +
+
e.stopPropagation()}> +
+ {t("complainList.title")} + +
+
+ {!entries ? ( +
+ {timedOut ? t("connectionInfo.unavailable") : t("connectionInfo.loading")} +
+ ) : entries.length === 0 ? ( +
{t("complainList.empty")}
+ ) : ( + + + + + + + + + + + + {entries.map((e, i) => ( + + + + + + + + ))} + +
{t("complainList.target")}{t("complainList.from")}{t("complainList.message")}{t("complainList.timestamp")}
{e.targetName}{e.fromName}{e.message}{e.timestamp} + +
+ )} +
+
+
+ +
+
+
+
+ ); +} + function ServerProtocolLogDialog({ lines, onClose, @@ -2676,6 +2857,10 @@ function AppInner() { const [serverEditOpen, setServerEditOpen] = useState(false); const [serverProtocolLogOpen, setServerProtocolLogOpen] = useState(false); const [serverProtocolLog, setServerProtocolLog] = useState(null); + const [banListOpen, setBanListOpen] = useState(false); + const [banList, setBanList] = useState(null); + const [complainListOpen, setComplainListOpen] = useState(false); + const [complainList, setComplainList] = useState(null); const [treeWidth, setTreeWidth] = useState(260); const [upperHeight, setUpperHeight] = useState(340); const [selected, setSelected] = useState(null); @@ -3240,6 +3425,12 @@ function AppInner() { case "serverProtocolLog": setServerProtocolLog(data.lines); break; + case "banList": + setBanList(data.entries); + break; + case "complainList": + setComplainList(data.entries); + break; } }; @@ -3816,6 +4007,41 @@ function AppInner() { socketRef.current?.send(JSON.stringify({ type: "getServerLog" })); }; + const handleShowBanList = () => { + setBanListOpen(true); + setBanList(null); + socketRef.current?.send(JSON.stringify({ type: "getBanList" })); + }; + + const handleDeleteBan = (banId: number) => { + socketRef.current?.send(JSON.stringify({ type: "deleteBan", banId })); + setBanList((prev) => (prev ? prev.filter((e) => e.banId !== banId) : prev)); + }; + + const handleDeleteAllBans = () => { + socketRef.current?.send(JSON.stringify({ type: "deleteAllBans" })); + setBanList([]); + }; + + const handleShowComplainList = () => { + setComplainListOpen(true); + setComplainList(null); + socketRef.current?.send(JSON.stringify({ type: "getComplainList" })); + }; + + const handleDeleteComplaint = (targetClientDbId: number, fromClientDbId: number) => { + socketRef.current?.send( + JSON.stringify({ type: "deleteComplaint", targetClientDbId, fromClientDbId }) + ); + setComplainList((prev) => + prev + ? prev.filter( + (e) => !(e.targetClientDbId === targetClientDbId && e.fromClientDbId === fromClientDbId) + ) + : prev + ); + }; + const handleClientContextMenu = ( e: React.MouseEvent, clientId: number, @@ -4174,17 +4400,32 @@ function AppInner() { Strg+L
- {[ - { 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") }, - ].map((item) => ( - - ))} + + +