]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merged in changes to phpmsnclass
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sat, 12 Jun 2010 20:19:08 +0000 (21:19 +0100)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sat, 12 Jun 2010 20:19:08 +0000 (21:19 +0100)
plugins/Msn/extlib/phpmsnclass/msn.class.php

index c387bbeae9958e88fd22175551e8f325de6cd038..030cc5dc046ab7fb11227f726a1165660775106b 100644 (file)
@@ -60,6 +60,7 @@ class MSN {
     private $ABAuthHeader;\r
     private $ABService;\r
     private $Contacts;\r
+    private $IgnoreList;\r
 \r
     public $server = 'messenger.hotmail.com';\r
     public $port = 1863;\r
@@ -107,18 +108,6 @@ class MSN {
     // for YIM: 518 bytes\r
     public $max_msn_message_len = 1664;\r
     public $max_yahoo_message_len = 518;\r
-    \r
-    // Begin added for StatusNet\r
-    \r
-    private $aContactList = array();\r
-    private $switchBoardSessions = array();\r
-    \r
-    /** \r
-     * Event Handler Functions\r
-     */\r
-    private $myEventHandlers = array();\r
-    \r
-    // End added for StatusNet\r
 \r
     private function Array2SoapVar($Array,$ReturnSoapVarObj=true,$TypeName=null,$TypeNameSpace=null)\r
     {\r
@@ -158,6 +147,15 @@ class MSN {
         $this->log_message("*** someone kill me ***");\r
         $this->kill_me=true;\r
     }\r
+    private function IsIgnoreMail($Email)\r
+    {        \r
+        if($this->IgnoreList==false) return false;\r
+        foreach($this->IgnoreList as $Pattern)\r
+        {\r
+            if(preg_match($Pattern,$Email)) return true;\r
+        }\r
+        return false;\r
+    }\r
     public function __construct ($Configs=array(), $timeout = 15, $client_id = 0x7000800C)\r
     {\r
         $this->user = $Configs['user'];\r
@@ -171,6 +169,7 @@ class MSN {
         $this->backup_file = isset($Configs['backup_file']) ? $Configs['backup_file'] : true;\r
         $this->update_pending = isset($Configs['update_pending']) ? $Configs['update_pending'] : true;\r
         $this->PhotoStickerFile=$Configs['PhotoSticker'];\r
+        $this->IgnoreList=isset($Configs['IgnoreList'])?$Configs['IgnoreList']:false;\r
         if($this->Emotions = isset($Configs['Emotions']) ? $Configs['Emotions']:false)\r
         {\r
             foreach($this->Emotions as $EmotionFilePath)\r
@@ -532,99 +531,6 @@ class MSN {
         }\r
         $this->UpdateContacts();\r
         return true;\r
-\r
-\r
-        $ABContactAdd=new SoapParam($this->Array2SoapVar($ABContactAddArray),'ABContactAdd');\r
-\r
-        // add contact for WLM\r
-        $ticket = htmlspecialchars($this->ticket['contact_ticket']);\r
-        $displayName = htmlspecialchars($display);\r
-        $user = $email;\r
-\r
-        $XML = '<?xml version="1.0" encoding="utf-8"?>\r
-<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"\r
-               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\r
-               xmlns:xsd="http://www.w3.org/2001/XMLSchema"\r
-               xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">\r
-<soap:Header>\r
-    <ABApplicationHeader xmlns="http://www.msn.com/webservices/AddressBook">\r
-        <ApplicationId>CFE80F9D-180F-4399-82AB-413F33A1FA11</ApplicationId>\r
-        <IsMigration>false</IsMigration>\r
-        <PartnerScenario>ContactSave</PartnerScenario>\r
-    </ABApplicationHeader>\r
-    <ABAuthHeader xmlns="http://www.msn.com/webservices/AddressBook">\r
-        <ManagedGroupRequest>false</ManagedGroupRequest>\r
-        <TicketToken>'.$ticket.'</TicketToken>\r
-    </ABAuthHeader>\r
-</soap:Header>\r
-<soap:Body>\r
-    <ABContactAdd xmlns="http://www.msn.com/webservices/AddressBook">\r
-        <abId>00000000-0000-0000-0000-000000000000</abId>\r
-        <contacts>\r
-            <Contact xmlns="http://www.msn.com/webservices/AddressBook">\r
-                <contactInfo>\r
-                    <contactType>LivePending</contactType>\r
-                    <passportName>'.$user.'</passportName>\r
-                    <isMessengerUser>true</isMessengerUser>\r
-                    <MessengerMemberInfo>\r
-                        <DisplayName>'.$displayName.'</DisplayName>\r
-                    </MessengerMemberInfo>\r
-                </contactInfo>\r
-            </Contact>\r
-        </contacts>\r
-        <options>\r
-            <EnableAllowListManagement>true</EnableAllowListManagement>\r
-        </options>\r
-    </ABContactAdd>\r
-</soap:Body>\r
-</soap:Envelope>';\r
-\r
-        $header_array = array(\r
-            'SOAPAction: '.$this->addcontact_soap,\r
-            'Content-Type: text/xml; charset=utf-8',\r
-            'User-Agent: MSN Explorer/9.0 (MSN 8.0; TmstmpExt)'\r
-            );\r
-\r
-            $this->debug_message("*** URL: $this->addcontact_url");\r
-            $this->debug_message("*** Sending SOAP:\n$XML");\r
-            $curl = curl_init();\r
-            curl_setopt($curl, CURLOPT_URL, $this->addcontact_url);\r
-            curl_setopt($curl, CURLOPT_HTTPHEADER, $header_array);\r
-            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);\r
-            curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);\r
-            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);\r
-            if ($this->debug) curl_setopt($curl, CURLOPT_HEADER, 1);\r
-            curl_setopt($curl, CURLOPT_POST, 1);\r
-            curl_setopt($curl, CURLOPT_POSTFIELDS, $XML);\r
-            $data = curl_exec($curl);\r
-            $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);\r
-            curl_close($curl);\r
-            $this->debug_message("*** Get Result:\n$data");\r
-\r
-            if ($http_code != 200) {\r
-                preg_match('#<faultcode>(.*)</faultcode><faultstring>(.*)</faultstring>#', $data, $matches);\r
-                if (count($matches) == 0) {\r
-                    $this->log_message("*** can't add contact (network: $network) $email");\r
-                    return false;\r
-                }\r
-                $faultcode = trim($matches[1]);\r
-                $faultstring = trim($matches[2]);\r
-                $this->log_message("*** can't add contact (network: $network) $email, error code: $faultcode, $faultstring");\r
-                return false;\r
-            }\r
-            $this->log_message("*** add contact (network: $network) $email");\r
-            if ($sendADL && !feof($this->NSfp)) {\r
-                @list($u_name, $u_domain) = @explode('@', $email);\r
-                foreach (array('1', '2') as $l) {\r
-                    $str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="'.$l.'" t="'.$network.'" /></d></ml>';\r
-                    $len = strlen($str);\r
-                    // NS: >>> ADL {id} {size}\r
-                    $this->ns_writeln("ADL $this->id $len");\r
-                    $this->ns_writedata($str);\r
-                }\r
-            }\r
-            $this->UpdateContacts();\r
-            return true;\r
     }\r
 \r
     function delMemberFromList($memberID, $email, $network, $list) {\r
@@ -934,7 +840,7 @@ class MSN {
             $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);\r
             curl_close($curl);\r
             $this->debug_message("*** Get Result:\n$data");\r
-            if(($http_code != 200)||(!$returnData)) return array();\r
+            if($http_code != 200) return array();\r
             $p = $data;\r
             $aMemberships = array();\r
             while (1) {\r
@@ -1562,7 +1468,7 @@ class MSN {
                 $start_tm = time();\r
                 $ping_tm = time();\r
                 stream_set_timeout($this->NSfp, $this->NSStreamTimeout);\r
-                    $aContactList = $this->getMembershipList(true);\r
+                    $aContactList = $this->getMembershipList();\r
                     if ($this->update_pending) {\r
                         if (is_array($aContactList)) {\r
                             $pending = 'Pending';\r
@@ -2102,6 +2008,11 @@ class MSN {
                     $this->log_message("NS: <<< RNG $data");\r
                     @list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data);\r
                     @list($sb_ip, $sb_port) = @explode(':', $server);\r
+                    if($this->IsIgnoreMail($email)) \r
+                    {\r
+                     $this->log_message("*** Ignore RNG from $email");\r
+                     break;   \r
+                    }\r
                     $this->log_message("*** RING from $email, $sb_ip:$sb_port");\r
                     $this->addContact($email,1,$email, true);\r
                     $pid=pcntl_fork();\r
@@ -2132,7 +2043,7 @@ class MSN {
                     break;\r
 \r
                 default:\r
-                       $code = substr($data,0,3);\r
+                    $code = substr($data,0,3);\r
                     if (is_numeric($code)) {\r
                         $this->error = "Error code: $code, please check the detail information from: http://msnpiki.msnfanatic.com/index.php/Reference:Error_List";\r
                         $this->debug_message("*** NS: $this->error");\r
@@ -2329,7 +2240,7 @@ class MSN {
                     $this->SB_writedata($aMessage);\r
                 }\r
                 $this->SwitchBoardMessageQueue=array();\r
-                $LastActive=time();\r
+                if(!$this->IsIgnoreMail($user)) $LastActive = time();\r
                 continue;\r
             }\r
             $code = substr($data, 0, 3);\r
@@ -2725,7 +2636,7 @@ class MSN {
                     }\r
                     break;\r
             }\r
-            $LastActive = time();\r
+            if(!$this->IsIgnoreMail($user)) $LastActive = time();\r
         }\r
         if (feof($this->SBFp))\r
         {\r
@@ -3089,7 +3000,7 @@ X-OIM-Sequence-Num: 1
         $start_tm = time();\r
         $ping_tm = time();\r
         stream_set_timeout($this->NSfp, $this->NSStreamTimeout);\r
-        $this->aContactList = $this->getMembershipList(true);\r
+        $this->aContactList = $this->getMembershipList();\r
         if ($this->update_pending) {\r
             if (is_array($this->aContactList)) {\r
                 $pending = 'Pending';\r
@@ -3182,7 +3093,7 @@ X-OIM-Sequence-Num: 1
         // NS: >>> CHG {id} {status} {clientid} {msnobj}\r
         $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
         if($this->PhotoStickerFile!==false)\r
-        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+            $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
         // NS: >>> UUX {id} length\r
         $str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>';\r
         $len = strlen($str);\r
@@ -3201,477 +3112,465 @@ X-OIM-Sequence-Num: 1
         }\r
         \r
         $data = $this->ns_readln();\r
-        /*if($data===false)\r
-        {\r
-            if(count($this->ChildProcess)<$this->MAXChildProcess)\r
+        if($data === false) {\r
+            // There was no data / an error when reading from the socket so reconnect\r
+            $this->signon();\r
+        } else {\r
+            switch (substr($data,0,3))\r
             {\r
-                $Index=0;\r
-                foreach($this->MessageQueue as $User => $Message)\r
-                {\r
-                    if(!trim($User)) continue;\r
-                    if($Inxdex>=$this->MAXChildProcess-count($this->ChildProcess)) break;\r
-                    if((!$Message['XFRSent'])||($Message['XFRSent']&&(time()-$this->MessageQueue[$User]['ReqTime']>$this->ReqSBXFRTimeout)))\r
-                    {\r
-                        $this->MessageQueue[$User]['XFRSent']=true;\r
-                        $this->MessageQueue[$User]['ReqTime']=time();\r
-                        $this->log_message("*** Request SB for $User");\r
-                        $this->ns_writeln("XFR $this->id SB");\r
-                        $Index++;\r
+                case 'SBS':\r
+                    // after 'USR {id} OK {user} {verify} 0' response, the server will send SBS and profile to us\r
+                    // NS: <<< SBS 0 null\r
+                    break;\r
+    \r
+                case 'RFS':\r
+                    // FIXME:\r
+                    // NS: <<< RFS ???\r
+                    // refresh ADL, so we re-send it again\r
+                    if (is_array($aADL)) {\r
+                        foreach ($aADL as $str) {\r
+                            $len = strlen($str);\r
+                            // NS: >>> ADL {id} {size}\r
+                            $this->ns_writeln("ADL $this->id $len");\r
+                            $this->ns_writedata($str);\r
+                        }\r
                     }\r
-                }\r
-            }\r
-            if($this->ProcessSendMessageFileQueue()) continue;\r
-            break;\r
-        }*/\r
-        switch (substr($data,0,3))\r
-        {\r
-            case 'SBS':\r
-                // after 'USR {id} OK {user} {verify} 0' response, the server will send SBS and profile to us\r
-                // NS: <<< SBS 0 null\r
-                break;\r
-\r
-            case 'RFS':\r
-                // FIXME:\r
-                // NS: <<< RFS ???\r
-                // refresh ADL, so we re-send it again\r
-                if (is_array($aADL)) {\r
-                    foreach ($aADL as $str) {\r
-                        $len = strlen($str);\r
-                        // NS: >>> ADL {id} {size}\r
-                        $this->ns_writeln("ADL $this->id $len");\r
-                        $this->ns_writedata($str);\r
+                    break;\r
+    \r
+                case 'LST':\r
+                    // NS: <<< LST {email} {alias} 11 0\r
+                    @list(/* LST */, $email, /* alias */, ) = @explode(' ', $data);\r
+                    @list($u_name, $u_domain) = @explode('@', $email);\r
+                    if (!isset($this->aContactList[$u_domain][$u_name][1])) {\r
+                        $this->aContactList[$u_domain][$u_name][1]['Allow'] = 'Allow';\r
+                        $this->log_message("*** add to our contact list: $u_name@$u_domain");\r
                     }\r
-                }\r
-                break;\r
-\r
-            case 'LST':\r
-                // NS: <<< LST {email} {alias} 11 0\r
-                @list(/* LST */, $email, /* alias */, ) = @explode(' ', $data);\r
-                @list($u_name, $u_domain) = @explode('@', $email);\r
-                if (!isset($this->aContactList[$u_domain][$u_name][1])) {\r
-                    $this->aContactList[$u_domain][$u_name][1]['Allow'] = 'Allow';\r
-                    $this->log_message("*** add to our contact list: $u_name@$u_domain");\r
-                }\r
-                break;\r
-\r
-            case 'ADL':\r
-                // randomly, we get ADL command, someome add us to their contact list for MSNP15\r
-                // NS: <<< ADL 0 {size}\r
-                @list(/* ADL */, /* 0 */, $size,) = @explode(' ', $data);\r
-                if (is_numeric($size) && $size > 0)\r
-                {\r
-                    $data = $this->ns_readdata($size);\r
-                    preg_match('#<ml><d n="([^"]+)"><c n="([^"]+)"(.*) t="(\d*)"(.*) /></d></ml>#', $data, $matches);\r
-                    if (is_array($matches) && count($matches) > 0)\r
+                    break;\r
+    \r
+                case 'ADL':\r
+                    // randomly, we get ADL command, someome add us to their contact list for MSNP15\r
+                    // NS: <<< ADL 0 {size}\r
+                    @list(/* ADL */, /* 0 */, $size,) = @explode(' ', $data);\r
+                    if (is_numeric($size) && $size > 0)\r
                     {\r
-                        $u_domain = $matches[1];\r
-                        $u_name = $matches[2];\r
-                        $network = $matches[4];\r
-                        if (isset($this->aContactList[$u_domain][$u_name][$network]))\r
-                        $this->log_message("*** someone (network: $network) add us to their list (but already in our list): $u_name@$u_domain");\r
-                        else\r
+                        $data = $this->ns_readdata($size);\r
+                        preg_match('#<ml><d n="([^"]+)"><c n="([^"]+)"(.*) t="(\d*)"(.*) /></d></ml>#', $data, $matches);\r
+                        if (is_array($matches) && count($matches) > 0)\r
                         {\r
-                            $re_login = false;\r
-                            $cnt = 0;\r
-                            foreach (array('Allow', 'Reverse') as $list)\r
+                            $u_domain = $matches[1];\r
+                            $u_name = $matches[2];\r
+                            $network = $matches[4];\r
+                            if (isset($this->aContactList[$u_domain][$u_name][$network]))\r
+                            $this->log_message("*** someone (network: $network) add us to their list (but already in our list): $u_name@$u_domain");\r
+                            else\r
                             {\r
-                                if (!$this->addMemberToList($u_name.'@'.$u_domain, $network, $list))\r
+                                $re_login = false;\r
+                                $cnt = 0;\r
+                                foreach (array('Allow', 'Reverse') as $list)\r
                                 {\r
-                                    if ($re_login) {\r
-                                        $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
-                                        continue;\r
-                                    }\r
-                                    $aTickets = $this->get_passport_ticket();\r
-                                    if (!$aTickets || !is_array($aTickets)) {\r
-                                        // failed to login? ignore it\r
-                                        $this->log_message("*** can't re-login, something wrong here");\r
-                                        $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
-                                        continue;\r
-                                    }\r
-                                    $re_login = true;\r
-                                    $this->ticket = $aTickets;\r
-                                    $this->log_message("**** get new ticket, try it again");\r
                                     if (!$this->addMemberToList($u_name.'@'.$u_domain, $network, $list))\r
                                     {\r
-                                        $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
-                                        continue;\r
+                                        if ($re_login) {\r
+                                            $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
+                                            continue;\r
+                                        }\r
+                                        $aTickets = $this->get_passport_ticket();\r
+                                        if (!$aTickets || !is_array($aTickets)) {\r
+                                            // failed to login? ignore it\r
+                                            $this->log_message("*** can't re-login, something wrong here");\r
+                                            $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
+                                            continue;\r
+                                        }\r
+                                        $re_login = true;\r
+                                        $this->ticket = $aTickets;\r
+                                        $this->log_message("**** get new ticket, try it again");\r
+                                        if (!$this->addMemberToList($u_name.'@'.$u_domain, $network, $list))\r
+                                        {\r
+                                            $this->log_message("*** can't add $u_name@$u_domain (network: $network) to $list");\r
+                                            continue;\r
+                                        }\r
                                     }\r
+                                    $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
+                                    $cnt++;\r
                                 }\r
-                                $this->aContactList[$u_domain][$u_name][$network][$list] = false;\r
-                                $cnt++;\r
+                                $this->log_message("*** someone (network: $network) add us to their list: $u_name@$u_domain");\r
                             }\r
-                            $this->log_message("*** someone (network: $network) add us to their list: $u_name@$u_domain");\r
+                            $str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="3" t="'.$network.'" /></d></ml>';\r
+                            $len = strlen($str);\r
                         }\r
-                        $str = '<ml l="1"><d n="'.$u_domain.'"><c n="'.$u_name.'" l="3" t="'.$network.'" /></d></ml>';\r
-                        $len = strlen($str);\r
+                        else\r
+                        $this->log_message("*** someone add us to their list: $data");\r
+                        $this->AddUsToMemberList($u_name.'@'.$u_domain, $network);\r
                     }\r
-                    else\r
-                    $this->log_message("*** someone add us to their list: $data");\r
-                    $this->AddUsToMemberList($u_name.'@'.$u_domain, $network);\r
-                }\r
-                break;\r
-\r
-            case 'RML':\r
-                // randomly, we get RML command, someome remove us to their contact list for MSNP15\r
-                // NS: <<< RML 0 {size}\r
-                @list(/* RML */, /* 0 */, $size,) = @explode(' ', $data);\r
-                if (is_numeric($size) && $size > 0)\r
-                {\r
-                    $data = $this->ns_readdata($size);\r
-                    preg_match('#<ml><d n="([^"]+)"><c n="([^"]+)"(.*) t="(\d*)"(.*) /></d></ml>#', $data, $matches);\r
-                    if (is_array($matches) && count($matches) > 0)\r
+                    break;\r
+    \r
+                case 'RML':\r
+                    // randomly, we get RML command, someome remove us to their contact list for MSNP15\r
+                    // NS: <<< RML 0 {size}\r
+                    @list(/* RML */, /* 0 */, $size,) = @explode(' ', $data);\r
+                    if (is_numeric($size) && $size > 0)\r
                     {\r
-                        $u_domain = $matches[1];\r
-                        $u_name = $matches[2];\r
-                        $network = $matches[4];\r
-                        if (isset($this->aContactList[$u_domain][$u_name][$network]))\r
+                        $data = $this->ns_readdata($size);\r
+                        preg_match('#<ml><d n="([^"]+)"><c n="([^"]+)"(.*) t="(\d*)"(.*) /></d></ml>#', $data, $matches);\r
+                        if (is_array($matches) && count($matches) > 0)\r
                         {\r
-                            $aData = $this->aContactList[$u_domain][$u_name][$network];\r
-                            foreach ($aData as $list => $id)\r
-                            $this->delMemberFromList($id, $u_name.'@'.$u_domain, $network, $list);\r
-                            unset($this->aContactList[$u_domain][$u_name][$network]);\r
-                            $this->log_message("*** someone (network: $network) remove us from their list: $u_name@$u_domain");\r
+                            $u_domain = $matches[1];\r
+                            $u_name = $matches[2];\r
+                            $network = $matches[4];\r
+                            if (isset($this->aContactList[$u_domain][$u_name][$network]))\r
+                            {\r
+                                $aData = $this->aContactList[$u_domain][$u_name][$network];\r
+                                foreach ($aData as $list => $id)\r
+                                $this->delMemberFromList($id, $u_name.'@'.$u_domain, $network, $list);\r
+                                unset($this->aContactList[$u_domain][$u_name][$network]);\r
+                                $this->log_message("*** someone (network: $network) remove us from their list: $u_name@$u_domain");\r
+                            }\r
+                            else\r
+                            $this->log_message("*** someone (network: $network) remove us from their list (but not in our list): $u_name@$u_domain");\r
+                            $this->RemoveUsFromMemberList($u_name.'@'.$u_domain, $network);\r
                         }\r
                         else\r
-                        $this->log_message("*** someone (network: $network) remove us from their list (but not in our list): $u_name@$u_domain");\r
-                        $this->RemoveUsFromMemberList($u_name.'@'.$u_domain, $network);\r
+                        $this->log_message("*** someone remove us from their list: $data");\r
                     }\r
-                    else\r
-                    $this->log_message("*** someone remove us from their list: $data");\r
-                }\r
-                break;\r
-\r
-            case 'MSG':\r
-                // randomly, we get MSG notification from server\r
-                // NS: <<< MSG Hotmail Hotmail {size}\r
-                @list(/* MSG */, /* Hotmail */, /* Hotmail */, $size,) = @explode(' ', $data);\r
-                if (is_numeric($size) && $size > 0) {\r
-                    $data = $this->ns_readdata($size);\r
-                    $aLines = @explode("\n", $data);\r
-                    $header = true;\r
-                    $ignore = false;\r
-                    $maildata = '';\r
-                    foreach ($aLines as $line) {\r
-                        $line = rtrim($line);\r
-                        if ($header) {\r
-                            if ($line === '') {\r
-                                $header = false;\r
+                    break;\r
+    \r
+                case 'MSG':\r
+                    // randomly, we get MSG notification from server\r
+                    // NS: <<< MSG Hotmail Hotmail {size}\r
+                    @list(/* MSG */, /* Hotmail */, /* Hotmail */, $size,) = @explode(' ', $data);\r
+                    if (is_numeric($size) && $size > 0) {\r
+                        $data = $this->ns_readdata($size);\r
+                        $aLines = @explode("\n", $data);\r
+                        $header = true;\r
+                        $ignore = false;\r
+                        $maildata = '';\r
+                        foreach ($aLines as $line) {\r
+                            $line = rtrim($line);\r
+                            if ($header) {\r
+                                if ($line === '') {\r
+                                    $header = false;\r
+                                    continue;\r
+                                }\r
+                                if (strncasecmp($line, 'Content-Type:', 13) == 0) {\r
+                                    if (strpos($line, 'text/x-msmsgsinitialmdatanotification') === false &&\r
+                                    strpos($line, 'text/x-msmsgsoimnotification') === false) {\r
+                                        // we just need text/x-msmsgsinitialmdatanotification\r
+                                        // or text/x-msmsgsoimnotification\r
+                                        $ignore = true;\r
+                                        break;\r
+                                    }\r
+                                }\r
                                 continue;\r
                             }\r
-                            if (strncasecmp($line, 'Content-Type:', 13) == 0) {\r
-                                if (strpos($line, 'text/x-msmsgsinitialmdatanotification') === false &&\r
-                                strpos($line, 'text/x-msmsgsoimnotification') === false) {\r
-                                    // we just need text/x-msmsgsinitialmdatanotification\r
-                                    // or text/x-msmsgsoimnotification\r
-                                    $ignore = true;\r
-                                    break;\r
-                                }\r
+                            if (strncasecmp($line, 'Mail-Data:', 10) == 0) {\r
+                                $maildata = trim(substr($line, 10));\r
+                                break;\r
                             }\r
-                            continue;\r
                         }\r
-                        if (strncasecmp($line, 'Mail-Data:', 10) == 0) {\r
-                            $maildata = trim(substr($line, 10));\r
+                        if ($ignore) {\r
+                            $this->log_message("*** ingnore MSG for: $line");\r
                             break;\r
                         }\r
-                    }\r
-                    if ($ignore) {\r
-                        $this->log_message("*** ingnore MSG for: $line");\r
-                        break;\r
-                    }\r
-                    if ($maildata == '') {\r
-                        $this->log_message("*** ingnore MSG not for OIM");\r
-                        break;\r
-                    }\r
-                    $re_login = false;\r
-                    if (strcasecmp($maildata, 'too-large') == 0) {\r
-                        $this->log_message("*** large mail-data, need to get the data via SOAP");\r
-                        $maildata = $this->getOIM_maildata();\r
-                        if ($maildata === false) {\r
-                            $this->log_message("*** can't get mail-data via SOAP");\r
-                            // maybe we need to re-login again\r
-                            $aTickets = $this->get_passport_ticket();\r
-                            if (!$aTickets || !is_array($aTickets)) {\r
-                                // failed to login? ignore it\r
-                                $this->log_message("*** can't re-login, something wrong here, ignore this OIM");\r
-                                break;\r
-                            }\r
-                            $re_login = true;\r
-                            $this->ticket = $aTickets;\r
-                            $this->log_message("**** get new ticket, try it again");\r
+                        if ($maildata == '') {\r
+                            $this->log_message("*** ingnore MSG not for OIM");\r
+                            break;\r
+                        }\r
+                        $re_login = false;\r
+                        if (strcasecmp($maildata, 'too-large') == 0) {\r
+                            $this->log_message("*** large mail-data, need to get the data via SOAP");\r
                             $maildata = $this->getOIM_maildata();\r
                             if ($maildata === false) {\r
-                                $this->log_message("*** can't get mail-data via SOAP, and we already re-login again, so ignore this OIM");\r
-                                break;\r
-                            }\r
-                        }\r
-                    }\r
-                    // could be a lots of <M>...</M>, so we can't use preg_match here\r
-                    $p = $maildata;\r
-                    $aOIMs = array();\r
-                    while (1) {\r
-                        $start = strpos($p, '<M>');\r
-                        $end = strpos($p, '</M>');\r
-                        if ($start === false || $end === false || $start > $end) break;\r
-                        $end += 4;\r
-                        $sOIM = substr($p, $start, $end - $start);\r
-                        $aOIMs[] = $sOIM;\r
-                        $p = substr($p, $end);\r
-                    }\r
-                    if (count($aOIMs) == 0) {\r
-                        $this->log_message("*** ingnore empty OIM");\r
-                        break;\r
-                    }\r
-                    foreach ($aOIMs as $maildata) {\r
-                        // T: 11 for MSN, 13 for Yahoo\r
-                        // S: 6 for MSN, 7 for Yahoo\r
-                        // RT: the datetime received by server\r
-                        // RS: already read or not\r
-                        // SZ: size of message\r
-                        // E: sender\r
-                        // I: msgid\r
-                        // F: always 00000000-0000-0000-0000-000000000009\r
-                        // N: sender alias\r
-                        preg_match('#<T>(.*)</T>#', $maildata, $matches);\r
-                        if (count($matches) == 0) {\r
-                            $this->log_message("*** ingnore OIM maildata without <T>type</T>");\r
-                            continue;\r
+                                $this->log_message("*** can't get mail-data via SOAP");\r
+                                // maybe we need to re-login again\r
+                                $aTickets = $this->get_passport_ticket();\r
+                                if (!$aTickets || !is_array($aTickets)) {\r
+                                    // failed to login? ignore it\r
+                                    $this->log_message("*** can't re-login, something wrong here, ignore this OIM");\r
+                                    break;\r
+                                }\r
+                                $re_login = true;\r
+                                $this->ticket = $aTickets;\r
+                                $this->log_message("**** get new ticket, try it again");\r
+                                $maildata = $this->getOIM_maildata();\r
+                                if ($maildata === false) {\r
+                                    $this->log_message("*** can't get mail-data via SOAP, and we already re-login again, so ignore this OIM");\r
+                                    break;\r
+                                }\r
+                            }\r
                         }\r
-                        $oim_type = $matches[1];\r
-                        if ($oim_type = 13)\r
-                        $network = 32;\r
-                        else\r
-                        $network = 1;\r
-                        preg_match('#<E>(.*)</E>#', $maildata, $matches);\r
-                        if (count($matches) == 0) {\r
-                            $this->log_message("*** ingnore OIM maildata without <E>sender</E>");\r
-                            continue;\r
+                        // could be a lots of <M>...</M>, so we can't use preg_match here\r
+                        $p = $maildata;\r
+                        $aOIMs = array();\r
+                        while (1) {\r
+                            $start = strpos($p, '<M>');\r
+                            $end = strpos($p, '</M>');\r
+                            if ($start === false || $end === false || $start > $end) break;\r
+                            $end += 4;\r
+                            $sOIM = substr($p, $start, $end - $start);\r
+                            $aOIMs[] = $sOIM;\r
+                            $p = substr($p, $end);\r
                         }\r
-                        $oim_sender = $matches[1];\r
-                        preg_match('#<I>(.*)</I>#', $maildata, $matches);\r
-                        if (count($matches) == 0) {\r
-                            $this->log_message("*** ingnore OIM maildata without <I>msgid</I>");\r
-                            continue;\r
+                        if (count($aOIMs) == 0) {\r
+                            $this->log_message("*** ingnore empty OIM");\r
+                            break;\r
                         }\r
-                        $oim_msgid = $matches[1];\r
-                        preg_match('#<SZ>(.*)</SZ>#', $maildata, $matches);\r
-                        $oim_size = (count($matches) == 0) ? 0 : $matches[1];\r
-                        preg_match('#<RT>(.*)</RT>#', $maildata, $matches);\r
-                        $oim_time = (count($matches) == 0) ? 0 : $matches[1];\r
-                        $this->log_message("*** You've OIM sent by $oim_sender, Time: $oim_time, MSGID: $oim_msgid, size: $oim_size");\r
-                        $sMsg = $this->getOIM_message($oim_msgid);\r
-                        if ($sMsg === false) {\r
-                            $this->log_message("*** can't get OIM, msgid = $oim_msgid");\r
-                            if ($re_login) {\r
-                                $this->log_message("*** can't get OIM via SOAP, and we already re-login again, so ignore this OIM");\r
+                        foreach ($aOIMs as $maildata) {\r
+                            // T: 11 for MSN, 13 for Yahoo\r
+                            // S: 6 for MSN, 7 for Yahoo\r
+                            // RT: the datetime received by server\r
+                            // RS: already read or not\r
+                            // SZ: size of message\r
+                            // E: sender\r
+                            // I: msgid\r
+                            // F: always 00000000-0000-0000-0000-000000000009\r
+                            // N: sender alias\r
+                            preg_match('#<T>(.*)</T>#', $maildata, $matches);\r
+                            if (count($matches) == 0) {\r
+                                $this->log_message("*** ingnore OIM maildata without <T>type</T>");\r
+                                continue;\r
+                            }\r
+                            $oim_type = $matches[1];\r
+                            if ($oim_type = 13)\r
+                            $network = 32;\r
+                            else\r
+                            $network = 1;\r
+                            preg_match('#<E>(.*)</E>#', $maildata, $matches);\r
+                            if (count($matches) == 0) {\r
+                                $this->log_message("*** ingnore OIM maildata without <E>sender</E>");\r
                                 continue;\r
                             }\r
-                            $aTickets = $this->get_passport_ticket();\r
-                            if (!$aTickets || !is_array($aTickets)) {\r
-                                // failed to login? ignore it\r
-                                $this->log_message("*** can't re-login, something wrong here, ignore this OIM");\r
+                            $oim_sender = $matches[1];\r
+                            preg_match('#<I>(.*)</I>#', $maildata, $matches);\r
+                            if (count($matches) == 0) {\r
+                                $this->log_message("*** ingnore OIM maildata without <I>msgid</I>");\r
                                 continue;\r
                             }\r
-                            $re_login = true;\r
-                            $this->ticket = $aTickets;\r
-                            $this->log_message("**** get new ticket, try it again");\r
+                            $oim_msgid = $matches[1];\r
+                            preg_match('#<SZ>(.*)</SZ>#', $maildata, $matches);\r
+                            $oim_size = (count($matches) == 0) ? 0 : $matches[1];\r
+                            preg_match('#<RT>(.*)</RT>#', $maildata, $matches);\r
+                            $oim_time = (count($matches) == 0) ? 0 : $matches[1];\r
+                            $this->log_message("*** You've OIM sent by $oim_sender, Time: $oim_time, MSGID: $oim_msgid, size: $oim_size");\r
                             $sMsg = $this->getOIM_message($oim_msgid);\r
                             if ($sMsg === false) {\r
-                                $this->log_message("*** can't get OIM via SOAP, and we already re-login again, so ignore this OIM");\r
-                                continue;\r
+                                $this->log_message("*** can't get OIM, msgid = $oim_msgid");\r
+                                if ($re_login) {\r
+                                    $this->log_message("*** can't get OIM via SOAP, and we already re-login again, so ignore this OIM");\r
+                                    continue;\r
+                                }\r
+                                $aTickets = $this->get_passport_ticket();\r
+                                if (!$aTickets || !is_array($aTickets)) {\r
+                                    // failed to login? ignore it\r
+                                    $this->log_message("*** can't re-login, something wrong here, ignore this OIM");\r
+                                    continue;\r
+                                }\r
+                                $re_login = true;\r
+                                $this->ticket = $aTickets;\r
+                                $this->log_message("**** get new ticket, try it again");\r
+                                $sMsg = $this->getOIM_message($oim_msgid);\r
+                                if ($sMsg === false) {\r
+                                    $this->log_message("*** can't get OIM via SOAP, and we already re-login again, so ignore this OIM");\r
+                                    continue;\r
+                                }\r
                             }\r
+                            $this->log_message("*** MSG (Offline) from $oim_sender (network: $network): $sMsg");\r
+    \r
+                            //$this->ReceivedMessage($oim_sender,$sMsg,$network,true);\r
+                            $this->callHandler('IMin', array('sender' => $oim_sender, 'message' => $sMsg, 'network' => $network, 'offline' => true));\r
                         }\r
-                        $this->log_message("*** MSG (Offline) from $oim_sender (network: $network): $sMsg");\r
-\r
-                        //$this->ReceivedMessage($oim_sender,$sMsg,$network,true);\r
-                        $this->callHandler('IMin', array('sender' => $oim_sender, 'message' => $sMsg, 'network' => $network, 'offline' => true));\r
                     }\r
-                }\r
-                break;\r
-\r
-            case 'UBM':\r
-                // randomly, we get UBM, this is the message from other network, like Yahoo!\r
-                // NS: <<< UBM {email} $network $type {size}\r
-                @list(/* UBM */, $from_email, $network, $type, $size,) = @explode(' ', $data);\r
-                if (is_numeric($size) && $size > 0)\r
-                {\r
-                    $data = $this->ns_readdata($size);\r
-                    $aLines = @explode("\n", $data);\r
-                    $header = true;\r
-                    $ignore = false;\r
-                    $sMsg = '';\r
-                    foreach ($aLines as $line) {\r
-                        $line = rtrim($line);\r
-                        if ($header) {\r
-                            if ($line === '') {\r
-                                $header = false;\r
+                    break;\r
+    \r
+                case 'UBM':\r
+                    // randomly, we get UBM, this is the message from other network, like Yahoo!\r
+                    // NS: <<< UBM {email} $network $type {size}\r
+                    @list(/* UBM */, $from_email, $network, $type, $size,) = @explode(' ', $data);\r
+                    if (is_numeric($size) && $size > 0)\r
+                    {\r
+                        $data = $this->ns_readdata($size);\r
+                        $aLines = @explode("\n", $data);\r
+                        $header = true;\r
+                        $ignore = false;\r
+                        $sMsg = '';\r
+                        foreach ($aLines as $line) {\r
+                            $line = rtrim($line);\r
+                            if ($header) {\r
+                                if ($line === '') {\r
+                                    $header = false;\r
+                                    continue;\r
+                                }\r
+                                if (strncasecmp($line, 'TypingUser:', 11) == 0) {\r
+                                    $ignore = true;\r
+                                    break;\r
+                                }\r
                                 continue;\r
                             }\r
-                            if (strncasecmp($line, 'TypingUser:', 11) == 0) {\r
-                                $ignore = true;\r
-                                break;\r
+                            $aSubLines = @explode("\r", $line);\r
+                            foreach ($aSubLines as $str) {\r
+                                if ($sMsg !== '')\r
+                                $sMsg .= "\n";\r
+                                $sMsg .= $str;\r
                             }\r
-                            continue;\r
                         }\r
-                        $aSubLines = @explode("\r", $line);\r
-                        foreach ($aSubLines as $str) {\r
-                            if ($sMsg !== '')\r
-                            $sMsg .= "\n";\r
-                            $sMsg .= $str;\r
+                        if($ignore)\r
+                        {\r
+                            $this->log_message("*** ingnore from $from_email: $line");\r
+                            break;\r
                         }\r
+                        $this->log_message("*** MSG from $from_email (network: $network): $sMsg");\r
+                        //$this->ReceivedMessage($from_email,$sMsg,$network,false);\r
+                        $this->callHandler('IMin', array('sender' => $from_email, 'message' => $sMsg, 'network' => $network, 'offline' => false));\r
                     }\r
-                    if($ignore)\r
-                    {\r
-                        $this->log_message("*** ingnore from $from_email: $line");\r
-                        break;\r
+                    break;\r
+    \r
+                case 'UBX':\r
+                    // randomly, we get UBX notification from server\r
+                    // NS: <<< UBX email {network} {size}\r
+                    @list(/* UBX */, /* email */, /* network */, $size,) = @explode(' ', $data);\r
+                    // we don't need the notification data, so just ignore it\r
+                    if (is_numeric($size) && $size > 0)\r
+                    $this->ns_readdata($size);\r
+                    break;\r
+    \r
+                case 'CHL':\r
+                    // randomly, we'll get challenge from server\r
+                    // NS: <<< CHL 0 {code}\r
+                    @list(/* CHL */, /* 0 */, $chl_code,) = @explode(' ', $data);\r
+                    $fingerprint = $this->getChallenge($chl_code);\r
+                    // NS: >>> QRY {id} {product_id} 32\r
+                    // NS: >>> fingerprint\r
+                    $this->ns_writeln("QRY $this->id $this->prod_id 32");\r
+                    $this->ns_writedata($fingerprint);\r
+                    $this->ns_writeln("CHG $this->id NLN $this->clientid");                    \r
+                    if($this->PhotoStickerFile!==false)\r
+                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                    break;\r
+                case 'CHG':\r
+                    // NS: <<< CHG {id} {status} {code}\r
+                    // ignore it\r
+                    // change our status to online first\r
+                    break;\r
+    \r
+                case 'XFR':\r
+                    // sometimes, NS will redirect to another NS\r
+                    // MSNP9\r
+                    // NS: <<< XFR {id} NS {server} 0 {server}\r
+                    // MSNP15\r
+                    // NS: <<< XFR {id} NS {server} U D\r
+                    // for normal switchboard XFR\r
+                    // NS: <<< XFR {id} SB {server} CKI {cki} U messenger.msn.com 0\r
+                    @list(/* XFR */, /* {id} */, $server_type, $server, /* CKI */, $cki_code, /* ... */) = @explode(' ', $data);\r
+                    @list($ip, $port) = @explode(':', $server);\r
+                    if ($server_type != 'SB') {\r
+                        // maybe exit?\r
+                        // this connection will close after XFR\r
+                        $this->NSLogout();\r
+                        continue;\r
                     }\r
-                    $this->log_message("*** MSG from $from_email (network: $network): $sMsg");\r
-                    //$this->ReceivedMessage($from_email,$sMsg,$network,false);\r
-                    $this->callHandler('IMin', array('sender' => $from_email, 'message' => $sMsg, 'network' => $network, 'offline' => false));\r
-                }\r
-                break;\r
-\r
-            case 'UBX':\r
-                // randomly, we get UBX notification from server\r
-                // NS: <<< UBX email {network} {size}\r
-                @list(/* UBX */, /* email */, /* network */, $size,) = @explode(' ', $data);\r
-                // we don't need the notification data, so just ignore it\r
-                if (is_numeric($size) && $size > 0)\r
-                $this->ns_readdata($size);\r
-                break;\r
-\r
-            case 'CHL':\r
-                // randomly, we'll get challenge from server\r
-                // NS: <<< CHL 0 {code}\r
-                @list(/* CHL */, /* 0 */, $chl_code,) = @explode(' ', $data);\r
-                $fingerprint = $this->getChallenge($chl_code);\r
-                // NS: >>> QRY {id} {product_id} 32\r
-                // NS: >>> fingerprint\r
-                $this->ns_writeln("QRY $this->id $this->prod_id 32");\r
-                $this->ns_writedata($fingerprint);\r
-                $this->ns_writeln("CHG $this->id NLN $this->clientid");                    \r
-                if($this->PhotoStickerFile!==false)\r
-                $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
-                break;\r
-            case 'CHG':\r
-                // NS: <<< CHG {id} {status} {code}\r
-                // ignore it\r
-                // change our status to online first\r
-                break;\r
-\r
-            case 'XFR':\r
-                // sometimes, NS will redirect to another NS\r
-                // MSNP9\r
-                // NS: <<< XFR {id} NS {server} 0 {server}\r
-                // MSNP15\r
-                // NS: <<< XFR {id} NS {server} U D\r
-                // for normal switchboard XFR\r
-                // NS: <<< XFR {id} SB {server} CKI {cki} U messenger.msn.com 0\r
-                @list(/* XFR */, /* {id} */, $server_type, $server, /* CKI */, $cki_code, /* ... */) = @explode(' ', $data);\r
-                @list($ip, $port) = @explode(':', $server);\r
-                if ($server_type != 'SB') {\r
-                    // maybe exit?\r
-                    // this connection will close after XFR\r
-                    $this->NSLogout();\r
-                    continue;\r
-                }\r
-                if(count($this->MessageQueue))\r
-                {\r
-                    foreach($this->MessageQueue as $User => $Message)\r
+                    if(count($this->MessageQueue))\r
                     {\r
-                        //$this->ChildProcess[$ChildPid]\r
-                        $this->log_message("*** XFR SB $User");\r
-                        $pid=pcntl_fork();\r
-                        if($pid)\r
-                        {\r
-                            //Parrent Process\r
-                            $this->ChildProcess[$pid]=$User;\r
-                            break;\r
-                        }\r
-                        elseif($pid==-1)\r
-                        {\r
-                            $this->log_message("*** Fork Error $User");\r
-                            break;\r
-                        }\r
-                        else\r
+                        foreach($this->MessageQueue as $User => $Message)\r
                         {\r
-                            //Child Process\r
-                            $this->log_message("*** Child Process Start for $User");\r
-                            unset($Message['XFRSent']);\r
-                            unset($Message['ReqTime']);\r
-                            $bSBresult = $this->switchboard_control($ip, $port, $cki_code, $User, $Message);\r
-                            if ($bSBresult === false)\r
+                            //$this->ChildProcess[$ChildPid]\r
+                            $this->log_message("*** XFR SB $User");\r
+                            $pid=pcntl_fork();\r
+                            if($pid)\r
+                            {\r
+                                //Parrent Process\r
+                                $this->ChildProcess[$pid]=$User;\r
+                                break;\r
+                            }\r
+                            elseif($pid==-1)\r
+                            {\r
+                                $this->log_message("*** Fork Error $User");\r
+                                break;\r
+                            }\r
+                            else\r
                             {\r
-                                // error for switchboard\r
-                                $this->log_message("!!! error for sending message to ".$User);\r
+                                //Child Process\r
+                                $this->log_message("*** Child Process Start for $User");\r
+                                unset($Message['XFRSent']);\r
+                                unset($Message['ReqTime']);\r
+                                $bSBresult = $this->switchboard_control($ip, $port, $cki_code, $User, $Message);\r
+                                if ($bSBresult === false)\r
+                                {\r
+                                    // error for switchboard\r
+                                    $this->log_message("!!! error for sending message to ".$User);\r
+                                }\r
+                                die;\r
                             }\r
-                            die;\r
                         }\r
+                        unset($this->MessageQueue[$User]);\r
                     }\r
-                    unset($this->MessageQueue[$User]);\r
-                }\r
-                /*\r
-                 $bSBresult = $this->switchboard_control($ip, $port, $cki_code, $aMSNUsers[$nCurrentUser], $sMessage);\r
-                 if ($bSBresult === false) {\r
-                 // error for switchboard\r
-                 $this->log_message("!!! error for sending message to ".$aMSNUsers[$nCurrentUser]);\r
-                 $aOfflineUsers[] = $aMSNUsers[$nCurrentUser];\r
-                 }*/\r
-                break;\r
-            case 'QNG':\r
-                // NS: <<< QNG {time}\r
-                //@list(/* QNG */, $this->ping_wait) = @explode(' ', $data);\r
-                //if ($this->ping_wait == 0) $this->ping_wait = 50;\r
-                //if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping;\r
-                //Mod by Ricky Set Online\r
-                break;\r
-\r
-            case 'RNG':\r
-                if($this->PhotoStickerFile!==false)\r
-                $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
-                else\r
-                $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
-                // someone is trying to talk to us\r
-                // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0\r
-                $this->log_message("NS: <<< RNG $data");\r
-                @list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data);\r
-                @list($sb_ip, $sb_port) = @explode(':', $server);\r
-                $this->log_message("*** RING from $email, $sb_ip:$sb_port");\r
-                $this->addContact($email,1,$email, true);\r
-                $pid=pcntl_fork();\r
-                if($pid)\r
-                {\r
-                    //Parrent Process\r
-                    $this->ChildProcess[$pid]='RNG';\r
+                    /*\r
+                     $bSBresult = $this->switchboard_control($ip, $port, $cki_code, $aMSNUsers[$nCurrentUser], $sMessage);\r
+                     if ($bSBresult === false) {\r
+                     // error for switchboard\r
+                     $this->log_message("!!! error for sending message to ".$aMSNUsers[$nCurrentUser]);\r
+                     $aOfflineUsers[] = $aMSNUsers[$nCurrentUser];\r
+                     }*/\r
                     break;\r
-                }\r
-                elseif($pid==-1)\r
-                {\r
-                    $this->log_message("*** Fork Error $User");\r
+                case 'QNG':\r
+                    // NS: <<< QNG {time}\r
+                    //@list(/* QNG */, $this->ping_wait) = @explode(' ', $data);\r
+                    //if ($this->ping_wait == 0) $this->ping_wait = 50;\r
+                    //if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping;\r
+                    //Mod by Ricky Set Online\r
                     break;\r
-                }\r
-                else\r
-                {\r
-                    //Child Process\r
-                    $this->log_message("*** Ring Child Process Start for $User");\r
-                    $this->switchboard_ring($sb_ip, $sb_port, $sid, $ticket,$email);\r
-                    die;\r
-                }\r
-                break;\r
-            case 'OUT':\r
-                // force logout from NS\r
-                // NS: <<< OUT xxx\r
-                $this->log_message("*** LOGOUT from NS");\r
-                return $this->NsLogout();\r
-\r
-            default:\r
-                $code = substr($data,0,3);\r
-                if (is_numeric($code)) {\r
-                    $this->error = "Error code: $code, please check the detail information from: http://msnpiki.msnfanatic.com/index.php/Reference:Error_List";\r
-                    $this->debug_message("*** NS: $this->error");\r
-\r
+    \r
+                case 'RNG':\r
+                    if($this->PhotoStickerFile!==false)\r
+                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                    else\r
+                    $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
+                    // someone is trying to talk to us\r
+                    // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0\r
+                    $this->log_message("NS: <<< RNG $data");\r
+                    @list(/* RNG */, $sid, $server, /* auth_type */, $ticket, $email, $name, ) = @explode(' ', $data);\r
+                    @list($sb_ip, $sb_port) = @explode(':', $server);\r
+                    if($this->IsIgnoreMail($email))\r
+                    {\r
+                        $this->log_message("*** Ignore RNG from $email");\r
+                        break;\r
+                    }\r
+                    $this->log_message("*** RING from $email, $sb_ip:$sb_port");\r
+                    $this->addContact($email,1,$email, true);\r
+                    $pid=pcntl_fork();\r
+                    if($pid)\r
+                    {\r
+                        //Parrent Process\r
+                        $this->ChildProcess[$pid]='RNG';\r
+                        break;\r
+                    }\r
+                    elseif($pid==-1)\r
+                    {\r
+                        $this->log_message("*** Fork Error $User");\r
+                        break;\r
+                    }\r
+                    else\r
+                    {\r
+                        //Child Process\r
+                        $this->log_message("*** Ring Child Process Start for $User");\r
+                        $this->switchboard_ring($sb_ip, $sb_port, $sid, $ticket,$email);\r
+                        die;\r
+                    }\r
+                    break;\r
+                case 'OUT':\r
+                    // force logout from NS\r
+                    // NS: <<< OUT xxx\r
+                    $this->log_message("*** LOGOUT from NS");\r
                     return $this->NsLogout();\r
-                }\r
-                break;\r
+    \r
+                default:\r
+                    $code = substr($data,0,3);\r
+                    if (is_numeric($code)) {\r
+                        $this->error = "Error code: $code, please check the detail information from: http://msnpiki.msnfanatic.com/index.php/Reference:Error_List";\r
+                        $this->debug_message("*** NS: $this->error");\r
+    \r
+                        return $this->NsLogout();\r
+                    }\r
+                    break;\r
+            }\r
         }\r
     }\r
     \r
@@ -3680,7 +3579,7 @@ X-OIM-Sequence-Num: 1
         $lastActive = $this->switchBoardSessions[$to]['lastActive'];\r
         $joined = $this->switchBoardSessions[$to]['joined'];\r
         \r
-        //TODO Probably not needed (we're not running in a loop anymore)\r
+        //FIXME Probably not needed (we're not running in a loop anymore)\r
         /*if($this->kill_me)\r
         {\r
             $this->log_message("*** SB Okay, kill me now!");\r
@@ -3725,7 +3624,7 @@ X-OIM-Sequence-Num: 1
         return true;\r
     }\r
     \r
-    //TODO Not sure if this is needed?\r
+    //FIXME Not sure if this is needed?\r
     private function endSBSession($socket) {\r
         if (feof($this->SBFp))\r
         {\r
@@ -3746,12 +3645,13 @@ X-OIM-Sequence-Num: 1
             if($network === 1 && isset($this->switchBoardSessions[$to])) {\r
                 $recipient = $name . $host;\r
                 $this->debug_message("*** Sending Message to $recipient using existing SB session");\r
-                $this->sendMessageViaSB($message, $recipient);\r
+                return $this->sendMessageViaSB($message, $recipient);\r
             } else {\r
                 $this->debug_message("*** Not MSN network or no existing SB session");\r
-                \r
+                //TODO implement creation of SB session etc\r
             }\r
         }\r
+        return true;\r
     }\r
     \r
     /**\r