# HG changeset patch # User Dan # Date 1230777717 18000 # Node ID e6a4b7f91e91ae849236a78d89d7c19681368ddb # Parent c3cbefda414abe8f905ca0bf73fa99de7fdc2fdf Built de-ghosting code into libirc core diff -r c3cbefda414a -r e6a4b7f91e91 enanobot.php --- a/enanobot.php Tue Dec 30 06:16:54 2008 -0500 +++ b/enanobot.php Wed Dec 31 21:41:57 2008 -0500 @@ -240,9 +240,7 @@ $libirc_channels = array(); // we were able to get back in; ask NickServ to GHOST the old nick - $irc->connect("$nick`gh", $user, $name, false); - $irc->privmsg('NickServ', "GHOST $nick $pass"); - $irc->change_nick($nick, $pass); + $irc->connect($nick, $user, $name, false); foreach ( $channels as $channel ) { diff -r c3cbefda414a -r e6a4b7f91e91 libirc.php --- a/libirc.php Tue Dec 30 06:16:54 2008 -0500 +++ b/libirc.php Wed Dec 31 21:41:57 2008 -0500 @@ -132,12 +132,20 @@ $this->put("NICK $nick\r\n"); $this->put("USER $username 0 * :$realname\r\n"); + $need_deghost = false; + // wait for a mode +i or end of the motd while ( true ) { $msg = $this->get(); if ( empty($msg) ) continue; + if ( strstr($msg, "433") ) + { + // nick already in use - try to ghost + $this->change_nick("{$nick}|de-ghosting"); + $need_deghost = true; + } if ( ( strstr($msg, 'MODE') && strstr($msg, '+i') ) || strstr(strtolower($msg), 'end of /motd') ) { break; @@ -148,6 +156,17 @@ } } + if ( $need_deghost ) + { + $this->privmsg('NickServ', "GHOST $nick $pass"); + while ( $msg = $this->get(10) ) + { + if ( stristr($msg, 'nickserv') && stristr($msg, 'ghost') ) + break; + } + $this->change_nick($nick); + } + // identify to nickserv if ( $pass ) $this->privmsg('NickServ', "IDENTIFY $pass"); @@ -304,6 +323,11 @@ } else if ( $match ) { + if ( $match['action'] == 'KILL' ) + { + // be ethical here and die + return 'killed'; + } // Received PRIVMSG or other mainstream action if ( $match['action'] == 'JOIN' || $match['action'] == 'PART' ) $channel =& $match['message'];