function queryToAS($rawvarpath, &$result, $asAddr, $asPort) { global $nel_queries; $nel_queries[] = $rawvarpath; $ok = false; connectToAS($fp, $result, $asAddr, $asPort); if (strlen($result) != 0) { return $ok; } // send the message that say that we want to add a user $msgout = new CMemStream(); $fake = 0; $msgout->serialuint32($fake); // fake used to number the packet $messageType = 0; $msgout->serialuint8($messageType); $msgout->serialstring($rawvarpath); sendMessage($fp, $msgout); waitMessage($fp, $msgin); $msgin->serialstring($result); if (strlen($result) == 0) { // it failed } else { // it's ok $ok = true; } disconnectFromAS(&$fp); return $ok; }
function displayLASQueries($LASHost, &$result) { if (!connectToLAS($LASHost, $fp, $result)) { $result = "Failed to connect to LAS {$LASHost} (ec 12)"; return false; } // send the message that say that we want to add a user $msgout = new CMemStream(); $fake = 0; $msgout->serialuint32($fake); // fake used to number the packet $messageType = 2; $msgout->serialuint8($messageType); if (!sendMessage($fp, $msgout)) { $result = "Failed to send query to LAS {$LASHost} (ec 13)"; return false; } if (!waitMessage($fp, $msgin)) { $result = "Failed to wait for LAS {$LASHost} (ec 14)"; return false; } $result = ''; if (!$msgin->serialstring($result)) { $result = "Failed to decode LAS message {$LASHost} (ec 15)"; return false; } fclose($fp); $pos = strpos($result, ':'); if ($pos === FALSE) { $result = "Failed to decode LAS message {$LASHost} (ec 16)"; return false; } $success = substr($result, 0, $pos) == '1'; if ($success) { ++$pos; $npos = strpos($result, "\n", $pos); $result = substr($result, $npos); } else { $result = substr($result, $pos + 1); } return $success; }
function waitMessage() { if (!$this->ConSock) { debug(sprintf("Socket is not valid\n")); return false; } $size = 0; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size = ord($val) << 24; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size = ord($val) << 16; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size += ord($val) << 8; $val = fread($this->ConSock, 1); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size += ord($val); debug(sprintf("receive packet size '%d'<br>\n", $size)); $fake = fread($this->ConSock, 5); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } $size -= 5; // remove the fake $Buffer = ""; while ($size > 0 && strlen($Buffer) != $size) { $Buffer .= fread($this->ConSock, $size - strlen($Buffer)); $info = stream_get_meta_data($this->ConSock); if ($info['timed_out']) { debug('Connection timed out!'); return false; } } $msgin = new CMemStream(); $msgin->setBuffer($Buffer); // decode msg name $msgin->serialString($name); debug(sprintf("Message name = '%s'<BR>", $name)); $message = new CMessage(); $message->setBuffer(substr($msgin->Buffer, $msgin->Pos)); $message->setName($name); debug(sprintf("In message name = '%s'<br>", $message->MsgName)); return $message; }
function disconnectClient($shardid, $uid, &$res) { $ok = false; connectToLS($fp, $res); if (strlen($res) != 0) { return $ok; } // send the message that say that we want to add a user $msgout = new CMemStream(); $fake = 0; $msgout->serialuint32($fake); // fake used to number the packet $messageType = 1; $msgout->serialuint8($messageType); $msgout->serialuint32($shardid); $msgout->serialuint32($uid); if (!sendMessage($fp, $msgout)) { $res = "Can't send message disconnect to the Login Service (error code 47)"; return $ok; } if (!waitMessage($fp, $msgin)) { $res = "Can't receive the answer from the Login Service (error code 48)"; return $ok; } if (!$msgin->serialstring($res)) { $res = "Can't read the string (error code 49)"; return $ok; } $ok = true; //printf("receive response '$reason' '$cookie' '$addr'<br>"); fclose($fp); //echo "sent OK.<br><br>"; return $ok; }