From: David ‘Bombe’ Roden Date: Fri, 26 Apr 2013 05:14:08 +0000 (+0200) Subject: Add commands to show the current connections and close them. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=a3b22ab8e686c5c5b0a609132fb7101e4962ad57;p=xudocci.git Add commands to show the current connections and close them. --- diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index 5b883db..6af2f73 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -147,6 +147,15 @@ public class Core extends AbstractExecutionThreadService { // /** + * Returns all currently known connections. + * + * @return All currently known connections + */ + public Collection connections() { + return networkConnections.values(); + } + + /** * Returns all configured channels. Due to various circumstances, configured * channels might not actually be joined. * diff --git a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java index 836f406..58ef4d0 100644 --- a/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java +++ b/src/main/java/net/pterodactylus/xdcc/ui/stdin/CommandReader.java @@ -26,6 +26,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import net.pterodactylus.irc.Connection; import net.pterodactylus.irc.DccReceiver; import net.pterodactylus.irc.util.MessageCleaner; import net.pterodactylus.xdcc.core.Core; @@ -85,6 +86,7 @@ public class CommandReader extends AbstractExecutionThreadService { String lastLine = ""; String line; final List lastResult = Lists.newArrayList(); + final List lastConnections = Lists.newArrayList(); while ((line = reader.readLine()) != null) { if (line.equals("")) { line = lastLine; @@ -158,6 +160,19 @@ public class CommandReader extends AbstractExecutionThreadService { } writeLine(String.format("%d channels (%d joined, %d extra), %d bots offering %d packs (%d unique).", configuredChannelsCount, joinedChannelsCount, extraChannelsCount, bots.size(), packsCount, packNames.size())); + } else if (words[0].equalsIgnoreCase("connections")) { + lastConnections.clear(); + int counter = 0; + for (Connection connection : core.connections()) { + lastConnections.add(connection); + writer.write(String.format("[%d] %s:%d, %s/s\n", counter++, connection.hostname(), connection.port(), f(connection.getInputRate()))); + } + 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)); + } } lastLine = line;