+ /**
+ * Cancels the download of the given pack from the given bot.
+ *
+ * @param bot
+ * The bot the pack is being downloaded from
+ * @param pack
+ * The pack being downloaded
+ */
+ public void cancelDownload(Bot bot, Pack pack) {
+ Optional<Download> download = getDownload(pack, bot);
+ if (!download.isPresent()) {
+ return;
+ }
+
+ /* get connection. */
+ Connection connection = networkConnections.get(bot.network());
+ if (connection == null) {
+ /* request for unknown network? */
+ return;
+ }
+
+ /* 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. */
+ try {
+ connection.sendMessage(bot.name(), String.format("XDCC %s", (download.get().dccReceiver() != null) ? "CANCEL" : "REMOVE"));
+ } catch (IOException ioe1) {
+ logger.log(Level.WARNING, String.format("Could not cancel DCC from %s (%s)!", bot.name(), bot.network().name()), ioe1);
+ }
+ }
+
+ /**
+ * Closes the given connection.
+ *
+ * @param connection
+ * The connection to close
+ */
+ public void closeConnection(Connection connection) {
+ try {
+ connection.close();
+ } catch (IOException ioe1) {
+ /* TODO */
+ }
+ }
+