]> de.git.xonotic.org Git - xonotic/xonotic.git/blob - server/rcon2irc/showlogins.pl
275e9fcd4d817858bba66da552e9a821049e0e8f
[xonotic/xonotic.git] / server / rcon2irc / showlogins.pl
1 # Xonotic 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, # only for logins to the irc bot
6         show_failed => 1, # only for logins to the irc bot
7         show_rcon_failure => 1,
8         failed_interval => 60,
9 ); $store{plugin_showlogins} = \%sl; }
10
11 sub out($$@);
12 sub schedule($$);
13
14 if (defined %config) {
15         schedule sub {
16                 my ($timer) = @_;
17                 if ($store{plugin_showlogins}->{failed_attempts}) {
18                         # Generate hostmakes
19                         my %temp = undef;
20                         my @hostmasks = grep !$temp{$_}++, @{ $store{plugin_showlogins}->{failed_attempts} };
21                         
22                         foreach my $mask (@hostmasks) {
23                                 my $count = 0;
24                                 foreach (@{ $store{plugin_showlogins}->{failed_attempts} }) {
25                                         $count++ if ($_ eq $mask);
26                                 }
27                                 
28                                 out irc => 0, "PRIVMSG $config{irc_channel} :\00305* login failed\017 \00304$mask\017 tried to become an IRC admin \00304$count\017 times";
29                         }
30                         
31                         $store{plugin_showlogins}->{failed_attempts} = undef;
32                 }
33                 
34                 if ($store{plugin_showlogins}->{rcon_fail}) {
35                         my %temp = undef;
36                         my @names = grep !$temp{$_}++, @{ $store{plugin_showlogins}->{rcon_fail} };
37                         
38                         foreach my $name (@names) {
39                                 my $count = 0;
40                                 foreach (@{ $store{plugin_showlogins}->{rcon_fail} }) {
41                                         $count++ if ($_ eq $name);
42                                 }
43                                 
44                                 out irc => 0, "PRIVMSG $config{irc_channel} :\00305* login failed\017 \00304$name\017 tried to use rcon commands \00304$count\017 times";
45                         }
46                         
47                         $store{plugin_showlogins}->{rcon_fail} = undef;
48                 }
49                 
50                 schedule $timer => $store{plugin_showlogins}->{failed_interval};;
51         } => 1;
52 }
53
54 [ irc => q{:(([^! ]*)![^ ]*) (?i:PRIVMSG) [^&#%]\S* :(.*)} => sub {
55         my ($hostmask, $nick, $command) = @_;
56         my $sl = $store{plugin_showlogins};
57         
58         if ($command eq "login $config{irc_admin_password}") {
59                 out irc => 0, "PRIVMSG $config{irc_channel} :\00310* login\017 $nick is now logged in as an IRC admin" if ($sl->{show_success});
60                 return 0;
61         }
62         
63         if ($command =~ m/^login/i && $sl->{show_failed}) {
64                 push @{ $store{plugin_showlogins}->{failed_attempts} }, $hostmask;
65         }
66         
67         return 0;
68 } ],
69
70 # failed rcon attempts
71 [ dp => q{server denied rcon access to (.*)} => sub {
72         my ($name) = map { color_dp2irc $_ } @_;
73         my $sl = $store{plugin_showlogins};
74         
75         if ($sl->{show_rcon_failure}) {
76                 push @{ $store{plugin_showlogins}->{rcon_fail} }, $name
77         }
78         
79         return 0;
80 } ],