Android: create, edit and delete channels

A one-page channel editor with what the desktop dialog has but the
permissions and the icon: name, password, topic, description, type,
sorting, talk power, codec preset or codec and quality, and the limits.
Create channel is on the server sheet; create sub-channel, edit and
delete on the channel sheet, each only with the permission for it.

The codec list, presets and bandwidth move to core for both editors.
Core gains channel delete, and the desktop channel menu a Delete Channel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 22:19:52 +00:00
co-authored by Claude Opus 5.5
parent 60ef727f22
commit 7938b49b07
14 changed files with 449 additions and 40 deletions
@@ -97,6 +97,13 @@ final class ChannelAdmin {
conn.socket().executeCommand(cmd).complete();
}
/** Deletes a channel, with its sub-channels and whoever is in them moved out when {@code force}. */
void delete(int channelId, boolean force) throws Exception {
conn.socket().executeCommand(new SingleCommand("channeldelete", ProtocolRole.CLIENT,
new CommandSingleParameter("cid", Integer.toString(channelId)),
new CommandSingleParameter("force", force ? "1" : "0"))).complete();
}
// ---- channel permissions ----
/**
@@ -0,0 +1,73 @@
package com.ts3client.net;
/**
* The voice codecs a channel can use, in TeamSpeak's own id order, with the editor's
* presets and what one talking client costs in bandwidth.
*/
public final class ChannelCodec {
/** Codec names, indexed by {@link ChannelSettings#codec}. */
public static final String[] NAMES = {
"Speex Narrowband", "Speex Wideband", "Speex Ultra-Wideband",
"CELT Mono", "Opus Voice", "Opus Music"};
public static final int OPUS_VOICE = 4;
public static final int OPUS_MUSIC = 5;
public static final int MAX_QUALITY = 10;
/** The channel editor's presets; a codec and quality matching none of them is custom. */
public enum Preset {
VOICE_MOBILE("Voice Mobile", OPUS_VOICE, 4),
VOICE_DESKTOP("Voice Desktop", OPUS_VOICE, 6),
MUSIC("Music", OPUS_MUSIC, 6);
public final String label;
public final int codec;
public final int quality;
Preset(String label, int codec, int quality) {
this.label = label;
this.codec = codec;
this.quality = quality;
}
/** The preset with this codec and quality, or null for a custom setting. */
public static Preset of(int codec, int quality) {
for (Preset p : values()) {
if (p.codec == codec && p.quality == quality) return p;
}
return null;
}
}
/**
* Bandwidth per talking client in KiB/s at quality 0 and 10, per codec, as published by
* TeamSpeak. The steps in between are interpolated: the client shows a figure per
* quality step, and only the two ends of each codec's range are documented.
*/
private static final double[][] BANDWIDTH_RANGE = {
{2.49, 5.22}, {2.69, 7.37}, {2.73, 7.57}, {6.10, 13.92}, {2.73, 7.71}, {3.08, 11.87}};
private ChannelCodec() {
}
public static String name(int codec) {
return NAMES[clampCodec(codec)];
}
public static int clampCodec(int codec) {
return Math.max(0, Math.min(NAMES.length - 1, codec));
}
/** KiB/s one talking client costs. */
public static double bandwidth(int codec, int quality) {
double[] range = BANDWIDTH_RANGE[clampCodec(codec)];
int q = Math.max(0, Math.min(MAX_QUALITY, quality));
return range[0] + (range[1] - range[0]) * q / MAX_QUALITY;
}
/** {@link #bandwidth} as the editor shows it. */
public static String bandwidthText(int codec, int quality) {
return String.format("%.2f KiB/s", bandwidth(codec, quality));
}
}
@@ -18,6 +18,9 @@ public final class ChannelSettings {
/** How long a channel outlives its last occupant. */
public enum Type {TEMPORARY, SEMI_PERMANENT, PERMANENT}
/** TeamSpeak's ceiling for {@code channel_delete_delay}, in seconds. */
public static final int MAX_DELETE_DELAY = 604800;
public int id;
public int parentId;
public String name = "";
@@ -1432,6 +1432,18 @@ public final class TeamspeakConnection implements TS3Listener {
});
}
/**
* Deletes a channel; with {@code force}, also one that has sub-channels or clients in it.
*
* @param callback given {@code null} on success, or the failure message
*/
public void deleteChannel(int channelId, boolean force, Consumer<String> callback) {
run((ignored, error) -> callback.accept(error), () -> {
channels.delete(channelId, force);
return null;
});
}
/** The ids of the icons uploaded to this virtual server. */
public void requestServerIcons(BiConsumer<List<Long>, String> callback) {
run(callback, channels::listIcons);
@@ -630,6 +630,29 @@ public final class ServerSession {
return hasPower("i_client_ban_power");
}
public boolean canCreateChannels() {
return permitsAny("b_channel_create_temporary", "b_channel_create_semi_permanent",
"b_channel_create_permanent");
}
public boolean canEditChannels() {
return permitsAny("b_channel_modify_name", "b_channel_modify_topic", "b_channel_modify_description",
"b_channel_modify_password", "b_channel_modify_codec", "b_channel_modify_maxclients");
}
public boolean canDeleteChannels() {
return permitsAny("b_channel_delete_temporary", "b_channel_delete_semi_permanent",
"b_channel_delete_permanent");
}
private boolean permitsAny(String... permissions) {
if (!conn.isConnected()) return false;
for (String p : permissions) {
if (conn.getModel().permits(p)) return true;
}
return false;
}
/**
* Whether we have any of a power; whether it beats the client's needed power only the
* server knows, so it is left to refuse.