]> git.xonotic.org Git - xonotic/xonotic.git/blob - server/rcon2irc/joinsparts.pl
New icon version by sev, should work better at low res
[xonotic/xonotic.git] / server / rcon2irc / joinsparts.pl
1 # Xonotic rcon2irc plugin by Merlijn Hofstra licensed under GPL - joinsparts.pl
2 # Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins.
3 # Don't forget to edit the options below to suit your needs.
4
5 { my %pj = (
6         irc_announce_joins => 1,
7         irc_announce_parts => 1,
8         irc_show_playerip => 0,
9         irc_show_statusnumber => 0,
10         irc_show_mapname => 0,
11         irc_show_amount_of_players => 0,
12         irc_show_country => 0,
13         check_clones => 1
14 );
15
16 # current code has been tested against version 0.8 of the Geo::IPfree module
17 # You can obtain a copy here: http://search.cpan.org/~bricas/Geo-IPfree-0.8/lib/Geo/IPfree.pm
18 # Place the 'Geo' dir in the same directory as this plugin or anywhere in @INC.
19 if ($pj{irc_show_country}) {
20         eval { 
21                 require Geo::IPfree;
22                 $pj{geo} = Geo::IPfree->new;
23                 $pj{geo}->Faster; # Due to a relatively large amount of lookups, this is probably a good idea 
24         } or die "joinsparts.pl: requested countrynames, but can't load data, $@";
25
26
27 $store{plugin_joinsparts} = \%pj; }
28
29 sub out($$@);
30
31 sub get_player_count
32 {
33         my $count = 0;
34         for (1 .. $store{slots_max}) {
35                 my $id = $store{"playerid_byslot_$_"};
36                 $count++ if (defined $id && $store{"playerip_byid_$id"} ne 'bot');
37         }
38         return $count;
39 }
40 # Catch joins and display requested info
41 [ dp => q{:join:(\d+):(\d+):([^:]*):(.*)} => sub {
42         my ($id, $slot, $ip, $nick) = @_;
43         my $pj = $store{plugin_joinsparts};
44         $pj->{alive_check}->[$slot] = 1;
45         
46         return 0 if ($ip eq 'bot');
47         
48         my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country});
49         
50         my $clonenicks;
51         if ($pj->{check_clones}) {
52                 for (1 .. $store{slots_max}) {
53                         my $plrid = $store{"playerid_byslot_$_"};
54                         next if (!defined $plrid || $plrid == $id || $ip ne $store{"playerip_byid_$plrid"});
55                         $clonenicks .= ' ' . $store{"playernick_byid_$plrid"} . "\017";
56                 }
57         }
58         
59         $nick = color_dp2irc $nick;
60         if ($pj->{irc_announce_joins} && !$store{"playerid_byslot_$slot"}) {
61                 out irc => 0, "PRIVMSG $config{irc_channel} :\00309+ join\017: $nick\017" . 
62                         ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
63                         ($pj->{irc_show_statusnumber} ? " #\00304$slot\017 " : '') .
64                         ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017" : '') .
65                         ($clonenicks ? " Clone of:$clonenicks" : '') .
66                         ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
67                         ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()+1) . "\017/$store{slots_max}" : '');
68         }
69         return 0;
70 } ],
71
72 # Record parts so the info in $store is always up to date
73 [ dp => q{:part:(\d+)} => sub {
74         my ($id) = @_;
75         my $pj = $store{plugin_joinsparts};
76         
77         my $ip = $store{"playerip_byid_$id"};
78         my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
79         
80         if ($pj->{irc_announce_parts} && defined $store{"playernick_byid_$id"} && $store{"playerip_byid_$id"} ne 'bot') {
81                 out irc => 0, "PRIVMSG $config{irc_channel} :\00304- part\017: " . $store{"playernick_byid_$id"} . "\017" . 
82                         ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
83                         ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017": '') .
84                         ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
85                         ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()-1) . "\017/$store{slots_max}" : '');
86         }
87         my $slot = $store{"playerslot_byid_$id"};
88         $store{"playernickraw_byid_$id"} = undef;
89         $store{"playernick_byid_$id"} = undef;
90         $store{"playerip_byid_$id"} = undef;
91         $store{"playerslot_byid_$id"} = undef;
92         $store{"playerid_byslot_$slot"} = undef;
93         return 0;
94 } ],
95
96 # Add some functionality that should clear 'ghost' clients that disconnect at unfortunate times
97 [ dp => q{:end} => sub {
98         return 0 unless (time() - $store{map_starttime} > 180); # make sure the map has been played at least 3 minutes
99         
100         my $pj = $store{plugin_joinsparts};
101         for (1 .. $store{slots_max}) {
102                 if ($store{"playerid_byslot_$_"} && !$pj->{alive_check}->[$_]) {
103                         my $id = $store{"playerid_byslot_$_"};
104                         $store{"playernickraw_byid_$id"} = undef;
105                         $store{"playernick_byid_$id"} = undef;
106                         $store{"playerip_byid_$id"} = undef;
107                         $store{"playerslot_byid_$id"} = undef;
108                         $store{"playerid_byslot_$_"} = undef;
109                 }
110         }
111         $pj->{alive_check} = ();
112         
113         return 0;
114 } ],