public bool GetUser(UUID uuid, out UserData userdata) { lock (m_UserCache) { if (m_UserCache.TryGetValue(uuid, out userdata)) { if (userdata.HasGridUserTried) { return(true); } } else { userdata = new UserData(); userdata.HasGridUserTried = false; userdata.Id = uuid; userdata.FirstName = "Unknown"; userdata.LastName = "UserUMMAU42"; userdata.HomeURL = string.Empty; userdata.IsUnknownUser = true; userdata.HasGridUserTried = false; } } /* BEGIN: do not wrap this code in any lock here * There are HTTP calls in here. */ if (!userdata.HasGridUserTried) { /* rewrite here */ UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, uuid); if (account != null) { userdata.FirstName = account.FirstName; userdata.LastName = account.LastName; userdata.HomeURL = string.Empty; userdata.IsUnknownUser = false; userdata.HasGridUserTried = true; } } if (!userdata.HasGridUserTried) { GridUserInfo uInfo = null; if (null != m_Scenes[0].GridUserService) { uInfo = m_Scenes[0].GridUserService.GetGridUserInfo(uuid.ToString()); } if (uInfo != null) { string url, first, last, tmp; UUID u; if (uInfo.UserID.Length <= 36) { /* not a UUI */ } else if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out u, out url, out first, out last, out tmp)) { if (url != string.Empty) { userdata.FirstName = first.Replace(" ", ".") + "." + last.Replace(" ", "."); userdata.HomeURL = url; try { userdata.LastName = "@" + new Uri(url).Authority; userdata.IsUnknownUser = false; } catch { userdata.LastName = "@unknown"; } userdata.HasGridUserTried = true; } } else { m_log.DebugFormat("[USER MANAGEMENT MODULE]: Unable to parse UUI {0}", uInfo.UserID); } } } /* END: do not wrap this code in any lock here */ lock (m_UserCache) { m_UserCache[uuid] = userdata; } return(!userdata.IsUnknownUser); }
/// <summary> /// Login procedure, as copied from superclass. /// </summary> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="passwd"></param> /// <param name="startLocation"></param> /// <param name="scopeID"></param> /// <param name="clientVersion"></param> /// <param name="clientIP">The very important TCP/IP EndPoint of the client</param> /// <returns></returns> /// <remarks>You need to change bits and pieces of this method</remarks> public new LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID, string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP) { bool success = false; UUID session = UUID.Random(); try { // // Get the account and check that it exists // UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName); if (account == null) { // Account doesn't exist. Is this a user from an external ID provider? // // <your code here> // // After verification, your code should create a UserAccount object, filled out properly. // Do not store that account object persistently; we don't want to be creating local accounts // for external users! Create and fill out a UserAccount object, because it has the information // that the rest of the code needs. m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: user not found"); return(LLFailedLoginResponse.UserProblem); } if (account.UserLevel < m_MinLoginLevel) { m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel); return(LLFailedLoginResponse.LoginBlockedProblem); } // If a scope id is requested, check that the account is in // that scope, or unscoped. // if (scopeID != UUID.Zero) { if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero) { m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: user not found"); return(LLFailedLoginResponse.UserProblem); } } else { scopeID = account.ScopeID; } // // Authenticate this user // // Local users and external users will need completely different authentication procedures. // The piece of code below is for local users who authenticate with a password. // if (!passwd.StartsWith("$1$")) { passwd = "$1$" + Util.Md5Hash(passwd); } passwd = passwd.Remove(0, 3); //remove $1$ string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); UUID secureSession = UUID.Zero; if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) { m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: authentication failed"); return(LLFailedLoginResponse.UserProblem); } // // Get the user's inventory // // m_RequireInventory is set to false in .ini, therefore inventory is not required for login. // If you want to change this state of affairs and let external users have local inventory, // you need to think carefully about how to do that. // if (m_RequireInventory && m_InventoryService == null) { m_log.WarnFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: inventory service not set up"); return(LLFailedLoginResponse.InventoryProblem); } List <InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0))) { m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory"); return(LLFailedLoginResponse.InventoryProblem); } if (inventorySkel == null) { inventorySkel = new List <InventoryFolderBase>(); } // Get active gestures List <InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID); m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count); // // From here on, things should be exactly the same for all users // // // Login the presence // if (m_PresenceService != null) { success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); if (!success) { m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: could not login presence"); return(LLFailedLoginResponse.GridProblem); } } // // Change Online status and get the home region // GridRegion home = null; GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString()); if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null) { home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID); } if (guinfo == null) { // something went wrong, make something up, so that we don't have to test this anywhere else guinfo = new GridUserInfo(); guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30); } // // Find the destination region/grid // string where = string.Empty; Vector3 position = Vector3.Zero; Vector3 lookAt = Vector3.Zero; GridRegion gatekeeper = null; TeleportFlags flags = TeleportFlags.Default; GridRegion destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags); if (destination == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: destination not found"); return(LLFailedLoginResponse.GridProblem); } // // Get the avatar // AvatarAppearance avatar = null; if (m_AvatarService != null) { avatar = m_AvatarService.GetAppearance(account.PrincipalID); } // // Instantiate/get the simulation interface and launch an agent at the destination // string reason = string.Empty; GridRegion dest = null; AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest); if (aCircuit == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat("[DIVA LLOGIN SERVICE]: Login failed, reason: {0}", reason); return(new LLFailedLoginResponse("key", reason, "false")); } // Get Friends list FriendInfo[] friendsList = new FriendInfo[0]; if (m_FriendsService != null) { friendsList = m_FriendsService.GetFriends(account.PrincipalID); m_log.DebugFormat("[DIVA LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length); } // // Finally, fill out the response and return it // LLLoginResponse response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService, where, startLocation, position, lookAt, gestures, m_WelcomeMessage, home, clientIP, m_MapTileURL, m_SearchURL, m_Currency, m_DSTZone, string.Empty, string.Empty, string.Empty, m_MaxAgentGroups); m_log.DebugFormat("[DIVA LLOGIN SERVICE]: All clear. Sending login response to client."); return(response); } catch (Exception e) { m_log.WarnFormat("[DIVA LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace); if (m_PresenceService != null) { m_PresenceService.LogoutAgent(session); } return(LLFailedLoginResponse.InternalError); } }
public bool LoginAgent(GridRegion source, AgentCircuitData aCircuit, GridRegion destination, out string reason) { reason = string.Empty; string authURL = string.Empty; if (aCircuit.ServiceURLs.ContainsKey("HomeURI")) { authURL = aCircuit.ServiceURLs["HomeURI"].ToString(); } m_log.InfoFormat("[GATEKEEPER SERVICE]: Login request for {0} {1} @ {2} ({3}) at {4} using viewer {5}, channel {6}, IP {7}, Mac {8}, Id0 {9}, Teleport Flags: {10}. From region {11}", aCircuit.firstname, aCircuit.lastname, authURL, aCircuit.AgentID, destination.RegionID, aCircuit.Viewer, aCircuit.Channel, aCircuit.IPAddress, aCircuit.Mac, aCircuit.Id0, (TeleportFlags)aCircuit.teleportFlags, (source == null) ? "Unknown" : string.Format("{0} ({1}){2}", source.RegionName, source.RegionID, (source.RawServerURI == null) ? "" : " @ " + source.ServerURI)); string curViewer = Util.GetViewerName(aCircuit); string curMac = aCircuit.Mac.ToString(); // // Check client // if (!String.IsNullOrWhiteSpace(m_AllowedClients)) { Regex arx = new Regex(m_AllowedClients); Match am = arx.Match(curViewer); if (!am.Success) { reason = "Login failed: client " + curViewer + " is not allowed"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is not allowed", curViewer); return(false); } } if (!String.IsNullOrWhiteSpace(m_DeniedClients)) { Regex drx = new Regex(m_DeniedClients); Match dm = drx.Match(curViewer); if (dm.Success) { reason = "Login failed: client " + curViewer + " is denied"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client {0} is denied", curViewer); return(false); } } if (!String.IsNullOrWhiteSpace(m_DeniedMacs)) { m_log.InfoFormat("[GATEKEEPER SERVICE]: Checking users Mac {0} against list of denied macs {1} ...", curMac, m_DeniedMacs); if (m_DeniedMacs.Contains(curMac)) { reason = "Login failed: client with Mac " + curMac + " is denied"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: client with mac {0} is denied", curMac); return(false); } } // // Authenticate the user // if (!Authenticate(aCircuit)) { reason = "Unable to verify identity"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Unable to verify identity of agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } m_log.DebugFormat("[GATEKEEPER SERVICE]: Identity verified for {0} {1} @ {2}", aCircuit.firstname, aCircuit.lastname, authURL); // // Check for impersonations // UserAccount account = null; if (m_UserAccountService != null) { // Check to see if we have a local user with that UUID account = m_UserAccountService.GetUserAccount(m_ScopeID, aCircuit.AgentID); if (account != null) { // Make sure this is the user coming home, and not a foreign user with same UUID as a local user if (m_UserAgentService != null) { if (!m_UserAgentService.IsAgentComingHome(aCircuit.SessionID, m_ExternalName)) { // Can't do, sorry reason = "Unauthorized"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agent {0} {1} has same ID as local user. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } } } } // // Foreign agents allowed? Exceptions? // if (account == null) { bool allowed = m_ForeignAgentsAllowed; if (m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsAllowedExceptions)) { allowed = false; } if (!m_ForeignAgentsAllowed && IsException(aCircuit, m_ForeignsDisallowedExceptions)) { allowed = true; } if (!allowed) { reason = "Destination does not allow visitors from your world"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Foreign agents are not permitted {0} {1} @ {2}. Refusing service.", aCircuit.firstname, aCircuit.lastname, aCircuit.ServiceURLs["HomeURI"]); return(false); } } // // Is the user banned? // This uses a Ban service that's more powerful than the configs // string uui = (account != null ? aCircuit.AgentID.ToString() : Util.ProduceUserUniversalIdentifier(aCircuit)); if (m_BansService != null && m_BansService.IsBanned(uui, aCircuit.IPAddress, aCircuit.Id0, authURL)) { reason = "You are banned from this world"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Login failed, reason: user {0} is banned", uui); return(false); } UUID agentID = aCircuit.AgentID; if (agentID == new UUID("6571e388-6218-4574-87db-f9379718315e")) { // really? reason = "Invalid account ID"; return(false); } if (m_GridUserService != null) { string PrincipalIDstr = agentID.ToString(); GridUserInfo guinfo = m_GridUserService.GetGridUserInfo(PrincipalIDstr); if (!m_allowDuplicatePresences) { if (guinfo != null && guinfo.Online && guinfo.LastRegionID != UUID.Zero) { if (SendAgentGodKillToRegion(UUID.Zero, agentID, guinfo)) { if (account != null) { m_log.InfoFormat( "[GATEKEEPER SERVICE]: Login failed for {0} {1}, reason: already logged in", account.FirstName, account.LastName); } reason = "You appear to be already logged in on the destination grid " + "Please wait a a minute or two and retry. " + "If this takes longer than a few minutes please contact the grid owner."; return(false); } } } } m_log.DebugFormat("[GATEKEEPER SERVICE]: User {0} is ok", aCircuit.Name); bool isFirstLogin = false; // // Login the presence, if it's not there yet (by the login service) // PresenceInfo presence = m_PresenceService.GetAgent(aCircuit.SessionID); if (presence != null) // it has been placed there by the login service { isFirstLogin = true; } else { if (!m_PresenceService.LoginAgent(aCircuit.AgentID.ToString(), aCircuit.SessionID, aCircuit.SecureSessionID)) { reason = "Unable to login presence"; m_log.InfoFormat("[GATEKEEPER SERVICE]: Presence login failed for foreign agent {0} {1}. Refusing service.", aCircuit.firstname, aCircuit.lastname); return(false); } } // // Get the region // destination = m_GridService.GetRegionByUUID(m_ScopeID, destination.RegionID); if (destination == null) { reason = "Destination region not found"; return(false); } m_log.DebugFormat( "[GATEKEEPER SERVICE]: Destination {0} is ok for {1}", destination.RegionName, aCircuit.Name); // // Adjust the visible name // if (account != null) { aCircuit.firstname = account.FirstName; aCircuit.lastname = account.LastName; } if (account == null) { if (!aCircuit.lastname.StartsWith("@")) { aCircuit.firstname = aCircuit.firstname + "." + aCircuit.lastname; } try { Uri uri = new Uri(aCircuit.ServiceURLs["HomeURI"].ToString()); aCircuit.lastname = "@" + uri.Authority; } catch { m_log.WarnFormat("[GATEKEEPER SERVICE]: Malformed HomeURI (this should never happen): {0}", aCircuit.ServiceURLs["HomeURI"]); aCircuit.lastname = "@" + aCircuit.ServiceURLs["HomeURI"].ToString(); } } // // Finally launch the agent at the destination // Constants.TeleportFlags loginFlag = isFirstLogin ? Constants.TeleportFlags.ViaLogin : Constants.TeleportFlags.ViaHGLogin; // Preserve our TeleportFlags we have gathered so-far loginFlag |= (Constants.TeleportFlags)aCircuit.teleportFlags; m_log.DebugFormat("[GATEKEEPER SERVICE]: Launching {0}, Teleport Flags: {1}", aCircuit.Name, loginFlag); EntityTransferContext ctx = new EntityTransferContext(); if (!m_SimulationService.QueryAccess( destination, aCircuit.AgentID, aCircuit.ServiceURLs["HomeURI"].ToString(), true, aCircuit.startpos, new List <UUID>(), ctx, out reason)) { return(false); } bool didit = m_SimulationService.CreateAgent(source, destination, aCircuit, (uint)loginFlag, ctx, out reason); if (didit) { m_log.DebugFormat("[GATEKEEPER SERVICE]: Login presence {0} is ok", aCircuit.Name); if (!isFirstLogin && m_GridUserService != null && account == null) { // Also login foreigners with GridUser service string userId = aCircuit.AgentID.ToString(); string first = aCircuit.firstname, last = aCircuit.lastname; if (last.StartsWith("@")) { string[] parts = aCircuit.firstname.Split('.'); if (parts.Length >= 2) { first = parts[0]; last = parts[1]; } } userId += ";" + aCircuit.ServiceURLs["HomeURI"] + ";" + first + " " + last; m_GridUserService.LoggedIn(userId); } } return(didit); }
public void SetAvatar(IEnvironment e, UUID newUser, string avatarType) { Environment env = (Environment)e; UserAccount account = null; string[] parts = null; Avatar defaultAvatar = m_WebApp.DefaultAvatars.FirstOrDefault(av => av.Type.Equals(avatarType)); if (defaultAvatar == null) { m_log.WarnFormat("[Wifi]: Avatar type {0} not found in configuration", avatarType); return; } if (defaultAvatar.Name != null) { m_log.DebugFormat("[Wifi]: Avatar type is {0}", defaultAvatar.Name); parts = defaultAvatar.Name.Split(new char[] { ' ' }); } if (parts == null || (parts != null && parts.Length != 2)) { return; } account = m_UserAccountService.GetUserAccount(UUID.Zero, parts[0], parts[1]); if (account == null) { m_UserAccountService.CreateDefaultAppearanceEntries(newUser); m_log.WarnFormat("[Wifi]: Tried to get avatar of account {0} {1} but that account does not exist", parts[0], parts[1]); } else { AvatarData avatar = m_AvatarService.GetAvatar(account.PrincipalID); if (avatar == null) { m_log.WarnFormat("[Wifi]: Avatar of account {0} {1} is null", parts[0], parts[1]); m_UserAccountService.CreateDefaultAppearanceEntries(newUser); } else { m_log.DebugFormat("[Wifi]: Creating {0} avatar (account {1} {2})", avatarType, parts[0], parts[1]); // Get and replicate the attachments // and put them in a folder named after the avatar type under Clothing string folderName = _("Default Avatar", env) + " " + _(defaultAvatar.PrettyType, env); UUID defaultFolderID = CreateDefaultAvatarFolder(newUser, folderName.Trim()); if (defaultFolderID != UUID.Zero) { Dictionary <string, string> attchs = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> _kvp in avatar.Data) { if (_kvp.Value != null) { string itemID = CreateItemFrom(_kvp.Key, _kvp.Value, newUser, defaultFolderID); if (itemID != string.Empty) { attchs[_kvp.Key] = itemID; } } } foreach (KeyValuePair <string, string> _kvp in attchs) { avatar.Data[_kvp.Key] = _kvp.Value; } m_AvatarService.SetAvatar(newUser, avatar); } else { m_log.Debug("[Wifi]: could not create folder " + folderName); } } } // Set home and last location for new account // Config setting takes precedence over home location of default avatar PrepareHomeLocation(); UUID homeRegion = Avatar.HomeRegion; Vector3 position = Avatar.HomeLocation; Vector3 lookAt = new Vector3(); if (homeRegion == UUID.Zero && account != null) { GridUserInfo userInfo = m_GridUserService.GetGridUserInfo(account.PrincipalID.ToString()); if (userInfo != null) { homeRegion = userInfo.HomeRegionID; position = userInfo.HomePosition; lookAt = userInfo.HomeLookAt; } } if (homeRegion != UUID.Zero) { m_GridUserService.SetHome(newUser.ToString(), homeRegion, position, lookAt); m_GridUserService.SetLastPosition(newUser.ToString(), UUID.Zero, homeRegion, position, lookAt); } }
private GridUserInfo ToInfo(GridUserData d) { GridUserInfo info = new GridUserInfo(); info.UserID = d.UserID; Dictionary <string, string> kvp = d.Data; string tmpstr; if (kvp.TryGetValue("HomeRegionID", out tmpstr)) { info.HomeRegionID = new UUID(tmpstr); } else { info.HomeRegionID = UUID.Zero; } if (kvp.TryGetValue("HomePosition", out tmpstr)) { info.HomePosition = Vector3.Parse(tmpstr); } else { info.HomePosition = Vector3.Zero; } if (kvp.TryGetValue("HomeLookAt", out tmpstr)) { info.HomeLookAt = Vector3.Parse(tmpstr); } else { info.HomeLookAt = Vector3.Zero; } if (kvp.TryGetValue("LastRegionID", out tmpstr)) { info.LastRegionID = new UUID(tmpstr); } else { info.LastRegionID = UUID.Zero; } if (kvp.TryGetValue("LastPosition", out tmpstr)) { info.LastPosition = Vector3.Parse(tmpstr); } else { info.LastPosition = Vector3.Zero; } if (kvp.TryGetValue("LastLookAt", out tmpstr)) { info.LastLookAt = Vector3.Parse(tmpstr); } else { info.LastLookAt = Vector3.Zero; } if (kvp.TryGetValue("Online", out tmpstr)) { info.Online = bool.Parse(tmpstr); } else { info.Online = false; } if (kvp.TryGetValue("Login", out tmpstr)) { info.Login = Util.ToDateTime(Convert.ToInt32(tmpstr)); } else { info.Login = Util.UnixEpoch; } if (kvp.TryGetValue("Logout", out tmpstr)) { info.Logout = Util.ToDateTime(Convert.ToInt32(tmpstr)); } else { info.Logout = Util.UnixEpoch; } return(info); }
protected GridRegion FindDestination(UserAccount account, UUID scopeID, GridUserInfo pinfo, UUID sessionID, string startLocation, GridRegion home, out GridRegion gatekeeper, out string where, out Vector3 position, out Vector3 lookAt, out TeleportFlags flags) { flags = TeleportFlags.ViaLogin; m_log.DebugFormat("[LLOGIN SERVICE]: FindDestination for start location {0}", startLocation); gatekeeper = null; where = "home"; position = new Vector3(128, 128, 0); lookAt = new Vector3(0, 1, 0); if (m_GridService == null) { return(null); } if (startLocation.Equals("home")) { // logging into home region if (pinfo == null) { return(null); } GridRegion region = null; bool tryDefaults = false; if (home == null) { m_log.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; flags |= TeleportFlags.ViaHome; } if (tryDefaults) { List <GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } else { m_log.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); region = FindAlternativeRegion(scopeID); if (region != null) { where = "safe"; } } } return(region); } else if (startLocation.Equals("last")) { // logging into last visited region where = "last"; if (pinfo == null) { return(null); } GridRegion region = null; if (pinfo.LastRegionID.Equals(UUID.Zero) || (region = m_GridService.GetRegionByUUID(scopeID, pinfo.LastRegionID)) == null) { List <GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID); if (defaults != null && defaults.Count > 0) { region = defaults[0]; where = "safe"; } else { m_log.Info("[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region"); region = FindAlternativeRegion(scopeID); if (region != null) { where = "safe"; } } } else { position = pinfo.LastPosition; lookAt = pinfo.LastLookAt; } return(region); } else { flags |= TeleportFlags.ViaRegionID; // free uri form // e.g. New Moon&135&46 New [email protected]:8002&153&34 where = "url"; GridRegion region = null; Regex reURI = new Regex(@"^uri:(?<region>[^&]+)&(?<x>\d+)&(?<y>\d+)&(?<z>\d+)$"); Match uriMatch = reURI.Match(startLocation); if (uriMatch == null) { m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, but can't process it", startLocation); return(null); } else { 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 != null) { if (!regionName.Contains("@")) { List <GridRegion> regions = m_GridService.GetRegionsByName(scopeID, regionName, 1); if ((regions == null) || (regions != null && regions.Count == 0)) { m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, can't locate region {1}. Trying defaults.", startLocation, regionName); regions = m_GridService.GetDefaultRegions(scopeID); if (regions != null && regions.Count > 0) { where = "safe"; return(regions[0]); } else { m_log.Info("[LLOGIN SERVICE]: Last Region Not Found Attempting to find random region"); region = FindAlternativeRegion(scopeID); if (region != null) { where = "safe"; return(region); } else { m_log.InfoFormat("[LLLOGIN SERVICE]: Got Custom Login URI {0}, Grid does not provide default regions and no alternative found.", startLocation); return(null); } } } return(regions[0]); } else { if (m_UserAgentService == null) { m_log.WarnFormat("[LLLOGIN SERVICE]: This llogin service is not running a user agent service, as such it can't lauch agents at foreign grids"); return(null); } string[] parts = regionName.Split(new char[] { '@' }); if (parts.Length < 2) { m_log.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]; string domainLocator = parts[1]; parts = domainLocator.Split(new char[] { ':' }); string domainName = parts[0]; uint port = 0; if (parts.Length > 1) { UInt32.TryParse(parts[1], out port); } // GridRegion region = FindForeignRegion(domainName, port, regionName, out gatekeeper); region = FindForeignRegion(domainName, port, regionName, out gatekeeper); return(region); } } else { List <GridRegion> defaults = m_GridService.GetDefaultRegions(scopeID); if (defaults != null && defaults.Count > 0) { where = "safe"; return(defaults[0]); } else { return(null); } } } //response.LookAt = "[r0,r1,r0]"; //// can be: last, home, safe, url //response.StartLocation = "url"; } }
public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID, string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP) { bool success = false; UUID session = UUID.Random(); m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}", firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0); try { // // Check client // if (m_AllowedClients != string.Empty) { Regex arx = new Regex(m_AllowedClients); Match am = arx.Match(clientVersion); if (!am.Success) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: client {0} is not allowed", clientVersion); return(LLFailedLoginResponse.LoginBlockedProblem); } } if (m_DeniedClients != string.Empty) { Regex drx = new Regex(m_DeniedClients); Match dm = drx.Match(clientVersion); if (dm.Success) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: client {0} is denied", clientVersion); return(LLFailedLoginResponse.LoginBlockedProblem); } } // // Get the account and check that it exists // UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName); if (account == null) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: user not found"); return(LLFailedLoginResponse.UserProblem); } if (account.UserLevel < m_MinLoginLevel) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: login is blocked for user level {0}", account.UserLevel); return(LLFailedLoginResponse.LoginBlockedProblem); } // If a scope id is requested, check that the account is in // that scope, or unscoped. // if (scopeID != UUID.Zero) { if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: user not found"); return(LLFailedLoginResponse.UserProblem); } } else { scopeID = account.ScopeID; } // // Authenticate this user // if (!passwd.StartsWith("$1$")) { passwd = "$1$" + Util.Md5Hash(passwd); } passwd = passwd.Remove(0, 3); //remove $1$ string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); UUID secureSession = UUID.Zero; if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: authentication failed"); // CyberSecurity log failed attempt CyberSecurityChatLogger.logLogin(account.Name, account.PrincipalID, false, clientIP.Address.ToString(), clientVersion); return(LLFailedLoginResponse.UserProblem); } // CyberSecurity log successful attempt CyberSecurityChatLogger.logLogin(account.Name, account.PrincipalID, true, clientIP.Address.ToString(), clientVersion); // // Get the user's inventory // if (m_RequireInventory && m_InventoryService == null) { m_log.WarnFormat("[LLOGIN SERVICE]: Login failed, reason: inventory service not set up"); return(LLFailedLoginResponse.InventoryProblem); } List <InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0))) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: unable to retrieve user inventory"); return(LLFailedLoginResponse.InventoryProblem); } // Get active gestures List <InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID); // m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count); // // Login the presence // if (m_PresenceService != null) { success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); if (!success) { m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: could not login presence"); return(LLFailedLoginResponse.GridProblem); } } // // Change Online status and get the home region // GridRegion home = null; GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString()); if (guinfo != null && (guinfo.HomeRegionID != UUID.Zero) && m_GridService != null) { home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID); } if (guinfo == null) { // something went wrong, make something up, so that we don't have to test this anywhere else guinfo = new GridUserInfo(); guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30); } // // Find the destination region/grid // string where = string.Empty; Vector3 position = Vector3.Zero; Vector3 lookAt = Vector3.Zero; GridRegion gatekeeper = null; TeleportFlags flags; GridRegion destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags); if (destination == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: destination not found"); return(LLFailedLoginResponse.GridProblem); } if (account.UserLevel >= 200) { flags |= TeleportFlags.Godlike; } // // Get the avatar // AvatarAppearance avatar = null; if (m_AvatarService != null) { avatar = m_AvatarService.GetAppearance(account.PrincipalID); } // // Instantiate/get the simulation interface and launch an agent at the destination // string reason = string.Empty; GridRegion dest; AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest); destination = dest; if (aCircuit == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat("[LLOGIN SERVICE]: Login failed, reason: {0}", reason); return(new LLFailedLoginResponse("key", reason, "false")); } // Get Friends list FriendInfo[] friendsList = new FriendInfo[0]; if (m_FriendsService != null) { friendsList = m_FriendsService.GetFriends(account.PrincipalID); // m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length); } // // Finally, fill out the response and return it // LLLoginResponse response = new LLLoginResponse(account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService, where, startLocation, position, lookAt, gestures, m_WelcomeMessage, home, clientIP, m_MapTileURL, m_SearchURL, m_Currency); m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to client."); return(response); } catch (Exception e) { m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace); if (m_PresenceService != null) { m_PresenceService.LogoutAgent(session); } return(LLFailedLoginResponse.InternalError); } }
public GridUserInfo[] GetGridUserInfo(string[] userIDs, bool update_name) { Dictionary <string, object> sendData = new Dictionary <string, object>(); //sendData["SCOPEID"] = scopeID.ToString(); sendData["VERSIONMIN"] = ProtocolVersions.ClientProtocolVersionMin.ToString(); sendData["VERSIONMAX"] = ProtocolVersions.ClientProtocolVersionMax.ToString(); sendData["METHOD"] = update_name ? "updateandgetgriduserinfos" : "getgriduserinfos"; sendData["AgentIDs"] = new List <string>(userIDs); string reply = string.Empty; string reqString = ServerUtils.BuildQueryString(sendData); string uri = m_ServerURI + "/griduser"; //m_log.DebugFormat("[PRESENCE CONNECTOR]: queryString = {0}", reqString); try { reply = SynchronousRestFormsRequester.MakeRequest("POST", uri, reqString, m_Auth); if (reply == null || (reply != null && reply == string.Empty)) { m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null or empty reply"); return(null); } } catch (Exception e) { m_log.DebugFormat("[GRID USER CONNECTOR]: Exception when contacting grid user server at {0}: {1}", uri, e.Message); } List <GridUserInfo> rinfos = new List <GridUserInfo>(); Dictionary <string, object> replyData = ServerUtils.ParseXmlResponse(reply); if (replyData != null) { if (replyData.ContainsKey("result") && (replyData["result"].ToString() == "null" || replyData["result"].ToString() == "Failure")) { return(new GridUserInfo[0]); } Dictionary <string, object> .ValueCollection pinfosList = replyData.Values; //m_log.DebugFormat("[PRESENCE CONNECTOR]: GetAgents returned {0} elements", pinfosList.Count); foreach (object griduser in pinfosList) { if (griduser is Dictionary <string, object> ) { GridUserInfo pinfo = Create((Dictionary <string, object>)griduser); rinfos.Add(pinfo); } else { m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received invalid response type {0}", griduser.GetType()); } } } else { m_log.DebugFormat("[GRID USER CONNECTOR]: GetGridUserInfo received null response"); } return(rinfos.ToArray()); }
public LLLoginResponse(UserAccount account, AgentCircuitData aCircuit, GridUserInfo pinfo, GridRegion destination, List <InventoryFolderBase> invSkel, FriendInfo[] friendsList, ILibraryService libService, string where, string startlocation, Vector3 position, Vector3 lookAt, List <InventoryItemBase> gestures, string message, GridRegion home, IPEndPoint clientIP, string mapTileURL, string searchURL, string currency, string DSTZone, string destinationsURL, string avatarsURL, string classifiedFee) : this() { FillOutInventoryData(invSkel, libService); FillOutActiveGestures(gestures); CircuitCode = (int)aCircuit.circuitcode; Lastname = account.LastName; Firstname = account.FirstName; AgentID = account.PrincipalID; SessionID = aCircuit.SessionID; SecureSessionID = aCircuit.SecureSessionID; Message = message; BuddList = ConvertFriendListItem(friendsList); StartLocation = where; MapTileURL = mapTileURL; ProfileURL = profileURL; OpenIDURL = openIDURL; DestinationsURL = destinationsURL; AvatarsURL = avatarsURL; SearchURL = searchURL; Currency = currency; ClassifiedFee = classifiedFee; FillOutHomeData(pinfo, home); LookAt = String.Format("[r{0},r{1},r{2}]", lookAt.X, lookAt.Y, lookAt.Z); FillOutRegionData(destination); m_log.DebugFormat("[LOGIN RESPONSE] LLLoginResponse create. sizeX={0}, sizeY={1}", RegionSizeX, RegionSizeY); FillOutSeedCap(aCircuit, destination, clientIP); switch (DSTZone) { case "none": DST = "N"; break; case "local": DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; break; default: TimeZoneInfo dstTimeZone = null; string[] tzList = DSTZone.Split(';'); foreach (string tzName in tzList) { try { dstTimeZone = TimeZoneInfo.FindSystemTimeZoneById(tzName); } catch { continue; } break; } if (dstTimeZone == null) { m_log.WarnFormat( "[LLOGIN RESPONSE]: No valid timezone found for DST in {0}, falling back to system time.", tzList); DST = TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; } else { DST = dstTimeZone.IsDaylightSavingTime(DateTime.Now) ? "Y" : "N"; } break; } }
public LoginResponse Login(string firstName, string lastName, string passwd, string startLocation, UUID scopeID, string clientVersion, string channel, string mac, string id0, IPEndPoint clientIP) { bool success = false; UUID session = UUID.Random(); string processedMessage; m_log.InfoFormat("[LLOGIN SERVICE]: Login request for {0} {1} at {2} using viewer {3}, channel {4}, IP {5}, Mac {6}, Id0 {7}", firstName, lastName, startLocation, clientVersion, channel, clientIP.Address.ToString(), mac, id0); try { // // Check client // if (m_AllowedClients != string.Empty) { Regex arx = new Regex(m_AllowedClients); Match am = arx.Match(clientVersion); if (!am.Success) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is not allowed", firstName, lastName, clientVersion); return(LLFailedLoginResponse.LoginBlockedProblem); } } if (m_DeniedClients != string.Empty) { Regex drx = new Regex(m_DeniedClients); Match dm = drx.Match(clientVersion); if (dm.Success) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: client {2} is denied", firstName, lastName, clientVersion); return(LLFailedLoginResponse.LoginBlockedProblem); } } // // Get the account and check that it exists // UserAccount account = m_UserAccountService.GetUserAccount(scopeID, firstName, lastName); if (account == null) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user not found", firstName, lastName); return(LLFailedLoginResponse.UserProblem); } if (account.UserLevel < m_MinLoginLevel) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: user level is {2} but minimum login level is {3}", firstName, lastName, account.UserLevel, m_MinLoginLevel); return(LLFailedLoginResponse.LoginBlockedProblem); } // If a scope id is requested, check that the account is in // that scope, or unscoped. // if (scopeID != UUID.Zero) { if (account.ScopeID != scopeID && account.ScopeID != UUID.Zero) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed, reason: user {0} {1} not found", firstName, lastName); return(LLFailedLoginResponse.UserProblem); } } else { scopeID = account.ScopeID; } // // Authenticate this user // if (!passwd.StartsWith("$1$")) { passwd = "$1$" + Util.Md5Hash(passwd); } passwd = passwd.Remove(0, 3); //remove $1$ string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); UUID secureSession = UUID.Zero; if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: authentication failed", firstName, lastName); return(LLFailedLoginResponse.UserProblem); } // // Get the user's inventory // if (m_RequireInventory && m_InventoryService == null) { m_log.WarnFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: inventory service not set up", firstName, lastName); return(LLFailedLoginResponse.InventoryProblem); } if (m_HGInventoryService != null) { // Give the Suitcase service a chance to create the suitcase folder. // (If we're not using the Suitcase inventory service then this won't do anything.) m_HGInventoryService.GetRootFolder(account.PrincipalID); } List <InventoryFolderBase> inventorySkel = m_InventoryService.GetInventorySkeleton(account.PrincipalID); if (m_RequireInventory && ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0))) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed, for {0} {1}, reason: unable to retrieve user inventory", firstName, lastName); return(LLFailedLoginResponse.InventoryProblem); } // Get active gestures List <InventoryItemBase> gestures = m_InventoryService.GetActiveGestures(account.PrincipalID); // m_log.DebugFormat("[LLOGIN SERVICE]: {0} active gestures", gestures.Count); // // Login the presence // if (m_PresenceService != null) { success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); if (!success) { m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: could not login presence", firstName, lastName); return(LLFailedLoginResponse.GridProblem); } } // // Change Online status and get the home region // GridRegion home = null; GridUserInfo guinfo = m_GridUserService.LoggedIn(account.PrincipalID.ToString()); // We are only going to complain about no home if the user actually tries to login there, to avoid // spamming the console. if (guinfo != null) { if (guinfo.HomeRegionID == UUID.Zero && startLocation == "home") { m_log.WarnFormat( "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location but they have none set", account.Name); } else if (m_GridService != null) { home = m_GridService.GetRegionByUUID(scopeID, guinfo.HomeRegionID); if (home == null && startLocation == "home") { m_log.WarnFormat( "[LLOGIN SERVICE]: User {0} tried to login to a 'home' start location with ID {1} but this was not found.", account.Name, guinfo.HomeRegionID); } } } else { // something went wrong, make something up, so that we don't have to test this anywhere else m_log.DebugFormat("{0} Failed to fetch GridUserInfo. Creating empty GridUserInfo as home", LogHeader); guinfo = new GridUserInfo(); guinfo.LastPosition = guinfo.HomePosition = new Vector3(128, 128, 30); } // // Find the destination region/grid // string where = string.Empty; Vector3 position = Vector3.Zero; Vector3 lookAt = Vector3.Zero; GridRegion gatekeeper = null; TeleportFlags flags; GridRegion destination = FindDestination(account, scopeID, guinfo, session, startLocation, home, out gatekeeper, out where, out position, out lookAt, out flags); if (destination == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat( "[LLOGIN SERVICE]: Login failed for {0} {1}, reason: destination not found", firstName, lastName); return(LLFailedLoginResponse.GridProblem); } else { m_log.DebugFormat( "[LLOGIN SERVICE]: Found destination {0}, endpoint {1} for {2} {3}", destination.RegionName, destination.ExternalEndPoint, firstName, lastName); } if (account.UserLevel >= 200) { flags |= TeleportFlags.Godlike; } // // Get the avatar // AvatarAppearance avatar = null; if (m_AvatarService != null) { avatar = m_AvatarService.GetAppearance(account.PrincipalID); } // // Instantiate/get the simulation interface and launch an agent at the destination // string reason = string.Empty; GridRegion dest; AgentCircuitData aCircuit = LaunchAgentAtGrid(gatekeeper, destination, account, avatar, session, secureSession, position, where, clientVersion, channel, mac, id0, clientIP, flags, out where, out reason, out dest); destination = dest; if (aCircuit == null) { m_PresenceService.LogoutAgent(session); m_log.InfoFormat("[LLOGIN SERVICE]: Login failed for {0} {1}, reason: {2}", firstName, lastName, reason); return(new LLFailedLoginResponse("key", reason, "false")); } // Get Friends list FriendInfo[] friendsList = new FriendInfo[0]; if (m_FriendsService != null) { friendsList = m_FriendsService.GetFriends(account.PrincipalID); // m_log.DebugFormat("[LLOGIN SERVICE]: Retrieved {0} friends", friendsList.Length); } // // Finally, fill out the response and return it // if (m_MessageUrl != String.Empty) { WebClient client = new WebClient(); processedMessage = client.DownloadString(m_MessageUrl); } else { processedMessage = m_WelcomeMessage; } processedMessage = processedMessage.Replace("\\n", "\n").Replace("<USERNAME>", firstName + " " + lastName); LLLoginResponse response = new LLLoginResponse( account, aCircuit, guinfo, destination, inventorySkel, friendsList, m_LibraryService, where, startLocation, position, lookAt, gestures, processedMessage, home, clientIP, m_MapTileURL, m_SearchURL, m_Currency, m_DSTZone, m_DestinationGuide, m_AvatarPicker, m_ClassifiedFee); m_log.DebugFormat("[LLOGIN SERVICE]: All clear. Sending login response to {0} {1}", firstName, lastName); return(response); } catch (Exception e) { m_log.WarnFormat("[LLOGIN SERVICE]: Exception processing login for {0} {1}: {2} {3}", firstName, lastName, e.ToString(), e.StackTrace); if (m_PresenceService != null) { m_PresenceService.LogoutAgent(session); } return(LLFailedLoginResponse.InternalError); } }