1 # Nexuiz 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.
6 irc_announce_joins => 1,
7 irc_announce_parts => 1,
8 irc_show_playerip => 0,
10 irc_show_amount_of_players => 0,
14 # current code has been tested against version 0.8 of the Geo::IPfree module
15 # You can obtain a copy here: http://search.cpan.org/~bricas/Geo-IPfree-0.8/lib/Geo/IPfree.pm
16 # Place the 'Geo' dir in the same directory as this plugin or anywhere in @INC.
17 if ($pj{irc_show_country}) {
19 $pj{geo} = Geo::IPfree->new;
20 $pj{geo}->Faster; # Due to a relatively large amount of lookups, this is probably a good idea
23 $store{plugin_joinsparts} = \%pj; }
30 for (1 .. $store{slots_max}) {
31 my $id = $store{"playerid_byslot_$_"};
32 $count++ if (defined $id && $store{"playerip_byid_$id"} ne 'bot');
36 # Catch joins and display requested info
37 [ dp => q{:join:(\d+):(\d+):([^:]*):(.*)} => sub {
38 my ($id, $slot, $ip, $nick) = @_;
39 my $pj = $store{plugin_joinsparts};
40 $pj->{alive_check}->[$slot] = 1;
42 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
44 $nick = color_dp2irc $nick;
45 if ($pj->{irc_announce_joins} && !$store{"playerid_byslot_$slot"} && $ip ne 'bot') {
46 out irc => 0, "PRIVMSG $config{irc_channel} :\00309+ join\017: $nick\017" .
47 ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
48 ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017" : '') .
49 ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
50 ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()+1) . "\017/$store{slots_max}" : '');
55 # Record parts so the info in $store is always up to date
56 [ dp => q{:part:(\d+)} => sub {
58 my $pj = $store{plugin_joinsparts};
60 my $ip = $store{"playerip_byid_$id"};
61 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
63 if ($pj->{irc_announce_parts} && defined $store{"playernick_byid_$id"} && $store{"playerip_byid_$id"} ne 'bot') {
64 out irc => 0, "PRIVMSG $config{irc_channel} :\00304- part\017: " . $store{"playernick_byid_$id"} . "\017" .
65 ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
66 ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017": '') .
67 ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
68 ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()-1) . "\017/$store{slots_max}" : '');
70 my $slot = $store{"playerslot_byid_$id"};
71 $store{"playernickraw_byid_$id"} = undef;
72 $store{"playernick_byid_$id"} = undef;
73 $store{"playerip_byid_$id"} = undef;
74 $store{"playerslot_byid_$id"} = undef;
75 $store{"playerid_byslot_$slot"} = undef;
79 # Add some functionality that should clear 'ghost' clients that disconnect at unfortunate times
80 [ dp => q{:end} => sub {
81 return 0 unless (time() - $store{map_starttime} > 180); # make sure the map has been played at least 3 minutes
83 my $pj = $store{plugin_joinsparts};
84 for (1 .. $store{slots_max}) {
85 if ($store{"playerid_byslot_$_"} && !$pj->{alive_check}->[$_]) {
86 my $id = $store{"playerid_byslot_$_"};
87 $store{"playernickraw_byid_$id"} = undef;
88 $store{"playernick_byid_$id"} = undef;
89 $store{"playerip_byid_$id"} = undef;
90 $store{"playerslot_byid_$id"} = undef;
91 $store{"playerid_byslot_$_"} = undef;
94 $pj->{alive_check} = ();