From f7eac63e01d957bd9c115ac0f55d1dd6109f6aea Mon Sep 17 00:00:00 2001 From: diva Date: Sun, 29 Mar 2009 22:04:45 +0000 Subject: [PATCH] Another bit of refactoring to try to make sense of OpenSim.Framework.Communications. Everything that looks like a service, with service handlers, moved to .Services -- i.e. LoginService and Response, and GridInfoService. The rest of the changes were to adapt to the new locations of those files. --- .../CreateCommsManagerPlugin.cs | 3 +- .../Client/Linden/LLStandaloneLoginService.cs | 1 + .../{ => Services}/GridInfoService.cs | 344 +-- .../Services/HGInventoryService.cs | 33 +- .../{ => Services}/LoginResponse.cs | 1624 ++++++------ .../{ => Services}/LoginService.cs | 2186 ++++++++--------- .../Communications/Tests/LoginServiceTests.cs | 1 + .../GridInfoServiceModule.cs | 1 + .../UserServer.Modules/UserLoginService.cs | 1 + OpenSim/Region/Application/OpenSimBase.cs | 1 + .../Hypergrid/HGCommunicationsGridMode.cs | 2 +- .../Hypergrid/HGInventoryService.cs | 4 +- 12 files changed, 2114 insertions(+), 2087 deletions(-) rename OpenSim/Framework/Communications/{ => Services}/GridInfoService.cs (96%) rename OpenSim/Framework/Communications/{ => Services}/LoginResponse.cs (97%) rename OpenSim/Framework/Communications/{ => Services}/LoginService.cs (97%) diff --git a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs index 3bf87b36e4..70803c874c 100644 --- a/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs +++ b/OpenSim/ApplicationPlugins/CreateCommsManager/CreateCommsManagerPlugin.cs @@ -30,6 +30,7 @@ using System.Reflection; using log4net; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Services; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Servers; using OpenSim.Region.Communications.Hypergrid; @@ -210,7 +211,7 @@ namespace OpenSim.ApplicationPlugins.CreateCommsManager { // Standalone mode - HGInventoryService inventoryService = new HGInventoryService(m_openSim.NetServersInfo.InventoryURL, null, false); + HGInventoryServiceClient inventoryService = new HGInventoryServiceClient(m_openSim.NetServersInfo.InventoryURL, null, false); inventoryService.AddPlugin(m_openSim.ConfigurationSettings.StandaloneInventoryPlugin, m_openSim.ConfigurationSettings.StandaloneInventorySource); LocalUserServices userService = diff --git a/OpenSim/Client/Linden/LLStandaloneLoginService.cs b/OpenSim/Client/Linden/LLStandaloneLoginService.cs index e6949a611e..5e286e2007 100644 --- a/OpenSim/Client/Linden/LLStandaloneLoginService.cs +++ b/OpenSim/Client/Linden/LLStandaloneLoginService.cs @@ -36,6 +36,7 @@ using Nini.Config; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Services; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Capabilities; using OpenSim.Framework.Servers; diff --git a/OpenSim/Framework/Communications/GridInfoService.cs b/OpenSim/Framework/Communications/Services/GridInfoService.cs similarity index 96% rename from OpenSim/Framework/Communications/GridInfoService.cs rename to OpenSim/Framework/Communications/Services/GridInfoService.cs index 4ad447d5c2..96fe0d83f6 100644 --- a/OpenSim/Framework/Communications/GridInfoService.cs +++ b/OpenSim/Framework/Communications/Services/GridInfoService.cs @@ -1,172 +1,172 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.IO; -using System.Reflection; -using System.Text; -using log4net; -using Nini.Config; -using Nwc.XmlRpc; -using OpenSim.Framework.Servers; - -namespace OpenSim.Framework.Communications -{ - public class GridInfoService - { - private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Hashtable _info = new Hashtable(); - - /// - /// Instantiate a GridInfoService object. - /// - /// path to config path containing - /// grid information - /// - /// GridInfoService uses the [GridInfo] section of the - /// standard OpenSim.ini file --- which is not optimal, but - /// anything else requires a general redesign of the config - /// system. - /// - public GridInfoService(IConfigSource configSource) - { - loadGridInfo(configSource); - } - - /// - /// Default constructor, uses OpenSim.ini. - /// - public GridInfoService() - { - try - { - IConfigSource configSource = new IniConfigSource(Path.Combine(Util.configDir(), "OpenSim.ini")); - loadGridInfo(configSource); - } - catch (FileNotFoundException) - { - _log.Warn("[GridInfoService] no OpenSim.ini file found --- GridInfoServices WILL NOT BE AVAILABLE to your users"); - } - } - - private void loadGridInfo(IConfigSource configSource) - { - _info["platform"] = "OpenSim"; - try - { - IConfig startupCfg = configSource.Configs["Startup"]; - IConfig gridCfg = configSource.Configs["GridInfo"]; - IConfig netCfg = configSource.Configs["Network"]; - - bool grid = startupCfg.GetBoolean("gridmode", false); - - if (grid) - _info["mode"] = "grid"; - else - _info["mode"] = "standalone"; - - - if (null != gridCfg) - { - foreach (string k in gridCfg.GetKeys()) - { - _info[k] = gridCfg.GetString(k); - } - } - else if (null != netCfg) - { - if (grid) - _info["login"] - = netCfg.GetString( - "user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString()); - else - _info["login"] - = String.Format( - "http://127.0.0.1:{0}/", - netCfg.GetString( - "http_listener_port", NetworkServersInfo.DefaultHttpListenerPort.ToString())); - - IssueWarning(); - } - else - { - _info["login"] = "http://127.0.0.1:9000/"; - IssueWarning(); - } - } - catch (Exception) - { - _log.Debug("[GridInfoService] cannot get grid info from config source, using minimal defaults"); - } - _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); - - } - - private void IssueWarning() - { - _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini"); - _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:"); - foreach (string k in _info.Keys) - { - _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]); - } - } - - public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable responseData = new Hashtable(); - - _log.Info("[GridInfo]: Request for grid info"); - - foreach (string k in _info.Keys) - { - responseData[k] = _info[k]; - } - response.Value = responseData; - - return response; - } - - public string RestGetGridInfoMethod(string request, string path, string param, - OSHttpRequest httpRequest, OSHttpResponse httpResponse) - { - StringBuilder sb = new StringBuilder(); - - sb.Append("\n"); - foreach (string k in _info.Keys) - { - sb.AppendFormat("<{0}>{1}\n", k, _info[k]); - } - sb.Append("\n"); - - return sb.ToString(); - } - } -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.IO; +using System.Reflection; +using System.Text; +using log4net; +using Nini.Config; +using Nwc.XmlRpc; +using OpenSim.Framework.Servers; + +namespace OpenSim.Framework.Communications.Services +{ + public class GridInfoService + { + private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Hashtable _info = new Hashtable(); + + /// + /// Instantiate a GridInfoService object. + /// + /// path to config path containing + /// grid information + /// + /// GridInfoService uses the [GridInfo] section of the + /// standard OpenSim.ini file --- which is not optimal, but + /// anything else requires a general redesign of the config + /// system. + /// + public GridInfoService(IConfigSource configSource) + { + loadGridInfo(configSource); + } + + /// + /// Default constructor, uses OpenSim.ini. + /// + public GridInfoService() + { + try + { + IConfigSource configSource = new IniConfigSource(Path.Combine(Util.configDir(), "OpenSim.ini")); + loadGridInfo(configSource); + } + catch (FileNotFoundException) + { + _log.Warn("[GridInfoService] no OpenSim.ini file found --- GridInfoServices WILL NOT BE AVAILABLE to your users"); + } + } + + private void loadGridInfo(IConfigSource configSource) + { + _info["platform"] = "OpenSim"; + try + { + IConfig startupCfg = configSource.Configs["Startup"]; + IConfig gridCfg = configSource.Configs["GridInfo"]; + IConfig netCfg = configSource.Configs["Network"]; + + bool grid = startupCfg.GetBoolean("gridmode", false); + + if (grid) + _info["mode"] = "grid"; + else + _info["mode"] = "standalone"; + + + if (null != gridCfg) + { + foreach (string k in gridCfg.GetKeys()) + { + _info[k] = gridCfg.GetString(k); + } + } + else if (null != netCfg) + { + if (grid) + _info["login"] + = netCfg.GetString( + "user_server_url", "http://127.0.0.1:" + UserConfig.DefaultHttpPort.ToString()); + else + _info["login"] + = String.Format( + "http://127.0.0.1:{0}/", + netCfg.GetString( + "http_listener_port", NetworkServersInfo.DefaultHttpListenerPort.ToString())); + + IssueWarning(); + } + else + { + _info["login"] = "http://127.0.0.1:9000/"; + IssueWarning(); + } + } + catch (Exception) + { + _log.Debug("[GridInfoService] cannot get grid info from config source, using minimal defaults"); + } + _log.InfoFormat("[GridInfoService] Grid info service initialized with {0} keys", _info.Count); + + } + + private void IssueWarning() + { + _log.Warn("[GridInfoService] found no [GridInfo] section in your OpenSim.ini"); + _log.Warn("[GridInfoService] trying to guess sensible defaults, you might want to provide better ones:"); + foreach (string k in _info.Keys) + { + _log.WarnFormat("[GridInfoService] {0}: {1}", k, _info[k]); + } + } + + public XmlRpcResponse XmlRpcGridInfoMethod(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable responseData = new Hashtable(); + + _log.Info("[GridInfo]: Request for grid info"); + + foreach (string k in _info.Keys) + { + responseData[k] = _info[k]; + } + response.Value = responseData; + + return response; + } + + public string RestGetGridInfoMethod(string request, string path, string param, + OSHttpRequest httpRequest, OSHttpResponse httpResponse) + { + StringBuilder sb = new StringBuilder(); + + sb.Append("\n"); + foreach (string k in _info.Keys) + { + sb.AppendFormat("<{0}>{1}\n", k, _info[k]); + } + sb.Append("\n"); + + return sb.ToString(); + } + } +} diff --git a/OpenSim/Framework/Communications/Services/HGInventoryService.cs b/OpenSim/Framework/Communications/Services/HGInventoryService.cs index f0b225980a..33d7722eeb 100644 --- a/OpenSim/Framework/Communications/Services/HGInventoryService.cs +++ b/OpenSim/Framework/Communications/Services/HGInventoryService.cs @@ -52,19 +52,41 @@ namespace OpenSim.Framework.Communications.Services = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private InventoryServiceBase m_inventoryService; - private UserManagerBase m_userService; - IAssetDataPlugin m_assetProvider; IHttpServer httpServer; private string m_thisInventoryUrl = "http://localhost:9000"; private string m_thisHostname = "127.0.0.1"; private uint m_thisPort = 9000; + // These two used for local access, standalone mode + private UserManagerBase m_userService = null; + IAssetDataPlugin m_assetProvider = null; - public HGInventoryService(InventoryServiceBase invService, IAssetDataPlugin assetService, UserManagerBase userService, IHttpServer httpserver, string url) + // These two used for remote access + string m_UserServerURL = string.Empty; + string m_AssetServerURL = string.Empty; + + // Constructor for grid inventory server + public HGInventoryService(InventoryServiceBase invService, string assetServiceURL, string userServiceURL, IHttpServer httpserver, string thisurl) + { + m_UserServerURL = userServiceURL; + m_AssetServerURL = assetServiceURL; + + Init(invService, thisurl, httpserver); + } + + // Constructor for standalone mode + public HGInventoryService(InventoryServiceBase invService, IAssetDataPlugin assetService, UserManagerBase userService, IHttpServer httpserver, string thisurl) + { + m_userService = userService; + m_assetProvider = assetService; + + Init(invService, thisurl, httpserver); + } + + private void Init(InventoryServiceBase invService, string thisurl, IHttpServer httpserver) { m_inventoryService = invService; - m_userService = userService; - m_thisInventoryUrl = url; + m_thisInventoryUrl = thisurl; if (!m_thisInventoryUrl.EndsWith("/")) m_thisInventoryUrl += "/"; @@ -75,7 +97,6 @@ namespace OpenSim.Framework.Communications.Services m_thisPort = (uint)uri.Port; } - m_assetProvider = assetService; httpServer = httpserver; AddHttpHandlers(); diff --git a/OpenSim/Framework/Communications/LoginResponse.cs b/OpenSim/Framework/Communications/Services/LoginResponse.cs similarity index 97% rename from OpenSim/Framework/Communications/LoginResponse.cs rename to OpenSim/Framework/Communications/Services/LoginResponse.cs index 698636964a..82515e0574 100644 --- a/OpenSim/Framework/Communications/LoginResponse.cs +++ b/OpenSim/Framework/Communications/Services/LoginResponse.cs @@ -1,812 +1,812 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Reflection; -using log4net; -using Nwc.XmlRpc; -using OpenMetaverse; -using OpenMetaverse.StructuredData; - -namespace OpenSim.Framework.Communications -{ - /// - /// A temp class to handle login response. - /// Should make use of UserProfileManager where possible. - /// - public class LoginResponse - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - private Hashtable loginFlagsHash; - private Hashtable globalTexturesHash; - private Hashtable loginError; - private Hashtable uiConfigHash; - - private ArrayList loginFlags; - private ArrayList globalTextures; - private ArrayList eventCategories; - private ArrayList uiConfig; - private ArrayList classifiedCategories; - private ArrayList inventoryRoot; - private ArrayList initialOutfit; - private ArrayList agentInventory; - private ArrayList inventoryLibraryOwner; - private ArrayList inventoryLibRoot; - private ArrayList inventoryLibrary; - private ArrayList activeGestures; - - private UserInfo userProfile; - - private UUID agentID; - private UUID sessionID; - private UUID secureSessionID; - - // Login Flags - private string dst; - private string stipendSinceLogin; - private string gendered; - private string everLoggedIn; - private string login; - private uint simPort; - private uint simHttpPort; - private string simAddress; - private string agentAccess; - private Int32 circuitCode; - private uint regionX; - private uint regionY; - - // Login - private string firstname; - private string lastname; - - // Global Textures - private string sunTexture; - private string cloudTexture; - private string moonTexture; - - // Error Flags - private string errorReason; - private string errorMessage; - - // Response - private XmlRpcResponse xmlRpcResponse; - // private XmlRpcResponse defaultXmlRpcResponse; - - private string welcomeMessage; - private string startLocation; - private string allowFirstLife; - private string home; - private string seedCapability; - private string lookAt; - - private BuddyList m_buddyList = null; - - public LoginResponse() - { - loginFlags = new ArrayList(); - globalTextures = new ArrayList(); - eventCategories = new ArrayList(); - uiConfig = new ArrayList(); - classifiedCategories = new ArrayList(); - - loginError = new Hashtable(); - uiConfigHash = new Hashtable(); - - // defaultXmlRpcResponse = new XmlRpcResponse(); - userProfile = new UserInfo(); - inventoryRoot = new ArrayList(); - initialOutfit = new ArrayList(); - agentInventory = new ArrayList(); - inventoryLibrary = new ArrayList(); - inventoryLibraryOwner = new ArrayList(); - activeGestures = new ArrayList(); - - xmlRpcResponse = new XmlRpcResponse(); - // defaultXmlRpcResponse = new XmlRpcResponse(); - - SetDefaultValues(); - } - - private void SetDefaultValues() - { - DST = "N"; - StipendSinceLogin = "N"; - Gendered = "Y"; - EverLoggedIn = "Y"; - login = "false"; - firstname = "Test"; - lastname = "User"; - agentAccess = "M"; - startLocation = "last"; - allowFirstLife = "Y"; - - SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; - CloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621"; - MoonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621"; - - ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; - ErrorReason = "key"; - welcomeMessage = "Welcome to OpenSim!"; - seedCapability = String.Empty; - home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" + - userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" + - userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" + - userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}"; - lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; - RegionX = (uint) 255232; - RegionY = (uint) 254976; - - // Classifieds; - AddClassifiedCategory((Int32) 1, "Shopping"); - AddClassifiedCategory((Int32) 2, "Land Rental"); - AddClassifiedCategory((Int32) 3, "Property Rental"); - AddClassifiedCategory((Int32) 4, "Special Attraction"); - AddClassifiedCategory((Int32) 5, "New Products"); - AddClassifiedCategory((Int32) 6, "Employment"); - AddClassifiedCategory((Int32) 7, "Wanted"); - AddClassifiedCategory((Int32) 8, "Service"); - AddClassifiedCategory((Int32) 9, "Personal"); - - SessionID = UUID.Random(); - SecureSessionID = UUID.Random(); - AgentID = UUID.Random(); - - Hashtable InitialOutfitHash = new Hashtable(); - InitialOutfitHash["folder_name"] = "Nightclub Female"; - InitialOutfitHash["gender"] = "female"; - initialOutfit.Add(InitialOutfitHash); - } - - #region Login Failure Methods - - public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login) - { - // Overwrite any default values; - xmlRpcResponse = new XmlRpcResponse(); - - // Ensure Login Failed message/reason; - ErrorMessage = message; - ErrorReason = reason; - - loginError["reason"] = ErrorReason; - loginError["message"] = ErrorMessage; - loginError["login"] = login; - xmlRpcResponse.Value = loginError; - return (xmlRpcResponse); - } - - public OSD GenerateFailureResponseLLSD(string reason, string message, string login) - { - OSDMap map = new OSDMap(); - - // Ensure Login Failed message/reason; - ErrorMessage = message; - ErrorReason = reason; - - map["reason"] = OSD.FromString(ErrorReason); - map["message"] = OSD.FromString(ErrorMessage); - map["login"] = OSD.FromString(login); - - return map; - } - - public XmlRpcResponse CreateFailedResponse() - { - return (CreateLoginFailedResponse()); - } - - public OSD CreateFailedResponseLLSD() - { - return CreateLoginFailedResponseLLSD(); - } - - public XmlRpcResponse CreateLoginFailedResponse() - { - return - (GenerateFailureResponse("key", - "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", - "false")); - } - - public OSD CreateLoginFailedResponseLLSD() - { - return GenerateFailureResponseLLSD( - "key", - "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", - "false"); - } - - /// - /// Response to indicate that login failed because the agent's inventory was not available. - /// - /// - public XmlRpcResponse CreateLoginInventoryFailedResponse() - { - return GenerateFailureResponse( - "key", - "The avatar inventory service is not responding. Please notify your login region operator.", - "false"); - } - - public XmlRpcResponse CreateAlreadyLoggedInResponse() - { - return - (GenerateFailureResponse("presence", - "You appear to be already logged in. " + - "If this is not the case please wait for your session to timeout. " + - "If this takes longer than a few minutes please contact the grid owner. " + - "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.", - "false")); - } - - public OSD CreateAlreadyLoggedInResponseLLSD() - { - return GenerateFailureResponseLLSD( - "presence", - "You appear to be already logged in. " + - "If this is not the case please wait for your session to timeout. " + - "If this takes longer than a few minutes please contact the grid owner", - "false"); - } - - public XmlRpcResponse CreateLoginBlockedResponse() - { - return - (GenerateFailureResponse("presence", - "Logins are currently restricted. Please try again later", - "false")); - } - - public OSD CreateLoginBlockedResponseLLSD() - { - return GenerateFailureResponseLLSD( - "presence", - "Logins are currently restricted. Please try again later", - "false"); - } - - public XmlRpcResponse CreateDeadRegionResponse() - { - return - (GenerateFailureResponse("key", - "The region you are attempting to log into is not responding. Please select another region and try again.", - "false")); - } - - public OSD CreateDeadRegionResponseLLSD() - { - return GenerateFailureResponseLLSD( - "key", - "The region you are attempting to log into is not responding. Please select another region and try again.", - "false"); - } - - public XmlRpcResponse CreateGridErrorResponse() - { - return - (GenerateFailureResponse("key", - "Error connecting to grid. Could not percieve credentials from login XML.", - "false")); - } - - public OSD CreateGridErrorResponseLLSD() - { - return GenerateFailureResponseLLSD( - "key", - "Error connecting to grid. Could not percieve credentials from login XML.", - "false"); - } - - #endregion - - public virtual XmlRpcResponse ToXmlRpcResponse() - { - try - { - Hashtable responseData = new Hashtable(); - - loginFlagsHash = new Hashtable(); - loginFlagsHash["daylight_savings"] = DST; - loginFlagsHash["stipend_since_login"] = StipendSinceLogin; - loginFlagsHash["gendered"] = Gendered; - loginFlagsHash["ever_logged_in"] = EverLoggedIn; - loginFlags.Add(loginFlagsHash); - - responseData["first_name"] = Firstname; - responseData["last_name"] = Lastname; - responseData["agent_access"] = agentAccess; - - globalTexturesHash = new Hashtable(); - globalTexturesHash["sun_texture_id"] = SunTexture; - globalTexturesHash["cloud_texture_id"] = CloudTexture; - globalTexturesHash["moon_texture_id"] = MoonTexture; - globalTextures.Add(globalTexturesHash); - // this.eventCategories.Add(this.eventCategoriesHash); - - AddToUIConfig("allow_first_life", allowFirstLife); - uiConfig.Add(uiConfigHash); - - responseData["sim_port"] = (Int32) SimPort; - responseData["sim_ip"] = SimAddress; - responseData["http_port"] = (Int32)SimHttpPort; - - responseData["agent_id"] = AgentID.ToString(); - responseData["session_id"] = SessionID.ToString(); - responseData["secure_session_id"] = SecureSessionID.ToString(); - responseData["circuit_code"] = CircuitCode; - responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; - responseData["login-flags"] = loginFlags; - responseData["global-textures"] = globalTextures; - responseData["seed_capability"] = seedCapability; - - responseData["event_categories"] = eventCategories; - responseData["event_notifications"] = new ArrayList(); // todo - responseData["classified_categories"] = classifiedCategories; - responseData["ui-config"] = uiConfig; - - responseData["inventory-skeleton"] = agentInventory; - responseData["inventory-skel-lib"] = inventoryLibrary; - responseData["inventory-root"] = inventoryRoot; - responseData["inventory-lib-root"] = inventoryLibRoot; - responseData["gestures"] = activeGestures; - responseData["inventory-lib-owner"] = inventoryLibraryOwner; - responseData["initial-outfit"] = initialOutfit; - responseData["start_location"] = startLocation; - responseData["seed_capability"] = seedCapability; - responseData["home"] = home; - responseData["look_at"] = lookAt; - responseData["message"] = welcomeMessage; - responseData["region_x"] = (Int32)(RegionX * Constants.RegionSize); - responseData["region_y"] = (Int32)(RegionY * Constants.RegionSize); - - //responseData["inventory-lib-root"] = new ArrayList(); // todo - - if (m_buddyList != null) - { - responseData["buddy-list"] = m_buddyList.ToArray(); - } - - responseData["login"] = "true"; - xmlRpcResponse.Value = responseData; - - return (xmlRpcResponse); - } - catch (Exception e) - { - m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message); - - return (GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); - } - } - - public OSD ToLLSDResponse() - { - try - { - OSDMap map = new OSDMap(); - - map["first_name"] = OSD.FromString(Firstname); - map["last_name"] = OSD.FromString(Lastname); - map["agent_access"] = OSD.FromString(agentAccess); - - map["sim_port"] = OSD.FromInteger(SimPort); - map["sim_ip"] = OSD.FromString(SimAddress); - - map["agent_id"] = OSD.FromUUID(AgentID); - map["session_id"] = OSD.FromUUID(SessionID); - map["secure_session_id"] = OSD.FromUUID(SecureSessionID); - map["circuit_code"] = OSD.FromInteger(CircuitCode); - map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); - - #region Login Flags - - OSDMap loginFlagsLLSD = new OSDMap(); - loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST); - loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin); - loginFlagsLLSD["gendered"] = OSD.FromString(Gendered); - loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn); - map["login-flags"] = WrapOSDMap(loginFlagsLLSD); - - #endregion Login Flags - - #region Global Textures - - OSDMap globalTexturesLLSD = new OSDMap(); - globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture); - globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture); - globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture); - - map["global-textures"] = WrapOSDMap(globalTexturesLLSD); - - #endregion Global Textures - - map["seed_capability"] = OSD.FromString(seedCapability); - - map["event_categories"] = ArrayListToOSDArray(eventCategories); - //map["event_notifications"] = new OSDArray(); // todo - map["classified_categories"] = ArrayListToOSDArray(classifiedCategories); - - #region UI Config - - OSDMap uiConfigLLSD = new OSDMap(); - uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife); - map["ui-config"] = WrapOSDMap(uiConfigLLSD); - - #endregion UI Config - - #region Inventory - - map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory); - - map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary); - map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ; - map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot); - map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner); - - #endregion Inventory - - map["gestures"] = ArrayListToOSDArray(activeGestures); - - map["initial-outfit"] = ArrayListToOSDArray(initialOutfit); - map["start_location"] = OSD.FromString(startLocation); - - map["seed_capability"] = OSD.FromString(seedCapability); - map["home"] = OSD.FromString(home); - map["look_at"] = OSD.FromString(lookAt); - map["message"] = OSD.FromString(welcomeMessage); - map["region_x"] = OSD.FromInteger(RegionX * Constants.RegionSize); - map["region_y"] = OSD.FromInteger(RegionY * Constants.RegionSize); - - if (m_buddyList != null) - { - map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray()); - } - - map["login"] = OSD.FromString("true"); - - return map; - } - catch (Exception e) - { - m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message); - - return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); - } - } - - public OSDArray ArrayListToOSDArray(ArrayList arrlst) - { - OSDArray llsdBack = new OSDArray(); - foreach (Hashtable ht in arrlst) - { - OSDMap mp = new OSDMap(); - foreach (DictionaryEntry deHt in ht) - { - mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value)); - } - llsdBack.Add(mp); - } - return llsdBack; - } - - private static OSDArray WrapOSDMap(OSDMap wrapMe) - { - OSDArray array = new OSDArray(); - array.Add(wrapMe); - return array; - } - - public void SetEventCategories(string category, string value) - { - // this.eventCategoriesHash[category] = value; - //TODO - } - - public void AddToUIConfig(string itemName, string item) - { - uiConfigHash[itemName] = item; - } - - public void AddClassifiedCategory(Int32 ID, string categoryName) - { - Hashtable hash = new Hashtable(); - hash["category_name"] = categoryName; - hash["category_id"] = ID; - classifiedCategories.Add(hash); - // this.classifiedCategoriesHash.Clear(); - } - - #region Properties - - public string Login - { - get { return login; } - set { login = value; } - } - - public string DST - { - get { return dst; } - set { dst = value; } - } - - public string StipendSinceLogin - { - get { return stipendSinceLogin; } - set { stipendSinceLogin = value; } - } - - public string Gendered - { - get { return gendered; } - set { gendered = value; } - } - - public string EverLoggedIn - { - get { return everLoggedIn; } - set { everLoggedIn = value; } - } - - public uint SimPort - { - get { return simPort; } - set { simPort = value; } - } - - public uint SimHttpPort - { - get { return simHttpPort; } - set { simHttpPort = value; } - } - - public string SimAddress - { - get { return simAddress; } - set { simAddress = value; } - } - - public UUID AgentID - { - get { return agentID; } - set { agentID = value; } - } - - public UUID SessionID - { - get { return sessionID; } - set { sessionID = value; } - } - - public UUID SecureSessionID - { - get { return secureSessionID; } - set { secureSessionID = value; } - } - - public Int32 CircuitCode - { - get { return circuitCode; } - set { circuitCode = value; } - } - - public uint RegionX - { - get { return regionX; } - set { regionX = value; } - } - - public uint RegionY - { - get { return regionY; } - set { regionY = value; } - } - - public string SunTexture - { - get { return sunTexture; } - set { sunTexture = value; } - } - - public string CloudTexture - { - get { return cloudTexture; } - set { cloudTexture = value; } - } - - public string MoonTexture - { - get { return moonTexture; } - set { moonTexture = value; } - } - - public string Firstname - { - get { return firstname; } - set { firstname = value; } - } - - public string Lastname - { - get { return lastname; } - set { lastname = value; } - } - - public string AgentAccess - { - get { return agentAccess; } - set { agentAccess = value; } - } - - public string StartLocation - { - get { return startLocation; } - set { startLocation = value; } - } - - public string LookAt - { - get { return lookAt; } - set { lookAt = value; } - } - - public string SeedCapability - { - get { return seedCapability; } - set { seedCapability = value; } - } - - public string ErrorReason - { - get { return errorReason; } - set { errorReason = value; } - } - - public string ErrorMessage - { - get { return errorMessage; } - set { errorMessage = value; } - } - - public ArrayList InventoryRoot - { - get { return inventoryRoot; } - set { inventoryRoot = value; } - } - - public ArrayList InventorySkeleton - { - get { return agentInventory; } - set { agentInventory = value; } - } - - public ArrayList InventoryLibrary - { - get { return inventoryLibrary; } - set { inventoryLibrary = value; } - } - - public ArrayList InventoryLibraryOwner - { - get { return inventoryLibraryOwner; } - set { inventoryLibraryOwner = value; } - } - - public ArrayList InventoryLibRoot - { - get { return inventoryLibRoot; } - set { inventoryLibRoot = value; } - } - - public ArrayList ActiveGestures - { - get { return activeGestures; } - set { activeGestures = value; } - } - - public string Home - { - get { return home; } - set { home = value; } - } - - public string Message - { - get { return welcomeMessage; } - set { welcomeMessage = value; } - } - - public BuddyList BuddList - { - get { return m_buddyList; } - set { m_buddyList = value; } - } - - #endregion - - public class UserInfo - { - public string firstname; - public string lastname; - public ulong homeregionhandle; - public Vector3 homepos; - public Vector3 homelookat; - } - - public class BuddyList - { - public List Buddies = new List(); - - public void AddNewBuddy(BuddyInfo buddy) - { - if (!Buddies.Contains(buddy)) - { - Buddies.Add(buddy); - } - } - - public ArrayList ToArray() - { - ArrayList buddyArray = new ArrayList(); - foreach (BuddyInfo buddy in Buddies) - { - buddyArray.Add(buddy.ToHashTable()); - } - return buddyArray; - } - - public class BuddyInfo - { - public int BuddyRightsHave = 1; - public int BuddyRightsGiven = 1; - public UUID BuddyID; - - public BuddyInfo(string buddyID) - { - BuddyID = new UUID(buddyID); - } - - public BuddyInfo(UUID buddyID) - { - BuddyID = buddyID; - } - - public Hashtable ToHashTable() - { - Hashtable hTable = new Hashtable(); - hTable["buddy_rights_has"] = BuddyRightsHave; - hTable["buddy_rights_given"] = BuddyRightsGiven; - hTable["buddy_id"] = BuddyID.ToString(); - return hTable; - } - } - } - } -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; +using OpenMetaverse.StructuredData; + +namespace OpenSim.Framework.Communications.Services +{ + /// + /// A temp class to handle login response. + /// Should make use of UserProfileManager where possible. + /// + public class LoginResponse + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + private Hashtable loginFlagsHash; + private Hashtable globalTexturesHash; + private Hashtable loginError; + private Hashtable uiConfigHash; + + private ArrayList loginFlags; + private ArrayList globalTextures; + private ArrayList eventCategories; + private ArrayList uiConfig; + private ArrayList classifiedCategories; + private ArrayList inventoryRoot; + private ArrayList initialOutfit; + private ArrayList agentInventory; + private ArrayList inventoryLibraryOwner; + private ArrayList inventoryLibRoot; + private ArrayList inventoryLibrary; + private ArrayList activeGestures; + + private UserInfo userProfile; + + private UUID agentID; + private UUID sessionID; + private UUID secureSessionID; + + // Login Flags + private string dst; + private string stipendSinceLogin; + private string gendered; + private string everLoggedIn; + private string login; + private uint simPort; + private uint simHttpPort; + private string simAddress; + private string agentAccess; + private Int32 circuitCode; + private uint regionX; + private uint regionY; + + // Login + private string firstname; + private string lastname; + + // Global Textures + private string sunTexture; + private string cloudTexture; + private string moonTexture; + + // Error Flags + private string errorReason; + private string errorMessage; + + // Response + private XmlRpcResponse xmlRpcResponse; + // private XmlRpcResponse defaultXmlRpcResponse; + + private string welcomeMessage; + private string startLocation; + private string allowFirstLife; + private string home; + private string seedCapability; + private string lookAt; + + private BuddyList m_buddyList = null; + + public LoginResponse() + { + loginFlags = new ArrayList(); + globalTextures = new ArrayList(); + eventCategories = new ArrayList(); + uiConfig = new ArrayList(); + classifiedCategories = new ArrayList(); + + loginError = new Hashtable(); + uiConfigHash = new Hashtable(); + + // defaultXmlRpcResponse = new XmlRpcResponse(); + userProfile = new UserInfo(); + inventoryRoot = new ArrayList(); + initialOutfit = new ArrayList(); + agentInventory = new ArrayList(); + inventoryLibrary = new ArrayList(); + inventoryLibraryOwner = new ArrayList(); + activeGestures = new ArrayList(); + + xmlRpcResponse = new XmlRpcResponse(); + // defaultXmlRpcResponse = new XmlRpcResponse(); + + SetDefaultValues(); + } + + private void SetDefaultValues() + { + DST = "N"; + StipendSinceLogin = "N"; + Gendered = "Y"; + EverLoggedIn = "Y"; + login = "false"; + firstname = "Test"; + lastname = "User"; + agentAccess = "M"; + startLocation = "last"; + allowFirstLife = "Y"; + + SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271"; + CloudTexture = "dc4b9f0b-d008-45c6-96a4-01dd947ac621"; + MoonTexture = "ec4b9f0b-d008-45c6-96a4-01dd947ac621"; + + ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock."; + ErrorReason = "key"; + welcomeMessage = "Welcome to OpenSim!"; + seedCapability = String.Empty; + home = "{'region_handle':[r" + (1000*Constants.RegionSize).ToString() + ",r" + (1000*Constants.RegionSize).ToString() + "], 'position':[r" + + userProfile.homepos.X.ToString() + ",r" + userProfile.homepos.Y.ToString() + ",r" + + userProfile.homepos.Z.ToString() + "], 'look_at':[r" + userProfile.homelookat.X.ToString() + ",r" + + userProfile.homelookat.Y.ToString() + ",r" + userProfile.homelookat.Z.ToString() + "]}"; + lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; + RegionX = (uint) 255232; + RegionY = (uint) 254976; + + // Classifieds; + AddClassifiedCategory((Int32) 1, "Shopping"); + AddClassifiedCategory((Int32) 2, "Land Rental"); + AddClassifiedCategory((Int32) 3, "Property Rental"); + AddClassifiedCategory((Int32) 4, "Special Attraction"); + AddClassifiedCategory((Int32) 5, "New Products"); + AddClassifiedCategory((Int32) 6, "Employment"); + AddClassifiedCategory((Int32) 7, "Wanted"); + AddClassifiedCategory((Int32) 8, "Service"); + AddClassifiedCategory((Int32) 9, "Personal"); + + SessionID = UUID.Random(); + SecureSessionID = UUID.Random(); + AgentID = UUID.Random(); + + Hashtable InitialOutfitHash = new Hashtable(); + InitialOutfitHash["folder_name"] = "Nightclub Female"; + InitialOutfitHash["gender"] = "female"; + initialOutfit.Add(InitialOutfitHash); + } + + #region Login Failure Methods + + public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login) + { + // Overwrite any default values; + xmlRpcResponse = new XmlRpcResponse(); + + // Ensure Login Failed message/reason; + ErrorMessage = message; + ErrorReason = reason; + + loginError["reason"] = ErrorReason; + loginError["message"] = ErrorMessage; + loginError["login"] = login; + xmlRpcResponse.Value = loginError; + return (xmlRpcResponse); + } + + public OSD GenerateFailureResponseLLSD(string reason, string message, string login) + { + OSDMap map = new OSDMap(); + + // Ensure Login Failed message/reason; + ErrorMessage = message; + ErrorReason = reason; + + map["reason"] = OSD.FromString(ErrorReason); + map["message"] = OSD.FromString(ErrorMessage); + map["login"] = OSD.FromString(login); + + return map; + } + + public XmlRpcResponse CreateFailedResponse() + { + return (CreateLoginFailedResponse()); + } + + public OSD CreateFailedResponseLLSD() + { + return CreateLoginFailedResponseLLSD(); + } + + public XmlRpcResponse CreateLoginFailedResponse() + { + return + (GenerateFailureResponse("key", + "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", + "false")); + } + + public OSD CreateLoginFailedResponseLLSD() + { + return GenerateFailureResponseLLSD( + "key", + "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", + "false"); + } + + /// + /// Response to indicate that login failed because the agent's inventory was not available. + /// + /// + public XmlRpcResponse CreateLoginInventoryFailedResponse() + { + return GenerateFailureResponse( + "key", + "The avatar inventory service is not responding. Please notify your login region operator.", + "false"); + } + + public XmlRpcResponse CreateAlreadyLoggedInResponse() + { + return + (GenerateFailureResponse("presence", + "You appear to be already logged in. " + + "If this is not the case please wait for your session to timeout. " + + "If this takes longer than a few minutes please contact the grid owner. " + + "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.", + "false")); + } + + public OSD CreateAlreadyLoggedInResponseLLSD() + { + return GenerateFailureResponseLLSD( + "presence", + "You appear to be already logged in. " + + "If this is not the case please wait for your session to timeout. " + + "If this takes longer than a few minutes please contact the grid owner", + "false"); + } + + public XmlRpcResponse CreateLoginBlockedResponse() + { + return + (GenerateFailureResponse("presence", + "Logins are currently restricted. Please try again later", + "false")); + } + + public OSD CreateLoginBlockedResponseLLSD() + { + return GenerateFailureResponseLLSD( + "presence", + "Logins are currently restricted. Please try again later", + "false"); + } + + public XmlRpcResponse CreateDeadRegionResponse() + { + return + (GenerateFailureResponse("key", + "The region you are attempting to log into is not responding. Please select another region and try again.", + "false")); + } + + public OSD CreateDeadRegionResponseLLSD() + { + return GenerateFailureResponseLLSD( + "key", + "The region you are attempting to log into is not responding. Please select another region and try again.", + "false"); + } + + public XmlRpcResponse CreateGridErrorResponse() + { + return + (GenerateFailureResponse("key", + "Error connecting to grid. Could not percieve credentials from login XML.", + "false")); + } + + public OSD CreateGridErrorResponseLLSD() + { + return GenerateFailureResponseLLSD( + "key", + "Error connecting to grid. Could not percieve credentials from login XML.", + "false"); + } + + #endregion + + public virtual XmlRpcResponse ToXmlRpcResponse() + { + try + { + Hashtable responseData = new Hashtable(); + + loginFlagsHash = new Hashtable(); + loginFlagsHash["daylight_savings"] = DST; + loginFlagsHash["stipend_since_login"] = StipendSinceLogin; + loginFlagsHash["gendered"] = Gendered; + loginFlagsHash["ever_logged_in"] = EverLoggedIn; + loginFlags.Add(loginFlagsHash); + + responseData["first_name"] = Firstname; + responseData["last_name"] = Lastname; + responseData["agent_access"] = agentAccess; + + globalTexturesHash = new Hashtable(); + globalTexturesHash["sun_texture_id"] = SunTexture; + globalTexturesHash["cloud_texture_id"] = CloudTexture; + globalTexturesHash["moon_texture_id"] = MoonTexture; + globalTextures.Add(globalTexturesHash); + // this.eventCategories.Add(this.eventCategoriesHash); + + AddToUIConfig("allow_first_life", allowFirstLife); + uiConfig.Add(uiConfigHash); + + responseData["sim_port"] = (Int32) SimPort; + responseData["sim_ip"] = SimAddress; + responseData["http_port"] = (Int32)SimHttpPort; + + responseData["agent_id"] = AgentID.ToString(); + responseData["session_id"] = SessionID.ToString(); + responseData["secure_session_id"] = SecureSessionID.ToString(); + responseData["circuit_code"] = CircuitCode; + responseData["seconds_since_epoch"] = (Int32) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; + responseData["login-flags"] = loginFlags; + responseData["global-textures"] = globalTextures; + responseData["seed_capability"] = seedCapability; + + responseData["event_categories"] = eventCategories; + responseData["event_notifications"] = new ArrayList(); // todo + responseData["classified_categories"] = classifiedCategories; + responseData["ui-config"] = uiConfig; + + responseData["inventory-skeleton"] = agentInventory; + responseData["inventory-skel-lib"] = inventoryLibrary; + responseData["inventory-root"] = inventoryRoot; + responseData["inventory-lib-root"] = inventoryLibRoot; + responseData["gestures"] = activeGestures; + responseData["inventory-lib-owner"] = inventoryLibraryOwner; + responseData["initial-outfit"] = initialOutfit; + responseData["start_location"] = startLocation; + responseData["seed_capability"] = seedCapability; + responseData["home"] = home; + responseData["look_at"] = lookAt; + responseData["message"] = welcomeMessage; + responseData["region_x"] = (Int32)(RegionX * Constants.RegionSize); + responseData["region_y"] = (Int32)(RegionY * Constants.RegionSize); + + //responseData["inventory-lib-root"] = new ArrayList(); // todo + + if (m_buddyList != null) + { + responseData["buddy-list"] = m_buddyList.ToArray(); + } + + responseData["login"] = "true"; + xmlRpcResponse.Value = responseData; + + return (xmlRpcResponse); + } + catch (Exception e) + { + m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message); + + return (GenerateFailureResponse("Internal Error", "Error generating Login Response", "false")); + } + } + + public OSD ToLLSDResponse() + { + try + { + OSDMap map = new OSDMap(); + + map["first_name"] = OSD.FromString(Firstname); + map["last_name"] = OSD.FromString(Lastname); + map["agent_access"] = OSD.FromString(agentAccess); + + map["sim_port"] = OSD.FromInteger(SimPort); + map["sim_ip"] = OSD.FromString(SimAddress); + + map["agent_id"] = OSD.FromUUID(AgentID); + map["session_id"] = OSD.FromUUID(SessionID); + map["secure_session_id"] = OSD.FromUUID(SecureSessionID); + map["circuit_code"] = OSD.FromInteger(CircuitCode); + map["seconds_since_epoch"] = OSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); + + #region Login Flags + + OSDMap loginFlagsLLSD = new OSDMap(); + loginFlagsLLSD["daylight_savings"] = OSD.FromString(DST); + loginFlagsLLSD["stipend_since_login"] = OSD.FromString(StipendSinceLogin); + loginFlagsLLSD["gendered"] = OSD.FromString(Gendered); + loginFlagsLLSD["ever_logged_in"] = OSD.FromString(EverLoggedIn); + map["login-flags"] = WrapOSDMap(loginFlagsLLSD); + + #endregion Login Flags + + #region Global Textures + + OSDMap globalTexturesLLSD = new OSDMap(); + globalTexturesLLSD["sun_texture_id"] = OSD.FromString(SunTexture); + globalTexturesLLSD["cloud_texture_id"] = OSD.FromString(CloudTexture); + globalTexturesLLSD["moon_texture_id"] = OSD.FromString(MoonTexture); + + map["global-textures"] = WrapOSDMap(globalTexturesLLSD); + + #endregion Global Textures + + map["seed_capability"] = OSD.FromString(seedCapability); + + map["event_categories"] = ArrayListToOSDArray(eventCategories); + //map["event_notifications"] = new OSDArray(); // todo + map["classified_categories"] = ArrayListToOSDArray(classifiedCategories); + + #region UI Config + + OSDMap uiConfigLLSD = new OSDMap(); + uiConfigLLSD["allow_first_life"] = OSD.FromString(allowFirstLife); + map["ui-config"] = WrapOSDMap(uiConfigLLSD); + + #endregion UI Config + + #region Inventory + + map["inventory-skeleton"] = ArrayListToOSDArray(agentInventory); + + map["inventory-skel-lib"] = ArrayListToOSDArray(inventoryLibrary); + map["inventory-root"] = ArrayListToOSDArray(inventoryRoot); ; + map["inventory-lib-root"] = ArrayListToOSDArray(inventoryLibRoot); + map["inventory-lib-owner"] = ArrayListToOSDArray(inventoryLibraryOwner); + + #endregion Inventory + + map["gestures"] = ArrayListToOSDArray(activeGestures); + + map["initial-outfit"] = ArrayListToOSDArray(initialOutfit); + map["start_location"] = OSD.FromString(startLocation); + + map["seed_capability"] = OSD.FromString(seedCapability); + map["home"] = OSD.FromString(home); + map["look_at"] = OSD.FromString(lookAt); + map["message"] = OSD.FromString(welcomeMessage); + map["region_x"] = OSD.FromInteger(RegionX * Constants.RegionSize); + map["region_y"] = OSD.FromInteger(RegionY * Constants.RegionSize); + + if (m_buddyList != null) + { + map["buddy-list"] = ArrayListToOSDArray(m_buddyList.ToArray()); + } + + map["login"] = OSD.FromString("true"); + + return map; + } + catch (Exception e) + { + m_log.Warn("[CLIENT]: LoginResponse: Error creating LLSD Response: " + e.Message); + + return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); + } + } + + public OSDArray ArrayListToOSDArray(ArrayList arrlst) + { + OSDArray llsdBack = new OSDArray(); + foreach (Hashtable ht in arrlst) + { + OSDMap mp = new OSDMap(); + foreach (DictionaryEntry deHt in ht) + { + mp.Add((string)deHt.Key, OSDString.FromObject(deHt.Value)); + } + llsdBack.Add(mp); + } + return llsdBack; + } + + private static OSDArray WrapOSDMap(OSDMap wrapMe) + { + OSDArray array = new OSDArray(); + array.Add(wrapMe); + return array; + } + + public void SetEventCategories(string category, string value) + { + // this.eventCategoriesHash[category] = value; + //TODO + } + + public void AddToUIConfig(string itemName, string item) + { + uiConfigHash[itemName] = item; + } + + public void AddClassifiedCategory(Int32 ID, string categoryName) + { + Hashtable hash = new Hashtable(); + hash["category_name"] = categoryName; + hash["category_id"] = ID; + classifiedCategories.Add(hash); + // this.classifiedCategoriesHash.Clear(); + } + + #region Properties + + public string Login + { + get { return login; } + set { login = value; } + } + + public string DST + { + get { return dst; } + set { dst = value; } + } + + public string StipendSinceLogin + { + get { return stipendSinceLogin; } + set { stipendSinceLogin = value; } + } + + public string Gendered + { + get { return gendered; } + set { gendered = value; } + } + + public string EverLoggedIn + { + get { return everLoggedIn; } + set { everLoggedIn = value; } + } + + public uint SimPort + { + get { return simPort; } + set { simPort = value; } + } + + public uint SimHttpPort + { + get { return simHttpPort; } + set { simHttpPort = value; } + } + + public string SimAddress + { + get { return simAddress; } + set { simAddress = value; } + } + + public UUID AgentID + { + get { return agentID; } + set { agentID = value; } + } + + public UUID SessionID + { + get { return sessionID; } + set { sessionID = value; } + } + + public UUID SecureSessionID + { + get { return secureSessionID; } + set { secureSessionID = value; } + } + + public Int32 CircuitCode + { + get { return circuitCode; } + set { circuitCode = value; } + } + + public uint RegionX + { + get { return regionX; } + set { regionX = value; } + } + + public uint RegionY + { + get { return regionY; } + set { regionY = value; } + } + + public string SunTexture + { + get { return sunTexture; } + set { sunTexture = value; } + } + + public string CloudTexture + { + get { return cloudTexture; } + set { cloudTexture = value; } + } + + public string MoonTexture + { + get { return moonTexture; } + set { moonTexture = value; } + } + + public string Firstname + { + get { return firstname; } + set { firstname = value; } + } + + public string Lastname + { + get { return lastname; } + set { lastname = value; } + } + + public string AgentAccess + { + get { return agentAccess; } + set { agentAccess = value; } + } + + public string StartLocation + { + get { return startLocation; } + set { startLocation = value; } + } + + public string LookAt + { + get { return lookAt; } + set { lookAt = value; } + } + + public string SeedCapability + { + get { return seedCapability; } + set { seedCapability = value; } + } + + public string ErrorReason + { + get { return errorReason; } + set { errorReason = value; } + } + + public string ErrorMessage + { + get { return errorMessage; } + set { errorMessage = value; } + } + + public ArrayList InventoryRoot + { + get { return inventoryRoot; } + set { inventoryRoot = value; } + } + + public ArrayList InventorySkeleton + { + get { return agentInventory; } + set { agentInventory = value; } + } + + public ArrayList InventoryLibrary + { + get { return inventoryLibrary; } + set { inventoryLibrary = value; } + } + + public ArrayList InventoryLibraryOwner + { + get { return inventoryLibraryOwner; } + set { inventoryLibraryOwner = value; } + } + + public ArrayList InventoryLibRoot + { + get { return inventoryLibRoot; } + set { inventoryLibRoot = value; } + } + + public ArrayList ActiveGestures + { + get { return activeGestures; } + set { activeGestures = value; } + } + + public string Home + { + get { return home; } + set { home = value; } + } + + public string Message + { + get { return welcomeMessage; } + set { welcomeMessage = value; } + } + + public BuddyList BuddList + { + get { return m_buddyList; } + set { m_buddyList = value; } + } + + #endregion + + public class UserInfo + { + public string firstname; + public string lastname; + public ulong homeregionhandle; + public Vector3 homepos; + public Vector3 homelookat; + } + + public class BuddyList + { + public List Buddies = new List(); + + public void AddNewBuddy(BuddyInfo buddy) + { + if (!Buddies.Contains(buddy)) + { + Buddies.Add(buddy); + } + } + + public ArrayList ToArray() + { + ArrayList buddyArray = new ArrayList(); + foreach (BuddyInfo buddy in Buddies) + { + buddyArray.Add(buddy.ToHashTable()); + } + return buddyArray; + } + + public class BuddyInfo + { + public int BuddyRightsHave = 1; + public int BuddyRightsGiven = 1; + public UUID BuddyID; + + public BuddyInfo(string buddyID) + { + BuddyID = new UUID(buddyID); + } + + public BuddyInfo(UUID buddyID) + { + BuddyID = buddyID; + } + + public Hashtable ToHashTable() + { + Hashtable hTable = new Hashtable(); + hTable["buddy_rights_has"] = BuddyRightsHave; + hTable["buddy_rights_given"] = BuddyRightsGiven; + hTable["buddy_id"] = BuddyID.ToString(); + return hTable; + } + } + } + } +} diff --git a/OpenSim/Framework/Communications/LoginService.cs b/OpenSim/Framework/Communications/Services/LoginService.cs similarity index 97% rename from OpenSim/Framework/Communications/LoginService.cs rename to OpenSim/Framework/Communications/Services/LoginService.cs index 99b5df739f..51158c9295 100644 --- a/OpenSim/Framework/Communications/LoginService.cs +++ b/OpenSim/Framework/Communications/Services/LoginService.cs @@ -1,1093 +1,1093 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text.RegularExpressions; -using System.Threading; -using System.Web; -using log4net; -using Nwc.XmlRpc; -using OpenMetaverse; -using OpenMetaverse.StructuredData; -using OpenSim.Framework.Communications.Cache; -using OpenSim.Framework.Statistics; - -namespace OpenSim.Framework.Communications -{ - public abstract class LoginService - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - protected string m_welcomeMessage = "Welcome to OpenSim"; - protected int m_minLoginLevel = 0; - protected UserManagerBase m_userManager = null; - protected Mutex m_loginMutex = new Mutex(false); - - /// - /// Used during login to send the skeleton of the OpenSim Library to the client. - /// - protected LibraryRootFolder m_libraryRootFolder; - - protected uint m_defaultHomeX; - protected uint m_defaultHomeY; - - /// - /// Used by the login service to make requests to the inventory service. - /// - protected IInterServiceInventoryServices m_inventoryService; - - /// - /// Constructor - /// - /// - /// - /// - public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder, - string welcomeMess) - { - m_userManager = userManager; - m_libraryRootFolder = libraryRootFolder; - - if (welcomeMess != String.Empty) - { - m_welcomeMessage = welcomeMess; - } - } - - /// - /// If the user is already logged in, try to notify the region that the user they've got is dead. - /// - /// - public virtual void LogOffUser(UserProfileData theUser, string message) - { - } - - - /// - /// Called when we receive the client's initial XMLRPC login_to_simulator request message - /// - /// The XMLRPC request - /// The response to send - public virtual XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) - { - // Temporary fix - m_loginMutex.WaitOne(); - - try - { - //CFK: CustomizeResponse contains sufficient strings to alleviate the need for this. - //CKF: m_log.Info("[LOGIN]: Attempting login now..."); - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable)request.Params[0]; - - SniffLoginKey((Uri)request.Params[2], requestData); - - bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && - (requestData.Contains("passwd") || requestData.Contains("web_login_key"))); - - string startLocationRequest = "last"; - - UserProfileData userProfile; - LoginResponse logResponse = new LoginResponse(); - - string firstname; - string lastname; - - if (GoodXML) - { - if (requestData.Contains("start")) - { - startLocationRequest = (string)requestData["start"]; - } - - firstname = (string)requestData["first"]; - lastname = (string)requestData["last"]; - - m_log.InfoFormat( - "[LOGIN BEGIN]: XMLRPC Received login request message from user '{0}' '{1}'", - firstname, lastname); - - string clientVersion = "Unknown"; - - if (requestData.Contains("version")) - { - clientVersion = (string)requestData["version"]; - } - - m_log.DebugFormat( - "[LOGIN]: XMLRPC Client is {0}, start location is {1}", clientVersion, startLocationRequest); - - if (!TryAuthenticateXmlRpcLogin(request, firstname, lastname, out userProfile)) - { - return logResponse.CreateLoginFailedResponse(); - } - } - else - { - m_log.Info( - "[LOGIN END]: XMLRPC login_to_simulator login message did not contain all the required data"); - - return logResponse.CreateGridErrorResponse(); - } - - if (userProfile.GodLevel < m_minLoginLevel) - { - return logResponse.CreateLoginBlockedResponse(); - } - else - { - // If we already have a session... - if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline) - { - //TODO: The following statements can cause trouble: - // If agentOnline could not turn from true back to false normally - // because of some problem, for instance, the crashment of server or client, - // the user cannot log in any longer. - userProfile.CurrentAgent.AgentOnline = false; - - m_userManager.CommitAgent(ref userProfile); - - // try to tell the region that their user is dead. - LogOffUser(userProfile, " XMLRPC You were logged off because you logged in from another location"); - - // Reject the login - - m_log.InfoFormat( - "[LOGIN END]: XMLRPC Notifying user {0} {1} that they are already logged in", - firstname, lastname); - - return logResponse.CreateAlreadyLoggedInResponse(); - } - - // Otherwise... - // Create a new agent session - - m_userManager.ResetAttachments(userProfile.ID); - - CreateAgent(userProfile, request); - - try - { - UUID agentID = userProfile.ID; - InventoryData inventData; - - try - { - inventData = GetInventorySkeleton(agentID); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LOGIN END]: Error retrieving inventory skeleton of agent {0} - {1}", - agentID, e); - - return logResponse.CreateLoginInventoryFailedResponse(); - } - - ArrayList AgentInventoryArray = inventData.InventoryArray; - - Hashtable InventoryRootHash = new Hashtable(); - InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); - ArrayList InventoryRoot = new ArrayList(); - InventoryRoot.Add(InventoryRootHash); - userProfile.RootInventoryFolderID = inventData.RootFolderID; - - // Inventory Library Section - Hashtable InventoryLibRootHash = new Hashtable(); - InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; - ArrayList InventoryLibRoot = new ArrayList(); - InventoryLibRoot.Add(InventoryLibRootHash); - - logResponse.InventoryLibRoot = InventoryLibRoot; - logResponse.InventoryLibraryOwner = GetLibraryOwner(); - logResponse.InventoryRoot = InventoryRoot; - logResponse.InventorySkeleton = AgentInventoryArray; - logResponse.InventoryLibrary = GetInventoryLibrary(); - - logResponse.CircuitCode = Util.RandomClass.Next(); - logResponse.Lastname = userProfile.SurName; - logResponse.Firstname = userProfile.FirstName; - logResponse.AgentID = agentID; - logResponse.SessionID = userProfile.CurrentAgent.SessionID; - logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID; - logResponse.Message = GetMessage(); - logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); - logResponse.StartLocation = startLocationRequest; - - if (CustomiseResponse(logResponse, userProfile, startLocationRequest)) - { - userProfile.LastLogin = userProfile.CurrentAgent.LoginTime; - CommitAgent(ref userProfile); - - // If we reach this point, then the login has successfully logged onto the grid - if (StatsManager.UserStats != null) - StatsManager.UserStats.AddSuccessfulLogin(); - - m_log.DebugFormat( - "[LOGIN END]: XMLRPC Authentication of user {0} {1} successful. Sending response to client.", - firstname, lastname); - - return logResponse.ToXmlRpcResponse(); - } - else - { - m_log.ErrorFormat("[LOGIN END]: XMLRPC informing user {0} {1} that login failed due to an unavailable region", firstname, lastname); - return logResponse.CreateDeadRegionResponse(); - } - } - catch (Exception e) - { - m_log.Error("[LOGIN END]: XMLRPC Login failed, " + e); - m_log.Error(e.StackTrace); - } - } - - m_log.Info("[LOGIN END]: XMLRPC Login failed. Sending back blank XMLRPC response"); - return response; - } - finally - { - m_loginMutex.ReleaseMutex(); - } - } - - protected virtual bool TryAuthenticateXmlRpcLogin(XmlRpcRequest request, string firstname, string lastname, out UserProfileData userProfile) - { - Hashtable requestData = (Hashtable)request.Params[0]; - - bool GoodLogin = false; - - userProfile = GetTheUser(firstname, lastname); - if (userProfile == null) - { - m_log.Info("[LOGIN END]: XMLRPC Could not find a profile for " + firstname + " " + lastname); - } - else - { - if (requestData.Contains("passwd")) - { - string passwd = (string)requestData["passwd"]; - GoodLogin = AuthenticateUser(userProfile, passwd); - } - if (!GoodLogin && (requestData.Contains("web_login_key"))) - { - try - { - UUID webloginkey = new UUID((string)requestData["web_login_key"]); - GoodLogin = AuthenticateUser(userProfile, webloginkey); - } - catch (Exception e) - { - m_log.InfoFormat( - "[LOGIN END]: XMLRPC Bad web_login_key: {0} for user {1} {2}, exception {3}", - requestData["web_login_key"], firstname, lastname, e); - } - } - } - - return GoodLogin; - } - - protected virtual bool TryAuthenticateLLSDLogin(string firstname, string lastname, string passwd, out UserProfileData userProfile) - { - bool GoodLogin = false; - userProfile = GetTheUser(firstname, lastname); - if (userProfile == null) - { - m_log.Info("[LOGIN]: LLSD Could not find a profile for " + firstname + " " + lastname); - - return false; - } - - GoodLogin = AuthenticateUser(userProfile, passwd); - return GoodLogin; - } - - /// - /// Called when we receive the client's initial LLSD login_to_simulator request message - /// - /// The LLSD request - /// The response to send - public OSD LLSDLoginMethod(OSD request) - { - // Temporary fix - m_loginMutex.WaitOne(); - - try - { - // bool GoodLogin = false; - - string startLocationRequest = "last"; - - UserProfileData userProfile = null; - LoginResponse logResponse = new LoginResponse(); - - if (request.Type == OSDType.Map) - { - OSDMap map = (OSDMap)request; - - if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd")) - { - string firstname = map["first"].AsString(); - string lastname = map["last"].AsString(); - string passwd = map["passwd"].AsString(); - - if (map.ContainsKey("start")) - { - m_log.Info("[LOGIN]: LLSD StartLocation Requested: " + map["start"].AsString()); - startLocationRequest = map["start"].AsString(); - } - m_log.Info("[LOGIN]: LLSD Login Requested for: '" + firstname + "' '" + lastname + "' / " + passwd); - - if (!TryAuthenticateLLSDLogin(firstname, lastname, passwd, out userProfile)) - { - return logResponse.CreateLoginFailedResponseLLSD(); - } - } - else - return logResponse.CreateLoginFailedResponseLLSD(); - } - else - return logResponse.CreateLoginFailedResponseLLSD(); - - - if (userProfile.GodLevel < m_minLoginLevel) - { - return logResponse.CreateLoginBlockedResponseLLSD(); - } - else - { - // If we already have a session... - if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline) - { - userProfile.CurrentAgent.AgentOnline = false; - - m_userManager.CommitAgent(ref userProfile); - // try to tell the region that their user is dead. - LogOffUser(userProfile, " LLSD You were logged off because you logged in from another location"); - - // Reject the login - - m_log.InfoFormat( - "[LOGIN END]: LLSD Notifying user {0} {1} that they are already logged in", - userProfile.FirstName, userProfile.SurName); - - userProfile.CurrentAgent = null; - return logResponse.CreateAlreadyLoggedInResponseLLSD(); - } - - // Otherwise... - // Create a new agent session - - m_userManager.ResetAttachments(userProfile.ID); - - CreateAgent(userProfile, request); - - try - { - UUID agentID = userProfile.ID; - - //InventoryData inventData = GetInventorySkeleton(agentID); - InventoryData inventData = null; - - try - { - inventData = GetInventorySkeleton(agentID); - } - catch (Exception e) - { - m_log.ErrorFormat( - "[LOGIN END]: LLSD Error retrieving inventory skeleton of agent {0}, {1} - {2}", - agentID, e.GetType(), e.Message); - - return logResponse.CreateLoginFailedResponseLLSD();// .CreateLoginInventoryFailedResponseLLSD (); - } - - - ArrayList AgentInventoryArray = inventData.InventoryArray; - - Hashtable InventoryRootHash = new Hashtable(); - InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); - ArrayList InventoryRoot = new ArrayList(); - InventoryRoot.Add(InventoryRootHash); - userProfile.RootInventoryFolderID = inventData.RootFolderID; - - - // Inventory Library Section - Hashtable InventoryLibRootHash = new Hashtable(); - InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; - ArrayList InventoryLibRoot = new ArrayList(); - InventoryLibRoot.Add(InventoryLibRootHash); - - logResponse.InventoryLibRoot = InventoryLibRoot; - logResponse.InventoryLibraryOwner = GetLibraryOwner(); - logResponse.InventoryRoot = InventoryRoot; - logResponse.InventorySkeleton = AgentInventoryArray; - logResponse.InventoryLibrary = GetInventoryLibrary(); - - logResponse.CircuitCode = (Int32)Util.RandomClass.Next(); - logResponse.Lastname = userProfile.SurName; - logResponse.Firstname = userProfile.FirstName; - logResponse.AgentID = agentID; - logResponse.SessionID = userProfile.CurrentAgent.SessionID; - logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID; - logResponse.Message = GetMessage(); - logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); - logResponse.StartLocation = startLocationRequest; - - try - { - CustomiseResponse(logResponse, userProfile, startLocationRequest); - } - catch (Exception ex) - { - m_log.Info("[LOGIN]: LLSD " + ex.ToString()); - return logResponse.CreateDeadRegionResponseLLSD(); - } - - userProfile.LastLogin = userProfile.CurrentAgent.LoginTime; - CommitAgent(ref userProfile); - - // If we reach this point, then the login has successfully logged onto the grid - if (StatsManager.UserStats != null) - StatsManager.UserStats.AddSuccessfulLogin(); - - m_log.DebugFormat( - "[LOGIN END]: LLSD Authentication of user {0} {1} successful. Sending response to client.", - userProfile.FirstName, userProfile.SurName); - - return logResponse.ToLLSDResponse(); - } - catch (Exception ex) - { - m_log.Info("[LOGIN]: LLSD " + ex.ToString()); - return logResponse.CreateFailedResponseLLSD(); - } - } - } - finally - { - m_loginMutex.ReleaseMutex(); - } - } - - public Hashtable ProcessHTMLLogin(Hashtable keysvals) - { - // Matches all unspecified characters - // Currently specified,; lowercase letters, upper case letters, numbers, underline - // period, space, parens, and dash. - - Regex wfcut = new Regex("[^a-zA-Z0-9_\\.\\$ \\(\\)\\-]"); - - Hashtable returnactions = new Hashtable(); - int statuscode = 200; - - string firstname = String.Empty; - string lastname = String.Empty; - string location = String.Empty; - string region = String.Empty; - string grid = String.Empty; - string channel = String.Empty; - string version = String.Empty; - string lang = String.Empty; - string password = String.Empty; - string errormessages = String.Empty; - - // the client requires the HTML form field be named 'username' - // however, the data it sends when it loads the first time is 'firstname' - // another one of those little nuances. - - if (keysvals.Contains("firstname")) - firstname = wfcut.Replace((string)keysvals["firstname"], String.Empty, 99999); - - if (keysvals.Contains("username")) - firstname = wfcut.Replace((string)keysvals["username"], String.Empty, 99999); - - if (keysvals.Contains("lastname")) - lastname = wfcut.Replace((string)keysvals["lastname"], String.Empty, 99999); - - if (keysvals.Contains("location")) - location = wfcut.Replace((string)keysvals["location"], String.Empty, 99999); - - if (keysvals.Contains("region")) - region = wfcut.Replace((string)keysvals["region"], String.Empty, 99999); - - if (keysvals.Contains("grid")) - grid = wfcut.Replace((string)keysvals["grid"], String.Empty, 99999); - - if (keysvals.Contains("channel")) - channel = wfcut.Replace((string)keysvals["channel"], String.Empty, 99999); - - if (keysvals.Contains("version")) - version = wfcut.Replace((string)keysvals["version"], String.Empty, 99999); - - if (keysvals.Contains("lang")) - lang = wfcut.Replace((string)keysvals["lang"], String.Empty, 99999); - - if (keysvals.Contains("password")) - password = wfcut.Replace((string)keysvals["password"], String.Empty, 99999); - - // load our login form. - string loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages); - - if (keysvals.ContainsKey("show_login_form")) - { - UserProfileData user = GetTheUser(firstname, lastname); - bool goodweblogin = false; - - if (user != null) - goodweblogin = AuthenticateUser(user, password); - - if (goodweblogin) - { - UUID webloginkey = UUID.Random(); - m_userManager.StoreWebLoginKey(user.ID, webloginkey); - //statuscode = 301; - - // string redirectURL = "about:blank?redirect-http-hack=" + - // HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" + - // lastname + - // "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString()); - //m_log.Info("[WEB]: R:" + redirectURL); - returnactions["int_response_code"] = statuscode; - //returnactions["str_redirect_location"] = redirectURL; - //returnactions["str_response_string"] = "GoodLogin"; - returnactions["str_response_string"] = webloginkey.ToString(); - } - else - { - errormessages = "The Username and password supplied did not match our records. Check your caps lock and try again"; - - loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages); - returnactions["int_response_code"] = statuscode; - returnactions["str_response_string"] = loginform; - } - } - else - { - returnactions["int_response_code"] = statuscode; - returnactions["str_response_string"] = loginform; - } - return returnactions; - } - - public string GetLoginForm(string firstname, string lastname, string location, string region, - string grid, string channel, string version, string lang, - string password, string errormessages) - { - // inject our values in the form at the markers - - string loginform = String.Empty; - string file = Path.Combine(Util.configDir(), "http_loginform.html"); - if (!File.Exists(file)) - { - loginform = GetDefaultLoginForm(); - } - else - { - StreamReader sr = File.OpenText(file); - loginform = sr.ReadToEnd(); - sr.Close(); - } - - loginform = loginform.Replace("[$firstname]", firstname); - loginform = loginform.Replace("[$lastname]", lastname); - loginform = loginform.Replace("[$location]", location); - loginform = loginform.Replace("[$region]", region); - loginform = loginform.Replace("[$grid]", grid); - loginform = loginform.Replace("[$channel]", channel); - loginform = loginform.Replace("[$version]", version); - loginform = loginform.Replace("[$lang]", lang); - loginform = loginform.Replace("[$password]", password); - loginform = loginform.Replace("[$errors]", errormessages); - - return loginform; - } - - public string GetDefaultLoginForm() - { - string responseString = - ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += "OpenSim Login"; - responseString += "
"; - responseString += "
"; - - responseString += "
"; - - responseString += "
[$errors]
"; - responseString += "
"; - responseString += "First Name:"; - responseString += ""; - responseString += "
"; - responseString += "
"; - responseString += "Last Name:"; - responseString += ""; - responseString += "
"; - responseString += "
"; - responseString += "Password:"; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += "
"; - responseString += "
"; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += ""; - responseString += "
"; - responseString += ""; - responseString += "
"; - responseString += "
Connecting...
"; - - responseString += "
"; - - responseString += "
[$channel] | [$version]=[$lang]
"; - responseString += "
"; - responseString += ""; - responseString += "
"; - responseString += ""; - responseString += ""; - responseString += ""; - - return responseString; - } - - /// - /// Saves a target agent to the database - /// - /// The users profile - /// Successful? - public bool CommitAgent(ref UserProfileData profile) - { - return m_userManager.CommitAgent(ref profile); - } - - /// - /// Checks a user against it's password hash - /// - /// The users profile - /// The supplied password - /// Authenticated? - public virtual bool AuthenticateUser(UserProfileData profile, string password) - { - bool passwordSuccess = false; - //m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID); - - // Web Login method seems to also occasionally send the hashed password itself - - // we do this to get our hash in a form that the server password code can consume - // when the web-login-form submits the password in the clear (supposed to be over SSL!) - if (!password.StartsWith("$1$")) - password = "$1$" + Util.Md5Hash(password); - - password = password.Remove(0, 3); //remove $1$ - - string s = Util.Md5Hash(password + ":" + profile.PasswordSalt); - // Testing... - //m_log.Info("[LOGIN]: SubHash:" + s + " userprofile:" + profile.passwordHash); - //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password); - - passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase) - || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase)); - - return passwordSuccess; - } - - public virtual bool AuthenticateUser(UserProfileData profile, UUID webloginkey) - { - bool passwordSuccess = false; - m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID); - - // Match web login key unless it's the default weblogin key UUID.Zero - passwordSuccess = ((profile.WebLoginKey == webloginkey) && profile.WebLoginKey != UUID.Zero); - - return passwordSuccess; - } - - /// - /// - /// - /// - /// - public void CreateAgent(UserProfileData profile, XmlRpcRequest request) - { - m_userManager.CreateAgent(profile, request); - } - - public void CreateAgent(UserProfileData profile, OSD request) - { - m_userManager.CreateAgent(profile, request); - } - - /// - /// - /// - /// - /// - /// - public virtual UserProfileData GetTheUser(string firstname, string lastname) - { - return m_userManager.GetUserProfile(firstname, lastname); - } - - /// - /// - /// - /// - public virtual string GetMessage() - { - return m_welcomeMessage; - } - - private static LoginResponse.BuddyList ConvertFriendListItem(List LFL) - { - LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList(); - foreach (FriendListItem fl in LFL) - { - LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend); - buddyitem.BuddyID = fl.Friend; - buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms; - buddyitem.BuddyRightsGiven = (int)fl.FriendPerms; - buddylistreturn.AddNewBuddy(buddyitem); - } - return buddylistreturn; - } - - /// - /// Converts the inventory library skeleton into the form required by the rpc request. - /// - /// - protected virtual ArrayList GetInventoryLibrary() - { - Dictionary rootFolders - = m_libraryRootFolder.RequestSelfAndDescendentFolders(); - ArrayList folderHashes = new ArrayList(); - - foreach (InventoryFolderBase folder in rootFolders.Values) - { - Hashtable TempHash = new Hashtable(); - TempHash["name"] = folder.Name; - TempHash["parent_id"] = folder.ParentID.ToString(); - TempHash["version"] = (Int32)folder.Version; - TempHash["type_default"] = (Int32)folder.Type; - TempHash["folder_id"] = folder.ID.ToString(); - folderHashes.Add(TempHash); - } - - return folderHashes; - } - - /// - /// - /// - /// - protected virtual ArrayList GetLibraryOwner() - { - //for now create random inventory library owner - Hashtable TempHash = new Hashtable(); - TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; - ArrayList inventoryLibOwner = new ArrayList(); - inventoryLibOwner.Add(TempHash); - return inventoryLibOwner; - } - - public class InventoryData - { - public ArrayList InventoryArray = null; - public UUID RootFolderID = UUID.Zero; - - public InventoryData(ArrayList invList, UUID rootID) - { - InventoryArray = invList; - RootFolderID = rootID; - } - } - - protected void SniffLoginKey(Uri uri, Hashtable requestData) - { - string uri_str = uri.ToString(); - string[] parts = uri_str.Split(new char[] { '=' }); - if (parts.Length > 1) - { - string web_login_key = parts[1]; - requestData.Add("web_login_key", web_login_key); - m_log.InfoFormat("[LOGIN]: Login with web_login_key {0}", web_login_key); - } - } - - /// - /// Customises the login response and fills in missing values. This method also tells the login region to - /// expect a client connection. - /// - /// The existing response - /// The user profile - /// The requested start location - /// true on success, false if the region was not successfully told to expect a user connection - public bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) - { - // add active gestures to login-response - AddActiveGestures(response, theUser); - - // HomeLocation - RegionInfo homeInfo = null; - - // use the homeRegionID if it is stored already. If not, use the regionHandle as before - UUID homeRegionId = theUser.HomeRegionID; - ulong homeRegionHandle = theUser.HomeRegion; - if (homeRegionId != UUID.Zero) - { - homeInfo = GetRegionInfo(homeRegionId); - } - else - { - homeInfo = GetRegionInfo(homeRegionHandle); - } - - if (homeInfo != null) - { - response.Home = - string.Format( - "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", - (homeInfo.RegionLocX * Constants.RegionSize), - (homeInfo.RegionLocY * Constants.RegionSize), - theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, - theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); - } - else - { - m_log.InfoFormat("not found the region at {0} {1}", theUser.HomeRegionX, theUser.HomeRegionY); - // Emergency mode: Home-region isn't available, so we can't request the region info. - // Use the stored home regionHandle instead. - // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again - ulong regionX = homeRegionHandle >> 32; - ulong regionY = homeRegionHandle & 0xffffffff; - response.Home = - string.Format( - "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", - regionX, regionY, - theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, - theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); - - m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}", - theUser.FirstName, theUser.SurName, - regionX, regionY); - } - - // StartLocation - RegionInfo regionInfo = null; - if (startLocationRequest == "home") - { - regionInfo = homeInfo; - theUser.CurrentAgent.Position = theUser.HomeLocation; - response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]"; - } - else if (startLocationRequest == "last") - { - UUID lastRegion = theUser.CurrentAgent.Region; - regionInfo = GetRegionInfo(lastRegion); - response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]"; - } - else - { - Regex reURI = new Regex(@"^uri:(?[^&]+)&(?\d+)&(?\d+)&(?\d+)$"); - Match uriMatch = reURI.Match(startLocationRequest); - if (uriMatch == null) - { - m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest); - } - else - { - string region = uriMatch.Groups["region"].ToString(); - regionInfo = RequestClosestRegion(region); - if (regionInfo == null) - { - m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region); - } - else - { - theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), - float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value)); - } - } - response.LookAt = "[r0,r1,r0]"; - // can be: last, home, safe, url - response.StartLocation = "url"; - } - - if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response))) - { - return true; - } - - // StartLocation not available, send him to a nearby region instead - // regionInfo = m_gridService.RequestClosestRegion(""); - //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName); - - // Send him to default region instead - ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) | - ((ulong)m_defaultHomeY * Constants.RegionSize); - - if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle)) - { - m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); - return false; - } - - m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead"); - regionInfo = GetRegionInfo(defaultHandle); - - if (regionInfo == null) - { - m_log.ErrorFormat("[LOGIN]: No default region available. Aborting."); - return false; - } - - theUser.CurrentAgent.Position = new Vector3(128, 128, 0); - response.StartLocation = "safe"; - - return PrepareLoginToRegion(regionInfo, theUser, response); - } - - protected abstract RegionInfo RequestClosestRegion(string region); - protected abstract RegionInfo GetRegionInfo(ulong homeRegionHandle); - protected abstract RegionInfo GetRegionInfo(UUID homeRegionId); - protected abstract bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response); - - /// - /// Add active gestures of the user to the login response. - /// - /// - /// A - /// - /// - /// A - /// - protected void AddActiveGestures(LoginResponse response, UserProfileData theUser) - { - List gestures = m_inventoryService.GetActiveGestures(theUser.ID); - //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); - ArrayList list = new ArrayList(); - if (gestures != null) - { - foreach (InventoryItemBase gesture in gestures) - { - Hashtable item = new Hashtable(); - item["item_id"] = gesture.ID.ToString(); - item["asset_id"] = gesture.AssetID.ToString(); - list.Add(item); - } - } - response.ActiveGestures = list; - } - - /// - /// Get the initial login inventory skeleton (in other words, the folder structure) for the given user. - /// - /// - /// - /// This will be thrown if there is a problem with the inventory service - protected InventoryData GetInventorySkeleton(UUID userID) - { - List folders = m_inventoryService.GetInventorySkeleton(userID); - - // If we have user auth but no inventory folders for some reason, create a new set of folders. - if (folders == null || folders.Count == 0) - { - m_log.InfoFormat( - "[LOGIN]: A root inventory folder for user {0} was not found. Requesting creation.", userID); - - // Although the create user function creates a new agent inventory along with a new user profile, some - // tools are creating the user profile directly in the database without creating the inventory. At - // this time we'll accomodate them by lazily creating the user inventory now if it doesn't already - // exist. - if (!m_inventoryService.CreateNewUserInventory(userID)) - { - throw new Exception( - String.Format( - "The inventory creation request for user {0} did not succeed." - + " Please contact your inventory service provider for more information.", - userID)); - } - - m_log.InfoFormat("[LOGIN]: A new inventory skeleton was successfully created for user {0}", userID); - - folders = m_inventoryService.GetInventorySkeleton(userID); - - if (folders == null || folders.Count == 0) - { - throw new Exception( - String.Format( - "A root inventory folder for user {0} could not be retrieved from the inventory service", - userID)); - } - } - - UUID rootID = UUID.Zero; - ArrayList AgentInventoryArray = new ArrayList(); - Hashtable TempHash; - foreach (InventoryFolderBase InvFolder in folders) - { - if (InvFolder.ParentID == UUID.Zero) - { - rootID = InvFolder.ID; - } - TempHash = new Hashtable(); - TempHash["name"] = InvFolder.Name; - TempHash["parent_id"] = InvFolder.ParentID.ToString(); - TempHash["version"] = (Int32)InvFolder.Version; - TempHash["type_default"] = (Int32)InvFolder.Type; - TempHash["folder_id"] = InvFolder.ID.ToString(); - AgentInventoryArray.Add(TempHash); - } - - return new InventoryData(AgentInventoryArray, rootID); - } - } -} +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSim Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text.RegularExpressions; +using System.Threading; +using System.Web; +using log4net; +using Nwc.XmlRpc; +using OpenMetaverse; +using OpenMetaverse.StructuredData; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Statistics; + +namespace OpenSim.Framework.Communications.Services +{ + public abstract class LoginService + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected string m_welcomeMessage = "Welcome to OpenSim"; + protected int m_minLoginLevel = 0; + protected UserManagerBase m_userManager = null; + protected Mutex m_loginMutex = new Mutex(false); + + /// + /// Used during login to send the skeleton of the OpenSim Library to the client. + /// + protected LibraryRootFolder m_libraryRootFolder; + + protected uint m_defaultHomeX; + protected uint m_defaultHomeY; + + /// + /// Used by the login service to make requests to the inventory service. + /// + protected IInterServiceInventoryServices m_inventoryService; + + /// + /// Constructor + /// + /// + /// + /// + public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder, + string welcomeMess) + { + m_userManager = userManager; + m_libraryRootFolder = libraryRootFolder; + + if (welcomeMess != String.Empty) + { + m_welcomeMessage = welcomeMess; + } + } + + /// + /// If the user is already logged in, try to notify the region that the user they've got is dead. + /// + /// + public virtual void LogOffUser(UserProfileData theUser, string message) + { + } + + + /// + /// Called when we receive the client's initial XMLRPC login_to_simulator request message + /// + /// The XMLRPC request + /// The response to send + public virtual XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) + { + // Temporary fix + m_loginMutex.WaitOne(); + + try + { + //CFK: CustomizeResponse contains sufficient strings to alleviate the need for this. + //CKF: m_log.Info("[LOGIN]: Attempting login now..."); + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable requestData = (Hashtable)request.Params[0]; + + SniffLoginKey((Uri)request.Params[2], requestData); + + bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && + (requestData.Contains("passwd") || requestData.Contains("web_login_key"))); + + string startLocationRequest = "last"; + + UserProfileData userProfile; + LoginResponse logResponse = new LoginResponse(); + + string firstname; + string lastname; + + if (GoodXML) + { + if (requestData.Contains("start")) + { + startLocationRequest = (string)requestData["start"]; + } + + firstname = (string)requestData["first"]; + lastname = (string)requestData["last"]; + + m_log.InfoFormat( + "[LOGIN BEGIN]: XMLRPC Received login request message from user '{0}' '{1}'", + firstname, lastname); + + string clientVersion = "Unknown"; + + if (requestData.Contains("version")) + { + clientVersion = (string)requestData["version"]; + } + + m_log.DebugFormat( + "[LOGIN]: XMLRPC Client is {0}, start location is {1}", clientVersion, startLocationRequest); + + if (!TryAuthenticateXmlRpcLogin(request, firstname, lastname, out userProfile)) + { + return logResponse.CreateLoginFailedResponse(); + } + } + else + { + m_log.Info( + "[LOGIN END]: XMLRPC login_to_simulator login message did not contain all the required data"); + + return logResponse.CreateGridErrorResponse(); + } + + if (userProfile.GodLevel < m_minLoginLevel) + { + return logResponse.CreateLoginBlockedResponse(); + } + else + { + // If we already have a session... + if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline) + { + //TODO: The following statements can cause trouble: + // If agentOnline could not turn from true back to false normally + // because of some problem, for instance, the crashment of server or client, + // the user cannot log in any longer. + userProfile.CurrentAgent.AgentOnline = false; + + m_userManager.CommitAgent(ref userProfile); + + // try to tell the region that their user is dead. + LogOffUser(userProfile, " XMLRPC You were logged off because you logged in from another location"); + + // Reject the login + + m_log.InfoFormat( + "[LOGIN END]: XMLRPC Notifying user {0} {1} that they are already logged in", + firstname, lastname); + + return logResponse.CreateAlreadyLoggedInResponse(); + } + + // Otherwise... + // Create a new agent session + + m_userManager.ResetAttachments(userProfile.ID); + + CreateAgent(userProfile, request); + + try + { + UUID agentID = userProfile.ID; + InventoryData inventData; + + try + { + inventData = GetInventorySkeleton(agentID); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LOGIN END]: Error retrieving inventory skeleton of agent {0} - {1}", + agentID, e); + + return logResponse.CreateLoginInventoryFailedResponse(); + } + + ArrayList AgentInventoryArray = inventData.InventoryArray; + + Hashtable InventoryRootHash = new Hashtable(); + InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); + ArrayList InventoryRoot = new ArrayList(); + InventoryRoot.Add(InventoryRootHash); + userProfile.RootInventoryFolderID = inventData.RootFolderID; + + // Inventory Library Section + Hashtable InventoryLibRootHash = new Hashtable(); + InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; + ArrayList InventoryLibRoot = new ArrayList(); + InventoryLibRoot.Add(InventoryLibRootHash); + + logResponse.InventoryLibRoot = InventoryLibRoot; + logResponse.InventoryLibraryOwner = GetLibraryOwner(); + logResponse.InventoryRoot = InventoryRoot; + logResponse.InventorySkeleton = AgentInventoryArray; + logResponse.InventoryLibrary = GetInventoryLibrary(); + + logResponse.CircuitCode = Util.RandomClass.Next(); + logResponse.Lastname = userProfile.SurName; + logResponse.Firstname = userProfile.FirstName; + logResponse.AgentID = agentID; + logResponse.SessionID = userProfile.CurrentAgent.SessionID; + logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID; + logResponse.Message = GetMessage(); + logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); + logResponse.StartLocation = startLocationRequest; + + if (CustomiseResponse(logResponse, userProfile, startLocationRequest)) + { + userProfile.LastLogin = userProfile.CurrentAgent.LoginTime; + CommitAgent(ref userProfile); + + // If we reach this point, then the login has successfully logged onto the grid + if (StatsManager.UserStats != null) + StatsManager.UserStats.AddSuccessfulLogin(); + + m_log.DebugFormat( + "[LOGIN END]: XMLRPC Authentication of user {0} {1} successful. Sending response to client.", + firstname, lastname); + + return logResponse.ToXmlRpcResponse(); + } + else + { + m_log.ErrorFormat("[LOGIN END]: XMLRPC informing user {0} {1} that login failed due to an unavailable region", firstname, lastname); + return logResponse.CreateDeadRegionResponse(); + } + } + catch (Exception e) + { + m_log.Error("[LOGIN END]: XMLRPC Login failed, " + e); + m_log.Error(e.StackTrace); + } + } + + m_log.Info("[LOGIN END]: XMLRPC Login failed. Sending back blank XMLRPC response"); + return response; + } + finally + { + m_loginMutex.ReleaseMutex(); + } + } + + protected virtual bool TryAuthenticateXmlRpcLogin(XmlRpcRequest request, string firstname, string lastname, out UserProfileData userProfile) + { + Hashtable requestData = (Hashtable)request.Params[0]; + + bool GoodLogin = false; + + userProfile = GetTheUser(firstname, lastname); + if (userProfile == null) + { + m_log.Info("[LOGIN END]: XMLRPC Could not find a profile for " + firstname + " " + lastname); + } + else + { + if (requestData.Contains("passwd")) + { + string passwd = (string)requestData["passwd"]; + GoodLogin = AuthenticateUser(userProfile, passwd); + } + if (!GoodLogin && (requestData.Contains("web_login_key"))) + { + try + { + UUID webloginkey = new UUID((string)requestData["web_login_key"]); + GoodLogin = AuthenticateUser(userProfile, webloginkey); + } + catch (Exception e) + { + m_log.InfoFormat( + "[LOGIN END]: XMLRPC Bad web_login_key: {0} for user {1} {2}, exception {3}", + requestData["web_login_key"], firstname, lastname, e); + } + } + } + + return GoodLogin; + } + + protected virtual bool TryAuthenticateLLSDLogin(string firstname, string lastname, string passwd, out UserProfileData userProfile) + { + bool GoodLogin = false; + userProfile = GetTheUser(firstname, lastname); + if (userProfile == null) + { + m_log.Info("[LOGIN]: LLSD Could not find a profile for " + firstname + " " + lastname); + + return false; + } + + GoodLogin = AuthenticateUser(userProfile, passwd); + return GoodLogin; + } + + /// + /// Called when we receive the client's initial LLSD login_to_simulator request message + /// + /// The LLSD request + /// The response to send + public OSD LLSDLoginMethod(OSD request) + { + // Temporary fix + m_loginMutex.WaitOne(); + + try + { + // bool GoodLogin = false; + + string startLocationRequest = "last"; + + UserProfileData userProfile = null; + LoginResponse logResponse = new LoginResponse(); + + if (request.Type == OSDType.Map) + { + OSDMap map = (OSDMap)request; + + if (map.ContainsKey("first") && map.ContainsKey("last") && map.ContainsKey("passwd")) + { + string firstname = map["first"].AsString(); + string lastname = map["last"].AsString(); + string passwd = map["passwd"].AsString(); + + if (map.ContainsKey("start")) + { + m_log.Info("[LOGIN]: LLSD StartLocation Requested: " + map["start"].AsString()); + startLocationRequest = map["start"].AsString(); + } + m_log.Info("[LOGIN]: LLSD Login Requested for: '" + firstname + "' '" + lastname + "' / " + passwd); + + if (!TryAuthenticateLLSDLogin(firstname, lastname, passwd, out userProfile)) + { + return logResponse.CreateLoginFailedResponseLLSD(); + } + } + else + return logResponse.CreateLoginFailedResponseLLSD(); + } + else + return logResponse.CreateLoginFailedResponseLLSD(); + + + if (userProfile.GodLevel < m_minLoginLevel) + { + return logResponse.CreateLoginBlockedResponseLLSD(); + } + else + { + // If we already have a session... + if (userProfile.CurrentAgent != null && userProfile.CurrentAgent.AgentOnline) + { + userProfile.CurrentAgent.AgentOnline = false; + + m_userManager.CommitAgent(ref userProfile); + // try to tell the region that their user is dead. + LogOffUser(userProfile, " LLSD You were logged off because you logged in from another location"); + + // Reject the login + + m_log.InfoFormat( + "[LOGIN END]: LLSD Notifying user {0} {1} that they are already logged in", + userProfile.FirstName, userProfile.SurName); + + userProfile.CurrentAgent = null; + return logResponse.CreateAlreadyLoggedInResponseLLSD(); + } + + // Otherwise... + // Create a new agent session + + m_userManager.ResetAttachments(userProfile.ID); + + CreateAgent(userProfile, request); + + try + { + UUID agentID = userProfile.ID; + + //InventoryData inventData = GetInventorySkeleton(agentID); + InventoryData inventData = null; + + try + { + inventData = GetInventorySkeleton(agentID); + } + catch (Exception e) + { + m_log.ErrorFormat( + "[LOGIN END]: LLSD Error retrieving inventory skeleton of agent {0}, {1} - {2}", + agentID, e.GetType(), e.Message); + + return logResponse.CreateLoginFailedResponseLLSD();// .CreateLoginInventoryFailedResponseLLSD (); + } + + + ArrayList AgentInventoryArray = inventData.InventoryArray; + + Hashtable InventoryRootHash = new Hashtable(); + InventoryRootHash["folder_id"] = inventData.RootFolderID.ToString(); + ArrayList InventoryRoot = new ArrayList(); + InventoryRoot.Add(InventoryRootHash); + userProfile.RootInventoryFolderID = inventData.RootFolderID; + + + // Inventory Library Section + Hashtable InventoryLibRootHash = new Hashtable(); + InventoryLibRootHash["folder_id"] = "00000112-000f-0000-0000-000100bba000"; + ArrayList InventoryLibRoot = new ArrayList(); + InventoryLibRoot.Add(InventoryLibRootHash); + + logResponse.InventoryLibRoot = InventoryLibRoot; + logResponse.InventoryLibraryOwner = GetLibraryOwner(); + logResponse.InventoryRoot = InventoryRoot; + logResponse.InventorySkeleton = AgentInventoryArray; + logResponse.InventoryLibrary = GetInventoryLibrary(); + + logResponse.CircuitCode = (Int32)Util.RandomClass.Next(); + logResponse.Lastname = userProfile.SurName; + logResponse.Firstname = userProfile.FirstName; + logResponse.AgentID = agentID; + logResponse.SessionID = userProfile.CurrentAgent.SessionID; + logResponse.SecureSessionID = userProfile.CurrentAgent.SecureSessionID; + logResponse.Message = GetMessage(); + logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); + logResponse.StartLocation = startLocationRequest; + + try + { + CustomiseResponse(logResponse, userProfile, startLocationRequest); + } + catch (Exception ex) + { + m_log.Info("[LOGIN]: LLSD " + ex.ToString()); + return logResponse.CreateDeadRegionResponseLLSD(); + } + + userProfile.LastLogin = userProfile.CurrentAgent.LoginTime; + CommitAgent(ref userProfile); + + // If we reach this point, then the login has successfully logged onto the grid + if (StatsManager.UserStats != null) + StatsManager.UserStats.AddSuccessfulLogin(); + + m_log.DebugFormat( + "[LOGIN END]: LLSD Authentication of user {0} {1} successful. Sending response to client.", + userProfile.FirstName, userProfile.SurName); + + return logResponse.ToLLSDResponse(); + } + catch (Exception ex) + { + m_log.Info("[LOGIN]: LLSD " + ex.ToString()); + return logResponse.CreateFailedResponseLLSD(); + } + } + } + finally + { + m_loginMutex.ReleaseMutex(); + } + } + + public Hashtable ProcessHTMLLogin(Hashtable keysvals) + { + // Matches all unspecified characters + // Currently specified,; lowercase letters, upper case letters, numbers, underline + // period, space, parens, and dash. + + Regex wfcut = new Regex("[^a-zA-Z0-9_\\.\\$ \\(\\)\\-]"); + + Hashtable returnactions = new Hashtable(); + int statuscode = 200; + + string firstname = String.Empty; + string lastname = String.Empty; + string location = String.Empty; + string region = String.Empty; + string grid = String.Empty; + string channel = String.Empty; + string version = String.Empty; + string lang = String.Empty; + string password = String.Empty; + string errormessages = String.Empty; + + // the client requires the HTML form field be named 'username' + // however, the data it sends when it loads the first time is 'firstname' + // another one of those little nuances. + + if (keysvals.Contains("firstname")) + firstname = wfcut.Replace((string)keysvals["firstname"], String.Empty, 99999); + + if (keysvals.Contains("username")) + firstname = wfcut.Replace((string)keysvals["username"], String.Empty, 99999); + + if (keysvals.Contains("lastname")) + lastname = wfcut.Replace((string)keysvals["lastname"], String.Empty, 99999); + + if (keysvals.Contains("location")) + location = wfcut.Replace((string)keysvals["location"], String.Empty, 99999); + + if (keysvals.Contains("region")) + region = wfcut.Replace((string)keysvals["region"], String.Empty, 99999); + + if (keysvals.Contains("grid")) + grid = wfcut.Replace((string)keysvals["grid"], String.Empty, 99999); + + if (keysvals.Contains("channel")) + channel = wfcut.Replace((string)keysvals["channel"], String.Empty, 99999); + + if (keysvals.Contains("version")) + version = wfcut.Replace((string)keysvals["version"], String.Empty, 99999); + + if (keysvals.Contains("lang")) + lang = wfcut.Replace((string)keysvals["lang"], String.Empty, 99999); + + if (keysvals.Contains("password")) + password = wfcut.Replace((string)keysvals["password"], String.Empty, 99999); + + // load our login form. + string loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages); + + if (keysvals.ContainsKey("show_login_form")) + { + UserProfileData user = GetTheUser(firstname, lastname); + bool goodweblogin = false; + + if (user != null) + goodweblogin = AuthenticateUser(user, password); + + if (goodweblogin) + { + UUID webloginkey = UUID.Random(); + m_userManager.StoreWebLoginKey(user.ID, webloginkey); + //statuscode = 301; + + // string redirectURL = "about:blank?redirect-http-hack=" + + // HttpUtility.UrlEncode("secondlife:///app/login?first_name=" + firstname + "&last_name=" + + // lastname + + // "&location=" + location + "&grid=Other&web_login_key=" + webloginkey.ToString()); + //m_log.Info("[WEB]: R:" + redirectURL); + returnactions["int_response_code"] = statuscode; + //returnactions["str_redirect_location"] = redirectURL; + //returnactions["str_response_string"] = "GoodLogin"; + returnactions["str_response_string"] = webloginkey.ToString(); + } + else + { + errormessages = "The Username and password supplied did not match our records. Check your caps lock and try again"; + + loginform = GetLoginForm(firstname, lastname, location, region, grid, channel, version, lang, password, errormessages); + returnactions["int_response_code"] = statuscode; + returnactions["str_response_string"] = loginform; + } + } + else + { + returnactions["int_response_code"] = statuscode; + returnactions["str_response_string"] = loginform; + } + return returnactions; + } + + public string GetLoginForm(string firstname, string lastname, string location, string region, + string grid, string channel, string version, string lang, + string password, string errormessages) + { + // inject our values in the form at the markers + + string loginform = String.Empty; + string file = Path.Combine(Util.configDir(), "http_loginform.html"); + if (!File.Exists(file)) + { + loginform = GetDefaultLoginForm(); + } + else + { + StreamReader sr = File.OpenText(file); + loginform = sr.ReadToEnd(); + sr.Close(); + } + + loginform = loginform.Replace("[$firstname]", firstname); + loginform = loginform.Replace("[$lastname]", lastname); + loginform = loginform.Replace("[$location]", location); + loginform = loginform.Replace("[$region]", region); + loginform = loginform.Replace("[$grid]", grid); + loginform = loginform.Replace("[$channel]", channel); + loginform = loginform.Replace("[$version]", version); + loginform = loginform.Replace("[$lang]", lang); + loginform = loginform.Replace("[$password]", password); + loginform = loginform.Replace("[$errors]", errormessages); + + return loginform; + } + + public string GetDefaultLoginForm() + { + string responseString = + ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += "OpenSim Login"; + responseString += "
"; + responseString += "
"; + + responseString += "
"; + + responseString += "
[$errors]
"; + responseString += "
"; + responseString += "First Name:"; + responseString += ""; + responseString += "
"; + responseString += "
"; + responseString += "Last Name:"; + responseString += ""; + responseString += "
"; + responseString += "
"; + responseString += "Password:"; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += "
"; + responseString += "
"; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += ""; + responseString += "
"; + responseString += ""; + responseString += "
"; + responseString += "
Connecting...
"; + + responseString += "
"; + + responseString += "
[$channel] | [$version]=[$lang]
"; + responseString += "
"; + responseString += ""; + responseString += "
"; + responseString += ""; + responseString += ""; + responseString += ""; + + return responseString; + } + + /// + /// Saves a target agent to the database + /// + /// The users profile + /// Successful? + public bool CommitAgent(ref UserProfileData profile) + { + return m_userManager.CommitAgent(ref profile); + } + + /// + /// Checks a user against it's password hash + /// + /// The users profile + /// The supplied password + /// Authenticated? + public virtual bool AuthenticateUser(UserProfileData profile, string password) + { + bool passwordSuccess = false; + //m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID); + + // Web Login method seems to also occasionally send the hashed password itself + + // we do this to get our hash in a form that the server password code can consume + // when the web-login-form submits the password in the clear (supposed to be over SSL!) + if (!password.StartsWith("$1$")) + password = "$1$" + Util.Md5Hash(password); + + password = password.Remove(0, 3); //remove $1$ + + string s = Util.Md5Hash(password + ":" + profile.PasswordSalt); + // Testing... + //m_log.Info("[LOGIN]: SubHash:" + s + " userprofile:" + profile.passwordHash); + //m_log.Info("[LOGIN]: userprofile:" + profile.passwordHash + " SubCT:" + password); + + passwordSuccess = (profile.PasswordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase) + || profile.PasswordHash.Equals(password, StringComparison.InvariantCultureIgnoreCase)); + + return passwordSuccess; + } + + public virtual bool AuthenticateUser(UserProfileData profile, UUID webloginkey) + { + bool passwordSuccess = false; + m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.FirstName, profile.SurName, profile.ID); + + // Match web login key unless it's the default weblogin key UUID.Zero + passwordSuccess = ((profile.WebLoginKey == webloginkey) && profile.WebLoginKey != UUID.Zero); + + return passwordSuccess; + } + + /// + /// + /// + /// + /// + public void CreateAgent(UserProfileData profile, XmlRpcRequest request) + { + m_userManager.CreateAgent(profile, request); + } + + public void CreateAgent(UserProfileData profile, OSD request) + { + m_userManager.CreateAgent(profile, request); + } + + /// + /// + /// + /// + /// + /// + public virtual UserProfileData GetTheUser(string firstname, string lastname) + { + return m_userManager.GetUserProfile(firstname, lastname); + } + + /// + /// + /// + /// + public virtual string GetMessage() + { + return m_welcomeMessage; + } + + private static LoginResponse.BuddyList ConvertFriendListItem(List LFL) + { + LoginResponse.BuddyList buddylistreturn = new LoginResponse.BuddyList(); + foreach (FriendListItem fl in LFL) + { + LoginResponse.BuddyList.BuddyInfo buddyitem = new LoginResponse.BuddyList.BuddyInfo(fl.Friend); + buddyitem.BuddyID = fl.Friend; + buddyitem.BuddyRightsHave = (int)fl.FriendListOwnerPerms; + buddyitem.BuddyRightsGiven = (int)fl.FriendPerms; + buddylistreturn.AddNewBuddy(buddyitem); + } + return buddylistreturn; + } + + /// + /// Converts the inventory library skeleton into the form required by the rpc request. + /// + /// + protected virtual ArrayList GetInventoryLibrary() + { + Dictionary rootFolders + = m_libraryRootFolder.RequestSelfAndDescendentFolders(); + ArrayList folderHashes = new ArrayList(); + + foreach (InventoryFolderBase folder in rootFolders.Values) + { + Hashtable TempHash = new Hashtable(); + TempHash["name"] = folder.Name; + TempHash["parent_id"] = folder.ParentID.ToString(); + TempHash["version"] = (Int32)folder.Version; + TempHash["type_default"] = (Int32)folder.Type; + TempHash["folder_id"] = folder.ID.ToString(); + folderHashes.Add(TempHash); + } + + return folderHashes; + } + + /// + /// + /// + /// + protected virtual ArrayList GetLibraryOwner() + { + //for now create random inventory library owner + Hashtable TempHash = new Hashtable(); + TempHash["agent_id"] = "11111111-1111-0000-0000-000100bba000"; + ArrayList inventoryLibOwner = new ArrayList(); + inventoryLibOwner.Add(TempHash); + return inventoryLibOwner; + } + + public class InventoryData + { + public ArrayList InventoryArray = null; + public UUID RootFolderID = UUID.Zero; + + public InventoryData(ArrayList invList, UUID rootID) + { + InventoryArray = invList; + RootFolderID = rootID; + } + } + + protected void SniffLoginKey(Uri uri, Hashtable requestData) + { + string uri_str = uri.ToString(); + string[] parts = uri_str.Split(new char[] { '=' }); + if (parts.Length > 1) + { + string web_login_key = parts[1]; + requestData.Add("web_login_key", web_login_key); + m_log.InfoFormat("[LOGIN]: Login with web_login_key {0}", web_login_key); + } + } + + /// + /// Customises the login response and fills in missing values. This method also tells the login region to + /// expect a client connection. + /// + /// The existing response + /// The user profile + /// The requested start location + /// true on success, false if the region was not successfully told to expect a user connection + public bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) + { + // add active gestures to login-response + AddActiveGestures(response, theUser); + + // HomeLocation + RegionInfo homeInfo = null; + + // use the homeRegionID if it is stored already. If not, use the regionHandle as before + UUID homeRegionId = theUser.HomeRegionID; + ulong homeRegionHandle = theUser.HomeRegion; + if (homeRegionId != UUID.Zero) + { + homeInfo = GetRegionInfo(homeRegionId); + } + else + { + homeInfo = GetRegionInfo(homeRegionHandle); + } + + if (homeInfo != null) + { + response.Home = + string.Format( + "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", + (homeInfo.RegionLocX * Constants.RegionSize), + (homeInfo.RegionLocY * Constants.RegionSize), + theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, + theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); + } + else + { + m_log.InfoFormat("not found the region at {0} {1}", theUser.HomeRegionX, theUser.HomeRegionY); + // Emergency mode: Home-region isn't available, so we can't request the region info. + // Use the stored home regionHandle instead. + // NOTE: If the home-region moves, this will be wrong until the users update their user-profile again + ulong regionX = homeRegionHandle >> 32; + ulong regionY = homeRegionHandle & 0xffffffff; + response.Home = + string.Format( + "{{'region_handle':[r{0},r{1}], 'position':[r{2},r{3},r{4}], 'look_at':[r{5},r{6},r{7}]}}", + regionX, regionY, + theUser.HomeLocation.X, theUser.HomeLocation.Y, theUser.HomeLocation.Z, + theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); + + m_log.InfoFormat("[LOGIN] Home region of user {0} {1} is not available; using computed region position {2} {3}", + theUser.FirstName, theUser.SurName, + regionX, regionY); + } + + // StartLocation + RegionInfo regionInfo = null; + if (startLocationRequest == "home") + { + regionInfo = homeInfo; + theUser.CurrentAgent.Position = theUser.HomeLocation; + response.LookAt = "[r" + theUser.HomeLookAt.X.ToString() + ",r" + theUser.HomeLookAt.Y.ToString() + ",r" + theUser.HomeLookAt.Z.ToString() + "]"; + } + else if (startLocationRequest == "last") + { + UUID lastRegion = theUser.CurrentAgent.Region; + regionInfo = GetRegionInfo(lastRegion); + response.LookAt = "[r" + theUser.CurrentAgent.LookAt.X.ToString() + ",r" + theUser.CurrentAgent.LookAt.Y.ToString() + ",r" + theUser.CurrentAgent.LookAt.Z.ToString() + "]"; + } + else + { + Regex reURI = new Regex(@"^uri:(?[^&]+)&(?\d+)&(?\d+)&(?\d+)$"); + Match uriMatch = reURI.Match(startLocationRequest); + if (uriMatch == null) + { + m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, but can't process it", startLocationRequest); + } + else + { + string region = uriMatch.Groups["region"].ToString(); + regionInfo = RequestClosestRegion(region); + if (regionInfo == null) + { + m_log.InfoFormat("[LOGIN]: Got Custom Login URL {0}, can't locate region {1}", startLocationRequest, region); + } + else + { + theUser.CurrentAgent.Position = new Vector3(float.Parse(uriMatch.Groups["x"].Value), + float.Parse(uriMatch.Groups["y"].Value), float.Parse(uriMatch.Groups["z"].Value)); + } + } + response.LookAt = "[r0,r1,r0]"; + // can be: last, home, safe, url + response.StartLocation = "url"; + } + + if ((regionInfo != null) && (PrepareLoginToRegion(regionInfo, theUser, response))) + { + return true; + } + + // StartLocation not available, send him to a nearby region instead + // regionInfo = m_gridService.RequestClosestRegion(""); + //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName); + + // Send him to default region instead + ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) | + ((ulong)m_defaultHomeY * Constants.RegionSize); + + if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle)) + { + m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); + return false; + } + + m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead"); + regionInfo = GetRegionInfo(defaultHandle); + + if (regionInfo == null) + { + m_log.ErrorFormat("[LOGIN]: No default region available. Aborting."); + return false; + } + + theUser.CurrentAgent.Position = new Vector3(128, 128, 0); + response.StartLocation = "safe"; + + return PrepareLoginToRegion(regionInfo, theUser, response); + } + + protected abstract RegionInfo RequestClosestRegion(string region); + protected abstract RegionInfo GetRegionInfo(ulong homeRegionHandle); + protected abstract RegionInfo GetRegionInfo(UUID homeRegionId); + protected abstract bool PrepareLoginToRegion(RegionInfo regionInfo, UserProfileData user, LoginResponse response); + + /// + /// Add active gestures of the user to the login response. + /// + /// + /// A + /// + /// + /// A + /// + protected void AddActiveGestures(LoginResponse response, UserProfileData theUser) + { + List gestures = m_inventoryService.GetActiveGestures(theUser.ID); + //m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); + ArrayList list = new ArrayList(); + if (gestures != null) + { + foreach (InventoryItemBase gesture in gestures) + { + Hashtable item = new Hashtable(); + item["item_id"] = gesture.ID.ToString(); + item["asset_id"] = gesture.AssetID.ToString(); + list.Add(item); + } + } + response.ActiveGestures = list; + } + + /// + /// Get the initial login inventory skeleton (in other words, the folder structure) for the given user. + /// + /// + /// + /// This will be thrown if there is a problem with the inventory service + protected InventoryData GetInventorySkeleton(UUID userID) + { + List folders = m_inventoryService.GetInventorySkeleton(userID); + + // If we have user auth but no inventory folders for some reason, create a new set of folders. + if (folders == null || folders.Count == 0) + { + m_log.InfoFormat( + "[LOGIN]: A root inventory folder for user {0} was not found. Requesting creation.", userID); + + // Although the create user function creates a new agent inventory along with a new user profile, some + // tools are creating the user profile directly in the database without creating the inventory. At + // this time we'll accomodate them by lazily creating the user inventory now if it doesn't already + // exist. + if (!m_inventoryService.CreateNewUserInventory(userID)) + { + throw new Exception( + String.Format( + "The inventory creation request for user {0} did not succeed." + + " Please contact your inventory service provider for more information.", + userID)); + } + + m_log.InfoFormat("[LOGIN]: A new inventory skeleton was successfully created for user {0}", userID); + + folders = m_inventoryService.GetInventorySkeleton(userID); + + if (folders == null || folders.Count == 0) + { + throw new Exception( + String.Format( + "A root inventory folder for user {0} could not be retrieved from the inventory service", + userID)); + } + } + + UUID rootID = UUID.Zero; + ArrayList AgentInventoryArray = new ArrayList(); + Hashtable TempHash; + foreach (InventoryFolderBase InvFolder in folders) + { + if (InvFolder.ParentID == UUID.Zero) + { + rootID = InvFolder.ID; + } + TempHash = new Hashtable(); + TempHash["name"] = InvFolder.Name; + TempHash["parent_id"] = InvFolder.ParentID.ToString(); + TempHash["version"] = (Int32)InvFolder.Version; + TempHash["type_default"] = (Int32)InvFolder.Type; + TempHash["folder_id"] = InvFolder.ID.ToString(); + AgentInventoryArray.Add(TempHash); + } + + return new InventoryData(AgentInventoryArray, rootID); + } + } +} diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs index ca25922281..303efe18be 100644 --- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs @@ -34,6 +34,7 @@ using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using Nwc.XmlRpc; using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Communications.Services; using OpenSim.Region.Communications.Local; using OpenSim.Tests.Common.Mock; using OpenSim.Client.Linden; diff --git a/OpenSim/Grid/UserServer.Modules/GridInfoServiceModule.cs b/OpenSim/Grid/UserServer.Modules/GridInfoServiceModule.cs index 33b55b67e8..902dccd9bf 100644 --- a/OpenSim/Grid/UserServer.Modules/GridInfoServiceModule.cs +++ b/OpenSim/Grid/UserServer.Modules/GridInfoServiceModule.cs @@ -34,6 +34,7 @@ using log4net.Config; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Services; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Servers; using OpenSim.Grid.Communications.OGS1; diff --git a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs b/OpenSim/Grid/UserServer.Modules/UserLoginService.cs index b354630359..3598ac6911 100644 --- a/OpenSim/Grid/UserServer.Modules/UserLoginService.cs +++ b/OpenSim/Grid/UserServer.Modules/UserLoginService.cs @@ -36,6 +36,7 @@ using OpenMetaverse; using OpenSim.Data; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Services; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Communications.Capabilities; using OpenSim.Framework.Servers; diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 05f773e266..ffabdd84c4 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -36,6 +36,7 @@ using Nini.Config; using OpenMetaverse; using OpenSim.Framework; using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Services; using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Console; using OpenSim.Framework.Servers; diff --git a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs index 8b7c3d1a2a..375a81be4d 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGCommunicationsGridMode.cs @@ -59,7 +59,7 @@ namespace OpenSim.Region.Communications.Hypergrid m_osw = gridInterComms; // The HG InventoryService always uses secure handlers - HGInventoryService invService = new HGInventoryService(serversInfo.InventoryURL, this.m_userProfileCacheService, true); + HGInventoryServiceClient invService = new HGInventoryServiceClient(serversInfo.InventoryURL, this.m_userProfileCacheService, true); AddSecureInventoryService(invService); m_defaultInventoryHost = invService.Host; if (SecureInventoryService != null) diff --git a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs index a9e008ccb9..2e402a4e1b 100644 --- a/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs +++ b/OpenSim/Region/Communications/Hypergrid/HGInventoryService.cs @@ -40,7 +40,7 @@ using OpenSim.Region.Communications.Local; namespace OpenSim.Region.Communications.Hypergrid { - public class HGInventoryService : LocalInventoryService, ISecureInventoryService + public class HGInventoryServiceClient : LocalInventoryService, ISecureInventoryService { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); @@ -58,7 +58,7 @@ namespace OpenSim.Region.Communications.Hypergrid set { m_userProfileCache = value; } } - public HGInventoryService(string inventoryServerUrl, UserProfileCacheService userProfileCacheService, bool gridmode) + public HGInventoryServiceClient(string inventoryServerUrl, UserProfileCacheService userProfileCacheService, bool gridmode) { _inventoryServerUrl = HGNetworkServersInfo.ServerURI(inventoryServerUrl); //m_Uri = new Uri(_inventoryServerUrl);