Built de-ghosting code into libirc core
authorDan
Wed, 31 Dec 2008 21:41:57 -0500
changeset 38 e6a4b7f91e91
parent 37 c3cbefda414a
child 39 4027a5b47db5
Built de-ghosting code into libirc core
enanobot.php
libirc.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 )
   {
--- 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'];