function process_login($method_name, $params, $userID) { $config =& get_config(); $userService = $config['user_service']; log_message('debug', "Processing new login request"); $req = $params[0]; $fullname = $req["first"] . ' ' . $req["last"]; // Sanity check the request, make sure it's somewhat valid if (empty($userID)) { if (!isset($req["first"], $req["last"], $req["passwd"]) || empty($req["first"]) || empty($req["last"]) || empty($req["passwd"])) { return array('reason' => 'key', 'login' => 'false', 'message' => "Login request must contain a first name, last name, and password and they cannot be blank"); } // Authorize the first/last/password and resolve it to a user account UUID log_message('debug', "Doing password-based authorization for user {$fullname}"); $userID = authorize_identity($fullname, $req['passwd']); if (empty($userID)) { return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry! We couldn't log you in.\nPlease check to make sure you entered the right\n * Account name\n * Password\nAlso, please make sure your Caps Lock key is off."); } log_message('debug', sprintf("Authorization success for %s", $userID)); } else { log_message('debug', sprintf("Using pre-authenticated capability for %s", $userID)); } // Get information about the user account $user = get_user_by_id($userID); if (empty($user)) { return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry! We couldn't log you in. User account information could not be retrieved. If this problem persists, please contact the grid operator."); } $login_success = true; //ensure username has the same case as in the database $fullname = $user['Name']; if (!empty($user['UserFlags'])) { // get_user_by_id() fully decodes the structure, this is not needed //$userflags = json_decode($user['UserFlags'], TRUE); $userflags = $user['UserFlags']; if (!empty($userflags['Suspended']) && (bool) $userflags['Suspended'] === true) { $login_success = false; log_message('debug', "User " . $user['Name'] . " is banned."); } else { if ($user['AccessLevel'] < $config['access_level_minimum']) { if ($config['validation_required']) { if (!empty($userflags['Validated'])) { $login_success = $userflags['Validated']; } else { $login_success = false; } if (!$login_success) { log_message('debug', "User " . $user['Name'] . " has not validated their email."); } } } } } else { if ($user['AccessLevel'] < $config['access_level_minimum'] && $config['validation_required']) { $login_success = false; log_message('debug', "User " . $user['Name'] . " has not validated their email."); } } if (!$login_success) { return array('reason' => 'key', 'login' => 'false', 'message' => "Sorry! We couldn't log you in. User account has been suspended or is not yet activated. If this problem persists, please contact the grid operator."); } $lastLocation = null; if (isset($user['LastLocation'])) { $lastLocation = SceneLocation::fromOSD($user['LastLocation']); } $homeLocation = null; if (isset($user['HomeLocation'])) { $homeLocation = SceneLocation::fromOSD($user['HomeLocation']); } log_message('debug', sprintf("User retrieval success for %s", $fullname)); // Check for an existing session $existingSession = get_session($userID); if (!empty($existingSession)) { log_message('debug', sprintf("Existing session %s found for %s in scene %s", $existingSession["SessionID"], $fullname, $existingSession["SceneID"])); $sceneID = null; if (UUID::TryParse($existingSession["SceneID"], $sceneID)) { inform_scene_of_logout($sceneID, $userID); } if (remove_session($userID)) { log_message('debug', "Removed existing session for {$fullname} ({$userID})"); } else { log_message('warn', "Failed to remove session for {$fullname} ({$userID})"); return array('reason' => 'presence', 'login' => 'false', 'message' => "You are already logged in from another location. Please try again later."); } } else { log_message('debug', "No existing session found for {$fullname} ({$userID})"); } // Create a login session $sessionID = null; $secureSessionID = null; $extradata = array('ClientIP' => $_SERVER['REMOTE_ADDR']); if (!add_session($userID, $sessionID, $secureSessionID, $extradata)) { return array('reason' => 'presence', 'login' => 'false', 'message' => "Failed to create a login session. Please try again later."); } log_message('debug', sprintf("Session creation success for %s (%s)", $fullname, $userID)); // Find the starting scene for this user $scene = null; $startPosition = null; $startLookAt = null; if (!find_start_location($req['start'], $lastLocation, $homeLocation, $scene, $startPosition, $startLookAt) || !isset($scene->ExtraData['ExternalAddress'], $scene->ExtraData['ExternalPort'])) { return array('reason' => 'presence', 'login' => 'false', 'message' => "Error connecting to the grid. No suitable region to connect to."); } $lludpAddress = $scene->ExtraData['ExternalAddress']; $lludpPort = $scene->ExtraData['ExternalPort']; // Generate a circuit code srand(make_seed()); $circuitCode = rand(); // Prepare a login to the destination scene $seedCapability = NULL; $appearance = $user['LLPackedAppearance']; if (!create_opensim_presence($scene, $userID, $circuitCode, $fullname, $appearance, $sessionID, $secureSessionID, $startPosition, $seedCapability)) { return array('reason' => 'presence', 'login' => 'false', 'message' => "Failed to establish a presence in the destination region. Please try again later."); } log_message('debug', sprintf("Presence creation success for %s (%s) in %s with seedcap %s", $fullname, $userID, $scene->Name, $seedCapability)); // Build the response $response = array(); $response['seconds_since_epoch'] = time(); $response['login'] = '******'; $response['agent_id'] = (string) $userID; list($response['first_name'], $response['last_name']) = explode(' ', $fullname); $response['message'] = $config['message_of_the_day']; $response['udp_blacklist'] = $config['udp_blacklist']; $response['circuit_code'] = $circuitCode; $response['sim_ip'] = $lludpAddress; $response['sim_port'] = (int) $lludpPort; $response['seed_capability'] = $seedCapability; $response['region_x'] = (string) $scene->MinPosition->X; $response['region_y'] = (string) $scene->MinPosition->Y; $response['region_size_x'] = (string) ($scene->MaxPosition->X - $scene->MinPosition->X); $response['region_size_y'] = (string) ($scene->MaxPosition->Y - $scene->MinPosition->Y); $response['look_at'] = sprintf("[r%s, r%s, r%s]", $startLookAt->X, $startLookAt->Y, $startLookAt->Z); // TODO: If a valid $homeLocation is set, we should be pulling region_handle / position / lookat out of it $response['home'] = sprintf("{'region_handle':[r%s, r%s], 'position':[r%s, r%s, r%s], 'look_at':[r%s, r%s, r%s]}", $scene->MinPosition->X, $scene->MinPosition->Y, $startPosition->X, $startPosition->Y, $startPosition->Z, $startLookAt->X, $startLookAt->Y, $startLookAt->Z); $response['session_id'] = (string) $sessionID; $response['secure_session_id'] = (string) $secureSessionID; $req['options'][] = 'initial-outfit'; for ($i = 0; $i < count($req['options']); $i++) { $option = str_replace('-', '_', $req['options'][$i]); if (file_exists(BASEPATH . "options/Class.{$option}.php")) { if (include_once BASEPATH . "options/Class.{$option}.php") { $instance = new $option($user); $response[$req["options"][$i]] = $instance->GetResults(); } else { log_message('warn', "Unable to process login option: " . $option); } } else { log_message('debug', "Option " . $option . " not implemented."); } } $response["start_location"] = $req["start"]; $response["agent_access"] = 'A'; $response["agent_region_access"] = 'A'; $response["agent_access_max"] = 'A'; $response["agent_flags"] = 0; $response["ao_transition"] = 0; $response["inventory_host"] = "127.0.0.1"; log_message('info', sprintf("Login User=%s %s Channel=%s Start=%s Viewer=%s id0=%s Mac=%s", $req["first"], $req["last"], $req["channel"], $req["start"], $req["version"], $req["id0"], $req["mac"])); return $response; }
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; }