X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fcore%2FCore.java;h=e95cf0e436517e43d77480b058ed301b4b23c678;hb=d1fbb9c5a7e32ed55e5ddc2c107be6c4d31ba5cb;hp=5df7f425891d98b511b868e890e706b5379e56d6;hpb=207761aba7e6ddf5e736058f15e844a4df0d1f55;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 5df7f42..e95cf0e 100644 --- a/src/main/java/net/pterodactylus/xdcc/core/Core.java +++ b/src/main/java/net/pterodactylus/xdcc/core/Core.java @@ -17,7 +17,11 @@ package net.pterodactylus.xdcc.core; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -28,8 +32,10 @@ import java.util.logging.Logger; import net.pterodactylus.irc.Connection; import net.pterodactylus.irc.ConnectionBuilder; +import net.pterodactylus.irc.DccReceiver; import net.pterodactylus.irc.event.ChannelMessageReceived; import net.pterodactylus.irc.event.ConnectionEstablished; +import net.pterodactylus.irc.event.DccSendReceived; import net.pterodactylus.irc.util.MessageCleaner; import net.pterodactylus.irc.util.RandomNickname; import net.pterodactylus.xdcc.core.event.BotAdded; @@ -73,6 +79,9 @@ public class Core extends AbstractIdleService { /** The currently known bots. */ private final Table networkBots = HashBasedTable.create(); + /** The current DCC receivers. */ + private final Collection dccReceivers = Sets.newHashSet(); + /** * Creates a new core. * @@ -97,6 +106,15 @@ public class Core extends AbstractIdleService { return networkBots.values(); } + /** + * Returns the currently active DCC receivers. + * + * @return The currently active DCC receivers + */ + public Collection dccReceivers() { + return dccReceivers; + } + // // ACTIONS // @@ -111,6 +129,27 @@ public class Core extends AbstractIdleService { channels.add(channel); } + /** + * Fetches the given pack from the given bot. + * + * @param bot + * The bot to fetch the pack from + * @param pack + * The pack to fetch + */ + public void fetch(Bot bot, Pack pack) { + Connection connection = networkConnections.get(bot.network()); + if (connection == null) { + return; + } + + try { + connection.sendMessage(bot.name(), "XDCC SEND " + pack.id()); + } catch (IOException ioe1) { + logger.log(Level.WARNING, "Could not send message to bot!", ioe1); + } + } + // // ABSTRACTIDLESERVICE METHODS // @@ -215,6 +254,25 @@ public class Core extends AbstractIdleService { logger.fine(String.format("Bot %s now has %d packs.", bot, bot.packs().size())); } + /** + * Starts a DCC download. + * + * @param dccSendReceived + * The DCC SEND event + */ + @Subscribe + public void dccSendReceived(DccSendReceived dccSendReceived) { + logger.info(String.format("Starting download of %s.", dccSendReceived.filename())); + try { + OutputStream fileOutputStream = new FileOutputStream(new File("/home/bombe/Temp", dccSendReceived.filename())); + DccReceiver dccReceiver = new DccReceiver(dccSendReceived.inetAddress(), dccSendReceived.port(), dccSendReceived.filename(), dccSendReceived.filesize(), fileOutputStream); + dccReceivers.add(dccReceiver); + dccReceiver.start(); + } catch (FileNotFoundException fnfe1) { + logger.log(Level.WARNING, "Could not open file for download!", fnfe1); + } + } + // // PRIVATE METHODS //