Esempio n. 1
0
function get_home_region($method_name, $params, $user_data)
{
    $response = array();
    $req = $params[0];
    $userID = $req['userID'];
    $response = array();
    log_message('info', "get_home_region called with UserID {$userID}");
    // Fetch the user
    $user = get_user($userID);
    if (empty($user)) {
        log_message('warn', "Unknown UserID {$userID}");
        $response['result'] = 'false';
        return $response;
    }
    $homeLocation = null;
    if (isset($user['HomeLocation'])) {
        $homeLocation = SceneLocation::fromOSD($user['HomeLocation']);
    }
    log_message('debug', "User retrieval success for {$userID}, HomeLocation is {$homeLocation}");
    $scene = null;
    $position = null;
    $lookat = null;
    // If the user's home is set, try to grab info for that scene
    if (isset($homeLocation)) {
        log_message('debug', sprintf("Looking up scene '%s'", $homeLocation->SceneID));
        $scene = lookup_scene_by_id($homeLocation->SceneID);
        if (isset($scene)) {
            $position = $homeLocation->Position;
            $lookat = $homeLocation->LookAt;
        }
    }
    // No home set, last resort lookup for *any* scene in the grid
    if (!isset($scene)) {
        $position = Vector3::Zero();
        log_message('debug', "Looking up scene closest to '{$position}'");
        $scene = lookup_scene_by_position($position, true);
        if (isset($scene)) {
            $position = new Vector3(($scene->MinPosition->X + $scene->MaxPosition->X) / 2 - $scene->MinPosition->X, ($scene->MinPosition->Y + $scene->MaxPosition->Y) / 2 - $scene->MinPosition->Y, 25);
            $lookat = new Vector3(1, 0, 0);
        }
    }
    if (isset($scene)) {
        $response['result'] = 'true';
        $response['uuid'] = $scene->SceneID;
        $response['x'] = $scene->MinPosition->X;
        $response['y'] = $scene->MinPosition->Y;
        $response['region_name'] = $scene->Name;
        $response['hostname'] = $scene->Address;
        $response['http_port'] = $scene->ExtraData['ExternalPort'];
        $response['internal_port'] = $scene->ExtraData['InternalPort'];
        $response['position'] = (string) $position;
        $response['lookAt'] = (string) $lookat;
        log_message('debug', "Returning successful home lookup for {$userID}");
    } else {
        $response['result'] = 'false';
        log_message('warn', "Failed to find a valid home scene for {$userID}, returning failure");
    }
    return $response;
}
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;
}
function foreignagent_handler($path_tail, $data)
{
    log_message('info', "[hypergrid] foreignagent_handler called");
    $data = decodedata($data);
    $config =& get_config();
    $userid = $path_tail[0];
    log_message('info', "foreign_agent called for {$userid} with {$data}");
    $osd = decode_recursive_json($data);
    if ($osd == null) {
        log_message('error', sprintf('[hypergrid] failed to decode foreignagent json string %s', $data));
        sendresponse(false, 'failed to decode foreignagent string');
    }
    $dest_x = $osd['destination_x'];
    $dest_y = $osd['destination_y'];
    if ($dest_x == null) {
        $dest_x = 0;
    }
    if ($dest_y == null) {
        $dest_y = 0;
    }
    $caps_path = $osd['caps_path'];
    $username = $osd['first_name'] . ' ' . $osd['last_name'];
    $circuit_code = $osd['circuit_code'];
    $session_id = $osd['session_id'];
    $secure_session_id = $osd['secure_session_id'];
    $service_session_id = $osd['service_session_id'];
    $start_pos = $osd['start_pos'];
    $appearance = $osd['packed_appearance'];
    //$service_urls['HomeURI'] = $osd['service_urls'][1];
    //$service_urls['GatekeeperURI'] = $osd['service_urls'][3];
    //$service_urls['InventoryServerURI'] = $osd['service_urls'][5];
    //$service_urls['AssetServerURI'] = $osd['service_urls'][7];
    if (isset($osd['client_ip'])) {
        $client_ip = $osd['client_ip'];
    } else {
        log_message('info', '[hypergrid] no client ip specified in foreignagent request');
        $client_ip = null;
    }
    if (empty($osd['destination_uuid'])) {
        header("HTTP/1.1 400 Bad Request");
        echo "missing destination_uuid";
        exit;
    }
    $dest_uuid = $osd['destination_uuid'];
    $scene = lookup_scene_by_id($dest_uuid);
    if ($scene == null) {
        header("HTTP/1.1 400 Bad Request");
        echo "invalid destination uuid";
        exit;
    }
    $dest_name = $scene->Name;
    $homeuri = $osd['serviceurls']['HomeURI'];
    // $username = $osd['first_name'] . ' ' . $osd['last_name'] . '@' . $service_urls['HomeURI'];
    $username = $osd['first_name'] . ' ' . $osd['last_name'];
    log_message('info', "[hypergrid] check user name {$username} with homeuri {$homeuri}");
    if ($homeuri != $config['hypergrid_uri']) {
        $username = $username . '@' . $homeuri;
        hg_register_user($userid, $username, $homeuri);
    }
    $extradata = null;
    if ($client_ip != null) {
        $extradata = array('ClientIP' => $client_ip);
    }
    log_message('info', "[hypergrid] create session for {$username}");
    create_session($userid, $session_id, $secure_session_id, $extradata);
    $result = create_opensim_presence_full($scene->Address, $dest_name, $dest_uuid, $dest_x, $dest_y, $userid, $circuit_code, $username, $appearance, $session_id, $secure_session_id, $start_pos, $caps_path, $client_ip, $osd['serviceurls'], 1073741824, $service_session_id, $seedCaps);
    sendresponse($result, 'no reason given');
}