Add possibility to disconnect all connections at once.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / ui / stdin / CommandReader.java
index 58ef4d0..eaaef23 100644 (file)
@@ -94,8 +94,8 @@ public class CommandReader extends AbstractExecutionThreadService {
                        String[] words = line.split(" +");
                        if (words[0].equalsIgnoreCase("search")) {
                                lastResult.clear();
-                               for (Bot bot : core.bots()) {
-                                       for (Pack pack : bot) {
+                               for (Bot bot : Lists.newArrayList(core.bots())) {
+                                       for (Pack pack : Lists.newArrayList(bot)) {
                                                boolean found = true;
                                                for (int wordIndex = 1; wordIndex < words.length; ++wordIndex) {
                                                        if (words[wordIndex].startsWith("-") && pack.name().toLowerCase().contains(words[wordIndex].toLowerCase().substring(1))) {
@@ -169,9 +169,15 @@ public class CommandReader extends AbstractExecutionThreadService {
                                }
                                writeLine("End of connections.");
                        } else if (words[0].equalsIgnoreCase("disconnect")) {
-                               Integer index = Ints.tryParse(words[1]);
-                               if ((index != null) && (index < lastConnections.size())) {
-                                       core.closeConnection(lastConnections.get(index));
+                               if ((words.length == 1) || ("all".equals(words[1]))) {
+                                       for (Connection connection : lastConnections) {
+                                               core.closeConnection(connection);
+                                       }
+                               } else {
+                                       Integer index = Ints.tryParse(words[1]);
+                                       if ((index != null) && (index < lastConnections.size())) {
+                                               core.closeConnection(lastConnections.get(index));
+                                       }
                                }
                        }