X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=fab43ab74284576ab5bae5b9c266a982741279e1;hb=5e7f77e44cacc40da04ac9f744566de0710b12a1;hp=00d1fbdf4a949ffd78da8d3873ce6351601f3890;hpb=44825f1cf5ddb021cbf9b8416e8649e768905e77;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 00d1fbd..fab43ab 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -30,6 +30,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.time.Duration; +import java.time.Instant; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -110,6 +112,7 @@ public class Core extends AbstractExecutionThreadService { /** The logger. */ private static final Logger logger = Logger.getLogger(Core.class.getName()); + private final Instant startup = Instant.now(); private final Object syncObject = new Object(); /** The event bus. */ private final EventBus eventBus; @@ -196,8 +199,11 @@ public class Core extends AbstractExecutionThreadService { Network network = entry.getKey(); Collection bots = networkBots.row(network).values(); int packCount = bots.stream().mapToInt((bot) -> bot.packs().size()).reduce((a, b) -> a + b).orElse(0); - return new ConnectedNetwork(network, entry.getValue().hostname(), - entry.getValue().port(), entry.getValue().nickname(), + Connection connection = entry.getValue(); + return new ConnectedNetwork(network, connection.hostname(), + connection.port(), + connection.getUptime().get(), + connection.nickname(), channels.stream() .filter((channel) -> channel.network() .equals(network)) @@ -258,6 +264,10 @@ public class Core extends AbstractExecutionThreadService { return downloads.values(); } + public Duration getUptime() { + return Duration.between(startup, Instant.now()); + } + // // ACTIONS // @@ -435,7 +445,7 @@ public class Core extends AbstractExecutionThreadService { continue; } if (firstNetwork.get().getKey() > System.currentTimeMillis()) { - eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey() - System.currentTimeMillis()), firstNetwork.get().getValue().name()))); + eventBus.post(new GenericMessage(String.format("Will connect to %2$s at %1$tH:%1$tM...", firstNetwork.get().getKey(), firstNetwork.get().getValue().name()))); synchronized (syncObject) { try { syncObject.wait(firstNetwork.get().getKey() - System.currentTimeMillis()); @@ -503,9 +513,6 @@ public class Core extends AbstractExecutionThreadService { return; } networkConnections.remove(network.get()); - if (!connection.established()) { - return; - } /* find all channels that need to be removed. */ for (Collection channels : ImmutableList.of(joinedChannels, extraChannels)) { @@ -658,30 +665,24 @@ public class Core extends AbstractExecutionThreadService { .forEach(bot -> networkBots.row(network.get()) .remove(bot.name())); + channelBanManager.ban(channel.get()); if (channelNotJoined.reason() == registeredNicknamesOnly) { - channels.remove(channel.get()); eventBus.post(new GenericMessage( - format("Not trying to join %s anymore.", channel.get()))); - return; - } - if (channelNotJoined.reason() == inviteOnly) { - channelBanManager.ban(channel.get()); + format("%s requires nickname registration, suspending join for a day.", + channel.get()))); + } else if (channelNotJoined.reason() == inviteOnly) { eventBus.post(new GenericMessage( format("%s is invite-only, suspending join for a day.", channel.get()))); - return; - } - if (channelNotJoined.reason() == banned) { - channelBanManager.ban(channel.get()); + } else if (channelNotJoined.reason() == banned) { eventBus.post(new GenericMessage( format("Banned from %s, suspending join for a day.", channel.get()))); - return; + } else { + eventBus.post(new GenericMessage( + format("Could not join %s: %s", channelNotJoined.channel(), + channelNotJoined.reason()))); } - - eventBus.post(new GenericMessage( - format("Could not join %s: %s", channelNotJoined.channel(), - channelNotJoined.reason()))); } /** @@ -756,7 +757,7 @@ public class Core extends AbstractExecutionThreadService { "Kicked from %s by %s: %s", kickedFromChannel.channel(), kickedFromChannel.kicker(), - kickedFromChannel.reason().or("") + kickedFromChannel.reason().orElse("") ))); } }