From 9418634ff820b6b38b09bdc811b134302b61dba3 Mon Sep 17 00:00:00 2001 From: fruitiex Date: Sat, 2 Jan 2010 15:28:50 +0000 Subject: [PATCH] rcon2irc plugin update by merlijn git-svn-id: svn://svn.icculus.org/nexuiz/trunk@8470 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- server/rcon2irc/joinsparts.pl | 53 ++++++++++++++++++++++++++++++----- server/rcon2irc/rename.pl | 18 ++++++++++++ 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 server/rcon2irc/rename.pl diff --git a/server/rcon2irc/joinsparts.pl b/server/rcon2irc/joinsparts.pl index 886134761..e842f5f19 100644 --- a/server/rcon2irc/joinsparts.pl +++ b/server/rcon2irc/joinsparts.pl @@ -2,15 +2,25 @@ # Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins. # Don't forget to edit the options below to suit your needs. -my %pj = ( +{ my %pj = ( irc_announce_joins => 1, irc_announce_parts => 1, irc_show_playerip => 0, irc_show_mapname => 0, - irc_show_amount_of_players => 0 + irc_show_amount_of_players => 0, + irc_show_country => 0 ); -$store{plugin_joinsparts} = \%pj; +# current code has been tested against version 0.8 of the Geo::IPfree module +# You can obtain a copy here: http://search.cpan.org/~bricas/Geo-IPfree-0.8/lib/Geo/IPfree.pm +# Place the 'Geo' dir in the same directory as this plugin or anywhere in @INC. +if ($pj{irc_show_country}) { + use Geo::IPfree; + $pj{geo} = Geo::IPfree->new; + $pj{geo}->Faster; # Due to a relatively large amount of lookups, this is probably a good idea +} + +$store{plugin_joinsparts} = \%pj; } sub out($$@); @@ -23,28 +33,37 @@ sub get_player_count } return $count; } - -# chat: Nexuiz server -> IRC channel, nick set +# Catch joins and display requested info [ dp => q{:join:(\d+):(\d+):([^:]*):(.*)} => sub { my ($id, $slot, $ip, $nick) = @_; my $pj = $store{plugin_joinsparts}; - $store{"playernickraw_byid_$id"} = $nick; + $pj->{alive_check}->[$slot] = 1; + + my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot'); + $nick = color_dp2irc $nick; if ($pj->{irc_announce_joins} && !$store{"playerid_byslot_$slot"} && $ip ne 'bot') { out irc => 0, "PRIVMSG $config{irc_channel} :\00309+ join\017: $nick\017" . ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') . + ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017" : '') . ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') . ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()+1) . "\017/$store{slots_max}" : ''); } return 0; } ], + # Record parts so the info in $store is always up to date [ dp => q{:part:(\d+)} => sub { my ($id) = @_; my $pj = $store{plugin_joinsparts}; + + my $ip = $store{"playerip_byid_$id"}; + my ($cn) = $pj->{geo}->LookUp($ip) if ($pj->{irc_show_country} && $ip ne 'bot'); + if ($pj->{irc_announce_parts} && defined $store{"playernick_byid_$id"} && $store{"playerip_byid_$id"} ne 'bot') { out irc => 0, "PRIVMSG $config{irc_channel} :\00304- part\017: " . $store{"playernick_byid_$id"} . "\017" . - ($pj->{irc_show_playerip} ? " (\00304" . $store{"playerip_byid_$id"} . "\017)" : '') . + ($pj->{irc_show_playerip} ? " (\00304$ip\017)" : '') . + ($pj->{irc_show_country} && $cn ? " CN: \00304$cn\017": '') . ($pj->{irc_show_mapname} ? " playing on \00304$store{map}\017" : '') . ($pj->{irc_show_amount_of_players} ? " players: \00304" . (get_player_count()-1) . "\017/$store{slots_max}" : ''); } @@ -56,3 +75,23 @@ sub get_player_count $store{"playerid_byslot_$slot"} = undef; return 0; } ], + +# Add some functionality that should clear 'ghost' clients that disconnect at unfortunate times +[ dp => q{:end} => sub { + return 0 unless (time() - $store{map_starttime} > 180); # make sure the map has been played at least 3 minutes + + my $pj = $store{plugin_joinsparts}; + for (1 .. $store{slots_max}) { + if ($store{"playerid_byslot_$_"} && !$pj->{alive_check}->[$_]) { + my $id = $store{"playerid_byslot_$_"}; + $store{"playernickraw_byid_$id"} = undef; + $store{"playernick_byid_$id"} = undef; + $store{"playerip_byid_$id"} = undef; + $store{"playerslot_byid_$id"} = undef; + $store{"playerid_byslot_$_"} = undef; + } + } + $pj->{alive_check} = (); + + return 0; +} ], diff --git a/server/rcon2irc/rename.pl b/server/rcon2irc/rename.pl new file mode 100644 index 000000000..f0b1b20d4 --- /dev/null +++ b/server/rcon2irc/rename.pl @@ -0,0 +1,18 @@ +# Nexuiz rcon2irc plugin by Merlijn Hofstra licensed under GPL - rename.pl +# Place this file inside the same directory as rcon2irc.pl and add the full filename to the plugins. + +sub out($$@); + +[ irc => q{:(([^! ]*)![^ ]*) (?i:PRIVMSG) [^&#%]\S* :(.*)} => sub { + my ($hostmask, $nick, $command) = @_; + + return 0 if (($store{logins}{$hostmask} || 0) < time()); + + if ($command =~ m/^name (\d+) (.*)/i) { + out dp => 0, "prvm_edictset server $1 netname \"$2\""; + + return -1; + } + + return 0; +} ], -- 2.39.2