Needed virtual server id

This commit is contained in:
Manevolent
2018-08-04 19:31:51 -04:00
parent 1ed4e0c4da
commit 7239f3f7ef
3 changed files with 16 additions and 2 deletions
@@ -129,6 +129,10 @@ public class MultiCommand implements Command {
singleCommands.add(command); singleCommands.add(command);
} }
// Make sure is empty if needed
if (singleCommands.size() <= 0)
singleCommands.add(new SingleCommand(label, role));
return new MultiCommand(label, role, singleCommands); return new MultiCommand(label, role, singleCommands);
} }
} }
@@ -60,12 +60,16 @@ public class LocalTeamspeakClientSocket
private int acceptingReturnCode = 0; private int acceptingReturnCode = 0;
private int lastReturnCode = 0; private int lastReturnCode = 0;
private Integer serverId = null;
private Map<Integer, ClientCommandResponse> awaitingCommands = new ConcurrentHashMap<>(); private Map<Integer, ClientCommandResponse> awaitingCommands = new ConcurrentHashMap<>();
public LocalTeamspeakClientSocket() { public LocalTeamspeakClientSocket() {
super(); super();
namedProcessors.put("initserver", new InitServerHandler()); namedProcessors.put("initserver", new InitServerHandler());
namedProcessors.put("channellist", new CommandProcessor() { namedProcessors.put("channellist", new CommandProcessor() {
@Override @Override
public void process(AbstractTeamspeakClientSocket client, SingleCommand singleCommand) public void process(AbstractTeamspeakClientSocket client, SingleCommand singleCommand)
@@ -74,6 +78,7 @@ public class LocalTeamspeakClientSocket
for (TS3Listener listener : listeners) listener.onChannelList(channelListEvent); for (TS3Listener listener : listeners) listener.onChannelList(channelListEvent);
} }
}); });
namedProcessors.put("channellistfinished", new ChannelListFinishedHandler()); namedProcessors.put("channellistfinished", new ChannelListFinishedHandler());
} }
@@ -446,6 +451,8 @@ public class LocalTeamspeakClientSocket
throws CommandProcessException { throws CommandProcessException {
try { try {
setClientId(Integer.parseInt(singleCommand.get("aclid").getValue())); setClientId(Integer.parseInt(singleCommand.get("aclid").getValue()));
setNickname(singleCommand.get("acn").getValue());
serverId = Integer.parseInt(singleCommand.get("virtualserver_id").getValue());
} catch (Exception e) { } catch (Exception e) {
throw new CommandProcessException(e); throw new CommandProcessException(e);
} }
@@ -619,7 +626,8 @@ public class LocalTeamspeakClientSocket
throws IOException, TimeoutException, ExecutionException, InterruptedException { throws IOException, TimeoutException, ExecutionException, InterruptedException {
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT); Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
command.add(new CommandSingleParameter("targetmode", Integer.toString(1))); command.add(new CommandSingleParameter("targetmode", Integer.toString(3)));
command.add(new CommandSingleParameter("target", Integer.toString(serverId)));
command.add(new CommandSingleParameter("msg", message)); command.add(new CommandSingleParameter("msg", message));
executeCommand(command).complete(); executeCommand(command).complete();
@@ -648,7 +656,7 @@ public class LocalTeamspeakClientSocket
throws IOException, TimeoutException, ExecutionException, InterruptedException { throws IOException, TimeoutException, ExecutionException, InterruptedException {
Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT); Command command = new SingleCommand("sendtextmessage", ProtocolRole.CLIENT);
command.add(new CommandSingleParameter("targetmode", Integer.toString(3))); command.add(new CommandSingleParameter("targetmode", Integer.toString(1)));
command.add(new CommandSingleParameter("target", Integer.toString(clientId))); command.add(new CommandSingleParameter("target", Integer.toString(clientId)));
command.add(new CommandSingleParameter("msg", message)); command.add(new CommandSingleParameter("msg", message));
@@ -40,6 +40,8 @@ public class ServerConnectionTest {
assertEquals(client.getState(), ClientConnectionState.CONNECTED); assertEquals(client.getState(), ClientConnectionState.CONNECTED);
client.sendServerMessage("Heyyyy");
while (true) { while (true) {
Thread.sleep(1000L); Thread.sleep(1000L);