]> icculus.org git repositories - divverent/nexuiz.git/blob - server/rcon2irc/showlogins.pl
rcon2irc plugin: allow people to view who (tries to) log in to the irc admin feature
[divverent/nexuiz.git] / server / rcon2irc / showlogins.pl
1 # Nexuiz rcon2irc plugin by Merlijn Hofstra licensed under GPL - showlogins.pl
2 # Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins.
3
4 { my %sl = (
5         show_success => 1,
6         show_failed => 1,
7         failed_interval => 60,
8 ); $store{plugin_showlogins} = \%sl; }
9
10 sub out($$@);
11 sub schedule($$);
12
13 schedule sub {
14         my ($timer) = @_;
15         if ($store{plugin_showlogins}->{failed_attempts}) {
16                 # Generate hostmakes
17                 my %temp = undef;
18                 my @hostmasks = grep !$temp{$_}++, @{ $store{plugin_showlogins}->{failed_attempts} };
19                 
20                 foreach my $mask (@hostmasks) {
21                         my $count = 0;
22                         foreach (@{ $store{plugin_showlogins}->{failed_attempts} }) {
23                                 $count++ if ($_ eq $mask);
24                         }
25                         
26                         out irc => 0, "PRIVMSG $config{irc_channel} :\00305* login failed\017 \00304$mask\017 tried to become an IRC admin \00304$count\017 times";
27                 }
28                 
29                 $store{plugin_showlogins}->{failed_attempts} = undef;
30         }
31         schedule $timer => $store{plugin_showlogins}->{failed_interval};;
32 } => 1;
33
34 [ irc => q{:(([^! ]*)![^ ]*) (?i:PRIVMSG) [^&#%]\S* :(.*)} => sub {
35         my ($hostmask, $nick, $command) = @_;
36         my $sl = $store{plugin_showlogins};
37         
38         if ($command eq "login $config{irc_admin_password}") {
39                 out irc => 0, "PRIVMSG $config{irc_channel} :\00310* login\017 $nick is now logged in as an IRC admin" if ($sl->{show_success});
40                 return 0;
41         }
42         
43         if ($command =~ m/^login/i && $sl->{show_failed}) {
44                 push @{ $store{plugin_showlogins}->{failed_attempts} }, $hostmask;
45         }
46         
47         return 0;
48 } ],