[nexuiz-commits] r8470 - trunk/server/rcon2irc

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Jan 2 10:28:50 EST 2010


Author: fruitiex
Date: 2010-01-02 10:28:50 -0500 (Sat, 02 Jan 2010)
New Revision: 8470

Added:
   trunk/server/rcon2irc/rename.pl
Modified:
   trunk/server/rcon2irc/joinsparts.pl
Log:
rcon2irc plugin update by merlijn


Modified: trunk/server/rcon2irc/joinsparts.pl
===================================================================
--- trunk/server/rcon2irc/joinsparts.pl	2010-01-01 13:28:54 UTC (rev 8469)
+++ trunk/server/rcon2irc/joinsparts.pl	2010-01-02 15:28:50 UTC (rev 8470)
@@ -2,16 +2,26 @@
 # 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($$@);
 
 sub get_player_count
@@ -23,28 +33,37 @@
 	}
 	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 @@
 	$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;
+} ],

Added: trunk/server/rcon2irc/rename.pl
===================================================================
--- trunk/server/rcon2irc/rename.pl	                        (rev 0)
+++ trunk/server/rcon2irc/rename.pl	2010-01-02 15:28:50 UTC (rev 8470)
@@ -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;
+} ],



More information about the nexuiz-commits mailing list