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.
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,
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}) {
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, $@";
27 $store{plugin_joinsparts} = \%pj; }
34 for (1 .. $store{slots_max}) {
35 my $id = $store{"playerid_byslot_$_"};
36 $count++ if (defined $id && $store{"playerip_byid_$id"} ne 'bot');
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;
46 return 0 if ($ip eq 'bot');
48 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country});
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";
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}" : '');
72 # Record parts so the info in $store is always up to date
73 [ dp => q{:part:(\d+)} => sub {
75 my $pj = $store{plugin_joinsparts};
77 my $ip = $store{"playerip_byid_$id"};
78 my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot');
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}" : '');
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;
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
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;
111 $pj->{alive_check} = ();