From 54ccca1e2cb8af5d0fdc420f64574a7d7b13c94b Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Tue, 31 Mar 2009 02:00:33 +0000 Subject: Update svn properties, add copyright header, formatting cleanup. --- .../Rest/Inventory/RestHandler.cs | 2 +- .../Framework/Communications/Cache/AssetCache.cs | 4 +- .../Framework/Communications/IAuthentication.cs | 51 +- .../Communications/Services/GridInfoService.cs | 344 +-- .../Communications/Services/LoginResponse.cs | 1624 +++++++-------- .../Communications/Services/LoginService.cs | 2186 ++++++++++---------- .../UserServer.Modules/UserLoginAuthService.cs | 448 ++-- .../Avatar/InstantMessage/OfflineMessageModule.cs | 2 +- .../Hypergrid/HGStandaloneInventoryModule.cs | 330 +-- .../Hypergrid/HGStandaloneLoginModule.cs | 506 ++--- .../DynamicTexture/DynamicTextureModule.cs | 64 +- .../Shared/Api/Implementation/LSL_Api.cs | 56 +- .../Shared/Api/Implementation/Plugins/Timer.cs | 1 - 13 files changed, 2819 insertions(+), 2799 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs b/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs index 5ff9da3..180d6f4 100644 --- a/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs +++ b/OpenSim/ApplicationPlugins/Rest/Inventory/RestHandler.cs @@ -227,7 +227,7 @@ namespace OpenSim.ApplicationPlugins.Rest.Inventory // them easy to reach from anywhere in the assembly. Rest.main = openSim; - if(Rest.main == null) + if (Rest.main == null) throw new Exception("OpenSim base pointer is null"); Rest.Plugin = this; diff --git a/OpenSim/Framework/Communications/Cache/AssetCache.cs b/OpenSim/Framework/Communications/Cache/AssetCache.cs index d79645e..73aa6ba 100644 --- a/OpenSim/Framework/Communications/Cache/AssetCache.cs +++ b/OpenSim/Framework/Communications/Cache/AssetCache.cs @@ -503,7 +503,7 @@ namespace OpenSim.Framework.Communications.Cache req.Params = transferRequest.TransferInfo.Params; req.AssetInf = new AssetInfo(asset); req.NumPackets = CalculateNumPackets(asset.Data); - lock(AssetRequests) AssetRequests.Add(req); + lock (AssetRequests) AssetRequests.Add(req); } /// @@ -526,7 +526,7 @@ namespace OpenSim.Framework.Communications.Cache for (int i = 0; i < num; i++) { - lock(AssetRequests) + lock (AssetRequests) { req = AssetRequests[0]; AssetRequests.RemoveAt(0); diff --git a/OpenSim/Framework/Communications/IAuthentication.cs b/OpenSim/Framework/Communications/IAuthentication.cs index 5d6d5f2..0f62569 100644 --- a/OpenSim/Framework/Communications/IAuthentication.cs +++ b/OpenSim/Framework/Communications/IAuthentication.cs @@ -1,13 +1,38 @@ -using System; - -using OpenMetaverse; - - -namespace OpenSim.Framework.Communications -{ - public interface IAuthentication - { - string GetNewKey(string url, UUID userID, UUID authToken); - bool VerifyKey(UUID userID, string key); - } -} +/* + * 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 OpenSimulator 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 OpenMetaverse; + +namespace OpenSim.Framework.Communications +{ + public interface IAuthentication + { + string GetNewKey(string url, UUID userID, UUID authToken); + bool VerifyKey(UUID userID, string key); + } +} diff --git a/OpenSim/Framework/Communications/Services/GridInfoService.cs b/OpenSim/Framework/Communications/Services/GridInfoService.cs index 96fe0d8..030ea61 100644 --- a/OpenSim/Framework/Communications/Services/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.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(); - } - } -} +/* + * 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/LoginResponse.cs b/OpenSim/Framework/Communications/Services/LoginResponse.cs index 82515e0..db208a4 100644 --- a/OpenSim/Framework/Communications/Services/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.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; - } - } - } - } -} +/* + * 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/Services/LoginService.cs b/OpenSim/Framework/Communications/Services/LoginService.cs index 51158c9..1b6520d 100644 --- a/OpenSim/Framework/Communications/Services/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.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); - } - } -} +/* + * 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/Grid/UserServer.Modules/UserLoginAuthService.cs b/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs index a910136..4811434 100644 --- a/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs +++ b/OpenSim/Grid/UserServer.Modules/UserLoginAuthService.cs @@ -1,224 +1,224 @@ -/* - * 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 System.Text.RegularExpressions; -using log4net; -using Nwc.XmlRpc; -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; - -namespace OpenSim.Grid.UserServer.Modules -{ - - /// - /// Hypergrid login service used in grid mode. - /// - public class UserLoginAuthService : HGLoginAuthService - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public UserConfig m_config; - private readonly IRegionProfileRouter m_regionProfileService; - - protected BaseHttpServer m_httpServer; - - public UserLoginAuthService( - UserManagerBase userManager, IInterServiceInventoryServices inventoryService, - LibraryRootFolder libraryRootFolder, - UserConfig config, string welcomeMess, IRegionProfileRouter regionProfileService) - : base(userManager, welcomeMess, inventoryService, null, true, libraryRootFolder, null) - { - m_config = config; - m_defaultHomeX = m_config.DefaultX; - m_defaultHomeY = m_config.DefaultY; - m_inventoryService = inventoryService; - m_regionProfileService = regionProfileService; - - NetworkServersInfo serversinfo = new NetworkServersInfo(1000, 1000); - serversinfo.GridRecvKey = m_config.GridRecvKey; - serversinfo.GridSendKey = m_config.GridSendKey; - serversinfo.GridURL = m_config.GridServerURL.ToString(); - serversinfo.InventoryURL = m_config.InventoryUrl.ToString(); - serversinfo.UserURL = m_config.AuthUrl.ToString(); - SetServersInfo(serversinfo); - } - - public void RegisterHandlers(BaseHttpServer httpServer) - { - m_httpServer = httpServer; - - httpServer.AddXmlRPCHandler("hg_login", XmlRpcLoginMethod); - httpServer.AddXmlRPCHandler("hg_new_auth_key", XmlRpcGenerateKeyMethod); - httpServer.AddXmlRPCHandler("hg_verify_auth_key", XmlRpcVerifyKeyMethod); - } - - - public override void LogOffUser(UserProfileData theUser, string message) - { - RegionProfileData SimInfo; - try - { - SimInfo = m_regionProfileService.RequestSimProfileData( - theUser.CurrentAgent.Handle, m_config.GridServerURL, - m_config.GridSendKey, m_config.GridRecvKey); - - if (SimInfo == null) - { - m_log.Error("[GRID]: Region user was in isn't currently logged in"); - return; - } - } - catch (Exception) - { - m_log.Error("[GRID]: Unable to look up region to log user off"); - return; - } - - // Prepare notification - Hashtable SimParams = new Hashtable(); - SimParams["agent_id"] = theUser.ID.ToString(); - SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); - SimParams["region_secret2"] = SimInfo.regionSecret; - //m_log.Info(SimInfo.regionSecret); - SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); - SimParams["message"] = message; - ArrayList SendParams = new ArrayList(); - SendParams.Add(SimParams); - - m_log.InfoFormat( - "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", - SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, - theUser.FirstName + " " + theUser.SurName); - - try - { - XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); - XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); - - if (GridResp.IsFault) - { - m_log.ErrorFormat( - "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", - SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); - } - } - catch (Exception) - { - m_log.Error("[LOGIN]: Error telling region to logout user!"); - } - - // Prepare notification - SimParams = new Hashtable(); - SimParams["agent_id"] = theUser.ID.ToString(); - SimParams["region_secret"] = SimInfo.regionSecret; - //m_log.Info(SimInfo.regionSecret); - SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); - SimParams["message"] = message; - SendParams = new ArrayList(); - SendParams.Add(SimParams); - - m_log.InfoFormat( - "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", - SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, - theUser.FirstName + " " + theUser.SurName); - - try - { - XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); - XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); - - if (GridResp.IsFault) - { - m_log.ErrorFormat( - "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", - SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); - } - } - catch (Exception) - { - m_log.Error("[LOGIN]: Error telling region to logout user!"); - } - //base.LogOffUser(theUser); - } - - protected override RegionInfo RequestClosestRegion(string region) - { - RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(region, - m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); - - if (profileData != null) - { - return profileData.ToRegionInfo(); - } - else - { - return null; - } - } - - protected override RegionInfo GetRegionInfo(ulong homeRegionHandle) - { - RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionHandle, - m_config.GridServerURL, m_config.GridSendKey, - m_config.GridRecvKey); - if (profileData != null) - { - return profileData.ToRegionInfo(); - } - else - { - return null; - } - } - - protected override RegionInfo GetRegionInfo(UUID homeRegionId) - { - RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionId, - m_config.GridServerURL, m_config.GridSendKey, - m_config.GridRecvKey); - if (profileData != null) - { - return profileData.ToRegionInfo(); - } - else - { - return null; - } - } - - } -} +/* + * 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 System.Text.RegularExpressions; +using log4net; +using Nwc.XmlRpc; +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; + +namespace OpenSim.Grid.UserServer.Modules +{ + + /// + /// Hypergrid login service used in grid mode. + /// + public class UserLoginAuthService : HGLoginAuthService + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public UserConfig m_config; + private readonly IRegionProfileRouter m_regionProfileService; + + protected BaseHttpServer m_httpServer; + + public UserLoginAuthService( + UserManagerBase userManager, IInterServiceInventoryServices inventoryService, + LibraryRootFolder libraryRootFolder, + UserConfig config, string welcomeMess, IRegionProfileRouter regionProfileService) + : base(userManager, welcomeMess, inventoryService, null, true, libraryRootFolder, null) + { + m_config = config; + m_defaultHomeX = m_config.DefaultX; + m_defaultHomeY = m_config.DefaultY; + m_inventoryService = inventoryService; + m_regionProfileService = regionProfileService; + + NetworkServersInfo serversinfo = new NetworkServersInfo(1000, 1000); + serversinfo.GridRecvKey = m_config.GridRecvKey; + serversinfo.GridSendKey = m_config.GridSendKey; + serversinfo.GridURL = m_config.GridServerURL.ToString(); + serversinfo.InventoryURL = m_config.InventoryUrl.ToString(); + serversinfo.UserURL = m_config.AuthUrl.ToString(); + SetServersInfo(serversinfo); + } + + public void RegisterHandlers(BaseHttpServer httpServer) + { + m_httpServer = httpServer; + + httpServer.AddXmlRPCHandler("hg_login", XmlRpcLoginMethod); + httpServer.AddXmlRPCHandler("hg_new_auth_key", XmlRpcGenerateKeyMethod); + httpServer.AddXmlRPCHandler("hg_verify_auth_key", XmlRpcVerifyKeyMethod); + } + + + public override void LogOffUser(UserProfileData theUser, string message) + { + RegionProfileData SimInfo; + try + { + SimInfo = m_regionProfileService.RequestSimProfileData( + theUser.CurrentAgent.Handle, m_config.GridServerURL, + m_config.GridSendKey, m_config.GridRecvKey); + + if (SimInfo == null) + { + m_log.Error("[GRID]: Region user was in isn't currently logged in"); + return; + } + } + catch (Exception) + { + m_log.Error("[GRID]: Unable to look up region to log user off"); + return; + } + + // Prepare notification + Hashtable SimParams = new Hashtable(); + SimParams["agent_id"] = theUser.ID.ToString(); + SimParams["region_secret"] = theUser.CurrentAgent.SecureSessionID.ToString(); + SimParams["region_secret2"] = SimInfo.regionSecret; + //m_log.Info(SimInfo.regionSecret); + SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); + SimParams["message"] = message; + ArrayList SendParams = new ArrayList(); + SendParams.Add(SimParams); + + m_log.InfoFormat( + "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", + SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, + theUser.FirstName + " " + theUser.SurName); + + try + { + XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); + XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + + if (GridResp.IsFault) + { + m_log.ErrorFormat( + "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", + SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); + } + } + catch (Exception) + { + m_log.Error("[LOGIN]: Error telling region to logout user!"); + } + + // Prepare notification + SimParams = new Hashtable(); + SimParams["agent_id"] = theUser.ID.ToString(); + SimParams["region_secret"] = SimInfo.regionSecret; + //m_log.Info(SimInfo.regionSecret); + SimParams["regionhandle"] = theUser.CurrentAgent.Handle.ToString(); + SimParams["message"] = message; + SendParams = new ArrayList(); + SendParams.Add(SimParams); + + m_log.InfoFormat( + "[ASSUMED CRASH]: Telling region {0} @ {1},{2} ({3}) that their agent is dead: {4}", + SimInfo.regionName, SimInfo.regionLocX, SimInfo.regionLocY, SimInfo.httpServerURI, + theUser.FirstName + " " + theUser.SurName); + + try + { + XmlRpcRequest GridReq = new XmlRpcRequest("logoff_user", SendParams); + XmlRpcResponse GridResp = GridReq.Send(SimInfo.httpServerURI, 6000); + + if (GridResp.IsFault) + { + m_log.ErrorFormat( + "[LOGIN]: XMLRPC request for {0} failed, fault code: {1}, reason: {2}, This is likely an old region revision.", + SimInfo.httpServerURI, GridResp.FaultCode, GridResp.FaultString); + } + } + catch (Exception) + { + m_log.Error("[LOGIN]: Error telling region to logout user!"); + } + //base.LogOffUser(theUser); + } + + protected override RegionInfo RequestClosestRegion(string region) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(region, + m_config.GridServerURL, m_config.GridSendKey, m_config.GridRecvKey); + + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + protected override RegionInfo GetRegionInfo(ulong homeRegionHandle) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionHandle, + m_config.GridServerURL, m_config.GridSendKey, + m_config.GridRecvKey); + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + protected override RegionInfo GetRegionInfo(UUID homeRegionId) + { + RegionProfileData profileData = m_regionProfileService.RequestSimProfileData(homeRegionId, + m_config.GridServerURL, m_config.GridSendKey, + m_config.GridRecvKey); + if (profileData != null) + { + return profileData.ToRegionInfo(); + } + else + { + return null; + } + } + + } +} diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs index 56eb508..a521ead 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs @@ -184,7 +184,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage bool success = SynchronousRestObjectPoster.BeginPostObject( "POST", m_RestURL+"/SaveMessage/", im); - if(im.dialog == (byte)InstantMessageDialog.MessageFromAgent) + if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) { IClientAPI client = FindClient(new UUID(im.fromAgentID)); if (client == null) diff --git a/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneInventoryModule.cs b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneInventoryModule.cs index 525dda7..a1306cd 100644 --- a/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneInventoryModule.cs +++ b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneInventoryModule.cs @@ -1,165 +1,165 @@ -/** - * Copyright (c) 2008, Contributors. All rights reserved. - * 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 Organizations nor the names of Individual - * Contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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 Nini.Config; -using OpenMetaverse; -using OpenSim.Data; -using OpenSim.Framework; -using OpenSim.Framework.Communications; -using OpenSim.Framework.Communications.Cache; -using OpenSim.Framework.Communications.Services; -using Caps = OpenSim.Framework.Communications.Capabilities.Caps; -using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers; -using OpenSim.Framework.Servers; -using OpenSim.Framework.Servers.Interfaces; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Region.CoreModules.Communications.REST; - -using OpenMetaverse.StructuredData; - -namespace OpenSim.Region.CoreModules.Hypergrid -{ - public class HGStandaloneInventoryModule : IRegionModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static bool initialized = false; - private static bool enabled = false; - - private bool m_doLookup = false; - Scene m_scene; - HGInventoryService m_inventoryService; - InventoryServiceBase m_inventoryBase; - - public bool DoLookup - { - get { return m_doLookup; } - set { m_doLookup = value; } - } - - #region IRegionModule interface - - public void Initialise(Scene scene, IConfigSource config) - { - if (!initialized) - { - initialized = true; - m_scene = scene; - - // This module is only on for standalones - enabled = !config.Configs["Startup"].GetBoolean("gridmode", true) && config.Configs["Startup"].GetBoolean("hypergrid", false); - } - } - - public void PostInitialise() - { - if (enabled) - { - m_log.Info("[HGStandaloneInvModule]: Starting..."); - //m_inventoryService = new InventoryService(m_scene); - m_inventoryBase = (InventoryServiceBase)m_scene.CommsManager.SecureInventoryService; - - m_inventoryService = new HGInventoryService(m_inventoryBase, - ((AssetServerBase)m_scene.CommsManager.AssetCache.AssetServer).AssetProviderPlugin, - (UserManagerBase)m_scene.CommsManager.UserService, m_scene.CommsManager.HttpServer, - m_scene.CommsManager.NetworkServersInfo.InventoryURL); - - AddHttpHandlers(m_scene.CommsManager.HttpServer); - m_inventoryService.AddHttpHandlers(); - } - } - - public void Close() - { - } - - public string Name - { - get { return "HGStandaloneInventoryModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } - - #endregion - - public virtual void AddHttpHandlers(IHttpServer httpServer) - { - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/GetInventory/", m_inventoryService.GetUserInventory, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/NewFolder/", m_inventoryBase.AddFolder, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/UpdateFolder/", m_inventoryBase.UpdateFolder, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/MoveFolder/", m_inventoryBase.MoveFolder, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/PurgeFolder/", m_inventoryBase.PurgeFolder, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/NewItem/", m_inventoryBase.AddItem, CheckAuthSession)); - - httpServer.AddStreamHandler( - new RestDeserialiseSecureHandler( - "POST", "/DeleteItem/", m_inventoryBase.DeleteItem, CheckAuthSession)); - - } - - /// - /// Check that the source of an inventory request for a particular agent is a current session belonging to - /// that agent. - /// - /// - /// - /// - public bool CheckAuthSession(string session_id, string avatar_id) - { - return true; - } - - } - -} +/** + * Copyright (c) 2008, Contributors. All rights reserved. + * 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 Organizations nor the names of Individual + * Contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT OWNER OR 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 Nini.Config; +using OpenMetaverse; +using OpenSim.Data; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using OpenSim.Framework.Communications.Cache; +using OpenSim.Framework.Communications.Services; +using Caps = OpenSim.Framework.Communications.Capabilities.Caps; +using LLSDHelpers = OpenSim.Framework.Communications.Capabilities.LLSDHelpers; +using OpenSim.Framework.Servers; +using OpenSim.Framework.Servers.Interfaces; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.CoreModules.Communications.REST; + +using OpenMetaverse.StructuredData; + +namespace OpenSim.Region.CoreModules.Hypergrid +{ + public class HGStandaloneInventoryModule : IRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static bool initialized = false; + private static bool enabled = false; + + private bool m_doLookup = false; + Scene m_scene; + HGInventoryService m_inventoryService; + InventoryServiceBase m_inventoryBase; + + public bool DoLookup + { + get { return m_doLookup; } + set { m_doLookup = value; } + } + + #region IRegionModule interface + + public void Initialise(Scene scene, IConfigSource config) + { + if (!initialized) + { + initialized = true; + m_scene = scene; + + // This module is only on for standalones + enabled = !config.Configs["Startup"].GetBoolean("gridmode", true) && config.Configs["Startup"].GetBoolean("hypergrid", false); + } + } + + public void PostInitialise() + { + if (enabled) + { + m_log.Info("[HGStandaloneInvModule]: Starting..."); + //m_inventoryService = new InventoryService(m_scene); + m_inventoryBase = (InventoryServiceBase)m_scene.CommsManager.SecureInventoryService; + + m_inventoryService = new HGInventoryService(m_inventoryBase, + ((AssetServerBase)m_scene.CommsManager.AssetCache.AssetServer).AssetProviderPlugin, + (UserManagerBase)m_scene.CommsManager.UserService, m_scene.CommsManager.HttpServer, + m_scene.CommsManager.NetworkServersInfo.InventoryURL); + + AddHttpHandlers(m_scene.CommsManager.HttpServer); + m_inventoryService.AddHttpHandlers(); + } + } + + public void Close() + { + } + + public string Name + { + get { return "HGStandaloneInventoryModule"; } + } + + public bool IsSharedModule + { + get { return true; } + } + + #endregion + + public virtual void AddHttpHandlers(IHttpServer httpServer) + { + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/GetInventory/", m_inventoryService.GetUserInventory, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/NewFolder/", m_inventoryBase.AddFolder, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/UpdateFolder/", m_inventoryBase.UpdateFolder, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/MoveFolder/", m_inventoryBase.MoveFolder, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/PurgeFolder/", m_inventoryBase.PurgeFolder, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/NewItem/", m_inventoryBase.AddItem, CheckAuthSession)); + + httpServer.AddStreamHandler( + new RestDeserialiseSecureHandler( + "POST", "/DeleteItem/", m_inventoryBase.DeleteItem, CheckAuthSession)); + + } + + /// + /// Check that the source of an inventory request for a particular agent is a current session belonging to + /// that agent. + /// + /// + /// + /// + public bool CheckAuthSession(string session_id, string avatar_id) + { + return true; + } + + } + +} diff --git a/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs index 9e134be..f0e957b 100644 --- a/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs +++ b/OpenSim/Region/CoreModules/Hypergrid/HGStandaloneLoginModule.cs @@ -1,253 +1,253 @@ -/* - * 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 OpenSimulator 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.Net; -using System.Reflection; -using System.Text.RegularExpressions; -using log4net; -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.Interfaces; -using OpenSim.Region.Framework.Scenes; -using OpenSim.Region.Framework.Interfaces; - -namespace OpenSim.Region.CoreModules.Hypergrid -{ - public class HGStandaloneLoginModule : IRegionModule, ILoginServiceToRegionsConnector - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - protected List m_scenes = new List(); - protected Scene m_firstScene; - - protected bool m_enabled = false; // Module is only enabled if running in standalone mode - - - public bool RegionLoginsEnabled - { - get - { - if (m_firstScene != null) - { - return m_firstScene.CommsManager.GridService.RegionLoginsEnabled; - } - else - { - return false; - } - } - } - - protected HGLoginAuthService m_loginService; - - #region IRegionModule Members - - public void Initialise(Scene scene, IConfigSource source) - { - if (m_firstScene == null) - { - m_firstScene = scene; - - IConfig startupConfig = source.Configs["Startup"]; - if (startupConfig != null) - { - m_enabled = !startupConfig.GetBoolean("gridmode", false); - } - - if (m_enabled) - { - m_log.Debug("[HGLogin] HGlogin module enabled"); - bool authenticate = true; - string welcomeMessage = "Welcome to OpenSim"; - IConfig standaloneConfig = source.Configs["StandAlone"]; - if (standaloneConfig != null) - { - authenticate = standaloneConfig.GetBoolean("accounts_authenticate", true); - welcomeMessage = standaloneConfig.GetString("welcome_message"); - } - - //TODO: fix casting. - LibraryRootFolder rootFolder = m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder; - - IHttpServer httpServer = m_firstScene.CommsManager.HttpServer; - - //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference - m_loginService = new HGLoginAuthService((UserManagerBase)m_firstScene.CommsManager.UserService, welcomeMessage, m_firstScene.CommsManager.InterServiceInventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate, rootFolder, this); - - httpServer.AddXmlRPCHandler("hg_login", m_loginService.XmlRpcLoginMethod); - httpServer.AddXmlRPCHandler("hg_new_auth_key", m_loginService.XmlRpcGenerateKeyMethod); - httpServer.AddXmlRPCHandler("hg_verify_auth_key", m_loginService.XmlRpcVerifyKeyMethod); - - } - } - - if (m_enabled) - { - AddScene(scene); - } - } - - public void PostInitialise() - { - - } - - public void Close() - { - - } - - public string Name - { - get { return "HGStandaloneLoginModule"; } - } - - public bool IsSharedModule - { - get { return true; } - } - - #endregion - - protected void AddScene(Scene scene) - { - lock (m_scenes) - { - if (!m_scenes.Contains(scene)) - { - m_scenes.Add(scene); - } - } - } - - public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent) - { - return true; - } - - public void LogOffUserFromGrid(ulong regionHandle, UUID AvatarID, UUID RegionSecret, string message) - { - Scene scene; - if (TryGetRegion(regionHandle, out scene)) - { - scene.HandleLogOffUserFromGrid(AvatarID, RegionSecret, message); - } - } - - public RegionInfo RequestNeighbourInfo(ulong regionhandle) - { - Scene scene; - if (TryGetRegion(regionhandle, out scene)) - { - return scene.RegionInfo; - } - return null; - } - - public RegionInfo RequestClosestRegion(string region) - { - Scene scene; - if (TryGetRegion(region, out scene)) - { - return scene.RegionInfo; - } - return null; - } - - public RegionInfo RequestNeighbourInfo(UUID regionID) - { - Scene scene; - if (TryGetRegion(regionID, out scene)) - { - return scene.RegionInfo; - } - return null; - } - - protected bool TryGetRegion(ulong regionHandle, out Scene scene) - { - lock (m_scenes) - { - foreach (Scene nextScene in m_scenes) - { - if (nextScene.RegionInfo.RegionHandle == regionHandle) - { - scene = nextScene; - return true; - } - } - } - - scene = null; - return false; - } - - protected bool TryGetRegion(UUID regionID, out Scene scene) - { - lock (m_scenes) - { - foreach (Scene nextScene in m_scenes) - { - if (nextScene.RegionInfo.RegionID == regionID) - { - scene = nextScene; - return true; - } - } - } - - scene = null; - return false; - } - - protected bool TryGetRegion(string regionName, out Scene scene) - { - lock (m_scenes) - { - foreach (Scene nextScene in m_scenes) - { - if (nextScene.RegionInfo.RegionName == regionName) - { - scene = nextScene; - return true; - } - } - } - - scene = null; - return false; - } - } -} +/* + * 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 OpenSimulator 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.Net; +using System.Reflection; +using System.Text.RegularExpressions; +using log4net; +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.Interfaces; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.Framework.Interfaces; + +namespace OpenSim.Region.CoreModules.Hypergrid +{ + public class HGStandaloneLoginModule : IRegionModule, ILoginServiceToRegionsConnector + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + protected List m_scenes = new List(); + protected Scene m_firstScene; + + protected bool m_enabled = false; // Module is only enabled if running in standalone mode + + + public bool RegionLoginsEnabled + { + get + { + if (m_firstScene != null) + { + return m_firstScene.CommsManager.GridService.RegionLoginsEnabled; + } + else + { + return false; + } + } + } + + protected HGLoginAuthService m_loginService; + + #region IRegionModule Members + + public void Initialise(Scene scene, IConfigSource source) + { + if (m_firstScene == null) + { + m_firstScene = scene; + + IConfig startupConfig = source.Configs["Startup"]; + if (startupConfig != null) + { + m_enabled = !startupConfig.GetBoolean("gridmode", false); + } + + if (m_enabled) + { + m_log.Debug("[HGLogin] HGlogin module enabled"); + bool authenticate = true; + string welcomeMessage = "Welcome to OpenSim"; + IConfig standaloneConfig = source.Configs["StandAlone"]; + if (standaloneConfig != null) + { + authenticate = standaloneConfig.GetBoolean("accounts_authenticate", true); + welcomeMessage = standaloneConfig.GetString("welcome_message"); + } + + //TODO: fix casting. + LibraryRootFolder rootFolder = m_firstScene.CommsManager.UserProfileCacheService.LibraryRoot as LibraryRootFolder; + + IHttpServer httpServer = m_firstScene.CommsManager.HttpServer; + + //TODO: fix the casting of the user service, maybe by registering the userManagerBase with scenes, or refactoring so we just need a IUserService reference + m_loginService = new HGLoginAuthService((UserManagerBase)m_firstScene.CommsManager.UserService, welcomeMessage, m_firstScene.CommsManager.InterServiceInventoryService, m_firstScene.CommsManager.NetworkServersInfo, authenticate, rootFolder, this); + + httpServer.AddXmlRPCHandler("hg_login", m_loginService.XmlRpcLoginMethod); + httpServer.AddXmlRPCHandler("hg_new_auth_key", m_loginService.XmlRpcGenerateKeyMethod); + httpServer.AddXmlRPCHandler("hg_verify_auth_key", m_loginService.XmlRpcVerifyKeyMethod); + + } + } + + if (m_enabled) + { + AddScene(scene); + } + } + + public void PostInitialise() + { + + } + + public void Close() + { + + } + + public string Name + { + get { return "HGStandaloneLoginModule"; } + } + + public bool IsSharedModule + { + get { return true; } + } + + #endregion + + protected void AddScene(Scene scene) + { + lock (m_scenes) + { + if (!m_scenes.Contains(scene)) + { + m_scenes.Add(scene); + } + } + } + + public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent) + { + return true; + } + + public void LogOffUserFromGrid(ulong regionHandle, UUID AvatarID, UUID RegionSecret, string message) + { + Scene scene; + if (TryGetRegion(regionHandle, out scene)) + { + scene.HandleLogOffUserFromGrid(AvatarID, RegionSecret, message); + } + } + + public RegionInfo RequestNeighbourInfo(ulong regionhandle) + { + Scene scene; + if (TryGetRegion(regionhandle, out scene)) + { + return scene.RegionInfo; + } + return null; + } + + public RegionInfo RequestClosestRegion(string region) + { + Scene scene; + if (TryGetRegion(region, out scene)) + { + return scene.RegionInfo; + } + return null; + } + + public RegionInfo RequestNeighbourInfo(UUID regionID) + { + Scene scene; + if (TryGetRegion(regionID, out scene)) + { + return scene.RegionInfo; + } + return null; + } + + protected bool TryGetRegion(ulong regionHandle, out Scene scene) + { + lock (m_scenes) + { + foreach (Scene nextScene in m_scenes) + { + if (nextScene.RegionInfo.RegionHandle == regionHandle) + { + scene = nextScene; + return true; + } + } + } + + scene = null; + return false; + } + + protected bool TryGetRegion(UUID regionID, out Scene scene) + { + lock (m_scenes) + { + foreach (Scene nextScene in m_scenes) + { + if (nextScene.RegionInfo.RegionID == regionID) + { + scene = nextScene; + return true; + } + } + } + + scene = null; + return false; + } + + protected bool TryGetRegion(string regionName, out Scene scene) + { + lock (m_scenes) + { + foreach (Scene nextScene in m_scenes) + { + if (nextScene.RegionInfo.RegionName == regionName) + { + scene = nextScene; + return true; + } + } + } + + scene = null; + return false; + } + } +} diff --git a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs index dedd37f..f9059e0 100644 --- a/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs +++ b/OpenSim/Region/CoreModules/Scripting/DynamicTexture/DynamicTextureModule.cs @@ -66,18 +66,17 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture /// public void ReturnData(UUID id, byte[] data) { + DynamicTextureUpdater updater = null; - DynamicTextureUpdater updater = null; - - lock(Updaters) + lock (Updaters) { - if (Updaters.ContainsKey(id)) - { - updater = Updaters[id]; + if (Updaters.ContainsKey(id)) + { + updater = Updaters[id]; } } - if(updater != null) + if (updater != null) { if (RegisteredScenes.ContainsKey(updater.SimUUID)) { @@ -86,27 +85,26 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } } - if(updater.UpdateTimer == 0) - { - lock(Updaters) - { - if (!Updaters.ContainsKey(updater.UpdaterID)) - { - Updaters.Remove(updater.UpdaterID); - } - } - } - + if (updater.UpdateTimer == 0) + { + lock (Updaters) + { + if (!Updaters.ContainsKey(updater.UpdaterID)) + { + Updaters.Remove(updater.UpdaterID); + } + } + } } public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, - string extraParams, int updateTimer) + string extraParams, int updateTimer) { return AddDynamicTextureURL(simID, primID, contentType, url, extraParams, updateTimer, false, 255); } public UUID AddDynamicTextureURL(UUID simID, UUID primID, string contentType, string url, - string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) + string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) { if (RenderPlugins.ContainsKey(contentType)) { @@ -123,12 +121,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture updater.BlendWithOldTexture = SetBlending; updater.FrontAlpha = AlphaValue; - lock(Updaters) + lock (Updaters) { - if (!Updaters.ContainsKey(updater.UpdaterID)) - { - Updaters.Add(updater.UpdaterID, updater); - } + if (!Updaters.ContainsKey(updater.UpdaterID)) + { + Updaters.Add(updater.UpdaterID, updater); + } } RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams); @@ -138,13 +136,13 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture } public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, - string extraParams, int updateTimer) + string extraParams, int updateTimer) { return AddDynamicTextureData(simID, primID, contentType, data, extraParams, updateTimer, false, 255); } public UUID AddDynamicTextureData(UUID simID, UUID primID, string contentType, string data, - string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) + string extraParams, int updateTimer, bool SetBlending, byte AlphaValue) { if (RenderPlugins.ContainsKey(contentType)) { @@ -159,12 +157,12 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture updater.BlendWithOldTexture = SetBlending; updater.FrontAlpha = AlphaValue; - lock(Updaters) + lock (Updaters) { - if (!Updaters.ContainsKey(updater.UpdaterID)) - { - Updaters.Add(updater.UpdaterID, updater); - } + if (!Updaters.ContainsKey(updater.UpdaterID)) + { + Updaters.Add(updater.UpdaterID, updater); + } } RenderPlugins[contentType].AsyncConvertData(updater.UpdaterID, data, extraParams); @@ -173,7 +171,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture return UUID.Zero; } - public void GetDrawStringSize(string contentType, string text, string fontName, int fontSize, out double xSize, out double ySize) { @@ -307,7 +304,6 @@ namespace OpenSim.Region.CoreModules.Scripting.DynamicTexture part.ScheduleFullUpdate(); scene.CommsManager.AssetCache.ExpireAsset(oldID); - } private byte[] BlendTextures(byte[] frontImage, byte[] backImage, bool setNewAlpha, byte newAlpha) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 3c1b87f..e32f1b4 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4998,29 +4998,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (dir.x == 0) { - if (dir.y == 0) - { - // Direction vector is 0,0 so return - // false since we're staying in the sim - return 0; - } - else - { - // Y is the only valid direction - edge.y = dir.y / Math.Abs(dir.y); - } + if (dir.y == 0) + { + // Direction vector is 0,0 so return + // false since we're staying in the sim + return 0; + } + else + { + // Y is the only valid direction + edge.y = dir.y / Math.Abs(dir.y); + } } else { LSL_Float mag; - if (dir.x > 0) - { + if (dir.x > 0) + { mag = (Constants.RegionSize - pos.x) / dir.x; - } - else - { + } + else + { mag = (pos.x/dir.x); - } + } mag = Math.Abs(mag); @@ -5028,7 +5028,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (edge.y > Constants.RegionSize || edge.y < 0) { - // Y goes out of bounds first + // Y goes out of bounds first edge.y = dir.y / Math.Abs(dir.y); } else @@ -5039,18 +5039,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - List neighbors = World.CommsManager.GridService.RequestNeighbours(World.RegionInfo.RegionLocX, World.RegionInfo.RegionLocY); + List neighbors = World.CommsManager.GridService.RequestNeighbours(World.RegionInfo.RegionLocX, World.RegionInfo.RegionLocY); - uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x; - uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y; - - foreach (SimpleRegionInfo sri in neighbors) - { - if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY) - return 0; - } + uint neighborX = World.RegionInfo.RegionLocX + (uint)dir.x; + uint neighborY = World.RegionInfo.RegionLocY + (uint)dir.y; + + foreach (SimpleRegionInfo sri in neighbors) + { + if (sri.RegionLocX == neighborX && sri.RegionLocY == neighborY) + return 0; + } - return 1; + return 1; } /// diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs index 09351fd..5353fc9 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs @@ -49,7 +49,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { return localID.ToString() + itemID.ToString(); } - private class TimerClass { -- cgit v1.1