X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=d875a5b21d2f0cb5ef38db28b10a37a203b7fea3;hb=0c607fe61d662a15fb9b6368a7f32b92a694096a;hp=e78c4f10095874b77f52819c18baf3354b499091;hpb=dba342edc56ae069040f7a78eecf54dd1c3bab12;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/core/Core.java b/src/main/java/net/pterodactylus/xdcc/core/Core.java index e78c4f1..d875a5b 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -17,6 +17,8 @@ package net.pterodactylus.xdcc.core; +import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance; +import static net.pterodactylus.xdcc.data.Channel.TO_NETWORK; import static net.pterodactylus.xdcc.data.Download.FILTER_RUNNING; import java.io.File; @@ -52,7 +54,6 @@ import net.pterodactylus.irc.event.NicknameChanged; import net.pterodactylus.irc.event.PrivateMessageReceived; import net.pterodactylus.irc.event.PrivateNoticeReceived; import net.pterodactylus.irc.event.ReplyReceived; -import net.pterodactylus.irc.util.MessageCleaner; import net.pterodactylus.irc.util.RandomNickname; import net.pterodactylus.xdcc.core.event.BotAdded; import net.pterodactylus.xdcc.core.event.CoreStarted; @@ -69,6 +70,7 @@ import net.pterodactylus.xdcc.data.Network; import net.pterodactylus.xdcc.data.Pack; import net.pterodactylus.xdcc.data.Server; +import com.google.common.base.Function; import com.google.common.base.Optional; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; @@ -158,6 +160,29 @@ public class Core extends AbstractExecutionThreadService { } /** + * Returns all defined networks. + * + * @return All defined networks + */ + public Collection networks() { + return FluentIterable.from(channels).transform(TO_NETWORK).toSet(); + } + + /** + * Returns all connected networks. + * + * @return All connected networks + */ + public Collection connectedNetworks() { + return Lists.newArrayList(Optional.presentInstances(FluentIterable.from(networkConnections.values()).transform(new Function>() { + @Override + public Optional apply(Connection connection) { + return getNetwork(connection); + } + }))); + } + + /** * Returns all configured channels. Due to various circumstances, configured * channels might not actually be joined. * @@ -281,12 +306,12 @@ public class Core extends AbstractExecutionThreadService { return; } - /* remove download. */ - downloads.remove(pack.name(), download.get()); - /* stop the DCC receiver. */ if (download.get().dccReceiver() != null) { download.get().dccReceiver().stop(); + } else { + /* remove download if it hasn’t started yet. */ + downloads.remove(pack.name(), download.get()); } /* remove the request from the bot, too. */ @@ -479,6 +504,7 @@ public class Core extends AbstractExecutionThreadService { * @param connectionFailed * The connection failed event */ + @Subscribe public void connectionFailed(ConnectionFailed connectionFailed) { removeConnection(connectionFailed.connection()); } @@ -597,7 +623,7 @@ public class Core extends AbstractExecutionThreadService { */ @Subscribe public void channelMessageReceived(ChannelMessageReceived channelMessageReceived) { - String message = MessageCleaner.getDefaultInstance().clean(channelMessageReceived.message()); + String message = getDefaultInstance().clean(channelMessageReceived.message()); if (!message.startsWith("#")) { /* most probably not a pack announcement. */ return;