Some work on restructuring the namespaces / project names. Note this doesn't compile yet as not all the code has been changed to use the new namespaces. Am committing it now for feedback on the namespaces.

This commit is contained in:
MW
2007-06-27 15:28:52 +00:00
commit 646bbbc84b
1413 changed files with 62000 additions and 0 deletions

View File

@@ -0,0 +1,645 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Collections;
using System.Xml;
using libsecondlife;
using OpenSim.Framework.Utilities;
using OpenSim.Framework.Interfaces;
using Nwc.XmlRpc;
namespace OpenSim.Framework.UserManagement
{
/// <summary>
/// A temp class to handle login response.
/// Should make use of UserProfileManager where possible.
/// </summary>
public class LoginResponse
{
private Hashtable loginFlagsHash;
private Hashtable globalTexturesHash;
private Hashtable loginError;
private Hashtable eventCategoriesHash;
private Hashtable uiConfigHash;
private Hashtable classifiedCategoriesHash;
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 UserInfo userProfile;
private LLUUID agentID;
private LLUUID sessionID;
private LLUUID secureSessionID;
// Login Flags
private string dst;
private string stipendSinceLogin;
private string gendered;
private string everLoggedIn;
private string login;
private int simPort;
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;
public LoginResponse()
{
this.loginFlags = new ArrayList();
this.globalTextures = new ArrayList();
this.eventCategories = new ArrayList();
this.uiConfig = new ArrayList();
this.classifiedCategories = new ArrayList();
this.loginError = new Hashtable();
this.eventCategoriesHash = new Hashtable();
this.classifiedCategoriesHash = new Hashtable();
this.uiConfigHash = new Hashtable();
this.defaultXmlRpcResponse = new XmlRpcResponse();
this.userProfile = new UserInfo();
this.inventoryRoot = new ArrayList();
this.initialOutfit = new ArrayList();
this.agentInventory = new ArrayList();
this.xmlRpcResponse = new XmlRpcResponse();
this.defaultXmlRpcResponse = new XmlRpcResponse();
this.SetDefaultValues();
} // LoginServer
public void SetDefaultValues()
{
this.DST = "N";
this.StipendSinceLogin = "N";
this.Gendered = "Y";
this.EverLoggedIn = "Y";
this.login = "false";
this.firstname = "Test";
this.lastname = "User";
this.agentAccess = "M";
this.startLocation = "last";
this.allowFirstLife = "Y";
this.SunTexture = "cce0f112-878f-4586-a2e2-a8f104bba271";
this.CloudTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
this.MoonTexture = "fc4b9f0b-d008-45c6-96a4-01dd947ac621";
this.ErrorMessage = "You have entered an invalid name/password combination. Check Caps/lock.";
this.ErrorReason = "key";
this.welcomeMessage = "Welcome to OpenSim!";
this.seedCapability = "";
this.home = "{'region_handle':[r" + (997 * 256).ToString() + ",r" + (996 * 256).ToString() + "], 'position':[r" + this.userProfile.homepos.X.ToString() + ",r" + this.userProfile.homepos.Y.ToString() + ",r" + this.userProfile.homepos.Z.ToString() + "], 'look_at':[r" + this.userProfile.homelookat.X.ToString() + ",r" + this.userProfile.homelookat.Y.ToString() + ",r" + this.userProfile.homelookat.Z.ToString() + "]}";
this.lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]";
this.RegionX = (uint)255232;
this.RegionY = (uint)254976;
// Classifieds;
this.AddClassifiedCategory((Int32)1, "Shopping");
this.AddClassifiedCategory((Int32)2, "Land Rental");
this.AddClassifiedCategory((Int32)3, "Property Rental");
this.AddClassifiedCategory((Int32)4, "Special Attraction");
this.AddClassifiedCategory((Int32)5, "New Products");
this.AddClassifiedCategory((Int32)6, "Employment");
this.AddClassifiedCategory((Int32)7, "Wanted");
this.AddClassifiedCategory((Int32)8, "Service");
this.AddClassifiedCategory((Int32)9, "Personal");
this.SessionID = LLUUID.Random();
this.SecureSessionID = LLUUID.Random();
this.AgentID = LLUUID.Random();
Hashtable InitialOutfitHash = new Hashtable();
InitialOutfitHash["folder_name"] = "Nightclub Female";
InitialOutfitHash["gender"] = "female";
this.initialOutfit.Add(InitialOutfitHash);
} // SetDefaultValues
#region Login Failure Methods
public XmlRpcResponse GenerateFailureResponse(string reason, string message, string login)
{
// Overwrite any default values;
this.xmlRpcResponse = new XmlRpcResponse();
// Ensure Login Failed message/reason;
this.ErrorMessage = message;
this.ErrorReason = reason;
this.loginError["reason"] = this.ErrorReason;
this.loginError["message"] = this.ErrorMessage;
this.loginError["login"] = login;
this.xmlRpcResponse.Value = this.loginError;
return (this.xmlRpcResponse);
} // GenerateResponse
public XmlRpcResponse CreateFailedResponse()
{
return (this.CreateLoginFailedResponse());
} // CreateErrorConnectingToGridResponse()
public XmlRpcResponse CreateLoginFailedResponse()
{
return (this.GenerateFailureResponse("key", "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", "false"));
} // LoginFailedResponse
public XmlRpcResponse CreateAlreadyLoggedInResponse()
{
return (this.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", "false"));
} // CreateAlreadyLoggedInResponse()
public XmlRpcResponse CreateDeadRegionResponse()
{
return (this.GenerateFailureResponse("key", "The region you are attempting to log into is not responding. Please select another region and try again.", "false"));
}
public XmlRpcResponse CreateGridErrorResponse()
{
return (this.GenerateFailureResponse("key", "Error connecting to grid. Could not percieve credentials from login XML.", "false"));
}
#endregion
public XmlRpcResponse ToXmlRpcResponse()
{
try
{
Hashtable responseData = new Hashtable();
this.loginFlagsHash = new Hashtable();
this.loginFlagsHash["daylight_savings"] = this.DST;
this.loginFlagsHash["stipend_since_login"] = this.StipendSinceLogin;
this.loginFlagsHash["gendered"] = this.Gendered;
this.loginFlagsHash["ever_logged_in"] = this.EverLoggedIn;
this.loginFlags.Add(this.loginFlagsHash);
responseData["first_name"] = this.Firstname;
responseData["last_name"] = this.Lastname;
responseData["agent_access"] = this.agentAccess;
this.globalTexturesHash = new Hashtable();
this.globalTexturesHash["sun_texture_id"] = this.SunTexture;
this.globalTexturesHash["cloud_texture_id"] = this.CloudTexture;
this.globalTexturesHash["moon_texture_id"] = this.MoonTexture;
this.globalTextures.Add(this.globalTexturesHash);
this.eventCategories.Add(this.eventCategoriesHash);
this.AddToUIConfig("allow_first_life", this.allowFirstLife);
this.uiConfig.Add(this.uiConfigHash);
responseData["sim_port"] =(Int32) this.SimPort;
responseData["sim_ip"] = this.SimAddress;
responseData["agent_id"] = this.AgentID.ToStringHyphenated();
responseData["session_id"] = this.SessionID.ToStringHyphenated();
responseData["secure_session_id"] = this.SecureSessionID.ToStringHyphenated();
responseData["circuit_code"] = this.CircuitCode;
responseData["seconds_since_epoch"] = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
responseData["login-flags"] = this.loginFlags;
responseData["global-textures"] = this.globalTextures;
responseData["seed_capability"] = this.seedCapability;
responseData["event_categories"] = this.eventCategories;
responseData["event_notifications"] = new ArrayList(); // todo
responseData["classified_categories"] = this.classifiedCategories;
responseData["ui-config"] = this.uiConfig;
responseData["inventory-skeleton"] = this.agentInventory;
responseData["inventory-skel-lib"] = new ArrayList(); // todo
responseData["inventory-root"] = this.inventoryRoot;
responseData["gestures"] = new ArrayList(); // todo
responseData["inventory-lib-owner"] = new ArrayList(); // todo
responseData["initial-outfit"] = this.initialOutfit;
responseData["start_location"] = this.startLocation;
responseData["seed_capability"] = this.seedCapability;
responseData["home"] = this.home;
responseData["look_at"] = this.lookAt;
responseData["message"] = this.welcomeMessage;
responseData["region_x"] = (Int32)this.RegionX * 256;
responseData["region_y"] = (Int32)this.RegionY * 256;
//responseData["inventory-lib-root"] = new ArrayList(); // todo
//responseData["buddy-list"] = new ArrayList(); // todo
responseData["login"] = "true";
this.xmlRpcResponse.Value = responseData;
return (this.xmlRpcResponse);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.WriteLine(
OpenSim.Framework.Console.LogPriority.LOW,
"LoginResponse: Error creating XML-RPC Response: " + e.Message
);
return (this.GenerateFailureResponse("Internal Error", "Error generating Login Response", "false"));
}
} // ToXmlRpcResponse
public void SetEventCategories(string category, string value)
{
this.eventCategoriesHash[category] = value;
} // SetEventCategories
public void AddToUIConfig(string itemName, string item)
{
this.uiConfigHash[itemName] = item;
} // SetUIConfig
public void AddClassifiedCategory(Int32 ID, string categoryName)
{
this.classifiedCategoriesHash["category_name"] = categoryName;
this.classifiedCategoriesHash["category_id"] = ID;
this.classifiedCategories.Add(this.classifiedCategoriesHash);
// this.classifiedCategoriesHash.Clear();
} // SetClassifiedCategory
#region Properties
public string Login
{
get
{
return this.login;
}
set
{
this.login = value;
}
} // Login
public string DST
{
get
{
return this.dst;
}
set
{
this.dst = value;
}
} // DST
public string StipendSinceLogin
{
get
{
return this.stipendSinceLogin;
}
set
{
this.stipendSinceLogin = value;
}
} // StipendSinceLogin
public string Gendered
{
get
{
return this.gendered;
}
set
{
this.gendered = value;
}
} // Gendered
public string EverLoggedIn
{
get
{
return this.everLoggedIn;
}
set
{
this.everLoggedIn = value;
}
} // EverLoggedIn
public int SimPort
{
get
{
return this.simPort;
}
set
{
this.simPort = value;
}
} // SimPort
public string SimAddress
{
get
{
return this.simAddress;
}
set
{
this.simAddress = value;
}
} // SimAddress
public LLUUID AgentID
{
get
{
return this.agentID;
}
set
{
this.agentID = value;
}
} // AgentID
public LLUUID SessionID
{
get
{
return this.sessionID;
}
set
{
this.sessionID = value;
}
} // SessionID
public LLUUID SecureSessionID
{
get
{
return this.secureSessionID;
}
set
{
this.secureSessionID = value;
}
} // SecureSessionID
public Int32 CircuitCode
{
get
{
return this.circuitCode;
}
set
{
this.circuitCode = value;
}
} // CircuitCode
public uint RegionX
{
get
{
return this.regionX;
}
set
{
this.regionX = value;
}
} // RegionX
public uint RegionY
{
get
{
return this.regionY;
}
set
{
this.regionY = value;
}
} // RegionY
public string SunTexture
{
get
{
return this.sunTexture;
}
set
{
this.sunTexture = value;
}
} // SunTexture
public string CloudTexture
{
get
{
return this.cloudTexture;
}
set
{
this.cloudTexture = value;
}
} // CloudTexture
public string MoonTexture
{
get
{
return this.moonTexture;
}
set
{
this.moonTexture = value;
}
} // MoonTexture
public string Firstname
{
get
{
return this.firstname;
}
set
{
this.firstname = value;
}
} // Firstname
public string Lastname
{
get
{
return this.lastname;
}
set
{
this.lastname = value;
}
} // Lastname
public string AgentAccess
{
get
{
return this.agentAccess;
}
set
{
this.agentAccess = value;
}
}
public string StartLocation
{
get
{
return this.startLocation;
}
set
{
this.startLocation = value;
}
} // StartLocation
public string LookAt
{
get
{
return this.lookAt;
}
set
{
this.lookAt = value;
}
}
public string SeedCapability
{
get
{
return this.seedCapability;
}
set
{
this.seedCapability = value;
}
} // SeedCapability
public string ErrorReason
{
get
{
return this.errorReason;
}
set
{
this.errorReason = value;
}
} // ErrorReason
public string ErrorMessage
{
get
{
return this.errorMessage;
}
set
{
this.errorMessage = value;
}
} // ErrorMessage
public ArrayList InventoryRoot
{
get
{
return this.inventoryRoot;
}
set
{
this.inventoryRoot = value;
}
}
public ArrayList InventorySkeleton
{
get
{
return this.agentInventory;
}
set
{
this.agentInventory = value;
}
}
public string Home
{
get
{
return this.home;
}
set
{
this.home = value;
}
}
public string Message
{
get
{
return this.welcomeMessage;
}
set
{
this.welcomeMessage = value;
}
}
#endregion
public class UserInfo
{
public string firstname;
public string lastname;
public ulong homeregionhandle;
public LLVector3 homepos;
public LLVector3 homelookat;
}
}
}

View File

@@ -0,0 +1,125 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{586E2916-0000-0000-0000-000000000000}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ApplicationIcon></ApplicationIcon>
<AssemblyKeyContainerName>
</AssemblyKeyContainerName>
<AssemblyName>OpenSim.Framework.UserManagement</AssemblyName>
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<AppDesignerFolder></AppDesignerFolder>
<RootNamespace>OpenSim.Framework.UserManagement</RootNamespace>
<StartupObject></StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>False</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE</DefineConstants>
<DocumentationFile></DocumentationFile>
<DebugSymbols>False</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<Optimize>True</Optimize>
<OutputPath>..\..\..\bin\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn></NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="Db4objects.Db4o.dll" >
<HintPath>..\..\..\bin\Db4objects.Db4o.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="libsecondlife.dll" >
<HintPath>..\..\..\bin\libsecondlife.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Framework" >
<HintPath>OpenSim.Framework.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Framework.Console" >
<HintPath>OpenSim.Framework.Console.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Framework.GenericConfig.Xml" >
<HintPath>OpenSim.Framework.GenericConfig.Xml.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="OpenSim.Framework.Servers" >
<HintPath>OpenSim.Framework.Servers.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" >
<HintPath>System.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Data" >
<HintPath>System.Data.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System.Xml" >
<HintPath>System.Xml.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="XMLRPC.dll" >
<HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Data\OpenSim.Framework.Data.csproj">
<Name>OpenSim.Framework.Data</Name>
<Project>{36B72A9B-0000-0000-0000-000000000000}</Project>
<Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="LoginResponse.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="UserManagerBase.cs">
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,12 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ReferencePath>C:\New Folder\second-life-viewer\opensim-dailys2\opensim15-06\NameSpaceChanges\bin\</ReferencePath>
<LastOpenVersion>8.0.50727</LastOpenVersion>
<ProjectView>ProjectFiles</ProjectView>
<ProjectTrust>0</ProjectTrust>
</PropertyGroup>
<PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition = " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
</Project>

View File

@@ -0,0 +1,641 @@
/*
* Copyright (c) Contributors, http://www.openmetaverse.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.Text;
using OpenSim.Framework.Data;
using libsecondlife;
using System.Reflection;
using System.Xml;
using Nwc.XmlRpc;
using OpenSim.Framework.Sims;
using OpenSim.Framework.Inventory;
using OpenSim.Framework.Utilities;
using System.Security.Cryptography;
namespace OpenSim.Framework.UserManagement
{
public class UserManagerBase
{
public OpenSim.Framework.Interfaces.UserConfig _config;
Dictionary<string, IUserData> _plugins = new Dictionary<string, IUserData>();
/// <summary>
/// Adds a new user server plugin - user servers will be requested in the order they were loaded.
/// </summary>
/// <param name="FileName">The filename to the user server plugin DLL</param>
public void AddPlugin(string FileName)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Userstorage: Attempting to load " + FileName);
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
OpenSim.Framework.Console.MainLog.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.MainLog.Instance.Verbose( "Userstorage: Added IUserData Interface");
}
typeInterface = null;
}
}
pluginAssembly = null;
}
#region Get UserProfile
/// <summary>
/// Loads a user profile from a database by UUID
/// </summary>
/// <param name="uuid">The target UUID</param>
/// <returns>A user profile</returns>
public UserProfileData getUserProfile(LLUUID uuid)
{
foreach (KeyValuePair<string, IUserData> plugin in _plugins)
{
try
{
UserProfileData profile = plugin.Value.getUserByUUID(uuid);
profile.currentAgent = getUserAgent(profile.UUID);
return profile;
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
/// <summary>
/// Loads a user profile by name
/// </summary>
/// <param name="name">The target name</param>
/// <returns>A user profile</returns>
public UserProfileData getUserProfile(string name)
{
foreach (KeyValuePair<string, IUserData> plugin in _plugins)
{
try
{
UserProfileData profile = plugin.Value.getUserByName(name);
profile.currentAgent = getUserAgent(profile.UUID);
return profile;
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
/// <summary>
/// Loads a user profile by name
/// </summary>
/// <param name="fname">First name</param>
/// <param name="lname">Last name</param>
/// <returns>A user profile</returns>
public UserProfileData getUserProfile(string fname, string lname)
{
foreach (KeyValuePair<string, IUserData> 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.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
#endregion
#region Get UserAgent
/// <summary>
/// Loads a user agent by uuid (not called directly)
/// </summary>
/// <param name="uuid">The agents UUID</param>
/// <returns>Agent profiles</returns>
public UserAgentData getUserAgent(LLUUID uuid)
{
foreach (KeyValuePair<string, IUserData> plugin in _plugins)
{
try
{
return plugin.Value.getAgentByUUID(uuid);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
/// <summary>
/// Loads a user agent by name (not called directly)
/// </summary>
/// <param name="name">The agents name</param>
/// <returns>A user agent</returns>
public UserAgentData getUserAgent(string name)
{
foreach (KeyValuePair<string, IUserData> plugin in _plugins)
{
try
{
return plugin.Value.getAgentByName(name);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
/// <summary>
/// Loads a user agent by name (not called directly)
/// </summary>
/// <param name="fname">The agents firstname</param>
/// <param name="lname">The agents lastname</param>
/// <returns>A user agent</returns>
public UserAgentData getUserAgent(string fname, string lname)
{
foreach (KeyValuePair<string, IUserData> plugin in _plugins)
{
try
{
return plugin.Value.getAgentByName(fname,lname);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose( "Unable to find user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
return null;
}
#endregion
#region CreateAgent
/// <summary>
/// Creates and initialises a new user agent - make sure to use CommitAgent when done to submit to the DB
/// </summary>
/// <param name="profile">The users profile</param>
/// <param name="request">The users loginrequest</param>
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;
}
/// <summary>
/// Saves a target agent to the database
/// </summary>
/// <param name="profile">The users profile</param>
/// <returns>Successful?</returns>
public bool CommitAgent(ref UserProfileData profile)
{
// Saves the agent to database
return true;
}
#endregion
/// <summary>
/// Checks a user against it's password hash
/// </summary>
/// <param name="profile">The users profile</param>
/// <param name="password">The supplied password</param>
/// <returns>Authenticated?</returns>
public virtual bool AuthenticateUser(ref UserProfileData profile, string password)
{
OpenSim.Framework.Console.MainLog.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);
}
#region Xml Response
/// <summary>
///
/// </summary>
/// <param name="firstname"></param>
/// <param name="lastname"></param>
/// <returns></returns>
public virtual UserProfileData GetTheUser(string firstname, string lastname)
{
return getUserProfile(firstname, lastname);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual string GetMessage()
{
return _config.DefaultStartupMsg;
}
/// <summary>
/// Customises the login response and fills in missing values.
/// </summary>
/// <param name="response">The existing response</param>
/// <param name="theUser">The user profile</param>
public virtual void CustomiseResponse(ref LoginResponse response, ref UserProfileData theUser)
{
}
/// <summary>
/// Main user login function
/// </summary>
/// <param name="request">The XMLRPC request</param>
/// <returns>The response to send</returns>
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;
LoginResponse logResponse = new LoginResponse();
if (GoodXML)
{
firstname = (string)requestData["first"];
lastname = (string)requestData["last"];
passwd = (string)requestData["passwd"];
TheUser = GetTheUser(firstname, lastname);
if (TheUser == null)
return logResponse.CreateLoginFailedResponse();
GoodLogin = AuthenticateUser(ref TheUser, passwd);
}
else
{
return logResponse.CreateGridErrorResponse();
}
if (!GoodLogin)
{
return logResponse.CreateLoginFailedResponse();
}
else
{
// If we already have a session...
if (TheUser.currentAgent != null && TheUser.currentAgent.agentOnline)
{
// Reject the login
return logResponse.CreateAlreadyLoggedInResponse();
}
// Otherwise...
// Create a new agent session
CreateAgent(ref TheUser, request);
try
{
LLUUID AgentID = TheUser.UUID;
// 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);
// Circuit Code
uint circode = (uint)(Util.RandomClass.Next());
logResponse.Lastname = TheUser.surname;
logResponse.Firstname = TheUser.username;
logResponse.AgentID = AgentID.ToStringHyphenated();
logResponse.SessionID = TheUser.currentAgent.sessionID.ToStringHyphenated();
logResponse.SecureSessionID = TheUser.currentAgent.secureSessionID.ToStringHyphenated();
logResponse.InventoryRoot = InventoryRoot;
logResponse.InventorySkeleton = AgentInventoryArray;
logResponse.CircuitCode = (Int32)circode;
logResponse.RegionX = 0; //overwritten
logResponse.RegionY = 0; //overwritten
logResponse.Home = "!!null temporary value {home}!!"; // Overwritten
//logResponse.LookAt = "\n[r" + TheUser.homeLookAt.X.ToString() + ",r" + TheUser.homeLookAt.Y.ToString() + ",r" + TheUser.homeLookAt.Z.ToString() + "]\n";
logResponse.SimAddress = "127.0.0.1"; //overwritten
logResponse.SimPort = 0; //overwritten
logResponse.Message = this.GetMessage();
try
{
this.CustomiseResponse(ref logResponse, ref TheUser);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
return logResponse.CreateDeadRegionResponse();
}
CommitAgent(ref TheUser);
return logResponse.ToXmlRpcResponse();
}
catch (Exception E)
{
System.Console.WriteLine(E.ToString());
}
//}
}
return response;
}
#endregion
/// <summary>
/// Deletes an active agent session
/// </summary>
/// <param name="request">The request</param>
/// <param name="path">The path (eg /bork/narf/test)</param>
/// <param name="param">Parameters sent</param>
/// <returns>Success "OK" else error</returns>
public string RestDeleteUserSessionMethod(string request, string path, string param)
{
// TODO! Important!
return "OK";
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
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<string, IUserData> plugin in _plugins)
{
try
{
plugin.Value.addNewUserProfile(user);
}
catch (Exception e)
{
OpenSim.Framework.Console.MainLog.Instance.Verbose("Unable to add user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
}
/// <summary>
/// Returns an error message that the user could not be found in the database
/// </summary>
/// <returns>XML string consisting of a error element containing individual error(s)</returns>
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();
}
/// <summary>
/// Converts a user profile to an XML element which can be returned
/// </summary>
/// <param name="profile">The user profile</param>
/// <returns>A string containing an XML Document of the user profile</returns>
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();
}
#region REST Methods
//should most likely move out of here and into the grid's userserver sub class
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);
}
#endregion
}
}