adding/removing client permissions
This commit is contained in:
@@ -26,6 +26,8 @@ package com.github.manevolent.ts3j.api;
|
|||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -43,6 +45,14 @@ public class Permission extends Wrapper {
|
|||||||
super(map);
|
super(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Permission(String id, int value, boolean negated) {
|
||||||
|
super(createPermissionMap(id, value, negated));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Permission(String id, int value) {
|
||||||
|
this(id, value, false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of this permission.
|
* Gets the name of this permission.
|
||||||
* <p>
|
* <p>
|
||||||
@@ -107,4 +117,11 @@ public class Permission extends Wrapper {
|
|||||||
return getBoolean("permskip");
|
return getBoolean("permskip");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> createPermissionMap(String id, int value, boolean negated) {
|
||||||
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
|
map.put("permsid", id);
|
||||||
|
map.put("permvalue", Integer.toString(value));
|
||||||
|
map.put("permnegated", Integer.toString(negated ? 1 : 0));
|
||||||
|
return Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+67
-4
@@ -6,6 +6,7 @@ import com.github.manevolent.ts3j.api.Client;
|
|||||||
import com.github.manevolent.ts3j.api.Permission;
|
import com.github.manevolent.ts3j.api.Permission;
|
||||||
import com.github.manevolent.ts3j.audio.Microphone;
|
import com.github.manevolent.ts3j.audio.Microphone;
|
||||||
import com.github.manevolent.ts3j.command.*;
|
import com.github.manevolent.ts3j.command.*;
|
||||||
|
import com.github.manevolent.ts3j.command.parameter.CommandOption;
|
||||||
import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter;
|
import com.github.manevolent.ts3j.command.parameter.CommandSingleParameter;
|
||||||
import com.github.manevolent.ts3j.command.response.AbstractCommandResponse;
|
import com.github.manevolent.ts3j.command.response.AbstractCommandResponse;
|
||||||
import com.github.manevolent.ts3j.command.response.CommandResponse;
|
import com.github.manevolent.ts3j.command.response.CommandResponse;
|
||||||
@@ -454,7 +455,14 @@ public class LocalTeamspeakClientSocket
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandResponse<Iterable<SingleCommand>> executeCommand(Command command)
|
/**
|
||||||
|
* Executes a command.
|
||||||
|
* @param command Command to execute.
|
||||||
|
* @return Future, command response object.
|
||||||
|
* @throws IOException if there is a connectivity-level exception.
|
||||||
|
* @throws TimeoutException if command send times out.
|
||||||
|
*/
|
||||||
|
public CommandResponse<Iterable<SingleCommand>> executeCommand(Command command)
|
||||||
throws IOException, TimeoutException {
|
throws IOException, TimeoutException {
|
||||||
return executeCommand(command, Function.identity());
|
return executeCommand(command, Function.identity());
|
||||||
}
|
}
|
||||||
@@ -862,6 +870,58 @@ public class LocalTeamspeakClientSocket
|
|||||||
deleteBan(ban.getId());
|
deleteBan(ban.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public void clientListPermission(int clientDatabaseId)
|
||||||
|
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
||||||
|
MultiCommand command = new MultiCommand(
|
||||||
|
"clientpermlist",
|
||||||
|
ProtocolRole.CLIENT,
|
||||||
|
new SingleCommand("clientlistperm", ProtocolRole.CLIENT)
|
||||||
|
);
|
||||||
|
|
||||||
|
command.add(new CommandSingleParameter("cldbid", Integer.toString(clientDatabaseId)));
|
||||||
|
command.add(new CommandOption("permsid"));
|
||||||
|
|
||||||
|
executeCommand(command).complete();
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public void clientAddPermission(int clientDatabaseId, Permission... permission)
|
||||||
|
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
||||||
|
MultiCommand command = new MultiCommand(
|
||||||
|
"clientaddperm",
|
||||||
|
ProtocolRole.CLIENT,
|
||||||
|
Arrays.stream(permission).map(x ->
|
||||||
|
new SingleCommand("clientaddperm", ProtocolRole.CLIENT, // name is redundant here
|
||||||
|
new CommandSingleParameter("permsid", x.getName()),
|
||||||
|
new CommandSingleParameter("permvalue", Integer.toString(x.getValue())),
|
||||||
|
new CommandSingleParameter("permskip", Integer.toString(x.isNegated() ? 1 : 0))
|
||||||
|
)).collect(Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
command.add(new CommandSingleParameter("cldbid", Integer.toString(clientDatabaseId)));
|
||||||
|
|
||||||
|
executeCommand(command).complete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clientDeletePermission(int clientDatabaseId, Permission... permission)
|
||||||
|
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
||||||
|
MultiCommand command = new MultiCommand(
|
||||||
|
"clientdelperm",
|
||||||
|
ProtocolRole.CLIENT,
|
||||||
|
Arrays.stream(permission).map(x ->
|
||||||
|
new SingleCommand("clientdelperm", ProtocolRole.CLIENT, // name is redundant here
|
||||||
|
new CommandSingleParameter("permsid", x.getName()),
|
||||||
|
new CommandSingleParameter("permvalue", Integer.toString(x.getValue())),
|
||||||
|
new CommandSingleParameter("permskip", Integer.toString(x.isNegated() ? 1 : 0))
|
||||||
|
)).collect(Collectors.toList()
|
||||||
|
));
|
||||||
|
|
||||||
|
command.add(new CommandSingleParameter("cldbid", Integer.toString(clientDatabaseId)));
|
||||||
|
|
||||||
|
executeCommand(command).complete();
|
||||||
|
}
|
||||||
|
|
||||||
public void channelAddPermission(int channelId, Permission... permission)
|
public void channelAddPermission(int channelId, Permission... permission)
|
||||||
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
throws IOException, TimeoutException, ExecutionException, InterruptedException {
|
||||||
MultiCommand command = new MultiCommand(
|
MultiCommand command = new MultiCommand(
|
||||||
@@ -870,7 +930,8 @@ public class LocalTeamspeakClientSocket
|
|||||||
Arrays.stream(permission).map(x ->
|
Arrays.stream(permission).map(x ->
|
||||||
new SingleCommand("channeladdperm", ProtocolRole.CLIENT, // name is redundant here
|
new SingleCommand("channeladdperm", ProtocolRole.CLIENT, // name is redundant here
|
||||||
new CommandSingleParameter("permsid", x.getName()),
|
new CommandSingleParameter("permsid", x.getName()),
|
||||||
new CommandSingleParameter("permvalue", Integer.toString(x.getValue()))
|
new CommandSingleParameter("permvalue", Integer.toString(x.getValue())),
|
||||||
|
new CommandSingleParameter("permskip", Integer.toString(x.isNegated() ? 1 : 0))
|
||||||
)).collect(Collectors.toList()
|
)).collect(Collectors.toList()
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -887,7 +948,8 @@ public class LocalTeamspeakClientSocket
|
|||||||
Arrays.stream(permission).map(x ->
|
Arrays.stream(permission).map(x ->
|
||||||
new SingleCommand("channelclientaddperm", ProtocolRole.CLIENT, // name is redundant here
|
new SingleCommand("channelclientaddperm", ProtocolRole.CLIENT, // name is redundant here
|
||||||
new CommandSingleParameter("permsid", x.getName()),
|
new CommandSingleParameter("permsid", x.getName()),
|
||||||
new CommandSingleParameter("permvalue", Integer.toString(x.getValue()))
|
new CommandSingleParameter("permvalue", Integer.toString(x.getValue())),
|
||||||
|
new CommandSingleParameter("permskip", Integer.toString(x.isNegated() ? 1 : 0))
|
||||||
)).collect(Collectors.toList()
|
)).collect(Collectors.toList()
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -905,7 +967,8 @@ public class LocalTeamspeakClientSocket
|
|||||||
Arrays.stream(permission).map(x ->
|
Arrays.stream(permission).map(x ->
|
||||||
new SingleCommand("channeldelperm", ProtocolRole.CLIENT, // name is redundant here
|
new SingleCommand("channeldelperm", ProtocolRole.CLIENT, // name is redundant here
|
||||||
new CommandSingleParameter("permsid", x.getName()),
|
new CommandSingleParameter("permsid", x.getName()),
|
||||||
new CommandSingleParameter("permvalue", Integer.toString(x.getValue()))
|
new CommandSingleParameter("permvalue", Integer.toString(x.getValue())),
|
||||||
|
new CommandSingleParameter("permnegated", Integer.toString(x.isNegated() ? 1 : 0))
|
||||||
)).collect(Collectors.toList()
|
)).collect(Collectors.toList()
|
||||||
));
|
));
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
package com.github.manevolent.ts3j;
|
package com.github.manevolent.ts3j;
|
||||||
;
|
|
||||||
import com.github.manevolent.ts3j.identity.LocalIdentity;
|
import com.github.manevolent.ts3j.identity.LocalIdentity;
|
||||||
import com.github.manevolent.ts3j.protocol.client.ClientConnectionState;
|
import com.github.manevolent.ts3j.protocol.client.ClientConnectionState;
|
||||||
import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket;
|
import com.github.manevolent.ts3j.protocol.socket.client.LocalTeamspeakClientSocket;
|
||||||
import com.github.manevolent.ts3j.util.Ts3Debugging;
|
import com.github.manevolent.ts3j.util.Ts3Debugging;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class ServerConnectionTest {
|
public class ServerConnectionTest {
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Ts3Debugging.setEnabled(true);
|
Ts3Debugging.setEnabled(true);
|
||||||
|
|
||||||
LocalIdentity identity = LocalIdentity.generateNew(10);
|
LocalIdentity identity = LocalIdentity.read(new File("ident.ini"));
|
||||||
|
|
||||||
LocalTeamspeakClientSocket client = new LocalTeamspeakClientSocket();
|
LocalTeamspeakClientSocket client = new LocalTeamspeakClientSocket();
|
||||||
client.setIdentity(identity);
|
client.setIdentity(identity);
|
||||||
@@ -23,6 +25,9 @@ public class ServerConnectionTest {
|
|||||||
"teamlixo.net",
|
"teamlixo.net",
|
||||||
10000L
|
10000L
|
||||||
);
|
);
|
||||||
|
client.getChannels().get().forEach(x -> System.err.println(x.getTopic()));
|
||||||
|
|
||||||
|
client.clientListPermission(2);
|
||||||
|
|
||||||
assertEquals(client.getState(), ClientConnectionState.CONNECTED);
|
assertEquals(client.getState(), ClientConnectionState.CONNECTED);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user