From f4efa325bb8a1e4ae876ec5f080cf87c1f8c1de9 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 31 Dec 2009 11:42:33 -0800 Subject: More progress on both the Simulation service and the Login service. Both still unfinished. --- OpenSim/Services/LLLoginService/LLLoginService.cs | 162 +++++++++++++++++++++- 1 file changed, 160 insertions(+), 2 deletions(-) (limited to 'OpenSim/Services/LLLoginService') diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index 2c31ed5..4501da2 100644 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Text.RegularExpressions; using log4net; using Nini.Config; @@ -9,17 +10,24 @@ using OpenMetaverse; using OpenSim.Framework; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; +using GridRegion = OpenSim.Services.Interfaces.GridRegion; namespace OpenSim.Services.LLLoginService { public class LLLoginService : ILoginService { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private IUserAccountService m_UserAccountService; private IAuthenticationService m_AuthenticationService; private IInventoryService m_InventoryService; private IGridService m_GridService; private IPresenceService m_PresenceService; + private string m_DefaultRegionName; + private string m_LocalSimulationDll; + private string m_RemoteSimulationDll; + public LLLoginService(IConfigSource config) { IConfig serverConfig = config.Configs["LoginService"]; @@ -32,6 +40,10 @@ namespace OpenSim.Services.LLLoginService string gridService = serverConfig.GetString("GridService", String.Empty); string presenceService = serverConfig.GetString("PresenceService", String.Empty); + m_DefaultRegionName = serverConfig.GetString("DefaultRegion", String.Empty); + m_LocalSimulationDll = serverConfig.GetString("LocalSimulationService", String.Empty); + m_RemoteSimulationDll = serverConfig.GetString("RemoteSimulationService", String.Empty); + // These 3 are required; the other 2 aren't if (accountService == string.Empty || authService == string.Empty || invService == string.Empty) @@ -57,8 +69,8 @@ namespace OpenSim.Services.LLLoginService // Authenticate this user string token = m_AuthenticationService.Authenticate(account.PrincipalID, passwd, 30); - UUID session = UUID.Zero; - if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out session))) + UUID secureSession = UUID.Zero; + if ((token == string.Empty) || (token != string.Empty && !UUID.TryParse(token, out secureSession))) return LLFailedLoginResponse.UserProblem; // Get the user's inventory @@ -66,9 +78,155 @@ namespace OpenSim.Services.LLLoginService if ((inventorySkel == null) || (inventorySkel != null && inventorySkel.Count == 0)) return LLFailedLoginResponse.InventoryProblem; + // Login the presence + UUID session = UUID.Random(); + if (m_PresenceService != null) + { + bool success = m_PresenceService.LoginAgent(account.PrincipalID.ToString(), session, secureSession); + if (!success) + return LLFailedLoginResponse.GridProblem; + } + // lots of things missing... need to do the simulation service + string where = string.Empty; + Vector3 position = Vector3.Zero; + Vector3 lookAt = Vector3.Zero; + GridRegion destination = FindDestination(account, session, startLocation, out where, out position, out lookAt); + if (destination == null) + return LLFailedLoginResponse.GridProblem; + + ISimulationService sim = null; + Object[] args = new Object[] { destination }; + // HG standalones have both a localSimulatonDll and a remoteSimulationDll + // non-HG standalones have just a localSimulationDll + // independent login servers have just a remoteSimulationDll + if (!startLocation.Contains("@") && (m_LocalSimulationDll != string.Empty)) + sim = ServerUtils.LoadPlugin(m_LocalSimulationDll, args); + else + sim = ServerUtils.LoadPlugin(m_RemoteSimulationDll, args); + return null; } + + private GridRegion FindDestination(UserAccount account, UUID sessionID, string startLocation, out string where, out Vector3 position, out Vector3 lookAt) + { + where = "home"; + position = new Vector3(128, 128, 0); + lookAt = new Vector3(0, 1, 0); + if (startLocation.Equals("home")) + { + // logging into home region + if (m_PresenceService == null || m_GridService == null) + return null; + + GridRegion region = null; + PresenceInfo pinfo = m_PresenceService.GetAgent(sessionID); + // this should succeed; if it doesn't there's something wrong with this grid + if (pinfo == null) + return null; + + if (pinfo.HomeRegionID.Equals(UUID.Zero)) + region = m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); + else + region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.HomeRegionID); + + return region; + } + else if (startLocation.Equals("last")) + { + // logging into last visited region + where = "last"; + if (m_PresenceService == null || m_GridService == null) + return null; + + GridRegion region = null; + PresenceInfo pinfo = m_PresenceService.GetAgent(sessionID); + // this should succeed; if it doesn't there's something wrong with this grid + if (pinfo == null) + return null; + + if (pinfo.RegionID.Equals(UUID.Zero)) + region = m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); + else + { + region = m_GridService.GetRegionByUUID(account.ScopeID, pinfo.RegionID); + position = pinfo.Position; + lookAt = pinfo.LookAt; + } + return region; + + } + else + { + // free uri form + // e.g. New Moon&135&46 New Moon@osgrid.org:8002&153&34 + where = "url"; + Regex reURI = new Regex(@"^uri:(?[^&]+)&(?\d+)&(?\d+)&(?\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), + float.Parse(uriMatch.Groups["y"].Value), + float.Parse(uriMatch.Groups["z"].Value)); + + string regionName = uriMatch.Groups["region"].ToString(); + if (regionName != null) + { + if (!regionName.Contains("@")) + { + List regions = m_GridService.GetRegionsByName(account.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}", startLocation, regionName); + return null; + } + return regions[0]; + } + else + { + 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 = new GridRegion(); + region.ExternalHostName = domainName; + region.HttpPort = port; + region.RegionName = regionName; + return region; + } + + } + else + { + if (m_PresenceService == null || m_GridService == null) + return null; + + return m_GridService.GetRegionByName(account.ScopeID, m_DefaultRegionName); + + } + } + //response.LookAt = "[r0,r1,r0]"; + //// can be: last, home, safe, url + //response.StartLocation = "url"; + + } + + } } } -- cgit v1.1