diff options
| author | Jules <jules@asdf.us> | 2015-01-17 16:46:54 -0500 |
|---|---|---|
| committer | Jules <jules@asdf.us> | 2015-01-17 16:46:54 -0500 |
| commit | aba6e576e562762d2c634db360021c299f09e87a (patch) | |
| tree | f5771ff514df8534999a7e2f4ab298394ca9f371 | |
| parent | b063761323e93adb8b04dd26722dd2d6f2d6f3ef (diff) | |
lotsa changes
| -rw-r--r-- | .gitignore | 3 | ||||
| -rwxr-xr-x | xdcc.pl | 125 |
2 files changed, 77 insertions, 51 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..70bb2a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.swp + @@ -8,11 +8,11 @@ $VERSION = "1.01"; %IRSSI = ( authors => 'Julie LaLa', - contact => 'jules@okfoc.us', + contact => 'ryz@asdf.us', name => 'xdcc.pl', description => 'This script sets up a little XDCC server.', license => 'Jollo LNT license', - url => 'http://asdf.us/xdcc/xdcc.pl', + url => 'http://asdf.us/xdcc/', changed => 'Wed Jan 15 23:55:44 EST 2015', ); @@ -20,10 +20,14 @@ my @files; my @queue; my $queue_max = 10; -my $bother_delay = 5000; +my $bother_delay = 10000; my $irssidir = Irssi::get_irssi_dir(); +my $dcc_upload_path = Irssi::settings_get_str('dcc_upload_path'); my $sending = 0; +my $disabled = 0; +my $timeout = undef; +my $dcc = undef; my $stats = { files_sent => 0, files => {}, @@ -33,13 +37,15 @@ my $stats = { my $help_local = <<EOF; Usage: -/XDCC [-add <filename> <description>] [-del <id>] [-list] [-help] +/XDCC [-add <filename> <description>] [-del <id>] [-list] [-stats] [-help] -add: Add a file to our XDCC server. -del: Remove a file from the offerings. -list: Display the XDCC list (default). -reset: Reset the file list and the queue. -stats: Statistics for this session +-enable: Enable the XDCC server +-disable: Disable the XDCC server -help: Display this help. Examples: @@ -62,10 +68,12 @@ EOF my $help_remote = <<EOF; [%_XDCC%_] plugin $VERSION -%_/ctcp %nick XDCC list%_ - see a list of files -%_/ctcp %nick XDCC get 1%_ - request a file -%_/ctcp %nick XDCC queue%_ - see where you are in the queue -%_/ctcp %nick XDCC help%_ - this message +/ctcp %nick XDCC [send %_N%_] [list] [queue] [version] [help] [about] +EOF + +my $help_about = <<EOF; +[%_XDCC%_] plugin $VERSION by $IRSSI{authors} +[%_XDCC%_] $IRSSI{url} EOF Irssi::theme_register([ @@ -83,13 +91,14 @@ Irssi::theme_register([ 'xdcc_stats', '[%_XDCC%_] $0 ... %_$1%_', 'xdcc_help', '$0', + 'xdcc_version', $help_about, 'loaded', '%R>>%n %_Scriptinfo:%_ Loaded $0 version $1 by $2.' ]); my $messages = { 'queue_is_full' => "[%_XDCC%_] The XDCC queue is currently full.", 'queue_is_empty' => "[%_XDCC%_] The XDCC queue is currently empty.", - 'no_files_offered' => "[%_XDCC%_] Sorry there's no warez today", + 'no_files_offered' => "[%_XDCC%_] Sorry, there's no warez today", 'file_entry' => '[%_XDCC%_] [%d] %s ... %s', 'file_count' => '[%_XDCC%_] %d file%s', @@ -105,6 +114,7 @@ my $messages = { 'xdcc_autoget_tip' => '[%_XDCC%_] Tip: in irssi, type %_/set dcc_autoget ON%_', 'xdcc_help' => $help_remote, + 'xdcc_about' => $help_about, 'xdcc_version' => "[%_XDCC%_] plugin $VERSION", }; @@ -113,14 +123,15 @@ sub ctcp_reply { my ($ctcp, $cmd, $index) = split (" ", lc($data), 3); - if ($ctcp ne "xdcc") { return; } - - if ($cmd eq "get") { xdcc_enqueue($server, $nick, $index) } - elsif ($cmd eq "send") { xdcc_enqueue($server, $nick, $index) } - elsif ($cmd eq "queue") { xdcc_queue($server, $nick) } - elsif ($cmd eq "list") { xdcc_list($server, $nick) } - elsif ($cmd eq "help") { xdcc_message($server, $nick, 'xdcc_help_remote') } - else { xdcc_list($server, $nick) } + if ($disabled || $ctcp ne "xdcc") { return; } + if ($cmd eq "get") { xdcc_enqueue($server, $nick, $index) } + elsif ($cmd eq "send") { xdcc_enqueue($server, $nick, $index) } + 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') } + elsif ($cmd eq "help") { xdcc_message($server, $nick, 'xdcc_help') } + elsif ($cmd eq "about") { xdcc_message($server, $nick, 'xdcc_about') } + else { xdcc_list($server, $nick) } Irssi::signal_stop(); } @@ -128,8 +139,8 @@ sub xdcc_message { my ($server, $nick, $msgname, @params) = @_; my (@msgs) = split ("\n", $messages->{$msgname}); for my $msg (@msgs) { - $msg =~ s/%_/\x002/g; - $msg =~ s/%-/\x003/g; + $msg =~ s/%_/\x02/g; + $msg =~ s/%-/\x03/g; $msg =~ s/%nick/$server->{nick}/g; $msg = sprintf $msg, @params; $server->send_message( $nick, $msg, 1 ); @@ -191,10 +202,9 @@ sub xdcc_send { my $id = $request->{id}; my $file = $files[$id]; my $path = $file->{path}; + xdcc_message( $server, $nick, 'sending_file', $file->{fn} ); Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_sending_file', $id, $nick, $file->{fn}); $server->command("/DCC send $nick $path"); - xdcc_message( $server, $nick, 'sending_file', $file->{fn} ); - xdcc_message( $server, $nick, 'file_help_send'); $sending = 1; $stats->{files_sent}++; $stats->{users}->{$nick} ||= 0; @@ -222,28 +232,33 @@ sub xdcc_report { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_print_queue', $n+1, $queue[$n]->{nick}, $queue[$n]->{id}, $files[$queue[$n]->{id}-1]->{fn}); } } + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_hr'); } sub xdcc_stats { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', "plugin version", $VERSION); - Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', "total sent", $stats->{files_sent}); - + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', "files sent", $stats->{files_sent}); Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_hr'); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'top files'); - map { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', $_->[0], $_->[1] } + map { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', $_->[0], $_->[1]) } sort { $b->[1] <=> $a->[1] } map { [$_, $stats->{files}->{$_}] } - keys $stats->{files}; - + keys %{ $stats->{files} }; Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_hr'); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'top users'); - map { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', $_->[0], $_->[1] } + map { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_stats', $_->[0], $_->[1]) } sort { $b->[1] <=> $a->[1] } map { [$_, $stats->{users}->{$_}] } - keys $stats->{users}; + keys %{ $stats->{users} }; + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_hr'); } sub xdcc_add { my ($path, $desc) = @_; - if (substr($path, 0, 1) eq "~") { + if ($path !~ /^[\/~]/) { + $path = $dcc_upload_path . "/" . $path; + } + if ($path =~ /^[~]/) { $path =~ s/^~//; $path = $ENV{"HOME"} . $path; } @@ -294,7 +309,7 @@ sub xdcc_reset { $sending = 0; Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_reset'); } -sub xdcc_help_local { +sub xdcc_help { Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_help', $help_local); } @@ -302,34 +317,42 @@ sub xdcc { my ($cmd, $fn, $desc) = split (" ", $_[0], 3); $cmd = lc($cmd); + $cmd =~ s/^-//; - if ($cmd eq "-add") { xdcc_add($fn, $desc) } - elsif ($cmd eq "-del") { xdcc_remove($fn) } - elsif ($cmd eq "-list") { xdcc_report() } - elsif ($cmd eq "-reset") { xdcc_reset() } - elsif ($cmd eq "-stats") { xdcc_stats() } - elsif ($cmd eq "-help") { xdcc_help_local() } - else { xdcc_report() } + if ($cmd eq "add") { xdcc_add($fn, $desc) } + elsif ($cmd eq "del") { xdcc_remove($fn) } + elsif ($cmd eq "list") { xdcc_report() } + elsif ($cmd eq "reset") { xdcc_reset() } + elsif ($cmd eq "stats") { xdcc_stats() } + elsif ($cmd eq "enable") { $disabled = 0 } + elsif ($cmd eq "disable") { $disabled = 1 } + elsif ($cmd eq "help") { xdcc_help() } + elsif ($cmd eq "version") { xdcc_version() } + else { xdcc_report() } } -my $timeout = undef; + sub dcc_created { my ($dcc) = @_; # Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc created'); - Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_help', $_); - Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_help', @_); - if ($timeout) { timeout_remove($timeout) } - $timeout = timeout_add_once($bother_delay, xdcc_bother, $dcc, $times); + if ($timeout) { Irssi::timeout_remove($timeout) } + $timeout = Irssi::timeout_add_once($bother_delay, \&xdcc_bother, { dcc => $dcc, times => 1 }); } sub xdcc_bother { - my ($dcc, $times) = @_; - if ($times == 3) { xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_final_warning') } + my ($data) = @_; + my $dcc = $data->{dcc}; + my $times = $data->{times}; + if ($times == 3) { + xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_final_warning'); + } if ($times <= 3) { - xdcc_message($dcc->{server}, $dcc->{nick}, 'file_help_send') - $timeout = timeout_add_once($bother_delay, xdcc_bother, $times, $server, $nick); + xdcc_message($dcc->{server}, $dcc->{nick}, 'file_help_send'); + $data->{times}++; + $timeout = Irssi::timeout_add_once($bother_delay, \&xdcc_bother, $data); } else { - xdcc_message($server, $nick, 'xdcc_transfer_cancelled'); - xdcc_message($server, $nick, 'xdcc_autoget_tip'); + Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'Send to ' . $dcc->{nick} . ' timed out.'); + xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_cancelled'); + xdcc_message($dcc->{server}, $dcc->{nick}, 'xdcc_autoget_tip'); $dcc->destroy(); undef $timeout; return @@ -337,7 +360,7 @@ sub xdcc_bother { } sub dcc_destroyed { # Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc destroyed'); - if ($timeout) { timeout_remove($timeout) } + if ($timeout) { Irssi::timeout_remove($timeout) } $sending = 0; if (@queue == 0) { return; } my $request = shift @queue; @@ -345,7 +368,7 @@ sub dcc_destroyed { } sub dcc_connected { # Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc connected'); - if ($timeout) { timeout_remove($timeout) } + if ($timeout) { Irssi::timeout_remove($timeout) } } sub dcc_rejecting { # Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'xdcc_log', 'dcc rejecting'); @@ -362,5 +385,5 @@ Irssi::signal_add('dcc rejecting', 'dcc_rejecting'); Irssi::signal_add('dcc closed', 'dcc_closed'); Irssi::signal_add('default ctcp msg', 'ctcp_reply'); Irssi::command_bind('xdcc', 'xdcc'); -Irssi::command_set_options('xdcc','add del list stats reset help'); +Irssi::command_set_options('xdcc','add del list stats enable disable reset help version'); Irssi::printformat(MSGLEVEL_CLIENTCRAP, 'loaded', $IRSSI{name}, $VERSION, $IRSSI{authors}); |
