html/efnetorg.pl
1 # include $whois_decip somewhere in your /FORMAT whois
2
3 use Irssi 20011207;
4 use strict;
5 use vars qw($VERSION %IRSSI);
6
7 $VERSION = "1.2";
8
9 %IRSSI = (
10 authors => "Espen Holm Nilsen",
11 contact => "holm\@blackedge.org",
12 name => "efnetorg",
13 description => "Print the real IP address of efnet.org clients when they join/part channels, and whois.",
14 license => "GPLv2 or later",
15 url => "http://www.holmnilsen.com/"
16 );
17
18 my $whois_decip = "";
19
20 sub whois_signal {
21 my ($server, $data, $nick, $host) = @_;
22 my ($me, $nick, $user, $host) = split(" ", $data);
23 if($host eq "chat.efnet.org") {
24 $whois_decip = hex2dec($user);
25 } else {
26 $whois_decip = "";
27 }
28 }
29
30 sub expando_decip {
31 if($whois_decip ne "") {
32 return "(" . $whois_decip . ")";
33 } else {
34 return $whois_decip;
35 }
36 }
37
38 sub hex2dec ($) {
39 my ($hexip) = @_;
40 my @iparr = split(//, $hexip);
41 my $decip = hex($iparr[0] . $iparr[1]) . "." . hex($iparr[2] . $iparr[3]) . "." . hex($iparr[4] . $iparr[5]) . "." . hex($iparr[6] . $iparr[7]);
42 return $decip;
43 }
44
45 sub client_part {
46 my ($server, $channame, $nick, $host) = @_;
47 $channame =~ s/^://;
48
49 my $channel = $server->channel_find($channame);
50
51 return unless ($host =~ /\@chat.efnet.org$/);
52 my @hostz = split("\@", $host);
53
54 my $ident = $hostz[0];
55 my $decip = hex2dec($ident);
56 $channel->printformat(MSGLEVEL_PARTS, 'part_efnetorg', $nick, $host, $decip, $channel->{name});
57 Irssi::signal_stop();
58 return 0;
59 }
60
61 sub client_join {
62 my ($server, $channame, $nick, $host) = @_;
63 $channame =~ s/^://;
64
65 my $channel = $server->channel_find($channame);
66
67 return unless ($host =~ /\@chat.efnet.org$/);
68 my @hostz = split("\@", $host);
69
70 my $ident = $hostz[0];
71 my $decip = hex2dec($ident);
72 $channel->printformat(MSGLEVEL_JOINS, 'join_efnetorg', $nick, $host, $decip, $channel->{name});
73 Irssi::signal_stop();
74 return 0;
75
76 }
77
78 Irssi::theme_register([
79 'join_efnetorg', '{channick_hilight $0} {chanhost_hilight $1} ({hilight $2}) has joined {channel $3}',
80 'part_efnetorg', '{channick $0} {chanhost $1} ({hilight $2}) has left {channel $3}'
81 ]);
82
83 Irssi::expando_create('whois_decip', \&expando_decip, { 'event 311' => 'None' } );
84 Irssi::signal_add_first('event 311', 'whois_signal');
85 Irssi::signal_add('message join', 'client_join');
86 Irssi::signal_add('message part', 'client_part');
87