libirc.php
changeset 38 e6a4b7f91e91
parent 33 c3179049f670
child 40 1855846cbdab
--- 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'];