Add a Permissions menu with privilege keys: list, create, remove and use

Permissions > Use Privilege Key redeems a key (tokenuse). Permissions >
Privilege Keys opens a per-tab window listing the server's keys with
their group, channel, creation date and description; keys can be created,
removed, copied and reloaded. The create dialog takes a server group, or a
channel group in a chosen channel, plus a description, offers only groups
we have the power to add members to, and shows each new key for copying.

tokenlist and tokenadd answer with notifytokenlist / notifytokenadd ahead
of the command's completion, so core collects them the way it does the
ban list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 23:00:27 +00:00
co-authored by Claude Opus 5.5
parent 2c1b37ee30
commit 4911542d39
12 changed files with 806 additions and 9 deletions
@@ -16,7 +16,9 @@ import com.ts3client.sound.SoundNotifier;
import com.ts3client.text.TsLink;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import java.awt.Component;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
@@ -52,6 +54,7 @@ final class ServerTab {
/** The one open ban list window for this server, if any. */
private BanListDialog banList;
private PrivilegeKeysDialog privilegeKeys;
ServerTab(MainFrame host, Settings settings, IdentityStore identities, AudioBackend audio,
SoundNotifier sounds, ContactStore contacts, PictureDownloads pictures) {
@@ -187,11 +190,39 @@ final class ServerTab {
banList.toFront();
}
/** The server's name changed or the connection went; the ban list window follows. */
void banListServerChanged(boolean connected) {
if (banList == null) return;
if (connected) banList.serverNameChanged();
else banList.connectionLost();
/** Asks for a privilege key and redeems it on this server. */
void usePrivilegeKey() {
if (!session.isConnected()) return;
String key = (String) JOptionPane.showInputDialog(host, "Privilege Key:", "Use Privilege Key",
JOptionPane.PLAIN_MESSAGE, Icons.of("TOKEN_USE"), null, null);
if (key == null || key.isBlank()) return;
conn.usePrivilegeKey(key.trim(), error -> {
if (error == null) return;
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(host, error,
"Error using Privilege Key", JOptionPane.ERROR_MESSAGE));
});
}
/** Opens the server's privilege keys, or brings the already open window forward. */
void showPrivilegeKeys() {
if (!session.isConnected()) return;
if (privilegeKeys == null || !privilegeKeys.isDisplayable()) {
privilegeKeys = new PrivilegeKeysDialog(host, conn, groupIcons);
}
privilegeKeys.setVisible(true);
privilegeKeys.toFront();
}
/** The server's name changed or the connection went; the ban list and privilege keys windows follow. */
void serverWindowsChanged(boolean connected) {
if (banList != null) {
if (connected) banList.serverNameChanged();
else banList.connectionLost();
}
if (privilegeKeys != null) {
if (connected) privilegeKeys.serverNameChanged();
else privilegeKeys.connectionLost();
}
}
/** The contact list changed: names, colours and per-client playback follow. */