function getQueryResult($LASHost, $id, &$result, &$page, &$numpages) { if (!connectToLAS($LASHost, $fp, $result)) { $result = "Failed to connect to LAS {$LASHost} (ec 7)"; 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 = 1; $msgout->serialuint8($messageType); $str = $id . ":" . $page; $msgout->serialstring($str); if (!sendMessage($fp, $msgout)) { $result = "Failed to send query to LAS {$LASHost} (ec 8)"; return false; } if (!waitMessage($fp, $msgin)) { $result = "Failed to wait for LAS {$LASHost} (ec 9)"; return false; } $result = ''; if (!$msgin->serialstring($result)) { $result = "Failed to decode LAS message {$LASHost} (ec 10)"; return false; } fclose($fp); $pos = strpos($result, ':'); if ($pos === FALSE) { $result = "Failed to decode LAS message {$LASHost} (ec 11)"; return false; } $success = substr($result, 0, $pos) == '1'; if ($success) { ++$pos; $npos = strpos($result, ':', $pos); $numpages = substr($result, $pos, $npos - $pos); ++$npos; $pos = strpos($result, ':', $npos); $page = substr($result, $npos, $pos - $npos); $result = substr($result, $pos + 1); } else { $result = substr($result, $pos + 1); } return $success; }
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 askClientConnection($shardid, $uid, $name, $priv, $extended, &$res, &$patchURLS) { $ok = false; connectToLS($fp, $res); if ($res != "") { 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->serialuint32($shardid); $msgout->serialuint32($uid); $msgout->serialstring($name); $msgout->serialstring($priv); $msgout->serialstring($extended); if (!sendMessage($fp, $msgout)) { $res = "Can't send message connection to the Login Service (error code 42)"; return $ok; } if (!waitMessage($fp, $msgin)) { $res = "Can't receive the answer from the Login Service (error code 43)"; return $ok; } if (!$msgin->serialstring($reason)) { $res = "Can't read the reason (error code 44)"; return $ok; } //printf("reason size %d", strlen($reason)); if (strlen($reason) == 0) { // it s ok, let's connect if (!$msgin->serialstring($cookie)) { $res = "Can't read the cookie (error code 45)"; return $ok; } if (!$msgin->serialstring($addr)) { $res = "Can't read the addr (error code 46)"; return $ok; } $patchURLS = ''; /* if (!$msgin->serialstring($patchURLS)) { $patchURLS = ''; } */ $res = $cookie . ' ' . $addr; $ok = true; } else { // can't accept it, display the error // echo "Can't connect to the shard: $reason"; $res = $reason; } //printf("receive response '$reason' '$cookie' '$addr'<br>"); fclose($fp); //echo "sent OK.<br><br>"; return $ok; }