r5818 - trunk/server/rcon2irc

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Feb 10 01:05:57 EST 2009


Author: div0
Date: 2009-02-10 01:05:56 -0500 (Tue, 10 Feb 2009)
New Revision: 5818

Modified:
   trunk/server/rcon2irc/rcon2irc-example.conf
   trunk/server/rcon2irc/rcon2irc.pl
Log:
irc_nick_alternates;
fix name change bug


Modified: trunk/server/rcon2irc/rcon2irc-example.conf
===================================================================
--- trunk/server/rcon2irc/rcon2irc-example.conf	2009-02-10 00:38:00 UTC (rev 5817)
+++ trunk/server/rcon2irc/rcon2irc-example.conf	2009-02-10 06:05:56 UTC (rev 5818)
@@ -5,6 +5,7 @@
 # IRC configuration
 irc_server = irc.oftc.net
 irc_nick = testNex
+irc_nick_alternates = testNex_ testNex__
 irc_user = banme
 irc_channel = #Nexuiz-Pwayers
 

Modified: trunk/server/rcon2irc/rcon2irc.pl
===================================================================
--- trunk/server/rcon2irc/rcon2irc.pl	2009-02-10 00:38:00 UTC (rev 5817)
+++ trunk/server/rcon2irc/rcon2irc.pl	2009-02-10 06:05:56 UTC (rev 5818)
@@ -634,6 +634,7 @@
 our %config = (
 	irc_server => undef,
 	irc_nick => undef,
+	irc_nick_alternates => "",
 	irc_user => undef,
 	irc_channel => undef,
 	irc_ping_delay => 120,
@@ -817,6 +818,18 @@
 	return 0;
 }
 
+sub uniq(@)
+{
+	my @out = ();
+	my %found = ();
+	for(@_)
+	{
+		next if $found{$_}++;
+		push @out, $_;
+	}
+	return @out;
+}
+
 # IRC joining (if this is called as response to a nick name collision, $is433 is set);
 # among other stuff, it performs NickServ or Quakenet authentication. This is to be called
 # until the channel has been joined for every message that may be "interesting" (basically,
@@ -856,14 +869,36 @@
 		{
 			# we failed to get an initial nickname
 			# change ours a bit and try again
-			if(length $store{irc_nick_requested} < 9)
+
+			my @alternates = ($config{irc_nick}, grep { $_ ne "" } split /\s+/, $config{irc_nick_alternates});
+			my $nextnick = undef;
+			for(0.. at alternates-2)
 			{
-				$store{irc_nick_requested} .= '_';
+				if($store{irc_nick_requested} eq $alternates[$_])
+				{
+					$nextnick = $alternates[$_+1];
+				}
 			}
-			else
+			if($store{irc_nick_requested} eq $alternates[@alternates-1])
 			{
-				substr $store{irc_nick_requested}, int(rand length $store{irc_nick_requested}), 1, chr(97 + int rand 26);
+				$store{irc_nick_requested} = $alternates[0];
+				# but don't set nextnick, so we edit it
 			}
+			if(not defined $nextnick)
+			{
+				for(;;)
+				{
+					if(length $store{irc_nick_requested} < 9)
+					{
+						$store{irc_nick_requested} .= '_';
+					}
+					else
+					{
+						substr $store{irc_nick_requested}, int(rand length $store{irc_nick_requested}), 1, chr(97 + int rand 26);
+					}
+					last unless grep { $_ eq $store{irc_nick_requested} } @alternates;
+				}
+			}
 			out irc => 1, "NICK $store{irc_nick_requested}";
 			return; # when it fails, we'll get here again, and when it succeeds, we will continue
 		}




More information about the nexuiz-commits mailing list