import java.io.OutputStream;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.pterodactylus.irc.event.ChannelLeft;
import net.pterodactylus.irc.event.ChannelMessageReceived;
import net.pterodactylus.irc.event.ClientQuit;
+import net.pterodactylus.irc.event.ConnectionClosed;
import net.pterodactylus.irc.event.ConnectionEstablished;
import net.pterodactylus.irc.event.DccAcceptReceived;
import net.pterodactylus.irc.event.DccDownloadFailed;
import com.google.common.base.Optional;
import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
}
/**
+ * Remove all data stored for a network if the connection is closed.
+ *
+ * @param connectionClosed
+ * The connection closed event
+ */
+ @Subscribe
+ public void connectionClosed(ConnectionClosed connectionClosed) {
+ Optional<Network> network = getNetwork(connectionClosed.connection());
+ if (!network.isPresent()) {
+ return;
+ }
+
+ /* find all channels that need to be removed. */
+ for (Collection channels : ImmutableList.of(joinedChannels, extraChannels)) {
+ for (Iterator<Channel> channelIterator = channels.iterator(); channelIterator.hasNext(); ) {
+ Channel joinedChannel = channelIterator.next();
+ if (!joinedChannel.network().equals(network.get())) {
+ continue;
+ }
+
+ channelIterator.remove();
+ }
+ }
+
+ /* now remove all bots for that network. */
+ Map<String, Bot> bots = networkBots.row(network.get());
+ int botCount = bots.size();
+ int packCount = 0;
+ for (Bot bot : bots.values()) {
+ packCount += bot.packs().size();
+ }
+ bots.clear();
+ eventBus.post(new GenericMessage(String.format("Network %s disconnected, %d bots removed, %d packs removed.", network.get().name(), botCount, packCount)));
+
+ /* now remove the network. */
+ networkConnections.remove(network.get());
+ }
+
+ /**
* Shows a message when a channel was joined by us.
*
* @param channelJoined