r5256 - trunk/Docs/server/rcon2irc

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Thu Dec 18 01:57:52 EST 2008


Author: div0
Date: 2008-12-18 01:57:51 -0500 (Thu, 18 Dec 2008)
New Revision: 5256

Modified:
   trunk/Docs/server/rcon2irc/rcon2irc.pl
Log:
add support for managing bans


Modified: trunk/Docs/server/rcon2irc/rcon2irc.pl
===================================================================
--- trunk/Docs/server/rcon2irc/rcon2irc.pl	2008-12-18 06:38:58 UTC (rev 5255)
+++ trunk/Docs/server/rcon2irc/rcon2irc.pl	2008-12-18 06:57:51 UTC (rev 5256)
@@ -722,7 +722,7 @@
 		$store{irc_nick} = "";
 		schedule sub {
 			my ($timer) = @_;
-			out dp => 0, 'status 1', 'log_dest_udp';
+			out dp => 0, 'sv_cmd bans', 'status 1', 'log_dest_udp';
 			$store{status_waiting} = -1;
 		} => 1;
 		# this will clear irc_error_active
@@ -867,11 +867,21 @@
 		return 0;
 	} ],
 
+	# retrieve list of banned hosts
+	[ dp => q{#(\d+): (\S+) is still banned for (\S+) seconds} => sub {
+		return 0 unless $store{status_waiting} < 0;
+		my ($id, $ip, $time) = @_;
+		$store{bans_new} = [] if $id == 0;
+		$store{bans_new}[$id] = { ip => $ip, 'time' => $time };
+		return 0;
+	} ],
+
 	# retrieve hostname from status replies
 	[ dp => q{host:     (.*)} => sub {
 		return 0 unless $store{status_waiting} < 0;
 		my ($name) = @_;
 		$store{dp_hostname} = $name;
+		$store{bans} = $store{bans_new};
 		return 0;
 	} ],
 
@@ -933,6 +943,7 @@
 		if($command eq "login $config{irc_admin_password}")
 		{
 			$store{logins}{$hostmask} = time() + $config{irc_admin_timeout};
+			out irc => 0, "PRIVMSG $nick :my wish is your command";
 			return -1;
 		}
 
@@ -951,18 +962,33 @@
 		if($command =~ /^status(?: (.*))?$/)
 		{
 			my ($match) = $1;
+			my $found = 0;
+			my $foundany = 0;
 			for my $slot(@{$store{playerslots_active}})
 			{
 				my $s = $store{"playerslot_$slot"};
 				if(not defined $match or index(color_dp2none($s->{name}), $match) >= 0)
 				{
-					out irc => 0, sprintf 'PRIVMSG %s :%-21s %2i %4i %8s %4i #%-3u %s', $s->{ip}, $s->{pl}, $s->{ping}, $s->{time}, $s->{frags}, $slot, $s->{name};
+					out irc => 0, sprintf 'PRIVMSG %s :%-21s %2i %4i %8s %4i #%-3u %s', $nick, $s->{ip}, $s->{pl}, $s->{ping}, $s->{time}, $s->{frags}, $slot, color_dp2irc $s->{name};
+					++$found;
 				}
+				++$foundany;
 			}
+			if(!$found)
+			{
+				if(!$foundany)
+				{
+					out irc => 0, "PRIVMSG $nick :the server is empty";
+				}
+				else
+				{
+					out irc => 0, "PRIVMSG $nick :no nicknames match";
+				}
+			}
 			return 0;
 		}
 
-		if($command =~ /^kick (\d+) (.*)$/)
+		if($command =~ /^kick # (\d+) (.*)$/)
 		{
 			my ($id, $reason) = ($1, $2);
 			my $dpreason = color_irc2dp $reason;
@@ -974,7 +1000,7 @@
 			return 0;
 		}
 
-		if($command =~ /^kickban (\d+) (\d+) (\d+) (.*)$/)
+		if($command =~ /^kickban # (\d+) (\d+) (\d+) (.*)$/)
 		{
 			my ($id, $bantime, $mask, $reason) = ($1, $2, $3, $4);
 			my $dpreason = color_irc2dp $reason;
@@ -986,8 +1012,28 @@
 			return 0;
 		}
 
-		out irc => 0, "PRIVMSG $nick :unknown command";
+		if($command eq "bans")
+		{
+			my $banlist =
+				join ", ",
+				map { "$_ ($store{bans}[$_]{ip}, $store{bans}[$_]{time}s)" }
+				0..@{$store{bans} || []}-1;
+			$banlist = "no bans"
+				if $banlist eq "";
+			out irc => 0, "PRIVMSG $nick :$banlist";
+			return 0;
+		}
 
+		if($command eq "unban")
+		{
+			my ($id) = ($1);
+			out dp => 0, "unban $id";
+			out irc => 0, "PRIVMSG $nick :removed ban #$id ($store{bans}[$id])";
+			return 0;
+		}
+
+		out irc => 0, "PRIVMSG $nick :unknown command (supported: status [substring], kick # id, kickban # id bantime mask reason, bans, unban banid)";
+
 		return -1;
 	} ],
 
@@ -1386,7 +1432,7 @@
 # not containing our own IP:port, or by rcon2irc_eval not being a defined command).
 schedule sub {
 	my ($timer) = @_;
-	out dp => 0, 'status 1', 'log_dest_udp', 'rcon2irc_eval set dummy 1';
+	out dp => 0, 'sv_cmd bans', 'status 1', 'log_dest_udp', 'rcon2irc_eval set dummy 1';
 	$store{status_waiting} = -1;
 	schedule $timer => (exists $store{dp_hostname} ? $config{dp_status_delay} : 1);;
 } => 1;




More information about the nexuiz-commits mailing list