irc_nick_alternates;
authordiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Tue, 10 Feb 2009 06:05:56 +0000 (06:05 +0000)
committerdiv0 <div0@f962a42d-fe04-0410-a3ab-8c8b0445ebaa>
Tue, 10 Feb 2009 06:05:56 +0000 (06:05 +0000)
fix name change bug

git-svn-id: svn://svn.icculus.org/nexuiz/trunk@5818 f962a42d-fe04-0410-a3ab-8c8b0445ebaa

server/rcon2irc/rcon2irc-example.conf
server/rcon2irc/rcon2irc.pl

index 6624912..78510f5 100644 (file)
@@ -5,6 +5,7 @@ dp_password = hackme
 # IRC configuration
 irc_server = irc.oftc.net
 irc_nick = testNex
+irc_nick_alternates = testNex_ testNex__
 irc_user = banme
 irc_channel = #Nexuiz-Pwayers
 
index a7711d5..d166fe4 100755 (executable)
@@ -634,6 +634,7 @@ our %store = (
 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 @@ sub irc_error()
        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,13 +869,35 @@ sub irc_joinstage($)
                {
                        # 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..@alternates-2)
+                       {
+                               if($store{irc_nick_requested} eq $alternates[$_])
+                               {
+                                       $nextnick = $alternates[$_+1];
+                               }
+                       }
+                       if($store{irc_nick_requested} eq $alternates[@alternates-1])
                        {
-                               $store{irc_nick_requested} .= '_';
+                               $store{irc_nick_requested} = $alternates[0];
+                               # but don't set nextnick, so we edit it
                        }
-                       else
+                       if(not defined $nextnick)
                        {
-                               substr $store{irc_nick_requested}, int(rand length $store{irc_nick_requested}), 1, chr(97 + int rand 26);
+                               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