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 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; }