From 320fbcb7b4179968994100d0819da2e0732451ef Mon Sep 17 00:00:00 2001 From: MW Date: Tue, 19 Jun 2007 10:40:20 +0000 Subject: Made a base class from the Grid mode UserServer.UserManager and included that in the OpenSim solution. Included OpenGrid.Framework.Data in the OpenSim solution (and OpenGrid.Framework.Data.DB4O). Changed OpenSim.LocalCommunications.LocalUserServices so that it inherits from the UserManagement Base class. (still not finished implementing the CustomiseResponse() method) --- .../OpenGridServices.UserServer.csproj | 6 +- .../OpenGridServices.UserServer.exe.build | 1 + .../OpenGridServices.UserServer/UserManager.cs | 668 +-------------------- 3 files changed, 11 insertions(+), 664 deletions(-) (limited to 'OpenGridServices/OpenGridServices.UserServer') diff --git a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj index b3d318c..ad0080a 100644 --- a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj +++ b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.csproj @@ -66,6 +66,10 @@ ..\..\bin\libsecondlife.dll False + + OpenGrid.Framework.UserManager.dll + False + OpenSim.Framework.dll False @@ -100,7 +104,7 @@ - + OpenGrid.Framework.Data {62CDF671-0000-0000-0000-000000000000} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} diff --git a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build index 68cbef7..a24003f 100644 --- a/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build +++ b/OpenGridServices/OpenGridServices.UserServer/OpenGridServices.UserServer.exe.build @@ -23,6 +23,7 @@ + diff --git a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs index f512b15..6f5f054 100644 --- a/OpenGridServices/OpenGridServices.UserServer/UserManager.cs +++ b/OpenGridServices/OpenGridServices.UserServer/UserManager.cs @@ -38,284 +38,16 @@ using Nwc.XmlRpc; using OpenSim.Framework.Sims; using OpenSim.Framework.Inventory; using OpenSim.Framework.Utilities; +using OpenGrid.Framework.UserManagement; using System.Security.Cryptography; namespace OpenGridServices.UserServer { - public class UserManager + public class UserManager : UserManagerBase { - public OpenSim.Framework.Interfaces.UserConfig _config; - Dictionary _plugins = new Dictionary(); - - /// - /// Adds a new user server plugin - user servers will be requested in the order they were loaded. - /// - /// The filename to the user server plugin DLL - public void AddPlugin(string FileName) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Userstorage: Attempting to load " + FileName); - Assembly pluginAssembly = Assembly.LoadFrom(FileName); - - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Userstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); - foreach (Type pluginType in pluginAssembly.GetTypes()) - { - if (!pluginType.IsAbstract) - { - Type typeInterface = pluginType.GetInterface("IUserData", true); - - if (typeInterface != null) - { - IUserData plug = (IUserData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); - plug.Initialise(); - this._plugins.Add(plug.getName(), plug); - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Userstorage: Added IUserData Interface"); - } - - typeInterface = null; - } - } - - pluginAssembly = null; - } - - /// - /// - /// - /// - public void AddUserProfile(string firstName, string lastName, string pass, uint regX, uint regY) - { - UserProfileData user = new UserProfileData(); - user.homeLocation = new LLVector3(128, 128, 100); - user.UUID = LLUUID.Random(); - user.username = firstName; - user.surname = lastName; - user.passwordHash = pass; - user.passwordSalt = ""; - user.created = Util.UnixTimeSinceEpoch(); - user.homeLookAt = new LLVector3(100, 100, 100); - user.homeRegion = Util.UIntsToLong((regX * 256), (regY * 256)); - - foreach (KeyValuePair plugin in _plugins) - { - try - { - plugin.Value.addNewUserProfile(user); - - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - } - - /// - /// Loads a user profile from a database by UUID - /// - /// The target UUID - /// A user profile - public UserProfileData getUserProfile(LLUUID uuid) - { - foreach (KeyValuePair plugin in _plugins) - { - try - { - UserProfileData profile = plugin.Value.getUserByUUID(uuid); - profile.currentAgent = getUserAgent(profile.UUID); - return profile; - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - - /// - /// Loads a user profile by name - /// - /// The target name - /// A user profile - public UserProfileData getUserProfile(string name) - { - foreach (KeyValuePair plugin in _plugins) - { - try - { - UserProfileData profile = plugin.Value.getUserByName(name); - profile.currentAgent = getUserAgent(profile.UUID); - return profile; - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - /// - /// Loads a user profile by name - /// - /// First name - /// Last name - /// A user profile - public UserProfileData getUserProfile(string fname, string lname) - { - foreach (KeyValuePair plugin in _plugins) - { - try - { - UserProfileData profile = plugin.Value.getUserByName(fname,lname); - try - { - profile.currentAgent = getUserAgent(profile.UUID); - } - catch (Exception e) - { - // Ignore - } - return profile; - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - /// - /// Loads a user agent by uuid (not called directly) - /// - /// The agents UUID - /// Agent profiles - public UserAgentData getUserAgent(LLUUID uuid) - { - foreach (KeyValuePair plugin in _plugins) - { - try - { - return plugin.Value.getAgentByUUID(uuid); - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - /// - /// Loads a user agent by name (not called directly) - /// - /// The agents name - /// A user agent - public UserAgentData getUserAgent(string name) + public UserManager() { - foreach (KeyValuePair plugin in _plugins) - { - try - { - return plugin.Value.getAgentByName(name); - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - /// - /// Loads a user agent by name (not called directly) - /// - /// The agents firstname - /// The agents lastname - /// A user agent - public UserAgentData getUserAgent(string fname, string lname) - { - foreach (KeyValuePair plugin in _plugins) - { - try - { - return plugin.Value.getAgentByName(fname,lname); - } - catch (Exception e) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); - } - } - - return null; - } - - /// - /// Creates a error response caused by invalid XML - /// - /// An XMLRPC response - private static XmlRpcResponse CreateErrorConnectingToGridResponse() - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable ErrorRespData = new Hashtable(); - ErrorRespData["reason"] = "key"; - ErrorRespData["message"] = "Error connecting to grid. Could not percieve credentials from login XML."; - ErrorRespData["login"] = "false"; - response.Value = ErrorRespData; - return response; - } - - /// - /// Creates an error response caused by bad login credentials - /// - /// An XMLRPC response - private static XmlRpcResponse CreateLoginErrorResponse() - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable ErrorRespData = new Hashtable(); - ErrorRespData["reason"] = "key"; - ErrorRespData["message"] = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist."; - ErrorRespData["login"] = "false"; - response.Value = ErrorRespData; - return response; - } - - /// - /// Creates an error response caused by being logged in already - /// - /// An XMLRPC Response - private static XmlRpcResponse CreateAlreadyLoggedInResponse() - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable PresenceErrorRespData = new Hashtable(); - PresenceErrorRespData["reason"] = "presence"; - PresenceErrorRespData["message"] = "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"; - PresenceErrorRespData["login"] = "false"; - response.Value = PresenceErrorRespData; - return response; - } - - /// - /// Creates an error response caused by target region being down - /// - /// An XMLRPC Response - private static XmlRpcResponse CreateDeadRegionResponse() - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable PresenceErrorRespData = new Hashtable(); - PresenceErrorRespData["reason"] = "key"; - PresenceErrorRespData["message"] = "The region you are attempting to log into is not responding. Please select another region and try again."; - PresenceErrorRespData["login"] = "false"; - response.Value = PresenceErrorRespData; - return response; } /// @@ -323,7 +55,7 @@ namespace OpenGridServices.UserServer /// /// The existing response /// The user profile - public virtual void CustomiseResponse(ref Hashtable response, ref UserProfileData theUser) + public override void CustomiseResponse(ref Hashtable response, ref UserProfileData theUser) { // Load information from the gridserver SimProfile SimInfo = new SimProfile(); @@ -331,7 +63,7 @@ namespace OpenGridServices.UserServer // Customise the response // Home Location - response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 256).ToString() + "], " + + response["home"] = "{'region_handle':[r" + (SimInfo.RegionLocX * 256).ToString() + ",r" + (SimInfo.RegionLocY * 256).ToString() + "], " + "'position':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "], " + "'look_at':[r" + theUser.homeLocation.X.ToString() + ",r" + theUser.homeLocation.Y.ToString() + ",r" + theUser.homeLocation.Z.ToString() + "]}"; @@ -366,395 +98,5 @@ namespace OpenGridServices.UserServer XmlRpcRequest GridReq = new XmlRpcRequest("expect_user", SendParams); XmlRpcResponse GridResp = GridReq.Send(SimInfo.caps_url, 3000); } - - /// - /// Checks a user against it's password hash - /// - /// The users profile - /// The supplied password - /// Authenticated? - public bool AuthenticateUser(ref UserProfileData profile, string password) - { - OpenSim.Framework.Console.MainConsole.Instance.Verbose( - "Authenticating " + profile.username + " " + profile.surname); - - password = password.Remove(0, 3); //remove $1$ - - string s = Util.Md5Hash(password + ":" + profile.passwordSalt); - - return profile.passwordHash.Equals(s.ToString(), StringComparison.InvariantCultureIgnoreCase); - } - - /// - /// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB - /// - /// The users profile - /// The users loginrequest - public void CreateAgent(ref UserProfileData profile, XmlRpcRequest request) - { - Hashtable requestData = (Hashtable)request.Params[0]; - - UserAgentData agent = new UserAgentData(); - - // User connection - agent.agentIP = ""; - agent.agentOnline = true; - agent.agentPort = 0; - - // Generate sessions - RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider(); - byte[] randDataS = new byte[16]; - byte[] randDataSS = new byte[16]; - rand.GetBytes(randDataS); - rand.GetBytes(randDataSS); - - agent.secureSessionID = new LLUUID(randDataSS, 0); - agent.sessionID = new LLUUID(randDataS, 0); - - // Profile UUID - agent.UUID = profile.UUID; - - // Current position (from Home) - agent.currentHandle = profile.homeRegion; - agent.currentPos = profile.homeLocation; - - // If user specified additional start, use that - if (requestData.ContainsKey("start")) - { - string startLoc = ((string)requestData["start"]).Trim(); - if (!(startLoc == "last" || startLoc == "home")) - { - // Format: uri:Ahern&162&213&34 - try - { - string[] parts = startLoc.Remove(0, 4).Split('&'); - string region = parts[0]; - - //////////////////////////////////////////////////// - //SimProfile SimInfo = new SimProfile(); - //SimInfo = SimInfo.LoadFromGrid(theUser.currentAgent.currentHandle, _config.GridServerURL, _config.GridSendKey, _config.GridRecvKey); - } - catch (Exception e) - { - - } - } - } - - // What time did the user login? - agent.loginTime = Util.UnixTimeSinceEpoch(); - agent.logoutTime = 0; - - // Current location - agent.regionID = new LLUUID(); // Fill in later - agent.currentRegion = new LLUUID(); // Fill in later - - profile.currentAgent = agent; - } - - /// - /// Saves a target agent to the database - /// - /// The users profile - /// Successful? - public bool CommitAgent(ref UserProfileData profile) - { - // Saves the agent to database - return true; - } - - /// - /// Main user login function - /// - /// The XMLRPC request - /// The response to send - public XmlRpcResponse XmlRpcLoginMethod(XmlRpcRequest request) - { - XmlRpcResponse response = new XmlRpcResponse(); - Hashtable requestData = (Hashtable)request.Params[0]; - - bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && requestData.Contains("passwd")); - bool GoodLogin = false; - string firstname = ""; - string lastname = ""; - string passwd = ""; - - UserProfileData TheUser; - - if (GoodXML) - { - firstname = (string)requestData["first"]; - lastname = (string)requestData["last"]; - passwd = (string)requestData["passwd"]; - - TheUser = getUserProfile(firstname, lastname); - if (TheUser == null) - return CreateLoginErrorResponse(); - - GoodLogin = AuthenticateUser(ref TheUser, passwd); - } - else - { - return CreateErrorConnectingToGridResponse(); - } - - if (!GoodLogin) - { - return CreateLoginErrorResponse(); - } - else - { - // If we already have a session... - if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline) - { - // Reject the login - return CreateAlreadyLoggedInResponse(); - } - // Otherwise... - // Create a new agent session - CreateAgent(ref TheUser, request); - - try - { - Hashtable responseData = new Hashtable(); - - LLUUID AgentID = TheUser.UUID; - - // Global Texture Section - Hashtable GlobalT = new Hashtable(); - GlobalT["sun_texture_id"] = "cce0f112-878f-4586-a2e2-a8f104bba271"; - GlobalT["cloud_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; - GlobalT["moon_texture_id"] = "fc4b9f0b-d008-45c6-96a4-01dd947ac621"; - ArrayList GlobalTextures = new ArrayList(); - GlobalTextures.Add(GlobalT); - - // Login Flags Section - Hashtable LoginFlagsHash = new Hashtable(); - LoginFlagsHash["daylight_savings"] = "N"; - LoginFlagsHash["stipend_since_login"] = "N"; - LoginFlagsHash["gendered"] = "Y"; // Needs to be combined with below... - LoginFlagsHash["ever_logged_in"] = "Y"; // Should allow male/female av selection - ArrayList LoginFlags = new ArrayList(); - LoginFlags.Add(LoginFlagsHash); - - // UI Customisation Section - Hashtable uiconfig = new Hashtable(); - uiconfig["allow_first_life"] = "Y"; - ArrayList ui_config = new ArrayList(); - ui_config.Add(uiconfig); - - // Classified Categories Section - Hashtable ClassifiedCategoriesHash = new Hashtable(); - ClassifiedCategoriesHash["category_name"] = "Generic"; - ClassifiedCategoriesHash["category_id"] = (Int32)1; - ArrayList ClassifiedCategories = new ArrayList(); - ClassifiedCategories.Add(ClassifiedCategoriesHash); - - // Inventory Library Section - ArrayList AgentInventoryArray = new ArrayList(); - Hashtable TempHash; - - AgentInventory Library = new AgentInventory(); - Library.CreateRootFolder(AgentID, true); - - foreach (InventoryFolder InvFolder in Library.InventoryFolders.Values) - { - TempHash = new Hashtable(); - TempHash["name"] = InvFolder.FolderName; - TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); - TempHash["version"] = (Int32)InvFolder.Version; - TempHash["type_default"] = (Int32)InvFolder.DefaultType; - TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); - AgentInventoryArray.Add(TempHash); - } - - Hashtable InventoryRootHash = new Hashtable(); - InventoryRootHash["folder_id"] = Library.InventoryRoot.FolderID.ToStringHyphenated(); - ArrayList InventoryRoot = new ArrayList(); - InventoryRoot.Add(InventoryRootHash); - - Hashtable InitialOutfitHash = new Hashtable(); - InitialOutfitHash["folder_name"] = "Nightclub Female"; - InitialOutfitHash["gender"] = "female"; - ArrayList InitialOutfit = new ArrayList(); - InitialOutfit.Add(InitialOutfitHash); - - // Circuit Code - uint circode = (uint)(Util.RandomClass.Next()); - - // Generics - responseData["last_name"] = TheUser.surname; - responseData["ui-config"] = ui_config; - responseData["sim_ip"] = "127.0.0.1"; //SimInfo.sim_ip.ToString(); - responseData["login-flags"] = LoginFlags; - responseData["global-textures"] = GlobalTextures; - responseData["classified_categories"] = ClassifiedCategories; - responseData["event_categories"] = new ArrayList(); - responseData["inventory-skeleton"] = AgentInventoryArray; - responseData["inventory-skel-lib"] = new ArrayList(); - responseData["inventory-root"] = InventoryRoot; - responseData["event_notifications"] = new ArrayList(); - responseData["gestures"] = new ArrayList(); - responseData["inventory-lib-owner"] = new ArrayList(); - responseData["initial-outfit"] = InitialOutfit; - responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; - responseData["start_location"] = "last"; - responseData["home"] = "!!null temporary value {home}!!"; // Overwritten - responseData["message"] = _config.DefaultStartupMsg; - responseData["first_name"] = TheUser.username; - responseData["circuit_code"] = (Int32)circode; - responseData["sim_port"] = 0; //(Int32)SimInfo.sim_port; - responseData["secure_session_id"] = TheUser.currentAgent.secureSessionID.ToStringHyphenated(); - responseData["look_at"] = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n"; - responseData["agent_id"] = AgentID.ToStringHyphenated(); - responseData["region_y"] = (Int32)0; // Overwritten - responseData["region_x"] = (Int32)0; // Overwritten - responseData["seed_capability"] = ""; - responseData["agent_access"] = "M"; - responseData["session_id"] = TheUser.currentAgent.sessionID.ToStringHyphenated(); - responseData["login"] = "true"; - - try - { - this.CustomiseResponse(ref responseData, ref TheUser); - } - catch (Exception e) - { - Console.WriteLine(e.ToString()); - return CreateDeadRegionResponse(); - } - - CommitAgent(ref TheUser); - - response.Value = responseData; - // TheUser.SendDataToSim(SimInfo); - return response; - - } - catch (Exception E) - { - Console.WriteLine(E.ToString()); - } - //} - } - return response; - - } - - /// - /// Deletes an active agent session - /// - /// The request - /// The path (eg /bork/narf/test) - /// Parameters sent - /// Success "OK" else error - public string RestDeleteUserSessionMethod(string request, string path, string param) - { - // TODO! Important! - - return "OK"; - } - - /// - /// Returns an error message that the user could not be found in the database - /// - /// XML string consisting of a error element containing individual error(s) - public string CreateUnknownUserErrorResponse() - { - System.IO.StringWriter sw = new System.IO.StringWriter(); - XmlTextWriter xw = new XmlTextWriter(sw); - - // Header - xw.Formatting = Formatting.Indented; - xw.WriteStartDocument(); - xw.WriteDocType("error", null, null, null); - xw.WriteComment("An error occured"); - xw.WriteStartElement("error"); - - // User - xw.WriteElementString("unknownuser", "Unable to find a user with that name"); - - // Footer - xw.WriteEndElement(); - xw.Flush(); - xw.Close(); - - return sw.ToString(); - } - - /// - /// Converts a user profile to an XML element which can be returned - /// - /// The user profile - /// A string containing an XML Document of the user profile - public string ProfileToXml(UserProfileData profile) - { - System.IO.StringWriter sw = new System.IO.StringWriter(); - XmlTextWriter xw = new XmlTextWriter(sw); - - // Header - xw.Formatting = Formatting.Indented; - xw.WriteStartDocument(); - xw.WriteDocType("userprofile", null, null, null); - xw.WriteComment("Found user profiles matching the request"); - xw.WriteStartElement("users"); - - // User - xw.WriteStartElement("user"); - // Account information - xw.WriteAttributeString("firstname", profile.username); - xw.WriteAttributeString("lastname", profile.surname); - xw.WriteAttributeString("uuid", profile.UUID.ToStringHyphenated()); - // Server Information - xw.WriteAttributeString("server_inventory", profile.userInventoryURI); - xw.WriteAttributeString("server_asset", profile.userAssetURI); - // Profile Information - xw.WriteAttributeString("profile_about", profile.profileAboutText); - xw.WriteAttributeString("profile_firstlife_about", profile.profileFirstText); - xw.WriteAttributeString("profile_firstlife_image", profile.profileFirstImage.ToStringHyphenated()); - xw.WriteAttributeString("profile_can_do", profile.profileCanDoMask.ToString()); - xw.WriteAttributeString("profile_want_do", profile.profileWantDoMask.ToString()); - xw.WriteAttributeString("profile_image", profile.profileImage.ToStringHyphenated()); - xw.WriteAttributeString("profile_created",profile.created.ToString()); - xw.WriteAttributeString("profile_lastlogin",profile.lastLogin.ToString()); - // Home region information - xw.WriteAttributeString("home_coordinates", profile.homeLocation.ToString()); - xw.WriteAttributeString("home_region", profile.homeRegion.ToString()); - xw.WriteAttributeString("home_look", profile.homeLookAt.ToString()); - - xw.WriteEndElement(); - - // Footer - xw.WriteEndElement(); - xw.Flush(); - xw.Close(); - - return sw.ToString(); - } - - public string RestGetUserMethodName(string request, string path, string param) - { - UserProfileData userProfile = getUserProfile(param.Trim()); - - if (userProfile == null) - { - return CreateUnknownUserErrorResponse(); - } - - return ProfileToXml(userProfile); - } - - public string RestGetUserMethodUUID(string request, string path, string param) - { - UserProfileData userProfile = getUserProfile(new LLUUID(param)); - - if (userProfile == null) - { - return CreateUnknownUserErrorResponse(); - } - - return ProfileToXml(userProfile); - } - } } -- cgit v1.1