X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=272076c4bddd15525e67f7f0530247592448064e;hb=67092b8d7109812ba079965503bb61b11f5655c6;hp=68628d70bbce5d0f39912558eb8a0b0b7e501d74;hpb=f5fcfe1bbd91b46e873a870a0548349002a0c626;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 68628d7..272076c 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -18,8 +18,6 @@ package net.pterodactylus.xdcc.core; import static java.lang.String.format; -import static java.lang.System.currentTimeMillis; -import static java.util.concurrent.TimeUnit.HOURS; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.banned; import static net.pterodactylus.irc.event.ChannelNotJoined.Reason.registeredNicknamesOnly; import static net.pterodactylus.irc.util.MessageCleaner.getDefaultInstance; @@ -38,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import net.pterodactylus.irc.Connection; import net.pterodactylus.irc.ConnectionBuilder; @@ -70,12 +69,12 @@ import net.pterodactylus.xdcc.core.event.GenericMessage; import net.pterodactylus.xdcc.core.event.MessageReceived; import net.pterodactylus.xdcc.data.Bot; import net.pterodactylus.xdcc.data.Channel; +import net.pterodactylus.xdcc.data.ConnectedNetwork; import net.pterodactylus.xdcc.data.Download; 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; @@ -181,13 +180,25 @@ public class Core extends AbstractExecutionThreadService { * * @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); - } - }))); + public Collection connectedNetworks() { + return networkConnections.entrySet().stream().map((entry) -> { + Network network = entry.getKey(); + Collection bots = networkBots.row(network).values(); + int packCount = bots.stream().mapToInt((bot) -> bot.packs().size()).reduce((a, b) -> a + b).getAsInt(); + return new ConnectedNetwork(network, entry.getValue().hostname(), + entry.getValue().port(), entry.getValue().nickname(), + channels.stream() + .filter((channel) -> channel.network() + .equals(network)) + .map(Channel::name) + .collect(Collectors.toList()), + extraChannels.stream() + .filter((channel) -> channel.network() + .equals(network)) + .map(Channel::name) + .collect(Collectors.toList()), + bots.size(), packCount); + }).collect(Collectors.toList()); } /** @@ -435,6 +446,9 @@ public class Core extends AbstractExecutionThreadService { if (!network.isPresent()) { return; } + if (!connection.established()) { + return; + } /* find all channels that need to be removed. */ for (Collection channels : ImmutableList.of(joinedChannels, extraChannels)) { @@ -572,7 +586,7 @@ public class Core extends AbstractExecutionThreadService { if (channelNotJoined.reason() == banned) { channelBanManager.ban(channel.get()); eventBus.post(new GenericMessage( - format("Banned from %s, suspending join for day.", + format("Banned from %s, suspending join for a day.", channel.get()))); return; }