From c3dd2bf8e78ed4424953a410fd647ad4336a91f3 Mon Sep 17 00:00:00 2001 From: div0 Date: Tue, 10 Feb 2009 06:05:56 +0000 Subject: [PATCH] irc_nick_alternates; fix name change bug git-svn-id: svn://svn.icculus.org/nexuiz/trunk@5818 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- server/rcon2irc/rcon2irc-example.conf | 1 + server/rcon2irc/rcon2irc.pl | 43 ++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/server/rcon2irc/rcon2irc-example.conf b/server/rcon2irc/rcon2irc-example.conf index 66249121b..78510f581 100644 --- a/server/rcon2irc/rcon2irc-example.conf +++ b/server/rcon2irc/rcon2irc-example.conf @@ -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 diff --git a/server/rcon2irc/rcon2irc.pl b/server/rcon2irc/rcon2irc.pl index a7711d593..d166fe4b2 100755 --- a/server/rcon2irc/rcon2irc.pl +++ b/server/rcon2irc/rcon2irc.pl @@ -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 -- 2.39.2