Merge pull request #19 from VoySpeak/fix/channel-order-and-bans

Fix channel list order and ban feedback, per-identity HWID
This commit is contained in:
Möpchi authored and GitHub committed 2026-11-24 23:21:39 +01:00
commit b856094b48
3 files changed
+110 -8

No files matched your search

+47 -1
View File
@@ -902,6 +902,29 @@ async fn main() {
}
}
/// Stable per-identity HWID in the TeamSpeak shape (`<32 hex>,<32 hex>`),
/// derived from the identity's UID hash so it survives reconnects.
fn hardware_id_for(uid: &[u8]) -> String {
let hex = |bytes: &[u8]| bytes.iter().map(|b| format!("{b:02x}")).collect::<String>();
let mut padded = uid.to_vec();
padded.resize(20, 0);
format!("{},{}", hex(&padded[..16]), hex(&padded[4..20]))
}
/// Text for a `banclient` the server refused. Permission ids differ between
/// TeamSpeak and TeaSpeak, so the usual causes are named instead of the id.
fn ban_failure_message(e: &tsclientlib::CommandError) -> String {
match e.missing_permission {
Some(perm) => format!(
"Ban failed: missing permission (id {}). Usual causes: a permanent ban (duration 0) \
without unlimited i_client_ban_max_bantime, a duration above it, too little \
i_client_ban_power, or the target has b_client_ignore_bans.",
perm.0
),
None => format!("Ban failed: {e}"),
}
}
/// VoySpeak (formerly GreenTeaSpeak) servers report versions like `2.5.1 [Build: …]`.
/// Classic TeaSpeak reports `TeaSpeak 1.4.21-beta [Build: …]` — not a GTS host.
/// Classic TeamSpeak 3 reports `3.13.8 [Build: …]` — must not use GTS labels.
@@ -1015,7 +1038,13 @@ async fn run(args: Args) -> Result<()> {
.and_then(|s| serde_json::from_str::<Identity>(s).ok().or_else(|| Identity::new_from_str(s).ok()))
.unwrap_or_else(Identity::create);
let identity_str = serde_json::to_string(&identity).unwrap();
let mut con_config = Connection::build(args.address).name(args.nickname).identity(identity);
// Without this every web user sends tsclientlib's built-in HWID, so a
// hardware-id ban on one web user would lock out all of them.
let hardware_id = hardware_id_for(&identity.key().to_pub().get_uid_no_base64());
let mut con_config = Connection::build(args.address)
.name(args.nickname)
.hardware_id(hardware_id)
.identity(identity);
let server_type = match args.server_type.as_str() {
"teaspeak" => ServerType::Teaspeak,
"teamspeak" => ServerType::Teamspeak,
@@ -2777,6 +2806,14 @@ async fn run(args: Args) -> Result<()> {
} else {
emit(&Event::Error { message: format!("{label} failed: {e}") });
}
} else if label == "Ban client" {
// A rejected ban must be visible: the UI only knows it sent one.
emit(&Event::Error { message: ban_failure_message(&e) });
if e.missing_permission.is_some() {
emit(&Event::ServerLog {
entry: ServerLogEntry::PermissionError { action: label },
});
}
} else if e.missing_permission.is_some() {
emit(&Event::ServerLog {
entry: ServerLogEntry::PermissionError { action: label },
@@ -3311,6 +3348,15 @@ mod tests {
);
}
#[test]
fn hardware_id_is_stable_and_per_identity() {
let a = hardware_id_for(&[1u8; 20]);
assert_eq!(a, hardware_id_for(&[1u8; 20]));
assert_ne!(a, hardware_id_for(&[2u8; 20]));
let (left, right) = a.split_once(',').unwrap();
assert_eq!((left.len(), right.len()), (32, 32));
}
#[test]
fn upload_chunks_assemble_in_order_and_reject_gaps() {
let mut partials = HashMap::new();
+14 -7
View File
@@ -236,6 +236,7 @@ import {
} from "./ConnectionTabs";
import { BARE_URL_REGEX, renderBbcode, wrapUrls } from "./lib/bbcode";
import { parseChannelName, spacerDisplayName } from "./lib/spacer";
import { channelsInTreeOrder } from "./lib/channelOrder";
import akimoPhoto from "./assets/akimo.jpg";
import {
applyParkedGatewayEvent,
@@ -4452,7 +4453,7 @@ function MoveClientDialog({
}) {
const t = useT();
const backdrop = useBackdropDismiss(onClose);
const movable = [...channels].sort((a, b) => a.order - b.order);
const movable = channelsInTreeOrder(channels);
return (
<div className="ts-dialog-backdrop" {...backdrop}>
@@ -4470,7 +4471,7 @@ function MoveClientDialog({
<div className="ts-connection-info-loading">{t("moveClient.empty")}</div>
) : (
<ul className="ts-group-assign-list">
{movable.map((ch) => {
{movable.map(({ channel: ch, depth }) => {
const current = ch.id === currentChannelId;
const spacer = spacerDisplayName(ch.name, ch.parent === 0);
const label = spacer.isSpacer
@@ -4482,6 +4483,7 @@ function MoveClientDialog({
className={`ts-menu-item${current ? " ts-group-assign-current" : ""}`}
disabled={current || spacer.isSpacer}
onClick={() => onSelect(ch.id)}
style={depth > 0 ? { paddingLeft: `${depth * 1.25}em` } : undefined}
>
<span className="ts-menu-item-icon">
{current ? "✔️" : spacer.isSpacer ? "➖" : "📁"}
@@ -5125,8 +5127,8 @@ function PermissionsEditorDialog({
))}
{(scope === "channel" || scope === "channelclient") && (
<ul className="ts-perms-editor-list">
{channels.map((c) => (
<li key={c.id}>
{channelsInTreeOrder(channels).map(({ channel: c, depth }) => (
<li key={c.id} style={depth > 0 ? { paddingLeft: `${depth * 1.25}em` } : undefined}>
<button
className={`ts-link-button${channelId === c.id ? " ts-perms-editor-selected" : ""}`}
onClick={() => {
@@ -12727,7 +12729,8 @@ function AppInner() {
reason: banReason,
})
);
logClient("info", "Moderation", `Banned ${banTarget.name}`);
// Only a request: the server may still refuse it (an error event follows then).
logClient("info", "Moderation", `Ban requested for ${banTarget.name}`);
setBanTarget(null);
setBanReason("");
setBanSeconds("0");
@@ -13503,8 +13506,12 @@ function AppInner() {
{whisperMenuOpen && (
<div className="ts-menu ts-menu-away" ref={focusFirstItem} onKeyDown={handleMenuKeyDown}>
<div className="ts-context-menu-title">{t("whisper.channels")}</div>
{channels.map((ch) => (
<label key={ch.id} className="ts-menu-item">
{channelsInTreeOrder(channels).map(({ channel: ch, depth }) => (
<label
key={ch.id}
className="ts-menu-item"
style={depth > 0 ? { paddingLeft: `${depth * 1.25}em` } : undefined}
>
<input
type="checkbox"
checked={whisperChannelIds.has(ch.id)}
+49
View File
@@ -0,0 +1,49 @@
/** Minimal shape needed to lay channels out like the channel tree. */
export interface OrderedChannelLike {
id: number;
parent: number;
/** Position among the siblings of the same parent (not a global index). */
order: number;
}
/**
* Flattens channels in channel-tree order: each parent is followed by its
* subchannels (recursively), siblings sorted by `order`. `order` is only
* meaningful between siblings, so a flat sort by it interleaves the levels.
* Channels whose parent is missing are appended at the end as roots.
*/
export function channelsInTreeOrder<T extends OrderedChannelLike>(
channels: readonly T[],
): { channel: T; depth: number }[] {
const byParent = new Map<number, T[]>();
for (const ch of channels) {
const list = byParent.get(ch.parent);
if (list) list.push(ch);
else byParent.set(ch.parent, [ch]);
}
for (const list of byParent.values()) list.sort((a, b) => a.order - b.order || a.id - b.id);
const out: { channel: T; depth: number }[] = [];
const seen = new Set<number>();
const walk = (parent: number, depth: number) => {
for (const ch of byParent.get(parent) ?? []) {
if (seen.has(ch.id)) continue;
seen.add(ch.id);
out.push({ channel: ch, depth });
walk(ch.id, depth + 1);
}
};
walk(0, 0);
// Orphans (parent not in the list) and anything in a parent cycle.
for (const ch of channels) {
if (seen.has(ch.id)) continue;
const orphanParent = ch.parent;
for (const sibling of byParent.get(orphanParent) ?? []) {
if (seen.has(sibling.id)) continue;
seen.add(sibling.id);
out.push({ channel: sibling, depth: 0 });
walk(sibling.id, 1);
}
}
return out;
}