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}) {
20 $pj{geo} = Geo::IPfree->new;
21 $pj{geo}->Faster; # Due to a relatively large amount of lookups, this is probably a good idea
22 } or die "joinsparts.pl: requested countrynames, but can't load data, $@";
25 $store{plugin_joinsparts} = \%pj; }
32 for (1 .. $store{slots_max}) {
33 my $id = $store{"playerid_byslot_$_"};
34 $count++ if (defined $id && $store{"playerip_byid_$id"} ne 'bot');
38 # Catch joins and display requested info
39 [ dp => q{:join:(\d+):(\d+):([^:]*):(.*)} => sub {
40 my ($id, $slot, $ip, $nick) = @_;
41 my $pj = $store{plugin_joinsparts};
42 $pj->{alive_check}->[$slot] = 1;
44 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
46 $nick = color_dp2irc $nick;
47 if ($pj->{irc_announce_joins} && !$store{"playerid_byslot_$slot"} && $ip ne 'bot') {
48 out irc => 0, "PRIVMSG $config{irc_channel} :\00309+ join\017: $nick\017" .
49 ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
50 ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017" : '') .
51 ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
52 ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()+1) . "\017/$store{slots_max}" : '');
57 # Record parts so the info in $store is always up to date
58 [ dp => q{:part:(\d+)} => sub {
60 my $pj = $store{plugin_joinsparts};
62 my $ip = $store{"playerip_byid_$id"};
63 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
65 if ($pj->{irc_announce_parts} && defined $store{"playernick_byid_$id"} && $store{"playerip_byid_$id"} ne 'bot') {
66 out irc => 0, "PRIVMSG $config{irc_channel} :\00304- part\017: " . $store{"playernick_byid_$id"} . "\017" .
67 ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') .
68 ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017": '') .
69 ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') .
70 ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()-1) . "\017/$store{slots_max}" : '');
72 my $slot = $store{"playerslot_byid_$id"};
73 $store{"playernickraw_byid_$id"} = undef;
74 $store{"playernick_byid_$id"} = undef;
75 $store{"playerip_byid_$id"} = undef;
76 $store{"playerslot_byid_$id"} = undef;
77 $store{"playerid_byslot_$slot"} = undef;
81 # Add some functionality that should clear 'ghost' clients that disconnect at unfortunate times
82 [ dp => q{:end} => sub {
83 return 0 unless (time() - $store{map_starttime} > 180); # make sure the map has been played at least 3 minutes
85 my $pj = $store{plugin_joinsparts};
86 for (1 .. $store{slots_max}) {
87 if ($store{"playerid_byslot_$_"} && !$pj->{alive_check}->[$_]) {
88 my $id = $store{"playerid_byslot_$_"};
89 $store{"playernickraw_byid_$id"} = undef;
90 $store{"playernick_byid_$id"} = undef;
91 $store{"playerip_byid_$id"} = undef;
92 $store{"playerslot_byid_$id"} = undef;
93 $store{"playerid_byslot_$_"} = undef;
96 $pj->{alive_check} = ();