protected GridRegion FindDestination(UserAccount account, UserInfo pinfo, UUID sessionID, string startLocation, GridRegion home, out TeleportFlags tpFlags, out string where, out Vector3 position, out Vector3 lookAt) { where = "home"; position = new Vector3(128, 128, 25); lookAt = new Vector3(0, 1, 0); tpFlags = TeleportFlags.ViaLogin; if (m_GridService == null) return null; if (startLocation.Equals("home")) { tpFlags |= TeleportFlags.ViaLandmark; // logging into home region if (pinfo == null) return null; GridRegion region = null; bool tryDefaults = false; if (home == null) { MainConsole.Instance.WarnFormat( "[LLOGIN SERVICE]: User {0} {1} tried to login to a 'home' start location but they have none set", account.FirstName, account.LastName); tryDefaults = true; } else { region = home; position = pinfo.HomePosition; lookAt = pinfo.HomeLookAt; } if (tryDefaults) { tpFlags &= ~TeleportFlags.ViaLandmark; List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.AllScopeIDs); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } else { List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0); if (fallbacks != null && fallbacks.Count > 0) { region = fallbacks[0]; where = "safe"; } else { //Try to find any safe region List<GridRegion> safeRegions = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0); if (safeRegions != null && safeRegions.Count > 0) { region = safeRegions[0]; where = "safe"; } else { MainConsole.Instance.WarnFormat( "[LLOGIN SERVICE]: User {0} {1} does not have a valid home and this grid does not have default locations. Attempting to find random region", account.FirstName, account.LastName); defaults = m_GridService.GetRegionsByName(account.AllScopeIDs, "", 0, 1); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } } } } } return region; } if (startLocation.Equals("last")) { tpFlags |= TeleportFlags.ViaLandmark; // logging into last visited region where = "last"; if (pinfo == null) return null; GridRegion region = null; if (pinfo.CurrentRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(account.AllScopeIDs, pinfo.CurrentRegionID)) == null) { tpFlags &= ~TeleportFlags.ViaLandmark; List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.AllScopeIDs); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } else { defaults = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } else { defaults = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } } } } else { position = pinfo.CurrentPosition; if (position.X < 0) position.X = 0; if (position.Y < 0) position.Y = 0; if (position.Z < 0) position.Z = 0; if (position.X > region.RegionSizeX) position.X = region.RegionSizeX; if (position.Y > region.RegionSizeY) position.Y = region.RegionSizeY; lookAt = pinfo.CurrentLookAt; } return region; } else { // free uri form // e.g. New Moon&135&46 New [email protected]:8002&153&34 where = "url"; Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); Match uriMatch = reURI.Match(startLocation); position = new Vector3(float.Parse(uriMatch.Groups["x"].Value, Culture.NumberFormatInfo), float.Parse(uriMatch.Groups["y"].Value, Culture.NumberFormatInfo), float.Parse(uriMatch.Groups["z"].Value, Culture.NumberFormatInfo)); string regionName = uriMatch.Groups["region"].ToString(); if (!regionName.Contains("@")) { List<GridRegion> regions = m_GridService.GetRegionsByName(account.AllScopeIDs, regionName, 0, 1); if ((regions == null) || (regions.Count == 0)) { MainConsole.Instance.InfoFormat( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName); regions = m_GridService.GetDefaultRegions(account.AllScopeIDs); if (regions != null && regions.Count > 0) { where = "safe"; return regions[0]; } List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0); if (fallbacks != null && fallbacks.Count > 0) { where = "safe"; return fallbacks[0]; } //Try to find any safe region List<GridRegion> safeRegions = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0); if (safeRegions != null && safeRegions.Count > 0) { where = "safe"; return safeRegions[0]; } MainConsole.Instance.InfoFormat( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not have any available regions.", startLocation); return null; } return regions[0]; } //This is so that you can login to other grids via IWC (or HG), example"[email protected]:8002". All this really needs to do is inform the other grid that we have a user who wants to connect. IWC allows users to login by default to other regions (without the host names), but if one is provided and we don't have a link, we need to create one here. string[] parts = regionName.Split(new char[] {'@'}); if (parts.Length < 2) { MainConsole.Instance.InfoFormat( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}", startLocation, regionName); return null; } // Valid specification of a remote grid regionName = parts[0]; //Try now that we removed the domain locator GridRegion region = m_GridService.GetRegionByName(account.AllScopeIDs, regionName); if (region != null && region.RegionName == regionName) //Make sure the region name is right too... it could just be a similar name return region; List<GridRegion> defaults = m_GridService.GetDefaultRegions(account.AllScopeIDs); if (defaults != null && defaults.Count > 0) { where = "safe"; return defaults[0]; } else { List<GridRegion> fallbacks = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0); if (fallbacks != null && fallbacks.Count > 0) { where = "safe"; return fallbacks[0]; } else { //Try to find any safe region List<GridRegion> safeRegions = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0); if (safeRegions != null && safeRegions.Count > 0) { where = "safe"; return safeRegions[0]; } MainConsole.Instance.InfoFormat( "[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not have any available regions.", startLocation); return null; } } } }
public LoginResponse Login(UUID AgentID, string Name, string authType, string passwd, string startLocation, string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP, Hashtable requestData) { LoginResponse response; UUID session = UUID.Random(); UUID secureSession = UUID.Zero; MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login request for {0} from {1} with user agent {2} starting in {3}", Name, clientIP.Address, clientVersion, startLocation); UserAccount account = AgentID != UUID.Zero ? m_UserAccountService.GetUserAccount(null, AgentID) : m_UserAccountService.GetUserAccount(null, Name); if (account == null && m_AllowAnonymousLogin) { m_UserAccountService.CreateUser(Name, passwd.StartsWith("$1$") ? passwd.Remove(0, 3) : passwd, ""); account = m_UserAccountService.GetUserAccount(null, Name); } if (account == null) { MainConsole.Instance.InfoFormat("[LLOGIN SERVICE]: Login failed for user {0}: no account found", Name); return LLFailedLoginResponse.AccountProblem; } if (account.UserLevel < 0) //No allowing anyone less than 0 { MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login failed for user {0}, reason: user is banned", account.Name); return LLFailedLoginResponse.PermanentBannedProblem; } if (account.UserLevel < m_MinLoginLevel) { MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login failed for user {1}, reason: login is blocked for user level {0}", account.UserLevel, account.Name); return LLFailedLoginResponse.LoginBlockedProblem; } IAgentInfo agent = null; IAgentConnector agentData = Framework.Utilities.DataManager.RequestPlugin<IAgentConnector>(); if (agentData != null) agent = agentData.GetAgent(account.PrincipalID); if (agent == null) { agentData.CreateNewAgent(account.PrincipalID); agent = agentData.GetAgent(account.PrincipalID); } requestData["ip"] = clientIP.ToString(); foreach (ILoginModule module in LoginModules) { object data; if ((response = module.Login(requestData, account, agent, authType, passwd, out data)) != null) { MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login failed for user {1}, reason: {0}", (data != null ? data.ToString() : (response is LLFailedLoginResponse) ? (response as LLFailedLoginResponse).Value : "Unknown"), account.Name); return response; } if (data != null) secureSession = (UUID) data; //TODO: NEED TO FIND BETTER WAY TO GET THIS DATA } try { string DisplayName = account.Name; AvatarAppearance avappearance = null; IProfileConnector profileData = Framework.Utilities.DataManager.RequestPlugin<IProfileConnector>(); // // Get the user's inventory // if (m_RequireInventory && m_InventoryService == null) { MainConsole.Instance.WarnFormat( "[LLOGIN SERVICE]: Login failed for user {0}, reason: inventory service not set up", account.Name); return LLFailedLoginResponse.InventoryProblem; } List<InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel.Count == 0))) { List<InventoryItemBase> defaultItems; m_InventoryService.CreateUserInventory(account.PrincipalID, m_DefaultUserAvatarArchive == "", out defaultItems); inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel.Count == 0))) { MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login failed for user {0}, reason: unable to retrieve user inventory", account.Name); return LLFailedLoginResponse.InventoryProblem; } if (defaultItems.Count > 0) { avappearance = new AvatarAppearance(account.PrincipalID); avappearance.SetWearable((int)WearableType.Shape, new AvatarWearable(defaultItems[0].ID, defaultItems[0].AssetID)); avappearance.SetWearable((int)WearableType.Skin, new AvatarWearable(defaultItems[1].ID, defaultItems[1].AssetID)); avappearance.SetWearable((int)WearableType.Hair, new AvatarWearable(defaultItems[2].ID, defaultItems[2].AssetID)); avappearance.SetWearable((int)WearableType.Eyes, new AvatarWearable(defaultItems[3].ID, defaultItems[3].AssetID)); avappearance.SetWearable((int)WearableType.Shirt, new AvatarWearable(defaultItems[4].ID, defaultItems[4].AssetID)); avappearance.SetWearable((int)WearableType.Pants, new AvatarWearable(defaultItems[5].ID, defaultItems[5].AssetID)); m_AvatarService.SetAppearance(account.PrincipalID, avappearance); } } if (profileData != null) { IUserProfileInfo UPI = profileData.GetUserProfile(account.PrincipalID); if (UPI == null) { profileData.CreateNewProfile(account.PrincipalID); UPI = profileData.GetUserProfile(account.PrincipalID); UPI.AArchiveName = m_DefaultUserAvatarArchive; UPI.IsNewUser = true; //profileData.UpdateUserProfile(UPI); //It gets hit later by the next thing } //Find which is set, if any string archiveName = (UPI.AArchiveName != "" && UPI.AArchiveName != " ") ? UPI.AArchiveName : m_DefaultUserAvatarArchive; if (UPI.IsNewUser && archiveName != "") { AvatarArchive arch = m_ArchiveService.LoadAvatarArchive(archiveName, account.PrincipalID); UPI.AArchiveName = ""; if (arch != null) { avappearance = arch.Appearance; m_AvatarService.SetAppearance(account.PrincipalID, avappearance); //Must reload this, as we created a new folder inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); } } if (UPI.IsNewUser) { UPI.IsNewUser = false; profileData.UpdateUserProfile(UPI); } if (UPI.DisplayName != "") DisplayName = UPI.DisplayName; } // Get active gestures List<InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID); //MainConsole.Instance.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count); //Now get the logged in status, then below make sure to kill the previous agent if we crashed before UserInfo guinfo = m_agentInfoService.GetUserInfo(account.PrincipalID.ToString()); // // Clear out any existing CAPS the user may have // if (m_CapsService != null) { IAgentProcessing agentProcessor = m_registry.RequestModuleInterface<IAgentProcessing>(); if (agentProcessor != null) { IClientCapsService clientCaps = m_CapsService.GetClientCapsService(account.PrincipalID); if (clientCaps != null) { IRegionClientCapsService rootRegionCaps = clientCaps.GetRootCapsService(); if (rootRegionCaps != null) agentProcessor.LogoutAgent(rootRegionCaps, !m_AllowDuplicateLogin); } } else m_CapsService.RemoveCAPS(account.PrincipalID); } // // Change Online status and get the home region // GridRegion home = null; if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null) home = m_GridService.GetRegionByUUID(account.AllScopeIDs, guinfo.HomeRegionID); if (guinfo == null || guinfo.HomeRegionID == UUID.Zero) //Give them a default home and last { if (guinfo == null) guinfo = new UserInfo {UserID = account.PrincipalID.ToString()}; GridRegion DefaultRegion = null, FallbackRegion = null, SafeRegion = null; if (m_GridService != null) { if (m_DefaultHomeRegion != "") { DefaultRegion = m_GridService.GetRegionByName(account.AllScopeIDs, m_DefaultHomeRegion); if (DefaultRegion != null) guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID; } if (guinfo.HomeRegionID == UUID.Zero) { List<GridRegion> DefaultRegions = m_GridService.GetDefaultRegions(account.AllScopeIDs); DefaultRegion = DefaultRegions.Count == 0 ? null : DefaultRegions[0]; if (DefaultRegion != null) guinfo.HomeRegionID = guinfo.CurrentRegionID = DefaultRegion.RegionID; if (guinfo.HomeRegionID == UUID.Zero) { List<GridRegion> Fallback = m_GridService.GetFallbackRegions(account.AllScopeIDs, 0, 0); FallbackRegion = Fallback.Count == 0 ? null : Fallback[0]; if (FallbackRegion != null) guinfo.HomeRegionID = guinfo.CurrentRegionID = FallbackRegion.RegionID; if (guinfo.HomeRegionID == UUID.Zero) { List<GridRegion> Safe = m_GridService.GetSafeRegions(account.AllScopeIDs, 0, 0); SafeRegion = Safe.Count == 0 ? null : Safe[0]; if (SafeRegion != null) guinfo.HomeRegionID = guinfo.CurrentRegionID = SafeRegion.RegionID; } } } } guinfo.CurrentPosition = guinfo.HomePosition = new Vector3(128, 128, 25); guinfo.HomeLookAt = guinfo.CurrentLookAt = new Vector3(0, 0, 0); m_agentInfoService.SetHomePosition(guinfo.UserID, guinfo.HomeRegionID, guinfo.HomePosition, guinfo.HomeLookAt); MainConsole.Instance.Info("[LLLoginService]: User did not have a home, set to " + (guinfo.HomeRegionID == UUID.Zero ? "(no region found)" : guinfo.HomeRegionID.ToString())); } // // Find the destination region/grid // string where = string.Empty; Vector3 position = Vector3.Zero; Vector3 lookAt = Vector3.Zero; TeleportFlags tpFlags = TeleportFlags.ViaLogin; GridRegion destination = FindDestination(account, guinfo, session, startLocation, home, out tpFlags, out where, out position, out lookAt); if (destination == null) { MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: Login failed for user {0}, reason: destination not found", account.Name); return LLFailedLoginResponse.DeadRegionProblem; } #region Appearance // // Get the avatar // if (m_AvatarService != null) { bool loadedArchive; avappearance = m_AvatarService.GetAndEnsureAppearance(account.PrincipalID, m_DefaultUserAvatarArchive, out loadedArchive); if (loadedArchive) //Must reload this, as we created a new folder inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); } else avappearance = new AvatarAppearance(account.PrincipalID); if ((m_forceUserToWearFolderName != "") && (m_forceUserToWearFolderOwnerUUID.Length == 36)) { UUID userThatOwnersFolder; if (UUID.TryParse(m_forceUserToWearFolderOwnerUUID, out userThatOwnersFolder)) { avappearance = WearFolder(avappearance, account.PrincipalID, userThatOwnersFolder); } } //Makes sure that all links are properly placed in the current outfit folder for v2 viewers FixCurrentOutFitFolder(account.PrincipalID, ref avappearance); #endregion List<UUID> friendsToInform = new List<UUID>(); if (m_FriendsService != null) friendsToInform = m_FriendsService.GetFriendOnlineStatuses(account.PrincipalID, true); // // Instantiate/get the simulation interface and launch an agent at the destination // string reason = "", seedCap = ""; AgentCircuitData aCircuit = LaunchAgentAtGrid(destination, tpFlags, account, session, secureSession, position, where, clientIP, friendsToInform, out where, out reason, out seedCap, out destination); if (aCircuit == null) { MainConsole.Instance.InfoFormat("[LLOGIN SERVICE]: Login failed for user {1}, reason: {0}", reason, account.Name); return new LLFailedLoginResponse(LoginResponseEnum.InternalError, reason, false); } // Get Friends list List<FriendInfo> friendsList = new List<FriendInfo>(); if (m_FriendsService != null) friendsList = m_FriendsService.GetFriends(account.PrincipalID); //Set them as logged in now, they are ready, and fire the logged in event now, as we're all done m_agentInfoService.SetLastPosition(account.PrincipalID.ToString(), destination.RegionID, position, lookAt, destination.ServerURI); m_agentInfoService.SetLoggedIn(account.PrincipalID.ToString(), true, destination.RegionID, destination.ServerURI); m_agentInfoService.FireUserStatusChangeEvent(account.PrincipalID.ToString(), true, destination.RegionID); // // Finally, fill out the response and return it // string MaturityRating = "A"; string MaxMaturity = "A"; if (agent != null) { MaturityRating = agent.MaturityRating == 0 ? "P" : agent.MaturityRating == 1 ? "M" : "A"; MaxMaturity = agent.MaxMaturity == 0 ? "P" : agent.MaxMaturity == 1 ? "M" : "A"; } ArrayList eventNotifications = new ArrayList(); BuildEventNotifications(account.PrincipalID, ref eventNotifications); if (m_FriendsService != null) m_FriendsService.SendFriendOnlineStatuses(account.PrincipalID, true); response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList.ToArray(), m_InventoryService, m_LibraryService, where, startLocation, position, lookAt, gestures, home, clientIP, MaxMaturity, MaturityRating, eventCategories, eventNotifications, classifiedCategories, seedCap, m_config, DisplayName, avappearance.Serial.ToString(), m_registry.RequestModuleInterface<IGridInfo>()); MainConsole.Instance.InfoFormat( "[LLOGIN SERVICE]: All clear. Sending login response to client to login to region " + destination.RegionName + ", tried to login to " + startLocation + " at " + position.ToString() + "."); return response; } catch (Exception e) { MainConsole.Instance.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} : {1}", Name, e); if (account != null) { //Revert their logged in status if we got that far m_agentInfoService.SetLoggedIn(account.PrincipalID.ToString(), false, UUID.Zero, ""); } return LLFailedLoginResponse.InternalError; } }
public bool Set(UserInfo info) { object[] values = new object[14]; values[0] = info.UserID; values[1] = info.CurrentRegionID; values[2] = Util.ToUnixTime(DateTime.Now.ToUniversalTime()); //Convert to binary so that it can be converted easily values[3] = info.IsOnline ? 1 : 0; values[4] = Util.ToUnixTime(info.LastLogin); values[5] = Util.ToUnixTime(info.LastLogout); values[6] = OSDParser.SerializeJsonString(info.Info); values[7] = info.CurrentRegionID.ToString(); values[8] = info.CurrentPosition.ToString(); values[9] = info.CurrentLookAt.ToString(); values[10] = info.HomeRegionID.ToString(); values[11] = info.HomePosition.ToString(); values[12] = info.HomeLookAt.ToString(); values[13] = info.CurrentRegionURI; QueryFilter filter = new QueryFilter(); filter.andFilters["UserID"] = info.UserID; GD.Delete(m_realm, filter); return GD.Insert(m_realm, values); }
private static List<UserInfo> ParseQuery(List<string> query) { List<UserInfo> users = new List<UserInfo>(); if (query.Count%14 == 0) { for (int i = 0; i < query.Count; i += 14) { UserInfo user = new UserInfo { UserID = query[i], CurrentRegionID = UUID.Parse(query[i + 1]), IsOnline = query[i + 3] == "1", LastLogin = Util.ToDateTime(int.Parse(query[i + 4])), LastLogout = Util.ToDateTime(int.Parse(query[i + 5])), Info = (OSDMap) OSDParser.DeserializeJson(query[i + 6]) }; try { user.CurrentRegionID = UUID.Parse(query[i + 7]); if (query[i + 8] != "") user.CurrentPosition = Vector3.Parse(query[i + 8]); if (query[i + 9] != "") user.CurrentLookAt = Vector3.Parse(query[i + 9]); user.HomeRegionID = UUID.Parse(query[i + 10]); if (query[i + 11] != "") user.HomePosition = Vector3.Parse(query[i + 11]); if (query[i + 12] != "") user.HomeLookAt = Vector3.Parse(query[i + 12]); user.CurrentRegionURI = query[i + 13]; } catch { } users.Add(user); } } return users; }
public virtual void Save(UserInfo userInfo) { m_agentInfoConnector.Set(userInfo); }