function find_start_location($start, $lastLocation, $homeLocation, &$scene, &$startPosition, &$startLookAt)
{
    $config =& get_config();
    $defaultLocation = $config['default_location'];
    $scene = null;
    if (strtolower($start) == "last") {
        if (isset($lastLocation)) {
            log_message('debug', sprintf("Finding start location (last) for '%s'", $lastLocation->SceneID));
            $scene = lookup_scene_by_id($lastLocation->SceneID);
            if (isset($scene)) {
                $startPosition = $lastLocation->Position;
                $startLookAt = $lastLocation->LookAt;
                return true;
            }
        }
    }
    if (strtolower($start) == "home") {
        if (isset($homeLocation)) {
            log_message('debug', sprintf("Finding start location (home) for '%s'", $homeLocation->SceneID));
            $scene = lookup_scene_by_id($homeLocation->SceneID);
            if (isset($scene)) {
                $startPosition = $homeLocation->Position;
                $startLookAt = $homeLocation->LookAt;
                return true;
            }
        }
    }
    if (preg_match('/^uri:([a-zA-Z0-9\\s-_]+)&(\\d+)&(\\d+)&(\\d+)$/', $start, $matches)) {
        log_message('debug', sprintf("Finding start location (custom: %s) for '%s'", $start, $matches[1]));
        $scene = lookup_scene_by_name($matches[1]);
        if (isset($scene)) {
            $startPosition = new Vector3($matches[2], $matches[3], $matches[4]);
            $startLookAt = new Vector3(1, 0, 0);
            return true;
        }
    }
    // Check to see if a valid default location has been set
    if (preg_match('/^([a-zA-Z0-9\\s-_]+)\\/(\\d+)\\/(\\d+)\\/(\\d+)$/', $defaultLocation, $matches)) {
        log_message('debug', sprintf("Finding start location (default: %s) for '%s'", $defaultLocation, $matches[1]));
        $scene = lookup_scene_by_name($matches[1]);
        if (isset($scene)) {
            $startPosition = new Vector3($matches[2], $matches[3], $matches[4]);
            $startLookAt = new Vector3(1, 0, 0);
            return true;
        }
    } else {
        log_message('info', 'No valid default_location set');
    }
    // Last resort lookup
    $position = Vector3::Zero();
    log_message('debug', sprintf("Finding start location (any: %s) for '%s'", $start, $position));
    $scene = lookup_scene_by_position($position, true);
    if (isset($scene)) {
        $startPosition = new Vector3(($scene->MinPosition->X + $scene->MaxPosition->X) / 2 - $scene->MinPosition->X, ($scene->MinPosition->Y + $scene->MaxPosition->Y) / 2 - $scene->MinPosition->Y, 25);
        $startLookAt = new Vector3(1, 0, 0);
        return true;
    }
    return false;
}
Exemple #2
0
function link_region($method_name, $params, $user_data)
{
    log_message('info', "link_region called");
    $config =& get_config();
    $req = $params[0];
    if (isset($req['region_name']) && strlen($req['region_name']) > 0) {
        $region_name = $req['region_name'];
        log_message('debug', "Using specified region name {$region_name}");
    } else {
        $region_name = $config['hypergrid_default_region'];
        log_message('debug', "No region name specified - using {$region_name}");
    }
    $scene = lookup_scene_by_name($region_name);
    $response = array();
    if ($scene == null) {
        log_message('warn', "Unable to link to unknown region {$region_name} - no scene found");
        $response['result'] = 'false';
    } else {
        $response['result'] = 'true';
        $response['uuid'] = $scene->SceneID;
        // Yay for 64-bit integer bitmath in PHP
        $x = $scene->MinPosition->X;
        $y = $scene->MinPosition->Y;
        $handle = bitShift($x, 32);
        $handle = bitOr($handle, (string) $y, 0);
        $response['handle'] = (string) $handle;
        $response['region_image'] = "http://" . $scene->ExtraData['ExternalAddress'] . ":" . ($response['server_uri'] = $scene->Address);
        $response['external_name'] = $scene->Name;
        log_message('debug', "Succesfully linked to {$region_name}@" . $scene->Address);
    }
    return $response;
}