summaryrefslogtreecommitdiffstats
path: root/scripts/dccself.pl
blob: 1a6ccea72fc75162e145e2551443548e535bc756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use strict;
use vars qw/%IRSSI $VERSION/;
use Irssi qw(command_bind active_server);

$VERSION= "0.1";
%IRSSI = (
	authors     => "David Leadbeater",
	contact     => "dgl\@dgl.cx",
	name        => "dccself",
	description => "/dccself ip port, starts a dcc chat with yourself on that 
	                host/port, best used with /set dcc_autochat_masks.",
	license     => "GPL",
);

# I tried using Juerd's style for this script - seems to make it easier to read
# :)

command_bind('dccself', sub { 
   my $data = shift;
	my($ip,$port) = split / |:/, $data, 2;

   return unless ref active_server;
   my $nick = active_server->{nick};
   $ip = dcc_ip($ip);
   active_server->command("ctcp $nick DCC CHAT CHAT $ip $port");
} );

sub dcc_ip {
   my $ip = shift;
   # This could block!
   $ip = sprintf("%d.%d.%d.%d", unpack('C4',(gethostbyname($ip))[4])) 
       unless $ip =~ /\d$/;

   my @a = split /\./, $ip, 4;
   # Thanks to perlguy/grifferz/AndrewR
   return $a[0]*0x1000000 + $a[1]*0x10000 + $a[2]*0x100 + $a[3];
}