Select several clients in the tree to move or kick them together
Desktop: Ctrl/Shift in the tree (ClientSelectionModel keeps a selection to
one row of any kind or several clients; a Shift range keeps its clients),
drag them onto a channel, or right-click for Kick Clients from Channel /
Server and Move Clients to own Channel. The selection survives rebuilds.
Android: long-press a client, tap more; a bar offers Move to…, Move to my
channel and both kicks (as far as we may), Back clears it.
Core sends one piped clientmove / clientkick. The server refuses the whole
pipe when one row fails ("already member of channel"), so it leaves out
clients already in the target, and for a channel kick those already in
the default channel, which the model now tracks (channel_flag_default).
Verified on a local 3.13.7 server with both frontends.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -452,8 +452,11 @@ final class ConnectionEventHandler implements TS3Listener {
|
||||
}
|
||||
|
||||
/** The properties a channel event carries that the model keeps; each only when present. */
|
||||
private static void applyChannelProperties(ChannelNode ch, BaseEvent e) {
|
||||
private void applyChannelProperties(ChannelNode ch, BaseEvent e) {
|
||||
if (has(e, "channel_name")) ch.name = e.get("channel_name");
|
||||
if (has(e, "channel_flag_default") && e.getBoolean("channel_flag_default")) {
|
||||
conn.getModel().setDefaultChannel(ch.id);
|
||||
}
|
||||
// An emptied topic arrives as a bare key, which has() would skip.
|
||||
if (reported(e, "channel_topic")) ch.topic = TeamspeakConnection.orEmpty(e.get("channel_topic"));
|
||||
if (has(e, "channel_icon_id")) ch.iconId = TeamspeakConnection.safeLong(e, "channel_icon_id");
|
||||
|
||||
@@ -42,6 +42,8 @@ public final class ServerModel {
|
||||
private final Map<String, String> serverProperties = new HashMap<>();
|
||||
/** The channel group everyone starts in, e.g. "Guest" — not worth offering to (re)assign. */
|
||||
private int defaultChannelGroupId;
|
||||
/** The channel new clients land in, and kicked ones go back to; 0 until the server names it. */
|
||||
private int defaultChannelId;
|
||||
|
||||
public synchronized void clear() {
|
||||
channels.clear();
|
||||
@@ -55,6 +57,7 @@ public final class ServerModel {
|
||||
unreportedValues.clear();
|
||||
serverProperties.clear();
|
||||
defaultChannelGroupId = 0;
|
||||
defaultChannelId = 0;
|
||||
}
|
||||
|
||||
// ---- groups ----
|
||||
@@ -352,6 +355,15 @@ public final class ServerModel {
|
||||
return c;
|
||||
}
|
||||
|
||||
public synchronized int defaultChannelId() {
|
||||
return defaultChannelId;
|
||||
}
|
||||
|
||||
/** The server announces only the new default channel, so this replaces the old one. */
|
||||
public synchronized void setDefaultChannel(int id) {
|
||||
defaultChannelId = id;
|
||||
}
|
||||
|
||||
public synchronized ChannelNode getChannel(int id) {
|
||||
return channels.get(id);
|
||||
}
|
||||
|
||||
@@ -752,20 +752,66 @@ public final class TeamspeakConnection implements TS3Listener {
|
||||
(password == null || password.isEmpty()) ? null : password));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves several clients (ourselves among them, if wanted) into a channel in one piped
|
||||
* command. Clients already in it are left out, which the server would refuse.
|
||||
*/
|
||||
public void moveClients(Collection<Integer> clientIds, int channelId) {
|
||||
List<SingleCommand> rows = new ArrayList<>(clientIds.size());
|
||||
for (int id : clientIds) {
|
||||
ClientEntry client = model.getClient(id);
|
||||
if (client != null && client.channelId == channelId) continue;
|
||||
rows.add(new SingleCommand("clientmove", ProtocolRole.CLIENT,
|
||||
new CommandSingleParameter("clid", Integer.toString(id))));
|
||||
}
|
||||
if (rows.isEmpty()) return;
|
||||
act(rows.size() == 1 ? "Could not move client: " : "Could not move clients: ", sock -> {
|
||||
MultiCommand cmd = new MultiCommand("clientmove", ProtocolRole.CLIENT, rows);
|
||||
cmd.add(new CommandSingleParameter("cid", Integer.toString(channelId)));
|
||||
sock.executeCommand(cmd).complete();
|
||||
});
|
||||
}
|
||||
|
||||
/** Kicks a client out of its channel, back into the server's default one. */
|
||||
public void kickFromChannel(int clientId, String reason) {
|
||||
kick(clientId, REASON_KICK_CHANNEL, reason, "Could not kick client from the channel: ");
|
||||
kickFromChannel(List.of(clientId), reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicks clients out of their channels in one command; we are never among them, nor are
|
||||
* clients already in the default channel, as the server would refuse the whole command.
|
||||
*/
|
||||
public void kickFromChannel(Collection<Integer> clientIds, String reason) {
|
||||
int defaultChannel = model.defaultChannelId();
|
||||
List<Integer> ids = new ArrayList<>(clientIds.size());
|
||||
for (int id : clientIds) {
|
||||
ClientEntry client = model.getClient(id);
|
||||
if (client == null || client.channelId != defaultChannel) ids.add(id);
|
||||
}
|
||||
kick(ids, REASON_KICK_CHANNEL, reason, "channel");
|
||||
}
|
||||
|
||||
/** Kicks a client off the server entirely. */
|
||||
public void kickFromServer(int clientId, String reason) {
|
||||
kick(clientId, REASON_KICK_SERVER, reason, "Could not kick client from the server: ");
|
||||
kickFromServer(List.of(clientId), reason);
|
||||
}
|
||||
|
||||
private void kick(int clientId, int reasonId, String reason, String errorPrefix) {
|
||||
/** Kicks clients off the server in one command; we are never among them. */
|
||||
public void kickFromServer(Collection<Integer> clientIds, String reason) {
|
||||
kick(clientIds, REASON_KICK_SERVER, reason, "server");
|
||||
}
|
||||
|
||||
private void kick(Collection<Integer> clientIds, int reasonId, String reason, String from) {
|
||||
List<SingleCommand> rows = new ArrayList<>(clientIds.size());
|
||||
for (int id : clientIds) {
|
||||
if (id == selfClientId) continue;
|
||||
rows.add(new SingleCommand("clientkick", ProtocolRole.CLIENT,
|
||||
new CommandSingleParameter("clid", Integer.toString(id))));
|
||||
}
|
||||
if (rows.isEmpty()) return;
|
||||
String errorPrefix = "Could not kick " + (rows.size() == 1 ? "client" : "clients") + " from the " + from + ": ";
|
||||
act(errorPrefix, sock -> {
|
||||
SingleCommand cmd = new SingleCommand("clientkick", ProtocolRole.CLIENT);
|
||||
cmd.add(new CommandSingleParameter("clid", Integer.toString(clientId)));
|
||||
MultiCommand cmd = new MultiCommand("clientkick", ProtocolRole.CLIENT, rows);
|
||||
cmd.add(new CommandSingleParameter("reasonid", Integer.toString(reasonId)));
|
||||
if (reason != null && !reason.isEmpty()) {
|
||||
cmd.add(new CommandSingleParameter("reasonmsg", reason));
|
||||
|
||||
Reference in New Issue
Block a user