summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules <jules@asdf.us>2015-01-20 01:32:41 -0500
committerJules <jules@asdf.us>2015-01-20 01:32:41 -0500
commit79ba7f8ae7d478e05d53981feb0cda3d9e2b84d9 (patch)
tree1587a23ce0b3011a3e64328358bcd7a54a9f12df
parentcc9c6847828c502da1138a59bb37183e18395a2b (diff)
xdcc cancel
-rw-r--r--index.html1
-rw-r--r--xdcc.pl24
2 files changed, 18 insertions, 7 deletions
diff --git a/index.html b/index.html
index a8d842b..42f49d0 100644
--- a/index.html
+++ b/index.html
@@ -40,6 +40,7 @@ People can request files from you using these CTCP commands:
/ctcp <i>nick</i> XDCC get 1
/ctcp <i>nick</i> XDCC batch 2-4 <i># request multiple files</i>
/ctcp <i>nick</i> XDCC remove 3 <i># remove from queue</i>
+/ctcp <i>nick</i> XDCC cancel <i># cancel file transfer</i>
/ctcp <i>nick</i> XDCC queue
/ctcp <i>nick</i> XDCC help
/ctcp <i>nick</i> XDCC about</pre>
diff --git a/xdcc.pl b/xdcc.pl
index 43fa31d..d27f9bf 100644
--- a/xdcc.pl
+++ b/xdcc.pl
@@ -27,7 +27,7 @@ my $dcc_upload_path = Irssi::settings_get_str('dcc_upload_path');
my $sending = 0;
my $disabled = 0;
my $timeout = undef;
-my $dcc = undef;
+my $current_dcc = undef;
my $stats = {
files_sent => 0,
files => {},
@@ -66,6 +66,7 @@ my $help_remote = <<EOF;
/ctcp %nick XDCC %_get%_ 1
/ctcp %nick XDCC %_batch%_ 2-4 # request multiple files
/ctcp %nick XDCC %_remove%_ 3 # remove yourself from queue
+/ctcp %nick XDCC %_cancel%_ # cancel the current transfer
/ctcp %nick XDCC %_queue%_
/ctcp %nick XDCC %_help%_
/ctcp %nick XDCC %_about%_
@@ -121,6 +122,7 @@ my $messages = {
'xdcc_removed' => '[%_XDCC%_] Your request has been removed.',
'xdcc_file_removed' => '[%_XDCC%_] The file you requested [%d] has been removed.',
'xdcc_autoget_tip' => '[%_XDCC%_] Tip: in irssi, type %_/set dcc_autoget ON%_',
+ 'xdcc_cancelled' => '[%_XDCC%_] File transfer cancelled',
'xdcc_log' => "[%_XDCC%_] %s",
'xdcc_help' => $help_remote,
@@ -140,6 +142,7 @@ sub ctcp_reply {
elsif ($cmd eq "batch") { xdcc_batch($server, $nick, $index) }
elsif ($cmd eq "info") { xdcc_info($server, $nick, $index) }
elsif ($cmd eq "remove") { xdcc_remove($server, $nick, $index) }
+ elsif ($cmd eq "cancel") { xdcc_cancel($server, $nick) }
elsif ($cmd eq "queue") { xdcc_queue($server, $nick) }
elsif ($cmd eq "list") { xdcc_list($server, $nick) }
elsif ($cmd eq "version") { xdcc_message($server, $nick, 'xdcc_version') }
@@ -234,6 +237,13 @@ sub xdcc_remove {
xdcc_message( $server, $nick, 'not_in_queue' );
}
}
+sub xdcc_cancel {
+ my ($server, $nick) = @_;
+ if ($current_dcc && $current_dcc->{nick} eq $nick) {
+ xdcc_message( $server, $nick, 'xdcc_cancelled' );
+ $current_dcc->destroy();
+ }
+}
sub xdcc_info {
my ($server, $nick, $index) = @_;
my $id = int $index;
@@ -270,6 +280,9 @@ sub xdcc_queue {
xdcc_message( $server, $nick, 'queue_length', scalar @queue, scalar @queue == 1 ? "" : "s" )
}
sub xdcc_advance {
+ if ($timeout) { Irssi::timeout_remove($timeout) }
+ undef $timeout;
+ undef $current_dcc;
if (@queue == 0) { return; }
my $request = shift @queue;
xdcc_send($request);
@@ -282,7 +295,7 @@ sub xdcc_send {
my $file = $files[$id];
my $path = $file->{path};
my $fn = $file->{fn};
- xdcc_message( $server, $nick, 'sending_file', $id, $fn );
+ xdcc_message( $server, $nick, 'sending_file', $id+1, $fn );
Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_sending_file', $id, $nick, $fn);
$server->command("/DCC send $nick $path");
$sending = 1;
@@ -387,7 +400,7 @@ sub xdcc_del {
sub xdcc_reset {
@files = ();
@queue = ();
- if ($dcc) { $dcc->destroy() }
+ if ($current_dcc) { $current_dcc->destroy() }
$sending = 0;
Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_reset');
}
@@ -419,6 +432,7 @@ sub dcc_created {
# Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc created');
if ($timeout) { Irssi::timeout_remove($timeout) }
$timeout = Irssi::timeout_add_once($bother_delay, \&xdcc_bother, { dcc => $dcc, times => 1 });
+ $current_dcc = $dcc;
}
sub xdcc_bother {
my ($data) = @_;
@@ -435,17 +449,13 @@ sub xdcc_bother {
else {
Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'Send to ' . $dcc->{nick} . ' timed out.');
xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_inactive');
- Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'bla');
xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_autoget_tip');
$dcc->destroy();
- undef $timeout;
- xdcc_advance();
return
}
}
sub dcc_destroyed {
# Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc destroyed');
- if ($timeout) { Irssi::timeout_remove($timeout) }
$sending = 0;
xdcc_advance();
}