From d750f9685ca8748e7e256e88216c3485a9d834c1 Mon Sep 17 00:00:00 2001 From: Manevolent Date: Tue, 5 Mar 2019 11:04:54 -0500 Subject: [PATCH] Setting description, editing client properties --- .../client/LocalTeamspeakClientSocket.java | 36 +++++++++++++++++++ .../manevolent/ts3j/ServerConnectionTest.java | 2 ++ 2 files changed, 38 insertions(+) diff --git a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java index 0607929..6b48bc2 100644 --- a/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java +++ b/src/main/java/com/github/manevolent/ts3j/protocol/socket/client/LocalTeamspeakClientSocket.java @@ -831,6 +831,42 @@ public class LocalTeamspeakClientSocket return executeCommand(banCommand, command -> new Ban(command.toMap())).get(); } + public void setDescription(String description) + throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { + setClientDescription(getClientId(), description); + } + + public void setClientDescription(Client client, String description) + throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { + setClientDescription(client.getId(), description); + } + + public void setClientDescription(int clid, String description) + throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { + editClient(clid, Collections.singletonMap("client_description", description)); + } + + public void editClient(Client client, Map properties) + throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { + editClient(client.getId(), properties); + } + + public void editClient(int clid, Map properties) + throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { + MultiCommand command = new MultiCommand( + "clientedit", + ProtocolRole.CLIENT, + properties.entrySet().stream().map(x -> + new SingleCommand("clientedit", ProtocolRole.CLIENT, // name is redundant here + new CommandSingleParameter(x.getKey(), x.getValue()) + )).collect(Collectors.toList() + )); + + command.add(new CommandSingleParameter("clid", Integer.toString(clid))); + + executeCommand(command).complete(); + } + public Iterable banClient(Client client, Integer timeInSeconds, String reason) throws InterruptedException, ExecutionException, TimeoutException, CommandException, IOException { return banClient(client.getId(), timeInSeconds, reason); diff --git a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java index 6c1aa0e..d00d377 100644 --- a/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java +++ b/src/test/java/com/github/manevolent/ts3j/ServerConnectionTest.java @@ -26,6 +26,8 @@ public class ServerConnectionTest { assertEquals(client.getState(), ClientConnectionState.CONNECTED); + client.setDescription("Heyo"); + client.subscribeAll(); Thread.sleep(100000);