Public paste
aap
By: Ik | Date: Sep 29 2008 20:21 | Format: None | Expires: never | Size: 1.94 KB | Hits: 1253

  1. private function rawPacketRead($p_sResponse) {
  2.                 $iTotalSizeRead = 0;
  3.                 if (isset($this->m_aResponseBuff['packet'])) {
  4.                         $iPacketSizeRead = strlen($this->m_aResponseBuff['packet']);
  5.                 } else {
  6.                         $iPacketSizeRead = 0;
  7.                 }
  8.                 while ($iTotalSizeRead < strlen($p_sResponse)) {
  9.                         // New packet
  10.                         if (!isset($this->m_aResponseBuff['length'])) {
  11.                                 $aLength = unpack('V1PacketLength', substr($p_sResponse, $iTotalSizeRead, 4));
  12.                                 $this->m_aResponseBuff['length'] = $aLength['PacketLength'];
  13.                                 $this->m_aResponseBuff['packet'] = null;
  14.                                 $iTotalSizeRead += 4;
  15.                                 $iPacketSizeRead = 0;
  16.                         }
  17.  
  18.                         $this->m_aResponseBuff['packet'] .= substr($p_sResponse, $iTotalSizeRead, ( $this->m_aResponseBuff['length'] - $iPacketSizeRead ) );
  19.                         $iTotalSizeRead += ( $this->m_aResponseBuff['length'] - $iPacketSizeRead );
  20.  
  21.                         if (strlen($this->m_aResponseBuff['packet']) == $this->m_aResponseBuff['length']) {
  22.                                 $aResponse = unpack('V1RequestID/V1CommandResponse/a*String1/a*String2', $this->m_aResponseBuff['packet']);
  23.                                 $this->m_aResponseBuff = array();
  24.  
  25.                                 if ($this->m_bAuthenticated === false && $aResponse['RequestID'] == 1 && $aResponse['CommandResponse'] == SERVERDATA_AUTH_RESPONSE) {
  26.                                         // authenticated succesfully
  27.                                         $this->m_bAuthenticated = true;
  28.                                 } else if (array_key_exists($aResponse['RequestID'], $this->m_aResponses)) {
  29.                                         // add to command response
  30.                                         $this->m_aResponses[$aResponse['RequestID']]['String1'] .= $aResponse['String1'];
  31.                                         $this->m_aResponses[$aResponse['RequestID']]['String2'] .= $aResponse['String2'];
  32.                                 } else {
  33.                                         // build new command response
  34.                                         $this->m_aResponses[$aResponse['RequestID']] = array();
  35.                                         $this->m_aResponses[$aResponse['RequestID']]['CommandResponse'] = $aResponse['CommandResponse'];
  36.                                         $this->m_aResponses[$aResponse['RequestID']]['String1'] = $aResponse['String1'];
  37.                                         $this->m_aResponses[$aResponse['RequestID']]['String2'] = $aResponse['String2'];
  38.                                 }
  39.                         }
  40.                 }
  41.         }