Add Server Log tab notifications for client/channel/permission events

Surfaces join/leave/channel-switch/group-assignment/channel- and
server-edit events inline in the Server tab, matching the native TS3
client's behavior. Own missing-permission errors are shown; other
clients' permission failures are not. Sourced from tsclientlib's
book-event diffs rather than admin-only ServerQuery logs, so it works
for any connected user regardless of log-view permissions. Also
upgrades the channel-switch command to report permission errors
instead of failing silently, and adds a scripted demo-mode preview of
the feature for the GitHub Pages demo.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-08-01 10:54:18 +02:00
1 parent 0d8e9336f8
commit 42f82d49aa
6 files changed
+272 -11

No files matched your search

+141 -4
View File
@@ -11,7 +11,7 @@ use serde::Serialize;
use tokio::io::{AsyncBufReadExt, BufReader};
use tsclientlib::audio::AudioHandler;
use tsclientlib::events::Event as BookEvent;
use tsclientlib::events::{Event as BookEvent, PropertyId, PropertyValue};
use tsclientlib::messages::c2s::{OutClientPokeRequestPart, OutSendTextMessagePart};
use tsclientlib::prelude::*;
use tsclientlib::{
@@ -70,6 +70,26 @@ struct ClientInfo {
is_channel_commander: bool,
}
/// Human-facing entries for the Server tab's log-style notifications
/// (client join/leave/switch, channel group assignment, channel/server
/// changes, own permission errors) - mirrors what the native TS3 client
/// shows inline in the server chat. `rename_all = "camelCase"` covers both
/// the `kind` tag values and field names, so this needs no remapping on the
/// gateway side (unlike the snake_case variants below).
#[derive(Serialize)]
#[serde(tag = "kind", rename_all = "camelCase")]
enum ServerLogEntry {
ClientJoin { client: String, channel: String },
ClientLeave { client: String },
ClientChannelSwitch { client: String, from_channel: String, to_channel: String },
ClientChannelGroupAssigned { client: String, group: String },
ChannelCreated { channel: String },
ChannelDeleted { channel: String },
ChannelEdited { channel: String },
ServerEdited,
PermissionError { action: String },
}
#[derive(Serialize)]
#[serde(tag = "type")]
enum Event {
@@ -108,12 +128,118 @@ enum Event {
Disconnected { reason: String },
#[serde(rename = "error")]
Error { message: String },
/// Server-tab log notification (client join/leave/switch, channel group
/// assignment, channel/server changes, own permission errors).
#[serde(rename = "serverLog")]
ServerLog {
#[serde(flatten)]
entry: ServerLogEntry,
},
}
fn emit(event: &Event) {
println!("{}", serde_json::to_string(event).unwrap());
}
fn emit_server_log(entry: ServerLogEntry) {
emit(&Event::ServerLog { entry });
}
/// Translates a single book-state diff into a Server-tab log entry, when it's
/// one of the changes worth surfacing there (client join/leave/switch,
/// channel group assignment, channel/server changes). Most diffs (e.g.
/// per-field client updates like mute state) are intentionally not logged -
/// only the categories the native client's server log shows for these.
fn log_book_event(con: &data::Connection, event: &BookEvent) {
match event {
BookEvent::PropertyAdded { id: PropertyId::Client(client_id), .. } => {
if let Some(client) = con.clients.get(client_id) {
let channel = con.channels.get(&client.channel).map(|c| c.name.clone()).unwrap_or_default();
emit_server_log(ServerLogEntry::ClientJoin { client: client.name.clone(), channel });
}
}
BookEvent::PropertyRemoved { id: PropertyId::Client(_), old: PropertyValue::Client(client), .. } => {
emit_server_log(ServerLogEntry::ClientLeave { client: client.name.clone() });
}
BookEvent::PropertyAdded { id: PropertyId::Channel(channel_id), .. } => {
if let Some(channel) = con.channels.get(channel_id) {
emit_server_log(ServerLogEntry::ChannelCreated { channel: channel.name.clone() });
}
}
BookEvent::PropertyRemoved { id: PropertyId::Channel(_), old: PropertyValue::Channel(channel), .. } => {
emit_server_log(ServerLogEntry::ChannelDeleted { channel: channel.name.clone() });
}
BookEvent::PropertyChanged { id: PropertyId::ClientChannel(client_id), old: PropertyValue::ChannelId(old_channel), .. } => {
if let Some(client) = con.clients.get(client_id) {
let from_channel = con.channels.get(old_channel).map(|c| c.name.clone()).unwrap_or_default();
let to_channel = con.channels.get(&client.channel).map(|c| c.name.clone()).unwrap_or_default();
emit_server_log(ServerLogEntry::ClientChannelSwitch {
client: client.name.clone(),
from_channel,
to_channel,
});
}
}
BookEvent::PropertyChanged { id: PropertyId::ClientChannelGroup(client_id), .. } => {
if let Some(client) = con.clients.get(client_id) {
let group =
con.channel_groups.get(&client.channel_group).map(|g| g.name.clone()).unwrap_or_default();
emit_server_log(ServerLogEntry::ClientChannelGroupAssigned { client: client.name.clone(), group });
}
}
BookEvent::PropertyChanged {
id:
PropertyId::ChannelName(channel_id)
| PropertyId::ChannelTopic(channel_id)
| PropertyId::ChannelMaxClients(channel_id)
| PropertyId::ChannelMaxFamilyClients(channel_id)
| PropertyId::ChannelHasPassword(channel_id)
| PropertyId::ChannelNeededTalkPower(channel_id)
| PropertyId::ChannelCodec(channel_id)
| PropertyId::ChannelCodecQuality(channel_id)
| PropertyId::ChannelIsDefault(channel_id)
| PropertyId::ChannelDeleteDelay(channel_id)
| PropertyId::ChannelPhoneticName(channel_id)
| PropertyId::ChannelIsPrivate(channel_id)
| PropertyId::ChannelForcedSilence(channel_id)
| PropertyId::ChannelOrder(channel_id)
| PropertyId::ChannelParent(channel_id),
..
} => {
if let Some(channel) = con.channels.get(channel_id) {
emit_server_log(ServerLogEntry::ChannelEdited { channel: channel.name.clone() });
}
}
BookEvent::PropertyChanged {
id:
PropertyId::ServerName
| PropertyId::ServerWelcomeMessage
| PropertyId::ServerHostmessage
| PropertyId::ServerHostmessageMode
| PropertyId::ServerHostbannerUrl
| PropertyId::ServerHostbannerGfxUrl
| PropertyId::ServerHostbannerGfxInterval
| PropertyId::ServerHostbannerMode
| PropertyId::ServerHostbuttonTooltip
| PropertyId::ServerHostbuttonUrl
| PropertyId::ServerHostbuttonGfxUrl
| PropertyId::ServerPhoneticName
| PropertyId::ServerIcon
| PropertyId::ServerMaxClients
| PropertyId::ServerAskForPrivilegekey
| PropertyId::ServerDefaultServerGroup
| PropertyId::ServerDefaultChannelGroup
| PropertyId::ServerCodecEncryptionMode
| PropertyId::ServerTempChannelDefaultDeleteDelay
| PropertyId::ServerPrioritySpeakerDimmModificator,
..
} => {
emit_server_log(ServerLogEntry::ServerEdited);
}
_ => {}
}
}
/// `Channel::order` is not a plain position, it's the id of the preceding
/// sibling channel (0 = first child of its parent) - effectively a linked
/// list per parent. This resolves that into a plain 0-based sequence index
@@ -340,8 +466,11 @@ async fn run(args: Args) -> Result<()> {
let own = &state.clients[&state.own_client];
own.client_move(ChannelId(id))
};
if let Err(e) = part.send(&mut con) {
emit(&Event::Error { message: e.to_string() });
match part.send_with_result(&mut con) {
Ok(handle) => {
pending_messages.insert(handle, "Channel switch".into());
}
Err(e) => emit(&Event::Error { message: e.to_string() }),
}
}
Err(_) => emit(&Event::Error { message: format!("Invalid channel id: {rest}") }),
@@ -518,6 +647,8 @@ async fn run(args: Args) -> Result<()> {
emit(&Event::Poke { from: invoker.name.clone(), message: message.clone() });
}
}
} else {
log_book_event(con.get_state()?, event);
}
}
emit(&snapshot(con.get_state()?));
@@ -539,7 +670,13 @@ async fn run(args: Args) -> Result<()> {
Some(Ok(StreamItem::MessageResult(handle, result))) => {
if let Some(label) = pending_messages.remove(&handle) {
if let Err(e) = result {
emit(&Event::Error { message: format!("{label} failed: {e}") });
if e.missing_permission.is_some() {
emit(&Event::ServerLog {
entry: ServerLogEntry::PermissionError { action: label },
});
} else {
emit(&Event::Error { message: format!("{label} failed: {e}") });
}
}
}
}
+15 -2
View File
@@ -33,6 +33,17 @@ export interface ClientInfo {
isChannelCommander: boolean;
}
export type ServerLogEntry =
| { kind: "clientJoin"; client: string; channel: string }
| { kind: "clientLeave"; client: string }
| { kind: "clientChannelSwitch"; client: string; fromChannel: string; toChannel: string }
| { kind: "clientChannelGroupAssigned"; client: string; group: string }
| { kind: "channelCreated"; channel: string }
| { kind: "channelDeleted"; channel: string }
| { kind: "channelEdited"; channel: string }
| { kind: "serverEdited" }
| { kind: "permissionError"; action: string };
export type Ts3ConnectionEvent =
| {
type: "connected";
@@ -51,7 +62,8 @@ export type Ts3ConnectionEvent =
| { type: "audioOut"; pcm: string }
| { type: "talkers"; clients: number[] }
| { type: "disconnected"; reason: string }
| { type: "error"; message: string };
| { type: "error"; message: string }
| ({ type: "serverLog" } & ServerLogEntry);
export interface Ts3ConnectOptions {
host: string;
@@ -134,7 +146,8 @@ export class Ts3Connection {
| { type: "audioOut"; pcm: string }
| { type: "talkers"; clients: number[] }
| { type: "disconnected"; reason: string }
| { type: "error"; message: string };
| { type: "error"; message: string }
| ({ type: "serverLog" } & ServerLogEntry);
if (event.type === "connected") {
this.emit({
+5
View File
@@ -600,6 +600,11 @@
color: var(--accent);
}
.ts-chat-line-log {
color: var(--text-muted);
font-style: italic;
}
.ts-chat-input-row {
flex-shrink: 0;
display: flex;
+52 -5
View File
@@ -371,6 +371,9 @@ function InfoPanel({
interface ChatEntry {
from: string;
message: string;
/** Set for server-log notifications (join/leave/switch/etc.) so they render
* without a "from:" prefix, like the native client's server tab. */
isLog?: boolean;
}
interface PmMessage {
@@ -1709,6 +1712,44 @@ function AppInner() {
void playSound("poke");
break;
}
case "serverLog": {
let message: string;
switch (data.kind) {
case "clientJoin":
message = t("serverLog.clientJoin", { client: data.client, channel: data.channel });
break;
case "clientLeave":
message = t("serverLog.clientLeave", { client: data.client });
break;
case "clientChannelSwitch":
message = t("serverLog.clientChannelSwitch", {
client: data.client,
fromChannel: data.fromChannel,
toChannel: data.toChannel,
});
break;
case "clientChannelGroupAssigned":
message = t("serverLog.clientChannelGroupAssigned", { client: data.client, group: data.group });
break;
case "channelCreated":
message = t("serverLog.channelCreated", { channel: data.channel });
break;
case "channelDeleted":
message = t("serverLog.channelDeleted", { channel: data.channel });
break;
case "channelEdited":
message = t("serverLog.channelEdited", { channel: data.channel });
break;
case "serverEdited":
message = t("serverLog.serverEdited");
break;
case "permissionError":
message = t("serverLog.permissionError", { action: data.action });
break;
}
setServerChat((prev) => [...prev, { from: "", message, isLog: true }]);
break;
}
case "disconnected": {
const wasConnected = hasConnectedRef.current;
hasConnectedRef.current = false;
@@ -2575,11 +2616,17 @@ function AppInner() {
</div>
))
: activeTab === "server"
? serverChat.map((entry, i) => (
<div key={i} className="ts-chat-line">
<span className="ts-chat-from">{entry.from}:</span> <span>{entry.message}</span>
</div>
))
? serverChat.map((entry, i) =>
entry.isLog ? (
<div key={i} className="ts-chat-line ts-chat-line-log">
<span>{entry.message}</span>
</div>
) : (
<div key={i} className="ts-chat-line">
<span className="ts-chat-from">{entry.from}:</span> <span>{entry.message}</span>
</div>
)
)
: pmThreads[activeTab]?.messages.map((entry, i) => (
<div key={i} className="ts-chat-line">
<span className="ts-chat-from">
+39
View File
@@ -121,11 +121,21 @@ export class DemoSocket {
welcomeMessage: "This is a simulated demo - no real TeamSpeak server is involved. Connect with any name/address you like.",
});
this.after(150, () => this.sendChannels(nickname));
this.scriptServerLog(nickname);
});
break;
}
case "switchChannel": {
const fromChannel = this.channelName(this.selfChannel);
this.selfChannel = msg.channelId;
const toChannel = this.channelName(this.selfChannel);
this.emit({
type: "serverLog",
kind: "clientChannelSwitch",
client: this.lastNickname,
fromChannel,
toChannel,
});
this.after(120, () => this.sendChannels(this.lastNickname));
break;
}
@@ -167,6 +177,35 @@ export class DemoSocket {
private lastNickname = "Guest";
private channelName(id: number): string {
return DEMO_CHANNELS.find((c) => c.id === id)?.name ?? "";
}
/** A short, scripted burst of Server-tab log lines so the feature is visible
* in the demo without needing a second real user to trigger them. */
private scriptServerLog(nickname: string) {
this.after(2500, () =>
this.emit({ type: "serverLog", kind: "clientJoin", client: "Sam", channel: this.channelName(2) })
);
this.after(5000, () =>
this.emit({
type: "serverLog",
kind: "clientChannelSwitch",
client: "Jordan",
fromChannel: this.channelName(2),
toChannel: this.channelName(1),
})
);
this.after(7500, () =>
this.emit({
type: "serverLog",
kind: "clientChannelGroupAssigned",
client: nickname,
group: "Guest",
})
);
}
private sendChannels(nickname: string) {
this.lastNickname = nickname;
const self: DemoClient = {
+20
View File
@@ -189,6 +189,16 @@ const translations: Record<Lang, Record<string, string>> = {
"chat.send": "Senden",
"chat.you": "Du",
"serverLog.clientJoin": "{client} loggte sich in Channel \"{channel}\" ein",
"serverLog.clientLeave": "{client} hat die Verbindung getrennt (Verlassen)",
"serverLog.clientChannelSwitch": "{client} ging von Channel \"{fromChannel}\" in \"{toChannel}\"",
"serverLog.clientChannelGroupAssigned": "Die Channel-Gruppe \"{group}\" wurde {client} zugewiesen",
"serverLog.channelCreated": "Channel \"{channel}\" wurde erstellt",
"serverLog.channelDeleted": "Channel \"{channel}\" wurde gelöscht",
"serverLog.channelEdited": "Channel \"{channel}\" wurde bearbeitet",
"serverLog.serverEdited": "Die Servereinstellungen wurden geändert",
"serverLog.permissionError": "Fehlende Berechtigung: {action}",
"poke.title": "Anstupsen",
"poke.optionalMessage": "Optionale Nachricht...",
"poke.send": "Anstupsen",
@@ -407,6 +417,16 @@ const translations: Record<Lang, Record<string, string>> = {
"chat.send": "Send",
"chat.you": "You",
"serverLog.clientJoin": "{client} entered channel \"{channel}\"",
"serverLog.clientLeave": "{client} disconnected (Left)",
"serverLog.clientChannelSwitch": "{client} moved from channel \"{fromChannel}\" to \"{toChannel}\"",
"serverLog.clientChannelGroupAssigned": "Channel group \"{group}\" was assigned to {client}",
"serverLog.channelCreated": "Channel \"{channel}\" was created",
"serverLog.channelDeleted": "Channel \"{channel}\" was deleted",
"serverLog.channelEdited": "Channel \"{channel}\" was edited",
"serverLog.serverEdited": "Server settings were changed",
"serverLog.permissionError": "Missing permission: {action}",
"poke.title": "Poke",
"poke.optionalMessage": "Optional message...",
"poke.send": "Poke",