Remote copied curren trunk (3509) to 0.6b branch
							parent
							
								
									c0dc6b1a42
								
							
						
					
					
						commit
						24e3c71111
					
				|  | @ -0,0 +1,41 @@ | |||
| <property name="projectdir" value="opensim-0.4" /> | ||||
| 
 | ||||
| <target name="distdir"> | ||||
|    <delete dir="${projectdir}" /> | ||||
|    <copy todir="${projectdir}"> | ||||
|        <fileset basedir="."> | ||||
|           <include name="ThirdPartyLicenses/**" /> | ||||
|           <include name="CONTRIBUTORS.txt" /> | ||||
|           <include name="README" /> | ||||
|           <include name="OpenSim/**/*.cs" /> | ||||
|           <include name="**/*.build" /> | ||||
|           <include name="**/*.csproj" /> | ||||
|           <include name="**/*.csproj.user" /> | ||||
|           <include name="**/*.sln" /> | ||||
|           <include name="bin/*.dll" /> | ||||
|           <include name="bin/*.so" /> | ||||
|           <include name="bin/*.config" /> | ||||
|           <include name="bin/assets/**" /> | ||||
|           <include name="bin/data/**" /> | ||||
|           <include name="bin/OpenSim*xml" /> | ||||
|           <!-- the next is to exclude built libs --> | ||||
|           <exclude name="bin/OpenSim.*dll" /> | ||||
|           <include name="bin/OpenSim.ini" /> | ||||
|           <include name="bin/defaultstripe.png" /> | ||||
|        </fileset> | ||||
|    </copy> | ||||
|    <touch file="${projectdir}/bin/startup_commands.txt" /> | ||||
| </target> | ||||
| 
 | ||||
| <target name="dist" depends="distdir"> | ||||
|     <zip zipfile="${projectdir}.zip"> | ||||
|     <fileset basedir="."> | ||||
|         <include name="${projectdir}/**" /> | ||||
|     </fileset> | ||||
|     </zip> | ||||
|     <tar destfile="${projectdir}.tar.gz" compression="GZip"> | ||||
|     <fileset basedir="."> | ||||
|         <include name="${projectdir}/**" /> | ||||
|     </fileset> | ||||
|     </tar> | ||||
| </target> | ||||
|  | @ -0,0 +1,77 @@ | |||
| The following people have contributed to OpenSim (Thank you  | ||||
| for your effort!) | ||||
| 
 | ||||
| Add your name in here if you have committed to OpenSim | ||||
| 
 | ||||
| 
 | ||||
| OpenSim Developers  | ||||
| 
 | ||||
| * MW (Tribal Media AB) | ||||
| * Adam Frisby 	(DeepThink Pty Ltd) | ||||
| * MingChen 	(DeepThink Pty Ltd) | ||||
| * lbsa71 (Tribal Media AB) | ||||
| * sdague (International Business Machines Corp.) | ||||
| * Andy-	 | ||||
| * Gareth | ||||
| * MorphW | ||||
| * CW | ||||
| * Babblefrog | ||||
| * Tedd | ||||
| * justincc (International Business Machines Corp.) | ||||
| * Teravus (w3z) | ||||
| * Johan Berntsson (3Di) | ||||
| * Ckrinke (Charles Krinke) | ||||
| * Danx0r | ||||
| * Dalien | ||||
| * Darok | ||||
| * chi11ken (3Di) | ||||
| * adjohn (3Di) | ||||
| * Alondria | ||||
| 
 | ||||
| 
 | ||||
| Patches | ||||
| 
 | ||||
| * BigFootAg | ||||
| * CharlieO | ||||
| * jhurliman (LLSD Login) | ||||
| * kinoc | ||||
| * daTwitch  | ||||
| * mikkopa/_someone - RealXtend | ||||
| * openlifegrid.com | ||||
| * Dr Scofield (International Business Machines Corp.) | ||||
| * Daedius | ||||
| * alex_carnell | ||||
| * webmage (International Business Machines Corp.) | ||||
| * jimbo2120 (International Business Machines Corp.) | ||||
| 
 | ||||
| 
 | ||||
| LSL Devs | ||||
| 
 | ||||
| * Alondria | ||||
| * CharlieO | ||||
| * Tedd | ||||
| 
 | ||||
| 
 | ||||
| Testers | ||||
| 
 | ||||
| * Ckrinke | ||||
| * CharlieO (LSL) | ||||
| * openlifegrid.com | ||||
| 
 | ||||
| 
 | ||||
| This software uses components from the following developers: | ||||
| * Sleepycat Software (Berkeley DB) | ||||
| * DB4objects, Inc. (DB4o) | ||||
| * SQLite (Public Domain) | ||||
| * XmlRpcCS (http://xmlrpccs.sf.net/) | ||||
| * MySQL, Inc. (MySQL Connector/NET) | ||||
| * AGEIA Inc. (PhysX) | ||||
| * Russel L. Smith (ODE) | ||||
| * Prebuild ( http://sourceforge.net/projects/dnpb/ ) | ||||
| * LibSecondLife ( http://www.libsecondlife.org/wiki/Main_Page ) | ||||
| 
 | ||||
| 
 | ||||
| In addition, we would like to thank: | ||||
| * The Mono Project | ||||
| * The NANT Developers | ||||
| * Microsoft (.NET, MSSQL-Adapters) | ||||
|  | @ -0,0 +1,25 @@ | |||
| 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. | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -0,0 +1,108 @@ | |||
| /* | ||||
| * 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 Mono.Addins; | ||||
| using OpenSim.Framework; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.RegionLoader.Filesystem; | ||||
| using OpenSim.Framework.RegionLoader.Web; | ||||
| 
 | ||||
| [assembly : Addin] | ||||
| [assembly : AddinDependency("OpenSim", "0.5")] | ||||
| 
 | ||||
| namespace OpenSim.ApplicationPlugins.LoadRegions | ||||
| { | ||||
|     [Extension("/OpenSim/Startup")] | ||||
|     public class LoadRegionsPlugin : IApplicationPlugin | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public void Initialise(OpenSimMain openSim) | ||||
|         { | ||||
|             m_log.Info("[LOADREGIONS]: Load Regions addin being initialised"); | ||||
| 
 | ||||
|             IRegionLoader regionLoader; | ||||
|             if (openSim.ConfigSource.Configs["Startup"].GetString("region_info_source", "filesystem") == "filesystem") | ||||
|             { | ||||
|                 m_log.Info("[LOADREGIONS]: Loading Region Info from filesystem"); | ||||
|                 regionLoader = new RegionLoaderFileSystem(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.Info("[LOADREGIONSPLUGIN]: Loading Region Info from web"); | ||||
|                 regionLoader = new RegionLoaderWebServer(); | ||||
|             } | ||||
| 
 | ||||
|             regionLoader.SetIniConfigSource(openSim.ConfigSource); | ||||
|             RegionInfo[] regionsToLoad = regionLoader.LoadRegions(); | ||||
| 
 | ||||
|             openSim.ModuleLoader.LoadDefaultSharedModules(); | ||||
| 
 | ||||
|             for (int i = 0; i < regionsToLoad.Length; i++) | ||||
|             { | ||||
|                 m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ")"); | ||||
|                 openSim.CreateRegion(regionsToLoad[i]); | ||||
|             } | ||||
| 
 | ||||
|             openSim.ModuleLoader.PostInitialise(); | ||||
|             openSim.ModuleLoader.ClearCache(); | ||||
|         } | ||||
| 
 | ||||
|         public void LoadRegionFromConfig(OpenSimMain openSim, ulong regionhandle) | ||||
|         { | ||||
|             m_log.Info("[LOADREGIONS]: Load Regions addin being initialised"); | ||||
| 
 | ||||
|             IRegionLoader regionLoader; | ||||
|             if (openSim.ConfigSource.Configs["Startup"].GetString("region_info_source", "filesystem") == "filesystem") | ||||
|             { | ||||
|                 m_log.Info("[LOADREGIONS]: Loading Region Info from filesystem"); | ||||
|                 regionLoader = new RegionLoaderFileSystem(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.Info("[LOADREGIONS]: Loading Region Info from web"); | ||||
|                 regionLoader = new RegionLoaderWebServer(); | ||||
|             } | ||||
| 
 | ||||
|             regionLoader.SetIniConfigSource(openSim.ConfigSource); | ||||
|             RegionInfo[] regionsToLoad = regionLoader.LoadRegions(); | ||||
|             for (int i = 0; i < regionsToLoad.Length; i++) | ||||
|             { | ||||
|                 if (regionhandle == regionsToLoad[i].RegionHandle) | ||||
|                 { | ||||
|                     m_log.Debug("[LOADREGIONS]: Creating Region: " + regionsToLoad[i].RegionName + " (ThreadID: " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ")"); | ||||
|                     openSim.CreateRegion(regionsToLoad[i]); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void Close() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,67 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following  | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("OpenSim.Addin")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly : AssemblyConfiguration("")] | ||||
| [assembly : AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("OpenSim.Addin")] | ||||
| [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")] | ||||
| [assembly : AssemblyTrademark("")] | ||||
| [assembly : AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible  | ||||
| // to COM components.  If you need to access a type in this assembly from  | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| 
 | ||||
| [assembly : Guid("45b979d9-d8d4-42fd-9780-fe9ac7e86cb4")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version  | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| // You can specify all the values or you can default the Build and Revision Numbers  | ||||
| // by using the '*' as shown below: | ||||
| // [assembly: AssemblyVersion("1.0.*")] | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.0.0")] | ||||
| [assembly : AssemblyFileVersion("1.0.0.0")] | ||||
|  | @ -0,0 +1,391 @@ | |||
| /* | ||||
| * 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.Net; | ||||
| using System.Timers; | ||||
| using libsecondlife; | ||||
| using Mono.Addins; | ||||
| using Nwc.XmlRpc; | ||||
| using OpenSim.Framework; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Servers; | ||||
| using OpenSim.Region.Environment.Scenes; | ||||
| 
 | ||||
| [assembly : Addin] | ||||
| [assembly : AddinDependency("OpenSim", "0.5")] | ||||
| 
 | ||||
| namespace OpenSim.ApplicationPlugins.LoadRegions | ||||
| { | ||||
|     [Extension("/OpenSim/Startup")] | ||||
|     public class RemoteAdminPlugin : IApplicationPlugin | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private OpenSimMain m_app; | ||||
|         private BaseHttpServer m_httpd; | ||||
|         private string requiredPassword = String.Empty; | ||||
| 
 | ||||
|         public void Initialise(OpenSimMain openSim) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (openSim.ConfigSource.Configs["RemoteAdmin"].GetBoolean("enabled", false)) | ||||
|                 { | ||||
|                     m_log.Info("[RADMIN]: Remote Admin Plugin Enabled"); | ||||
|                     requiredPassword = openSim.ConfigSource.Configs["RemoteAdmin"].GetString("access_password", String.Empty); | ||||
| 
 | ||||
|                     m_app = openSim; | ||||
|                     m_httpd = openSim.HttpServer; | ||||
| 
 | ||||
|                     m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_broadcast", XmlRpcAlertMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod); | ||||
|                     m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod); | ||||
|                 } | ||||
|             } | ||||
|             catch (NullReferenceException) | ||||
|             { | ||||
|                 // Ignore. | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
| 
 | ||||
|             LLUUID regionID = new LLUUID((string) requestData["regionID"]); | ||||
| 
 | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["accepted"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 responseData["accepted"] = "true"; | ||||
|                 response.Value = responseData; | ||||
| 
 | ||||
|                 Scene RebootedScene; | ||||
| 
 | ||||
|                 if (m_app.SceneManager.TryGetScene(regionID, out RebootedScene)) | ||||
|                 { | ||||
|                     responseData["rebooting"] = "true"; | ||||
|                     RebootedScene.Restart(30); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     responseData["rebooting"] = "false"; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
| 
 | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["accepted"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 string message = (string) requestData["message"]; | ||||
|                 m_log.Info("[RADMIN]: Broadcasting: " + message); | ||||
| 
 | ||||
|                 responseData["accepted"] = "true"; | ||||
|                 response.Value = responseData; | ||||
| 
 | ||||
|                 m_app.SceneManager.SendGeneralMessage(message); | ||||
|             } | ||||
| 
 | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable)request.Params[0]; | ||||
| 
 | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != String.Empty && | ||||
|                 (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["accepted"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 string file = (string)requestData["filename"]; | ||||
|                 LLUUID regionID = LLUUID.Parse((string)requestData["regionid"]); | ||||
|                 m_log.Info("[RADMIN]: Terrain Loading: " + file); | ||||
| 
 | ||||
|                 responseData["accepted"] = "true"; | ||||
| 
 | ||||
|                 Scene region = null; | ||||
| 
 | ||||
|                 if (m_app.SceneManager.TryGetScene(regionID, out region)) | ||||
|                 { | ||||
|                     region.LoadWorldMap(file); | ||||
|                     responseData["success"] = "true"; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     responseData["success"] = "false"; | ||||
|                     responseData["error"] = "1: Unable to get a scene with that name."; | ||||
|                 } | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
| 
 | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             m_log.Info("[RADMIN]: Received Shutdown Administrator Request"); | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["accepted"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if ((string) requestData["shutdown"] == "delayed") | ||||
|                 { | ||||
|                     int timeout = (Int32) requestData["milliseconds"]; | ||||
| 
 | ||||
|                     responseData["accepted"] = "true"; | ||||
|                     response.Value = responseData; | ||||
| 
 | ||||
|                     m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() + | ||||
|                                                           " second(s). Please save what you are doing and log out."); | ||||
| 
 | ||||
|                     // Perform shutdown | ||||
|                     Timer shutdownTimer = new Timer(timeout); // Wait before firing | ||||
|                     shutdownTimer.AutoReset = false; | ||||
|                     shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); | ||||
|                     shutdownTimer.Start(); | ||||
| 
 | ||||
|                     return response; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     responseData["accepted"] = "true"; | ||||
|                     response.Value = responseData; | ||||
| 
 | ||||
|                     m_app.SceneManager.SendGeneralMessage("Region is going down now."); | ||||
| 
 | ||||
|                     // Perform shutdown | ||||
|                     Timer shutdownTimer = new Timer(2000); // Wait 2 seconds before firing | ||||
|                     shutdownTimer.AutoReset = false; | ||||
|                     shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed); | ||||
|                     shutdownTimer.Start(); | ||||
| 
 | ||||
|                     return response; | ||||
|                 } | ||||
|             } | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e) | ||||
|         { | ||||
|             m_app.Shutdown(); | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             m_log.Info("[RADMIN]: Received Create Region Administrator Request"); | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != System.String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["created"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 RegionInfo newRegionData = new RegionInfo(); | ||||
| 
 | ||||
|                 try | ||||
|                 { | ||||
|                     newRegionData.RegionID = (string) requestData["region_id"]; | ||||
|                     newRegionData.RegionName = (string) requestData["region_name"]; | ||||
|                     newRegionData.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]); | ||||
|                     newRegionData.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]); | ||||
| 
 | ||||
|                     // Security risk | ||||
|                     newRegionData.DataStore = (string) requestData["datastore"]; | ||||
| 
 | ||||
|                     newRegionData.InternalEndPoint = new IPEndPoint( | ||||
|                         IPAddress.Parse((string) requestData["listen_ip"]), 0); | ||||
| 
 | ||||
|                     newRegionData.InternalEndPoint.Port = (Int32) requestData["listen_port"]; | ||||
|                     newRegionData.ExternalHostName = (string) requestData["external_address"]; | ||||
| 
 | ||||
|                     newRegionData.MasterAvatarFirstName = (string) requestData["region_master_first"]; | ||||
|                     newRegionData.MasterAvatarLastName = (string) requestData["region_master_last"]; | ||||
| 
 | ||||
|                     m_app.CreateRegion(newRegionData); | ||||
| 
 | ||||
|                     responseData["created"] = "true"; | ||||
|                     response.Value = responseData; | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     responseData["created"] = "false"; | ||||
|                     responseData["error"] = e.ToString(); | ||||
|                     response.Value = responseData; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             m_log.Info("[RADMIN]: Received Create User Administrator Request"); | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != System.String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["created"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     string tempfirstname = (string) requestData["user_firstname"]; | ||||
|                     string templastname  = (string) requestData["user_lastname"]; | ||||
|                     string tempPasswd    = (string) requestData["user_password"]; | ||||
|                     uint   regX          = Convert.ToUInt32((Int32) requestData["start_region_x"]); | ||||
|                     uint   regY          = Convert.ToUInt32((Int32) requestData["start_region_y"]); | ||||
| 
 | ||||
|      	            LLUUID tempuserID = m_app.CreateUser(tempfirstname, templastname, tempPasswd, regX, regY); | ||||
| 
 | ||||
|                     if (tempuserID == LLUUID.Zero) | ||||
|                     { | ||||
|                         responseData["created"]     = "false"; | ||||
|                         responseData["error"]       = "Error creating user"; | ||||
|                         responseData["avatar_uuid"] = LLUUID.Zero; | ||||
|                         response.Value              = responseData; | ||||
|                         m_log.Error("[RADMIN]: Error creating user (" + tempfirstname + " " + templastname + ") :"); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         responseData["created"]     = "true"; | ||||
|                         responseData["avatar_uuid"] = tempuserID; | ||||
|                         response.Value              = responseData; | ||||
|                         m_log.Info("[RADMIN]: User " + tempfirstname + " " + templastname + " created. Userid " + tempuserID + " assigned."); | ||||
|                     }   | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     responseData["created"] = "false"; | ||||
|                     responseData["error"]   = e.ToString(); | ||||
|                     responseData["avatar_uuid"] = LLUUID.Zero; | ||||
|                     response.Value          = responseData; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request) | ||||
|         { | ||||
|             m_log.Info("[RADMIN]: Received Load XML Administrator Request"); | ||||
|             XmlRpcResponse response = new XmlRpcResponse(); | ||||
|             Hashtable requestData = (Hashtable) request.Params[0]; | ||||
|             Hashtable responseData = new Hashtable(); | ||||
|             if (requiredPassword != System.String.Empty && | ||||
|                 (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword)) | ||||
|             { | ||||
|                 responseData["loaded"] = "false"; | ||||
|                 responseData["switched"] = "false"; | ||||
|                 response.Value = responseData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     string region_name     = (string) requestData["region_name"]; | ||||
|                     string filename        = (string) requestData["filename"]; | ||||
|                      | ||||
|                     if (m_app.SceneManager.TrySetCurrentScene(region_name)) | ||||
|                     { | ||||
|                         m_log.Info("[RADMIN] Switched to region "+region_name); | ||||
|                         responseData["switched"] = "true"; | ||||
|                         m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0)); | ||||
|                         responseData["loaded"]   = "true"; | ||||
|                         response.Value           = responseData; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         m_log.Info("[RADMIN] Failed to switch to region "+region_name); | ||||
|                         responseData["loaded"] = "false"; | ||||
|                         responseData["switched"] = "false"; | ||||
|                         response.Value = responseData; | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     responseData["loaded"]  = "false"; | ||||
|                     responseData["error"]   = e.ToString(); | ||||
|                     response.Value          = responseData; | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             return response; | ||||
|         } | ||||
| 
 | ||||
|         public void Close() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,263 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     // ACL Class | ||||
|     // Modelled after the structure of the Zend ACL Framework Library | ||||
|     // with one key difference - the tree will search for all matching | ||||
|     // permissions rather than just the first. Deny permissions will | ||||
|     // override all others. | ||||
| 
 | ||||
|     #region ACL Core Class | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Access Control List Engine | ||||
|     /// </summary> | ||||
|     public class ACL | ||||
|     { | ||||
|         private Dictionary<string, Role> Roles = new Dictionary<string, Role>(); | ||||
|         private Dictionary<string, Resource> Resources = new Dictionary<string, Resource>(); | ||||
| 
 | ||||
|         public ACL AddRole(Role role) | ||||
|         { | ||||
|             if (Roles.ContainsKey(role.Name)) | ||||
|                 throw new AlreadyContainsRoleException(role); | ||||
| 
 | ||||
|             Roles.Add(role.Name, role); | ||||
| 
 | ||||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         public ACL AddResource(Resource resource) | ||||
|         { | ||||
|             Resources.Add(resource.Name, resource); | ||||
| 
 | ||||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         public Permission HasPermission(string role, string resource) | ||||
|         { | ||||
|             if (!Roles.ContainsKey(role)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             if (!Resources.ContainsKey(resource)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             return Roles[role].RequestPermission(resource); | ||||
|         } | ||||
| 
 | ||||
|         public ACL GrantPermission(string role, string resource) | ||||
|         { | ||||
|             if (!Roles.ContainsKey(role)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             if (!Resources.ContainsKey(resource)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             Roles[role].GivePermission(resource, Permission.Allow); | ||||
| 
 | ||||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         public ACL DenyPermission(string role, string resource) | ||||
|         { | ||||
|             if (!Roles.ContainsKey(role)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             if (!Resources.ContainsKey(resource)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             Roles[role].GivePermission(resource, Permission.Deny); | ||||
| 
 | ||||
|             return this; | ||||
|         } | ||||
| 
 | ||||
|         public ACL ResetPermission(string role, string resource) | ||||
|         { | ||||
|             if (!Roles.ContainsKey(role)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             if (!Resources.ContainsKey(resource)) | ||||
|                 throw new KeyNotFoundException(); | ||||
| 
 | ||||
|             Roles[role].GivePermission(resource, Permission.None); | ||||
| 
 | ||||
|             return this; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
|     #region Exceptions | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Thrown when an ACL attempts to add a duplicate role. | ||||
|     /// </summary> | ||||
|     public class AlreadyContainsRoleException : Exception | ||||
|     { | ||||
|         protected Role m_role; | ||||
| 
 | ||||
|         public Role ErrorRole | ||||
|         { | ||||
|             get { return m_role; } | ||||
|         } | ||||
| 
 | ||||
|         public AlreadyContainsRoleException(Role role) | ||||
|         { | ||||
|             m_role = role; | ||||
|         } | ||||
| 
 | ||||
|         public override string ToString() | ||||
|         { | ||||
|             return "This ACL already contains a role called '" + m_role.Name + "'."; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
|     #region Roles and Resources | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Does this Role have permission to access a specified Resource? | ||||
|     /// </summary> | ||||
|     public enum Permission | ||||
|     { | ||||
|         Deny, | ||||
|         None, | ||||
|         Allow | ||||
|     } ; | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// A role class, for use with Users or Groups | ||||
|     /// </summary> | ||||
|     public class Role | ||||
|     { | ||||
|         private string m_name; | ||||
|         private Role[] m_parents; | ||||
|         private Dictionary<string, Permission> m_resources = new Dictionary<string, Permission>(); | ||||
| 
 | ||||
|         public string Name | ||||
|         { | ||||
|             get { return m_name; } | ||||
|         } | ||||
| 
 | ||||
|         public Permission RequestPermission(string resource) | ||||
|         { | ||||
|             return RequestPermission(resource, Permission.None); | ||||
|         } | ||||
| 
 | ||||
|         public Permission RequestPermission(string resource, Permission current) | ||||
|         { | ||||
|             // Deny permissions always override any others | ||||
|             if (current == Permission.Deny) | ||||
|                 return current; | ||||
| 
 | ||||
|             Permission temp = Permission.None; | ||||
| 
 | ||||
|             // Pickup non-None permissions | ||||
|             if (m_resources.ContainsKey(resource) && m_resources[resource] != Permission.None) | ||||
|                 temp = m_resources[resource]; | ||||
| 
 | ||||
|             if (m_parents != null) | ||||
|             { | ||||
|                 foreach (Role parent in m_parents) | ||||
|                 { | ||||
|                     temp = parent.RequestPermission(resource, temp); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return temp; | ||||
|         } | ||||
| 
 | ||||
|         public void GivePermission(string resource, Permission perm) | ||||
|         { | ||||
|             m_resources[resource] = perm; | ||||
|         } | ||||
| 
 | ||||
|         public Role(string name) | ||||
|         { | ||||
|             m_name = name; | ||||
|             m_parents = null; | ||||
|         } | ||||
| 
 | ||||
|         public Role(string name, Role[] parents) | ||||
|         { | ||||
|             m_name = name; | ||||
|             m_parents = parents; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public class Resource | ||||
|     { | ||||
|         private string m_name; | ||||
| 
 | ||||
|         public string Name | ||||
|         { | ||||
|             get { return m_name; } | ||||
|         } | ||||
| 
 | ||||
|         public Resource(string name) | ||||
|         { | ||||
|             m_name = name; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| 
 | ||||
|     #region Tests | ||||
| 
 | ||||
|     internal class ACLTester | ||||
|     { | ||||
|         public ACLTester() | ||||
|         { | ||||
|             ACL acl = new ACL(); | ||||
| 
 | ||||
|             Role Guests = new Role("Guests"); | ||||
|             acl.AddRole(Guests); | ||||
| 
 | ||||
|             Role[] parents = new Role[0]; | ||||
|             parents[0] = Guests; | ||||
| 
 | ||||
|             Role JoeGuest = new Role("JoeGuest", parents); | ||||
|             acl.AddRole(JoeGuest); | ||||
| 
 | ||||
|             Resource CanBuild = new Resource("CanBuild"); | ||||
|             acl.AddResource(CanBuild); | ||||
| 
 | ||||
| 
 | ||||
|             acl.GrantPermission("Guests", "CanBuild"); | ||||
| 
 | ||||
|             acl.HasPermission("JoeGuest", "CanBuild"); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     #endregion | ||||
| } | ||||
|  | @ -0,0 +1,105 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AgentCircuitData | ||||
|     { | ||||
|         public AgentCircuitData() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public AgentCircuitData(sAgentCircuitData cAgent) | ||||
|         { | ||||
|             AgentID = new LLUUID(cAgent.AgentID); | ||||
|             SessionID = new LLUUID(cAgent.SessionID); | ||||
|             SecureSessionID = new LLUUID(cAgent.SecureSessionID); | ||||
|             startpos = new LLVector3(cAgent.startposx, cAgent.startposy, cAgent.startposz); | ||||
|             firstname = cAgent.firstname; | ||||
|             lastname = cAgent.lastname; | ||||
|             circuitcode = cAgent.circuitcode; | ||||
|             child = cAgent.child; | ||||
|             InventoryFolder = new LLUUID(cAgent.InventoryFolder); | ||||
|             BaseFolder = new LLUUID(cAgent.BaseFolder); | ||||
|             CapsPath = cAgent.CapsPath; | ||||
|         } | ||||
| 
 | ||||
|         public LLUUID AgentID; | ||||
|         public LLUUID SessionID; | ||||
|         public LLUUID SecureSessionID; | ||||
|         public LLVector3 startpos; | ||||
|         public string firstname; | ||||
|         public string lastname; | ||||
|         public uint circuitcode; | ||||
|         public bool child; | ||||
|         public LLUUID InventoryFolder; | ||||
|         public LLUUID BaseFolder; | ||||
|         public string CapsPath = String.Empty; | ||||
|     } | ||||
| 
 | ||||
|     [Serializable] | ||||
|     public class sAgentCircuitData | ||||
|     { | ||||
|         public sAgentCircuitData() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public sAgentCircuitData(AgentCircuitData cAgent) | ||||
|         { | ||||
|             AgentID = cAgent.AgentID.UUID; | ||||
|             SessionID = cAgent.SessionID.UUID; | ||||
|             SecureSessionID = cAgent.SecureSessionID.UUID; | ||||
|             startposx = cAgent.startpos.X; | ||||
|             startposy = cAgent.startpos.Y; | ||||
|             startposz = cAgent.startpos.Z; | ||||
|             firstname = cAgent.firstname; | ||||
|             lastname = cAgent.lastname; | ||||
|             circuitcode = cAgent.circuitcode; | ||||
|             child = cAgent.child; | ||||
|             InventoryFolder = cAgent.InventoryFolder.UUID; | ||||
|             BaseFolder = cAgent.BaseFolder.UUID; | ||||
|             CapsPath = cAgent.CapsPath; | ||||
|         } | ||||
| 
 | ||||
|         public Guid AgentID; | ||||
|         public Guid SessionID; | ||||
|         public Guid SecureSessionID; | ||||
|         public float startposx; | ||||
|         public float startposy; | ||||
|         public float startposz; | ||||
|         public string firstname; | ||||
|         public string lastname; | ||||
|         public uint circuitcode; | ||||
|         public bool child; | ||||
|         public Guid InventoryFolder; | ||||
|         public Guid BaseFolder; | ||||
|         public string CapsPath = String.Empty; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,127 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AgentCircuitManager | ||||
|     { | ||||
|         public Dictionary<uint, AgentCircuitData> AgentCircuits = new Dictionary<uint, AgentCircuitData>(); | ||||
| 
 | ||||
|         public AgentCircuitManager() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public virtual AuthenticateResponse AuthenticateSession(LLUUID sessionID, LLUUID agentID, uint circuitcode) | ||||
|         { | ||||
|             AgentCircuitData validcircuit = null; | ||||
|             if (AgentCircuits.ContainsKey(circuitcode)) | ||||
|             { | ||||
|                 validcircuit = AgentCircuits[circuitcode]; | ||||
|             } | ||||
|             AuthenticateResponse user = new AuthenticateResponse(); | ||||
|             if (validcircuit == null) | ||||
|             { | ||||
|                 //don't have this circuit code in our list | ||||
|                 user.Authorised = false; | ||||
|                 return (user); | ||||
|             } | ||||
| 
 | ||||
|             if ((sessionID == validcircuit.SessionID) && (agentID == validcircuit.AgentID)) | ||||
|             { | ||||
|                 user.Authorised = true; | ||||
|                 user.LoginInfo = new Login(); | ||||
|                 user.LoginInfo.Agent = agentID; | ||||
|                 user.LoginInfo.Session = sessionID; | ||||
|                 user.LoginInfo.SecureSession = validcircuit.SecureSessionID; | ||||
|                 user.LoginInfo.First = validcircuit.firstname; | ||||
|                 user.LoginInfo.Last = validcircuit.lastname; | ||||
|                 user.LoginInfo.InventoryFolder = validcircuit.InventoryFolder; | ||||
|                 user.LoginInfo.BaseFolder = validcircuit.BaseFolder; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 // Invalid | ||||
|                 user.Authorised = false; | ||||
|             } | ||||
| 
 | ||||
|             return (user); | ||||
|         } | ||||
| 
 | ||||
|         public virtual void AddNewCircuit(uint circuitCode, AgentCircuitData agentData) | ||||
|         { | ||||
|             if (AgentCircuits.ContainsKey(circuitCode)) | ||||
|             { | ||||
|                 AgentCircuits[circuitCode] = agentData; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 AgentCircuits.Add(circuitCode, agentData); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public LLVector3 GetPosition(uint circuitCode) | ||||
|         { | ||||
|             LLVector3 vec = new LLVector3(); | ||||
|             if (AgentCircuits.ContainsKey(circuitCode)) | ||||
|             { | ||||
|                 vec = AgentCircuits[circuitCode].startpos; | ||||
|             } | ||||
|             return vec; | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateAgentData(AgentCircuitData agentData) | ||||
|         { | ||||
|             if (AgentCircuits.ContainsKey((uint) agentData.circuitcode)) | ||||
|             { | ||||
|                 AgentCircuits[(uint) agentData.circuitcode].firstname = agentData.firstname; | ||||
|                 AgentCircuits[(uint) agentData.circuitcode].lastname = agentData.lastname; | ||||
|                 AgentCircuits[(uint) agentData.circuitcode].startpos = agentData.startpos; | ||||
|                 // Console.WriteLine("update user start pos is " + agentData.startpos.X + " , " + agentData.startpos.Y + " , " + agentData.startpos.Z); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateAgentChildStatus(uint circuitcode, bool childstatus) | ||||
|         { | ||||
|             if (AgentCircuits.ContainsKey(circuitcode)) | ||||
|             { | ||||
|                 AgentCircuits[circuitcode].child = childstatus; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool GetAgentChildStatus(uint circuitcode) | ||||
|         { | ||||
|             if (AgentCircuits.ContainsKey(circuitcode)) | ||||
|             { | ||||
|                 return AgentCircuits[circuitcode].child; | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,258 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using libsecondlife; | ||||
| using libsecondlife.Packets; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AgentInventory | ||||
|     { | ||||
|         //Holds the local copy of Inventory info for a agent | ||||
|         public Dictionary<LLUUID, InventoryFolder> InventoryFolders; | ||||
|         public Dictionary<LLUUID, InventoryItem> InventoryItems; | ||||
|         public InventoryFolder InventoryRoot; | ||||
|         public int LastCached; //maybe used by opensim app, time this was last stored/compared to user server | ||||
|         public LLUUID AgentID; | ||||
|         public AvatarWearable[] Wearables; | ||||
| 
 | ||||
|         public AgentInventory() | ||||
|         { | ||||
|             InventoryFolders = new Dictionary<LLUUID, InventoryFolder>(); | ||||
|             InventoryItems = new Dictionary<LLUUID, InventoryItem>(); | ||||
|             Initialise(); | ||||
|         } | ||||
| 
 | ||||
|         public virtual void Initialise() | ||||
|         { | ||||
|             Wearables = new AvatarWearable[13]; | ||||
|             for (int i = 0; i < 13; i++) | ||||
|             { | ||||
|                 Wearables[i] = new AvatarWearable(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool CreateNewFolder(LLUUID folderID, ushort type) | ||||
|         { | ||||
|             InventoryFolder Folder = new InventoryFolder(); | ||||
|             Folder.FolderID = folderID; | ||||
|             Folder.OwnerID = AgentID; | ||||
|             Folder.DefaultType = type; | ||||
|             InventoryFolders.Add(Folder.FolderID, Folder); | ||||
|             return (true); | ||||
|         } | ||||
| 
 | ||||
|         public void CreateRootFolder(LLUUID newAgentID, bool createTextures) | ||||
|         { | ||||
|             AgentID = newAgentID; | ||||
|             InventoryRoot = new InventoryFolder(); | ||||
|             InventoryRoot.FolderID = LLUUID.Random(); | ||||
|             InventoryRoot.ParentID = LLUUID.Zero; | ||||
|             InventoryRoot.Version = 1; | ||||
|             InventoryRoot.DefaultType = 8; | ||||
|             InventoryRoot.OwnerID = AgentID; | ||||
|             InventoryRoot.FolderName = "My Inventory"; | ||||
|             InventoryFolders.Add(InventoryRoot.FolderID, InventoryRoot); | ||||
|             InventoryRoot.OwnerID = AgentID; | ||||
|             if (createTextures) | ||||
|             { | ||||
|                 CreateNewFolder(LLUUID.Random(), 0, "Textures", InventoryRoot.FolderID); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName) | ||||
|         { | ||||
|             InventoryFolder Folder = new InventoryFolder(); | ||||
|             Folder.FolderID = folderID; | ||||
|             Folder.OwnerID = AgentID; | ||||
|             Folder.DefaultType = type; | ||||
|             Folder.FolderName = folderName; | ||||
|             InventoryFolders.Add(Folder.FolderID, Folder); | ||||
|             return (true); | ||||
|         } | ||||
| 
 | ||||
|         public bool CreateNewFolder(LLUUID folderID, ushort type, string folderName, LLUUID parentID) | ||||
|         { | ||||
|             if (!InventoryFolders.ContainsKey(folderID)) | ||||
|             { | ||||
|                 System.Console.WriteLine("creating new folder called " + folderName + " in agents inventory"); | ||||
|                 InventoryFolder Folder = new InventoryFolder(); | ||||
|                 Folder.FolderID = folderID; | ||||
|                 Folder.OwnerID = AgentID; | ||||
|                 Folder.DefaultType = type; | ||||
|                 Folder.FolderName = folderName; | ||||
|                 Folder.ParentID = parentID; | ||||
|                 InventoryFolders.Add(Folder.FolderID, Folder); | ||||
|             } | ||||
|             return (true); | ||||
|         } | ||||
| 
 | ||||
|         public bool HasFolder(LLUUID folderID) | ||||
|         { | ||||
|             if (InventoryFolders.ContainsKey(folderID)) | ||||
|             { | ||||
|                 return true; | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         public LLUUID GetFolderID(string folderName) | ||||
|         { | ||||
|             foreach (InventoryFolder inv in InventoryFolders.Values) | ||||
|             { | ||||
|                 if (inv.FolderName == folderName) | ||||
|                 { | ||||
|                     return inv.FolderID; | ||||
|                 } | ||||
|             } | ||||
|             return LLUUID.Zero; | ||||
|         } | ||||
| 
 | ||||
|         public bool UpdateItemAsset(LLUUID itemID, AssetBase asset) | ||||
|         { | ||||
|             if (InventoryItems.ContainsKey(itemID)) | ||||
|             { | ||||
|                 InventoryItem Item = InventoryItems[itemID]; | ||||
|                 Item.AssetID = asset.FullID; | ||||
|                 System.Console.WriteLine("updated inventory item " + itemID.ToString() + | ||||
|                                          " so it now is set to asset " + asset.FullID.ToString()); | ||||
|                 //TODO need to update the rest of the info | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public bool UpdateItemDetails(LLUUID itemID, UpdateInventoryItemPacket.InventoryDataBlock packet) | ||||
|         { | ||||
|             System.Console.WriteLine("updating inventory item details"); | ||||
|             if (InventoryItems.ContainsKey(itemID)) | ||||
|             { | ||||
|                 System.Console.WriteLine("changing name to " + Util.FieldToString(packet.Name)); | ||||
|                 InventoryItem Item = InventoryItems[itemID]; | ||||
|                 Item.Name = Util.FieldToString(packet.Name); | ||||
|                 System.Console.WriteLine("updated inventory item " + itemID.ToString()); | ||||
|                 //TODO need to update the rest of the info | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public LLUUID AddToInventory(LLUUID folderID, AssetBase asset) | ||||
|         { | ||||
|             if (InventoryFolders.ContainsKey(folderID)) | ||||
|             { | ||||
|                 LLUUID NewItemID = LLUUID.Random(); | ||||
| 
 | ||||
|                 InventoryItem Item = new InventoryItem(); | ||||
|                 Item.FolderID = folderID; | ||||
|                 Item.OwnerID = AgentID; | ||||
|                 Item.AssetID = asset.FullID; | ||||
|                 Item.ItemID = NewItemID; | ||||
|                 Item.Type = asset.Type; | ||||
|                 Item.Name = asset.Name; | ||||
|                 Item.Description = asset.Description; | ||||
|                 Item.InvType = asset.InvType; | ||||
|                 InventoryItems.Add(Item.ItemID, Item); | ||||
|                 InventoryFolder Folder = InventoryFolders[Item.FolderID]; | ||||
|                 Folder.Items.Add(Item); | ||||
|                 return (Item.ItemID); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return (null); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool DeleteFromInventory(LLUUID itemID) | ||||
|         { | ||||
|             bool res = false; | ||||
|             if (InventoryItems.ContainsKey(itemID)) | ||||
|             { | ||||
|                 InventoryItem item = InventoryItems[itemID]; | ||||
|                 InventoryItems.Remove(itemID); | ||||
|                 foreach (InventoryFolder fold in InventoryFolders.Values) | ||||
|                 { | ||||
|                     if (fold.Items.Contains(item)) | ||||
|                     { | ||||
|                         fold.Items.Remove(item); | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|                 res = true; | ||||
|             } | ||||
|             return res; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public class InventoryFolder | ||||
|     { | ||||
|         public List<InventoryItem> Items; | ||||
|         //public List<InventoryFolder> Subfolders; | ||||
|         public LLUUID FolderID; | ||||
|         public LLUUID OwnerID; | ||||
|         public LLUUID ParentID = LLUUID.Zero; | ||||
|         public string FolderName; | ||||
|         public ushort DefaultType; | ||||
|         public ushort Version; | ||||
| 
 | ||||
|         public InventoryFolder() | ||||
|         { | ||||
|             Items = new List<InventoryItem>(); | ||||
|             //Subfolders = new List<InventoryFolder>(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public class InventoryItem | ||||
|     { | ||||
|         public LLUUID FolderID; | ||||
|         public LLUUID OwnerID; | ||||
|         public LLUUID ItemID; | ||||
|         public LLUUID AssetID; | ||||
|         public LLUUID CreatorID; | ||||
|         public sbyte InvType; | ||||
|         public sbyte Type; | ||||
|         public string Name = System.String.Empty; | ||||
|         public string Description; | ||||
| 
 | ||||
|         public InventoryItem() | ||||
|         { | ||||
|             CreatorID = LLUUID.Zero; | ||||
|         } | ||||
| 
 | ||||
|         public string ExportString() | ||||
|         { | ||||
|             string typ = "notecard"; | ||||
|             string result = System.String.Empty; | ||||
|             result += "\tinv_object\t0\n\t{\n"; | ||||
|             result += "\t\tobj_id\t%s\n"; | ||||
|             result += "\t\tparent_id\t" + ItemID.ToString() + "\n"; | ||||
|             result += "\t\ttype\t" + typ + "\n"; | ||||
|             result += "\t\tname\t" + Name + "|\n"; | ||||
|             result += "\t}\n"; | ||||
|             return result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,64 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following  | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("OpenSim.FrameWork")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly : AssemblyConfiguration("")] | ||||
| [assembly : AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("OpenSim.FrameWork")] | ||||
| [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")] | ||||
| [assembly : AssemblyTrademark("")] | ||||
| [assembly : AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible  | ||||
| // to COM components.  If you need to access a type in this assembly from  | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| 
 | ||||
| [assembly : Guid("a08e20c7-f191-4137-b1f0-9291408fa521")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version  | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.0.0")] | ||||
| [assembly : AssemblyFileVersion("1.0.0.0")] | ||||
|  | @ -0,0 +1,55 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     [Serializable] | ||||
|     public class AssetBase | ||||
|     { | ||||
|         public byte[] Data; | ||||
|         public LLUUID FullID; | ||||
|         public sbyte Type; | ||||
|         public sbyte InvType; | ||||
|         public string Name = String.Empty; | ||||
|         public string Description = String.Empty; | ||||
|         public bool Local = false; | ||||
|         public bool Temporary = false; | ||||
| 
 | ||||
|         public AssetBase() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public AssetBase(LLUUID assetId, string name) | ||||
|         { | ||||
|             FullID = assetId; | ||||
|             Name = name; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,86 @@ | |||
| /* | ||||
| * 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 OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     /// <summary> | ||||
|     /// UserConfig -- For User Server Configuration | ||||
|     /// </summary> | ||||
|     public class AssetConfig | ||||
|     { | ||||
|         public string DefaultStartupMsg = String.Empty; | ||||
| 
 | ||||
|         public string DatabaseProvider = String.Empty; | ||||
| 
 | ||||
|         public static uint DefaultHttpPort = 8003; | ||||
|         public uint HttpPort = DefaultHttpPort; | ||||
| 
 | ||||
|         private ConfigurationMember configMember; | ||||
| 
 | ||||
|         public AssetConfig(string description, string filename) | ||||
|         { | ||||
|             configMember = | ||||
|                 new ConfigurationMember(filename, description, loadConfigurationOptions, handleIncomingConfiguration, true); | ||||
|             configMember.performConfigurationRetrieve(); | ||||
|         } | ||||
| 
 | ||||
|         public void loadConfigurationOptions() | ||||
|         { | ||||
|             configMember.addConfigurationOption("default_startup_message", | ||||
|                                                 ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, | ||||
|                                                 "Default Startup Message", "Welcome to OGS", false); | ||||
| 
 | ||||
|             configMember.addConfigurationOption("database_provider", ConfigurationOption.ConfigurationTypes.TYPE_STRING, | ||||
|                                                 "DLL for database provider", "OpenSim.Framework.Data.MySQL.dll", false); | ||||
| 
 | ||||
|             configMember.addConfigurationOption("http_port", ConfigurationOption.ConfigurationTypes.TYPE_UINT32, | ||||
|                                                 "Http Listener port", DefaultHttpPort.ToString(), false); | ||||
|         } | ||||
| 
 | ||||
|         public bool handleIncomingConfiguration(string configuration_key, object configuration_result) | ||||
|         { | ||||
|             switch (configuration_key) | ||||
|             { | ||||
|                 case "default_startup_message": | ||||
|                     DefaultStartupMsg = (string) configuration_result; | ||||
|                     break; | ||||
|                 case "database_provider": | ||||
|                     DatabaseProvider = (string) configuration_result; | ||||
|                     break; | ||||
|                 case "http_port": | ||||
|                     HttpPort = (uint) configuration_result; | ||||
|                     break; | ||||
|             } | ||||
| 
 | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,59 @@ | |||
| /* | ||||
| * 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.Text; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AssetLandmark : AssetBase | ||||
|     { | ||||
|         public int Version; | ||||
|         public LLVector3 Position; | ||||
|         public LLUUID RegionID; | ||||
| 
 | ||||
|         public AssetLandmark(AssetBase a) | ||||
|         { | ||||
|             Data = a.Data; | ||||
|             FullID = a.FullID; | ||||
|             Type = a.Type; | ||||
|             InvType = a.InvType; | ||||
|             Name = a.Name; | ||||
|             Description = a.Description; | ||||
|             InternData(); | ||||
|         } | ||||
| 
 | ||||
|         private void InternData() | ||||
|         { | ||||
|             string temp = Encoding.UTF8.GetString(Data).Trim(); | ||||
|             string[] parts = temp.Split('\n'); | ||||
|             int.TryParse(parts[0].Substring(17, 1), out Version); | ||||
|             LLUUID.TryParse(parts[1].Substring(10, 36), out RegionID); | ||||
|             LLVector3.TryParse(parts[2].Substring(11, parts[2].Length - 11), out Position); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,164 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.IO; | ||||
| using System.Xml; | ||||
| 
 | ||||
| using libsecondlife; | ||||
| using Nini.Config; | ||||
| 
 | ||||
| using OpenSim.Framework; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| /// <summary> | ||||
| /// Loads assets from the filesystem location.  Not yet a plugin, though it should be. | ||||
| /// </summary> | ||||
| namespace OpenSim.Framework.AssetLoader.Filesystem | ||||
| {  | ||||
|     public class AssetLoaderFileSystem : IAssetLoader | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         protected AssetBase CreateAsset(string assetIdStr, string name, string path, bool isImage) | ||||
|         { | ||||
|             AssetBase asset = new AssetBase( | ||||
|                 new LLUUID(assetIdStr), | ||||
|                 name | ||||
|                 ); | ||||
| 
 | ||||
|             if (!String.IsNullOrEmpty(path)) | ||||
|             { | ||||
|                 m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path); | ||||
| 
 | ||||
|                 LoadAsset(asset, isImage, path); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.InfoFormat("[ASSETS]: Instantiated: [{0}]", name); | ||||
|             } | ||||
| 
 | ||||
|             return asset; | ||||
|         } | ||||
|          | ||||
|         protected void LoadAsset(AssetBase info, bool image, string path) | ||||
|         { | ||||
|             FileInfo fInfo = new FileInfo(path); | ||||
|             long numBytes = fInfo.Length; | ||||
|             FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read); | ||||
|             byte[] idata = new byte[numBytes]; | ||||
|             BinaryReader br = new BinaryReader(fStream); | ||||
|             idata = br.ReadBytes((int) numBytes); | ||||
|             br.Close(); | ||||
|             fStream.Close(); | ||||
|             info.Data = idata; | ||||
|             //info.loaded=true; | ||||
|         } | ||||
|          | ||||
|         public void ForEachDefaultXmlAsset(Action<AssetBase> action) | ||||
|         { | ||||
|             string assetSetFilename = Path.Combine(Util.assetsDir(), "AssetSets.xml"); | ||||
| 
 | ||||
|             ForEachDefaultXmlAsset(assetSetFilename, action); | ||||
|         } | ||||
| 
 | ||||
|         public void ForEachDefaultXmlAsset(string assetSetFilename, Action<AssetBase> action) | ||||
|         { | ||||
|             List<AssetBase> assets = new List<AssetBase>(); | ||||
|             if (File.Exists(assetSetFilename)) | ||||
|             { | ||||
|                 string assetSetPath = "ERROR"; | ||||
|                  | ||||
|                 try | ||||
|                 { | ||||
|                     XmlConfigSource source = new XmlConfigSource(assetSetFilename); | ||||
|                      | ||||
|                     for (int i = 0; i < source.Configs.Count; i++) | ||||
|                     { | ||||
|                         assetSetPath = source.Configs[i].GetString("file", String.Empty); | ||||
|                          | ||||
|                         LoadXmlAssetSet(Path.Combine(Util.assetsDir(), assetSetPath), assets); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (XmlException e) | ||||
|                 { | ||||
|                     m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); | ||||
|                 }                 | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.Error("[ASSETS]: Asset set control file assets/AssetSets.xml does not exist!  No assets loaded."); | ||||
|             } | ||||
|                                          | ||||
|             assets.ForEach(action); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Use the asset set information at path to load assets | ||||
|         /// </summary> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="assets"></param> | ||||
|         protected void LoadXmlAssetSet(string assetSetPath, List<AssetBase> assets) | ||||
|         { | ||||
|             m_log.InfoFormat("[ASSETS]: Loading asset set {0}", assetSetPath); | ||||
|              | ||||
|             if (File.Exists(assetSetPath)) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     XmlConfigSource source = new XmlConfigSource(assetSetPath); | ||||
|                     String dir = Path.GetDirectoryName(assetSetPath); | ||||
| 
 | ||||
|                     for (int i = 0; i < source.Configs.Count; i++) | ||||
|                     { | ||||
|                         string assetIdStr = source.Configs[i].GetString("assetID", LLUUID.Random().ToString()); | ||||
|                         string name = source.Configs[i].GetString("name", String.Empty); | ||||
|                         sbyte type = (sbyte) source.Configs[i].GetInt("assetType", 0); | ||||
|                         sbyte invType = (sbyte) source.Configs[i].GetInt("inventoryType", 0); | ||||
|                         string assetPath = Path.Combine(dir, source.Configs[i].GetString("fileName", String.Empty)); | ||||
| 
 | ||||
|                         AssetBase newAsset = CreateAsset(assetIdStr, name, assetPath, false); | ||||
| 
 | ||||
|                         newAsset.Type = type; | ||||
|                         newAsset.InvType = invType; | ||||
|                         assets.Add(newAsset); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (XmlException e) | ||||
|                 { | ||||
|                     m_log.ErrorFormat("[ASSETS]: Error loading {0} : {1}", assetSetPath, e); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.ErrorFormat("[ASSETS]: Asset set file {0} does not exist!", assetSetPath); | ||||
|             } | ||||
|         }         | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,38 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public struct AssetRequest | ||||
|     { | ||||
|         public LLUUID AssetID; | ||||
|         public bool IsTexture; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,48 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AssetStorage | ||||
|     { | ||||
|         public AssetStorage() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public AssetStorage(LLUUID assetUUID) | ||||
|         { | ||||
|             UUID = assetUUID; | ||||
|         } | ||||
| 
 | ||||
|         public byte[] Data; | ||||
|         public sbyte Type; | ||||
|         public string Name; | ||||
|         public LLUUID UUID; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,39 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AuthenticateResponse | ||||
|     { | ||||
|         public bool Authorised; | ||||
|         public Login LoginInfo; | ||||
| 
 | ||||
|         public AuthenticateResponse() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,71 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class AvatarWearable | ||||
|     { | ||||
|         public LLUUID AssetID = new LLUUID("00000000-0000-0000-0000-000000000000"); | ||||
|         public LLUUID ItemID = new LLUUID("00000000-0000-0000-0000-000000000000"); | ||||
| 
 | ||||
|         public AvatarWearable() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public AvatarWearable(LLUUID itemId, LLUUID assetId) | ||||
|         { | ||||
|             AssetID = assetId; | ||||
|             ItemID = itemId; | ||||
|         } | ||||
| 
 | ||||
|         public static AvatarWearable[] DefaultWearables | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 AvatarWearable[] defaultWearables = new AvatarWearable[13]; //should be 13 of these | ||||
|                 for (int i = 0; i < 13; i++) | ||||
|                 { | ||||
|                     defaultWearables[i] = new AvatarWearable(); | ||||
|                 } | ||||
|                 defaultWearables[0].AssetID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"); | ||||
|                 defaultWearables[0].ItemID = new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"); | ||||
| 
 | ||||
|                 defaultWearables[1].ItemID = new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"); | ||||
|                 defaultWearables[1].AssetID = new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"); | ||||
| 
 | ||||
|                 defaultWearables[4].ItemID = new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"); | ||||
|                 defaultWearables[4].AssetID = new LLUUID("00000000-38f9-1111-024e-222222111110"); | ||||
| 
 | ||||
|                 defaultWearables[5].ItemID = new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"); | ||||
|                 defaultWearables[5].AssetID = new LLUUID("00000000-38f9-1111-024e-222222111120"); | ||||
|                 return defaultWearables; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,73 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using System.Threading; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class BlockingQueue<T> | ||||
|     { | ||||
|         private readonly Queue<T> m_queue = new Queue<T>(); | ||||
|         private readonly object m_queueSync = new object(); | ||||
| 
 | ||||
|         public void Enqueue(T value) | ||||
|         { | ||||
|             lock (m_queueSync) | ||||
|             { | ||||
|                 m_queue.Enqueue(value); | ||||
|                 Monitor.Pulse(m_queueSync); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public T Dequeue() | ||||
|         { | ||||
|             lock (m_queueSync) | ||||
|             { | ||||
|                 if (m_queue.Count < 1) | ||||
|                 { | ||||
|                     Monitor.Wait(m_queueSync); | ||||
|                 } | ||||
| 
 | ||||
|                 return m_queue.Dequeue(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool Contains(T item) | ||||
|         { | ||||
|             lock (m_queueSync) | ||||
|             { | ||||
|                 return m_queue.Contains(item); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         public int Count() | ||||
|         { | ||||
|             return m_queue.Count; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,53 @@ | |||
| /* | ||||
| * 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; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     [Serializable] | ||||
|     public class ChildAgentDataUpdate | ||||
|     { | ||||
|         public ChildAgentDataUpdate() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public sLLVector3 Position; | ||||
|         public ulong regionHandle; | ||||
|         public float drawdistance; | ||||
|         public sLLVector3 cameraPosition; | ||||
|         public sLLVector3 Velocity; | ||||
|         public float AVHeight; | ||||
|         public Guid AgentID; | ||||
|         public float godlevel; | ||||
|         public byte[] throttles; | ||||
|         public bool alwaysrun; | ||||
|         public Guid ActiveGroupID; | ||||
|         public uint GroupAccess; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,182 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using libsecondlife; | ||||
| using libsecondlife.Packets; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public delegate void ForEachClientDelegate(IClientAPI client); | ||||
| 
 | ||||
|     public class ClientManager | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private Dictionary<uint, IClientAPI> m_clients; | ||||
| 
 | ||||
|         public void ForEachClient(ForEachClientDelegate whatToDo) | ||||
|         { | ||||
|             // Wasteful, I know | ||||
|             IClientAPI[] LocalClients = new IClientAPI[0]; | ||||
|             lock (m_clients) | ||||
|             { | ||||
|                 LocalClients = new IClientAPI[m_clients.Count]; | ||||
|                 m_clients.Values.CopyTo(LocalClients, 0); | ||||
|             } | ||||
| 
 | ||||
|             for (int i = 0; i < LocalClients.Length; i++) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     whatToDo(LocalClients[i]); | ||||
|                 } | ||||
|                 catch (System.Exception e) | ||||
|                 { | ||||
|                     m_log.Warn("[CLIENT]: Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public ClientManager() | ||||
|         { | ||||
|             m_clients = new Dictionary<uint, IClientAPI>(); | ||||
|         } | ||||
| 
 | ||||
|         public void Remove(uint id) | ||||
|         { | ||||
|             //m_log.InfoFormat("[CLIENT]: Removing client with code {0}, current count {1}", id, m_clients.Count);             | ||||
|             m_clients.Remove(id); | ||||
|             m_log.InfoFormat("[CLIENT]: Removed client with code {0}, new client count {1}", id, m_clients.Count); | ||||
|         } | ||||
| 
 | ||||
|         public void Add(uint id, IClientAPI client) | ||||
|         { | ||||
|             m_clients.Add(id, client); | ||||
|         } | ||||
| 
 | ||||
|         public void InPacket(uint circuitCode, Packet packet) | ||||
|         { | ||||
|             IClientAPI client; | ||||
| 
 | ||||
|             if (m_clients.TryGetValue(circuitCode, out client)) | ||||
|             { | ||||
|                 client.InPacket(packet); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void CloseAllAgents(uint circuitCode) | ||||
|         { | ||||
|             IClientAPI client; | ||||
| 
 | ||||
|             if (m_clients.TryGetValue(circuitCode, out client)) | ||||
|             { | ||||
|                 CloseAllCircuits(client.AgentId); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void CloseAllCircuits(LLUUID agentId) | ||||
|         { | ||||
|             uint[] circuits = GetAllCircuits(agentId); | ||||
|             // We're using a for loop here so changes to the circuits don't cause it to completely fail. | ||||
| 
 | ||||
|             for (int i = 0; i < circuits.Length; i++) | ||||
|             { | ||||
|                 IClientAPI client; | ||||
|                 try | ||||
|                 { | ||||
| 
 | ||||
|                     if (m_clients.TryGetValue(circuits[i], out client)) | ||||
|                     { | ||||
|                         Remove(client.CircuitCode); | ||||
|                         client.Close(false); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (System.Exception e) | ||||
|                 { | ||||
|                     m_log.Error(string.Format("[CLIENT]: Unable to shutdown circuit for: {0}\n Reason: {1}", agentId, e)); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private uint[] GetAllCircuits(LLUUID agentId) | ||||
|         { | ||||
|             List<uint> circuits = new List<uint>(); | ||||
|             // Wasteful, I know | ||||
|             IClientAPI[] LocalClients = new IClientAPI[0]; | ||||
|             lock (m_clients) | ||||
|             { | ||||
|                 LocalClients = new IClientAPI[m_clients.Count]; | ||||
|                 m_clients.Values.CopyTo(LocalClients, 0); | ||||
|             } | ||||
| 
 | ||||
|             for (int i = 0; i < LocalClients.Length; i++ ) | ||||
|             { | ||||
|                 if (LocalClients[i].AgentId == agentId) | ||||
|                 { | ||||
|                     circuits.Add(LocalClients[i].CircuitCode); | ||||
|                 } | ||||
|             } | ||||
|             return circuits.ToArray(); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void ViewerEffectHandler(IClientAPI sender, ViewerEffectPacket.EffectBlock[] effectBlock) | ||||
|         { | ||||
|             ViewerEffectPacket packet = (ViewerEffectPacket)  PacketPool.Instance.GetPacket(PacketType.ViewerEffect); | ||||
|             // TODO: don't create new blocks if recycling an old packet | ||||
|             packet.Effect = effectBlock; | ||||
| 
 | ||||
|             // Wasteful, I know | ||||
|             IClientAPI[] LocalClients = new IClientAPI[0]; | ||||
|             lock (m_clients) | ||||
|             { | ||||
|                 LocalClients = new IClientAPI[m_clients.Count]; | ||||
|                 m_clients.Values.CopyTo(LocalClients, 0); | ||||
|             } | ||||
| 
 | ||||
|             for (int i = 0; i < LocalClients.Length; i++) | ||||
|             { | ||||
|                 if (LocalClients[i].AgentId != sender.AgentId) | ||||
|                 { | ||||
|                     packet.AgentData.AgentID = LocalClients[i].AgentId; | ||||
|                     packet.AgentData.SessionID = LocalClients[i].SessionId; | ||||
|                     packet.Header.Reliable = false; | ||||
|                     LocalClients[i].OutPacket(packet, ThrottleOutPacketType.Task); | ||||
|                 } | ||||
| 
 | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool TryGetClient(uint circuitId, out IClientAPI user) | ||||
|         { | ||||
|             return m_clients.TryGetValue(circuitId, out user); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,54 @@ | |||
| /* | ||||
| * 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 OpenSim.Framework.Servers; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public class CAPSService | ||||
|     { | ||||
|         private readonly BaseHttpServer m_server; | ||||
| 
 | ||||
|         public CAPSService(BaseHttpServer httpServer) | ||||
|         { | ||||
|             m_server = httpServer; | ||||
|             AddCapsSeedHandler("/CapsSeed/", CapsRequest); | ||||
|         } | ||||
| 
 | ||||
|         private void AddCapsSeedHandler(string path, RestMethod restMethod) | ||||
|         { | ||||
|             m_server.AddStreamHandler(new RestStreamHandler("POST", path, restMethod)); | ||||
|         } | ||||
| 
 | ||||
|         public string CapsRequest(string request, string path, string param) | ||||
|         { | ||||
|             System.Console.WriteLine("new caps request " + request + " from path " + path); | ||||
|             return System.String.Empty; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,558 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| //moved to a module, left here until the module is found to have no problems | ||||
| /* | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.IO; | ||||
| using libsecondlife; | ||||
| using libsecondlife.Packets; | ||||
| using OpenSim.Framework.Servers; | ||||
| using OpenSim.Region.Capabilities; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Manage asset transactions for a single agent. | ||||
|     /// </summary> | ||||
|     public class AgentAssetTransactions | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log  | ||||
|             = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
|          | ||||
|         // Fields | ||||
|         public List<AssetCapsUploader> CapsUploaders = new List<AssetCapsUploader>(); | ||||
|         public List<NoteCardCapsUpdate> NotecardUpdaters = new List<NoteCardCapsUpdate>(); | ||||
|         public LLUUID UserID; | ||||
|         public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>(); | ||||
|         public AgentAssetTransactionsManager Manager; | ||||
|         private bool m_dumpAssetsToFile; | ||||
| 
 | ||||
|         // Methods | ||||
|         public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile) | ||||
|         { | ||||
|             UserID = agentID; | ||||
|             Manager = manager; | ||||
|             m_dumpAssetsToFile = dumpAssetsToFile; | ||||
|         } | ||||
| 
 | ||||
|         public AssetCapsUploader RequestCapsUploader() | ||||
|         { | ||||
|             AssetCapsUploader uploader = new AssetCapsUploader(); | ||||
|             CapsUploaders.Add(uploader); | ||||
|             return uploader; | ||||
|         } | ||||
| 
 | ||||
|         public NoteCardCapsUpdate RequestNoteCardUpdater() | ||||
|         { | ||||
|             NoteCardCapsUpdate update = new NoteCardCapsUpdate(); | ||||
|             NotecardUpdaters.Add(update); | ||||
|             return update; | ||||
|         } | ||||
| 
 | ||||
|         public AssetXferUploader RequestXferUploader(LLUUID transactionID) | ||||
|         { | ||||
|             if (!XferUploaders.ContainsKey(transactionID)) | ||||
|             { | ||||
|                 AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile); | ||||
| 
 | ||||
|                 lock (XferUploaders) | ||||
|                 { | ||||
|                     XferUploaders.Add(transactionID, uploader); | ||||
|                 } | ||||
|                  | ||||
|                 return uploader; | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         public void HandleXfer(ulong xferID, uint packetID, byte[] data) | ||||
|         { | ||||
|             AssetXferUploader uploaderFound = null; | ||||
|              | ||||
|             lock (XferUploaders) | ||||
|             { | ||||
|                 foreach (AssetXferUploader uploader in XferUploaders.Values) | ||||
|                 { | ||||
|                     if (uploader.XferID == xferID) | ||||
|                     { | ||||
|                         if (uploader.HandleXferPacket(xferID, packetID, data)) | ||||
|                         { | ||||
|                             uploaderFound = uploader; | ||||
|                         } | ||||
|                          | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|                  | ||||
|                 // Remove the uploader once the uploader is complete  | ||||
|                 //[don't think we can be sure a upload has finished from here, uploads are multi part things] | ||||
|                 // [or maybe we can if we do more checking like data lenght checks] | ||||
|                 if (uploaderFound != null) | ||||
|                 {                 | ||||
| //                    m_log.InfoFormat( | ||||
| //                        "[ASSET TRANSACTIONS] Removing asset xfer uploader with transfer id {0}, transaction {1}",  | ||||
| //                        xferID, uploaderFound.TransactionID);                 | ||||
|                      | ||||
|    //                 XferUploaders.Remove(uploaderFound.TransactionID); | ||||
|                      | ||||
|                     //m_log.InfoFormat("[ASSET TRANSACTIONS] Current uploaders: {0}", XferUploaders.Count);                 | ||||
|                 }             | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | ||||
|                                                uint callbackID, string description, string name, sbyte invType, | ||||
|                                                sbyte type, byte wearableType, uint nextOwnerMask) | ||||
|         { | ||||
|             if (XferUploaders.ContainsKey(transactionID)) | ||||
|             { | ||||
|                 XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID, | ||||
|                                                                         callbackID, description, name, invType, type, | ||||
|                                                                         wearableType, nextOwnerMask); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,  | ||||
|                                                InventoryItemBase item) | ||||
|         { | ||||
|             if (XferUploaders.ContainsKey(transactionID)) | ||||
|             { | ||||
|                 XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item); | ||||
|             } | ||||
|         }         | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Get an uploaded asset.  If the data is successfully retrieved, the transaction will be removed. | ||||
|         /// </summary> | ||||
|         /// <param name="transactionID"></param> | ||||
|         /// <returns>The asset if the upload has completed, null if it has not.</returns> | ||||
|         public AssetBase GetTransactionAsset(LLUUID transactionID) | ||||
|         { | ||||
|             if (XferUploaders.ContainsKey(transactionID)) | ||||
|             { | ||||
|                 AssetXferUploader uploader = XferUploaders[transactionID]; | ||||
|                 AssetBase asset = uploader.GetAssetData(); | ||||
|                  | ||||
|                 lock (XferUploaders) | ||||
|                 { | ||||
|                     XferUploaders.Remove(transactionID); | ||||
|                 } | ||||
|                  | ||||
|                 return asset; | ||||
|             } | ||||
|              | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // Nested Types | ||||
|         public class AssetXferUploader | ||||
|         { | ||||
|             // Fields | ||||
|             public bool AddToInventory; | ||||
|             public AssetBase Asset; | ||||
|             public LLUUID InventFolder = LLUUID.Zero; | ||||
|             private IClientAPI ourClient; | ||||
|             public LLUUID TransactionID = LLUUID.Zero; | ||||
|             public bool UploadComplete; | ||||
|             public ulong XferID; | ||||
|             private string m_name = String.Empty; | ||||
|             private string m_description = String.Empty; | ||||
|             private sbyte type = 0; | ||||
|             private sbyte invType = 0; | ||||
|             private uint nextPerm = 0; | ||||
|             private bool m_finished = false; | ||||
|             private bool m_createItem = false; | ||||
|             private AgentAssetTransactions m_userTransactions; | ||||
|             private bool m_storeLocal; | ||||
|             private bool m_dumpAssetToFile; | ||||
| 
 | ||||
|             public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile) | ||||
|             { | ||||
|                 m_userTransactions = transactions; | ||||
|                 m_dumpAssetToFile = dumpAssetToFile; | ||||
|             } | ||||
| 
 | ||||
|             /// <summary> | ||||
|             /// Process transfer data received from the client. | ||||
|             /// </summary> | ||||
|             /// <param name="xferID"></param> | ||||
|             /// <param name="packetID"></param> | ||||
|             /// <param name="data"></param> | ||||
|             /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> | ||||
|             public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) | ||||
|             { | ||||
|                 if (XferID == xferID) | ||||
|                 { | ||||
|                     if (Asset.Data.Length > 1) | ||||
|                     { | ||||
|                         byte[] destinationArray = new byte[Asset.Data.Length + data.Length]; | ||||
|                         Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length); | ||||
|                         Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length); | ||||
|                         Asset.Data = destinationArray; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         byte[] buffer2 = new byte[data.Length - 4]; | ||||
|                         Array.Copy(data, 4, buffer2, 0, data.Length - 4); | ||||
|                         Asset.Data = buffer2; | ||||
|                     } | ||||
|                     ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket(); | ||||
|                     newPack.XferID.ID = xferID; | ||||
|                     newPack.XferID.Packet = packetID; | ||||
|                     ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | ||||
|                     if ((packetID & 0x80000000) != 0) | ||||
|                     { | ||||
|                         SendCompleteMessage(); | ||||
|                         return true; | ||||
|                     } | ||||
|                 } | ||||
|                  | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             /// <summary> | ||||
|             /// Initialise asset transfer from the client | ||||
|             /// </summary> | ||||
|             /// <param name="xferID"></param> | ||||
|             /// <param name="packetID"></param> | ||||
|             /// <param name="data"></param> | ||||
|             /// <returns>True if the transfer is complete, false otherwise</returns>             | ||||
|             public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, | ||||
|                                    bool storeLocal, bool tempFile) | ||||
|             { | ||||
|                 ourClient = remoteClient; | ||||
|                 Asset = new AssetBase(); | ||||
|                 Asset.FullID = assetID; | ||||
|                 Asset.InvType = type; | ||||
|                 Asset.Type = type; | ||||
|                 Asset.Data = data; | ||||
|                 Asset.Name = "blank"; | ||||
|                 Asset.Description = "empty"; | ||||
|                 Asset.Local = storeLocal; | ||||
|                 Asset.Temporary = tempFile; | ||||
| 
 | ||||
|                 TransactionID = transaction; | ||||
|                 m_storeLocal = storeLocal; | ||||
|                 if (Asset.Data.Length > 2) | ||||
|                 { | ||||
|                     SendCompleteMessage(); | ||||
|                     return true; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     RequestStartXfer(); | ||||
|                 } | ||||
|                  | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             protected void RequestStartXfer() | ||||
|             { | ||||
|                 UploadComplete = false; | ||||
|                 XferID = Util.GetNextXferID(); | ||||
|                 RequestXferPacket newPack = new RequestXferPacket(); | ||||
|                 newPack.XferID.ID = XferID; | ||||
|                 newPack.XferID.VFileType = Asset.Type; | ||||
|                 newPack.XferID.VFileID = Asset.FullID; | ||||
|                 newPack.XferID.FilePath = 0; | ||||
|                 newPack.XferID.Filename = new byte[0]; | ||||
|                 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | ||||
|             } | ||||
| 
 | ||||
|             protected void SendCompleteMessage() | ||||
|             { | ||||
|                 UploadComplete = true; | ||||
|                 AssetUploadCompletePacket newPack = new AssetUploadCompletePacket(); | ||||
|                 newPack.AssetBlock.Type = Asset.Type; | ||||
|                 newPack.AssetBlock.Success = true; | ||||
|                 newPack.AssetBlock.UUID = Asset.FullID; | ||||
|                 ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | ||||
|                 m_finished = true; | ||||
|                 if (m_createItem) | ||||
|                 { | ||||
|                     DoCreateItem(); | ||||
|                 } | ||||
|                 else if (m_storeLocal) | ||||
|                 { | ||||
|                     m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(Asset); | ||||
|                 } | ||||
| 
 | ||||
|                 // Console.WriteLine("upload complete "+ this.TransactionID); | ||||
| 
 | ||||
|                 if (m_dumpAssetToFile) | ||||
|                 { | ||||
|                     DateTime now = DateTime.Now; | ||||
|                     string filename = | ||||
|                         String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, | ||||
|                                       now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type); | ||||
|                     SaveAssetToFile(filename, Asset.Data); | ||||
|                 } | ||||
|             } | ||||
|              | ||||
|             ///Left this in and commented in case there are unforseen issues | ||||
|             //private void SaveAssetToFile(string filename, byte[] data) | ||||
|             //{ | ||||
|             //    FileStream fs = File.Create(filename); | ||||
|             //    BinaryWriter bw = new BinaryWriter(fs); | ||||
|             //    bw.Write(data); | ||||
|             //    bw.Close(); | ||||
|             //    fs.Close(); | ||||
|             //} | ||||
|             private void SaveAssetToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 string assetPath = "UserAssets"; | ||||
|                 if (!Directory.Exists(assetPath)) | ||||
|                 { | ||||
|                     Directory.CreateDirectory(assetPath); | ||||
|                 } | ||||
|                 FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||||
|                 BinaryWriter bw = new BinaryWriter(fs); | ||||
|                 bw.Write(data); | ||||
|                 bw.Close(); | ||||
|                 fs.Close(); | ||||
|             } | ||||
| 
 | ||||
|             public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | ||||
|                                                    uint callbackID, string description, string name, sbyte invType, | ||||
|                                                    sbyte type, byte wearableType, uint nextOwnerMask) | ||||
|             { | ||||
|                 if (TransactionID == transactionID) | ||||
|                 { | ||||
|                     InventFolder = folderID; | ||||
|                     m_name = name; | ||||
|                     m_description = description; | ||||
|                     this.type = type; | ||||
|                     this.invType = invType; | ||||
|                     nextPerm = nextOwnerMask; | ||||
|                     Asset.Name = name; | ||||
|                     Asset.Description = description; | ||||
|                     Asset.Type = type; | ||||
|                     Asset.InvType = invType; | ||||
|                     m_createItem = true; | ||||
|                     if (m_finished) | ||||
|                     { | ||||
|                         DoCreateItem(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|                        | ||||
|             public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID,  | ||||
|                                                    InventoryItemBase item) | ||||
|             { | ||||
|                 if (TransactionID == transactionID) | ||||
|                 {             | ||||
|                     CachedUserInfo userInfo = | ||||
|                         m_userTransactions.Manager.CommsManager.UserProfileCacheService.GetUserDetails( | ||||
|                             remoteClient.AgentId); | ||||
|                      | ||||
|                     if (userInfo != null) | ||||
|                     {                     | ||||
|                         LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId); | ||||
|                          | ||||
|                         AssetBase asset | ||||
|                             = m_userTransactions.Manager.CommsManager.AssetCache.GetAsset( | ||||
|                                 assetID, (item.assetType == (int) AssetType.Texture ? true : false)); | ||||
|                          | ||||
|                         if (asset == null) | ||||
|                         { | ||||
|                             asset = m_userTransactions.GetTransactionAsset(transactionID); | ||||
|                         }                     | ||||
| 
 | ||||
|                         if (asset != null && asset.FullID == assetID) | ||||
|                         { | ||||
|                             asset.Name = item.inventoryName; | ||||
|                             asset.Description = item.inventoryDescription; | ||||
|                             asset.InvType = (sbyte) item.invType; | ||||
|                             asset.Type = (sbyte) item.assetType; | ||||
|                             item.assetID = asset.FullID; | ||||
| 
 | ||||
|                             m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(Asset); | ||||
|                         }       | ||||
|                          | ||||
|                         userInfo.UpdateItem(remoteClient.AgentId, item);                     | ||||
|                     }      | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             private void DoCreateItem() | ||||
|             { | ||||
|                 //really need to fix this call, if lbsa71 saw this he would die.  | ||||
|                 m_userTransactions.Manager.CommsManager.AssetCache.AddAsset(Asset); | ||||
|                 CachedUserInfo userInfo = | ||||
|                     m_userTransactions.Manager.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId); | ||||
|                 if (userInfo != null) | ||||
|                 { | ||||
|                     InventoryItemBase item = new InventoryItemBase(); | ||||
|                     item.avatarID = ourClient.AgentId; | ||||
|                     item.creatorsID = ourClient.AgentId; | ||||
|                     item.inventoryID = LLUUID.Random(); | ||||
|                     item.assetID = Asset.FullID; | ||||
|                     item.inventoryDescription = m_description; | ||||
|                     item.inventoryName = m_name; | ||||
|                     item.assetType = type; | ||||
|                     item.invType = invType; | ||||
|                     item.parentFolderID = InventFolder; | ||||
|                     item.inventoryBasePermissions = 2147483647; | ||||
|                     item.inventoryCurrentPermissions = 2147483647; | ||||
|                     item.inventoryNextPermissions = nextPerm; | ||||
| 
 | ||||
|                     userInfo.AddItem(ourClient.AgentId, item); | ||||
|                     ourClient.SendInventoryItemCreateUpdate(item); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             public AssetBase GetAssetData() | ||||
|             { | ||||
|                 if (m_finished) | ||||
|                 { | ||||
|                     return Asset; | ||||
|                 } | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #region Nested Classes currently not in use (waiting for them to be enabled) | ||||
| 
 | ||||
|         public class AssetCapsUploader | ||||
|         { | ||||
|             // Fields | ||||
|             private BaseHttpServer httpListener; | ||||
|             private LLUUID inventoryItemID; | ||||
|             private string m_assetDescription = String.Empty; | ||||
|             private string m_assetName = String.Empty; | ||||
|             private LLUUID m_folderID; | ||||
|             private LLUUID newAssetID; | ||||
|             private bool m_dumpImageToFile; | ||||
|             private string uploaderPath = String.Empty; | ||||
| 
 | ||||
|             // Events | ||||
|             public event UpLoadedAsset OnUpLoad; | ||||
| 
 | ||||
|             // Methods | ||||
|             public void Initialise(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, | ||||
|                                    LLUUID folderID, string path, BaseHttpServer httpServer, bool dumpImageToFile) | ||||
|             { | ||||
|                 m_assetName = assetName; | ||||
|                 m_assetDescription = assetDescription; | ||||
|                 m_folderID = folderID; | ||||
|                 newAssetID = assetID; | ||||
|                 inventoryItemID = inventoryItem; | ||||
|                 uploaderPath = path; | ||||
|                 httpListener = httpServer; | ||||
|                 m_dumpImageToFile = dumpImageToFile; | ||||
|             } | ||||
| 
 | ||||
|             private void SaveImageToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 FileStream output = File.Create(filename); | ||||
|                 BinaryWriter writer = new BinaryWriter(output); | ||||
|                 writer.Write(data); | ||||
|                 writer.Close(); | ||||
|                 output.Close(); | ||||
|             } | ||||
| 
 | ||||
|             public string uploaderCaps(byte[] data, string path, string param) | ||||
|             { | ||||
|                 LLUUID inventoryItemID = this.inventoryItemID; | ||||
|                 string text = String.Empty; | ||||
|                 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); | ||||
|                 complete.new_asset = newAssetID.ToString(); | ||||
|                 complete.new_inventory_item = inventoryItemID; | ||||
|                 complete.state = "complete"; | ||||
|                 text = LLSDHelpers.SerialiseLLSDReply(complete); | ||||
|                 httpListener.RemoveStreamHandler("POST", uploaderPath); | ||||
|                 if (m_dumpImageToFile) | ||||
|                 { | ||||
|                     SaveImageToFile(m_assetName + ".jp2", data); | ||||
|                 } | ||||
|                 if (OnUpLoad != null) | ||||
|                 { | ||||
|                     OnUpLoad(m_assetName, "description", newAssetID, inventoryItemID, LLUUID.Zero, data, String.Empty, String.Empty); | ||||
|                 } | ||||
|                 return text; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public class NoteCardCapsUpdate | ||||
|         { | ||||
|             // Fields | ||||
|             private BaseHttpServer httpListener; | ||||
|             private LLUUID inventoryItemID; | ||||
|             private string m_assetName = String.Empty; | ||||
|             private LLUUID newAssetID; | ||||
|             private bool SaveImages = false; | ||||
|             private string uploaderPath = String.Empty; | ||||
| 
 | ||||
|             // Events | ||||
|             public event UpLoadedAsset OnUpLoad; | ||||
| 
 | ||||
|             // Methods | ||||
|             public void Initialise(LLUUID inventoryItem, string path, BaseHttpServer httpServer) | ||||
|             { | ||||
|                 inventoryItemID = inventoryItem; | ||||
|                 uploaderPath = path; | ||||
|                 httpListener = httpServer; | ||||
|                 newAssetID = LLUUID.Random(); | ||||
|             } | ||||
| 
 | ||||
|             private void SaveImageToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 FileStream output = File.Create(filename); | ||||
|                 BinaryWriter writer = new BinaryWriter(output); | ||||
|                 writer.Write(data); | ||||
|                 writer.Close(); | ||||
|                 output.Close(); | ||||
|             } | ||||
| 
 | ||||
|             public string uploaderCaps(byte[] data, string path, string param) | ||||
|             { | ||||
|                 LLUUID inventoryItemID = this.inventoryItemID; | ||||
|                 string text = String.Empty; | ||||
|                 LLSDAssetUploadComplete complete = new LLSDAssetUploadComplete(); | ||||
|                 complete.new_asset = newAssetID.ToString(); | ||||
|                 complete.new_inventory_item = inventoryItemID; | ||||
|                 complete.state = "complete"; | ||||
|                 text = LLSDHelpers.SerialiseLLSDReply(complete); | ||||
|                 httpListener.RemoveStreamHandler("POST", uploaderPath); | ||||
|                 if (SaveImages) | ||||
|                 { | ||||
|                     SaveImageToFile(m_assetName + "notecard.txt", data); | ||||
|                 } | ||||
|                 if (OnUpLoad != null) | ||||
|                 { | ||||
|                     OnUpLoad(m_assetName, "description", newAssetID, inventoryItemID, LLUUID.Zero, data, String.Empty, String.Empty); | ||||
|                 } | ||||
|                 return text; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
| */ | ||||
|  | @ -0,0 +1,206 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| //moved to a module, left here until the module is found to have no problems | ||||
| /* | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| 
 | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Provider handlers for processing asset transactions originating from the agent.  This encompasses | ||||
|     /// clothing creation and update as well as asset uploads. | ||||
|     /// </summary> | ||||
|     public class AgentAssetTransactionsManager | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log  | ||||
|             = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
|          | ||||
|         // Fields | ||||
|         public CommunicationsManager CommsManager; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Each agent has its own singleton collection of transactions | ||||
|         /// </summary> | ||||
|         private Dictionary<LLUUID, AgentAssetTransactions> AgentTransactions = | ||||
|             new Dictionary<LLUUID, AgentAssetTransactions>(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Should we dump uploaded assets to the filesystem? | ||||
|         /// </summary> | ||||
|         private bool m_dumpAssetsToFile; | ||||
| 
 | ||||
|         public AgentAssetTransactionsManager(CommunicationsManager commsManager, bool dumpAssetsToFile) | ||||
|         { | ||||
|             CommsManager = commsManager; | ||||
|             m_dumpAssetsToFile = dumpAssetsToFile; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Get the collection of asset transactions for the given user.  If one does not already exist, it | ||||
|         /// is created. | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <returns></returns> | ||||
|         private AgentAssetTransactions GetUserTransactions(LLUUID userID) | ||||
|         { | ||||
|             lock (AgentTransactions) | ||||
|             { | ||||
|                 if (!AgentTransactions.ContainsKey(userID)) | ||||
|                 { | ||||
|                     AgentAssetTransactions transactions  | ||||
|                         = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile); | ||||
|                     AgentTransactions.Add(userID, transactions);   | ||||
|                 } | ||||
|                  | ||||
|                 return AgentTransactions[userID];                 | ||||
|             }             | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Remove the given agent asset transactions.  This should be called when a client is departing | ||||
|         /// from a scene (and hence won't be making any more transactions here). | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         public void RemoveAgentAssetTransactions(LLUUID userID) | ||||
|         { | ||||
|             m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID); | ||||
|              | ||||
|             lock (AgentTransactions) | ||||
|             { | ||||
|                 AgentTransactions.Remove(userID); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Create an inventory item from data that has been received through a transaction. | ||||
|         ///  | ||||
|         /// This is called when new clothing or body parts are created.  It may also be called in other | ||||
|         /// situations. | ||||
|         /// </summary> | ||||
|         /// <param name="remoteClient"></param> | ||||
|         /// <param name="transactionID"></param> | ||||
|         /// <param name="folderID"></param> | ||||
|         /// <param name="callbackID"></param> | ||||
|         /// <param name="description"></param> | ||||
|         /// <param name="name"></param> | ||||
|         /// <param name="invType"></param> | ||||
|         /// <param name="type"></param> | ||||
|         /// <param name="wearableType"></param> | ||||
|         /// <param name="nextOwnerMask"></param> | ||||
|         public void HandleItemCreationFromTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | ||||
|                                                       uint callbackID, string description, string name, sbyte invType, | ||||
|                                                       sbyte type, byte wearableType, uint nextOwnerMask) | ||||
|         { | ||||
|             m_log.DebugFormat( | ||||
|                 "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); | ||||
|              | ||||
|             AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||||
|              | ||||
|             transactions.RequestCreateInventoryItem( | ||||
|                 remoteClient, transactionID, folderID, callbackID, description, | ||||
|                 name, invType, type, wearableType, nextOwnerMask); | ||||
|         }   | ||||
|             | ||||
|         /// <summary> | ||||
|         /// Update an inventory item with data that has been received through a transaction. | ||||
|         ///  | ||||
|         /// This is called when clothing or body parts are updated (for instance, with new textures or  | ||||
|         /// colours).  It may also be called in other situations. | ||||
|         /// </summary> | ||||
|         /// <param name="remoteClient"></param> | ||||
|         /// <param name="transactionID"></param> | ||||
|         /// <param name="item"></param> | ||||
|         public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, LLUUID transactionID,  | ||||
|                                                     InventoryItemBase item) | ||||
|         { | ||||
|             m_log.DebugFormat( | ||||
|                 "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}",  | ||||
|                 item.inventoryName); | ||||
|              | ||||
|             AgentAssetTransactions transactions | ||||
|                 = CommsManager.TransactionsManager.GetUserTransactions(remoteClient.AgentId); | ||||
| 
 | ||||
|             transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);         | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Request that a client (agent) begin an asset transfer. | ||||
|         /// </summary> | ||||
|         /// <param name="remoteClient"></param> | ||||
|         /// <param name="assetID"></param> | ||||
|         /// <param name="transaction"></param> | ||||
|         /// <param name="type"></param> | ||||
|         /// <param name="data"></param></param> | ||||
|         /// <param name="tempFile"></param> | ||||
|         public void HandleUDPUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, | ||||
|                                            byte[] data, bool storeLocal, bool tempFile) | ||||
|         { | ||||
|             // Console.WriteLine("asset upload of " + assetID); | ||||
|             AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||||
| 
 | ||||
|             AgentAssetTransactions.AssetXferUploader uploader = transactions.RequestXferUploader(transaction); | ||||
|             if (uploader != null) | ||||
|             { | ||||
|                 // Upload has already compelted uploading... | ||||
|                  | ||||
|                 if (uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile)) | ||||
|                 { | ||||
|                     //[commenting out as this removal breaks uploads] | ||||
|                    /*lock (transactions.XferUploaders) | ||||
|                     { | ||||
|                        | ||||
|                         // XXX Weak ass way of doing this by directly manipulating this public dictionary, purely temporary | ||||
|                         transactions.XferUploaders.Remove(uploader.TransactionID); | ||||
|                          | ||||
|                         //m_log.InfoFormat("[ASSET TRANSACTIONS] Current uploaders: {0}", transactions.XferUploaders.Count);                         | ||||
|                     }*/ | ||||
|          /*       } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Handle asset transfer data packets received in response to the asset upload request in | ||||
|         /// HandleUDPUploadRequest() | ||||
|         /// </summary> | ||||
|         /// <param name="remoteClient"></param> | ||||
|         /// <param name="xferID"></param> | ||||
|         /// <param name="packetID"></param> | ||||
|         /// <param name="data"></param> | ||||
|         public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | ||||
|         { | ||||
|             AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||||
|              | ||||
|             transactions.HandleXfer(xferID, packetID, data); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| */ | ||||
|  | @ -0,0 +1,696 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Threading; | ||||
| using libsecondlife; | ||||
| using libsecondlife.Packets; | ||||
| 
 | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Statistics; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public delegate void AssetRequestCallback(LLUUID assetID, AssetBase asset); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Manages local cache of assets and their sending to viewers. | ||||
|     /// </summary> | ||||
|     public class AssetCache : IAssetReceiver | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public Dictionary<LLUUID, AssetInfo> Assets; | ||||
|         public Dictionary<LLUUID, TextureImage> Textures; | ||||
| 
 | ||||
|         public List<AssetRequest> AssetRequests; //assets ready to be sent to viewers | ||||
|         public List<AssetRequest> TextureRequests; //textures ready to be sent | ||||
| 
 | ||||
|         public Dictionary<LLUUID, AssetRequest> RequestedAssets; | ||||
|         //Assets requested from the asset server | ||||
| 
 | ||||
|         public Dictionary<LLUUID, AssetRequest> RequestedTextures; | ||||
|         //Textures requested from the asset server | ||||
| 
 | ||||
|         public Dictionary<LLUUID, AssetRequestsList> RequestLists; | ||||
| 
 | ||||
|         private readonly IAssetServer m_assetServer; | ||||
| 
 | ||||
|         private readonly Thread m_assetCacheThread; | ||||
| 
 | ||||
|         public void ShowState() | ||||
|         { | ||||
|             m_log.InfoFormat("Assets:{0}  Textures:{1}  AssetRequests:{2}  TextureRequests:{3}  RequestedAssets:{4}  RequestedTextures:{5}  RequestLists:{6}", | ||||
|                 Assets.Count, | ||||
|                 Textures.Count, | ||||
|                 AssetRequests.Count, | ||||
|                 TextureRequests.Count, | ||||
|                 RequestedAssets.Count, | ||||
|                 RequestedTextures.Count, | ||||
|                 RequestLists.Count); | ||||
| 
 | ||||
|             int temporaryImages = 0; | ||||
|             int temporaryAssets = 0; | ||||
| 
 | ||||
|             long imageBytes = 0; | ||||
|             long assetBytes = 0; | ||||
| 
 | ||||
|                  | ||||
|              | ||||
| 
 | ||||
|             foreach (TextureImage texture in Textures.Values) | ||||
|             { | ||||
|                 if (texture.Temporary) | ||||
|                 { | ||||
|                     temporaryImages++; | ||||
|                 } | ||||
| 
 | ||||
|                 imageBytes += texture.Data.GetLongLength(0); | ||||
|             } | ||||
| 
 | ||||
|             foreach (AssetInfo asset in Assets.Values) | ||||
|             { | ||||
|                 if (asset.Temporary) | ||||
|                 { | ||||
|                     temporaryAssets++; | ||||
|                 } | ||||
| 
 | ||||
|                 assetBytes += asset.Data.GetLongLength(0); | ||||
|             } | ||||
| 
 | ||||
|             m_log.InfoFormat("Temporary Images: {0}  Temporary Assets: {1}", | ||||
|                 temporaryImages, | ||||
|                 temporaryAssets); | ||||
| 
 | ||||
|             m_log.InfoFormat("Image data: {0}kb  Asset data: {1}kb", | ||||
|     imageBytes/1024, | ||||
|     assetBytes/1024); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         public void Clear() | ||||
|         { | ||||
|             m_log.Info("[ASSETSTORAGE]: Clearing Asset cache"); | ||||
|             Initialize(); | ||||
|         } | ||||
| 
 | ||||
|         private void Initialize() | ||||
|         { | ||||
|             Assets = new Dictionary<LLUUID, AssetInfo>(); | ||||
|             Textures = new Dictionary<LLUUID, TextureImage>(); | ||||
|             AssetRequests = new List<AssetRequest>(); //assets ready to be sent to viewers | ||||
|             TextureRequests = new List<AssetRequest>(); //textures ready to be sent | ||||
| 
 | ||||
|             RequestedAssets = new Dictionary<LLUUID, AssetRequest>(); | ||||
|             RequestedTextures = new Dictionary<LLUUID, AssetRequest>(); | ||||
|             RequestLists = new Dictionary<LLUUID, AssetRequestsList>(); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public AssetCache(IAssetServer assetServer) | ||||
|         { | ||||
|             m_log.Info("[ASSETSTORAGE]: Creating Asset cache"); | ||||
|             Initialize(); | ||||
| 
 | ||||
|             m_assetServer = assetServer; | ||||
|             m_assetServer.SetReceiver(this); | ||||
| 
 | ||||
| 
 | ||||
|             m_assetCacheThread = new Thread(new ThreadStart(RunAssetManager)); | ||||
|             m_assetCacheThread.IsBackground = true; | ||||
|             m_assetCacheThread.Start(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         public void RunAssetManager() | ||||
|         { | ||||
|             while (true) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     ProcessAssetQueue(); | ||||
|                     Thread.Sleep(500); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Error("[ASSETCACHE]: " + e.ToString()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Only get an asset if we already have it in the cache. | ||||
|         /// </summary> | ||||
|         /// <param name="assetID"></param></param> | ||||
|         /// <returns></returns> | ||||
|         private AssetBase GetCachedAsset(LLUUID assetID) | ||||
|         { | ||||
|             AssetBase asset = null; | ||||
|             if (Textures.ContainsKey(assetID)) | ||||
|             { | ||||
|                 asset = Textures[assetID]; | ||||
|             } | ||||
|             else if (Assets.ContainsKey(assetID)) | ||||
|             { | ||||
|                 asset = Assets[assetID]; | ||||
|             } | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
|         public void GetAsset(LLUUID assetID, AssetRequestCallback callback) | ||||
|         { | ||||
|             AssetBase asset = null; | ||||
|             if (Textures.ContainsKey(assetID)) | ||||
|             { | ||||
|                 asset = Textures[assetID]; | ||||
|             } | ||||
|             else if (Assets.ContainsKey(assetID)) | ||||
|             { | ||||
|                 asset = Assets[assetID]; | ||||
|             } | ||||
| 
 | ||||
|             if (asset != null) | ||||
|             { | ||||
|                 callback(assetID, asset); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 NewAssetRequest req = new NewAssetRequest(assetID, callback); | ||||
| 
 | ||||
|                 AssetRequestsList requestList; | ||||
| 
 | ||||
|                 lock (RequestLists) | ||||
|                 { | ||||
|                     if (RequestLists.TryGetValue(assetID, out requestList)) | ||||
|                     { | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         requestList = new AssetRequestsList(assetID); | ||||
|                         RequestLists.Add(assetID, requestList); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 requestList.Requests.Add(req); | ||||
|      | ||||
|                 m_assetServer.RequestAsset(assetID, false); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Get an asset.  If the asset isn't in the cache, a request will be made to the persistent store to | ||||
|         /// load it into the cache.   | ||||
|         ///  | ||||
|         /// XXX We'll keep polling the cache until we get the asset or we exceed | ||||
|         /// the allowed number of polls.  This isn't a very good way of doing things since a single thread | ||||
|         /// is processing inbound packets, so if the asset server is slow, we could block this for up to | ||||
|         /// the timeout period.  What we might want to do is register asynchronous callbacks on asset | ||||
|         /// receipt in the same manner as the nascent (but not yet active) TextureDownloadModule.  Of course, | ||||
|         /// a timeout before asset receipt usually isn't fatal, the operation will work on the retry when the | ||||
|         /// asset is much more likely to have made it into the cache. | ||||
|         /// </summary> | ||||
|         /// <param name="assetID"></param> | ||||
|         /// <param name="isTexture"></param> | ||||
|         /// <returns>null if the asset could not be retrieved</returns> | ||||
|         public AssetBase GetAsset(LLUUID assetID, bool isTexture) | ||||
|         { | ||||
|             // I'm not going over 3 seconds since this will be blocking processing of all the other inbound | ||||
|             // packets from the client. | ||||
|             int pollPeriod = 200; | ||||
|             int maxPolls = 15; | ||||
| 
 | ||||
|             AssetBase asset = GetCachedAsset(assetID); | ||||
|             if (asset != null) | ||||
|             { | ||||
|                 return asset; | ||||
|             } | ||||
| 
 | ||||
|             m_assetServer.RequestAsset(assetID, isTexture); | ||||
| 
 | ||||
|             do | ||||
|             { | ||||
|                 Thread.Sleep(pollPeriod); | ||||
| 
 | ||||
|                 asset = GetCachedAsset(assetID); | ||||
|                 if (asset != null) | ||||
|                 { | ||||
|                     return asset; | ||||
|                 } | ||||
|             } while (--maxPolls > 0); | ||||
| 
 | ||||
|             m_log.WarnFormat("[ASSETCACHE]: Asset {0} was not received before the retrieval timeout was reached", assetID.ToString()); | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Add an asset to both the persistent store and the cache. | ||||
|         /// </summary> | ||||
|         /// <param name="asset"></param> | ||||
|         public void AddAsset(AssetBase asset) | ||||
|         { | ||||
|             string temporary = asset.Temporary ? "temporary" : String.Empty; | ||||
|             string type = asset.Type == 0 ? "texture" : "asset"; | ||||
| 
 | ||||
|             string result = "Ignored"; | ||||
| 
 | ||||
|             if (asset.Type == 0) | ||||
|             { | ||||
|                 if (Textures.ContainsKey(asset.FullID)) | ||||
|                 { | ||||
|                     result = "Duplicate ignored."; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     TextureImage textur = new TextureImage(asset); | ||||
|                     Textures.Add(textur.FullID, textur); | ||||
| 
 | ||||
|                     if (StatsManager.SimExtraStats != null) | ||||
|                         StatsManager.SimExtraStats.AddTexture(textur); | ||||
| 
 | ||||
|                     if (asset.Temporary) | ||||
|                     { | ||||
|                         result = "Added to cache"; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         m_assetServer.StoreAndCommitAsset(asset); | ||||
|                         result = "Added to server"; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (Assets.ContainsKey(asset.FullID)) | ||||
|                 { | ||||
|                     result = "Duplicate ignored."; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     AssetInfo assetInf = new AssetInfo(asset); | ||||
|                     Assets.Add(assetInf.FullID, assetInf); | ||||
| 
 | ||||
|                     if (StatsManager.SimExtraStats != null) | ||||
|                         StatsManager.SimExtraStats.AddAsset(assetInf); | ||||
| 
 | ||||
|                     if (asset.Temporary) | ||||
|                     { | ||||
|                         result = "Added to cache"; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         m_assetServer.StoreAndCommitAsset(asset); | ||||
|                         result = "Added to server"; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             m_log.InfoFormat("[ASSETCACHE]: Adding {0} {1} [{2}]: {3}.", temporary, type, asset.FullID, result); | ||||
|         } | ||||
| 
 | ||||
|         public void DeleteAsset(LLUUID assetID) | ||||
|         { | ||||
|             //  this.m_assetServer.DeleteAsset(assetID); | ||||
| 
 | ||||
|             //Todo should delete it from memory too | ||||
|         } | ||||
| 
 | ||||
|         public AssetBase CopyAsset(LLUUID assetID) | ||||
|         { | ||||
|             AssetBase asset = GetCachedAsset(assetID); | ||||
|             if (asset == null) | ||||
|                 return null; | ||||
| 
 | ||||
|             asset.FullID = LLUUID.Random(); // TODO: check for conflicts | ||||
|             AddAsset(asset); | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
|         public void AssetReceived(AssetBase asset, bool IsTexture) | ||||
|         { | ||||
|             if (asset.FullID != LLUUID.Zero) // if it is set to zero then the asset wasn't found by the server | ||||
|             { | ||||
|                 //check if it is a texture or not | ||||
|                 //then add to the correct cache list | ||||
|                 //then check for waiting requests for this asset/texture (in the Requested lists) | ||||
|                 //and move those requests into the Requests list. | ||||
| 
 | ||||
|                 if (IsTexture) | ||||
|                 { | ||||
|                     //Console.WriteLine("asset received from asset server"); | ||||
| 
 | ||||
|                     TextureImage image = new TextureImage(asset); | ||||
|                     if (!Textures.ContainsKey(image.FullID)) | ||||
|                     { | ||||
|                         Textures.Add(image.FullID, image); | ||||
| 
 | ||||
|                         if (StatsManager.SimExtraStats != null) | ||||
|                             StatsManager.SimExtraStats.AddTexture(image); | ||||
| 
 | ||||
|                         if (RequestedTextures.ContainsKey(image.FullID)) | ||||
|                         { | ||||
|                             AssetRequest req = RequestedTextures[image.FullID]; | ||||
|                             req.ImageInfo = image; | ||||
| 
 | ||||
|                             req.NumPackets = CalculateNumPackets(image.Data); | ||||
| 
 | ||||
|                             RequestedTextures.Remove(image.FullID); | ||||
|                             TextureRequests.Add(req); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     AssetInfo assetInf = new AssetInfo(asset); | ||||
|                     if (!Assets.ContainsKey(assetInf.FullID)) | ||||
|                     { | ||||
|                         Assets.Add(assetInf.FullID, assetInf); | ||||
| 
 | ||||
|                         if (StatsManager.SimExtraStats != null) | ||||
|                             StatsManager.SimExtraStats.AddAsset(assetInf); | ||||
| 
 | ||||
|                         if (RequestedAssets.ContainsKey(assetInf.FullID)) | ||||
|                         { | ||||
|                             AssetRequest req = RequestedAssets[assetInf.FullID]; | ||||
|                             req.AssetInf = assetInf; | ||||
|                             req.NumPackets = CalculateNumPackets(assetInf.Data); | ||||
|                             RequestedAssets.Remove(assetInf.FullID); | ||||
|                             AssetRequests.Add(req); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (RequestLists.ContainsKey(asset.FullID)) | ||||
|                 { | ||||
|                     AssetRequestsList reqList = RequestLists[asset.FullID]; | ||||
|                     foreach (NewAssetRequest req in reqList.Requests) | ||||
|                     { | ||||
|                         req.Callback(asset.FullID, asset); | ||||
|                     } | ||||
| 
 | ||||
|                     lock (RequestLists) | ||||
|                     { | ||||
|                         RequestLists.Remove(asset.FullID); | ||||
|                         reqList.Requests.Clear(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void AssetNotFound(LLUUID assetID) | ||||
|         { | ||||
|             //if (this.RequestedTextures.ContainsKey(assetID)) | ||||
|             //{ | ||||
|             //    m_log.WarnFormat("[ASSET CACHE]: sending image not found for {0}", assetID); | ||||
|             //    AssetRequest req = this.RequestedTextures[assetID]; | ||||
|             //    ImageNotInDatabasePacket notFound = new ImageNotInDatabasePacket(); | ||||
|             //    notFound.ImageID.ID = assetID; | ||||
|             //    req.RequestUser.OutPacket(notFound); | ||||
|             //    this.RequestedTextures.Remove(assetID); | ||||
|             //} | ||||
|             //else | ||||
|             //{ | ||||
|             //    m_log.ErrorFormat("[ASSET CACHE]: Cound not send image not found for {0}", assetID); | ||||
|             //} | ||||
|         } | ||||
| 
 | ||||
|         private int CalculateNumPackets(byte[] data) | ||||
|         { | ||||
|             const uint m_maxPacketSize = 600; | ||||
|             int numPackets = 1; | ||||
| 
 | ||||
|             if (data.LongLength > m_maxPacketSize) | ||||
|             { | ||||
|                 // over max number of bytes so split up file | ||||
|                 long restData = data.LongLength - m_maxPacketSize; | ||||
|                 int restPackets = (int)((restData + m_maxPacketSize - 1) / m_maxPacketSize); | ||||
|                 numPackets += restPackets; | ||||
|             } | ||||
| 
 | ||||
|             return numPackets; | ||||
|         } | ||||
| 
 | ||||
|         #region Assets | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="userInfo"></param> | ||||
|         /// <param name="transferRequest"></param> | ||||
|         public void AddAssetRequest(IClientAPI userInfo, TransferRequestPacket transferRequest) | ||||
|         { | ||||
|             LLUUID requestID = null; | ||||
|             byte source = 2; | ||||
|             if (transferRequest.TransferInfo.SourceType == 2) | ||||
|             { | ||||
|                 //direct asset request | ||||
|                 requestID = new LLUUID(transferRequest.TransferInfo.Params, 0); | ||||
|             } | ||||
|             else if (transferRequest.TransferInfo.SourceType == 3) | ||||
|             { | ||||
|                 //inventory asset request | ||||
|                 requestID = new LLUUID(transferRequest.TransferInfo.Params, 80); | ||||
|                 source = 3; | ||||
|                 //Console.WriteLine("asset request " + requestID); | ||||
|             } | ||||
|             //check to see if asset is in local cache, if not we need to request it from asset server. | ||||
|             //Console.WriteLine("asset request " + requestID); | ||||
|             if (!Assets.ContainsKey(requestID)) | ||||
|             { | ||||
|                 //not found asset | ||||
|                 // so request from asset server | ||||
|                 if (!RequestedAssets.ContainsKey(requestID)) | ||||
|                 { | ||||
|                     AssetRequest request = new AssetRequest(); | ||||
|                     request.RequestUser = userInfo; | ||||
|                     request.RequestAssetID = requestID; | ||||
|                     request.TransferRequestID = transferRequest.TransferInfo.TransferID; | ||||
|                     request.AssetRequestSource = source; | ||||
|                     request.Params = transferRequest.TransferInfo.Params; | ||||
|                     RequestedAssets.Add(requestID, request); | ||||
|                     m_assetServer.RequestAsset(requestID, false); | ||||
|                 } | ||||
|                 return; | ||||
|             } | ||||
|             //it is in our cache  | ||||
|             AssetInfo asset = Assets[requestID]; | ||||
| 
 | ||||
|             // add to the AssetRequests list | ||||
|             AssetRequest req = new AssetRequest(); | ||||
|             req.RequestUser = userInfo; | ||||
|             req.RequestAssetID = requestID; | ||||
|             req.TransferRequestID = transferRequest.TransferInfo.TransferID; | ||||
|             req.AssetRequestSource = source; | ||||
|             req.Params = transferRequest.TransferInfo.Params; | ||||
|             req.AssetInf = asset; | ||||
|             req.NumPackets = CalculateNumPackets(asset.Data); | ||||
|             AssetRequests.Add(req); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         private void ProcessAssetQueue() | ||||
|         { | ||||
|             //should move the asset downloading to a module, like has been done with texture downloading | ||||
|             if (AssetRequests.Count == 0) | ||||
|             { | ||||
|                 //no requests waiting | ||||
|                 return; | ||||
|             } | ||||
|             // if less than 5, do all of them | ||||
|             int num = Math.Min(5, AssetRequests.Count); | ||||
| 
 | ||||
|             AssetRequest req; | ||||
|             for (int i = 0; i < num; i++) | ||||
|             { | ||||
|                 req = (AssetRequest)AssetRequests[i]; | ||||
|                 //Console.WriteLine("sending asset " + req.RequestAssetID); | ||||
|                 TransferInfoPacket Transfer = new TransferInfoPacket(); | ||||
|                 Transfer.TransferInfo.ChannelType = 2; | ||||
|                 Transfer.TransferInfo.Status = 0; | ||||
|                 Transfer.TransferInfo.TargetType = 0; | ||||
|                 if (req.AssetRequestSource == 2) | ||||
|                 { | ||||
|                     Transfer.TransferInfo.Params = new byte[20]; | ||||
|                     Array.Copy(req.RequestAssetID.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16); | ||||
|                     int assType = (int)req.AssetInf.Type; | ||||
|                     Array.Copy(Helpers.IntToBytes(assType), 0, Transfer.TransferInfo.Params, 16, 4); | ||||
|                 } | ||||
|                 else if (req.AssetRequestSource == 3) | ||||
|                 { | ||||
|                     Transfer.TransferInfo.Params = req.Params; | ||||
|                     // Transfer.TransferInfo.Params = new byte[100]; | ||||
|                     //Array.Copy(req.RequestUser.AgentId.GetBytes(), 0, Transfer.TransferInfo.Params, 0, 16); | ||||
|                     //Array.Copy(req.RequestUser.SessionId.GetBytes(), 0, Transfer.TransferInfo.Params, 16, 16); | ||||
|                 } | ||||
|                 Transfer.TransferInfo.Size = (int)req.AssetInf.Data.Length; | ||||
|                 Transfer.TransferInfo.TransferID = req.TransferRequestID; | ||||
|                 req.RequestUser.OutPacket(Transfer, ThrottleOutPacketType.Asset); | ||||
| 
 | ||||
|                 if (req.NumPackets == 1) | ||||
|                 { | ||||
|                     TransferPacketPacket TransferPacket = new TransferPacketPacket(); | ||||
|                     TransferPacket.TransferData.Packet = 0; | ||||
|                     TransferPacket.TransferData.ChannelType = 2; | ||||
|                     TransferPacket.TransferData.TransferID = req.TransferRequestID; | ||||
|                     TransferPacket.TransferData.Data = req.AssetInf.Data; | ||||
|                     TransferPacket.TransferData.Status = 1; | ||||
|                     req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     int processedLength = 0; | ||||
|                     // libsecondlife hardcodes 1500 as the maximum data chunk size | ||||
|                     int maxChunkSize = 1250; | ||||
|                     int packetNumber = 0; | ||||
| 
 | ||||
|                     while (processedLength < req.AssetInf.Data.Length) | ||||
|                     { | ||||
|                         TransferPacketPacket TransferPacket = new TransferPacketPacket(); | ||||
|                         TransferPacket.TransferData.Packet = packetNumber; | ||||
|                         TransferPacket.TransferData.ChannelType = 2; | ||||
|                         TransferPacket.TransferData.TransferID = req.TransferRequestID; | ||||
| 
 | ||||
|                         int chunkSize = Math.Min(req.AssetInf.Data.Length - processedLength, maxChunkSize); | ||||
|                         byte[] chunk = new byte[chunkSize]; | ||||
|                         Array.Copy(req.AssetInf.Data, processedLength, chunk, 0, chunk.Length); | ||||
| 
 | ||||
|                         TransferPacket.TransferData.Data = chunk; | ||||
| 
 | ||||
|                         // 0 indicates more packets to come, 1 indicates last packet | ||||
|                         if (req.AssetInf.Data.Length - processedLength > maxChunkSize) | ||||
|                         { | ||||
|                             TransferPacket.TransferData.Status = 0; | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             TransferPacket.TransferData.Status = 1; | ||||
|                         } | ||||
| 
 | ||||
|                         req.RequestUser.OutPacket(TransferPacket, ThrottleOutPacketType.Asset); | ||||
| 
 | ||||
|                         processedLength += chunkSize; | ||||
|                         packetNumber++; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             //remove requests that have been completed | ||||
|             for (int i = 0; i < num; i++) | ||||
|             { | ||||
|                 AssetRequests.RemoveAt(0); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         public class AssetRequest | ||||
|         { | ||||
|             public IClientAPI RequestUser; | ||||
|             public LLUUID RequestAssetID; | ||||
|             public AssetInfo AssetInf; | ||||
|             public TextureImage ImageInfo; | ||||
|             public LLUUID TransferRequestID; | ||||
|             public long DataPointer = 0; | ||||
|             public int NumPackets = 0; | ||||
|             public int PacketCounter = 0; | ||||
|             public bool IsTextureRequest; | ||||
|             public byte AssetRequestSource = 2; | ||||
|             public byte[] Params = null; | ||||
|             //public bool AssetInCache; | ||||
|             //public int TimeRequested;  | ||||
|             public int DiscardLevel = -1; | ||||
| 
 | ||||
|             public AssetRequest() | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public class AssetInfo : AssetBase | ||||
|         { | ||||
|             public AssetInfo() | ||||
|             { | ||||
|             } | ||||
| 
 | ||||
|             public AssetInfo(AssetBase aBase) | ||||
|             { | ||||
|                 Data = aBase.Data; | ||||
|                 FullID = aBase.FullID; | ||||
|                 Type = aBase.Type; | ||||
|                 InvType = aBase.InvType; | ||||
|                 Name = aBase.Name; | ||||
|                 Description = aBase.Description; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public class TextureImage : AssetBase | ||||
|         { | ||||
|             public TextureImage() | ||||
|             { | ||||
|             } | ||||
| 
 | ||||
|             public TextureImage(AssetBase aBase) | ||||
|             { | ||||
|                 Data = aBase.Data; | ||||
|                 FullID = aBase.FullID; | ||||
|                 Type = aBase.Type; | ||||
|                 InvType = aBase.InvType; | ||||
|                 Name = aBase.Name; | ||||
|                 Description = aBase.Description; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public class AssetRequestsList | ||||
|         { | ||||
|             public LLUUID AssetID; | ||||
|             public List<NewAssetRequest> Requests = new List<NewAssetRequest>(); | ||||
| 
 | ||||
|             public AssetRequestsList(LLUUID assetID) | ||||
|             { | ||||
|                 AssetID = assetID; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public class NewAssetRequest | ||||
|         { | ||||
|             public LLUUID AssetID; | ||||
|             public AssetRequestCallback Callback; | ||||
| 
 | ||||
|             public NewAssetRequest(LLUUID assetID, AssetRequestCallback callback) | ||||
|             { | ||||
|                 AssetID = assetID; | ||||
|                 Callback = callback; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,145 @@ | |||
| /* | ||||
| * 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.IO; | ||||
| using Db4objects.Db4o; | ||||
| using Db4objects.Db4o.Query; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class LocalAssetServer : AssetServerBase | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private IObjectContainer db; | ||||
| 
 | ||||
|         public LocalAssetServer() | ||||
|         { | ||||
|             bool yapfile; | ||||
|             yapfile = File.Exists(Path.Combine(Util.dataDir(), "regionassets.yap")); | ||||
| 
 | ||||
|             db = Db4oFactory.OpenFile(Path.Combine(Util.dataDir(), "regionassets.yap")); | ||||
|             m_log.Info("[ASSETS]: Db4 Asset database  creation"); | ||||
| 
 | ||||
|             if (!yapfile) | ||||
|             { | ||||
|                 SetUpAssetDatabase(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void CreateAndCommitAsset(AssetBase asset) | ||||
|         { | ||||
|             AssetStorage store = new AssetStorage(); | ||||
|             store.Data = asset.Data; | ||||
|             store.Name = asset.Name; | ||||
|             store.UUID = asset.FullID; | ||||
|             db.Set(store); | ||||
|             db.Commit(); | ||||
|         } | ||||
| 
 | ||||
|         public override void Close() | ||||
|         { | ||||
|             base.Close(); | ||||
| 
 | ||||
|             if (db != null) | ||||
|             { | ||||
|                 m_log.Info("[ASSETSERVER]: Closing local asset server database"); | ||||
|                 db.Close(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected override AssetBase GetAsset(AssetRequest req) | ||||
|         { | ||||
|             byte[] idata = null; | ||||
|             bool found = false; | ||||
|             AssetStorage foundAsset = null; | ||||
|             IObjectSet result = db.Query(new AssetUUIDQuery(req.AssetID)); | ||||
|             if (result.Count > 0) | ||||
|             { | ||||
|                 foundAsset = (AssetStorage) result.Next(); | ||||
|                 found = true; | ||||
|             } | ||||
| 
 | ||||
|             AssetBase asset = new AssetBase(); | ||||
|             if (found) | ||||
|             { | ||||
|                 asset.FullID = foundAsset.UUID; | ||||
|                 asset.Type = foundAsset.Type; | ||||
|                 asset.InvType = foundAsset.Type; | ||||
|                 asset.Name = foundAsset.Name; | ||||
|                 idata = foundAsset.Data; | ||||
|                 asset.Data = idata; | ||||
| 
 | ||||
|                 return asset; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected override void StoreAsset(AssetBase asset) | ||||
|         { | ||||
|             AssetStorage store = new AssetStorage(); | ||||
|             store.Data = asset.Data; | ||||
|             store.Name = asset.Name; | ||||
|             store.UUID = asset.FullID; | ||||
|             db.Set(store); | ||||
| 
 | ||||
|             CommitAssets(); | ||||
|         } | ||||
| 
 | ||||
|         protected override void CommitAssets() | ||||
|         { | ||||
|             db.Commit(); | ||||
|         } | ||||
| 
 | ||||
|         protected virtual void SetUpAssetDatabase() | ||||
|         { | ||||
|             m_log.Info("[LOCAL ASSET SERVER]: Setting up asset database"); | ||||
| 
 | ||||
|             base.LoadDefaultAssets(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public class AssetUUIDQuery : Predicate | ||||
|     { | ||||
|         private LLUUID _findID; | ||||
| 
 | ||||
|         public AssetUUIDQuery(LLUUID find) | ||||
|         { | ||||
|             _findID = find; | ||||
|         } | ||||
| 
 | ||||
|         public bool Match(AssetStorage asset) | ||||
|         { | ||||
|             return (asset.UUID == _findID); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,163 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Threading; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.AssetLoader.Filesystem; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public abstract class AssetServerBase : IAssetServer | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         protected IAssetReceiver m_receiver; | ||||
|         protected BlockingQueue<AssetRequest> m_assetRequests; | ||||
|         protected Thread m_localAssetServerThread; | ||||
|         protected IAssetProvider m_assetProvider; | ||||
|         protected object m_syncLock = new object(); | ||||
| 
 | ||||
|         // Temporarily hardcoded - should be a plugin | ||||
|         protected IAssetLoader assetLoader = new AssetLoaderFileSystem(); | ||||
|          | ||||
|         protected abstract void StoreAsset(AssetBase asset); | ||||
|         protected abstract void CommitAssets(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// This method must be implemented by a subclass to retrieve the asset named in the  | ||||
|         /// AssetRequest.  If the asset is not found, null should be returned. | ||||
|         /// </summary> | ||||
|         /// <param name="req"></param> | ||||
|         /// <returns></returns> | ||||
|         protected abstract AssetBase GetAsset(AssetRequest req); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Process an asset request.  This method will call GetAsset(AssetRequest req)  | ||||
|         /// on the subclass. | ||||
|         /// </summary> | ||||
|         /// <param name="req"></param> | ||||
|         protected virtual void ProcessRequest(AssetRequest req) | ||||
|         { | ||||
|             AssetBase asset = GetAsset(req); | ||||
| 
 | ||||
|             if (asset != null) | ||||
|             { | ||||
|                 //m_log.InfoFormat("[ASSET]: Asset {0} received from asset server", req.AssetID); | ||||
| 
 | ||||
|                 m_receiver.AssetReceived(asset, req.IsTexture); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.ErrorFormat("[ASSET]: Asset {0} not found by asset server", req.AssetID); | ||||
| 
 | ||||
|                 m_receiver.AssetNotFound(req.AssetID); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public virtual void LoadDefaultAssets() | ||||
|         { | ||||
|             m_log.Info("[ASSETSERVER]: Setting up asset database"); | ||||
| 
 | ||||
|             assetLoader.ForEachDefaultXmlAsset(StoreAsset); | ||||
| 
 | ||||
|             CommitAssets(); | ||||
|         } | ||||
| 
 | ||||
|         public AssetServerBase() | ||||
|         { | ||||
|             m_log.Info("[ASSETSERVER]: Starting asset storage system"); | ||||
|             m_assetRequests = new BlockingQueue<AssetRequest>(); | ||||
| 
 | ||||
|             m_localAssetServerThread = new Thread(RunRequests); | ||||
|             m_localAssetServerThread.IsBackground = true; | ||||
|             m_localAssetServerThread.Start(); | ||||
|         } | ||||
| 
 | ||||
|         private void RunRequests() | ||||
|         { | ||||
|             while (true) // Since it's a 'blocking queue' | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     AssetRequest req = m_assetRequests.Dequeue(); | ||||
| 
 | ||||
|                     ProcessRequest(req); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Error("[ASSETSERVER]: " + e.Message); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void SetReceiver(IAssetReceiver receiver) | ||||
|         { | ||||
|             m_receiver = receiver; | ||||
|         } | ||||
| 
 | ||||
|         public void RequestAsset(LLUUID assetID, bool isTexture) | ||||
|         { | ||||
|             AssetRequest req = new AssetRequest(); | ||||
|             req.AssetID = assetID; | ||||
|             req.IsTexture = isTexture; | ||||
|             m_assetRequests.Enqueue(req); | ||||
| 
 | ||||
|             m_log.InfoFormat("[ASSET]: Added {0} to request queue", assetID); | ||||
|         } | ||||
| 
 | ||||
|         public virtual void UpdateAsset(AssetBase asset) | ||||
|         { | ||||
|             lock (m_syncLock) | ||||
|             { | ||||
|                 m_assetProvider.UpdateAsset(asset); | ||||
|                 m_assetProvider.CommitAssets(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void StoreAndCommitAsset(AssetBase asset) | ||||
|         { | ||||
|             lock (m_syncLock) | ||||
|             { | ||||
|                 StoreAsset(asset); | ||||
|                 CommitAssets(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public virtual void Close() | ||||
|         { | ||||
|             m_localAssetServerThread.Abort(); | ||||
|         } | ||||
| 
 | ||||
|         public void SetServerInfo(string ServerUrl, string ServerKey) | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,133 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class CachedUserInfo | ||||
|     { | ||||
|         private readonly CommunicationsManager m_parentCommsManager; | ||||
|         // Fields | ||||
|         public InventoryFolderImpl RootFolder = null; | ||||
|         public UserProfileData UserProfile = null; | ||||
| 
 | ||||
|         public CachedUserInfo(CommunicationsManager commsManager) | ||||
|         { | ||||
|             m_parentCommsManager = commsManager; | ||||
|         } | ||||
| 
 | ||||
|         // Methods | ||||
|         public void FolderReceive(LLUUID userID, InventoryFolderImpl folderInfo) | ||||
|         { | ||||
|             if (userID == UserProfile.UUID) | ||||
|             { | ||||
|                 if (RootFolder == null) | ||||
|                 { | ||||
|                     if (folderInfo.parentID == LLUUID.Zero) | ||||
|                     { | ||||
|                         RootFolder = folderInfo; | ||||
|                     } | ||||
|                 } | ||||
|                 else if (RootFolder.folderID == folderInfo.parentID) | ||||
|                 { | ||||
|                     if (!RootFolder.SubFolders.ContainsKey(folderInfo.folderID)) | ||||
|                     { | ||||
|                         RootFolder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     InventoryFolderImpl folder = RootFolder.HasSubFolder(folderInfo.parentID); | ||||
|                     if (folder != null) | ||||
|                     { | ||||
|                         if (!folder.SubFolders.ContainsKey(folderInfo.folderID)) | ||||
|                         { | ||||
|                             folder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo) | ||||
|         { | ||||
|             if ((userID == UserProfile.UUID) && (RootFolder != null)) | ||||
|             { | ||||
|                 if (itemInfo.parentFolderID == RootFolder.folderID) | ||||
|                 { | ||||
|                     if (!RootFolder.Items.ContainsKey(itemInfo.inventoryID)) | ||||
|                     { | ||||
|                         RootFolder.Items.Add(itemInfo.inventoryID, itemInfo); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     InventoryFolderImpl folder = RootFolder.HasSubFolder(itemInfo.parentFolderID); | ||||
|                     if (folder != null) | ||||
|                     { | ||||
|                         if (!folder.Items.ContainsKey(itemInfo.inventoryID)) | ||||
|                         { | ||||
|                             folder.Items.Add(itemInfo.inventoryID, itemInfo); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void AddItem(LLUUID userID, InventoryItemBase itemInfo) | ||||
|         { | ||||
|             if ((userID == UserProfile.UUID) && (RootFolder != null)) | ||||
|             { | ||||
|                 ItemReceive(userID, itemInfo); | ||||
|                 m_parentCommsManager.InventoryService.AddNewInventoryItem(userID, itemInfo); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateItem(LLUUID userID, InventoryItemBase itemInfo) | ||||
|         { | ||||
|             if ((userID == UserProfile.UUID) && (RootFolder != null)) | ||||
|             { | ||||
|                 m_parentCommsManager.InventoryService.AddNewInventoryItem(userID, itemInfo); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool DeleteItem(LLUUID userID, InventoryItemBase item) | ||||
|         { | ||||
|             bool result = false; | ||||
|             if ((userID == UserProfile.UUID) && (RootFolder != null)) | ||||
|             { | ||||
|                 result = RootFolder.DeleteItem(item.inventoryID); | ||||
|                 if (result) | ||||
|                 { | ||||
|                     m_parentCommsManager.InventoryService.DeleteInventoryItem(userID, item); | ||||
|                 } | ||||
|             } | ||||
|             return result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,125 @@ | |||
| /* | ||||
| * 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.IO; | ||||
| using System.Xml.Serialization; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Servers; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class GridAssetClient : AssetServerBase | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private string _assetServerUrl; | ||||
| 
 | ||||
|         public GridAssetClient(string serverUrl) | ||||
|         { | ||||
|             _assetServerUrl = serverUrl; | ||||
|         } | ||||
| 
 | ||||
|         #region IAssetServer Members | ||||
| 
 | ||||
|         protected override AssetBase GetAsset(AssetRequest req) | ||||
|         { | ||||
|             Stream s = null; | ||||
|             try | ||||
|             { | ||||
|                 m_log.DebugFormat("[ASSETCACHE]: Querying for {0}", req.AssetID.ToString()); | ||||
| 
 | ||||
|                 RestClient rc = new RestClient(_assetServerUrl); | ||||
|                 rc.AddResourcePath("assets"); | ||||
|                 rc.AddResourcePath(req.AssetID.ToString()); | ||||
|                 if (req.IsTexture) | ||||
|                     rc.AddQueryParameter("texture"); | ||||
| 
 | ||||
|                 rc.RequestMethod = "GET"; | ||||
|                 s = rc.Request(); | ||||
| 
 | ||||
|                 if (s.Length > 0) | ||||
|                 { | ||||
|                     XmlSerializer xs = new XmlSerializer(typeof (AssetBase)); | ||||
| 
 | ||||
|                     return (AssetBase) xs.Deserialize(s); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[ASSETCACHE]: " + e.Message); | ||||
|                 m_log.DebugFormat("[ASSETCACHE]: Getting asset {0}", req.AssetID.ToString()); | ||||
|                 m_log.Error("[ASSETCACHE]: " + e.StackTrace); | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public override void UpdateAsset(AssetBase asset) | ||||
|         { | ||||
|             throw new Exception("The method or operation is not implemented."); | ||||
|         } | ||||
| 
 | ||||
|         protected override void StoreAsset(AssetBase asset) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 //  MemoryStream s = new MemoryStream(); | ||||
| 
 | ||||
|                 // XmlSerializer xs = new XmlSerializer(typeof(AssetBase)); | ||||
|                 //   xs.Serialize(s, asset); | ||||
|                 //  RestClient rc = new RestClient(_assetServerUrl); | ||||
|                 m_log.Info("[ASSET]: Storing asset"); | ||||
|                 //rc.AddResourcePath("assets"); | ||||
| 
 | ||||
|                 // rc.RequestMethod = "POST"; | ||||
|                 //  rc.Request(s); | ||||
|                 //m_log.InfoFormat("[ASSET]: Stored {0}", rc); | ||||
|                 m_log.Info("[ASSET]: Sending to " + _assetServerUrl + "/assets/"); | ||||
|                 RestObjectPoster.BeginPostObject<AssetBase>(_assetServerUrl + "/assets/", asset); | ||||
| 
 | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[ASSETS]: " + e.Message); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected override void CommitAssets() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public override void Close() | ||||
|         { | ||||
|             throw new Exception("The method or operation is not implemented."); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,156 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class InventoryFolderImpl : InventoryFolderBase | ||||
|     { | ||||
|         // Fields | ||||
|         public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>(); | ||||
|         public Dictionary<LLUUID, InventoryFolderImpl> SubFolders = new Dictionary<LLUUID, InventoryFolderImpl>(); | ||||
| 
 | ||||
|         // Accessors | ||||
|         public int SubFoldersCount | ||||
|         { | ||||
|             get { return SubFolders.Count; } | ||||
|         } | ||||
| 
 | ||||
|         // Constructors | ||||
|         public InventoryFolderImpl(InventoryFolderBase folderbase) | ||||
|         { | ||||
|             agentID = folderbase.agentID; | ||||
|             folderID = folderbase.folderID; | ||||
|             name = folderbase.name; | ||||
|             parentID = folderbase.parentID; | ||||
|             type = folderbase.type; | ||||
|             version = folderbase.version; | ||||
|         } | ||||
| 
 | ||||
|         public InventoryFolderImpl() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         // Methods | ||||
|         public InventoryFolderImpl CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) | ||||
|         { | ||||
|             if (!SubFolders.ContainsKey(folderID)) | ||||
|             { | ||||
|                 InventoryFolderImpl subFold = new InventoryFolderImpl(); | ||||
|                 subFold.name = folderName; | ||||
|                 subFold.folderID = folderID; | ||||
|                 subFold.type = (short) type; | ||||
|                 subFold.parentID = this.folderID; | ||||
|                 subFold.agentID = agentID; | ||||
|                 SubFolders.Add(subFold.folderID, subFold); | ||||
|                 return subFold; | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         public InventoryItemBase HasItem(LLUUID itemID) | ||||
|         { | ||||
|             InventoryItemBase base2 = null; | ||||
|             if (Items.ContainsKey(itemID)) | ||||
|             { | ||||
|                 return Items[itemID]; | ||||
|             } | ||||
|             foreach (InventoryFolderImpl folder in SubFolders.Values) | ||||
|             { | ||||
|                 base2 = folder.HasItem(itemID); | ||||
|                 if (base2 != null) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             return base2; | ||||
|         } | ||||
| 
 | ||||
|         public bool DeleteItem(LLUUID itemID) | ||||
|         { | ||||
|             bool found = false; | ||||
|             if (Items.ContainsKey(itemID)) | ||||
|             { | ||||
|                 Items.Remove(itemID); | ||||
|                 return true; | ||||
|             } | ||||
|             foreach (InventoryFolderImpl folder in SubFolders.Values) | ||||
|             { | ||||
|                 found = folder.DeleteItem(itemID); | ||||
|                 if (found == true) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             return found; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public InventoryFolderImpl HasSubFolder(LLUUID folderID) | ||||
|         { | ||||
|             InventoryFolderImpl returnFolder = null; | ||||
|             if (SubFolders.ContainsKey(folderID)) | ||||
|             { | ||||
|                 returnFolder = SubFolders[folderID]; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 foreach (InventoryFolderImpl folder in SubFolders.Values) | ||||
|                 { | ||||
|                     returnFolder = folder.HasSubFolder(folderID); | ||||
|                     if (returnFolder != null) | ||||
|                     { | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             return returnFolder; | ||||
|         } | ||||
| 
 | ||||
|         public List<InventoryItemBase> RequestListOfItems() | ||||
|         { | ||||
|             List<InventoryItemBase> itemList = new List<InventoryItemBase>(); | ||||
|             foreach (InventoryItemBase item in Items.Values) | ||||
|             { | ||||
|                 itemList.Add(item); | ||||
|             } | ||||
|             return itemList; | ||||
|         } | ||||
| 
 | ||||
|         public List<InventoryFolderBase> RequestListOfFolders() | ||||
|         { | ||||
|             List<InventoryFolderBase> folderList = new List<InventoryFolderBase>(); | ||||
|             foreach (InventoryFolderBase folder in SubFolders.Values) | ||||
|             { | ||||
|                 folderList.Add(folder); | ||||
|             } | ||||
|             return folderList; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,278 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.IO; | ||||
| using System.Xml; | ||||
| using libsecondlife; | ||||
| using Nini.Config; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Basically a hack to give us a Inventory library while we don't have a inventory server | ||||
|     /// once the server is fully implemented then should read the data from that | ||||
|     /// </summary> | ||||
|     public class LibraryRootFolder : InventoryFolderImpl | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private LLUUID libOwner = new LLUUID("11111111-1111-0000-0000-000100bba000"); | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Holds the root library folder and all its descendents.  This is really only used during inventory | ||||
|         /// setup so that we don't have to repeatedly search the tree of library folders. | ||||
|         /// </summary> | ||||
|         protected Dictionary<LLUUID, InventoryFolderImpl> libraryFolders  | ||||
|             = new Dictionary<LLUUID, InventoryFolderImpl>(); | ||||
| 
 | ||||
|         public LibraryRootFolder() | ||||
|         { | ||||
|             m_log.Info("[LIBRARY INVENTORY]: Loading library inventory"); | ||||
|              | ||||
|             agentID = libOwner; | ||||
|             folderID = new LLUUID("00000112-000f-0000-0000-000100bba000"); | ||||
|             name = "OpenSim Library"; | ||||
|             parentID = LLUUID.Zero; | ||||
|             type = (short) 8; | ||||
|             version = (ushort) 1; | ||||
|              | ||||
|             libraryFolders.Add(folderID, this); | ||||
|              | ||||
|             LoadLibraries(Path.Combine(Util.inventoryDir(), "Libraries.xml")); | ||||
| 
 | ||||
|             // CreateLibraryItems(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Hardcoded item creation.  Please don't add any more items here - future items should be created  | ||||
|         /// in the xml in the bin/inventory folder. | ||||
|         /// </summary> | ||||
|         /// | ||||
|         /// Commented the following out due to sending it all through xml, remove this section once this is provin to work stable. | ||||
|         /// | ||||
|         //private void CreateLibraryItems() | ||||
|         //{ | ||||
|         //    InventoryItemBase item = | ||||
|         //        CreateItem(new LLUUID("66c41e39-38f9-f75a-024e-585989bfaba9"), | ||||
|         //                   new LLUUID("66c41e39-38f9-f75a-024e-585989bfab73"), "Default Shape", "Default Shape", | ||||
|         //                   (int) AssetType.Bodypart, (int) InventoryType.Wearable, folderID); | ||||
|         //    item.inventoryCurrentPermissions = 0; | ||||
|         //    item.inventoryNextPermissions = 0; | ||||
|         //    Items.Add(item.inventoryID, item); | ||||
| 
 | ||||
|         //    item = | ||||
|         //        CreateItem(new LLUUID("77c41e39-38f9-f75a-024e-585989bfabc9"), | ||||
|         //                   new LLUUID("77c41e39-38f9-f75a-024e-585989bbabbb"), "Default Skin", "Default Skin", | ||||
|         //                   (int) AssetType.Bodypart, (int) InventoryType.Wearable, folderID); | ||||
|         //    item.inventoryCurrentPermissions = 0; | ||||
|         //    item.inventoryNextPermissions = 0; | ||||
|         //    Items.Add(item.inventoryID, item); | ||||
| 
 | ||||
|         //    item = | ||||
|         //        CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-585989bf0000"), | ||||
|         //                   new LLUUID("00000000-38f9-1111-024e-222222111110"), "Default Shirt", "Default Shirt", | ||||
|         //                   (int) AssetType.Clothing, (int) InventoryType.Wearable, folderID); | ||||
|         //    item.inventoryCurrentPermissions = 0; | ||||
|         //    item.inventoryNextPermissions = 0; | ||||
|         //    Items.Add(item.inventoryID, item); | ||||
| 
 | ||||
|         //    item = | ||||
|         //        CreateItem(new LLUUID("77c41e39-38f9-f75a-0000-5859892f1111"), | ||||
|         //                   new LLUUID("00000000-38f9-1111-024e-222222111120"), "Default Pants", "Default Pants", | ||||
|         //                   (int) AssetType.Clothing, (int) InventoryType.Wearable, folderID); | ||||
|         //    item.inventoryCurrentPermissions = 0; | ||||
|         //    item.inventoryNextPermissions = 0; | ||||
|         //    Items.Add(item.inventoryID, item); | ||||
|         //} | ||||
| 
 | ||||
|         public InventoryItemBase CreateItem(LLUUID inventoryID, LLUUID assetID, string name, string description, | ||||
|                                             int assetType, int invType, LLUUID parentFolderID) | ||||
|         { | ||||
|             InventoryItemBase item = new InventoryItemBase(); | ||||
|             item.avatarID = libOwner; | ||||
|             item.creatorsID = libOwner; | ||||
|             item.inventoryID = inventoryID; | ||||
|             item.assetID = assetID; | ||||
|             item.inventoryDescription = description; | ||||
|             item.inventoryName = name; | ||||
|             item.assetType = assetType; | ||||
|             item.invType = invType; | ||||
|             item.parentFolderID = parentFolderID; | ||||
|             item.inventoryBasePermissions = 0x7FFFFFFF; | ||||
|             item.inventoryEveryOnePermissions = 0x7FFFFFFF; | ||||
|             item.inventoryCurrentPermissions = 0x7FFFFFFF; | ||||
|             item.inventoryNextPermissions = 0x7FFFFFFF; | ||||
|             return item; | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Use the asset set information at path to load assets | ||||
|         /// </summary> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="assets"></param> | ||||
|         protected void LoadLibraries(string librariesControlPath) | ||||
|         { | ||||
|             m_log.InfoFormat( | ||||
|                 "[LIBRARY INVENTORY]: Loading libraries control file {0}", librariesControlPath); | ||||
|              | ||||
|             LoadFromFile(librariesControlPath, "Libraries control", ReadLibraryFromConfig); | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Read a library set from config | ||||
|         /// </summary> | ||||
|         /// <param name="config"></param> | ||||
|         protected void ReadLibraryFromConfig(IConfig config) | ||||
|         { | ||||
|             string foldersPath  | ||||
|                 = Path.Combine( | ||||
|                     Util.inventoryDir(), config.GetString("foldersFile", System.String.Empty)); | ||||
|              | ||||
|             LoadFromFile(foldersPath, "Library folders", ReadFolderFromConfig); | ||||
|              | ||||
|             string itemsPath  | ||||
|                 = Path.Combine( | ||||
|                     Util.inventoryDir(), config.GetString("itemsFile", System.String.Empty)); | ||||
|              | ||||
|             LoadFromFile(itemsPath, "Library items", ReadItemFromConfig); | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Read a library inventory folder from a loaded configuration | ||||
|         /// </summary> | ||||
|         /// <param name="source"></param> | ||||
|         private void ReadFolderFromConfig(IConfig config) | ||||
|         {                         | ||||
|             InventoryFolderImpl folderInfo = new InventoryFolderImpl(); | ||||
|              | ||||
|             folderInfo.folderID = new LLUUID(config.GetString("folderID", folderID.ToString())); | ||||
|             folderInfo.name = config.GetString("name", "unknown");                 | ||||
|             folderInfo.parentID = new LLUUID(config.GetString("parentFolderID", folderID.ToString())); | ||||
|             folderInfo.type = (short)config.GetInt("type", 8); | ||||
|              | ||||
|             folderInfo.agentID = libOwner;                 | ||||
|             folderInfo.version = 1;                 | ||||
|              | ||||
|             if (libraryFolders.ContainsKey(folderInfo.parentID)) | ||||
|             {                 | ||||
|                 InventoryFolderImpl parentFolder = libraryFolders[folderInfo.parentID]; | ||||
|                  | ||||
|                 libraryFolders.Add(folderInfo.folderID, folderInfo); | ||||
|                 parentFolder.SubFolders.Add(folderInfo.folderID, folderInfo); | ||||
| 
 | ||||
| //                 m_log.InfoFormat("[LIBRARY INVENTORY]: Adding folder {0} ({1})", folderInfo.name, folderInfo.folderID); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.WarnFormat( | ||||
|                     "[LIBRARY INVENTORY]: Couldn't add folder {0} ({1}) since parent folder with ID {2} does not exist!", | ||||
|                     folderInfo.name, folderInfo.folderID, folderInfo.parentID); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Read a library inventory item metadata from a loaded configuration | ||||
|         /// </summary> | ||||
|         /// <param name="source"></param>         | ||||
|         private void ReadItemFromConfig(IConfig config) | ||||
|         { | ||||
|             InventoryItemBase item = new InventoryItemBase(); | ||||
|             item.avatarID = libOwner; | ||||
|             item.creatorsID = libOwner; | ||||
|             item.inventoryID = new LLUUID(config.GetString("inventoryID", folderID.ToString())); | ||||
|             item.assetID = new LLUUID(config.GetString("assetID", LLUUID.Random().ToString())); | ||||
|             item.parentFolderID = new LLUUID(config.GetString("folderID", folderID.ToString())); | ||||
|             item.inventoryDescription = config.GetString("description", System.String.Empty); | ||||
|             item.inventoryName = config.GetString("name", System.String.Empty); | ||||
|             item.assetType = config.GetInt("assetType", 0); | ||||
|             item.invType = config.GetInt("inventoryType", 0); | ||||
|             item.inventoryCurrentPermissions = (uint)config.GetLong("currentPermissions", 0x7FFFFFFF); | ||||
|             item.inventoryNextPermissions = (uint)config.GetLong("nextPermissions", 0x7FFFFFFF); | ||||
|             item.inventoryEveryOnePermissions = (uint)config.GetLong("everyonePermissions", 0x7FFFFFFF); | ||||
|             item.inventoryBasePermissions = (uint)config.GetLong("basePermissions", 0x7FFFFFFF); | ||||
|              | ||||
|             if (libraryFolders.ContainsKey(item.parentFolderID)) | ||||
|             { | ||||
|                 InventoryFolderImpl parentFolder = libraryFolders[item.parentFolderID]; | ||||
|                  | ||||
|                 parentFolder.Items.Add(item.inventoryID, item); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.WarnFormat( | ||||
|                     "[LIBRARY INVENTORY]: Couldn't add item {0} ({1}) since parent folder with ID {2} does not exist!", | ||||
|                     item.inventoryName, item.inventoryID, item.parentFolderID); | ||||
|             }                 | ||||
|         } | ||||
|                  | ||||
|         private delegate void ConfigAction(IConfig config);         | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Load the given configuration at a path and perform an action on each Config contained within it | ||||
|         /// </summary> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="fileDescription"></param> | ||||
|         /// <param name="action"></param> | ||||
|         private void LoadFromFile(string path, string fileDescription, ConfigAction action) | ||||
|         {             | ||||
|             if (File.Exists(path)) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     XmlConfigSource source = new XmlConfigSource(path); | ||||
| 
 | ||||
|                     for (int i = 0; i < source.Configs.Count; i++) | ||||
|                     {     | ||||
|                         action(source.Configs[i]); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (XmlException e) | ||||
|                 { | ||||
|                     m_log.ErrorFormat("[LIBRARY INVENTORY]: Error loading {0} : {1}", path, e); | ||||
|                 }                 | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.ErrorFormat("[LIBRARY INVENTORY]: {0} file {1} does not exist!", fileDescription, path); | ||||
|             }             | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Looks like a simple getter, but is written like this for some consistency with the other Request | ||||
|         /// methods in the superclass | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         public Dictionary<LLUUID, InventoryFolderImpl> RequestSelfAndDescendentFolders() | ||||
|         { | ||||
|             return libraryFolders; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,102 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class SQLAssetServer : AssetServerBase | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public SQLAssetServer(string pluginName) | ||||
|         { | ||||
|             AddPlugin(pluginName); | ||||
|         } | ||||
| 
 | ||||
|         public SQLAssetServer(IAssetProvider assetProvider) | ||||
|         { | ||||
|             m_assetProvider = assetProvider; | ||||
|         } | ||||
| 
 | ||||
|         public void AddPlugin(string FileName) | ||||
|         { | ||||
|             m_log.Info("[SQLAssetServer]: AssetStorage: Attempting to load " + FileName); | ||||
|             Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||||
| 
 | ||||
|             foreach (Type pluginType in pluginAssembly.GetTypes()) | ||||
|             { | ||||
|                 if (!pluginType.IsAbstract) | ||||
|                 { | ||||
|                     Type typeInterface = pluginType.GetInterface("IAssetProvider", true); | ||||
| 
 | ||||
|                     if (typeInterface != null) | ||||
|                     { | ||||
|                         IAssetProvider plug = | ||||
|                             (IAssetProvider) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||||
|                         m_assetProvider = plug; | ||||
|                         m_assetProvider.Initialise(); | ||||
| 
 | ||||
|                         m_log.Info("[AssetStorage]: " + | ||||
|                                    "Added " + m_assetProvider.Name + " " + | ||||
|                                    m_assetProvider.Version); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public override void Close() | ||||
|         { | ||||
|             base.Close(); | ||||
| 
 | ||||
|             m_assetProvider.CommitAssets(); | ||||
|         } | ||||
| 
 | ||||
|         protected override AssetBase GetAsset(AssetRequest req) | ||||
|         { | ||||
|             AssetBase asset; | ||||
|             lock (m_syncLock) | ||||
|             { | ||||
|                 asset = m_assetProvider.FetchAsset(req.AssetID); | ||||
|             } | ||||
| 
 | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
|         protected override void StoreAsset(AssetBase asset) | ||||
|         { | ||||
|             m_assetProvider.CreateAsset(asset); | ||||
|         } | ||||
| 
 | ||||
|         protected override void CommitAssets() | ||||
|         { | ||||
|             m_assetProvider.CommitAssets(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,308 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications.Cache | ||||
| { | ||||
|     public class UserProfileCacheService | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         // Fields | ||||
|         private readonly CommunicationsManager m_parent; | ||||
|         private readonly Dictionary<LLUUID, CachedUserInfo> m_userProfiles = new Dictionary<LLUUID, CachedUserInfo>(); | ||||
| 
 | ||||
|         public LibraryRootFolder libraryRoot = new LibraryRootFolder(); | ||||
| 
 | ||||
|         // Methods | ||||
|         public UserProfileCacheService(CommunicationsManager parent) | ||||
|         { | ||||
|             m_parent = parent; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// A new user has moved into a region in this instance | ||||
|         /// so get info from servers | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         public void AddNewUser(LLUUID userID) | ||||
|         { | ||||
|             // Potential fix - Multithreading issue. | ||||
|             lock (m_userProfiles) | ||||
|             { | ||||
|                 if (!m_userProfiles.ContainsKey(userID)) | ||||
|                 { | ||||
|                     CachedUserInfo userInfo = new CachedUserInfo(m_parent); | ||||
|                     userInfo.UserProfile = m_parent.UserService.GetUserProfile(userID); | ||||
| 
 | ||||
|                     if (userInfo.UserProfile != null) | ||||
|                     { | ||||
|                         // The request itself will occur when the agent finishes logging on to the region | ||||
|                         // so there's no need to do it here. | ||||
|                         //RequestInventoryForUser(userID, userInfo); | ||||
|                         m_userProfiles.Add(userID, userInfo); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         m_log.ErrorFormat("[USERCACHE]: User profile for user {0} not found", userID); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateUserInventory(LLUUID userID) | ||||
|         { | ||||
|             CachedUserInfo userInfo = GetUserDetails(userID); | ||||
|             if (userInfo != null) | ||||
|             { | ||||
|                 RequestInventoryForUser(userID, userInfo); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public CachedUserInfo GetUserDetails(LLUUID userID) | ||||
|         { | ||||
|             if (m_userProfiles.ContainsKey(userID)) | ||||
|                 return m_userProfiles[userID]; | ||||
|             else | ||||
|                 return null; | ||||
|         } | ||||
| 
 | ||||
|         public void HandleCreateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort folderType, | ||||
|                                                 string folderName, LLUUID parentID) | ||||
|         { | ||||
|             CachedUserInfo userProfile; | ||||
| 
 | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     if (userProfile.RootFolder.folderID == parentID) | ||||
|                     { | ||||
|                         InventoryFolderImpl createdFolder = | ||||
|                             userProfile.RootFolder.CreateNewSubFolder(folderID, folderName, folderType); | ||||
| 
 | ||||
|                         if (createdFolder != null) | ||||
|                         { | ||||
|                             InventoryFolderBase createdBaseFolder = new InventoryFolderBase(); | ||||
|                             createdBaseFolder.agentID = createdFolder.agentID; | ||||
|                             createdBaseFolder.folderID = createdFolder.folderID; | ||||
|                             createdBaseFolder.name = createdFolder.name; | ||||
|                             createdBaseFolder.parentID = createdFolder.parentID; | ||||
|                             createdBaseFolder.type = createdFolder.type; | ||||
|                             createdBaseFolder.version = createdFolder.version; | ||||
|                             m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, createdBaseFolder); | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         InventoryFolderImpl folder = userProfile.RootFolder.HasSubFolder(parentID); | ||||
|                         if (folder != null) | ||||
|                         { | ||||
|                             folder.CreateNewSubFolder(folderID, folderName, folderType); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void HandleUpdateInventoryFolder(IClientAPI remoteClient, LLUUID folderID, ushort type, string name, | ||||
|                                                 LLUUID parentID) | ||||
|         { | ||||
|             CachedUserInfo userProfile; | ||||
| 
 | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     InventoryFolderBase baseFolder = new InventoryFolderBase(); | ||||
|                     baseFolder.agentID = remoteClient.AgentId; | ||||
|                     baseFolder.folderID = folderID; | ||||
|                     baseFolder.name = name; | ||||
|                     baseFolder.parentID = parentID; | ||||
|                     baseFolder.type = (short) type; | ||||
|                     baseFolder.version = userProfile.RootFolder.version; | ||||
|                     m_parent.InventoryService.AddNewInventoryFolder(remoteClient.AgentId, baseFolder); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void HandleMoveInventoryFolder(IClientAPI remoteClient, LLUUID folderID, LLUUID parentID) | ||||
|         { | ||||
|             CachedUserInfo userProfile; | ||||
| 
 | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     InventoryFolderBase baseFolder = new InventoryFolderBase(); | ||||
|                     baseFolder.agentID = remoteClient.AgentId; | ||||
|                     baseFolder.folderID = folderID; | ||||
|                     baseFolder.parentID = parentID; | ||||
|                     m_parent.InventoryService.MoveInventoryFolder(remoteClient.AgentId, baseFolder); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Tell the client about the various child items and folders contained in the requested folder. | ||||
|         /// </summary> | ||||
|         /// <param name="remoteClient"></param> | ||||
|         /// <param name="folderID"></param> | ||||
|         /// <param name="ownerID"></param> | ||||
|         /// <param name="fetchFolders"></param> | ||||
|         /// <param name="fetchItems"></param> | ||||
|         /// <param name="sortOrder"></param> | ||||
|         public void HandleFetchInventoryDescendents(IClientAPI remoteClient, LLUUID folderID, LLUUID ownerID, | ||||
|                                                     bool fetchFolders, bool fetchItems, int sortOrder) | ||||
|         { | ||||
|             // XXX We're not handling sortOrder yet! | ||||
| 
 | ||||
|             InventoryFolderImpl fold = null; | ||||
|             if (folderID == libraryRoot.folderID) | ||||
|             { | ||||
|                 remoteClient.SendInventoryFolderDetails( | ||||
|                     libraryRoot.agentID, libraryRoot.folderID, libraryRoot.RequestListOfItems(), | ||||
|                     libraryRoot.RequestListOfFolders(), fetchFolders, fetchItems); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if ((fold = libraryRoot.HasSubFolder(folderID)) != null) | ||||
|             { | ||||
|                 remoteClient.SendInventoryFolderDetails( | ||||
|                     libraryRoot.agentID, folderID, fold.RequestListOfItems(), | ||||
|                     fold.RequestListOfFolders(), fetchFolders, fetchItems); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             CachedUserInfo userProfile; | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     if (userProfile.RootFolder.folderID == folderID) | ||||
|                     { | ||||
|                         remoteClient.SendInventoryFolderDetails( | ||||
|                             remoteClient.AgentId, folderID, userProfile.RootFolder.RequestListOfItems(), | ||||
|                             userProfile.RootFolder.RequestListOfFolders(), | ||||
|                             fetchFolders, fetchItems); | ||||
| 
 | ||||
|                         return; | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         if ((fold = userProfile.RootFolder.HasSubFolder(folderID)) != null) | ||||
|                         { | ||||
|                             remoteClient.SendInventoryFolderDetails( | ||||
|                                 remoteClient.AgentId, folderID, fold.RequestListOfItems(), | ||||
|                                 fold.RequestListOfFolders(), fetchFolders, fetchItems); | ||||
| 
 | ||||
|                             return; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     m_log.ErrorFormat("[INVENTORYCACHE]: Could not find root folder for user {0}", remoteClient.Name); | ||||
| 
 | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.ErrorFormat("[INVENTORYCACHE]: " + | ||||
|                                   "Could not find user profile for {0} for folder {1}", | ||||
|                                   remoteClient.Name, folderID); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             // If we've reached this point then we couldn't find the folder, even though the client thinks | ||||
|             // it exists | ||||
|             m_log.ErrorFormat("[INVENTORYCACHE]: " + | ||||
|                               "Could not find folder {0} for user {1}", | ||||
|                               folderID, remoteClient.Name); | ||||
|         } | ||||
| 
 | ||||
|         public void HandlePurgeInventoryDescendents(IClientAPI remoteClient, LLUUID folderID) | ||||
|         { | ||||
| //            m_log.InfoFormat("[INVENTORYCACHE]: Purging folder {0} for {1} uuid {2}",  | ||||
| //                folderID, remoteClient.Name, remoteClient.AgentId); | ||||
|              | ||||
|             CachedUserInfo userProfile; | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     InventoryFolderImpl subFolder = userProfile.RootFolder.HasSubFolder(folderID); | ||||
|                     if (subFolder != null) | ||||
|                     { | ||||
|                         List<InventoryItemBase> items = subFolder.RequestListOfItems(); | ||||
|                         foreach (InventoryItemBase item in items) | ||||
|                         { | ||||
|                             userProfile.DeleteItem(remoteClient.AgentId, item); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void HandleFetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID) | ||||
|         { | ||||
|             if (ownerID == libraryRoot.agentID) | ||||
|             { | ||||
|                 //Console.WriteLine("request info for library item"); | ||||
| 
 | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             CachedUserInfo userProfile; | ||||
|             if (m_userProfiles.TryGetValue(remoteClient.AgentId, out userProfile)) | ||||
|             { | ||||
|                 if (userProfile.RootFolder != null) | ||||
|                 { | ||||
|                     InventoryItemBase item = userProfile.RootFolder.HasItem(itemID); | ||||
|                     if (item != null) | ||||
|                     { | ||||
|                         remoteClient.SendInventoryItemDetails(ownerID, item); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void RequestInventoryForUser(LLUUID userID, CachedUserInfo userInfo) | ||||
|         { | ||||
|             m_parent.InventoryService.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,745 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| using OpenSim.Framework; | ||||
| using OpenSim.Framework.Communications.Cache; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Servers; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     public delegate void UpLoadedAsset( | ||||
|         string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, | ||||
|         byte[] data, string inventoryType, string assetType); | ||||
| 
 | ||||
|     public delegate LLUUID UpdateItem(LLUUID itemID, byte[] data); | ||||
| 
 | ||||
|     public delegate void UpdateTaskScript(LLUUID itemID, LLUUID primID, bool isScriptRunning, byte[] data); | ||||
| 
 | ||||
|     public delegate void NewInventoryItem(LLUUID userID, InventoryItemBase item); | ||||
| 
 | ||||
|     public delegate LLUUID ItemUpdatedCallback(LLUUID userID, LLUUID itemID, byte[] data); | ||||
| 
 | ||||
|     public delegate void TaskScriptUpdatedCallback(LLUUID userID, LLUUID itemID, LLUUID primID, | ||||
|                                                    bool isScriptRunning, byte[] data); | ||||
| 
 | ||||
|     public class Caps | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private string m_httpListenerHostName; | ||||
|         private uint m_httpListenPort; | ||||
| 
 | ||||
|         private string m_capsObjectPath = "00001-"; | ||||
|         private string m_requestPath = "0000/"; | ||||
|         private string m_mapLayerPath = "0001/"; | ||||
|         private string m_newInventory = "0002/"; | ||||
|         //private string m_requestTexture = "0003/"; | ||||
|         private string m_notecardUpdatePath = "0004/"; | ||||
|         private string m_notecardTaskUpdatePath = "0005/"; | ||||
| 
 | ||||
|         //private string eventQueue = "0100/"; | ||||
|         private BaseHttpServer m_httpListener; | ||||
|         private LLUUID m_agentID; | ||||
|         private AssetCache m_assetCache; | ||||
|         private int m_eventQueueCount = 1; | ||||
|         private Queue<string> m_capsEventQueue = new Queue<string>(); | ||||
|         private bool m_dumpAssetsToFile; | ||||
| 
 | ||||
|         // These are callbacks which will be setup by the scene so that we can update scene data when we  | ||||
|         // receive capability calls | ||||
|         public NewInventoryItem AddNewInventoryItem = null; | ||||
|         public ItemUpdatedCallback ItemUpdatedCall = null; | ||||
|         public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null; | ||||
| 
 | ||||
|         public Caps(AssetCache assetCache, BaseHttpServer httpServer, string httpListen, uint httpPort, string capsPath, | ||||
|                     LLUUID agent, bool dumpAssetsToFile) | ||||
|         { | ||||
|             m_assetCache = assetCache; | ||||
|             m_capsObjectPath = capsPath; | ||||
|             m_httpListener = httpServer; | ||||
|             m_httpListenerHostName = httpListen; | ||||
|             m_httpListenPort = httpPort; | ||||
|             m_agentID = agent; | ||||
|             m_dumpAssetsToFile = dumpAssetsToFile; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         public void RegisterHandlers() | ||||
|         { | ||||
|             m_log.Info("[CAPS]: Registering CAPS handlers"); | ||||
|             string capsBase = "/CAPS/" + m_capsObjectPath; | ||||
|             try | ||||
|             { | ||||
|                 m_httpListener.AddStreamHandler( | ||||
|                     new LLSDStreamhandler<LLSDMapRequest, LLSDMapLayerResponse>("POST", capsBase + m_mapLayerPath, | ||||
|                                                                                 GetMapLayer)); | ||||
|                 m_httpListener.AddStreamHandler( | ||||
|                     new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>("POST", | ||||
|                                                                                            capsBase + m_newInventory, | ||||
|                                                                                            NewAgentInventoryRequest)); | ||||
| 
 | ||||
|                 AddLegacyCapsHandler(m_httpListener, m_requestPath, CapsRequest); | ||||
|                 //AddLegacyCapsHandler(m_httpListener, m_requestTexture , RequestTexture); | ||||
|                 AddLegacyCapsHandler(m_httpListener, m_notecardUpdatePath, NoteCardAgentInventory); | ||||
|                 AddLegacyCapsHandler(m_httpListener, m_notecardTaskUpdatePath, ScriptTaskInventory); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[CAPS]: " + e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         //[Obsolete("Use BaseHttpServer.AddStreamHandler(new LLSDStreamHandler( LLSDMethod delegate )) instead.")] | ||||
|         //Commented out the obsolete as at this time the first caps request can not use the new Caps method  | ||||
|         //as the sent type is a array and not a map and the deserialising doesn't deal properly with arrays. | ||||
|         private void AddLegacyCapsHandler(BaseHttpServer httpListener, string path, RestMethod restMethod) | ||||
|         { | ||||
|             string capsBase = "/CAPS/" + m_capsObjectPath; | ||||
|             httpListener.AddStreamHandler(new RestStreamHandler("POST", capsBase + path, restMethod)); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Construct a client response detailing all the capabilities this server can provide. | ||||
|         /// </summary> | ||||
|         /// <param name="request"></param> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="param"></param> | ||||
|         /// <returns></returns> | ||||
|         public string CapsRequest(string request, string path, string param) | ||||
|         { | ||||
|             //Console.WriteLine("caps request " + request); | ||||
|             string result = LLSDHelpers.SerialiseLLSDReply(GetCapabilities()); | ||||
|             return result; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Return an LLSDCapsDetails listing all the capabilities this server can provide | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         protected LLSDCapsDetails GetCapabilities() | ||||
|         { | ||||
|             LLSDCapsDetails caps = new LLSDCapsDetails(); | ||||
|             string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + | ||||
|                                  m_capsObjectPath; | ||||
|             caps.MapLayer = capsBaseUrl + m_mapLayerPath; | ||||
|             // caps.RequestTextureDownload = capsBaseUrl + m_requestTexture; | ||||
|             caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; | ||||
|             caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; | ||||
|             caps.UpdateScriptAgentInventory = capsBaseUrl + m_notecardUpdatePath; | ||||
|             caps.UpdateScriptTaskInventory = capsBaseUrl + m_notecardTaskUpdatePath; | ||||
|             return caps; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="mapReq"></param> | ||||
|         /// <returns></returns> | ||||
|         public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq) | ||||
|         { | ||||
|             LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse(); | ||||
|             mapResponse.LayerData.Array.Add(GetLLSDMapLayerResponse()); | ||||
|             return mapResponse; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         protected LLSDMapLayer GetLLSDMapLayerResponse() | ||||
|         { | ||||
|             LLSDMapLayer mapLayer = new LLSDMapLayer(); | ||||
|             mapLayer.Right = 5000; | ||||
|             mapLayer.Top = 5000; | ||||
|             mapLayer.ImageID = new LLUUID("00000000-0000-0000-9999-000000000006"); | ||||
|             return mapLayer; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="request"></param> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="param"></param> | ||||
|         /// <returns></returns> | ||||
|         public string RequestTexture(string request, string path, string param) | ||||
|         { | ||||
|             Console.WriteLine("texture request " + request); | ||||
|             // Needs implementing (added to remove compiler warning) | ||||
|             return String.Empty; | ||||
|         } | ||||
| 
 | ||||
|         #region EventQueue (Currently not enabled) | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="request"></param> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="param"></param> | ||||
|         /// <returns></returns> | ||||
|         public string ProcessEventQueue(string request, string path, string param) | ||||
|         { | ||||
|             string res = String.Empty; | ||||
| 
 | ||||
|             if (m_capsEventQueue.Count > 0) | ||||
|             { | ||||
|                 lock (m_capsEventQueue) | ||||
|                 { | ||||
|                     string item = m_capsEventQueue.Dequeue(); | ||||
|                     res = item; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 res = CreateEmptyEventResponse(); | ||||
|             } | ||||
|             return res; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="caps"></param> | ||||
|         /// <param name="ipAddressPort"></param> | ||||
|         /// <returns></returns> | ||||
|         public string CreateEstablishAgentComms(string caps, string ipAddressPort) | ||||
|         { | ||||
|             LLSDCapEvent eventItem = new LLSDCapEvent(); | ||||
|             eventItem.id = m_eventQueueCount; | ||||
|             //should be creating a EstablishAgentComms item, but there isn't a class for it yet | ||||
|             eventItem.events.Array.Add(new LLSDEmpty()); | ||||
|             string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | ||||
|             m_eventQueueCount++; | ||||
| 
 | ||||
|             m_capsEventQueue.Enqueue(res); | ||||
|             return res; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         public string CreateEmptyEventResponse() | ||||
|         { | ||||
|             LLSDCapEvent eventItem = new LLSDCapEvent(); | ||||
|             eventItem.id = m_eventQueueCount; | ||||
|             eventItem.events.Array.Add(new LLSDEmpty()); | ||||
|             string res = LLSDHelpers.SerialiseLLSDReply(eventItem); | ||||
|             m_eventQueueCount++; | ||||
|             return res; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Callback for a client request for an upload url for a script task  | ||||
|         /// inventory update | ||||
|         /// </summary> | ||||
|         /// <param name="request"></param> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="param"></param> | ||||
|         /// <returns></returns> | ||||
|         public string ScriptTaskInventory(string request, string path, string param) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
| //                m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param); | ||||
| 
 | ||||
|                 Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(Helpers.StringToField(request)); | ||||
|                 LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate(); | ||||
|                 LLSDHelpers.DeserialiseLLSDMap(hash, llsdUpdateRequest); | ||||
| 
 | ||||
|                 string capsBase = "/CAPS/" + m_capsObjectPath; | ||||
|                 string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||||
| 
 | ||||
|                 TaskInventoryScriptUpdater uploader = | ||||
|                     new TaskInventoryScriptUpdater( | ||||
|                         llsdUpdateRequest.item_id, | ||||
|                         llsdUpdateRequest.task_id, | ||||
|                         llsdUpdateRequest.is_script_running, | ||||
|                         capsBase + uploaderPath, | ||||
|                         m_httpListener, | ||||
|                         m_dumpAssetsToFile); | ||||
|                 uploader.OnUpLoad += TaskScriptUpdated; | ||||
| 
 | ||||
|                 m_httpListener.AddStreamHandler( | ||||
|                     new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||||
|                 string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||||
|                                      uploaderPath; | ||||
| 
 | ||||
|                 LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||||
|                 uploadResponse.uploader = uploaderURL; | ||||
|                 uploadResponse.state = "upload"; | ||||
| 
 | ||||
| //                m_log.InfoFormat("[CAPS]: " + | ||||
| //                                 "ScriptTaskInventory response: {0}", | ||||
| //                                 LLSDHelpers.SerialiseLLSDReply(uploadResponse))); | ||||
| 
 | ||||
|                 return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[CAPS]: " + e.ToString()); | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Callback for a client request for an upload url for a notecard (or script)  | ||||
|         /// agent inventory update | ||||
|         /// </summary> | ||||
|         /// <param name="request"></param> | ||||
|         /// <param name="path"></param> | ||||
|         /// <param name="param"></param> | ||||
|         /// <returns></returns> | ||||
|         public string NoteCardAgentInventory(string request, string path, string param) | ||||
|         { | ||||
|             //libsecondlife.StructuredData.LLSDMap hash = (libsecondlife.StructuredData.LLSDMap)libsecondlife.StructuredData.LLSDParser.DeserializeBinary(Helpers.StringToField(request)); | ||||
|             Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(Helpers.StringToField(request)); | ||||
|             LLSDItemUpdate llsdRequest = new LLSDItemUpdate(); | ||||
|             LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest); | ||||
| 
 | ||||
|             string capsBase = "/CAPS/" + m_capsObjectPath; | ||||
|             string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||||
| 
 | ||||
|             ItemUpdater uploader = | ||||
|                 new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile); | ||||
|             uploader.OnUpLoad += ItemUpdated; | ||||
| 
 | ||||
|             m_httpListener.AddStreamHandler( | ||||
|                 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||||
|             string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||||
|                                  uploaderPath; | ||||
| 
 | ||||
|             LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||||
|             uploadResponse.uploader = uploaderURL; | ||||
|             uploadResponse.state = "upload"; | ||||
| 
 | ||||
| //            m_log.InfoFormat("[CAPS]: " + | ||||
| //                             "NoteCardAgentInventory response: {0}", | ||||
| //                             LLSDHelpers.SerialiseLLSDReply(uploadResponse))); | ||||
| 
 | ||||
|             return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="llsdRequest"></param> | ||||
|         /// <returns></returns> | ||||
|         public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) | ||||
|         { | ||||
|             //Console.WriteLine("asset upload request via CAPS" + llsdRequest.inventory_type +" , "+ llsdRequest.asset_type); | ||||
| 
 | ||||
|             string assetName = llsdRequest.name; | ||||
|             string assetDes = llsdRequest.description; | ||||
|             string capsBase = "/CAPS/" + m_capsObjectPath; | ||||
|             LLUUID newAsset = LLUUID.Random(); | ||||
|             LLUUID newInvItem = LLUUID.Random(); | ||||
|             LLUUID parentFolder = llsdRequest.folder_id; | ||||
|             string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||||
| 
 | ||||
|             AssetUploader uploader = | ||||
|                 new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, | ||||
|                                   llsdRequest.asset_type, capsBase + uploaderPath, m_httpListener, m_dumpAssetsToFile); | ||||
|             m_httpListener.AddStreamHandler( | ||||
|                 new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); | ||||
|             string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + | ||||
|                                  uploaderPath; | ||||
| 
 | ||||
|             LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||||
|             uploadResponse.uploader = uploaderURL; | ||||
|             uploadResponse.state = "upload"; | ||||
|             uploader.OnUpLoad += UploadCompleteHandler; | ||||
|             return uploadResponse; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="assetID"></param> | ||||
|         /// <param name="inventoryItem"></param> | ||||
|         /// <param name="data"></param> | ||||
|         public void UploadCompleteHandler(string assetName, string assetDescription, LLUUID assetID, | ||||
|                                           LLUUID inventoryItem, LLUUID parentFolder, byte[] data, string inventoryType, | ||||
|                                           string assetType) | ||||
|         { | ||||
|             sbyte assType = 0; | ||||
|             sbyte inType = 0; | ||||
| 
 | ||||
|             if (inventoryType == "sound") | ||||
|             { | ||||
|                 inType = 1; | ||||
|                 assType = 1; | ||||
|             } | ||||
|             else if (inventoryType == "animation") | ||||
|             { | ||||
|                 inType = 19; | ||||
|                 assType = 20; | ||||
|             } | ||||
| 
 | ||||
|             AssetBase asset; | ||||
|             asset = new AssetBase(); | ||||
|             asset.FullID = assetID; | ||||
|             asset.Type = assType; | ||||
|             asset.InvType = inType; | ||||
|             asset.Name = assetName; | ||||
|             asset.Data = data; | ||||
|             m_assetCache.AddAsset(asset); | ||||
| 
 | ||||
|             InventoryItemBase item = new InventoryItemBase(); | ||||
|             item.avatarID = m_agentID; | ||||
|             item.creatorsID = m_agentID; | ||||
|             item.inventoryID = inventoryItem; | ||||
|             item.assetID = asset.FullID; | ||||
|             item.inventoryDescription = assetDescription; | ||||
|             item.inventoryName = assetName; | ||||
|             item.assetType = assType; | ||||
|             item.invType = inType; | ||||
|             item.parentFolderID = parentFolder; | ||||
|             item.inventoryCurrentPermissions = 2147483647; | ||||
|             item.inventoryNextPermissions = 2147483647; | ||||
| 
 | ||||
|             if (AddNewInventoryItem != null) | ||||
|             { | ||||
|                 AddNewInventoryItem(m_agentID, item); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Called when new asset data for an agent inventory item update has been uploaded. | ||||
|         /// </summary> | ||||
|         /// <param name="itemID">Item to update</param> | ||||
|         /// <param name="data">New asset data</param> | ||||
|         /// <returns></returns> | ||||
|         public LLUUID ItemUpdated(LLUUID itemID, byte[] data) | ||||
|         { | ||||
|             if (ItemUpdatedCall != null) | ||||
|             { | ||||
|                 return ItemUpdatedCall(m_agentID, itemID, data); | ||||
|             } | ||||
| 
 | ||||
|             return LLUUID.Zero; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Called when new asset data for an agent inventory item update has been uploaded. | ||||
|         /// </summary> | ||||
|         /// <param name="itemID">Item to update</param> | ||||
|         /// <param name="primID">Prim containing item to update</param> | ||||
|         /// <param name="isScriptRunning">Signals whether the script to update is currently running</param> | ||||
|         /// <param name="data">New asset data</param>         | ||||
|         public void TaskScriptUpdated(LLUUID itemID, LLUUID primID, bool isScriptRunning, byte[] data) | ||||
|         { | ||||
|             if (TaskScriptUpdatedCall != null) | ||||
|             { | ||||
|                 TaskScriptUpdatedCall(m_agentID, itemID, primID, isScriptRunning, data); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public class AssetUploader | ||||
|         { | ||||
|             public event UpLoadedAsset OnUpLoad; | ||||
| 
 | ||||
|             private string uploaderPath = String.Empty; | ||||
|             private LLUUID newAssetID; | ||||
|             private LLUUID inventoryItemID; | ||||
|             private LLUUID parentFolder; | ||||
|             private BaseHttpServer httpListener; | ||||
|             private bool m_dumpAssetsToFile; | ||||
|             private string m_assetName = String.Empty; | ||||
|             private string m_assetDes = String.Empty; | ||||
| 
 | ||||
|             private string m_invType = String.Empty; | ||||
|             private string m_assetType = String.Empty; | ||||
| 
 | ||||
|             public AssetUploader(string assetName, string description, LLUUID assetID, LLUUID inventoryItem, | ||||
|                                  LLUUID parentFolderID, string invType, string assetType, string path, | ||||
|                                  BaseHttpServer httpServer, bool dumpAssetsToFile) | ||||
|             { | ||||
|                 m_assetName = assetName; | ||||
|                 m_assetDes = description; | ||||
|                 newAssetID = assetID; | ||||
|                 inventoryItemID = inventoryItem; | ||||
|                 uploaderPath = path; | ||||
|                 httpListener = httpServer; | ||||
|                 parentFolder = parentFolderID; | ||||
|                 m_assetType = assetType; | ||||
|                 m_invType = invType; | ||||
|                 m_dumpAssetsToFile = dumpAssetsToFile; | ||||
|             } | ||||
| 
 | ||||
|             /// <summary> | ||||
|             ///  | ||||
|             /// </summary> | ||||
|             /// <param name="data"></param> | ||||
|             /// <param name="path"></param> | ||||
|             /// <param name="param"></param> | ||||
|             /// <returns></returns> | ||||
|             public string uploaderCaps(byte[] data, string path, string param) | ||||
|             { | ||||
|                 LLUUID inv = inventoryItemID; | ||||
|                 string res = String.Empty; | ||||
|                 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||||
|                 uploadComplete.new_asset = newAssetID.ToString(); | ||||
|                 uploadComplete.new_inventory_item = inv; | ||||
|                 uploadComplete.state = "complete"; | ||||
| 
 | ||||
|                 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||||
| 
 | ||||
|                 httpListener.RemoveStreamHandler("POST", uploaderPath); | ||||
| 
 | ||||
|                 if (m_dumpAssetsToFile) | ||||
|                 { | ||||
|                     SaveAssetToFile(m_assetName + ".jp2", data); | ||||
|                 } | ||||
| 
 | ||||
|                 if (OnUpLoad != null) | ||||
|                 { | ||||
|                     OnUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType); | ||||
|                 } | ||||
| 
 | ||||
|                 return res; | ||||
|             } | ||||
|             ///Left this in and commented in case there are unforseen issues | ||||
|             //private void SaveAssetToFile(string filename, byte[] data) | ||||
|             //{ | ||||
|             //    FileStream fs = File.Create(filename); | ||||
|             //    BinaryWriter bw = new BinaryWriter(fs); | ||||
|             //    bw.Write(data); | ||||
|             //    bw.Close(); | ||||
|             //    fs.Close(); | ||||
|             //} | ||||
|             private void SaveAssetToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 string assetPath = "UserAssets"; | ||||
|                 if (!Directory.Exists(assetPath)) | ||||
|                 { | ||||
|                     Directory.CreateDirectory(assetPath); | ||||
|                 } | ||||
|                 FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||||
|                 BinaryWriter bw = new BinaryWriter(fs); | ||||
|                 bw.Write(data); | ||||
|                 bw.Close(); | ||||
|                 fs.Close(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// This class is a callback invoked when a client sends asset data to  | ||||
|         /// an agent inventory notecard update url | ||||
|         /// </summary> | ||||
|         public class ItemUpdater | ||||
|         { | ||||
|             public event UpdateItem OnUpLoad; | ||||
| 
 | ||||
|             private string uploaderPath = String.Empty; | ||||
|             private LLUUID inventoryItemID; | ||||
|             private BaseHttpServer httpListener; | ||||
|             private bool m_dumpAssetToFile; | ||||
| 
 | ||||
|             public ItemUpdater(LLUUID inventoryItem, string path, BaseHttpServer httpServer, bool dumpAssetToFile) | ||||
|             { | ||||
|                 m_dumpAssetToFile = dumpAssetToFile; | ||||
| 
 | ||||
|                 inventoryItemID = inventoryItem; | ||||
|                 uploaderPath = path; | ||||
|                 httpListener = httpServer; | ||||
|             } | ||||
| 
 | ||||
|             /// <summary> | ||||
|             ///  | ||||
|             /// </summary> | ||||
|             /// <param name="data"></param> | ||||
|             /// <param name="path"></param> | ||||
|             /// <param name="param"></param> | ||||
|             /// <returns></returns> | ||||
|             public string uploaderCaps(byte[] data, string path, string param) | ||||
|             { | ||||
|                 LLUUID inv = inventoryItemID; | ||||
|                 string res = String.Empty; | ||||
|                 LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||||
|                 LLUUID assetID = LLUUID.Zero; | ||||
| 
 | ||||
|                 if (OnUpLoad != null) | ||||
|                 { | ||||
|                     assetID = OnUpLoad(inv, data); | ||||
|                 } | ||||
| 
 | ||||
|                 uploadComplete.new_asset = assetID.ToString(); | ||||
|                 uploadComplete.new_inventory_item = inv; | ||||
|                 uploadComplete.state = "complete"; | ||||
| 
 | ||||
|                 res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||||
| 
 | ||||
|                 httpListener.RemoveStreamHandler("POST", uploaderPath); | ||||
| 
 | ||||
|                 if (m_dumpAssetToFile) | ||||
|                 { | ||||
|                     SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data); | ||||
|                 } | ||||
| 
 | ||||
|                 return res; | ||||
|             } | ||||
|             ///Left this in and commented in case there are unforseen issues | ||||
|             //private void SaveAssetToFile(string filename, byte[] data) | ||||
|             //{ | ||||
|             //    FileStream fs = File.Create(filename); | ||||
|             //    BinaryWriter bw = new BinaryWriter(fs); | ||||
|             //    bw.Write(data); | ||||
|             //    bw.Close(); | ||||
|             //    fs.Close(); | ||||
|             //} | ||||
|             private void SaveAssetToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 string assetPath = "UserAssets"; | ||||
|                 if (!Directory.Exists(assetPath)) | ||||
|                 { | ||||
|                     Directory.CreateDirectory(assetPath); | ||||
|                 } | ||||
|                 FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||||
|                 BinaryWriter bw = new BinaryWriter(fs); | ||||
|                 bw.Write(data); | ||||
|                 bw.Close(); | ||||
|                 fs.Close(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// This class is a callback invoked when a client sends asset data to  | ||||
|         /// a task inventory script update url | ||||
|         /// </summary> | ||||
|         public class TaskInventoryScriptUpdater | ||||
|         { | ||||
|             public event UpdateTaskScript OnUpLoad; | ||||
| 
 | ||||
|             private string uploaderPath = String.Empty; | ||||
|             private LLUUID inventoryItemID; | ||||
|             private LLUUID primID; | ||||
|             private bool isScriptRunning; | ||||
|             private BaseHttpServer httpListener; | ||||
|             private bool m_dumpAssetToFile; | ||||
| 
 | ||||
|             public TaskInventoryScriptUpdater(LLUUID inventoryItemID, LLUUID primID, int isScriptRunning, | ||||
|                                               string path, BaseHttpServer httpServer, bool dumpAssetToFile) | ||||
|             { | ||||
|                 m_dumpAssetToFile = dumpAssetToFile; | ||||
| 
 | ||||
|                 this.inventoryItemID = inventoryItemID; | ||||
|                 this.primID = primID; | ||||
| 
 | ||||
|                 // This comes in over the packet as an integer, but actually appears to be treated as a bool | ||||
|                 this.isScriptRunning = (0 == isScriptRunning ? false : true); | ||||
| 
 | ||||
|                 uploaderPath = path; | ||||
|                 httpListener = httpServer; | ||||
|             } | ||||
| 
 | ||||
|             /// <summary> | ||||
|             ///  | ||||
|             /// </summary> | ||||
|             /// <param name="data"></param> | ||||
|             /// <param name="path"></param> | ||||
|             /// <param name="param"></param> | ||||
|             /// <returns></returns> | ||||
|             public string uploaderCaps(byte[] data, string path, string param) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
| //                    m_log.InfoFormat("[CAPS]: " +  | ||||
| //                                     "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}", | ||||
| //                                     data, path, param)); | ||||
| 
 | ||||
|                     string res = String.Empty; | ||||
|                     LLSDTaskInventoryUploadComplete uploadComplete = new LLSDTaskInventoryUploadComplete(); | ||||
| 
 | ||||
|                     if (OnUpLoad != null) | ||||
|                     { | ||||
|                         OnUpLoad(inventoryItemID, primID, isScriptRunning, data); | ||||
|                     } | ||||
| 
 | ||||
|                     uploadComplete.item_id = inventoryItemID; | ||||
|                     uploadComplete.task_id = primID; | ||||
|                     uploadComplete.state = "complete"; | ||||
| 
 | ||||
|                     res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||||
| 
 | ||||
|                     httpListener.RemoveStreamHandler("POST", uploaderPath); | ||||
| 
 | ||||
|                     if (m_dumpAssetToFile) | ||||
|                     { | ||||
|                         SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data); | ||||
|                     } | ||||
| 
 | ||||
| //                    m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res); | ||||
| 
 | ||||
|                     return res; | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Error("[CAPS]: " + e.ToString()); | ||||
|                 } | ||||
| 
 | ||||
|                 // XXX Maybe this should be some meaningful error packet | ||||
|                 return null; | ||||
|             } | ||||
|             ///Left this in and commented in case there are unforseen issues | ||||
|             //private void SaveAssetToFile(string filename, byte[] data) | ||||
|             //{ | ||||
|             //    FileStream fs = File.Create(filename); | ||||
|             //    BinaryWriter bw = new BinaryWriter(fs); | ||||
|             //    bw.Write(data); | ||||
|             //    bw.Close(); | ||||
|             //    fs.Close(); | ||||
|             //} | ||||
|             private void SaveAssetToFile(string filename, byte[] data) | ||||
|             { | ||||
|                 string assetPath = "UserAssets"; | ||||
|                 if (!Directory.Exists(assetPath)) | ||||
|                 { | ||||
|                     Directory.CreateDirectory(assetPath); | ||||
|                 } | ||||
|                 FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||||
|                 BinaryWriter bw = new BinaryWriter(fs); | ||||
|                 bw.Write(data); | ||||
|                 bw.Close(); | ||||
|                 fs.Close(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,680 @@ | |||
| /* | ||||
| * 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.Globalization; | ||||
| using System.IO; | ||||
| using System.Security.Cryptography; | ||||
| using System.Text; | ||||
| using System.Xml; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Borrowed from (a older version of ) libsl for now, as their new llsd code doesn't work we our decoding code.  | ||||
|     /// </summary> | ||||
|     public static class LLSD | ||||
|     { | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         public class LLSDParseException : Exception | ||||
|         { | ||||
|             public LLSDParseException(string message) : base(message) | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         public class LLSDSerializeException : Exception | ||||
|         { | ||||
|             public LLSDSerializeException(string message) : base(message) | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="b"></param> | ||||
|         /// <returns></returns> | ||||
|         public static object LLSDDeserialize(byte[] b) | ||||
|         { | ||||
|             return LLSDDeserialize(new MemoryStream(b, false)); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="st"></param> | ||||
|         /// <returns></returns> | ||||
|         public static object LLSDDeserialize(Stream st) | ||||
|         { | ||||
|             XmlTextReader reader = new XmlTextReader(st); | ||||
|             reader.Read(); | ||||
|             SkipWS(reader); | ||||
| 
 | ||||
|             if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "llsd") | ||||
|                 throw new LLSDParseException("Expected <llsd>"); | ||||
| 
 | ||||
|             reader.Read(); | ||||
|             object ret = LLSDParseOne(reader); | ||||
|             SkipWS(reader); | ||||
| 
 | ||||
|             if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != "llsd") | ||||
|                 throw new LLSDParseException("Expected </llsd>"); | ||||
| 
 | ||||
|             return ret; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="obj"></param> | ||||
|         /// <returns></returns> | ||||
|         public static byte[] LLSDSerialize(object obj) | ||||
|         { | ||||
|             StringWriter sw = new StringWriter(); | ||||
|             XmlTextWriter writer = new XmlTextWriter(sw); | ||||
|             writer.Formatting = Formatting.None; | ||||
| 
 | ||||
|             writer.WriteStartElement(String.Empty, "llsd", String.Empty); | ||||
|             LLSDWriteOne(writer, obj); | ||||
|             writer.WriteEndElement(); | ||||
| 
 | ||||
|             writer.Close(); | ||||
| 
 | ||||
|             return Encoding.UTF8.GetBytes(sw.ToString()); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="writer"></param> | ||||
|         /// <param name="obj"></param> | ||||
|         public static void LLSDWriteOne(XmlTextWriter writer, object obj) | ||||
|         { | ||||
|             if (obj == null) | ||||
|             { | ||||
|                 writer.WriteStartElement(String.Empty, "undef", String.Empty); | ||||
|                 writer.WriteEndElement(); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if (obj is string) | ||||
|             { | ||||
|                 writer.WriteStartElement(String.Empty, "string", String.Empty); | ||||
|                 writer.WriteString((string) obj); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is int) | ||||
|             { | ||||
|                 writer.WriteStartElement(String.Empty, "integer", String.Empty); | ||||
|                 writer.WriteString(obj.ToString()); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is double) | ||||
|             { | ||||
|                 writer.WriteStartElement(String.Empty, "real", String.Empty); | ||||
|                 writer.WriteString(obj.ToString()); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is bool) | ||||
|             { | ||||
|                 bool b = (bool) obj; | ||||
|                 writer.WriteStartElement(String.Empty, "boolean", String.Empty); | ||||
|                 writer.WriteString(b ? "1" : "0"); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is ulong) | ||||
|             { | ||||
|                 throw new Exception("ulong in LLSD is currently not implemented, fix me!"); | ||||
|             } | ||||
|             else if (obj is LLUUID) | ||||
|             { | ||||
|                 LLUUID u = (LLUUID) obj; | ||||
|                 writer.WriteStartElement(String.Empty, "uuid", String.Empty); | ||||
|                 writer.WriteString(u.ToString()); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is Hashtable) | ||||
|             { | ||||
|                 Hashtable h = obj as Hashtable; | ||||
|                 writer.WriteStartElement(String.Empty, "map", String.Empty); | ||||
|                 foreach (string key in h.Keys) | ||||
|                 { | ||||
|                     writer.WriteStartElement(String.Empty, "key", String.Empty); | ||||
|                     writer.WriteString(key); | ||||
|                     writer.WriteEndElement(); | ||||
|                     LLSDWriteOne(writer, h[key]); | ||||
|                 } | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is ArrayList) | ||||
|             { | ||||
|                 ArrayList a = obj as ArrayList; | ||||
|                 writer.WriteStartElement(String.Empty, "array", String.Empty); | ||||
|                 foreach (object item in a) | ||||
|                 { | ||||
|                     LLSDWriteOne(writer, item); | ||||
|                 } | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else if (obj is byte[]) | ||||
|             { | ||||
|                 byte[] b = obj as byte[]; | ||||
|                 writer.WriteStartElement(String.Empty, "binary", String.Empty); | ||||
| 
 | ||||
|                 writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); | ||||
|                 writer.WriteString("base64"); | ||||
|                 writer.WriteEndAttribute(); | ||||
| 
 | ||||
|                 //// Calculate the length of the base64 output | ||||
|                 //long length = (long)(4.0d * b.Length / 3.0d); | ||||
|                 //if (length % 4 != 0) length += 4 - (length % 4); | ||||
| 
 | ||||
|                 //// Create the char[] for base64 output and fill it | ||||
|                 //char[] tmp = new char[length]; | ||||
|                 //int i = Convert.ToBase64CharArray(b, 0, b.Length, tmp, 0); | ||||
| 
 | ||||
|                 //writer.WriteString(new String(tmp)); | ||||
| 
 | ||||
|                 writer.WriteString(Convert.ToBase64String(b)); | ||||
|                 writer.WriteEndElement(); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 throw new LLSDSerializeException("Unknown type " + obj.GetType().Name); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="reader"></param> | ||||
|         /// <returns></returns> | ||||
|         public static object LLSDParseOne(XmlTextReader reader) | ||||
|         { | ||||
|             SkipWS(reader); | ||||
|             if (reader.NodeType != XmlNodeType.Element) | ||||
|                 throw new LLSDParseException("Expected an element"); | ||||
| 
 | ||||
|             string dtype = reader.LocalName; | ||||
|             object ret = null; | ||||
| 
 | ||||
|             switch (dtype) | ||||
|             { | ||||
|                 case "undef": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return null; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         SkipWS(reader); | ||||
|                         ret = null; | ||||
|                         break; | ||||
|                     } | ||||
|                 case "boolean": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return false; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         string s = reader.ReadString().Trim(); | ||||
| 
 | ||||
|                         if (s == String.Empty || s == "false" || s == "0") | ||||
|                             ret = false; | ||||
|                         else if (s == "true" || s == "1") | ||||
|                             ret = true; | ||||
|                         else | ||||
|                             throw new LLSDParseException("Bad boolean value " + s); | ||||
| 
 | ||||
|                         break; | ||||
|                     } | ||||
|                 case "integer": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return 0; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         ret = Convert.ToInt32(reader.ReadString().Trim()); | ||||
|                         break; | ||||
|                     } | ||||
|                 case "real": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return 0.0f; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         ret = Convert.ToDouble(reader.ReadString().Trim()); | ||||
|                         break; | ||||
|                     } | ||||
|                 case "uuid": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return LLUUID.Zero; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         ret = new LLUUID(reader.ReadString().Trim()); | ||||
|                         break; | ||||
|                     } | ||||
|                 case "string": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return String.Empty; | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         ret = reader.ReadString(); | ||||
|                         break; | ||||
|                     } | ||||
|                 case "binary": | ||||
|                     { | ||||
|                         if (reader.IsEmptyElement) | ||||
|                         { | ||||
|                             reader.Read(); | ||||
|                             return new byte[0]; | ||||
|                         } | ||||
| 
 | ||||
|                         if (reader.GetAttribute("encoding") != null && | ||||
|                             reader.GetAttribute("encoding") != "base64") | ||||
|                         { | ||||
|                             throw new LLSDParseException("Unknown encoding: " + reader.GetAttribute("encoding")); | ||||
|                         } | ||||
| 
 | ||||
|                         reader.Read(); | ||||
|                         FromBase64Transform b64 = new FromBase64Transform(FromBase64TransformMode.IgnoreWhiteSpaces); | ||||
|                         byte[] inp = Encoding.ASCII.GetBytes(reader.ReadString()); | ||||
|                         ret = b64.TransformFinalBlock(inp, 0, inp.Length); | ||||
|                         break; | ||||
|                     } | ||||
|                 case "date": | ||||
|                     { | ||||
|                         reader.Read(); | ||||
|                         throw new Exception("LLSD TODO: date"); | ||||
|                     } | ||||
|                 case "map": | ||||
|                     { | ||||
|                         return LLSDParseMap(reader); | ||||
|                     } | ||||
|                 case "array": | ||||
|                     { | ||||
|                         return LLSDParseArray(reader); | ||||
|                     } | ||||
|                 default: | ||||
|                     throw new LLSDParseException("Unknown element <" + dtype + ">"); | ||||
|             } | ||||
| 
 | ||||
|             if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != dtype) | ||||
|             { | ||||
|                 throw new LLSDParseException("Expected </" + dtype + ">"); | ||||
|             } | ||||
| 
 | ||||
|             reader.Read(); | ||||
|             return ret; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="reader"></param> | ||||
|         /// <returns></returns> | ||||
|         public static Hashtable LLSDParseMap(XmlTextReader reader) | ||||
|         { | ||||
|             Hashtable ret = new Hashtable(); | ||||
| 
 | ||||
|             if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "map") | ||||
|                 throw new LLSDParseException("Expected <map>"); | ||||
| 
 | ||||
|             if (reader.IsEmptyElement) | ||||
|             { | ||||
|                 reader.Read(); | ||||
|                 return ret; | ||||
|             } | ||||
| 
 | ||||
|             reader.Read(); | ||||
| 
 | ||||
|             while (true) | ||||
|             { | ||||
|                 SkipWS(reader); | ||||
|                 if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "map") | ||||
|                 { | ||||
|                     reader.Read(); | ||||
|                     break; | ||||
|                 } | ||||
| 
 | ||||
|                 if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "key") | ||||
|                     throw new LLSDParseException("Expected <key>"); | ||||
| 
 | ||||
|                 string key = reader.ReadString(); | ||||
| 
 | ||||
|                 if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != "key") | ||||
|                     throw new LLSDParseException("Expected </key>"); | ||||
| 
 | ||||
|                 reader.Read(); | ||||
|                 object val = LLSDParseOne(reader); | ||||
|                 ret[key] = val; | ||||
|             } | ||||
| 
 | ||||
|             return ret; // TODO | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="reader"></param> | ||||
|         /// <returns></returns> | ||||
|         public static ArrayList LLSDParseArray(XmlTextReader reader) | ||||
|         { | ||||
|             ArrayList ret = new ArrayList(); | ||||
| 
 | ||||
|             if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "array") | ||||
|                 throw new LLSDParseException("Expected <array>"); | ||||
| 
 | ||||
|             if (reader.IsEmptyElement) | ||||
|             { | ||||
|                 reader.Read(); | ||||
|                 return ret; | ||||
|             } | ||||
| 
 | ||||
|             reader.Read(); | ||||
| 
 | ||||
|             while (true) | ||||
|             { | ||||
|                 SkipWS(reader); | ||||
| 
 | ||||
|                 if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "array") | ||||
|                 { | ||||
|                     reader.Read(); | ||||
|                     break; | ||||
|                 } | ||||
| 
 | ||||
|                 ret.Insert(ret.Count, LLSDParseOne(reader)); | ||||
|             } | ||||
| 
 | ||||
|             return ret; // TODO | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="count"></param> | ||||
|         /// <returns></returns> | ||||
|         private static string GetSpaces(int count) | ||||
|         { | ||||
|             StringBuilder b = new StringBuilder(); | ||||
|             for (int i = 0; i < count; i++) b.Append(" "); | ||||
|             return b.ToString(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="obj"></param> | ||||
|         /// <param name="indent"></param> | ||||
|         /// <returns></returns> | ||||
|         public static String LLSDDump(object obj, int indent) | ||||
|         { | ||||
|             if (obj == null) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- undef\n"; | ||||
|             } | ||||
|             else if (obj is string) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- string \"" + (string) obj + "\"\n"; | ||||
|             } | ||||
|             else if (obj is int) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- integer " + obj.ToString() + "\n"; | ||||
|             } | ||||
|             else if (obj is double) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- float " + obj.ToString() + "\n"; | ||||
|             } | ||||
|             else if (obj is LLUUID) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- uuid " + ((LLUUID) obj).ToString() + Environment.NewLine; | ||||
|             } | ||||
|             else if (obj is Hashtable) | ||||
|             { | ||||
|                 StringBuilder ret = new StringBuilder(); | ||||
|                 ret.Append(GetSpaces(indent) + "- map" + Environment.NewLine); | ||||
|                 Hashtable map = (Hashtable) obj; | ||||
| 
 | ||||
|                 foreach (string key in map.Keys) | ||||
|                 { | ||||
|                     ret.Append(GetSpaces(indent + 2) + "- key \"" + key + "\"" + Environment.NewLine); | ||||
|                     ret.Append(LLSDDump(map[key], indent + 3)); | ||||
|                 } | ||||
| 
 | ||||
|                 return ret.ToString(); | ||||
|             } | ||||
|             else if (obj is ArrayList) | ||||
|             { | ||||
|                 StringBuilder ret = new StringBuilder(); | ||||
|                 ret.Append(GetSpaces(indent) + "- array\n"); | ||||
|                 ArrayList list = (ArrayList) obj; | ||||
| 
 | ||||
|                 foreach (object item in list) | ||||
|                 { | ||||
|                     ret.Append(LLSDDump(item, indent + 2)); | ||||
|                 } | ||||
| 
 | ||||
|                 return ret.ToString(); | ||||
|             } | ||||
|             else if (obj is byte[]) | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- binary\n" + Helpers.FieldToHexString((byte[]) obj, GetSpaces(indent)) + | ||||
|                        Environment.NewLine; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return GetSpaces(indent) + "- unknown type " + obj.GetType().Name + Environment.NewLine; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public static object ParseTerseLLSD(string llsd) | ||||
|         { | ||||
|             int notused; | ||||
|             return ParseTerseLLSD(llsd, out notused); | ||||
|         } | ||||
| 
 | ||||
|         public static object ParseTerseLLSD(string llsd, out int endPos) | ||||
|         { | ||||
|             if (llsd.Length == 0) | ||||
|             { | ||||
|                 endPos = 0; | ||||
|                 return null; | ||||
|             } | ||||
| 
 | ||||
|             // Identify what type of object this is | ||||
|             switch (llsd[0]) | ||||
|             { | ||||
|                 case '!': | ||||
|                     throw new LLSDParseException("Undefined value type encountered"); | ||||
|                 case '1': | ||||
|                     endPos = 1; | ||||
|                     return true; | ||||
|                 case '0': | ||||
|                     endPos = 1; | ||||
|                     return false; | ||||
|                 case 'i': | ||||
|                     { | ||||
|                         if (llsd.Length < 2) throw new LLSDParseException("Integer value type with no value"); | ||||
|                         int value; | ||||
|                         endPos = FindEnd(llsd, 1); | ||||
| 
 | ||||
|                         if (Int32.TryParse(llsd.Substring(1, endPos - 1), out value)) | ||||
|                             return value; | ||||
|                         else | ||||
|                             throw new LLSDParseException("Failed to parse integer value type"); | ||||
|                     } | ||||
|                 case 'r': | ||||
|                     { | ||||
|                         if (llsd.Length < 2) throw new LLSDParseException("Real value type with no value"); | ||||
|                         double value; | ||||
|                         endPos = FindEnd(llsd, 1); | ||||
| 
 | ||||
|                         if (Double.TryParse(llsd.Substring(1, endPos - 1), NumberStyles.Float, | ||||
|                                             Helpers.EnUsCulture.NumberFormat, out value)) | ||||
|                             return value; | ||||
|                         else | ||||
|                             throw new LLSDParseException("Failed to parse double value type"); | ||||
|                     } | ||||
|                 case 'u': | ||||
|                     { | ||||
|                         if (llsd.Length < 17) throw new LLSDParseException("LLUUID value type with no value"); | ||||
|                         LLUUID value; | ||||
|                         endPos = FindEnd(llsd, 1); | ||||
| 
 | ||||
|                         if (LLUUID.TryParse(llsd.Substring(1, endPos - 1), out value)) | ||||
|                             return value; | ||||
|                         else | ||||
|                             throw new LLSDParseException("Failed to parse LLUUID value type"); | ||||
|                     } | ||||
|                 case 'b': | ||||
|                     //byte[] value = new byte[llsd.Length - 1]; | ||||
|                     // This isn't the actual binary LLSD format, just the terse format sent | ||||
|                     // at login so I don't even know if there is a binary type | ||||
|                     throw new LLSDParseException("Binary value type is unimplemented"); | ||||
|                 case 's': | ||||
|                 case 'l': | ||||
|                     if (llsd.Length < 2) throw new LLSDParseException("String value type with no value"); | ||||
|                     endPos = FindEnd(llsd, 1); | ||||
|                     return llsd.Substring(1, endPos - 1); | ||||
|                 case 'd': | ||||
|                     // Never seen one before, don't know what the format is | ||||
|                     throw new LLSDParseException("Date value type is unimplemented"); | ||||
|                 case '[': | ||||
|                     { | ||||
|                         if (llsd.IndexOf(']') == -1) throw new LLSDParseException("Invalid array"); | ||||
| 
 | ||||
|                         int pos = 0; | ||||
|                         ArrayList array = new ArrayList(); | ||||
| 
 | ||||
|                         while (llsd[pos] != ']') | ||||
|                         { | ||||
|                             ++pos; | ||||
| 
 | ||||
|                             // Advance past comma if need be | ||||
|                             if (llsd[pos] == ',') ++pos; | ||||
| 
 | ||||
|                             // Allow a single whitespace character | ||||
|                             if (pos < llsd.Length && llsd[pos] == ' ') ++pos; | ||||
| 
 | ||||
|                             int end; | ||||
|                             array.Add(ParseTerseLLSD(llsd.Substring(pos), out end)); | ||||
|                             pos += end; | ||||
|                         } | ||||
| 
 | ||||
|                         endPos = pos + 1; | ||||
|                         return array; | ||||
|                     } | ||||
|                 case '{': | ||||
|                     { | ||||
|                         if (llsd.IndexOf('}') == -1) throw new LLSDParseException("Invalid map"); | ||||
| 
 | ||||
|                         int pos = 0; | ||||
|                         Hashtable hashtable = new Hashtable(); | ||||
| 
 | ||||
|                         while (llsd[pos] != '}') | ||||
|                         { | ||||
|                             ++pos; | ||||
| 
 | ||||
|                             // Advance past comma if need be | ||||
|                             if (llsd[pos] == ',') ++pos; | ||||
| 
 | ||||
|                             // Allow a single whitespace character | ||||
|                             if (pos < llsd.Length && llsd[pos] == ' ') ++pos; | ||||
| 
 | ||||
|                             if (llsd[pos] != '\'') throw new LLSDParseException("Expected a map key"); | ||||
|                             int endquote = llsd.IndexOf('\'', pos + 1); | ||||
|                             if (endquote == -1 || (endquote + 1) >= llsd.Length || llsd[endquote + 1] != ':') | ||||
|                                 throw new LLSDParseException("Invalid map format"); | ||||
|                             string key = llsd.Substring(pos, endquote - pos); | ||||
|                             key = key.Replace("'", String.Empty); | ||||
|                             pos += (endquote - pos) + 2; | ||||
| 
 | ||||
|                             int end; | ||||
|                             hashtable.Add(key, ParseTerseLLSD(llsd.Substring(pos), out end)); | ||||
|                             pos += end; | ||||
|                         } | ||||
| 
 | ||||
|                         endPos = pos + 1; | ||||
|                         return hashtable; | ||||
|                     } | ||||
|                 default: | ||||
|                     throw new Exception("Unknown value type"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private static int FindEnd(string llsd, int start) | ||||
|         { | ||||
|             int end = llsd.IndexOfAny(new char[] {',', ']', '}'}); | ||||
|             if (end == -1) end = llsd.Length - 1; | ||||
|             return end; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="reader"></param> | ||||
|         private static void SkipWS(XmlTextReader reader) | ||||
|         { | ||||
|             while ( | ||||
|                 reader.NodeType == XmlNodeType.Comment || | ||||
|                 reader.NodeType == XmlNodeType.Whitespace || | ||||
|                 reader.NodeType == XmlNodeType.SignificantWhitespace || | ||||
|                 reader.NodeType == XmlNodeType.XmlDeclaration) | ||||
|             { | ||||
|                 reader.Read(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,41 @@ | |||
| /* | ||||
| * 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.Collections; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("ARRAY")] | ||||
|     public class LLSDArray | ||||
|     { | ||||
|         public ArrayList Array = new ArrayList(); | ||||
| 
 | ||||
|         public LLSDArray() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,45 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| using System; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDAssetUploadComplete | ||||
|     { | ||||
|         public string new_asset = String.Empty; | ||||
|         public LLUUID new_inventory_item = LLUUID.Zero; | ||||
|         public string state = String.Empty; | ||||
|         //public bool success = false; | ||||
| 
 | ||||
|         public LLSDAssetUploadComplete() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,46 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDMap] | ||||
|     public class LLSDAssetUploadRequest | ||||
|     { | ||||
|         public string asset_type = System.String.Empty; | ||||
|         public string description = System.String.Empty; | ||||
|         public LLUUID folder_id = LLUUID.Zero; | ||||
|         public string inventory_type = System.String.Empty; | ||||
|         public string name = System.String.Empty; | ||||
| 
 | ||||
|         public LLSDAssetUploadRequest() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,41 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDMap] | ||||
|     public class LLSDAssetUploadResponse | ||||
|     { | ||||
|         public string uploader = System.String.Empty; | ||||
|         public string state = System.String.Empty; | ||||
| 
 | ||||
|         public LLSDAssetUploadResponse() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,40 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDCapEvent | ||||
|     { | ||||
|         public int id = 0; | ||||
|         public LLSDArray events = new LLSDArray(); | ||||
| 
 | ||||
|         public LLSDCapEvent() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,50 @@ | |||
| /* | ||||
| * 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; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDCapsDetails | ||||
|     { | ||||
|         public string MapLayer = String.Empty; | ||||
|         public string NewFileAgentInventory = String.Empty; | ||||
|         //public string EventQueueGet = String.Empty; | ||||
|         // public string RequestTextureDownload = String.Empty; | ||||
|         // public string ChatSessionRequest = String.Empty; | ||||
|         public string UpdateNotecardAgentInventory = String.Empty; | ||||
|         public string UpdateScriptAgentInventory = String.Empty; | ||||
|         public string UpdateScriptTaskInventory = String.Empty; | ||||
|         // public string ParcelVoiceInfoRequest = String.Empty; | ||||
| 
 | ||||
|         public LLSDCapsDetails() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,37 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDEmpty | ||||
|     { | ||||
|         public LLSDEmpty() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,151 @@ | |||
| /* | ||||
| * 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.Xml; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     public class LLSDHelpers | ||||
|     { | ||||
|         public static string SerialiseLLSDReply(object obj) | ||||
|         { | ||||
|             StringWriter sw = new StringWriter(); | ||||
|             XmlTextWriter writer = new XmlTextWriter(sw); | ||||
|             writer.Formatting = Formatting.None; | ||||
|             writer.WriteStartElement(String.Empty, "llsd", String.Empty); | ||||
|             SerializeLLSDType(writer, obj); | ||||
|             writer.WriteEndElement(); | ||||
|             writer.Close(); | ||||
|             return sw.ToString(); | ||||
|         } | ||||
| 
 | ||||
|         private static void SerializeLLSDType(XmlTextWriter writer, object obj) | ||||
|         { | ||||
|             Type myType = obj.GetType(); | ||||
|             LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); | ||||
|             if (llsdattributes.Length > 0) | ||||
|             { | ||||
|                 switch (llsdattributes[0].ObjectType) | ||||
|                 { | ||||
|                     case "MAP": | ||||
|                         writer.WriteStartElement(String.Empty, "map", String.Empty); | ||||
|                         FieldInfo[] fields = myType.GetFields(); | ||||
|                         for (int i = 0; i < fields.Length; i++) | ||||
|                         { | ||||
|                             object fieldValue = fields[i].GetValue(obj); | ||||
|                             LLSDType[] fieldAttributes = | ||||
|                                 (LLSDType[]) fieldValue.GetType().GetCustomAttributes(typeof (LLSDType), false); | ||||
|                             if (fieldAttributes.Length > 0) | ||||
|                             { | ||||
|                                 writer.WriteStartElement(String.Empty, "key", String.Empty); | ||||
|                                 writer.WriteString(fields[i].Name); | ||||
|                                 writer.WriteEndElement(); | ||||
|                                 SerializeLLSDType(writer, fieldValue); | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 writer.WriteStartElement(String.Empty, "key", String.Empty); | ||||
|                                 writer.WriteString(fields[i].Name); | ||||
|                                 writer.WriteEndElement(); | ||||
|                                 LLSD.LLSDWriteOne(writer, fieldValue); | ||||
|                                 // libsecondlife.StructuredData.LLSDParser.SerializeXmlElement( | ||||
|                                 //    writer, libsecondlife.StructuredData.LLSD.FromObject(fieldValue)); | ||||
|                             } | ||||
|                         } | ||||
|                         writer.WriteEndElement(); | ||||
|                         break; | ||||
|                     case "ARRAY": | ||||
|                         // LLSDArray arrayObject = obj as LLSDArray; | ||||
|                         // ArrayList a = arrayObject.Array; | ||||
|                         ArrayList a = (ArrayList) obj.GetType().GetField("Array").GetValue(obj); | ||||
|                         if (a != null) | ||||
|                         { | ||||
|                             writer.WriteStartElement(String.Empty, "array", String.Empty); | ||||
|                             foreach (object item in a) | ||||
|                             { | ||||
|                                 SerializeLLSDType(writer, item); | ||||
|                             } | ||||
|                             writer.WriteEndElement(); | ||||
|                         } | ||||
|                         break; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 LLSD.LLSDWriteOne(writer, obj); | ||||
|                 //libsecondlife.StructuredData.LLSDParser.SerializeXmlElement( | ||||
|                 //    writer, libsecondlife.StructuredData.LLSD.FromObject(obj)); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public static object DeserialiseLLSDMap(Hashtable llsd, object obj) | ||||
|         { | ||||
|             Type myType = obj.GetType(); | ||||
|             LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); | ||||
|             if (llsdattributes.Length > 0) | ||||
|             { | ||||
|                 switch (llsdattributes[0].ObjectType) | ||||
|                 { | ||||
|                     case "MAP": | ||||
|                         IDictionaryEnumerator enumerator = llsd.GetEnumerator(); | ||||
|                         while (enumerator.MoveNext()) | ||||
|                         { | ||||
|                             FieldInfo field = myType.GetField((string) enumerator.Key); | ||||
|                             if (field != null) | ||||
|                             { | ||||
|                                 // if (enumerator.Value is libsecondlife.StructuredData.LLSDMap) | ||||
|                                 if (enumerator.Value is Hashtable) | ||||
|                                 { | ||||
|                                     object fieldValue = field.GetValue(obj); | ||||
|                                     DeserialiseLLSDMap((Hashtable) enumerator.Value, fieldValue); | ||||
|                                     //  DeserialiseLLSDMap((libsecondlife.StructuredData.LLSDMap) enumerator.Value, fieldValue); | ||||
|                                 } | ||||
|                                 else if (enumerator.Value is ArrayList) | ||||
|                                 { | ||||
|                                     object fieldValue = field.GetValue(obj); | ||||
|                                     fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value); | ||||
|                                     //TODO | ||||
|                                     // the LLSD map/array types in the array need to be deserialised | ||||
|                                     // but first we need to know the right class to deserialise them into.  | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     field.SetValue(obj, enumerator.Value); | ||||
|                                 } | ||||
|                             } | ||||
|                         } | ||||
|                         break; | ||||
|                 } | ||||
|             } | ||||
|             return obj; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,42 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDMap] | ||||
|     public class LLSDItemUpdate | ||||
|     { | ||||
|         public LLUUID item_id; | ||||
| 
 | ||||
|         public LLSDItemUpdate() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,45 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDMapLayer | ||||
|     { | ||||
|         public int Left = 0; | ||||
|         public int Right = 0; | ||||
|         public int Top = 0; | ||||
|         public int Bottom = 0; | ||||
|         public LLUUID ImageID = LLUUID.Zero; | ||||
| 
 | ||||
|         public LLSDMapLayer() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,40 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDMapLayerResponse | ||||
|     { | ||||
|         public LLSDMapRequest AgentData = new LLSDMapRequest(); | ||||
|         public LLSDArray LayerData = new LLSDArray(); | ||||
| 
 | ||||
|         public LLSDMapLayerResponse() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,40 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDMapRequest | ||||
|     { | ||||
|         public int Flags = 0; | ||||
| 
 | ||||
|         public LLSDMapRequest() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,32 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     public delegate TResponse LLSDMethod<TRequest, TResponse>(TRequest request); | ||||
| } | ||||
|  | @ -0,0 +1,69 @@ | |||
| /* | ||||
| * 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.Collections; | ||||
| using System.IO; | ||||
| using System.Text; | ||||
| using OpenSim.Framework.Servers; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     public class LLSDStreamhandler<TRequest, TResponse> : BaseStreamHandler | ||||
|         where TRequest : new() | ||||
|     { | ||||
|         private LLSDMethod<TRequest, TResponse> m_method; | ||||
| 
 | ||||
|         public LLSDStreamhandler(string httpMethod, string path, LLSDMethod<TRequest, TResponse> method) | ||||
|             : base(httpMethod, path) | ||||
|         { | ||||
|             m_method = method; | ||||
|         } | ||||
| 
 | ||||
|         public override byte[] Handle(string path, Stream request) | ||||
|         { | ||||
|             //Encoding encoding = Encoding.UTF8; | ||||
|             //StreamReader streamReader = new StreamReader(request, false); | ||||
| 
 | ||||
|             //string requestBody = streamReader.ReadToEnd(); | ||||
|             //streamReader.Close(); | ||||
| 
 | ||||
|             // libsecondlife.StructuredData.LLSDMap hash = (libsecondlife.StructuredData.LLSDMap)  | ||||
|             //    libsecondlife.StructuredData.LLSDParser.DeserializeXml(new XmlTextReader(request)); | ||||
| 
 | ||||
|             Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(request); | ||||
|             TRequest llsdRequest = new TRequest(); | ||||
|             LLSDHelpers.DeserialiseLLSDMap(hash, llsdRequest); | ||||
| 
 | ||||
|             TResponse response = m_method(llsdRequest); | ||||
| 
 | ||||
|             Encoding encoding = new UTF8Encoding(false); | ||||
| 
 | ||||
|             return encoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,50 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDMap] | ||||
|     public class LLSDTaskInventoryUploadComplete | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// The task inventory item that was updated | ||||
|         /// </summary>  | ||||
|         public LLUUID item_id; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The task that was updated | ||||
|         /// </summary> | ||||
|         public LLUUID task_id; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// State of the upload.  So far have only even seen this set to "complete" | ||||
|         /// </summary> | ||||
|         public string state; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,51 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDMap] | ||||
|     public class LLSDTaskScriptUpdate | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// The item containing the script to update | ||||
|         /// </summary>  | ||||
|         public LLUUID item_id; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The task containing the script | ||||
|         /// </summary>  | ||||
|         public LLUUID task_id; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Signals whether the script is currently active | ||||
|         /// </summary>  | ||||
|         public int is_script_running; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,40 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [LLSDType("MAP")] | ||||
|     public class LLSDTest | ||||
|     { | ||||
|         public int Test1 = 20; | ||||
|         public int Test2 = 10; | ||||
| 
 | ||||
|         public LLSDTest() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,55 @@ | |||
| /* | ||||
| * 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; | ||||
| 
 | ||||
| namespace OpenSim.Region.Capabilities | ||||
| { | ||||
|     [AttributeUsage(AttributeTargets.Class)] | ||||
|     public class LLSDType : Attribute | ||||
|     { | ||||
|         protected string myType; | ||||
| 
 | ||||
|         public LLSDType(string type) | ||||
|         { | ||||
|             myType = type; | ||||
|         } | ||||
| 
 | ||||
|         public string ObjectType | ||||
|         { | ||||
|             get { return myType; } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     [AttributeUsage(AttributeTargets.Class)] | ||||
|     public class LLSDMap : LLSDType | ||||
|     { | ||||
|         public LLSDMap() : base("MAP") | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,244 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Communications.Cache; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Servers; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public class CommunicationsManager | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         protected IUserService m_userService; | ||||
| 
 | ||||
|         public IUserService UserService | ||||
|         { | ||||
|             get { return m_userService; } | ||||
|         } | ||||
| 
 | ||||
|         protected IGridServices m_gridService; | ||||
| 
 | ||||
|         public IGridServices GridService | ||||
|         { | ||||
|             get { return m_gridService; } | ||||
|         } | ||||
| 
 | ||||
|         protected IInventoryServices m_inventoryService; | ||||
| 
 | ||||
|         public IInventoryServices InventoryService | ||||
|         { | ||||
|             get { return m_inventoryService; } | ||||
|         } | ||||
| 
 | ||||
|         protected IInterRegionCommunications m_interRegion; | ||||
| 
 | ||||
|         public IInterRegionCommunications InterRegion | ||||
|         { | ||||
|             get { return m_interRegion; } | ||||
|         } | ||||
| 
 | ||||
|         protected UserProfileCacheService m_userProfileCacheService; | ||||
| 
 | ||||
|         public UserProfileCacheService UserProfileCacheService | ||||
|         { | ||||
|             get { return m_userProfileCacheService; } | ||||
|         } | ||||
| 
 | ||||
|       //  protected AgentAssetTransactionsManager m_transactionsManager; | ||||
| 
 | ||||
|        // public AgentAssetTransactionsManager TransactionsManager | ||||
|       //  { | ||||
|       //      get { return m_transactionsManager; } | ||||
|       //  } | ||||
| 
 | ||||
|         protected AssetCache m_assetCache; | ||||
| 
 | ||||
|         public AssetCache AssetCache | ||||
|         { | ||||
|             get { return m_assetCache; } | ||||
|         } | ||||
| 
 | ||||
|         protected NetworkServersInfo m_networkServersInfo; | ||||
| 
 | ||||
|         public NetworkServersInfo NetworkServersInfo | ||||
|         { | ||||
|             get { return m_networkServersInfo; } | ||||
|         } | ||||
| 
 | ||||
|         public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer, AssetCache assetCache, | ||||
|                                      bool dumpAssetsToFile) | ||||
|         { | ||||
|             m_networkServersInfo = serversInfo; | ||||
|             m_assetCache = assetCache; | ||||
|             m_userProfileCacheService = new UserProfileCacheService(this); | ||||
|          //   m_transactionsManager = new AgentAssetTransactionsManager(this, dumpAssetsToFile); | ||||
|         } | ||||
| 
 | ||||
|         public void doCreate(string[] cmmdParams) | ||||
|         { | ||||
|             switch (cmmdParams[0]) | ||||
|             { | ||||
|                 case "user": | ||||
|                     string firstName; | ||||
|                     string lastName; | ||||
|                     string password; | ||||
|                     uint regX = 1000; | ||||
|                     uint regY = 1000; | ||||
| 
 | ||||
|                     if (cmmdParams.Length < 2) | ||||
|                     { | ||||
|                         firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||||
|                         lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||||
|                         password = MainConsole.Instance.PasswdPrompt("Password"); | ||||
|                         regX = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region X", "1000")); | ||||
|                         regY = Convert.ToUInt32(MainConsole.Instance.CmdPrompt("Start Region Y", "1000")); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         firstName = cmmdParams[1]; | ||||
|                         lastName = cmmdParams[2]; | ||||
|                         password = cmmdParams[3]; | ||||
|                         regX = Convert.ToUInt32(cmmdParams[4]); | ||||
|                         regY = Convert.ToUInt32(cmmdParams[5]); | ||||
|                     } | ||||
| 
 | ||||
|                     AddUser(firstName, lastName, password, regX, regY); | ||||
|                     break; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public LLUUID AddUser(string firstName, string lastName, string password, uint regX, uint regY) | ||||
|         { | ||||
|             string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty); | ||||
| 
 | ||||
|             m_userService.AddUserProfile(firstName, lastName, md5PasswdHash, regX, regY); | ||||
|             UserProfileData userProf = UserService.GetUserProfile(firstName, lastName); | ||||
|             if (userProf == null) | ||||
|             { | ||||
|                 return LLUUID.Zero; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_inventoryService.CreateNewUserInventory(userProf.UUID); | ||||
|                 System.Console.WriteLine("Created new inventory set for " + firstName + " " + lastName); | ||||
|                 return userProf.UUID; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #region Friend Methods | ||||
|         /// <summary> | ||||
|         /// Adds a new friend to the database for XUser | ||||
|         /// </summary> | ||||
|         /// <param name="friendlistowner">The agent that who's friends list is being added to</param> | ||||
|         /// <param name="friend">The agent that being added to the friends list of the friends list owner</param> | ||||
|         /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param> | ||||
|         public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             m_userService.AddNewUserFriend(friendlistowner, friend, perms); | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Logs off a user and does the appropriate communications | ||||
|         /// </summary> | ||||
|         /// <param name="userid"></param> | ||||
|         /// <param name="regionid"></param> | ||||
|         /// <param name="regionhandle"></param> | ||||
|         /// <param name="posx"></param> | ||||
|         /// <param name="posy"></param> | ||||
|         /// <param name="posz"></param> | ||||
|         public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz) | ||||
|         { | ||||
|             m_userService.LogOffUser(userid, regionid, regionhandle, posx, posy, posz); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Delete friend on friendlistowner's friendlist. | ||||
|         /// </summary> | ||||
|         /// <param name="friendlistowner">The agent that who's friends list is being updated</param> | ||||
|         /// <param name="friend">The Ex-friend agent</param> | ||||
|         public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | ||||
|         { | ||||
|             m_userService.RemoveUserFriend(friendlistowner, friend); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Update permissions for friend on friendlistowner's friendlist. | ||||
|         /// </summary> | ||||
|         /// <param name="friendlistowner">The agent that who's friends list is being updated</param> | ||||
|         /// <param name="friend">The agent that is getting or loosing permissions</param> | ||||
|         /// <param name="perms">A uint bit vector for set perms that the friend being added has; 0 = none, 1=This friend can see when they sign on, 2 = map, 4 edit objects </param> | ||||
|         public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             m_userService.UpdateUserFriendPerms(friendlistowner, friend, perms); | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Returns a list of FriendsListItems that describe the friends and permissions in the friend relationship for LLUUID friendslistowner | ||||
|         /// </summary> | ||||
|         /// <param name="friendlistowner">The agent that we're retreiving the friends Data.</param> | ||||
|         public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) | ||||
|         { | ||||
|             return m_userService.GetUserFriendList(friendlistowner); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region Packet Handlers | ||||
| 
 | ||||
|         public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client) | ||||
|         { | ||||
|             if (uuid == m_userProfileCacheService.libraryRoot.agentID) | ||||
|             { | ||||
|                 remote_client.SendNameReply(uuid, "Mr", "OpenSim"); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 UserProfileData profileData = m_userService.GetUserProfile(uuid); | ||||
|                 if (profileData != null) | ||||
|                 { | ||||
|                     LLUUID profileId = profileData.UUID; | ||||
|                     string firstname = profileData.username; | ||||
|                     string lastname = profileData.surname; | ||||
| 
 | ||||
|                     remote_client.SendNameReply(profileId, firstname, lastname); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query) | ||||
|         { | ||||
|             List<AvatarPickerAvatar> pickerlist = m_userService.GenerateAgentPickerRequestResponse(queryID, query); | ||||
|             return pickerlist; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,42 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public interface IGridServices | ||||
|     { | ||||
|         string gdebugRegionName { get; set; } | ||||
|         RegionCommsListener RegisterRegion(RegionInfo regionInfos); | ||||
|         bool DeregisterRegion(RegionInfo regionInfo); | ||||
|         List<SimpleRegionInfo> RequestNeighbours(uint x, uint y); | ||||
|         RegionInfo RequestNeighbourInfo(ulong regionHandle); | ||||
|         Dictionary<string, string> GetGridSettings(); | ||||
|         List<MapBlockData> RequestNeighbourMapBlocks(int minX, int minY, int maxX, int maxY); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,50 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public interface IInterRegionCommunications | ||||
|     { | ||||
|         string rdebugRegionName { get; set; } | ||||
|         bool Available { get; } | ||||
|         void CheckRegion(string address, uint port); | ||||
|         bool InformRegionOfChildAgent(ulong regionHandle, AgentCircuitData agentData); | ||||
|         bool InformRegionOfPrimCrossing(ulong regionHandle, LLUUID primID, string objData); | ||||
|         bool RegionUp(SearializableRegionInfo region, ulong regionhandle); | ||||
|         bool ChildAgentUpdate(ulong regionHandle, ChildAgentDataUpdate cAgentData); | ||||
| 
 | ||||
|         bool ExpectAvatarCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position, bool isFlying); | ||||
|         bool ExpectPrimCrossing(ulong regionHandle, LLUUID primID, LLVector3 position, bool isFlying); | ||||
| 
 | ||||
|         bool AcknowledgeAgentCrossed(ulong regionHandle, LLUUID agentId); | ||||
|         bool AcknowledgePrimCrossed(ulong regionHandle, LLUUID primID); | ||||
| 
 | ||||
|         bool TellRegionToCloseChildConnection(ulong regionHandle, LLUUID agentID); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,100 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Communications.Cache; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public delegate void InventoryFolderInfo(LLUUID userID, InventoryFolderImpl folderInfo); | ||||
| 
 | ||||
|     public delegate void InventoryItemInfo(LLUUID userID, InventoryItemBase itemInfo); | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Defines all the operations one can perform on a user's inventory. | ||||
|     /// </summary> | ||||
|     public interface IInventoryServices | ||||
|     { | ||||
|         void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack); | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Add a new folder to the given user's inventory | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <param name="folder"></param> | ||||
|         void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder); | ||||
|          | ||||
|         void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder); | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Add a new item to the given user's inventory | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <param name="item"></param> | ||||
|         void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Delete an item from the given user's inventory | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <param name="item"></param> | ||||
|         void DeleteInventoryItem(LLUUID userID, InventoryItemBase item); | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Create a new inventory for the given user | ||||
|         /// </summary> | ||||
|         /// <param name="user"></param> | ||||
|         void CreateNewUserInventory(LLUUID user); | ||||
|          | ||||
|         bool HasInventoryForUser(LLUUID userID); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Retrieve the root inventory folder for the given user. | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <returns>null if no root folder was found</returns> | ||||
|         InventoryFolderBase RequestRootFolder(LLUUID userID); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the root folder plus any folders in root (so down one level in the Inventory folders tree) | ||||
|         /// for the given user. | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <returns></returns> | ||||
|         List<InventoryFolderBase> RequestFirstLevelFolders(LLUUID userID); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the named folder in that users inventory, returns null if folder is not found. | ||||
|         /// </summary> | ||||
|         /// <param name="userID"></param> | ||||
|         /// <param name="folderName"></param> | ||||
|         /// <returns></returns> | ||||
|         InventoryFolderBase RequestNamedFolder(LLUUID userID, string folderName); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,389 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Reflection; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     public abstract class InventoryServiceBase : IInventoryServices | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log  | ||||
|             = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         protected Dictionary<string, IInventoryData> m_plugins = new Dictionary<string, IInventoryData>(); | ||||
| 
 | ||||
|         #region Plugin methods | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Adds a new user server plugin - plugins 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) | ||||
|         { | ||||
|             if (!String.IsNullOrEmpty(FileName)) | ||||
|             { | ||||
|                 m_log.Info("[AGENTINVENTORY]: Inventorystorage: Attempting to load " + FileName); | ||||
|                 Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||||
| 
 | ||||
|                 foreach (Type pluginType in pluginAssembly.GetTypes()) | ||||
|                 { | ||||
|                     if (!pluginType.IsAbstract) | ||||
|                     { | ||||
|                         Type typeInterface = pluginType.GetInterface("IInventoryData", true); | ||||
| 
 | ||||
|                         if (typeInterface != null) | ||||
|                         { | ||||
|                             IInventoryData plug = | ||||
|                                 (IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||||
|                             plug.Initialise(); | ||||
|                             m_plugins.Add(plug.getName(), plug); | ||||
|                             m_log.Info("[AGENTINVENTORY]: Added IInventoryData Interface"); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         #endregion | ||||
|          | ||||
|         #region IInventoryServices methods | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public List<InventoryFolderBase> RequestFirstLevelFolders(Guid rawUserID) | ||||
|         { | ||||
|             LLUUID userID = new LLUUID(rawUserID); | ||||
|             return RequestFirstLevelFolders(userID); | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public List<InventoryFolderBase> RequestFirstLevelFolders(LLUUID userID) | ||||
|         { | ||||
|             List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>(); | ||||
|             InventoryFolderBase rootFolder = null; | ||||
| 
 | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 rootFolder = plugin.Value.getUserRootFolder(userID); | ||||
|                 if (rootFolder != null) | ||||
|                 { | ||||
|                     m_log.Info( | ||||
|                         "[INVENTORY]: Found root folder for user with ID " + userID + ".  Retrieving inventory contents."); | ||||
| 
 | ||||
|                     inventoryList = plugin.Value.getInventoryFolders(rootFolder.folderID); | ||||
|                     inventoryList.Insert(0, rootFolder); | ||||
|                     return inventoryList; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             m_log.Warn( | ||||
|                 "[INVENTORY]: Could not find a root folder belonging to user with ID " + userID); | ||||
| 
 | ||||
|             return inventoryList; | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public InventoryFolderBase RequestUsersRoot(LLUUID userID) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 return plugin.Value.getUserRootFolder(userID); | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public void MoveInventoryFolder(LLUUID userID, InventoryFolderBase folder) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 plugin.Value.moveInventoryFolder(folder); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         public virtual bool HasInventoryForUser(LLUUID userID) | ||||
|         { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public InventoryFolderBase RequestRootFolder(LLUUID userID) | ||||
|         { | ||||
|             return RequestUsersRoot(userID); | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public virtual InventoryFolderBase RequestNamedFolder(LLUUID userID, string folderName) | ||||
|         { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // See IInventoryServices | ||||
|         public void CreateNewUserInventory(LLUUID user) | ||||
|         { | ||||
|             InventoryFolderBase existingRootFolder = RequestUsersRoot(user); | ||||
|              | ||||
|             if (null != existingRootFolder) | ||||
|             { | ||||
|                 m_log.ErrorFormat("[AGENTINVENTORY]: " + | ||||
|                                   "Did not create a new inventory for user {0} since they already have " | ||||
|                                   + "a root inventory folder with id {1}", user, existingRootFolder); | ||||
|             } | ||||
|             else | ||||
|             {                 | ||||
|                 UsersInventory inven = new UsersInventory(); | ||||
|                 inven.CreateNewInventorySet(user); | ||||
|                 AddNewInventorySet(inven); | ||||
|             } | ||||
|         }       | ||||
|          | ||||
|         public abstract void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, | ||||
|                                                      InventoryItemInfo itemCallBack); | ||||
|         public abstract void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder); | ||||
|         public abstract void MoveExistingInventoryFolder(InventoryFolderBase folder); | ||||
|         public abstract void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); | ||||
|         public abstract void DeleteInventoryItem(LLUUID userID, InventoryItemBase item);         | ||||
|          | ||||
|         #endregion | ||||
|          | ||||
|         #region Methods used by GridInventoryService | ||||
| 
 | ||||
|         public List<InventoryFolderBase> RequestSubFolders(LLUUID parentFolderID) | ||||
|         { | ||||
|             List<InventoryFolderBase> inventoryList = new List<InventoryFolderBase>(); | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 return plugin.Value.getInventoryFolders(parentFolderID); | ||||
|             } | ||||
|             return inventoryList; | ||||
|         } | ||||
| 
 | ||||
|         public List<InventoryItemBase> RequestFolderItems(LLUUID folderID) | ||||
|         { | ||||
|             List<InventoryItemBase> itemsList = new List<InventoryItemBase>(); | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 itemsList = plugin.Value.getInventoryInFolder(folderID); | ||||
|                 return itemsList; | ||||
|             } | ||||
|             return itemsList; | ||||
|         } | ||||
|          | ||||
|         #endregion | ||||
| 
 | ||||
|         protected void AddFolder(InventoryFolderBase folder) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 plugin.Value.addInventoryFolder(folder); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected void MoveFolder(InventoryFolderBase folder) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 plugin.Value.moveInventoryFolder(folder); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected void AddItem(InventoryItemBase item) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 plugin.Value.addInventoryItem(item); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected void DeleteItem(InventoryItemBase item) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IInventoryData> plugin in m_plugins) | ||||
|             { | ||||
|                 plugin.Value.deleteInventoryItem(item.inventoryID); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         private void AddNewInventorySet(UsersInventory inventory) | ||||
|         { | ||||
|             foreach (InventoryFolderBase folder in inventory.Folders.Values) | ||||
|             { | ||||
|                 AddFolder(folder); | ||||
|             } | ||||
|         }         | ||||
| 
 | ||||
|         private class UsersInventory | ||||
|         { | ||||
|             public Dictionary<LLUUID, InventoryFolderBase> Folders = new Dictionary<LLUUID, InventoryFolderBase>(); | ||||
|             public Dictionary<LLUUID, InventoryItemBase> Items = new Dictionary<LLUUID, InventoryItemBase>(); | ||||
| 
 | ||||
|             public virtual void CreateNewInventorySet(LLUUID user) | ||||
|             { | ||||
|                 InventoryFolderBase folder = new InventoryFolderBase(); | ||||
| 
 | ||||
|                 folder.parentID = LLUUID.Zero; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "My Inventory"; | ||||
|                 folder.type = 8; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 LLUUID rootFolder = folder.folderID; | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Accessories"; | ||||
|                 folder.type = 8; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Animations"; | ||||
|                 folder.type = 20; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "BodyParts"; | ||||
|                 folder.type = 13; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Clothing"; | ||||
|                 folder.type = 5; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Gestures"; | ||||
|                 folder.type = 21; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Landmarks"; | ||||
|                 folder.type = 3; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Lost And Found"; | ||||
|                 folder.type = 3; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Notecards"; | ||||
|                 folder.type = 7; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Objects"; | ||||
|                 folder.type = 6; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Photo Album"; | ||||
|                 folder.type = 15; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Scripts"; | ||||
|                 folder.type = 10; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Sounds"; | ||||
|                 folder.type = 1; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Textures"; | ||||
|                 folder.type = 0; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
| 
 | ||||
|                 folder = new InventoryFolderBase(); | ||||
|                 folder.parentID = rootFolder; | ||||
|                 folder.agentID = user; | ||||
|                 folder.folderID = LLUUID.Random(); | ||||
|                 folder.name = "Trash"; | ||||
|                 folder.type = 14; | ||||
|                 folder.version = 1; | ||||
|                 Folders.Add(folder.folderID, folder); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,751 @@ | |||
| /* | ||||
| * 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 libsecondlife; | ||||
| using libsecondlife.StructuredData; | ||||
| using Nwc.XmlRpc; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.UserManagement | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A temp class to handle login response. | ||||
|     /// Should make use of UserProfileManager where possible. | ||||
|     /// </summary> | ||||
|     public class LoginResponse | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.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 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 uint 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; | ||||
| 
 | ||||
|         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(); | ||||
| 
 | ||||
|             xmlRpcResponse = new XmlRpcResponse(); | ||||
|             defaultXmlRpcResponse = new XmlRpcResponse(); | ||||
| 
 | ||||
|             SetDefaultValues(); | ||||
|         } // LoginServer | ||||
| 
 | ||||
|         public 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 = LLUUID.Random(); | ||||
|             SecureSessionID = LLUUID.Random(); | ||||
|             AgentID = LLUUID.Random(); | ||||
| 
 | ||||
|             Hashtable InitialOutfitHash = new Hashtable(); | ||||
|             InitialOutfitHash["folder_name"] = "Nightclub Female"; | ||||
|             InitialOutfitHash["gender"] = "female"; | ||||
|             initialOutfit.Add(InitialOutfitHash); | ||||
|         } // SetDefaultValues | ||||
| 
 | ||||
|         #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); | ||||
|         } // GenerateResponse | ||||
| 
 | ||||
|         public LLSD GenerateFailureResponseLLSD(string reason, string message, string login) | ||||
|         { | ||||
|             LLSDMap map = new LLSDMap(); | ||||
| 
 | ||||
|             // Ensure Login Failed message/reason; | ||||
|             ErrorMessage = message; | ||||
|             ErrorReason = reason; | ||||
| 
 | ||||
|             map["reason"] = LLSD.FromString(ErrorReason); | ||||
|             map["message"] = LLSD.FromString(ErrorMessage); | ||||
|             map["login"] = LLSD.FromString(login); | ||||
| 
 | ||||
|             return map; | ||||
|         } | ||||
| 
 | ||||
|         public XmlRpcResponse CreateFailedResponse() | ||||
|         { | ||||
|             return (CreateLoginFailedResponse()); | ||||
|         } // CreateErrorConnectingToGridResponse() | ||||
| 
 | ||||
|         public LLSD 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")); | ||||
|         } // LoginFailedResponse | ||||
| 
 | ||||
|         public LLSD CreateLoginFailedResponseLLSD() | ||||
|         { | ||||
|             return GenerateFailureResponseLLSD( | ||||
|                 "key", | ||||
|                 "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.", | ||||
|                 "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", | ||||
|                                          "false")); | ||||
|         } // CreateAlreadyLoggedInResponse() | ||||
| 
 | ||||
|         public LLSD 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 CreateDeadRegionResponse() | ||||
|         { | ||||
|             return | ||||
|                 (GenerateFailureResponse("key", | ||||
|                                          "The region you are attempting to log into is not responding. Please select another region and try again.", | ||||
|                                          "false")); | ||||
|         } | ||||
| 
 | ||||
|         public LLSD 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 LLSD CreateGridErrorResponseLLSD() | ||||
|         { | ||||
|             return GenerateFailureResponseLLSD( | ||||
|                 "key", | ||||
|                 "Error connecting to grid. Could not percieve credentials from login XML.", | ||||
|                 "false"); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         public 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["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"] = new ArrayList(); // todo | ||||
|                 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")); | ||||
|             } | ||||
|         } // ToXmlRpcResponse | ||||
| 
 | ||||
|         public LLSD ToLLSDResponse() | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 LLSDMap map = new LLSDMap(); | ||||
| 
 | ||||
|                 map["first_name"] = LLSD.FromString(Firstname); | ||||
|                 map["last_name"] = LLSD.FromString(Lastname); | ||||
|                 map["agent_access"] = LLSD.FromString(agentAccess); | ||||
| 
 | ||||
|                 map["sim_port"] = LLSD.FromInteger(SimPort); | ||||
|                 map["sim_ip"] = LLSD.FromString(SimAddress); | ||||
| 
 | ||||
|                 map["agent_id"] = LLSD.FromUUID(AgentID); | ||||
|                 map["session_id"] = LLSD.FromUUID(SessionID); | ||||
|                 map["secure_session_id"] = LLSD.FromUUID(SecureSessionID); | ||||
|                 map["circuit_code"] = LLSD.FromInteger(CircuitCode); | ||||
|                 map["seconds_since_epoch"] = LLSD.FromInteger((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds); | ||||
| 
 | ||||
|                 #region Login Flags | ||||
| 
 | ||||
|                 LLSDMap loginFlagsLLSD = new LLSDMap(); | ||||
|                 loginFlagsLLSD["daylight_savings"] = LLSD.FromString(DST); | ||||
|                 loginFlagsLLSD["stipend_since_login"] = LLSD.FromString(StipendSinceLogin); | ||||
|                 loginFlagsLLSD["gendered"] = LLSD.FromString(Gendered); | ||||
|                 loginFlagsLLSD["ever_logged_in"] = LLSD.FromString(EverLoggedIn); | ||||
|                 map["login-flags"] = WrapLLSDMap(loginFlagsLLSD); | ||||
| 
 | ||||
|                 #endregion Login Flags | ||||
| 
 | ||||
|                 #region Global Textures | ||||
| 
 | ||||
|                 LLSDMap globalTexturesLLSD = new LLSDMap(); | ||||
|                 globalTexturesLLSD["sun_texture_id"] = LLSD.FromString(SunTexture); | ||||
|                 globalTexturesLLSD["cloud_texture_id"] = LLSD.FromString(CloudTexture); | ||||
|                 globalTexturesLLSD["moon_texture_id"] = LLSD.FromString(MoonTexture); | ||||
| 
 | ||||
|                 map["global-textures"] = WrapLLSDMap(globalTexturesLLSD); | ||||
| 
 | ||||
|                 #endregion Global Textures | ||||
| 
 | ||||
|                 map["seed_capability"] = LLSD.FromString(seedCapability); | ||||
| 
 | ||||
|                 // FIXME: Need a function that will convert these ArrayLists in to LLSDArrays, | ||||
|                 // and convert the data inside them to LLSD objects as well | ||||
| 
 | ||||
|                 //map["event_categories"] = eventCategories; | ||||
|                 //map["event_notifications"] = new LLSDArray(); // todo | ||||
|                 //map["classified_categories"] = classifiedCategories; | ||||
| 
 | ||||
|                 #region UI Config | ||||
| 
 | ||||
|                 LLSDMap uiConfigLLSD = new LLSDMap(); | ||||
|                 uiConfigLLSD["allow_first_life"] = LLSD.FromString(allowFirstLife); | ||||
|                 map["ui-config"] = WrapLLSDMap(uiConfigLLSD); | ||||
| 
 | ||||
|                 #endregion UI Config | ||||
| 
 | ||||
|                 #region Inventory | ||||
| 
 | ||||
|                 //map["inventory-skeleton"] = agentInventory; | ||||
|                 //map["inventory-skel-lib"] = inventoryLibrary; | ||||
|                 //map["inventory-root"] = inventoryRoot; | ||||
|                 //map["inventory-lib-root"] = inventoryLibRoot; | ||||
|                 //map["inventory-lib-owner"] = inventoryLibraryOwner; | ||||
| 
 | ||||
|                 #endregion Inventory | ||||
| 
 | ||||
|                 map["gestures"] = new LLSDArray(); // todo | ||||
| 
 | ||||
|                 //responseData["initial-outfit"] = initialOutfit; | ||||
|                 //responseData["start_location"] = startLocation; | ||||
| 
 | ||||
|                 map["seed_capability"] = LLSD.FromString(seedCapability); | ||||
|                 map["home"] = LLSD.FromString(home); | ||||
|                 map["look_at"] = LLSD.FromString(lookAt); | ||||
|                 map["message"] = LLSD.FromString(welcomeMessage); | ||||
|                 map["region_x"] = LLSD.FromInteger(RegionX * Constants.RegionSize); | ||||
|                 map["region_y"] = LLSD.FromInteger(RegionY * Constants.RegionSize); | ||||
| 
 | ||||
|                 if (m_buddyList != null) | ||||
|                 { | ||||
|                     //map["buddy-list"] = m_buddyList.ToArray(); | ||||
|                 } | ||||
| 
 | ||||
|                 map["login"] = LLSD.FromString("true"); | ||||
| 
 | ||||
|                 return map; | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Warn("[CLIENT]: LoginResponse: Error creating XML-RPC Response: " + e.Message); | ||||
| 
 | ||||
|                 return GenerateFailureResponseLLSD("Internal Error", "Error generating Login Response", "false"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private LLSDArray WrapLLSDMap(LLSDMap wrapMe) | ||||
|         { | ||||
|             LLSDArray array = new LLSDArray(); | ||||
|             array.Add(wrapMe); | ||||
|             return array; | ||||
|         } | ||||
| 
 | ||||
|         public void SetEventCategories(string category, string value) | ||||
|         { | ||||
|             //  this.eventCategoriesHash[category] = value; | ||||
|             //TODO | ||||
|         } // SetEventCategories | ||||
| 
 | ||||
|         public void AddToUIConfig(string itemName, string item) | ||||
|         { | ||||
|             uiConfigHash[itemName] = item; | ||||
|         } // SetUIConfig | ||||
| 
 | ||||
|         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(); | ||||
|         } // SetClassifiedCategory | ||||
| 
 | ||||
|         #region Properties | ||||
| 
 | ||||
|         public string Login | ||||
|         { | ||||
|             get { return login; } | ||||
|             set { login = value; } | ||||
|         } // Login | ||||
| 
 | ||||
|         public string DST | ||||
|         { | ||||
|             get { return dst; } | ||||
|             set { dst = value; } | ||||
|         } // DST | ||||
| 
 | ||||
|         public string StipendSinceLogin | ||||
|         { | ||||
|             get { return stipendSinceLogin; } | ||||
|             set { stipendSinceLogin = value; } | ||||
|         } // StipendSinceLogin | ||||
| 
 | ||||
|         public string Gendered | ||||
|         { | ||||
|             get { return gendered; } | ||||
|             set { gendered = value; } | ||||
|         } // Gendered | ||||
| 
 | ||||
|         public string EverLoggedIn | ||||
|         { | ||||
|             get { return everLoggedIn; } | ||||
|             set { everLoggedIn = value; } | ||||
|         } // EverLoggedIn | ||||
| 
 | ||||
|         public uint SimPort | ||||
|         { | ||||
|             get { return simPort; } | ||||
|             set { simPort = value; } | ||||
|         } // SimPort | ||||
| 
 | ||||
|         public string SimAddress | ||||
|         { | ||||
|             get { return simAddress; } | ||||
|             set { simAddress = value; } | ||||
|         } // SimAddress | ||||
| 
 | ||||
|         public LLUUID AgentID | ||||
|         { | ||||
|             get { return agentID; } | ||||
|             set { agentID = value; } | ||||
|         } // AgentID | ||||
| 
 | ||||
|         public LLUUID SessionID | ||||
|         { | ||||
|             get { return sessionID; } | ||||
|             set { sessionID = value; } | ||||
|         } // SessionID | ||||
| 
 | ||||
|         public LLUUID SecureSessionID | ||||
|         { | ||||
|             get { return secureSessionID; } | ||||
|             set { secureSessionID = value; } | ||||
|         } // SecureSessionID | ||||
| 
 | ||||
|         public Int32 CircuitCode | ||||
|         { | ||||
|             get { return circuitCode; } | ||||
|             set { circuitCode = value; } | ||||
|         } // CircuitCode | ||||
| 
 | ||||
|         public uint RegionX | ||||
|         { | ||||
|             get { return regionX; } | ||||
|             set { regionX = value; } | ||||
|         } // RegionX | ||||
| 
 | ||||
|         public uint RegionY | ||||
|         { | ||||
|             get { return regionY; } | ||||
|             set { regionY = value; } | ||||
|         } // RegionY | ||||
| 
 | ||||
|         public string SunTexture | ||||
|         { | ||||
|             get { return sunTexture; } | ||||
|             set { sunTexture = value; } | ||||
|         } // SunTexture | ||||
| 
 | ||||
|         public string CloudTexture | ||||
|         { | ||||
|             get { return cloudTexture; } | ||||
|             set { cloudTexture = value; } | ||||
|         } // CloudTexture | ||||
| 
 | ||||
|         public string MoonTexture | ||||
|         { | ||||
|             get { return moonTexture; } | ||||
|             set { moonTexture = value; } | ||||
|         } // MoonTexture | ||||
| 
 | ||||
|         public string Firstname | ||||
|         { | ||||
|             get { return firstname; } | ||||
|             set { firstname = value; } | ||||
|         } // Firstname | ||||
| 
 | ||||
|         public string Lastname | ||||
|         { | ||||
|             get { return lastname; } | ||||
|             set { lastname = value; } | ||||
|         } // Lastname | ||||
| 
 | ||||
|         public string AgentAccess | ||||
|         { | ||||
|             get { return agentAccess; } | ||||
|             set { agentAccess = value; } | ||||
|         } | ||||
| 
 | ||||
|         public string StartLocation | ||||
|         { | ||||
|             get { return startLocation; } | ||||
|             set { startLocation = value; } | ||||
|         } // StartLocation | ||||
| 
 | ||||
|         public string LookAt | ||||
|         { | ||||
|             get { return lookAt; } | ||||
|             set { lookAt = value; } | ||||
|         } | ||||
| 
 | ||||
|         public string SeedCapability | ||||
|         { | ||||
|             get { return seedCapability; } | ||||
|             set { seedCapability = value; } | ||||
|         } // SeedCapability | ||||
| 
 | ||||
|         public string ErrorReason | ||||
|         { | ||||
|             get { return errorReason; } | ||||
|             set { errorReason = value; } | ||||
|         } // ErrorReason | ||||
| 
 | ||||
|         public string ErrorMessage | ||||
|         { | ||||
|             get { return errorMessage; } | ||||
|             set { errorMessage = value; } | ||||
|         } // ErrorMessage | ||||
| 
 | ||||
|         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 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 LLVector3 homepos; | ||||
|             public LLVector3 homelookat; | ||||
|         } | ||||
| 
 | ||||
|         public class BuddyList | ||||
|         { | ||||
|             public List<BuddyInfo> Buddies = new List<BuddyInfo>(); | ||||
| 
 | ||||
|             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 LLUUID BuddyID; | ||||
| 
 | ||||
|                 public BuddyInfo(string buddyID) | ||||
|                 { | ||||
|                     BuddyID = new LLUUID(buddyID); | ||||
|                 } | ||||
| 
 | ||||
|                 public BuddyInfo(LLUUID 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; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,758 @@ | |||
| /* | ||||
| * 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.Text.RegularExpressions; | ||||
| using System.Threading; | ||||
| using libsecondlife; | ||||
| using libsecondlife.StructuredData; | ||||
| using Nwc.XmlRpc; | ||||
| 
 | ||||
| using OpenSim.Framework.Communications.Cache; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Statistics; | ||||
| 
 | ||||
| namespace OpenSim.Framework.UserManagement | ||||
| { | ||||
|     public class LoginService | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         protected string m_welcomeMessage = "Welcome to OpenSim"; | ||||
|         protected UserManagerBase m_userManager = null; | ||||
|         protected Mutex m_loginMutex = new Mutex(false);      | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Used during login to send the skeleton of the OpenSim Library to the client. | ||||
|         /// </summary> | ||||
|         protected LibraryRootFolder m_libraryRootFolder; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Constructor | ||||
|         /// </summary> | ||||
|         /// <param name="userManager"></param> | ||||
|         /// <param name="libraryRootFolder"></param> | ||||
|         /// <param name="welcomeMess"></param> | ||||
|         public LoginService(UserManagerBase userManager, LibraryRootFolder libraryRootFolder,  | ||||
|                             string welcomeMess) | ||||
|         { | ||||
|             m_userManager = userManager; | ||||
|             m_libraryRootFolder = libraryRootFolder; | ||||
|              | ||||
|             if (welcomeMess != String.Empty) | ||||
|             { | ||||
|                 m_welcomeMessage = welcomeMess; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Main user login function | ||||
|         /// </summary> | ||||
|         /// <param name="request">The XMLRPC request</param> | ||||
|         /// <returns>The response to send</returns> | ||||
|         public 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]; | ||||
| 
 | ||||
|                 bool GoodXML = (requestData.Contains("first") && requestData.Contains("last") && | ||||
|                                 (requestData.Contains("passwd") || requestData.Contains("web_login_key"))); | ||||
|                 bool GoodLogin = false; | ||||
| 
 | ||||
|                 UserProfileData userProfile; | ||||
|                 LoginResponse logResponse = new LoginResponse(); | ||||
| 
 | ||||
|                 if (GoodXML) | ||||
|                 { | ||||
|                     string firstname = (string) requestData["first"]; | ||||
|                     string lastname = (string) requestData["last"]; | ||||
| 
 | ||||
|                     if( requestData.Contains("version")) | ||||
|                     { | ||||
|                         string clientversion = (string)requestData["version"]; | ||||
|                         m_log.Info("[LOGIN]: Client Version " + clientversion + " for " + firstname + " " + lastname); | ||||
|                     } | ||||
|                      | ||||
| 
 | ||||
|                     userProfile = GetTheUser(firstname, lastname); | ||||
|                     if (userProfile == null) | ||||
|                     { | ||||
|                         m_log.Info("[LOGIN]: Could not find a profile for " + firstname + " " + lastname); | ||||
| 
 | ||||
|                         return logResponse.CreateLoginFailedResponse(); | ||||
|                     } | ||||
|                     if (requestData.Contains("passwd")) | ||||
|                     { | ||||
|                         string passwd = (string)requestData["passwd"]; | ||||
|                         GoodLogin = AuthenticateUser(userProfile, passwd); | ||||
|                     } | ||||
|                     else if (requestData.Contains("web_login_key")) | ||||
|                     { | ||||
|                         LLUUID webloginkey = null; | ||||
|                         try | ||||
|                         { | ||||
|                             webloginkey = new LLUUID((string)requestData["web_login_key"]); | ||||
|                         } | ||||
|                         catch (System.Exception) | ||||
|                         { | ||||
|                             return logResponse.CreateFailedResponse(); | ||||
|                         } | ||||
|                         GoodLogin = AuthenticateUser(userProfile, webloginkey); | ||||
| 
 | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         return logResponse.CreateFailedResponse(); | ||||
|                     } | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return logResponse.CreateGridErrorResponse(); | ||||
|                 } | ||||
| 
 | ||||
|                 if (!GoodLogin) | ||||
|                 { | ||||
|                     return logResponse.CreateLoginFailedResponse(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // If we already have a session... | ||||
| 
 | ||||
|                     if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) | ||||
|                     { | ||||
|                         userProfile.currentAgent = null; | ||||
|                         m_userManager.CommitAgent(ref userProfile); | ||||
| 
 | ||||
|                         // Reject the login | ||||
|                         return logResponse.CreateAlreadyLoggedInResponse(); | ||||
|                     } | ||||
|                     // Otherwise... | ||||
|                     // Create a new agent session | ||||
|                     CreateAgent(userProfile, request); | ||||
| 
 | ||||
|                     try | ||||
|                     { | ||||
|                         LLUUID agentID = userProfile.UUID; | ||||
| 
 | ||||
|                         // Inventory Library Section | ||||
|                         InventoryData inventData = CreateInventoryData(agentID); | ||||
|                         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; | ||||
| 
 | ||||
|                         // Circuit Code | ||||
|                         uint circode = (uint) (Util.RandomClass.Next()); | ||||
| 
 | ||||
|                         logResponse.Lastname = userProfile.surname; | ||||
|                         logResponse.Firstname = userProfile.username; | ||||
|                         logResponse.AgentID = agentID.ToString(); | ||||
|                         logResponse.SessionID = userProfile.currentAgent.sessionID.ToString(); | ||||
|                         logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToString(); | ||||
|                         logResponse.InventoryRoot = InventoryRoot; | ||||
|                         logResponse.InventorySkeleton = AgentInventoryArray; | ||||
|                         logResponse.InventoryLibrary = GetInventoryLibrary(); | ||||
| 
 | ||||
|                         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.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 = GetMessage(); | ||||
|                         logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID));  | ||||
| 
 | ||||
|                         try | ||||
|                         { | ||||
|                             CustomiseResponse(logResponse, userProfile); | ||||
|                         } | ||||
|                         catch (Exception e) | ||||
|                         { | ||||
|                             m_log.Info("[LOGIN]: " + e.ToString()); | ||||
|                             return logResponse.CreateDeadRegionResponse(); | ||||
|                             //return logResponse.ToXmlRpcResponse(); | ||||
|                         } | ||||
|                         CommitAgent(ref userProfile); | ||||
|                          | ||||
|                         // If we reach this point, then the login has successfully logged onto the grid | ||||
|                         if (StatsManager.UserStats != null) | ||||
|                             StatsManager.UserStats.AddSuccessfulLogin(); | ||||
|                          | ||||
|                         return logResponse.ToXmlRpcResponse(); | ||||
|                     } | ||||
|                     catch (Exception e) | ||||
|                     { | ||||
|                         m_log.Info("[LOGIN]: " + e.ToString()); | ||||
|                     } | ||||
|                     //} | ||||
|                 } | ||||
|                 return response; | ||||
|             } | ||||
|             finally | ||||
|             { | ||||
|                 m_loginMutex.ReleaseMutex(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public LLSD LLSDLoginMethod(LLSD request) | ||||
|         { | ||||
|             // Temporary fix | ||||
|             m_loginMutex.WaitOne(); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 bool GoodLogin = false; | ||||
| 
 | ||||
|                 UserProfileData userProfile = null; | ||||
|                 LoginResponse logResponse = new LoginResponse(); | ||||
| 
 | ||||
|                 if (request.Type == LLSDType.Map) | ||||
|                 { | ||||
|                     LLSDMap map = (LLSDMap)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(); | ||||
| 
 | ||||
|                         userProfile = GetTheUser(firstname, lastname); | ||||
|                         if (userProfile == null) | ||||
|                         { | ||||
|                             m_log.Info("[LOGIN]: Could not find a profile for " + firstname + " " + lastname); | ||||
| 
 | ||||
|                             return logResponse.CreateLoginFailedResponseLLSD(); | ||||
|                         } | ||||
| 
 | ||||
|                         GoodLogin = AuthenticateUser(userProfile, passwd); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 if (!GoodLogin) | ||||
|                 { | ||||
|                     return logResponse.CreateLoginFailedResponseLLSD(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // If we already have a session... | ||||
|                     if (userProfile.currentAgent != null && userProfile.currentAgent.agentOnline) | ||||
|                     { | ||||
|                         userProfile.currentAgent = null; | ||||
|                         m_userManager.CommitAgent(ref userProfile); | ||||
| 
 | ||||
|                         // Reject the login | ||||
|                         return logResponse.CreateAlreadyLoggedInResponseLLSD(); | ||||
|                     } | ||||
| 
 | ||||
|                     // Otherwise... | ||||
|                     // Create a new agent session | ||||
|                     CreateAgent(userProfile, request); | ||||
| 
 | ||||
|                     try | ||||
|                     { | ||||
|                         LLUUID agentID = userProfile.UUID; | ||||
| 
 | ||||
|                         // Inventory Library Section | ||||
|                         InventoryData inventData = CreateInventoryData(agentID); | ||||
|                         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; | ||||
| 
 | ||||
|                         // Circuit Code | ||||
|                         uint circode = (uint)(Util.RandomClass.Next()); | ||||
| 
 | ||||
|                         logResponse.Lastname = userProfile.surname; | ||||
|                         logResponse.Firstname = userProfile.username; | ||||
|                         logResponse.AgentID = agentID.ToString(); | ||||
|                         logResponse.SessionID = userProfile.currentAgent.sessionID.ToString(); | ||||
|                         logResponse.SecureSessionID = userProfile.currentAgent.secureSessionID.ToString(); | ||||
|                         logResponse.InventoryRoot = InventoryRoot; | ||||
|                         logResponse.InventorySkeleton = AgentInventoryArray; | ||||
|                         logResponse.InventoryLibrary = GetInventoryLibrary(); | ||||
| 
 | ||||
|                         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.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 = GetMessage(); | ||||
|                         logResponse.BuddList = ConvertFriendListItem(m_userManager.GetUserFriendList(agentID)); | ||||
| 
 | ||||
|                         try | ||||
|                         { | ||||
|                             CustomiseResponse(logResponse, userProfile); | ||||
|                         } | ||||
|                         catch (Exception ex) | ||||
|                         { | ||||
|                             m_log.Info("[LOGIN]: " + ex.ToString()); | ||||
|                             return logResponse.CreateDeadRegionResponseLLSD(); | ||||
|                         } | ||||
| 
 | ||||
|                         CommitAgent(ref userProfile); | ||||
|                          | ||||
|                         // If we reach this point, then the login has successfully logged onto the grid | ||||
|                         if (StatsManager.UserStats != null) | ||||
|                             StatsManager.UserStats.AddSuccessfulLogin();                         | ||||
| 
 | ||||
|                         return logResponse.ToLLSDResponse(); | ||||
|                     } | ||||
|                     catch (Exception ex) | ||||
|                     { | ||||
|                         m_log.Info("[LOGIN]: " + ex.ToString()); | ||||
|                         return logResponse.CreateFailedResponseLLSD(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             finally | ||||
|             { | ||||
|                 m_loginMutex.ReleaseMutex(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <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(LoginResponse response, UserProfileData theUser) | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         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) | ||||
|                 { | ||||
|                     LLUUID webloginkey = LLUUID.Random(); | ||||
|                     m_userManager.StoreWebLoginKey(user.UUID, webloginkey); | ||||
|                     statuscode = 301; | ||||
| 
 | ||||
|                     string redirectURL = "about:blank?redirect-http-hack=" + System.Web.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"] = "<HTML><BODY>GoodLogin</BODY></HTML>"; | ||||
|                 } | ||||
|                 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 = | ||||
|            "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"; | ||||
|                 responseString = responseString + "<html xmlns=\"http://www.w3.org/1999/xhtml\">"; | ||||
|                 responseString = responseString + "<head>"; | ||||
|                 responseString = responseString + | ||||
|                                  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"; | ||||
|                 responseString = responseString + "<meta http-equiv=\"cache-control\" content=\"no-cache\">"; | ||||
|                 responseString = responseString + "<meta http-equiv=\"Pragma\" content=\"no-cache\">"; | ||||
|                 responseString = responseString + "<title>OpenSim Login</title>"; | ||||
|                 responseString = responseString + "<body><br />"; | ||||
|                 responseString = responseString + "<div id=\"login_box\">"; | ||||
|                  | ||||
|                 responseString = responseString + "<form action=\"/go.cgi\" method=\"GET\" id=\"login-form\">"; | ||||
| 
 | ||||
|                 responseString = responseString + "<div id=\"message\">[$errors]</div>"; | ||||
|                 responseString = responseString + "<fieldset id=\"firstname\">"; | ||||
|                 responseString = responseString + "<legend>First Name:</legend>"; | ||||
|                 responseString = responseString + "<input type=\"text\" id=\"firstname_input\" size=\"15\" maxlength=\"100\" name=\"username\" value=\"[$firstname]\" />"; | ||||
|                 responseString = responseString + "</fieldset>"; | ||||
|                 responseString = responseString + "<fieldset id=\"lastname\">"; | ||||
|                 responseString = responseString + "<legend>Last Name:</legend>"; | ||||
|                 responseString = responseString + "<input type=\"text\" size=\"15\" maxlength=\"100\" name=\"lastname\" value=\"[$lastname]\" />"; | ||||
|                 responseString = responseString + "</fieldset>"; | ||||
|                 responseString = responseString + "<fieldset id=\"password\">"; | ||||
|                 responseString = responseString + "<legend>Password:</legend>"; | ||||
|                 responseString = responseString + "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"; | ||||
|                 responseString = responseString + "<tr>"; | ||||
|                 responseString = responseString + "<td colspan=\"2\"><input type=\"password\" size=\"15\" maxlength=\"100\" name=\"password\" value=\"[$password]\" /></td>"; | ||||
|                 responseString = responseString + "</tr>"; | ||||
|                 responseString = responseString + "<tr>"; | ||||
|                 responseString = responseString + "<td valign=\"middle\"><input type=\"checkbox\" name=\"remember_password\" id=\"remember_password\" [$remember_password] style=\"margin-left:0px;\"/></td>"; | ||||
|                 responseString = responseString + "<td><label for=\"remember_password\">Remember password</label></td>"; | ||||
|                 responseString = responseString + "</tr>"; | ||||
|                 responseString = responseString + "</table>"; | ||||
|                 responseString = responseString + "</fieldset>"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" name=\"show_login_form\" value=\"FALSE\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" name=\"method\" value=\"login\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"grid\" name=\"grid\" value=\"[$grid]\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"region\" name=\"region\" value=\"[$region]\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"location\" name=\"location\" value=\"[$location]\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"channel\" name=\"channel\" value=\"[$channel]\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"version\" name=\"version\" value=\"[$version]\" />"; | ||||
|                 responseString = responseString + "<input type=\"hidden\" id=\"lang\" name=\"lang\" value=\"[$lang]\" />"; | ||||
|                 responseString = responseString + "<div id=\"submitbtn\">"; | ||||
|                 responseString = responseString + "<input class=\"input_over\" type=\"submit\" value=\"Connect\" />"; | ||||
|                 responseString = responseString + "</div>"; | ||||
|                 responseString = responseString + "<div id=\"connecting\" style=\"visibility:hidden\"> Connecting...</div>"; | ||||
| 
 | ||||
|                 responseString = responseString + "<div id=\"helplinks\">"; | ||||
|                 responseString = responseString + "<a href=\"#join now link\" target=\"_blank\"></a> | "; | ||||
|                 responseString = responseString + "<a href=\"#forgot password link\" target=\"_blank\"></a>"; | ||||
|                 responseString = responseString + "</div>"; | ||||
| 
 | ||||
|                 responseString = responseString + "<div id=\"channelinfo\"> [$channel] | [$version]=[$lang]</div>"; | ||||
|                 responseString = responseString + "</form>"; | ||||
|                 responseString = responseString + "<script language=\"JavaScript\">"; | ||||
|                 responseString = responseString + "document.getElementById('firstname_input').focus();"; | ||||
|                 responseString = responseString + "</script>"; | ||||
|                 responseString = responseString + "</div>"; | ||||
|                 responseString = responseString + "</div>"; | ||||
|                 responseString = responseString + "</body>"; | ||||
|                 responseString = responseString + "</html>"; | ||||
|             return responseString; | ||||
|         } | ||||
| 
 | ||||
|         /// <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) | ||||
|         { | ||||
|             return m_userManager.CommitAgent(ref profile); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <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(UserProfileData profile, string password) | ||||
|         { | ||||
|             bool passwordSuccess = false; | ||||
|             m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.username, profile.surname, profile.UUID); | ||||
| 
 | ||||
|             // 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, LLUUID webloginkey) | ||||
|         { | ||||
|             bool passwordSuccess = false; | ||||
|             m_log.InfoFormat("[LOGIN]: Authenticating {0} {1} ({2})", profile.username, profile.surname, profile.UUID); | ||||
| 
 | ||||
|             // Match web login key unless it's the default weblogin key LLUUID.Zero | ||||
|             passwordSuccess = ((profile.webLoginKey==webloginkey) && profile.webLoginKey != LLUUID.Zero); | ||||
| 
 | ||||
|             return passwordSuccess; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="profile"></param> | ||||
|         /// <param name="request"></param> | ||||
|         public void CreateAgent(UserProfileData profile, XmlRpcRequest request) | ||||
|         { | ||||
|             m_userManager.CreateAgent(profile, request); | ||||
|         } | ||||
| 
 | ||||
|         public void CreateAgent(UserProfileData profile, LLSD request) | ||||
|         { | ||||
|             m_userManager.CreateAgent(profile, request); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="firstname"></param> | ||||
|         /// <param name="lastname"></param> | ||||
|         /// <returns></returns> | ||||
|         public virtual UserProfileData GetTheUser(string firstname, string lastname) | ||||
|         { | ||||
|             return m_userManager.GetUserProfile(firstname, lastname); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         public virtual string GetMessage() | ||||
|         { | ||||
|             return m_welcomeMessage; | ||||
|         } | ||||
| 
 | ||||
|         private LoginResponse.BuddyList ConvertFriendListItem(List<FriendListItem> 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; | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Converts the inventory library skeleton into the form required by the rpc request. | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         protected virtual ArrayList GetInventoryLibrary() | ||||
|         { | ||||
|             Dictionary<LLUUID, InventoryFolderImpl> 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.folderID.ToString(); | ||||
|                 folderHashes.Add(TempHash); | ||||
|             } | ||||
|              | ||||
|             return folderHashes; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <returns></returns> | ||||
|         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; | ||||
|         } | ||||
| 
 | ||||
|         protected virtual InventoryData CreateInventoryData(LLUUID userID) | ||||
|         { | ||||
|             AgentInventory userInventory = new AgentInventory(); | ||||
|             userInventory.CreateRootFolder(userID, false); | ||||
| 
 | ||||
|             ArrayList AgentInventoryArray = new ArrayList(); | ||||
|             Hashtable TempHash; | ||||
|             foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values) | ||||
|             { | ||||
|                 TempHash = new Hashtable(); | ||||
|                 TempHash["name"] = InvFolder.FolderName; | ||||
|                 TempHash["parent_id"] = InvFolder.ParentID.ToString(); | ||||
|                 TempHash["version"] = (Int32) InvFolder.Version; | ||||
|                 TempHash["type_default"] = (Int32) InvFolder.DefaultType; | ||||
|                 TempHash["folder_id"] = InvFolder.FolderID.ToString(); | ||||
|                 AgentInventoryArray.Add(TempHash); | ||||
|             } | ||||
| 
 | ||||
|             return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID); | ||||
|         } | ||||
| 
 | ||||
|         public class InventoryData | ||||
|         { | ||||
|             public ArrayList InventoryArray = null; | ||||
|             public LLUUID RootFolderID = LLUUID.Zero; | ||||
| 
 | ||||
|             public InventoryData(ArrayList invList, LLUUID rootID) | ||||
|             { | ||||
|                 InventoryArray = invList; | ||||
|                 RootFolderID = rootID; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,65 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following  | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("OpenGrid.Framework.Communications")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly : AssemblyConfiguration("")] | ||||
| [assembly : AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("OpenGrid.Framework.Communications")] | ||||
| [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")] | ||||
| [assembly : AssemblyTrademark("")] | ||||
| [assembly : AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible  | ||||
| // to COM components.  If you need to access a type in this assembly from  | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| 
 | ||||
| [assembly : Guid("13e7c396-78a9-4a5c-baf2-6f980ea75d95")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version  | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| // You can specify all the values or you can default the Revision and Build Numbers  | ||||
| // by using the '*' as shown below: | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.0.0")] | ||||
| [assembly : AssemblyFileVersion("1.0.0.0")] | ||||
|  | @ -0,0 +1,186 @@ | |||
| /* | ||||
| * 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.Threading; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     internal class SimpleAsyncResult : IAsyncResult | ||||
|     { | ||||
|         private readonly AsyncCallback m_callback; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Is process completed? | ||||
|         /// </summary> | ||||
|         /// <remarks>Should really be boolean, but VolatileRead has no boolean method</remarks> | ||||
|         private byte m_completed; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Did process complete synchroneously? | ||||
|         /// </summary> | ||||
|         /// <remarks>I have a hard time imagining a scenario where this is the case, again, same issue about | ||||
|         /// booleans and VolatileRead as m_completed | ||||
|         /// </remarks> | ||||
|         private byte m_completedSynchronously; | ||||
| 
 | ||||
|         private readonly object m_asyncState; | ||||
|         private ManualResetEvent m_waitHandle; | ||||
|         private Exception m_exception; | ||||
| 
 | ||||
|         internal SimpleAsyncResult(AsyncCallback cb, object state) | ||||
|         { | ||||
|             m_callback = cb; | ||||
|             m_asyncState = state; | ||||
|             m_completed = 0; | ||||
|             m_completedSynchronously = 1; | ||||
|         } | ||||
| 
 | ||||
|         #region IAsyncResult Members | ||||
| 
 | ||||
|         public object AsyncState | ||||
|         { | ||||
|             get { return m_asyncState; } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public WaitHandle AsyncWaitHandle | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 if (m_waitHandle == null) | ||||
|                 { | ||||
|                     bool done = IsCompleted; | ||||
|                     ManualResetEvent mre = new ManualResetEvent(done); | ||||
|                     if (Interlocked.CompareExchange(ref m_waitHandle, mre, null) != null) | ||||
|                     { | ||||
|                         mre.Close(); | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         if (!done && IsCompleted) | ||||
|                         { | ||||
|                             m_waitHandle.Set(); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 return m_waitHandle; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public bool CompletedSynchronously | ||||
|         { | ||||
|             get { return Thread.VolatileRead(ref m_completedSynchronously) == 1; } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public bool IsCompleted | ||||
|         { | ||||
|             get { return Thread.VolatileRead(ref m_completed) == 1; } | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region class Methods | ||||
| 
 | ||||
|         internal void SetAsCompleted(bool completedSynchronously) | ||||
|         { | ||||
|             m_completed = 1; | ||||
|             if (completedSynchronously) | ||||
|                 m_completedSynchronously = 1; | ||||
|             else | ||||
|                 m_completedSynchronously = 0; | ||||
| 
 | ||||
|             SignalCompletion(); | ||||
|         } | ||||
| 
 | ||||
|         internal void HandleException(Exception e, bool completedSynchronously) | ||||
|         { | ||||
|             m_completed = 1; | ||||
|             if (completedSynchronously) | ||||
|                 m_completedSynchronously = 1; | ||||
|             else | ||||
|                 m_completedSynchronously = 0; | ||||
|             m_exception = e; | ||||
| 
 | ||||
|             SignalCompletion(); | ||||
|         } | ||||
| 
 | ||||
|         private void SignalCompletion() | ||||
|         { | ||||
|             if (m_waitHandle != null) m_waitHandle.Set(); | ||||
| 
 | ||||
|             if (m_callback != null) m_callback(this); | ||||
|         } | ||||
| 
 | ||||
|         public void EndInvoke() | ||||
|         { | ||||
|             // This method assumes that only 1 thread calls EndInvoke  | ||||
|             if (!IsCompleted) | ||||
|             { | ||||
|                 // If the operation isn't done, wait for it | ||||
|                 AsyncWaitHandle.WaitOne(); | ||||
|                 AsyncWaitHandle.Close(); | ||||
|                 m_waitHandle = null; // Allow early GC | ||||
|             } | ||||
| 
 | ||||
|             // Operation is done: if an exception occured, throw it | ||||
|             if (m_exception != null) throw m_exception; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| 
 | ||||
|     internal class AsyncResult<T> : SimpleAsyncResult | ||||
|     { | ||||
|         private T m_result = default(T); | ||||
| 
 | ||||
|         public AsyncResult(AsyncCallback asyncCallback, Object state) : | ||||
|             base(asyncCallback, state) | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void SetAsCompleted(T result, bool completedSynchronously) | ||||
|         { | ||||
|             // Save the asynchronous operation's result | ||||
|             m_result = result; | ||||
| 
 | ||||
|             // Tell the base class that the operation completed  | ||||
|             // sucessfully (no exception) | ||||
|             base.SetAsCompleted(completedSynchronously); | ||||
|         } | ||||
| 
 | ||||
|         public new T EndInvoke() | ||||
|         { | ||||
|             base.EndInvoke(); | ||||
|             return m_result; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,446 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.IO; | ||||
| using System.Net; | ||||
| using System.Text; | ||||
| using System.Threading; | ||||
| using System.Web; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Communications | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Implementation of a generic REST client | ||||
|     /// </summary> | ||||
|     /// <remarks> | ||||
|     /// This class is a generic implementation of a REST (Representational State Transfer) web service. This | ||||
|     /// class is designed to execute both synchroneously and asynchroneously. | ||||
|     ///  | ||||
|     /// Internally the implementation works as a two stage asynchroneous web-client. | ||||
|     /// When the request is initiated, RestClient will query asynchroneously for for a web-response, | ||||
|     /// sleeping until the initial response is returned by the server. Once the initial response is retrieved | ||||
|     /// the second stage of asynchroneous requests will be triggered, in an attempt to read of the response | ||||
|     /// object into a memorystream as a sequence of asynchroneous reads. | ||||
|     ///  | ||||
|     /// The asynchronisity of RestClient is designed to move as much processing into the back-ground, allowing  | ||||
|     /// other threads to execute, while it waits for a response from the web-service. RestClient it self, can be | ||||
|     /// invoked by the caller in either synchroneous mode or asynchroneous mode. | ||||
|     /// </remarks> | ||||
|     public class RestClient | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private string realuri; | ||||
| 
 | ||||
|         #region member variables | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The base Uri of the web-service e.g. http://www.google.com  | ||||
|         /// </summary> | ||||
|         private string _url; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Path elements of the query | ||||
|         /// </summary> | ||||
|         private List<string> _pathElements = new List<string>(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Parameter elements of the query, e.g. min=34 | ||||
|         /// </summary> | ||||
|         private Dictionary<string, string> _parameterElements = new Dictionary<string, string>(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Request method. E.g. GET, POST, PUT or DELETE | ||||
|         /// </summary> | ||||
|         private string _method; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Temporary buffer used to store bytes temporarily as they come in from the server | ||||
|         /// </summary> | ||||
|         private byte[] _readbuf; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// MemoryStream representing the resultiong resource | ||||
|         /// </summary> | ||||
|         private Stream _resource; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// WebRequest object, held as a member variable | ||||
|         /// </summary> | ||||
|         private HttpWebRequest _request; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// WebResponse object, held as a member variable, so we can close it | ||||
|         /// </summary> | ||||
|         private HttpWebResponse _response; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// This flag will help block the main synchroneous method, in case we run in synchroneous mode | ||||
|         /// </summary> | ||||
|         public static ManualResetEvent _allDone = new ManualResetEvent(false); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Default time out period | ||||
|         /// </summary> | ||||
|         private const int DefaultTimeout = 10*1000; // 10 seconds timeout | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Default Buffer size of a block requested from the web-server | ||||
|         /// </summary> | ||||
|         private const int BufferSize = 4096; // Read blocks of 4 KB. | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// if an exception occours during async processing, we need to save it, so it can be  | ||||
|         /// rethrown on the primary thread; | ||||
|         /// </summary> | ||||
|         private Exception _asyncException; | ||||
| 
 | ||||
|         #endregion member variables | ||||
| 
 | ||||
|         #region constructors | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Instantiate a new RestClient | ||||
|         /// </summary> | ||||
|         /// <param name="url">Web-service to query, e.g. http://osgrid.org:8003</param> | ||||
|         public RestClient(string url) | ||||
|         { | ||||
|             _url = url; | ||||
|             _readbuf = new byte[BufferSize]; | ||||
|             _resource = new MemoryStream(); | ||||
|             _request = null; | ||||
|             _response = null; | ||||
|             _lock = new object(); | ||||
|         } | ||||
| 
 | ||||
|         private object _lock; | ||||
| 
 | ||||
|         #endregion constructors | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Add a path element to the query, e.g. assets | ||||
|         /// </summary> | ||||
|         /// <param name="element">path entry</param> | ||||
|         public void AddResourcePath(string element) | ||||
|         { | ||||
|             if (isSlashed(element)) | ||||
|                 _pathElements.Add(element.Substring(0, element.Length - 1)); | ||||
|             else | ||||
|                 _pathElements.Add(element); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Add a query parameter to the Url | ||||
|         /// </summary> | ||||
|         /// <param name="name">Name of the parameter, e.g. min</param> | ||||
|         /// <param name="value">Value of the parameter, e.g. 42</param> | ||||
|         public void AddQueryParameter(string name, string value) | ||||
|         { | ||||
|             _parameterElements.Add(HttpUtility.UrlEncode(name), HttpUtility.UrlEncode(value)); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Add a query parameter to the Url | ||||
|         /// </summary> | ||||
|         /// <param name="name">Name of the parameter, e.g. min</param> | ||||
|         public void AddQueryParameter(string name) | ||||
|         { | ||||
|             _parameterElements.Add(HttpUtility.UrlEncode(name), null); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Web-Request method, e.g. GET, PUT, POST, DELETE | ||||
|         /// </summary> | ||||
|         public string RequestMethod | ||||
|         { | ||||
|             get { return _method; } | ||||
|             set { _method = value; } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// True if string contains a trailing slash '/' | ||||
|         /// </summary> | ||||
|         /// <param name="s">string to be examined</param> | ||||
|         /// <returns>true if slash is present</returns> | ||||
|         private bool isSlashed(string s) | ||||
|         { | ||||
|             return s.Substring(s.Length - 1, 1) == "/"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// return a slash or blank. A slash will be returned if the string does not contain one | ||||
|         /// </summary> | ||||
|         /// <param name="s">stromg to be examined</param> | ||||
|         /// <returns>slash '/' if not already present</returns> | ||||
|         private string slash(string s) | ||||
|         { | ||||
|             return isSlashed(s) ? String.Empty : "/"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Build a Uri based on the initial Url, path elements and parameters | ||||
|         /// </summary> | ||||
|         /// <returns>fully constructed Uri</returns> | ||||
|         private Uri buildUri() | ||||
|         { | ||||
|             StringBuilder sb = new StringBuilder(); | ||||
|             sb.Append(_url); | ||||
| 
 | ||||
|             foreach (string e in _pathElements) | ||||
|             { | ||||
|                 sb.Append("/"); | ||||
|                 sb.Append(e); | ||||
|             } | ||||
| 
 | ||||
|             bool firstElement = true; | ||||
|             foreach (KeyValuePair<string, string> kv in _parameterElements) | ||||
|             { | ||||
|                 if (firstElement) | ||||
|                 { | ||||
|                     sb.Append("?"); | ||||
|                     firstElement = false; | ||||
|                 } | ||||
|                 else | ||||
|                     sb.Append("&"); | ||||
| 
 | ||||
|                 sb.Append(kv.Key); | ||||
|                 if (kv.Value != null && kv.Value.Length != 0) | ||||
|                 { | ||||
|                     sb.Append("="); | ||||
|                     sb.Append(kv.Value); | ||||
|                 } | ||||
|             } | ||||
|             realuri = sb.ToString(); | ||||
|             m_log.InfoFormat("[REST]: RestURL: {0}", realuri); | ||||
|             return new Uri(sb.ToString()); | ||||
|         } | ||||
| 
 | ||||
|         #region Async communications with server | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Async method, invoked when a block of data has been received from the service | ||||
|         /// </summary> | ||||
|         /// <param name="ar"></param> | ||||
|         private void StreamIsReadyDelegate(IAsyncResult ar) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 Stream s = (Stream) ar.AsyncState; | ||||
|                 int read = s.EndRead(ar); | ||||
| 
 | ||||
|                 if (read > 0) | ||||
|                 { | ||||
|                     _resource.Write(_readbuf, 0, read); | ||||
|                     IAsyncResult asynchronousResult = | ||||
|                         s.BeginRead(_readbuf, 0, BufferSize, new AsyncCallback(StreamIsReadyDelegate), s); | ||||
| 
 | ||||
|                     // TODO! Implement timeout, without killing the server | ||||
|                     //ThreadPool.RegisterWaitForSingleObject(asynchronousResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     s.Close(); | ||||
|                     _allDone.Set(); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 _allDone.Set(); | ||||
|                 _asyncException = e; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Async method, invoked when the initial response if received from the server | ||||
|         /// </summary> | ||||
|         /// <param name="ar"></param> | ||||
|         private void ResponseIsReadyDelegate(IAsyncResult ar) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 // grab response | ||||
|                 WebRequest wr = (WebRequest) ar.AsyncState; | ||||
|                 _response = (HttpWebResponse) wr.EndGetResponse(ar); | ||||
| 
 | ||||
|                 // get response stream, and setup async reading | ||||
|                 Stream s = _response.GetResponseStream(); | ||||
|                 IAsyncResult asynchronousResult = | ||||
|                     s.BeginRead(_readbuf, 0, BufferSize, new AsyncCallback(StreamIsReadyDelegate), s); | ||||
| 
 | ||||
|                 // TODO! Implement timeout, without killing the server | ||||
|                 // wait until completed, or we timed out | ||||
|                 // ThreadPool.RegisterWaitForSingleObject(asynchronousResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 _allDone.Set(); | ||||
|                 _asyncException = e; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // Abort the request if the timer fires. | ||||
|         private static void TimeoutCallback(object state, bool timedOut) | ||||
|         { | ||||
|             if (timedOut) | ||||
|             { | ||||
|                 HttpWebRequest request = state as HttpWebRequest; | ||||
|                 if (request != null) | ||||
|                 { | ||||
|                     request.Abort(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #endregion Async communications with server | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Perform synchroneous request | ||||
|         /// </summary> | ||||
|         public Stream Request() | ||||
|         { | ||||
|             lock (_lock) | ||||
|             { | ||||
|                 _request = (HttpWebRequest) WebRequest.Create(buildUri()); | ||||
|                 _request.KeepAlive = false; | ||||
|                 _request.ContentType = "application/xml"; | ||||
|                 _request.Timeout = 200000; | ||||
|                 _asyncException = null; | ||||
| 
 | ||||
| //                IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); | ||||
|                 _response = (HttpWebResponse) _request.GetResponse(); | ||||
|                 Stream src = _response.GetResponseStream(); | ||||
|                 int length = src.Read(_readbuf, 0, BufferSize); | ||||
|                 while (length > 0) | ||||
|                 { | ||||
|                     _resource.Write(_readbuf, 0, length); | ||||
|                     length = src.Read(_readbuf, 0, BufferSize); | ||||
|                 } | ||||
| 
 | ||||
| 
 | ||||
|                 // TODO! Implement timeout, without killing the server | ||||
|                 // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted | ||||
|                 //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); | ||||
| 
 | ||||
| //                _allDone.WaitOne(); | ||||
|                 if (_response != null) | ||||
|                     _response.Close(); | ||||
|                 if (_asyncException != null) | ||||
|                     throw _asyncException; | ||||
| 
 | ||||
|                 if (_resource != null) | ||||
|                 { | ||||
|                     _resource.Flush(); | ||||
|                     _resource.Seek(0, SeekOrigin.Begin); | ||||
|                 } | ||||
| 
 | ||||
|                 return _resource; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public Stream Request(Stream src) | ||||
|         { | ||||
|             _request = (HttpWebRequest) WebRequest.Create(buildUri()); | ||||
|             _request.KeepAlive = false; | ||||
|             _request.ContentType = "application/xml"; | ||||
|             _request.Timeout = 900000; | ||||
|             _request.Method = RequestMethod; | ||||
|             _asyncException = null; | ||||
|             _request.ContentLength = src.Length; | ||||
| 
 | ||||
|             m_log.InfoFormat("[REST]: Request Length {0}", _request.ContentLength); | ||||
|             m_log.InfoFormat("[REST]: Sending Web Request {0}", buildUri()); | ||||
|             src.Seek(0, SeekOrigin.Begin); | ||||
|             m_log.Info("[REST]: Seek is ok"); | ||||
|             Stream dst = _request.GetRequestStream(); | ||||
|             m_log.Info("[REST]: GetRequestStream is ok"); | ||||
| 
 | ||||
|             byte[] buf = new byte[1024]; | ||||
|             int length = src.Read(buf, 0, 1024); | ||||
|             m_log.Info("[REST]: First Read is ok"); | ||||
|             while (length > 0) | ||||
|             { | ||||
|                 dst.Write(buf, 0, length); | ||||
|                 length = src.Read(buf, 0, 1024); | ||||
|             } | ||||
| 
 | ||||
|             _response = (HttpWebResponse) _request.GetResponse(); | ||||
| 
 | ||||
| //            IAsyncResult responseAsyncResult = _request.BeginGetResponse(new AsyncCallback(ResponseIsReadyDelegate), _request); | ||||
| 
 | ||||
|             // TODO! Implement timeout, without killing the server | ||||
|             // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted | ||||
|             //ThreadPool.RegisterWaitForSingleObject(responseAsyncResult.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), _request, DefaultTimeout, true); | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         #region Async Invocation | ||||
| 
 | ||||
|         public IAsyncResult BeginRequest(AsyncCallback callback, object state) | ||||
|         { | ||||
|             /// <summary> | ||||
|             /// In case, we are invoked asynchroneously this object will keep track of the state | ||||
|             /// </summary> | ||||
|             AsyncResult<Stream> ar = new AsyncResult<Stream>(callback, state); | ||||
|             ThreadPool.QueueUserWorkItem(RequestHelper, ar); | ||||
|             return ar; | ||||
|         } | ||||
| 
 | ||||
|         public Stream EndRequest(IAsyncResult asyncResult) | ||||
|         { | ||||
|             AsyncResult<Stream> ar = (AsyncResult<Stream>) asyncResult; | ||||
| 
 | ||||
|             // Wait for operation to complete, then return result or  | ||||
|             // throw exception | ||||
|             return ar.EndInvoke(); | ||||
|         } | ||||
| 
 | ||||
|         private void RequestHelper(Object asyncResult) | ||||
|         { | ||||
|             // We know that it's really an AsyncResult<DateTime> object | ||||
|             AsyncResult<Stream> ar = (AsyncResult<Stream>) asyncResult; | ||||
|             try | ||||
|             { | ||||
|                 // Perform the operation; if sucessful set the result | ||||
|                 Stream s = Request(); | ||||
|                 ar.SetAsCompleted(s, false); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 // If operation fails, set the exception | ||||
|                 ar.HandleException(e, false); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #endregion Async Invocation | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,550 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Reflection; | ||||
| using System.Security.Cryptography; | ||||
| using libsecondlife; | ||||
| using libsecondlife.StructuredData; | ||||
| using Nwc.XmlRpc; | ||||
| using OpenSim.Framework.Console; | ||||
| using OpenSim.Framework.Statistics; | ||||
| 
 | ||||
| namespace OpenSim.Framework.UserManagement | ||||
| { | ||||
|     /// <summary> | ||||
|     /// Base class for user management (create, read, etc) | ||||
|     /// </summary> | ||||
|     public abstract class UserManagerBase : IUserService | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public UserConfig _config; | ||||
|         private 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) | ||||
|         { | ||||
|             if (!String.IsNullOrEmpty(FileName)) | ||||
|             { | ||||
|                 m_log.Info("[USERSTORAGE]: Attempting to load " + FileName); | ||||
|                 Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||||
| 
 | ||||
|                 m_log.Info("[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())); | ||||
|                             AddPlugin(plug); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void AddPlugin(IUserData plug) | ||||
|         { | ||||
|             plug.Initialise(); | ||||
|             _plugins.Add(plug.getName(), plug); | ||||
|             m_log.Info("[USERSTORAGE]: Added IUserData Interface"); | ||||
|         } | ||||
| 
 | ||||
|         #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 null if no user profile is found.</returns> | ||||
|         public UserProfileData GetUserProfile(LLUUID uuid) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 UserProfileData profile = plugin.Value.GetUserByUUID(uuid); | ||||
| 
 | ||||
|                 if (null != profile) | ||||
|                 { | ||||
|                     profile.currentAgent = getUserAgent(profile.UUID); | ||||
|                     return profile; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         public List<AvatarPickerAvatar> GenerateAgentPickerRequestResponse(LLUUID queryID, string query) | ||||
|         { | ||||
|             List<AvatarPickerAvatar> pickerlist = new List<AvatarPickerAvatar>(); | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     pickerlist = plugin.Value.GeneratePickerResults(queryID, query); | ||||
|                 } | ||||
|                 catch (Exception) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to generate AgentPickerData via  " + plugin.Key + "(" + query + ")"); | ||||
|                     return new List<AvatarPickerAvatar>(); | ||||
|                 } | ||||
|             } | ||||
|             return pickerlist; | ||||
|         } | ||||
| 
 | ||||
|         /// <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 null if no profile is found</returns> | ||||
|         public UserProfileData GetUserProfile(string fname, string lname) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 UserProfileData profile = plugin.Value.GetUserByName(fname, lname); | ||||
| 
 | ||||
|                 if (profile != null) | ||||
|                 { | ||||
|                     profile.currentAgent = getUserAgent(profile.UUID); | ||||
|                     return profile; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Set's user profile from object | ||||
|         /// </summary> | ||||
|         /// <param name="fname">First name</param> | ||||
|         /// <param name="lname">Last name</param> | ||||
|         /// <returns>A user profile</returns> | ||||
|         public bool setUserProfile(UserProfileData data) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     plugin.Value.UpdateUserProfile(data); | ||||
|                     return true; | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to set user via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region Get UserAgent | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads a user agent by uuid (not called directly) | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The agent's 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) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads a user's friend list | ||||
|         /// </summary> | ||||
|         /// <param name="name">the UUID of the friend list owner</param> | ||||
|         /// <returns>A List of FriendListItems that contains info about the user's friends</returns> | ||||
|         public List<FriendListItem> GetUserFriendList(LLUUID ownerID) | ||||
|         { | ||||
| 
 | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     return plugin.Value.GetUserFriendList(ownerID); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to GetUserFriendList via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         public void StoreWebLoginKey(LLUUID agentID, LLUUID webLoginKey) | ||||
|         { | ||||
| 
 | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     plugin.Value.StoreWebLoginKey(agentID, webLoginKey); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to Store WebLoginKey via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     plugin.Value.AddNewUserFriend(friendlistowner,friend,perms); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to AddNewUserFriend via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                    plugin.Value.RemoveUserFriend(friendlistowner, friend); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to RemoveUserFriend via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     plugin.Value.UpdateUserFriendPerms(friendlistowner, friend, perms); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to UpdateUserFriendPerms via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Loads a user agent by name (not called directly) | ||||
|         /// </summary> | ||||
|         /// <param name="name">The agent's 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) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to find user via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // TODO: document | ||||
|         public void clearUserAgent(LLUUID agentID) | ||||
|         { | ||||
|             UserProfileData profile = GetUserProfile(agentID); | ||||
|             profile.currentAgent = null; | ||||
| 
 | ||||
|             setUserProfile(profile); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads a user agent by name (not called directly) | ||||
|         /// </summary> | ||||
|         /// <param name="fname">The agent's firstname</param> | ||||
|         /// <param name="lname">The agent's 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) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: 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(UserProfileData profile, XmlRpcRequest request) | ||||
|         { | ||||
|             //Hashtable requestData = (Hashtable) request.Params[0]; | ||||
| 
 | ||||
|             UserAgentData agent = new UserAgentData(); | ||||
| 
 | ||||
|             // User connection | ||||
|             agent.agentOnline = true; | ||||
| 
 | ||||
|             // 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) | ||||
| //                    { | ||||
| //                    } | ||||
| //                } | ||||
| //            } | ||||
| 
 | ||||
|             // What time did the user login? | ||||
|             agent.loginTime = Util.UnixTimeSinceEpoch(); | ||||
|             agent.logoutTime = 0; | ||||
| 
 | ||||
|             // Current location | ||||
|             agent.regionID = LLUUID.Zero; // Fill in later | ||||
|             agent.currentRegion = LLUUID.Zero; // Fill in later | ||||
| 
 | ||||
|             profile.currentAgent = agent; | ||||
|         } | ||||
|          | ||||
|         /// <summary> | ||||
|         /// Process a user logoff from OpenSim. | ||||
|         /// </summary> | ||||
|         /// <param name="userid"></param> | ||||
|         /// <param name="regionid"></param> | ||||
|         /// <param name="regionhandle"></param> | ||||
|         /// <param name="posx"></param> | ||||
|         /// <param name="posy"></param> | ||||
|         /// <param name="posz"></param> | ||||
|         public void LogOffUser(LLUUID userid, LLUUID regionid, ulong regionhandle, float posx, float posy, float posz) | ||||
|         { | ||||
|             if (StatsManager.UserStats != null) | ||||
|                 StatsManager.UserStats.AddLogout(); | ||||
|              | ||||
|             UserProfileData userProfile; | ||||
|             UserAgentData userAgent; | ||||
|             LLVector3 currentPos = new LLVector3(posx, posy, posz); | ||||
| 
 | ||||
|             userProfile = GetUserProfile(userid); | ||||
| 
 | ||||
|             if (userProfile != null) | ||||
|             { | ||||
|                 // This line needs to be in side the above if statement or the UserServer will crash on some logouts. | ||||
|                 m_log.Info("[LOGOUT]: " + userProfile.username + " " + userProfile.surname + " from " + regionhandle + "(" + posx + "," + posy + "," + posz + ")"); | ||||
|                  | ||||
|                 userAgent = userProfile.currentAgent; | ||||
|                 if (userAgent != null) | ||||
|                 { | ||||
|                     userAgent.agentOnline = false; | ||||
|                     userAgent.logoutTime = Util.UnixTimeSinceEpoch(); | ||||
|                     userAgent.sessionID = LLUUID.Zero; | ||||
|                     if (regionid != null) | ||||
|                     { | ||||
|                         userAgent.currentRegion = regionid; | ||||
|                     } | ||||
|                     userAgent.currentHandle = regionhandle; | ||||
| 
 | ||||
|                     userAgent.currentPos = currentPos; | ||||
| 
 | ||||
|                     userProfile.currentAgent = userAgent; | ||||
| 
 | ||||
| 
 | ||||
|                     CommitAgent(ref userProfile); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     // If currentagent is null, we can't reference it here or the UserServer crashes! | ||||
|                     m_log.Info("[LOGOUT]: didn't save logout position: " + userid.ToString()); | ||||
|                 } | ||||
|                  | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.Warn("[LOGOUT]: Unknown User logged out"); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         public void CreateAgent(UserProfileData profile, LLSD request) | ||||
|         { | ||||
|             UserAgentData agent = new UserAgentData(); | ||||
| 
 | ||||
|             // User connection | ||||
|             agent.agentOnline = true; | ||||
| 
 | ||||
|             // 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; | ||||
| 
 | ||||
|             // What time did the user login? | ||||
|             agent.loginTime = Util.UnixTimeSinceEpoch(); | ||||
|             agent.logoutTime = 0; | ||||
| 
 | ||||
|             // Current location | ||||
|             agent.regionID = LLUUID.Zero; // Fill in later | ||||
|             agent.currentRegion = LLUUID.Zero; // 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) | ||||
|         { | ||||
|             // TODO: how is this function different from setUserProfile? | ||||
|             return setUserProfile(profile); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="user"></param> | ||||
|         public LLUUID 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 = String.Empty; | ||||
|             user.created = Util.UnixTimeSinceEpoch(); | ||||
|             user.homeLookAt = new LLVector3(100, 100, 100); | ||||
|             user.homeRegionX = regX; | ||||
|             user.homeRegionY = regY; | ||||
| 
 | ||||
|             foreach (KeyValuePair<string, IUserData> plugin in _plugins) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     plugin.Value.AddNewUserProfile(user); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Info("[USERSTORAGE]: Unable to add user via " + plugin.Key + "(" + e.ToString() + ")"); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return user.UUID; | ||||
|         } | ||||
| 
 | ||||
|         public abstract UserProfileData SetupMasterUser(string firstName, string lastName); | ||||
|         public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password); | ||||
|         public abstract UserProfileData SetupMasterUser(LLUUID uuid); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,117 @@ | |||
| /* | ||||
| * 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.IO; | ||||
| using System.Net; | ||||
| using System.Text; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Configuration.HTTP | ||||
| { | ||||
|     public class HTTPConfiguration : IGenericConfig | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private RemoteConfigSettings remoteConfigSettings; | ||||
| 
 | ||||
|         private XmlConfiguration xmlConfig; | ||||
| 
 | ||||
|         private string configFileName = System.String.Empty; | ||||
| 
 | ||||
|         public HTTPConfiguration() | ||||
|         { | ||||
|             remoteConfigSettings = new RemoteConfigSettings("remoteconfig.xml"); | ||||
|             xmlConfig = new XmlConfiguration(); | ||||
|         } | ||||
| 
 | ||||
|         public void SetFileName(string fileName) | ||||
|         { | ||||
|             configFileName = fileName; | ||||
|         } | ||||
| 
 | ||||
|         public void LoadData() | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 StringBuilder sb = new StringBuilder(); | ||||
| 
 | ||||
|                 byte[] buf = new byte[8192]; | ||||
|                 HttpWebRequest request = | ||||
|                     (HttpWebRequest) WebRequest.Create(remoteConfigSettings.baseConfigURL + configFileName); | ||||
|                 HttpWebResponse response = (HttpWebResponse) request.GetResponse(); | ||||
| 
 | ||||
|                 Stream resStream = response.GetResponseStream(); | ||||
| 
 | ||||
|                 string tempString = null; | ||||
|                 int count = 0; | ||||
| 
 | ||||
|                 do | ||||
|                 { | ||||
|                     count = resStream.Read(buf, 0, buf.Length); | ||||
|                     if (count != 0) | ||||
|                     { | ||||
|                         tempString = Encoding.ASCII.GetString(buf, 0, count); | ||||
|                         sb.Append(tempString); | ||||
|                     } | ||||
|                 } while (count > 0); | ||||
|                 LoadDataFromString(sb.ToString()); | ||||
|             } | ||||
|             catch (WebException) | ||||
|             { | ||||
|                 m_log.Warn("Unable to connect to remote configuration file (" + | ||||
|                                       remoteConfigSettings.baseConfigURL + configFileName + | ||||
|                                       "). Creating local file instead."); | ||||
|                 xmlConfig.SetFileName(configFileName); | ||||
|                 xmlConfig.LoadData(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void LoadDataFromString(string data) | ||||
|         { | ||||
|             xmlConfig.LoadDataFromString(data); | ||||
|         } | ||||
| 
 | ||||
|         public string GetAttribute(string attributeName) | ||||
|         { | ||||
|             return xmlConfig.GetAttribute(attributeName); | ||||
|         } | ||||
| 
 | ||||
|         public bool SetAttribute(string attributeName, string attributeValue) | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public void Commit() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public void Close() | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,62 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| namespace OpenSim.Framework.Configuration.HTTP | ||||
| { | ||||
|     public class RemoteConfigSettings | ||||
|     { | ||||
|         private ConfigurationMember configMember; | ||||
| 
 | ||||
|         public string baseConfigURL = System.String.Empty; | ||||
| 
 | ||||
|         public RemoteConfigSettings(string filename) | ||||
|         { | ||||
|             configMember = | ||||
|                 new ConfigurationMember(filename, "REMOTE CONFIG SETTINGS", loadConfigurationOptions, | ||||
|                                         handleIncomingConfiguration,true); | ||||
|             configMember.forceConfigurationPluginLibrary("OpenSim.Framework.Configuration.XML.dll"); | ||||
|             configMember.performConfigurationRetrieve(); | ||||
|         } | ||||
| 
 | ||||
|         public void loadConfigurationOptions() | ||||
|         { | ||||
|             configMember.addConfigurationOption("base_config_url", | ||||
|                                                 ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY, | ||||
|                                                 "URL Containing Configuration Files", "http://localhost/", false); | ||||
|         } | ||||
| 
 | ||||
|         public bool handleIncomingConfiguration(string configuration_key, object configuration_result) | ||||
|         { | ||||
|             if (configuration_key == "base_config_url") | ||||
|             { | ||||
|                 baseConfigURL = (string) configuration_result; | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,139 @@ | |||
| /* | ||||
| * 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.IO; | ||||
| using System.Xml; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Configuration | ||||
| { | ||||
|     public class XmlConfiguration : IGenericConfig | ||||
|     { | ||||
|         private XmlDocument doc; | ||||
|         private XmlNode rootNode; | ||||
|         private XmlNode configNode; | ||||
|         private string fileName; | ||||
|         private bool createdFile = false; | ||||
| 
 | ||||
|         public void SetFileName(string file) | ||||
|         { | ||||
|             fileName = file; | ||||
|         } | ||||
| 
 | ||||
|         private void LoadDataToClass() | ||||
|         { | ||||
|             rootNode = doc.FirstChild; | ||||
|             if (rootNode.Name != "Root") | ||||
|                 throw new Exception("Error: Invalid .xml File. Missing <Root>"); | ||||
| 
 | ||||
|             configNode = rootNode.FirstChild; | ||||
|             if (configNode.Name != "Config") | ||||
|                 throw new Exception("Error: Invalid .xml File. <Root> first child should be <Config>"); | ||||
|         } | ||||
| 
 | ||||
|         public void LoadData() | ||||
|         { | ||||
|             lock (this) | ||||
|             { | ||||
|                 doc = new XmlDocument(); | ||||
|                 if (File.Exists(fileName)) | ||||
|                 { | ||||
|                     XmlTextReader reader = new XmlTextReader(fileName); | ||||
|                     reader.WhitespaceHandling = WhitespaceHandling.None; | ||||
|                     doc.Load(reader); | ||||
|                     reader.Close(); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     createdFile = true; | ||||
|                     rootNode = doc.CreateNode(XmlNodeType.Element, "Root", String.Empty); | ||||
|                     doc.AppendChild(rootNode); | ||||
|                     configNode = doc.CreateNode(XmlNodeType.Element, "Config", String.Empty); | ||||
|                     rootNode.AppendChild(configNode); | ||||
|                 } | ||||
| 
 | ||||
|                 LoadDataToClass(); | ||||
| 
 | ||||
|                 if (createdFile) | ||||
|                 { | ||||
|                     Commit(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void LoadDataFromString(string data) | ||||
|         { | ||||
|             doc = new XmlDocument(); | ||||
|             doc.LoadXml(data); | ||||
| 
 | ||||
|             LoadDataToClass(); | ||||
|         } | ||||
| 
 | ||||
|         public string GetAttribute(string attributeName) | ||||
|         { | ||||
|             string result = null; | ||||
|             if (configNode.Attributes[attributeName] != null) | ||||
|             { | ||||
|                 result = ((XmlAttribute) configNode.Attributes.GetNamedItem(attributeName)).Value; | ||||
|             } | ||||
|             return result; | ||||
|         } | ||||
| 
 | ||||
|         public bool SetAttribute(string attributeName, string attributeValue) | ||||
|         { | ||||
|             if (configNode.Attributes[attributeName] != null) | ||||
|             { | ||||
|                 ((XmlAttribute) configNode.Attributes.GetNamedItem(attributeName)).Value = attributeValue; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 XmlAttribute attri; | ||||
|                 attri = doc.CreateAttribute(attributeName); | ||||
|                 attri.Value = attributeValue; | ||||
|                 configNode.Attributes.Append(attri); | ||||
|             } | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public void Commit() | ||||
|         { | ||||
|             if (!Directory.Exists(Util.configDir())) | ||||
|             { | ||||
|                 Directory.CreateDirectory(Util.configDir()); | ||||
|             } | ||||
|             doc.Save(fileName); | ||||
|         } | ||||
| 
 | ||||
|         public void Close() | ||||
|         { | ||||
|             configNode = null; | ||||
|             rootNode = null; | ||||
|             doc = null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,503 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Globalization; | ||||
| using System.Net; | ||||
| using System.Reflection; | ||||
| using System.Xml; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class ConfigurationMember | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         public delegate bool ConfigurationOptionResult(string configuration_key, object configuration_result); | ||||
| 
 | ||||
|         public delegate void ConfigurationOptionsLoad(); | ||||
| 
 | ||||
|         private List<ConfigurationOption> configurationOptions = new List<ConfigurationOption>(); | ||||
|         private string configurationFilename = String.Empty; | ||||
|         private string configurationDescription = String.Empty; | ||||
|         private XmlNode configurationFromXMLNode = null; | ||||
|         private ConfigurationOptionsLoad loadFunction; | ||||
|         private ConfigurationOptionResult resultFunction; | ||||
| 
 | ||||
|         private IGenericConfig configurationPlugin = null; | ||||
|         private bool useConsoleToPromptOnError = true; | ||||
|         /// <summary> | ||||
|         /// This is the default configuration DLL loaded | ||||
|         /// </summary> | ||||
|         private string configurationPluginFilename = "OpenSim.Framework.Configuration.XML.dll"; | ||||
| 
 | ||||
|         public ConfigurationMember(string configuration_filename, string configuration_description, | ||||
|                                    ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function, bool use_console_to_prompt_on_error) | ||||
|         { | ||||
|             configurationFilename = configuration_filename; | ||||
|             configurationDescription = configuration_description; | ||||
|             loadFunction = load_function; | ||||
|             resultFunction = result_function; | ||||
|             useConsoleToPromptOnError = use_console_to_prompt_on_error; | ||||
|         } | ||||
| 
 | ||||
|         public ConfigurationMember(XmlNode configuration_xml, string configuration_description, | ||||
|                                    ConfigurationOptionsLoad load_function, ConfigurationOptionResult result_function, bool use_console_to_prompt_on_error) | ||||
|         { | ||||
|             configurationFilename = String.Empty; | ||||
|             configurationFromXMLNode = configuration_xml; | ||||
|             configurationDescription = configuration_description; | ||||
|             loadFunction = load_function; | ||||
|             resultFunction = result_function; | ||||
|             useConsoleToPromptOnError = use_console_to_prompt_on_error; | ||||
|         } | ||||
| 
 | ||||
|         public void setConfigurationFilename(string filename) | ||||
|         { | ||||
|             configurationFilename = filename; | ||||
|         } | ||||
| 
 | ||||
|         public void setConfigurationDescription(string desc) | ||||
|         { | ||||
|             configurationDescription = desc; | ||||
|         } | ||||
| 
 | ||||
|         public void setConfigurationResultFunction(ConfigurationOptionResult result) | ||||
|         { | ||||
|             resultFunction = result; | ||||
|         } | ||||
| 
 | ||||
|         public void forceConfigurationPluginLibrary(string dll_filename) | ||||
|         { | ||||
|             configurationPluginFilename = dll_filename; | ||||
|         } | ||||
| 
 | ||||
|         private void checkAndAddConfigOption(ConfigurationOption option) | ||||
|         { | ||||
|             if ((option.configurationKey != String.Empty && option.configurationQuestion != String.Empty) || | ||||
|                 (option.configurationKey != String.Empty && option.configurationUseDefaultNoPrompt)) | ||||
|             { | ||||
|                 if (!configurationOptions.Contains(option)) | ||||
|                 { | ||||
|                     configurationOptions.Add(option); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_log.Info( | ||||
|                     "Required fields for adding a configuration option is invalid. Will not add this option (" + | ||||
|                     option.configurationKey + ")"); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void addConfigurationOption(string configuration_key, | ||||
|                                            ConfigurationOption.ConfigurationTypes configuration_type, | ||||
|                                            string configuration_question, string configuration_default, | ||||
|                                            bool use_default_no_prompt) | ||||
|         { | ||||
|             ConfigurationOption configOption = new ConfigurationOption(); | ||||
|             configOption.configurationKey = configuration_key; | ||||
|             configOption.configurationQuestion = configuration_question; | ||||
|             configOption.configurationDefault = configuration_default; | ||||
|             configOption.configurationType = configuration_type; | ||||
|             configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; | ||||
|             configOption.shouldIBeAsked = null; //Assumes true, I can ask whenever | ||||
|             checkAndAddConfigOption(configOption); | ||||
|         } | ||||
| 
 | ||||
|         public void addConfigurationOption(string configuration_key, | ||||
|                                            ConfigurationOption.ConfigurationTypes configuration_type, | ||||
|                                            string configuration_question, string configuration_default, | ||||
|                                            bool use_default_no_prompt, | ||||
|                                            ConfigurationOption.ConfigurationOptionShouldBeAsked shouldIBeAskedDelegate) | ||||
|         { | ||||
|             ConfigurationOption configOption = new ConfigurationOption(); | ||||
|             configOption.configurationKey = configuration_key; | ||||
|             configOption.configurationQuestion = configuration_question; | ||||
|             configOption.configurationDefault = configuration_default; | ||||
|             configOption.configurationType = configuration_type; | ||||
|             configOption.configurationUseDefaultNoPrompt = use_default_no_prompt; | ||||
|             configOption.shouldIBeAsked = shouldIBeAskedDelegate; | ||||
|             checkAndAddConfigOption(configOption); | ||||
|         } | ||||
| 
 | ||||
|         // TEMP - REMOVE | ||||
|         private int cE = 0; | ||||
|         public void performConfigurationRetrieve() | ||||
|         { | ||||
|             if (cE > 1) | ||||
|                 m_log.Error("READING CONFIGURATION COUT: " + cE.ToString()); | ||||
| 
 | ||||
| 
 | ||||
|             configurationPlugin = LoadConfigDll(configurationPluginFilename); | ||||
|             configurationOptions.Clear(); | ||||
|             if (loadFunction == null) | ||||
|             { | ||||
|                 m_log.Error("Load Function for '" + configurationDescription + | ||||
|                                        "' is null. Refusing to run configuration."); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if (resultFunction == null) | ||||
|             { | ||||
|                 m_log.Error("Result Function for '" + configurationDescription + | ||||
|                                        "' is null. Refusing to run configuration."); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             m_log.Info("[CONFIG]: Calling Configuration Load Function..."); | ||||
|             loadFunction(); | ||||
| 
 | ||||
|             if (configurationOptions.Count <= 0) | ||||
|             { | ||||
|                 m_log.Error("[CONFIG]: No configuration options were specified for '" + configurationOptions + | ||||
|                             "'. Refusing to continue configuration."); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             bool useFile = true; | ||||
|             if (configurationPlugin == null) | ||||
|             { | ||||
|                 m_log.Error("[CONFIG]: Configuration Plugin NOT LOADED!"); | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if (configurationFilename.Trim() != String.Empty) | ||||
|             { | ||||
|                 configurationPlugin.SetFileName(configurationFilename); | ||||
|                 try | ||||
|                 { | ||||
|                     configurationPlugin.LoadData(); | ||||
|                     useFile = true; | ||||
|                 } | ||||
|                 catch (XmlException e) | ||||
|                 { | ||||
|                     m_log.Error("Error loading " + configurationFilename + ": " + e.ToString()); | ||||
|                     useFile = false; | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 if (configurationFromXMLNode != null) | ||||
|                 { | ||||
|                     m_log.Info("Loading from XML Node, will not save to the file"); | ||||
|                     configurationPlugin.LoadDataFromString(configurationFromXMLNode.OuterXml); | ||||
|                 } | ||||
| 
 | ||||
|                 m_log.Info("XML Configuration Filename is not valid; will not save to the file."); | ||||
|                 useFile = false; | ||||
|             } | ||||
| 
 | ||||
|             foreach (ConfigurationOption configOption in configurationOptions) | ||||
|             { | ||||
|                 bool convertSuccess = false; | ||||
|                 object return_result = null; | ||||
|                 string errorMessage = String.Empty; | ||||
|                 bool ignoreNextFromConfig = false; | ||||
|                 while (convertSuccess == false) | ||||
|                 { | ||||
|                     string console_result = String.Empty; | ||||
|                     string attribute = null; | ||||
|                     if (useFile || configurationFromXMLNode != null) | ||||
|                     { | ||||
|                         if (!ignoreNextFromConfig) | ||||
|                         { | ||||
|                             attribute = configurationPlugin.GetAttribute(configOption.configurationKey); | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             ignoreNextFromConfig = false; | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     if (attribute == null) | ||||
|                     { | ||||
|                         if (configOption.configurationUseDefaultNoPrompt || useConsoleToPromptOnError == false) | ||||
|                         { | ||||
|                             console_result = configOption.configurationDefault; | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             if ((configOption.shouldIBeAsked != null && | ||||
|                                  configOption.shouldIBeAsked(configOption.configurationKey)) || | ||||
|                                 configOption.shouldIBeAsked == null) | ||||
|                             { | ||||
|                                 if (configurationDescription.Trim() != String.Empty) | ||||
|                                 { | ||||
|                                     console_result = | ||||
|                                         MainConsole.Instance.CmdPrompt( | ||||
|                                             configurationDescription + ": " + configOption.configurationQuestion, | ||||
|                                             configOption.configurationDefault); | ||||
|                                 } | ||||
|                                 else | ||||
|                                 { | ||||
|                                     console_result = | ||||
|                                         MainConsole.Instance.CmdPrompt(configOption.configurationQuestion, | ||||
|                                                                       configOption.configurationDefault); | ||||
|                                 } | ||||
|                             } | ||||
|                             else | ||||
|                             { | ||||
|                                 //Dont Ask! Just use default | ||||
|                                 console_result = configOption.configurationDefault; | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         console_result = attribute; | ||||
|                     } | ||||
| 
 | ||||
|                     switch (configOption.configurationType) | ||||
|                     { | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_STRING: | ||||
|                             return_result = console_result; | ||||
|                             convertSuccess = true; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_STRING_NOT_EMPTY: | ||||
|                             if (console_result.Length > 0) | ||||
|                             { | ||||
|                                 return_result = console_result; | ||||
|                                 convertSuccess = true; | ||||
|                             } | ||||
|                             errorMessage = "a string that is not empty"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_BOOLEAN: | ||||
|                             bool boolResult; | ||||
|                             if (Boolean.TryParse(console_result, out boolResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = boolResult; | ||||
|                             } | ||||
|                             errorMessage = "'true' or 'false' (Boolean)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_BYTE: | ||||
|                             byte byteResult; | ||||
|                             if (Byte.TryParse(console_result, out byteResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = byteResult; | ||||
|                             } | ||||
|                             errorMessage = "a byte (Byte)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_CHARACTER: | ||||
|                             char charResult; | ||||
|                             if (Char.TryParse(console_result, out charResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = charResult; | ||||
|                             } | ||||
|                             errorMessage = "a character (Char)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_INT16: | ||||
|                             short shortResult; | ||||
|                             if (Int16.TryParse(console_result, out shortResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = shortResult; | ||||
|                             } | ||||
|                             errorMessage = "a signed 32 bit integer (short)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_INT32: | ||||
|                             int intResult; | ||||
|                             if (Int32.TryParse(console_result, out intResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = intResult; | ||||
|                             } | ||||
|                             errorMessage = "a signed 32 bit integer (int)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_INT64: | ||||
|                             long longResult; | ||||
|                             if (Int64.TryParse(console_result, out longResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = longResult; | ||||
|                             } | ||||
|                             errorMessage = "a signed 32 bit integer (long)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_IP_ADDRESS: | ||||
|                             IPAddress ipAddressResult; | ||||
|                             if (IPAddress.TryParse(console_result, out ipAddressResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = ipAddressResult; | ||||
|                             } | ||||
|                             errorMessage = "an IP Address (IPAddress)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_LLUUID: | ||||
|                             LLUUID uuidResult; | ||||
|                             if (LLUUID.TryParse(console_result, out uuidResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = uuidResult; | ||||
|                             } | ||||
|                             errorMessage = "a UUID (LLUUID)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_LLVECTOR3: | ||||
|                             LLVector3 vectorResult; | ||||
|                             if (LLVector3.TryParse(console_result, out vectorResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = vectorResult; | ||||
|                             } | ||||
|                             errorMessage = "a vector (LLVector3)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_UINT16: | ||||
|                             ushort ushortResult; | ||||
|                             if (UInt16.TryParse(console_result, out ushortResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = ushortResult; | ||||
|                             } | ||||
|                             errorMessage = "an unsigned 16 bit integer (ushort)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_UINT32: | ||||
|                             uint uintResult; | ||||
|                             if (UInt32.TryParse(console_result, out uintResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = uintResult; | ||||
|                             } | ||||
|                             errorMessage = "an unsigned 32 bit integer (uint)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_UINT64: | ||||
|                             ulong ulongResult; | ||||
|                             if (UInt64.TryParse(console_result, out ulongResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = ulongResult; | ||||
|                             } | ||||
|                             errorMessage = "an unsigned 64 bit integer (ulong)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_FLOAT: | ||||
|                             float floatResult; | ||||
|                             if ( | ||||
|                                 float.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, | ||||
|                                                out floatResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = floatResult; | ||||
|                             } | ||||
|                             errorMessage = "a single-precision floating point number (float)"; | ||||
|                             break; | ||||
|                         case ConfigurationOption.ConfigurationTypes.TYPE_DOUBLE: | ||||
|                             double doubleResult; | ||||
|                             if ( | ||||
|                                 Double.TryParse(console_result, NumberStyles.AllowDecimalPoint, Culture.NumberFormatInfo, | ||||
|                                                 out doubleResult)) | ||||
|                             { | ||||
|                                 convertSuccess = true; | ||||
|                                 return_result = doubleResult; | ||||
|                             } | ||||
|                             errorMessage = "an double-precision floating point number (double)"; | ||||
|                             break; | ||||
|                     } | ||||
| 
 | ||||
|                     if (convertSuccess) | ||||
|                     { | ||||
|                         if (useFile) | ||||
|                         { | ||||
|                             configurationPlugin.SetAttribute(configOption.configurationKey, console_result); | ||||
|                         } | ||||
| 
 | ||||
|                         if (!resultFunction(configOption.configurationKey, return_result)) | ||||
|                         { | ||||
|                             m_log.Info( | ||||
|                                 "The handler for the last configuration option denied that input, please try again."); | ||||
|                             convertSuccess = false; | ||||
|                             ignoreNextFromConfig = true; | ||||
|                         } | ||||
|                     } | ||||
|                     else | ||||
|                     { | ||||
|                         if (configOption.configurationUseDefaultNoPrompt) | ||||
|                         { | ||||
|                             m_log.Error(string.Format( | ||||
|                                             "[CONFIG]: [{3}]:[{1}] is not valid default for parameter [{0}].\nThe configuration result must be parsable to {2}.\n", | ||||
|                                             configOption.configurationKey, console_result, errorMessage, | ||||
|                                             configurationFilename)); | ||||
|                             convertSuccess = true; | ||||
|                         } | ||||
|                         else | ||||
|                         { | ||||
|                             m_log.Warn(string.Format( | ||||
|                                            "[CONFIG]: [{3}]:[{1}] is not a valid value [{0}].\nThe configuration result must be parsable to {2}.\n", | ||||
|                                            configOption.configurationKey, console_result, errorMessage, | ||||
|                                            configurationFilename)); | ||||
|                             ignoreNextFromConfig = true; | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (useFile) | ||||
|             { | ||||
|                 configurationPlugin.Commit(); | ||||
|                 configurationPlugin.Close(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private IGenericConfig LoadConfigDll(string dllName) | ||||
|         { | ||||
|             Assembly pluginAssembly = Assembly.LoadFrom(dllName); | ||||
|             IGenericConfig plug = null; | ||||
| 
 | ||||
|             foreach (Type pluginType in pluginAssembly.GetTypes()) | ||||
|             { | ||||
|                 if (pluginType.IsPublic) | ||||
|                 { | ||||
|                     if (!pluginType.IsAbstract) | ||||
|                     { | ||||
|                         Type typeInterface = pluginType.GetInterface("IGenericConfig", true); | ||||
| 
 | ||||
|                         if (typeInterface != null) | ||||
|                         { | ||||
|                             plug = | ||||
|                                 (IGenericConfig) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             pluginAssembly = null; | ||||
|             return plug; | ||||
|         } | ||||
| 
 | ||||
|         public void forceSetConfigurationOption(string configuration_key, string configuration_value) | ||||
|         { | ||||
|             configurationPlugin.LoadData(); | ||||
|             configurationPlugin.SetAttribute(configuration_key, configuration_value); | ||||
|             configurationPlugin.Commit(); | ||||
|             configurationPlugin.Close(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,65 @@ | |||
| /* | ||||
| * 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; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class ConfigurationOption | ||||
|     { | ||||
|         public delegate bool ConfigurationOptionShouldBeAsked(string configuration_key); | ||||
| 
 | ||||
|         public enum ConfigurationTypes | ||||
|         { | ||||
|             TYPE_STRING, | ||||
|             TYPE_STRING_NOT_EMPTY, | ||||
|             TYPE_UINT16, | ||||
|             TYPE_UINT32, | ||||
|             TYPE_UINT64, | ||||
|             TYPE_INT16, | ||||
|             TYPE_INT32, | ||||
|             TYPE_INT64, | ||||
|             TYPE_IP_ADDRESS, | ||||
|             TYPE_CHARACTER, | ||||
|             TYPE_BOOLEAN, | ||||
|             TYPE_BYTE, | ||||
|             TYPE_LLUUID, | ||||
|             TYPE_LLVECTOR3, | ||||
|             TYPE_FLOAT, | ||||
|             TYPE_DOUBLE | ||||
|         } ; | ||||
| 
 | ||||
|         public string configurationKey = String.Empty; | ||||
|         public string configurationQuestion = String.Empty; | ||||
|         public string configurationDefault = String.Empty; | ||||
| 
 | ||||
|         public ConfigurationTypes configurationType = ConfigurationTypes.TYPE_STRING; | ||||
|         public bool configurationUseDefaultNoPrompt = false; | ||||
|         public ConfigurationOptionShouldBeAsked shouldIBeAsked; //Should I be asked now? Based on previous answers | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,58 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // Information about this assembly is defined by the following | ||||
| // attributes. | ||||
| // | ||||
| // change them to the information which is associated with the assembly | ||||
| // you compile. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("ServerConsole")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly: AssemblyConfiguration("")] | ||||
| [assembly: AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("ServerConsole")] | ||||
| [assembly: AssemblyCopyright("")] | ||||
| [assembly: AssemblyTrademark("")] | ||||
| [assembly: AssemblyCulture("")] | ||||
| 
 | ||||
| // This sets the default COM visibility of types in the assembly to invisible. | ||||
| // If you need to expose a type to COM, use [ComVisible(true)] on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The assembly version has following format : | ||||
| // | ||||
| // Major.Minor.Build.Revision | ||||
| // | ||||
| // You can specify all values by your own or you can build default build and revision | ||||
| // numbers with the '*' character (the default): | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.*")] | ||||
|  | @ -0,0 +1,423 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Diagnostics; | ||||
| using System.IO; | ||||
| using System.Net; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Console | ||||
| { | ||||
|     public class ConsoleBase | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private object m_syncRoot = new object(); | ||||
| 
 | ||||
|         public conscmd_callback m_cmdParser; | ||||
|         public string m_componentName; | ||||
| 
 | ||||
|         public ConsoleBase(string componentname, conscmd_callback cmdparser) | ||||
|         { | ||||
|             m_componentName = componentname; | ||||
|             m_cmdParser = cmdparser; | ||||
| 
 | ||||
|             System.Console.WriteLine("Creating new local console"); | ||||
| 
 | ||||
|             m_log.Info("[" + m_componentName + "]: Started at " + DateTime.Now.ToString()); | ||||
|         } | ||||
| 
 | ||||
|         public void Close() | ||||
|         { | ||||
|             m_log.Info("[" + m_componentName + "]: Shutdown at " + DateTime.Now.ToString()); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// derive an ansi color from a string, ignoring the darker colors.   | ||||
|         /// This is used to help automatically bin component tags with colors | ||||
|         /// in various print functions. | ||||
|         /// </summary> | ||||
|         /// <param name="input">arbitrary string for input</param> | ||||
|         /// <returns>an ansii color</returns> | ||||
|         private ConsoleColor DeriveColor(string input) | ||||
|         { | ||||
|             int colIdx = (input.ToUpper().GetHashCode() % 6) + 9; | ||||
|             return (ConsoleColor) colIdx; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a warning to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Warn(string format, params object[] args) | ||||
|         { | ||||
|             WriteNewLine(ConsoleColor.Yellow, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a warning to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="sender">The module that sent this message</param> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Warn(string sender, string format, params object[] args) | ||||
|         { | ||||
|             WritePrefixLine(DeriveColor(sender), sender); | ||||
|             WriteNewLine(ConsoleColor.Yellow, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a notice to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Notice(string format, params object[] args) | ||||
|         { | ||||
|             WriteNewLine(ConsoleColor.White, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a notice to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="sender">The module that sent this message</param> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Notice(string sender, string format, params object[] args) | ||||
|         { | ||||
|             WritePrefixLine(DeriveColor(sender), sender); | ||||
|             WriteNewLine(ConsoleColor.White, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends an error to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Error(string format, params object[] args) | ||||
|         { | ||||
|             WriteNewLine(ConsoleColor.Red, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends an error to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="sender">The module that sent this message</param> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Error(string sender, string format, params object[] args) | ||||
|         { | ||||
|             WritePrefixLine(DeriveColor(sender), sender); | ||||
|             Error(format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a status message to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Status(string format, params object[] args) | ||||
|         { | ||||
|             WriteNewLine(ConsoleColor.Blue, format, args); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Sends a status message to the current console output | ||||
|         /// </summary> | ||||
|         /// <param name="sender">The module that sent this message</param> | ||||
|         /// <param name="format">The message to send</param> | ||||
|         /// <param name="args">WriteLine-style message arguments</param> | ||||
|         public void Status(string sender, string format, params object[] args) | ||||
|         { | ||||
|             WritePrefixLine(DeriveColor(sender), sender); | ||||
|             WriteNewLine(ConsoleColor.Blue, format, args); | ||||
|         } | ||||
| 
 | ||||
|         [Conditional("DEBUG")] | ||||
|         public void Debug(string format, params object[] args) | ||||
|         { | ||||
|             WriteNewLine(ConsoleColor.Gray, format, args); | ||||
|         } | ||||
| 
 | ||||
|         [Conditional("DEBUG")] | ||||
|         public void Debug(string sender, string format, params object[] args) | ||||
|         { | ||||
|             WritePrefixLine(DeriveColor(sender), sender); | ||||
|             WriteNewLine(ConsoleColor.Gray, format, args); | ||||
|         } | ||||
| 
 | ||||
|         private void WriteNewLine(ConsoleColor color, string format, params object[] args) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (m_syncRoot) | ||||
|                 { | ||||
|                     try | ||||
|                     { | ||||
|                         if (color != ConsoleColor.White) | ||||
|                             System.Console.ForegroundColor = color; | ||||
| 
 | ||||
|                         System.Console.WriteLine(format, args); | ||||
|                         System.Console.ResetColor(); | ||||
|                     } | ||||
|                     catch (ArgumentNullException) | ||||
|                     { | ||||
|                         // Some older systems dont support coloured text. | ||||
|                         System.Console.WriteLine(format, args); | ||||
|                     } | ||||
|                     catch (FormatException) | ||||
|                     { | ||||
|                         System.Console.WriteLine(args); | ||||
|                     } | ||||
|                 } | ||||
|             }  | ||||
|             catch (ObjectDisposedException) | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void WritePrefixLine(ConsoleColor color, string sender) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (m_syncRoot) | ||||
|                 { | ||||
|                     sender = sender.ToUpper(); | ||||
| 
 | ||||
|                     System.Console.WriteLine("[" + sender + "] "); | ||||
| 
 | ||||
|                     System.Console.Write("["); | ||||
| 
 | ||||
|                     try | ||||
|                     { | ||||
|                         System.Console.ForegroundColor = color; | ||||
|                         System.Console.Write(sender); | ||||
|                         System.Console.ResetColor(); | ||||
|                     } | ||||
|                     catch (ArgumentNullException) | ||||
|                     { | ||||
|                         // Some older systems dont support coloured text. | ||||
|                         System.Console.WriteLine(sender); | ||||
|                     } | ||||
| 
 | ||||
|                     System.Console.Write("] \t"); | ||||
|                 } | ||||
|             } | ||||
|             catch (ObjectDisposedException) | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public string ReadLine() | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return System.Console.ReadLine(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[Console]: System.Console.ReadLine exception " + e.ToString()); | ||||
|                 return String.Empty; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public int Read() | ||||
|         { | ||||
|             return System.Console.Read(); | ||||
|         } | ||||
| 
 | ||||
|         public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue) | ||||
|         { | ||||
|             IPAddress address; | ||||
|             string addressStr; | ||||
| 
 | ||||
|             while (true) | ||||
|             { | ||||
|                 addressStr = CmdPrompt(prompt, defaultvalue); | ||||
|                 if (IPAddress.TryParse(addressStr, out address)) | ||||
|                 { | ||||
|                     break; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     m_log.Error("Illegal address. Please re-enter."); | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             return address; | ||||
|         } | ||||
| 
 | ||||
|         public uint CmdPromptIPPort(string prompt, string defaultvalue) | ||||
|         { | ||||
|             uint port; | ||||
|             string portStr; | ||||
| 
 | ||||
|             while (true) | ||||
|             { | ||||
|                 portStr = CmdPrompt(prompt, defaultvalue); | ||||
|                 if (uint.TryParse(portStr, out port)) | ||||
|                 { | ||||
|                     if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort) | ||||
|                     { | ||||
|                         break; | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|                 m_log.Error("Illegal address. Please re-enter."); | ||||
|             } | ||||
| 
 | ||||
|             return port; | ||||
|         } | ||||
| 
 | ||||
|         // Displays a prompt and waits for the user to enter a string, then returns that string | ||||
|         // Done with no echo and suitable for passwords | ||||
|         public string PasswdPrompt(string prompt) | ||||
|         { | ||||
|             // FIXME: Needs to be better abstracted | ||||
|             System.Console.WriteLine(String.Format("{0}: ", prompt)); | ||||
|             ConsoleColor oldfg = System.Console.ForegroundColor; | ||||
|             System.Console.ForegroundColor = System.Console.BackgroundColor; | ||||
|             string temp = System.Console.ReadLine(); | ||||
|             System.Console.ForegroundColor = oldfg; | ||||
|             return temp; | ||||
|         } | ||||
| 
 | ||||
|         // Displays a command prompt and waits for the user to enter a string, then returns that string | ||||
|         public string CmdPrompt(string prompt) | ||||
|         { | ||||
|             System.Console.WriteLine(String.Format("{0}: ", prompt)); | ||||
|             return ReadLine(); | ||||
|         } | ||||
| 
 | ||||
|         // Displays a command prompt and returns a default value if the user simply presses enter | ||||
|         public string CmdPrompt(string prompt, string defaultresponse) | ||||
|         { | ||||
|             string temp = CmdPrompt(String.Format("{0} [{1}]", prompt, defaultresponse)); | ||||
|             if (temp == String.Empty) | ||||
|             { | ||||
|                 return defaultresponse; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return temp; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // Displays a command prompt and returns a default value, user may only enter 1 of 2 options | ||||
|         public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) | ||||
|         { | ||||
|             bool itisdone = false; | ||||
|             string temp = CmdPrompt(prompt, defaultresponse); | ||||
|             while (itisdone == false) | ||||
|             { | ||||
|                 if ((temp == OptionA) || (temp == OptionB)) | ||||
|                 { | ||||
|                     itisdone = true; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     System.Console.WriteLine("Valid options are " + OptionA + " or " + OptionB); | ||||
|                     temp = CmdPrompt(prompt, defaultresponse); | ||||
|                 } | ||||
|             } | ||||
|             return temp; | ||||
|         } | ||||
| 
 | ||||
|         // Runs a command with a number of parameters | ||||
|         public Object RunCmd(string Cmd, string[] cmdparams) | ||||
|         { | ||||
|             m_cmdParser.RunCmd(Cmd, cmdparams); | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         // Shows data about something | ||||
|         public void ShowCommands(string ShowWhat) | ||||
|         { | ||||
|             m_cmdParser.Show(ShowWhat); | ||||
|         } | ||||
| 
 | ||||
|         public void Prompt() | ||||
|         { | ||||
|             string tempstr = CmdPrompt(m_componentName + "# "); | ||||
|             RunCommand(tempstr); | ||||
|         } | ||||
| 
 | ||||
|         public void RunCommand(string command) | ||||
|         { | ||||
|             string[] tempstrarray; | ||||
|             tempstrarray = command.Split(' '); | ||||
|             string cmd = tempstrarray[0]; | ||||
|             Array.Reverse(tempstrarray); | ||||
|             Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1); | ||||
|             Array.Reverse(tempstrarray); | ||||
|             string[] cmdparams = (string[]) tempstrarray; | ||||
|             try | ||||
|             { | ||||
|                 RunCmd(cmd, cmdparams); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("[Console]: Command failed with exception " + e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public string LineInfo | ||||
|         { | ||||
|             get | ||||
|             { | ||||
|                 string result = String.Empty; | ||||
| 
 | ||||
|                 string stacktrace = Environment.StackTrace; | ||||
|                 List<string> lines = new List<string>(stacktrace.Split(new string[] {"at "}, StringSplitOptions.None)); | ||||
| 
 | ||||
|                 if (lines.Count > 4) | ||||
|                 { | ||||
|                     lines.RemoveRange(0, 4); | ||||
| 
 | ||||
|                     string tmpLine = lines[0]; | ||||
| 
 | ||||
|                     int inIndex = tmpLine.IndexOf(" in "); | ||||
| 
 | ||||
|                     if (inIndex > -1) | ||||
|                     { | ||||
|                         result = tmpLine.Substring(0, inIndex); | ||||
| 
 | ||||
|                         int lineIndex = tmpLine.IndexOf(":line "); | ||||
| 
 | ||||
|                         if (lineIndex > -1) | ||||
|                         { | ||||
|                             lineIndex += 6; | ||||
|                             result += ", line " + tmpLine.Substring(lineIndex, (tmpLine.Length - lineIndex) - 5); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|                 return result; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,35 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| namespace OpenSim.Framework.Console | ||||
| { | ||||
|     public interface conscmd_callback | ||||
|     { | ||||
|         void RunCmd(string cmd, string[] cmdparams); | ||||
|         void Show(string ShowWhat); | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,41 @@ | |||
| /* | ||||
| * 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. | ||||
| *  | ||||
| */ | ||||
| 
 | ||||
| namespace OpenSim.Framework.Console | ||||
| { | ||||
|     public class MainConsole | ||||
|     { | ||||
|         private static ConsoleBase instance; | ||||
| 
 | ||||
|         public static ConsoleBase Instance | ||||
|         { | ||||
|             get { return instance; } | ||||
|             set { instance = value; } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,115 @@ | |||
| /* | ||||
| * 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.Text; | ||||
| using System.Text.RegularExpressions; | ||||
| using System.Globalization; | ||||
| 
 | ||||
| using log4net.Core; | ||||
| using log4net.Layout; | ||||
| using log4net.Appender; | ||||
| using log4net.Util; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Console | ||||
| { | ||||
|     public class OpenSimAppender : AnsiColorTerminalAppender | ||||
|     { | ||||
|         override protected void Append(LoggingEvent le) | ||||
|         { | ||||
|             try { | ||||
|                 string loggingMessage = RenderLoggingEvent(le); | ||||
|                 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; | ||||
|                  | ||||
|                 Regex RE = new Regex(regex, RegexOptions.Multiline); | ||||
|                 MatchCollection matches = RE.Matches(loggingMessage); | ||||
|                 // Get some direct matches $1 $4 is a  | ||||
|                 if (matches.Count == 1) | ||||
|                 { | ||||
|                     System.Console.Write(matches[0].Groups["Front"].Value); | ||||
|                     System.Console.Write("["); | ||||
|                      | ||||
|                     WriteColorText(DeriveColor(matches[0].Groups["Category"].Value), matches[0].Groups["Category"].Value); | ||||
|                     System.Console.Write("]:"); | ||||
|                      | ||||
|                     if (le.Level == Level.Error)  | ||||
|                     { | ||||
|                         WriteColorText(ConsoleColor.Red, matches[0].Groups["End"].Value); | ||||
|                     } | ||||
|                     else if (le.Level == Level.Warn)  | ||||
|                     { | ||||
|                         WriteColorText(ConsoleColor.Yellow, matches[0].Groups["End"].Value); | ||||
|                     } | ||||
|                     else  | ||||
|                     { | ||||
|                         System.Console.Write(matches[0].Groups["End"].Value); | ||||
|                     } | ||||
|                     System.Console.WriteLine(); | ||||
|                 }  | ||||
|                 else | ||||
|                 { | ||||
|                     System.Console.Write(loggingMessage); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 System.Console.WriteLine("Couldn't write out log message", e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void WriteColorText(ConsoleColor color, string sender) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (this) | ||||
|                 { | ||||
|                     try | ||||
|                     { | ||||
|                         System.Console.ForegroundColor = color; | ||||
|                         System.Console.Write(sender); | ||||
|                         System.Console.ResetColor(); | ||||
|                     } | ||||
|                     catch (ArgumentNullException) | ||||
|                     { | ||||
|                         // Some older systems dont support coloured text. | ||||
|                         System.Console.WriteLine(sender); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             catch (ObjectDisposedException) | ||||
|             { | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private ConsoleColor DeriveColor(string input) | ||||
|         { | ||||
|             int colIdx = (input.ToUpper().GetHashCode() % 6) + 9; | ||||
|             return (ConsoleColor) colIdx; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,39 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Text; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class Constants | ||||
|     { | ||||
|         public const uint RegionSize = 256; | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,54 @@ | |||
| /* | ||||
| * 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.Globalization; | ||||
| using System.Threading; | ||||
| 
 | ||||
| namespace OpenSim.Framework | ||||
| { | ||||
|     public class Culture | ||||
|     { | ||||
|         private static readonly CultureInfo m_cultureInfo = new CultureInfo("en-US", true); | ||||
| 
 | ||||
|         public static NumberFormatInfo NumberFormatInfo | ||||
|         { | ||||
|             get { return m_cultureInfo.NumberFormat; } | ||||
|         } | ||||
| 
 | ||||
|         public static IFormatProvider FormatProvider | ||||
|         { | ||||
|             get { return m_cultureInfo; } | ||||
|         } | ||||
| 
 | ||||
|         public static void SetCurrentCulture() | ||||
|         { | ||||
|             Thread.CurrentThread.CurrentCulture = m_cultureInfo; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,177 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.DB4o | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A grid server storage mechanism employing the DB4o database system | ||||
|     /// </summary> | ||||
|     internal class DB4oGridData : IGridData | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// The database manager object | ||||
|         /// </summary> | ||||
|         private DB4oGridManager manager; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Called when the plugin is first loaded (as constructors are not called) | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             manager = new DB4oGridManager("gridserver.yap"); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a list of regions within the specified ranges | ||||
|         /// </summary> | ||||
|         /// <param name="a">minimum X coordinate</param> | ||||
|         /// <param name="b">minimum Y coordinate</param> | ||||
|         /// <param name="c">maximum X coordinate</param> | ||||
|         /// <param name="d">maximum Y coordinate</param> | ||||
|         /// <returns>An array of region profiles</returns> | ||||
|         public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | ||||
|         { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a region located at the specified regionHandle (warning multiple regions may occupy the one spot, first found is returned) | ||||
|         /// </summary> | ||||
|         /// <param name="handle">The handle to search for</param> | ||||
|         /// <returns>A region profile</returns> | ||||
|         public RegionProfileData GetProfileByHandle(ulong handle) | ||||
|         { | ||||
|             lock (manager.simProfiles) | ||||
|             { | ||||
|                 foreach (LLUUID UUID in manager.simProfiles.Keys) | ||||
|                 { | ||||
|                     if (manager.simProfiles[UUID].regionHandle == handle) | ||||
|                     { | ||||
|                         return manager.simProfiles[UUID]; | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             throw new Exception("Unable to find profile with handle (" + handle.ToString() + ")"); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a specific region | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The region ID code</param> | ||||
|         /// <returns>A region profile</returns> | ||||
|         public RegionProfileData GetProfileByLLUUID(LLUUID uuid) | ||||
|         { | ||||
|             lock (manager.simProfiles) | ||||
|             { | ||||
|                 if (manager.simProfiles.ContainsKey(uuid)) | ||||
|                     return manager.simProfiles[uuid]; | ||||
|             } | ||||
|             throw new Exception("Unable to find profile with UUID (" + uuid.ToString() + | ||||
|                                 "). Total Registered Regions: " + manager.simProfiles.Count); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a new specified region to the database | ||||
|         /// </summary> | ||||
|         /// <param name="profile">The profile to add</param> | ||||
|         /// <returns>A dataresponse enum indicating success</returns> | ||||
|         public DataResponse AddProfile(RegionProfileData profile) | ||||
|         { | ||||
|             lock (manager.simProfiles) | ||||
|             { | ||||
|                 if (manager.AddRow(profile)) | ||||
|                 { | ||||
|                     return DataResponse.RESPONSE_OK; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return DataResponse.RESPONSE_ERROR; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Authenticates a new region using the shared secrets. NOT SECURE. | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The UUID the region is authenticating with</param> | ||||
|         /// <param name="handle">The location the region is logging into (unused in Db4o)</param> | ||||
|         /// <param name="key">The shared secret</param> | ||||
|         /// <returns>Authenticated?</returns> | ||||
|         public bool AuthenticateSim(LLUUID uuid, ulong handle, string key) | ||||
|         { | ||||
|             if (manager.simProfiles[uuid].regionRecvKey == key) | ||||
|                 return true; | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Shuts down the database | ||||
|         /// </summary> | ||||
|         public void Close() | ||||
|         { | ||||
|             manager = null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// // Returns a list of avatar and UUIDs that match the query | ||||
|         /// </summary> | ||||
|         public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||||
|         { | ||||
|             //Do nothing yet | ||||
|             List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>(); | ||||
|             return returnlist; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the providers name | ||||
|         /// </summary> | ||||
|         /// <returns>The name of the storage system</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "DB4o Grid Provider"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the providers version | ||||
|         /// </summary> | ||||
|         /// <returns>The version of the storage system</returns> | ||||
|         public string getVersion() | ||||
|         { | ||||
|             return "0.1"; | ||||
|         } | ||||
| 
 | ||||
|         public ReservationData GetReservationAtPoint(uint x, uint y) | ||||
|         { | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,170 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using Db4objects.Db4o; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.DB4o | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A Database manager for Db4o | ||||
|     /// </summary> | ||||
|     internal class DB4oGridManager | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// A list of the current regions connected (in-memory cache) | ||||
|         /// </summary> | ||||
|         public Dictionary<LLUUID, RegionProfileData> simProfiles = new Dictionary<LLUUID, RegionProfileData>(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database File Name | ||||
|         /// </summary> | ||||
|         private string dbfl; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new grid storage manager | ||||
|         /// </summary> | ||||
|         /// <param name="db4odb">Filename to the database file</param> | ||||
|         public DB4oGridManager(string db4odb) | ||||
|         { | ||||
|             dbfl = db4odb; | ||||
|             IObjectContainer database; | ||||
|             database = Db4oFactory.OpenFile(dbfl); | ||||
|             IObjectSet result = database.Get(typeof (RegionProfileData)); | ||||
|             // Loads the file into the in-memory cache | ||||
|             foreach (RegionProfileData row in result) | ||||
|             { | ||||
|                 simProfiles.Add(row.UUID, row); | ||||
|             } | ||||
|             database.Close(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a new profile to the database (Warning: Probably slow.) | ||||
|         /// </summary> | ||||
|         /// <param name="row">The profile to add</param> | ||||
|         /// <returns>Successful?</returns> | ||||
|         public bool AddRow(RegionProfileData row) | ||||
|         { | ||||
|             if (simProfiles.ContainsKey(row.UUID)) | ||||
|             { | ||||
|                 simProfiles[row.UUID] = row; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 simProfiles.Add(row.UUID, row); | ||||
|             } | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IObjectContainer database; | ||||
|                 database = Db4oFactory.OpenFile(dbfl); | ||||
|                 database.Set(row); | ||||
|                 database.Close(); | ||||
|                 return true; | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// A manager for the DB4o database (user profiles) | ||||
|     /// </summary> | ||||
|     internal class DB4oUserManager | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// A list of the user profiles (in memory cache) | ||||
|         /// </summary> | ||||
|         public Dictionary<LLUUID, UserProfileData> userProfiles = new Dictionary<LLUUID, UserProfileData>(); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database filename | ||||
|         /// </summary> | ||||
|         private string dbfl; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Initialises a new DB manager | ||||
|         /// </summary> | ||||
|         /// <param name="db4odb">The filename to the database</param> | ||||
|         public DB4oUserManager(string db4odb) | ||||
|         { | ||||
|             dbfl = db4odb; | ||||
|             IObjectContainer database; | ||||
|             database = Db4oFactory.OpenFile(dbfl); | ||||
|             // Load to cache | ||||
|             IObjectSet result = database.Get(typeof (UserProfileData)); | ||||
|             foreach (UserProfileData row in result) | ||||
|             { | ||||
|                 if (userProfiles.ContainsKey(row.UUID)) | ||||
|                     userProfiles[row.UUID] = row; | ||||
|                 else | ||||
|                     userProfiles.Add(row.UUID, row); | ||||
|             } | ||||
|             database.Close(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds or updates a record to the user database.  Do this when changes are needed | ||||
|         /// in the user profile that need to be persistant. | ||||
|         ///  | ||||
|         /// TODO: the logic here is not ACID, the local cache will be | ||||
|         /// updated even if the persistant data is not.  This may lead | ||||
|         /// to unexpected results. | ||||
|         /// </summary> | ||||
|         /// <param name="record">The profile to update</param> | ||||
|         /// <returns>true on success, false on fail to persist to db</returns> | ||||
|         public bool UpdateRecord(UserProfileData record) | ||||
|         { | ||||
|             if (userProfiles.ContainsKey(record.UUID)) | ||||
|             { | ||||
|                 userProfiles[record.UUID] = record; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 userProfiles.Add(record.UUID, record); | ||||
|             } | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IObjectContainer database; | ||||
|                 database = Db4oFactory.OpenFile(dbfl); | ||||
|                 database.Set(record); | ||||
|                 database.Close(); | ||||
|                 return true; | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,270 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.IO; | ||||
| using libsecondlife; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.DB4o | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A User storage interface for the DB4o database system | ||||
|     /// </summary> | ||||
|     public class DB4oUserData : IUserData | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The database manager | ||||
|         /// </summary> | ||||
|         private DB4oUserManager manager; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Artificial constructor called upon plugin load | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             manager = new DB4oUserManager(Path.Combine(Util.dataDir(), "userprofiles.yap")); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads a specified user profile from a UUID | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The users UUID</param> | ||||
|         /// <returns>A user profile</returns> | ||||
|         public UserProfileData GetUserByUUID(LLUUID uuid) | ||||
|         { | ||||
|             if (manager.userProfiles.ContainsKey(uuid)) | ||||
|                 return manager.userProfiles[uuid]; | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a user by searching for its name | ||||
|         /// </summary> | ||||
|         /// <param name="name">The users account name</param> | ||||
|         /// <returns>A matching users profile</returns> | ||||
|         public UserProfileData GetUserByName(string name) | ||||
|         { | ||||
|             return GetUserByName(name.Split(' ')[0], name.Split(' ')[1]); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a user by searching for its name | ||||
|         /// </summary> | ||||
|         /// <param name="fname">The first part of the users account name</param> | ||||
|         /// <param name="lname">The second part of the users account name</param> | ||||
|         /// <returns>A matching users profile</returns> | ||||
|         public UserProfileData GetUserByName(string fname, string lname) | ||||
|         { | ||||
|             foreach (UserProfileData profile in manager.userProfiles.Values) | ||||
|             { | ||||
|                 if (profile.username == fname && profile.surname == lname) | ||||
|                     return profile; | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a user by UUID direct | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The users account ID</param> | ||||
|         /// <returns>A matching users profile</returns> | ||||
|         public UserAgentData GetAgentByUUID(LLUUID uuid) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return GetUserByUUID(uuid).currentAgent; | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a session by account name | ||||
|         /// </summary> | ||||
|         /// <param name="name">The account name</param> | ||||
|         /// <returns>The users session agent</returns> | ||||
|         public UserAgentData GetAgentByName(string name) | ||||
|         { | ||||
|             return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a session by account name | ||||
|         /// </summary> | ||||
|         /// <param name="fname">The first part of the users account name</param> | ||||
|         /// <param name="lname">The second part of the users account name</param> | ||||
|         /// <returns>A user agent</returns> | ||||
|         public UserAgentData GetAgentByName(string fname, string lname) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return GetUserByName(fname, lname).currentAgent; | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
|         public void StoreWebLoginKey(LLUUID AgentID, LLUUID WebLoginKey) | ||||
|         { | ||||
|             UserProfileData user = GetUserByUUID(AgentID); | ||||
|             user.webLoginKey = WebLoginKey; | ||||
|             UpdateUserProfile(user); | ||||
| 
 | ||||
|         } | ||||
|         #region User Friends List Data | ||||
| 
 | ||||
|         public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             //m_log.Info("[FRIEND]: Stub AddNewUserFriend called"); | ||||
|         } | ||||
| 
 | ||||
|         public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | ||||
|         { | ||||
|             //m_log.Info("[FRIEND]: Stub RemoveUserFriend called"); | ||||
|         } | ||||
|         public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             //m_log.Info("[FRIEND]: Stub UpdateUserFriendPerms called"); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) | ||||
|         { | ||||
|             //m_log.Info("[FRIEND]: Stub GetUserFriendList called"); | ||||
|             return new List<FriendListItem>(); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid) | ||||
|         { | ||||
|             //m_log.Info("[USER]: Stub UpdateUserCUrrentRegion called"); | ||||
|         } | ||||
| 
 | ||||
|          | ||||
| 
 | ||||
|         public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||||
|         { | ||||
|             //Do nothing yet | ||||
|             List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); | ||||
|             return returnlist; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new user profile | ||||
|         /// </summary> | ||||
|         /// <param name="user">The profile to add to the database</param> | ||||
|         public void AddNewUserProfile(UserProfileData user) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 manager.UpdateRecord(user); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 Console.WriteLine(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new user profile | ||||
|         /// </summary> | ||||
|         /// <param name="user">The profile to add to the database</param> | ||||
|         /// <returns>True on success, false on error</returns> | ||||
|         public bool UpdateUserProfile(UserProfileData user) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 return manager.UpdateRecord(user); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 Console.WriteLine(e.ToString()); | ||||
|                 return false; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new user agent | ||||
|         /// </summary> | ||||
|         /// <param name="agent">The agent to add to the database</param> | ||||
|         public void AddNewUserAgent(UserAgentData agent) | ||||
|         { | ||||
|             // Do nothing. yet. | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Transfers money between two user accounts | ||||
|         /// </summary> | ||||
|         /// <param name="from">Starting account</param> | ||||
|         /// <param name="to">End account</param> | ||||
|         /// <param name="amount">The amount to move</param> | ||||
|         /// <returns>Success?</returns> | ||||
|         public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Transfers inventory between two accounts | ||||
|         /// </summary> | ||||
|         /// <remarks>Move to inventory server</remarks> | ||||
|         /// <param name="from">Senders account</param> | ||||
|         /// <param name="to">Receivers account</param> | ||||
|         /// <param name="item">Inventory item</param> | ||||
|         /// <returns>Success?</returns> | ||||
|         public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||||
|         { | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the name of the storage provider | ||||
|         /// </summary> | ||||
|         /// <returns>Storage provider name</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "DB4o Userdata"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the version of the storage provider | ||||
|         /// </summary> | ||||
|         /// <returns>Storage provider version</returns> | ||||
|         public string GetVersion() | ||||
|         { | ||||
|             return "0.1"; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,66 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following  | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("OpenSim.Framework.Data.DB4o")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly : AssemblyConfiguration("")] | ||||
| [assembly : AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("OpenSim.Framework.Data.DB4o")] | ||||
| [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")] | ||||
| [assembly : AssemblyTrademark("")] | ||||
| [assembly : AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible  | ||||
| // to COM components.  If you need to access a type in this assembly from  | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| 
 | ||||
| [assembly : Guid("57991e15-79da-41b7-aa06-2e6b49165a63")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version  | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| // You can specify all the values or you can default the Revision and Build Numbers  | ||||
| // by using the '*' as shown below: | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.0.0")] | ||||
| [assembly : AssemblyFileVersion("1.0.0.0")] | ||||
|  | @ -0,0 +1,222 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using System.Data.SqlClient; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     internal class MSSQLAssetData : IAssetProvider | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private MSSQLManager database; | ||||
| 
 | ||||
|         #region IAssetProvider Members | ||||
| 
 | ||||
|         private void UpgradeAssetsTable(string tableName) | ||||
|         { | ||||
|             // null as the version, indicates that the table didn't exist | ||||
|             if (tableName == null) | ||||
|             { | ||||
|                 m_log.Info("[ASSETS]: Creating new database tables"); | ||||
|                 database.ExecuteResourceSql("CreateAssetsTable.sql"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Ensure that the assets related tables exists and are at the latest version | ||||
|         /// </summary> | ||||
|         private void TestTables() | ||||
|         { | ||||
|             Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||||
| 
 | ||||
|             tableList["assets"] = null; | ||||
|             database.GetTableVersion(tableList); | ||||
| 
 | ||||
|             UpgradeAssetsTable(tableList["assets"]); | ||||
|         } | ||||
| 
 | ||||
|         public AssetBase FetchAsset(LLUUID assetID) | ||||
|         { | ||||
|             AssetBase asset = null; | ||||
| 
 | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["id"] = assetID.ToString(); | ||||
| 
 | ||||
|             IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param); | ||||
|             IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|             asset = database.getAssetRow(reader); | ||||
|             reader.Close(); | ||||
|             result.Dispose(); | ||||
| 
 | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
|         public void CreateAsset(AssetBase asset) | ||||
|         { | ||||
|             if (ExistsAsset((LLUUID) asset.FullID)) | ||||
|             { | ||||
|                 return; | ||||
|             } | ||||
| 
 | ||||
| 
 | ||||
|             SqlCommand cmd = | ||||
|                 new SqlCommand( | ||||
|                     "INSERT INTO assets ([id], [name], [description], [assetType], [invType], [local], [temporary], [data])" + | ||||
|                     " VALUES " + | ||||
|                     "(@id, @name, @description, @assetType, @invType, @local, @temporary, @data)", | ||||
|                     database.getConnection()); | ||||
| 
 | ||||
|             using (cmd) | ||||
|             { | ||||
|                 //SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar); | ||||
|                 //p.Value = asset.FullID.ToString(); | ||||
|                 cmd.Parameters.AddWithValue("id", asset.FullID.ToString()); | ||||
|                 cmd.Parameters.AddWithValue("name", asset.Name); | ||||
|                 cmd.Parameters.AddWithValue("description", asset.Description); | ||||
|                 SqlParameter e = cmd.Parameters.Add("assetType", SqlDbType.TinyInt); | ||||
|                 e.Value = asset.Type; | ||||
|                 SqlParameter f = cmd.Parameters.Add("invType", SqlDbType.TinyInt); | ||||
|                 f.Value = asset.InvType; | ||||
|                 SqlParameter g = cmd.Parameters.Add("local", SqlDbType.TinyInt); | ||||
|                 g.Value = asset.Local; | ||||
|                 SqlParameter h = cmd.Parameters.Add("temporary", SqlDbType.TinyInt); | ||||
|                 h.Value = asset.Temporary; | ||||
|                 SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image); | ||||
|                 i.Value = asset.Data; | ||||
|                 try | ||||
|                 { | ||||
|                     cmd.ExecuteNonQuery(); | ||||
|                 } | ||||
|                 catch (Exception) | ||||
|                 { | ||||
|                     throw; | ||||
|                 } | ||||
| 
 | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public void UpdateAsset(AssetBase asset) | ||||
|         { | ||||
|             SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " + | ||||
|                                                 "name = @name, " + | ||||
|                                                 "description = @description," + | ||||
|                                                 "assetType = @assetType," + | ||||
|                                                 "invType = @invType," + | ||||
|                                                 "local = @local," + | ||||
|                                                 "temporary = @temporary," + | ||||
|                                                 "data = @data where " + | ||||
|                                                 "id = @keyId;", database.getConnection()); | ||||
|             SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString()); | ||||
|             SqlParameter param2 = new SqlParameter("@name", asset.Name); | ||||
|             SqlParameter param3 = new SqlParameter("@description", asset.Description); | ||||
|             SqlParameter param4 = new SqlParameter("@assetType", asset.Type); | ||||
|             SqlParameter param5 = new SqlParameter("@invType", asset.InvType); | ||||
|             SqlParameter param6 = new SqlParameter("@local", asset.Local); | ||||
|             SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary); | ||||
|             SqlParameter param8 = new SqlParameter("@data", asset.Data); | ||||
|             SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToString()); | ||||
|             command.Parameters.Add(param1); | ||||
|             command.Parameters.Add(param2); | ||||
|             command.Parameters.Add(param3); | ||||
|             command.Parameters.Add(param4); | ||||
|             command.Parameters.Add(param5); | ||||
|             command.Parameters.Add(param6); | ||||
|             command.Parameters.Add(param7); | ||||
|             command.Parameters.Add(param8); | ||||
|             command.Parameters.Add(param9); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 command.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public bool ExistsAsset(LLUUID uuid) | ||||
|         { | ||||
|             if (FetchAsset(uuid) != null) | ||||
|             { | ||||
|                 return true; | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// All writes are immediately commited to the database, so this is a no-op | ||||
|         /// </summary> | ||||
|         public void CommitAssets() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region IPlugin Members | ||||
| 
 | ||||
|         public void Initialise() | ||||
|         { | ||||
|             IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); | ||||
|             string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); | ||||
|             string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); | ||||
|             string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); | ||||
|             string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); | ||||
|             string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||||
| 
 | ||||
|             database = | ||||
|                 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||||
|                                  settingPassword); | ||||
| 
 | ||||
|             TestTables(); | ||||
|         } | ||||
| 
 | ||||
|         public string Version | ||||
|         { | ||||
| //            get { return database.getVersion(); }  | ||||
|             get { return database.getVersion(); } | ||||
|         } | ||||
| 
 | ||||
|         public string Name | ||||
|         { | ||||
|             get { return "MSSQL Asset storage engine"; } | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,327 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using System.Security.Cryptography; | ||||
| using System.Text; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A grid data interface for Microsoft SQL Server | ||||
|     /// </summary> | ||||
|     public class MSSQLGridData : IGridData | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database manager | ||||
|         /// </summary> | ||||
|         private MSSQLManager database; | ||||
| 
 | ||||
|         private string m_regionsTableName; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Initialises the Grid Interface | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             IniFile iniFile = new IniFile("mssql_connection.ini"); | ||||
| 
 | ||||
|             string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||||
|             string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||||
|             string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||||
|             string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||||
|             string settingPassword = iniFile.ParseFileReadValue("password"); | ||||
| 
 | ||||
|             m_regionsTableName = iniFile.ParseFileReadValue("regionstablename"); | ||||
|             if (m_regionsTableName == null) | ||||
|             { | ||||
|                 m_regionsTableName = "regions"; | ||||
|             } | ||||
| 
 | ||||
|             database = | ||||
|                 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||||
|                                  settingPassword); | ||||
| 
 | ||||
|             TestTables(); | ||||
|         } | ||||
| 
 | ||||
|         private void TestTables() | ||||
|         { | ||||
|             IDbCommand cmd = database.Query("SELECT TOP 1 * FROM "+m_regionsTableName, new Dictionary<string, string>()); | ||||
|   | ||||
|             try | ||||
|             { | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 m_log.Info("[DATASTORE]: MSSQL Database doesn't exist... creating"); | ||||
|                 database.ExecuteResourceSql("Mssql-regions.sql");             | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Shuts down the grid interface | ||||
|         /// </summary> | ||||
|         public void Close() | ||||
|         { | ||||
|             database.Close(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the storage system name | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the storage system name</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "Sql OpenGridData"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the storage system version | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the storage system version</returns> | ||||
|         public string getVersion() | ||||
|         { | ||||
|             return "0.1"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a list of regions within the specified ranges | ||||
|         /// </summary> | ||||
|         /// <param name="a">minimum X coordinate</param> | ||||
|         /// <param name="b">minimum Y coordinate</param> | ||||
|         /// <param name="c">maximum X coordinate</param> | ||||
|         /// <param name="d">maximum Y coordinate</param> | ||||
|         /// <returns>An array of region profiles</returns> | ||||
|         public RegionProfileData[] GetProfilesInRange(uint a, uint b, uint c, uint d) | ||||
|         { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a sim profile from it's location | ||||
|         /// </summary> | ||||
|         /// <param name="handle">Region location handle</param> | ||||
|         /// <returns>Sim profile</returns> | ||||
|         public RegionProfileData GetProfileByHandle(ulong handle) | ||||
|         { | ||||
|             IDataReader reader = null; | ||||
|             try | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["handle"] = handle.ToString(); | ||||
|                 IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle", param); | ||||
|                 reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                 RegionProfileData row = database.getRegionRow(reader); | ||||
|                 reader.Close(); | ||||
|                 result.Dispose(); | ||||
| 
 | ||||
|                 return row; | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 if (reader != null) | ||||
|                 { | ||||
|                     reader.Close(); | ||||
|                 } | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         | ||||
|         /// <summary> | ||||
|         /// Returns a sim profile from it's UUID | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The region UUID</param> | ||||
|         /// <returns>The sim profile</returns> | ||||
|         public RegionProfileData GetProfileByLLUUID(LLUUID uuid) | ||||
|         { | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["uuid"] = uuid.ToString(); | ||||
|             IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid", param); | ||||
|             IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|             RegionProfileData row = database.getRegionRow(reader); | ||||
|             reader.Close(); | ||||
|             result.Dispose(); | ||||
| 
 | ||||
|             return row; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a new specified region to the database | ||||
|         /// </summary> | ||||
|         /// <param name="profile">The profile to add</param> | ||||
|         /// <returns>A dataresponse enum indicating success</returns> | ||||
|         public DataResponse AddProfile(RegionProfileData profile) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (GetProfileByLLUUID(profile.UUID) != null) | ||||
|                 { | ||||
|                     return DataResponse.RESPONSE_OK; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception) | ||||
|             { | ||||
|                 System.Console.WriteLine("No regions found. Create new one."); | ||||
|             } | ||||
| 
 | ||||
|             if ( insertRegionRow(profile)) | ||||
|             { | ||||
|                 return DataResponse.RESPONSE_OK; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return DataResponse.RESPONSE_ERROR; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new region in the database | ||||
|         /// </summary> | ||||
|         /// <param name="profile">The region profile to insert</param> | ||||
|         /// <returns>Successful?</returns> | ||||
|         public bool insertRegionRow(RegionProfileData profile) | ||||
|         { | ||||
|             //Insert new region | ||||
|             string sql = | ||||
|                 "INSERT INTO " + m_regionsTableName + " ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], "; | ||||
|             sql += | ||||
|                 "[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], "; | ||||
|             sql += | ||||
|                 "[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort]) VALUES "; | ||||
| 
 | ||||
|             sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, "; | ||||
|             sql += | ||||
|                 "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, "; | ||||
|             sql += | ||||
|                 "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort);"; | ||||
| 
 | ||||
|             Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||||
| 
 | ||||
|             parameters["regionHandle"] = profile.regionHandle.ToString(); | ||||
|             parameters["regionName"] = profile.regionName; | ||||
|             parameters["uuid"] = profile.UUID.ToString(); | ||||
|             parameters["regionRecvKey"] = profile.regionRecvKey; | ||||
|             parameters["regionSecret"] = profile.regionSecret; | ||||
|             parameters["regionSendKey"] = profile.regionSendKey; | ||||
|             parameters["regionDataURI"] = profile.regionDataURI; | ||||
|             parameters["serverIP"] = profile.serverIP; | ||||
|             parameters["serverPort"] = profile.serverPort.ToString(); | ||||
|             parameters["serverURI"] = profile.serverURI; | ||||
|             parameters["locX"] = profile.regionLocX.ToString(); | ||||
|             parameters["locY"] = profile.regionLocY.ToString(); | ||||
|             parameters["locZ"] = profile.regionLocZ.ToString(); | ||||
|             parameters["eastOverrideHandle"] = profile.regionEastOverrideHandle.ToString(); | ||||
|             parameters["westOverrideHandle"] = profile.regionWestOverrideHandle.ToString(); | ||||
|             parameters["northOverrideHandle"] = profile.regionNorthOverrideHandle.ToString(); | ||||
|             parameters["southOverrideHandle"] = profile.regionSouthOverrideHandle.ToString(); | ||||
|             parameters["regionAssetURI"] = profile.regionAssetURI; | ||||
|             parameters["regionAssetRecvKey"] = profile.regionAssetRecvKey; | ||||
|             parameters["regionAssetSendKey"] = profile.regionAssetSendKey; | ||||
|             parameters["regionUserURI"] = profile.regionUserURI; | ||||
|             parameters["regionUserRecvKey"] = profile.regionUserRecvKey; | ||||
|             parameters["regionUserSendKey"] = profile.regionUserSendKey; | ||||
|             parameters["regionMapTexture"] = profile.regionMapTextureID.ToString(); | ||||
|             parameters["serverHttpPort"] = profile.httpPort.ToString(); | ||||
|             parameters["serverRemotingPort"] = profile.remotingPort.ToString(); | ||||
| 
 | ||||
| 
 | ||||
|             bool returnval = false; | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IDbCommand result = database.Query(sql, parameters); | ||||
| 
 | ||||
|                 if (result.ExecuteNonQuery() == 1) | ||||
|                     returnval = true; | ||||
| 
 | ||||
|                 result.Dispose(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error("MSSQLManager : " + e.ToString()); | ||||
|             } | ||||
| 
 | ||||
|             return returnval; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// DEPRECIATED. Attempts to authenticate a region by comparing a shared secret. | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The UUID of the challenger</param> | ||||
|         /// <param name="handle">The attempted regionHandle of the challenger</param> | ||||
|         /// <param name="authkey">The secret</param> | ||||
|         /// <returns>Whether the secret and regionhandle match the database entry for UUID</returns> | ||||
|         public bool AuthenticateSim(LLUUID uuid, ulong handle, string authkey) | ||||
|         { | ||||
|             bool throwHissyFit = false; // Should be true by 1.0 | ||||
| 
 | ||||
|             if (throwHissyFit) | ||||
|                 throw new Exception("CRYPTOWEAK AUTHENTICATE: Refusing to authenticate due to replay potential."); | ||||
| 
 | ||||
|             RegionProfileData data = GetProfileByLLUUID(uuid); | ||||
| 
 | ||||
|             return (handle == data.regionHandle && authkey == data.regionSecret); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// NOT YET FUNCTIONAL. Provides a cryptographic authentication of a region | ||||
|         /// </summary> | ||||
|         /// <remarks>This requires a security audit.</remarks> | ||||
|         /// <param name="uuid"></param> | ||||
|         /// <param name="handle"></param> | ||||
|         /// <param name="authhash"></param> | ||||
|         /// <param name="challenge"></param> | ||||
|         /// <returns></returns> | ||||
|         public bool AuthenticateSim(LLUUID uuid, ulong handle, string authhash, string challenge) | ||||
|         { | ||||
|             SHA512Managed HashProvider = new SHA512Managed(); | ||||
|             ASCIIEncoding TextProvider = new ASCIIEncoding(); | ||||
| 
 | ||||
|             byte[] stream = TextProvider.GetBytes(uuid.ToString() + ":" + handle.ToString() + ":" + challenge); | ||||
|             byte[] hash = HashProvider.ComputeHash(stream); | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         public ReservationData GetReservationAtPoint(uint x, uint y) | ||||
|         { | ||||
|             return null; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,728 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using System.Data.SqlClient; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A MySQL interface for the inventory server | ||||
|     /// </summary> | ||||
|     public class MSSQLInventoryData : IInventoryData | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The database manager | ||||
|         /// </summary> | ||||
|         private MSSQLManager database; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads and initialises this database plugin | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); | ||||
|             string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); | ||||
|             string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); | ||||
|             string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); | ||||
|             string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); | ||||
|             string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||||
| 
 | ||||
|             database = | ||||
|                 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||||
|                                  settingPassword); | ||||
|             TestTables(); | ||||
|         } | ||||
| 
 | ||||
|         #region Test and initialization code | ||||
| 
 | ||||
|         private void UpgradeFoldersTable(string tableName) | ||||
|         { | ||||
|             // null as the version, indicates that the table didn't exist | ||||
|             if (tableName == null) | ||||
|             { | ||||
|                 database.ExecuteResourceSql("CreateFoldersTable.sql"); | ||||
|                 //database.ExecuteResourceSql("UpgradeFoldersTableToVersion2.sql");    | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void UpgradeItemsTable(string tableName) | ||||
|         { | ||||
|             // null as the version, indicates that the table didn't exist | ||||
|             if (tableName == null) | ||||
|             { | ||||
|                 database.ExecuteResourceSql("CreateItemsTable.sql"); | ||||
|                 //database.ExecuteResourceSql("UpgradeItemsTableToVersion2.sql"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private void TestTables() | ||||
|         { | ||||
|             Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||||
| 
 | ||||
|             tableList["inventoryfolders"] = null; | ||||
|             tableList["inventoryitems"] = null; | ||||
| 
 | ||||
|             database.GetTableVersion(tableList); | ||||
| 
 | ||||
|             UpgradeFoldersTable(tableList["inventoryfolders"]); | ||||
|             UpgradeItemsTable(tableList["inventoryitems"]); | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The name of this DB provider | ||||
|         /// </summary> | ||||
|         /// <returns>Name of DB provider</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "MSSQL Inventory Data Interface"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Closes this DB provider | ||||
|         /// </summary> | ||||
|         public void Close() | ||||
|         { | ||||
|             // Do nothing. | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the version of this DB provider | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the DB provider</returns> | ||||
|         public string getVersion() | ||||
|         { | ||||
|             return database.getVersion(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a list of items in a specified folder | ||||
|         /// </summary> | ||||
|         /// <param name="folderID">The folder to search</param> | ||||
|         /// <returns>A list containing inventory items</returns> | ||||
|         public List<InventoryItemBase> getInventoryInFolder(LLUUID folderID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     List<InventoryItemBase> items = new List<InventoryItemBase>(); | ||||
| 
 | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["parentFolderID"] = folderID.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     while (reader.Read()) | ||||
|                         items.Add(readInventoryItem(reader)); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return items; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a list of the root folders within a users inventory | ||||
|         /// </summary> | ||||
|         /// <param name="user">The user whos inventory is to be searched</param> | ||||
|         /// <returns>A list of folder objects</returns> | ||||
|         public List<InventoryFolderBase> getUserRootFolders(LLUUID user) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["uuid"] = user.ToString(); | ||||
|                     param["zero"] = LLUUID.Zero.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query( | ||||
|                             "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||||
|                     while (reader.Read()) | ||||
|                         items.Add(readInventoryFolder(reader)); | ||||
| 
 | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return items; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         // see InventoryItemBase.getUserRootFolder | ||||
|         public InventoryFolderBase getUserRootFolder(LLUUID user) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["uuid"] = user.ToString(); | ||||
|                     param["zero"] = LLUUID.Zero.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query( | ||||
|                             "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||||
|                     while (reader.Read()) | ||||
|                         items.Add(readInventoryFolder(reader)); | ||||
| 
 | ||||
|                     InventoryFolderBase rootFolder = null; | ||||
| 
 | ||||
|                     // There should only ever be one root folder for a user.  However, if there's more | ||||
|                     // than one we'll simply use the first one rather than failing.  It would be even | ||||
|                     // nicer to print some message to this effect, but this feels like it's too low a  | ||||
|                     // to put such a message out, and it's too minor right now to spare the time to | ||||
|                     // suitably refactor.                     | ||||
|                     if (items.Count > 0) | ||||
|                     { | ||||
|                         rootFolder = items[0]; | ||||
|                     } | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return rootFolder; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a list of folders in a users inventory contained within the specified folder | ||||
|         /// </summary> | ||||
|         /// <param name="parentID">The folder to search</param> | ||||
|         /// <returns>A list of inventory folders</returns> | ||||
|         public List<InventoryFolderBase> getInventoryFolders(LLUUID parentID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["parentFolderID"] = parentID.ToString(); | ||||
| 
 | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||||
| 
 | ||||
|                     while (reader.Read()) | ||||
|                         items.Add(readInventoryFolder(reader)); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return items; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Reads a one item from an SQL result | ||||
|         /// </summary> | ||||
|         /// <param name="reader">The SQL Result</param> | ||||
|         /// <returns>the item read</returns> | ||||
|         private InventoryItemBase readInventoryItem(IDataReader reader) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 InventoryItemBase item = new InventoryItemBase(); | ||||
| 
 | ||||
|                 item.inventoryID = new LLUUID((string) reader["inventoryID"]); | ||||
|                 item.assetID = new LLUUID((string) reader["assetID"]); | ||||
|                 item.assetType = (int) reader["assetType"]; | ||||
|                 item.parentFolderID = new LLUUID((string) reader["parentFolderID"]); | ||||
|                 item.avatarID = new LLUUID((string) reader["avatarID"]); | ||||
|                 item.inventoryName = (string) reader["inventoryName"]; | ||||
|                 item.inventoryDescription = (string) reader["inventoryDescription"]; | ||||
|                 item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); | ||||
|                 item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); | ||||
|                 item.invType = (int) reader["invType"]; | ||||
|                 item.creatorsID = new LLUUID((string) reader["creatorID"]); | ||||
|                 item.inventoryBasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); | ||||
|                 item.inventoryEveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); | ||||
|                 return item; | ||||
|             } | ||||
|             catch (SqlException e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a specified inventory item | ||||
|         /// </summary> | ||||
|         /// <param name="item">The item to return</param> | ||||
|         /// <returns>An inventory item</returns> | ||||
|         public InventoryItemBase getInventoryItem(LLUUID itemID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["inventoryID"] = itemID.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     InventoryItemBase item = null; | ||||
|                     if (reader.Read()) | ||||
|                         item = readInventoryItem(reader); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return item; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Reads a list of inventory folders returned by a query. | ||||
|         /// </summary> | ||||
|         /// <param name="reader">A MySQL Data Reader</param> | ||||
|         /// <returns>A List containing inventory folders</returns> | ||||
|         protected InventoryFolderBase readInventoryFolder(IDataReader reader) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 InventoryFolderBase folder = new InventoryFolderBase(); | ||||
|                 folder.agentID = new LLUUID((string) reader["agentID"]); | ||||
|                 folder.parentID = new LLUUID((string) reader["parentFolderID"]); | ||||
|                 folder.folderID = new LLUUID((string) reader["folderID"]); | ||||
|                 folder.name = (string) reader["folderName"]; | ||||
|                 folder.type = (short) reader["type"]; | ||||
|                 folder.version = (ushort) ((int) reader["version"]); | ||||
|                 return folder; | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
| 
 | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a specified inventory folder | ||||
|         /// </summary> | ||||
|         /// <param name="folder">The folder to return</param> | ||||
|         /// <returns>A folder class</returns> | ||||
|         public InventoryFolderBase getInventoryFolder(LLUUID folderID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["uuid"] = folderID.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     reader.Read(); | ||||
|                     InventoryFolderBase folder = readInventoryFolder(reader); | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return folder; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Adds a specified item to the database | ||||
|         /// </summary> | ||||
|         /// <param name="item">The inventory item</param> | ||||
|         public void addInventoryItem(InventoryItemBase item) | ||||
|         { | ||||
|             string sql = "INSERT INTO inventoryitems"; | ||||
|             sql += | ||||
|                 "([inventoryID], [assetID], [assetType], [parentFolderID], [avatarID], [inventoryName], [inventoryDescription], [inventoryNextPermissions], [inventoryCurrentPermissions], [invType], [creatorID], [inventoryBasePermissions], [inventoryEveryOnePermissions]) VALUES "; | ||||
|             sql += | ||||
|                 "(@inventoryID, @assetID, @assetType, @parentFolderID, @avatarID, @inventoryName, @inventoryDescription, @inventoryNextPermissions, @inventoryCurrentPermissions, @invType, @creatorID, @inventoryBasePermissions, @inventoryEveryOnePermissions);"; | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["inventoryID"] = item.inventoryID.ToString(); | ||||
|                 param["assetID"] = item.assetID.ToString(); | ||||
|                 param["assetType"] = item.assetType.ToString(); | ||||
|                 param["parentFolderID"] = item.parentFolderID.ToString(); | ||||
|                 param["avatarID"] = item.avatarID.ToString(); | ||||
|                 param["inventoryName"] = item.inventoryName; | ||||
|                 param["inventoryDescription"] = item.inventoryDescription; | ||||
|                 param["inventoryNextPermissions"] = item.inventoryNextPermissions.ToString(); | ||||
|                 param["inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString(); | ||||
|                 param["invType"] = Convert.ToString(item.invType); | ||||
|                 param["creatorID"] = item.creatorsID.ToString(); | ||||
|                 param["inventoryBasePermissions"] = Convert.ToString(item.inventoryBasePermissions); | ||||
|                 param["inventoryEveryOnePermissions"] = Convert.ToString(item.inventoryEveryOnePermissions); | ||||
| 
 | ||||
|                 IDbCommand result = database.Query(sql, param); | ||||
|                 result.ExecuteNonQuery(); | ||||
|                 result.Dispose(); | ||||
|             } | ||||
|             catch (SqlException e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Updates the specified inventory item | ||||
|         /// </summary> | ||||
|         /// <param name="item">Inventory item to update</param> | ||||
|         public void updateInventoryItem(InventoryItemBase item) | ||||
|         { | ||||
|             SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " + | ||||
|                                                 "assetID = @assetID, " + | ||||
|                                                 "assetType = @assetType" + | ||||
|                                                 "parentFolderID = @parentFolderID" + | ||||
|                                                 "avatarID = @avatarID" + | ||||
|                                                 "inventoryName = @inventoryName" + | ||||
|                                                 "inventoryDescription = @inventoryDescription" + | ||||
|                                                 "inventoryNextPermissions = @inventoryNextPermissions" + | ||||
|                                                 "inventoryCurrentPermissions = @inventoryCurrentPermissions" + | ||||
|                                                 "invType = @invType" + | ||||
|                                                 "creatorID = @creatorID" + | ||||
|                                                 "inventoryBasePermissions = @inventoryBasePermissions" + | ||||
|                                                 "inventoryEveryOnePermissions = @inventoryEveryOnePermissions) where " + | ||||
|                                                 "inventoryID = @keyInventoryID;", database.getConnection()); | ||||
|             SqlParameter param1 = new SqlParameter("@inventoryID", item.inventoryID.ToString()); | ||||
|             SqlParameter param2 = new SqlParameter("@assetID", item.assetID); | ||||
|             SqlParameter param3 = new SqlParameter("@assetType", item.assetType); | ||||
|             SqlParameter param4 = new SqlParameter("@parentFolderID", item.parentFolderID); | ||||
|             SqlParameter param5 = new SqlParameter("@avatarID", item.avatarID); | ||||
|             SqlParameter param6 = new SqlParameter("@inventoryName", item.inventoryName); | ||||
|             SqlParameter param7 = new SqlParameter("@inventoryDescription", item.inventoryDescription); | ||||
|             SqlParameter param8 = new SqlParameter("@inventoryNextPermissions", item.inventoryNextPermissions); | ||||
|             SqlParameter param9 = new SqlParameter("@inventoryCurrentPermissions", item.inventoryCurrentPermissions); | ||||
|             SqlParameter param10 = new SqlParameter("@invType", item.invType); | ||||
|             SqlParameter param11 = new SqlParameter("@creatorID", item.creatorsID); | ||||
|             SqlParameter param12 = new SqlParameter("@inventoryBasePermissions", item.inventoryBasePermissions); | ||||
|             SqlParameter param13 = new SqlParameter("@inventoryEveryOnePermissions", item.inventoryEveryOnePermissions); | ||||
|             SqlParameter param14 = new SqlParameter("@keyInventoryID", item.inventoryID.ToString()); | ||||
|             command.Parameters.Add(param1); | ||||
|             command.Parameters.Add(param2); | ||||
|             command.Parameters.Add(param3); | ||||
|             command.Parameters.Add(param4); | ||||
|             command.Parameters.Add(param5); | ||||
|             command.Parameters.Add(param6); | ||||
|             command.Parameters.Add(param7); | ||||
|             command.Parameters.Add(param8); | ||||
|             command.Parameters.Add(param9); | ||||
|             command.Parameters.Add(param10); | ||||
|             command.Parameters.Add(param11); | ||||
|             command.Parameters.Add(param12); | ||||
|             command.Parameters.Add(param13); | ||||
|             command.Parameters.Add(param14); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 command.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         ///  | ||||
|         /// </summary> | ||||
|         /// <param name="item"></param> | ||||
|         public void deleteInventoryItem(LLUUID itemID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["uuid"] = itemID.ToString(); | ||||
| 
 | ||||
|                 IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param); | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|             catch (SqlException e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new inventory folder | ||||
|         /// </summary> | ||||
|         /// <param name="folder">Folder to create</param> | ||||
|         public void addInventoryFolder(InventoryFolderBase folder) | ||||
|         { | ||||
|             string sql = | ||||
|                 "INSERT INTO inventoryfolders ([folderID], [agentID], [parentFolderID], [folderName], [type], [version]) VALUES "; | ||||
|             sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);"; | ||||
| 
 | ||||
| 
 | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["folderID"] = folder.folderID.ToString(); | ||||
|             param["agentID"] = folder.agentID.ToString(); | ||||
|             param["parentFolderID"] = folder.parentID.ToString(); | ||||
|             param["folderName"] = folder.name; | ||||
|             param["type"] = Convert.ToString(folder.type); | ||||
|             param["version"] = Convert.ToString(folder.version); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IDbCommand result = database.Query(sql, param); | ||||
|                 result.ExecuteNonQuery(); | ||||
|                 result.Dispose(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Updates an inventory folder | ||||
|         /// </summary> | ||||
|         /// <param name="folder">Folder to update</param> | ||||
|         public void updateInventoryFolder(InventoryFolderBase folder) | ||||
|         { | ||||
|             SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + | ||||
|                                                 "agentID = @agentID, " + | ||||
|                                                 "parentFolderID = @parentFolderID," + | ||||
|                                                 "folderName = @folderName," + | ||||
|                                                 "type = @type," + | ||||
|                                                 "version = @version where " + | ||||
|                                                 "folderID = @keyFolderID;", database.getConnection()); | ||||
|             SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToString()); | ||||
|             SqlParameter param2 = new SqlParameter("@agentID", folder.agentID.ToString()); | ||||
|             SqlParameter param3 = new SqlParameter("@parentFolderID", folder.parentID.ToString()); | ||||
|             SqlParameter param4 = new SqlParameter("@folderName", folder.name); | ||||
|             SqlParameter param5 = new SqlParameter("@type", folder.type); | ||||
|             SqlParameter param6 = new SqlParameter("@version", folder.version); | ||||
|             SqlParameter param7 = new SqlParameter("@keyFolderID", folder.folderID.ToString()); | ||||
|             command.Parameters.Add(param1); | ||||
|             command.Parameters.Add(param2); | ||||
|             command.Parameters.Add(param3); | ||||
|             command.Parameters.Add(param4); | ||||
|             command.Parameters.Add(param5); | ||||
|             command.Parameters.Add(param6); | ||||
|             command.Parameters.Add(param7); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 command.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Updates an inventory folder | ||||
|         /// </summary> | ||||
|         /// <param name="folder">Folder to update</param> | ||||
|         public void moveInventoryFolder(InventoryFolderBase folder) | ||||
|         { | ||||
|             SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + | ||||
|                                                 "parentFolderID = @parentFolderID," + | ||||
|                                                 "folderID = @keyFolderID;", database.getConnection()); | ||||
|             SqlParameter param1 = new SqlParameter("@folderID", folder.folderID.ToString()); | ||||
|             SqlParameter param2 = new SqlParameter("@parentFolderID", folder.parentID.ToString()); | ||||
|             SqlParameter param3 = new SqlParameter("@keyFolderID", folder.folderID.ToString()); | ||||
|             command.Parameters.Add(param1); | ||||
|             command.Parameters.Add(param2); | ||||
|             command.Parameters.Add(param3); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 command.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Append a list of all the child folders of a parent folder  | ||||
|         /// </summary> | ||||
|         /// <param name="folders">list where folders will be appended</param> | ||||
|         /// <param name="parentID">ID of parent</param> | ||||
|         protected void getInventoryFolders(ref List<InventoryFolderBase> folders, LLUUID parentID) | ||||
|         { | ||||
|             List<InventoryFolderBase> subfolderList = getInventoryFolders(parentID); | ||||
| 
 | ||||
|             foreach (InventoryFolderBase f in subfolderList) | ||||
|                 folders.Add(f); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns all child folders in the hierarchy from the parent folder and down | ||||
|         /// </summary> | ||||
|         /// <param name="parentID">The folder to get subfolders for</param> | ||||
|         /// <returns>A list of inventory folders</returns> | ||||
|         protected List<InventoryFolderBase> getFolderHierarchy(LLUUID parentID) | ||||
|         { | ||||
|             List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | ||||
|             getInventoryFolders(ref folders, parentID); | ||||
| 
 | ||||
|             for (int i = 0; i < folders.Count; i++) | ||||
|                 getInventoryFolders(ref folders, folders[i].folderID); | ||||
| 
 | ||||
|             return folders; | ||||
|         } | ||||
| 
 | ||||
|         protected void deleteOneFolder(LLUUID folderID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["folderID"] = folderID.ToString(); | ||||
| 
 | ||||
|                 IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param); | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|             catch (SqlException e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         protected void deleteItemsInFolder(LLUUID folderID) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["parentFolderID"] = folderID.ToString(); | ||||
| 
 | ||||
| 
 | ||||
|                 IDbCommand cmd = | ||||
|                     database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param); | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|             catch (SqlException e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Delete an inventory folder | ||||
|         /// </summary> | ||||
|         /// <param name="folderId">Id of folder to delete</param> | ||||
|         public void deleteInventoryFolder(LLUUID folderID) | ||||
|         { | ||||
|             lock (database) | ||||
|             { | ||||
|                 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID); | ||||
| 
 | ||||
|                 //Delete all sub-folders | ||||
|                 foreach (InventoryFolderBase f in subFolders) | ||||
|                 { | ||||
|                     deleteOneFolder(f.folderID); | ||||
|                     deleteItemsInFolder(f.folderID); | ||||
|                 } | ||||
| 
 | ||||
|                 //Delete the actual row | ||||
|                 deleteOneFolder(folderID); | ||||
|                 deleteItemsInFolder(folderID); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,120 @@ | |||
| /* | ||||
| * 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.Collections.Generic; | ||||
| using System.Data; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     /// <summary> | ||||
|     /// An interface to the log database for MySQL | ||||
|     /// </summary> | ||||
|     internal class MSSQLLogData : ILogData | ||||
|     { | ||||
|         /// <summary> | ||||
|         /// The database manager | ||||
|         /// </summary> | ||||
|         public MSSQLManager database; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Artificial constructor called when the plugin is loaded | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); | ||||
|             string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); | ||||
|             string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); | ||||
|             string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); | ||||
|             string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); | ||||
|             string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); | ||||
| 
 | ||||
|             database = | ||||
|                 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||||
|                                  settingPassword); | ||||
| 
 | ||||
|             IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary<string, string>()); | ||||
|             try | ||||
|             { | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|                 cmd.Dispose(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 database.ExecuteResourceSql("Mssql-logs.sql"); | ||||
|             } | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Saves a log item to the database | ||||
|         /// </summary> | ||||
|         /// <param name="serverDaemon">The daemon triggering the event</param> | ||||
|         /// <param name="target">The target of the action (region / agent UUID, etc)</param> | ||||
|         /// <param name="methodCall">The method call where the problem occured</param> | ||||
|         /// <param name="arguments">The arguments passed to the method</param> | ||||
|         /// <param name="priority">How critical is this?</param> | ||||
|         /// <param name="logMessage">The message to log</param> | ||||
|         public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||||
|                             string logMessage) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the name of this DB provider | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the DB provider name</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "MSSQL Logdata Interface"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Closes the database provider | ||||
|         /// </summary> | ||||
|         public void Close() | ||||
|         { | ||||
|             // Do nothing. | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns the version of this DB provider | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the provider version</returns> | ||||
|         public string getVersion() | ||||
|         { | ||||
|             return "0.1"; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,525 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using System.Data.SqlClient; | ||||
| using System.IO; | ||||
| using System.Reflection; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A management class for the MS SQL Storage Engine | ||||
|     /// </summary> | ||||
|     public class MSSQLManager | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// The database connection object | ||||
|         /// </summary> | ||||
|         private IDbConnection dbcon; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Connection string for ADO.net | ||||
|         /// </summary> | ||||
|         private readonly string connectionString; | ||||
| 
 | ||||
|         public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId, | ||||
|                             string password) | ||||
|         { | ||||
|             connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog + | ||||
|                                    ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" + | ||||
|                                    password + ";"; | ||||
|             dbcon = new SqlConnection(connectionString); | ||||
|             dbcon.Open(); | ||||
|         } | ||||
| 
 | ||||
|         //private DataTable createRegionsTable() | ||||
|         //{ | ||||
|         //    DataTable regions = new DataTable("regions"); | ||||
| 
 | ||||
|         //    createCol(regions, "regionHandle", typeof (ulong)); | ||||
|         //    createCol(regions, "regionName", typeof (String)); | ||||
|         //    createCol(regions, "uuid", typeof (String)); | ||||
| 
 | ||||
|         //    createCol(regions, "regionRecvKey", typeof (String)); | ||||
|         //    createCol(regions, "regionSecret", typeof (String)); | ||||
|         //    createCol(regions, "regionSendKey", typeof (String)); | ||||
| 
 | ||||
|         //    createCol(regions, "regionDataURI", typeof (String)); | ||||
|         //    createCol(regions, "serverIP", typeof (String)); | ||||
|         //    createCol(regions, "serverPort", typeof (String)); | ||||
|         //    createCol(regions, "serverURI", typeof (String)); | ||||
| 
 | ||||
| 
 | ||||
|         //    createCol(regions, "locX", typeof (uint)); | ||||
|         //    createCol(regions, "locY", typeof (uint)); | ||||
|         //    createCol(regions, "locZ", typeof (uint)); | ||||
| 
 | ||||
|         //    createCol(regions, "eastOverrideHandle", typeof (ulong)); | ||||
|         //    createCol(regions, "westOverrideHandle", typeof (ulong)); | ||||
|         //    createCol(regions, "southOverrideHandle", typeof (ulong)); | ||||
|         //    createCol(regions, "northOverrideHandle", typeof (ulong)); | ||||
| 
 | ||||
|         //    createCol(regions, "regionAssetURI", typeof (String)); | ||||
|         //    createCol(regions, "regionAssetRecvKey", typeof (String)); | ||||
|         //    createCol(regions, "regionAssetSendKey", typeof (String)); | ||||
| 
 | ||||
|         //    createCol(regions, "regionUserURI", typeof (String)); | ||||
|         //    createCol(regions, "regionUserRecvKey", typeof (String)); | ||||
|         //    createCol(regions, "regionUserSendKey", typeof (String)); | ||||
| 
 | ||||
|         //    createCol(regions, "regionMapTexture", typeof (String)); | ||||
|         //    createCol(regions, "serverHttpPort", typeof (String)); | ||||
|         //    createCol(regions, "serverRemotingPort", typeof (uint)); | ||||
| 
 | ||||
|         //    // Add in contraints | ||||
|         //    regions.PrimaryKey = new DataColumn[] {regions.Columns["UUID"]}; | ||||
|         //    return regions; | ||||
|         //} | ||||
| 
 | ||||
|         protected static void createCol(DataTable dt, string name, Type type) | ||||
|         { | ||||
|             DataColumn col = new DataColumn(name, type); | ||||
|             dt.Columns.Add(col); | ||||
|         } | ||||
| 
 | ||||
|         protected static string defineTable(DataTable dt) | ||||
|         { | ||||
|             string sql = "create table " + dt.TableName + "("; | ||||
|             string subsql = String.Empty; | ||||
|             foreach (DataColumn col in dt.Columns) | ||||
|             { | ||||
|                 if (subsql.Length > 0) | ||||
|                 { | ||||
|                     // a map function would rock so much here | ||||
|                     subsql += ",\n"; | ||||
|                 } | ||||
| 
 | ||||
|                 subsql += col.ColumnName + " " + SqlType(col.DataType); | ||||
|                 if (col == dt.PrimaryKey[0]) | ||||
|                 { | ||||
|                     subsql += " primary key"; | ||||
|                 } | ||||
|             } | ||||
|             sql += subsql; | ||||
|             sql += ")"; | ||||
|             return sql; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         // this is something we'll need to implement for each db | ||||
|         // slightly differently. | ||||
|         private static string SqlType(Type type) | ||||
|         { | ||||
|             if (type == typeof(String)) | ||||
|             { | ||||
|                 return "varchar(255)"; | ||||
|             } | ||||
|             else if (type == typeof(Int32)) | ||||
|             { | ||||
|                 return "integer"; | ||||
|             } | ||||
|             else if (type == typeof(Double)) | ||||
|             { | ||||
|                 return "float"; | ||||
|             } | ||||
|             else if (type == typeof(Byte[])) | ||||
|             { | ||||
|                 return "image"; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return "varchar(255)"; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Shuts down the database connection | ||||
|         /// </summary> | ||||
|         public void Close() | ||||
|         { | ||||
|             dbcon.Close(); | ||||
|             dbcon = null; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Reconnects to the database | ||||
|         /// </summary> | ||||
|         public void Reconnect() | ||||
|         { | ||||
|             lock (dbcon) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     // Close the DB connection | ||||
|                     dbcon.Close(); | ||||
|                     // Try reopen it | ||||
|                     dbcon = new SqlConnection(connectionString); | ||||
|                     dbcon.Open(); | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.Error("Unable to reconnect to database " + e.ToString()); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Runs a query with protection against SQL Injection by using parameterised input. | ||||
|         /// </summary> | ||||
|         /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param> | ||||
|         /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param> | ||||
|         /// <returns>A Sql DB Command</returns> | ||||
|         public IDbCommand Query(string sql, Dictionary<string, string> parameters) | ||||
|         { | ||||
|             SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand(); | ||||
|             dbcommand.CommandText = sql; | ||||
|             foreach (KeyValuePair<string, string> param in parameters) | ||||
|             { | ||||
|                 dbcommand.Parameters.AddWithValue(param.Key, param.Value); | ||||
|             } | ||||
| 
 | ||||
|             return (IDbCommand)dbcommand; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Runs a database reader object and returns a region row | ||||
|         /// </summary> | ||||
|         /// <param name="reader">An active database reader</param> | ||||
|         /// <returns>A region row</returns> | ||||
|         public RegionProfileData getRegionRow(IDataReader reader) | ||||
|         { | ||||
|             RegionProfileData regionprofile = new RegionProfileData(); | ||||
| 
 | ||||
|             if (reader.Read()) | ||||
|             { | ||||
|                 // Region Main | ||||
|                 regionprofile.regionHandle = Convert.ToUInt64(reader["regionHandle"]); | ||||
|                 regionprofile.regionName = (string)reader["regionName"]; | ||||
|                 regionprofile.UUID = new LLUUID((string)reader["uuid"]); | ||||
| 
 | ||||
|                 // Secrets | ||||
|                 regionprofile.regionRecvKey = (string)reader["regionRecvKey"]; | ||||
|                 regionprofile.regionSecret = (string)reader["regionSecret"]; | ||||
|                 regionprofile.regionSendKey = (string)reader["regionSendKey"]; | ||||
| 
 | ||||
|                 // Region Server | ||||
|                 regionprofile.regionDataURI = (string)reader["regionDataURI"]; | ||||
|                 regionprofile.regionOnline = false; // Needs to be pinged before this can be set. | ||||
|                 regionprofile.serverIP = (string)reader["serverIP"]; | ||||
|                 regionprofile.serverPort = Convert.ToUInt32(reader["serverPort"]); | ||||
|                 regionprofile.serverURI = (string)reader["serverURI"]; | ||||
|                 regionprofile.httpPort = Convert.ToUInt32(reader["serverHttpPort"]); | ||||
|                 regionprofile.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"]); | ||||
| 
 | ||||
| 
 | ||||
|                 // Location | ||||
|                 regionprofile.regionLocX = Convert.ToUInt32(reader["locX"]); | ||||
|                 regionprofile.regionLocY = Convert.ToUInt32(reader["locY"]); | ||||
|                 regionprofile.regionLocZ = Convert.ToUInt32(reader["locZ"]); | ||||
| 
 | ||||
|                 // Neighbours - 0 = No Override | ||||
|                 regionprofile.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"]); | ||||
|                 regionprofile.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"]); | ||||
|                 regionprofile.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"]); | ||||
|                 regionprofile.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"]); | ||||
| 
 | ||||
|                 // Assets | ||||
|                 regionprofile.regionAssetURI = (string)reader["regionAssetURI"]; | ||||
|                 regionprofile.regionAssetRecvKey = (string)reader["regionAssetRecvKey"]; | ||||
|                 regionprofile.regionAssetSendKey = (string)reader["regionAssetSendKey"]; | ||||
| 
 | ||||
|                 // Userserver | ||||
|                 regionprofile.regionUserURI = (string)reader["regionUserURI"]; | ||||
|                 regionprofile.regionUserRecvKey = (string)reader["regionUserRecvKey"]; | ||||
|                 regionprofile.regionUserSendKey = (string)reader["regionUserSendKey"]; | ||||
| 
 | ||||
|                 // World Map Addition | ||||
|                 string tempRegionMap = reader["regionMapTexture"].ToString(); | ||||
|                 if (tempRegionMap != String.Empty) | ||||
|                 { | ||||
|                     regionprofile.regionMapTextureID = new LLUUID(tempRegionMap); | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     regionprofile.regionMapTextureID = new LLUUID(); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 reader.Close(); | ||||
|                 throw new Exception("No rows to return"); | ||||
|             } | ||||
|             return regionprofile; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Reads a user profile from an active data reader | ||||
|         /// </summary> | ||||
|         /// <param name="reader">An active database reader</param> | ||||
|         /// <returns>A user profile</returns> | ||||
|         public UserProfileData readUserRow(IDataReader reader) | ||||
|         { | ||||
|             UserProfileData retval = new UserProfileData(); | ||||
| 
 | ||||
|             if (reader.Read()) | ||||
|             { | ||||
|                 retval.UUID = new LLUUID((string)reader["UUID"]); | ||||
|                 retval.username = (string)reader["username"]; | ||||
|                 retval.surname = (string)reader["lastname"]; | ||||
| 
 | ||||
|                 retval.passwordHash = (string)reader["passwordHash"]; | ||||
|                 retval.passwordSalt = (string)reader["passwordSalt"]; | ||||
| 
 | ||||
|                 retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString()); | ||||
|                 retval.homeLocation = new LLVector3( | ||||
|                     Convert.ToSingle(reader["homeLocationX"].ToString()), | ||||
|                     Convert.ToSingle(reader["homeLocationY"].ToString()), | ||||
|                     Convert.ToSingle(reader["homeLocationZ"].ToString())); | ||||
|                 retval.homeLookAt = new LLVector3( | ||||
|                     Convert.ToSingle(reader["homeLookAtX"].ToString()), | ||||
|                     Convert.ToSingle(reader["homeLookAtY"].ToString()), | ||||
|                     Convert.ToSingle(reader["homeLookAtZ"].ToString())); | ||||
| 
 | ||||
|                 retval.created = Convert.ToInt32(reader["created"].ToString()); | ||||
|                 retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString()); | ||||
| 
 | ||||
|                 retval.userInventoryURI = (string)reader["userInventoryURI"]; | ||||
|                 retval.userAssetURI = (string)reader["userAssetURI"]; | ||||
| 
 | ||||
|                 retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString()); | ||||
|                 retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString()); | ||||
| 
 | ||||
|                 retval.profileAboutText = (string)reader["profileAboutText"]; | ||||
|                 retval.profileFirstText = (string)reader["profileFirstText"]; | ||||
| 
 | ||||
|                 retval.profileImage = new LLUUID((string)reader["profileImage"]); | ||||
|                 retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]); | ||||
|                 retval.webLoginKey = new LLUUID((string)reader["webLoginKey"]); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|             return retval; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Reads an agent row from a database reader | ||||
|         /// </summary> | ||||
|         /// <param name="reader">An active database reader</param> | ||||
|         /// <returns>A user session agent</returns> | ||||
|         public UserAgentData readAgentRow(IDataReader reader) | ||||
|         { | ||||
|             UserAgentData retval = new UserAgentData(); | ||||
| 
 | ||||
|             if (reader.Read()) | ||||
|             { | ||||
|                 // Agent IDs | ||||
|                 retval.UUID = new LLUUID((string)reader["UUID"]); | ||||
|                 retval.sessionID = new LLUUID((string)reader["sessionID"]); | ||||
|                 retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]); | ||||
| 
 | ||||
|                 // Agent Who? | ||||
|                 retval.agentIP = (string)reader["agentIP"]; | ||||
|                 retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString()); | ||||
|                 retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString()); | ||||
| 
 | ||||
|                 // Login/Logout times (UNIX Epoch) | ||||
|                 retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString()); | ||||
|                 retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString()); | ||||
| 
 | ||||
|                 // Current position | ||||
|                 retval.currentRegion = (string)reader["currentRegion"]; | ||||
|                 retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString()); | ||||
|                 LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|             return retval; | ||||
|         } | ||||
| 
 | ||||
|         public AssetBase getAssetRow(IDataReader reader) | ||||
|         { | ||||
|             AssetBase asset = new AssetBase(); | ||||
|             if (reader.Read()) | ||||
|             { | ||||
|                 // Region Main | ||||
| 
 | ||||
|                 asset = new AssetBase(); | ||||
|                 asset.Data = (byte[])reader["data"]; | ||||
|                 asset.Description = (string)reader["description"]; | ||||
|                 asset.FullID = new LLUUID((string)reader["id"]); | ||||
|                 asset.InvType = Convert.ToSByte(reader["invType"]); | ||||
|                 asset.Local = Convert.ToBoolean(reader["local"]); // ((sbyte)reader["local"]) != 0 ? true : false; | ||||
|                 asset.Name = (string)reader["name"]; | ||||
|                 asset.Type = Convert.ToSByte(reader["assetType"]); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 return null; // throw new Exception("No rows to return"); | ||||
|             } | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Inserts a new row into the log database | ||||
|         /// </summary> | ||||
|         /// <param name="serverDaemon">The daemon which triggered this event</param> | ||||
|         /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param> | ||||
|         /// <param name="methodCall">The method call where the problem occured</param> | ||||
|         /// <param name="arguments">The arguments passed to the method</param> | ||||
|         /// <param name="priority">How critical is this?</param> | ||||
|         /// <param name="logMessage">Extra message info</param> | ||||
|         /// <returns>Saved successfully?</returns> | ||||
|         public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, | ||||
|                                  string logMessage) | ||||
|         { | ||||
|             string sql = "INSERT INTO logs ([target], [server], [method], [arguments], [priority], [message]) VALUES "; | ||||
|             sql += "(@target, @server, @method, @arguments, @priority, @message);"; | ||||
| 
 | ||||
|             Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||||
|             parameters["server"] = serverDaemon; | ||||
|             parameters["target"] = target; | ||||
|             parameters["method"] = methodCall; | ||||
|             parameters["arguments"] = arguments; | ||||
|             parameters["priority"] = priority.ToString(); | ||||
|             parameters["message"] = logMessage; | ||||
| 
 | ||||
|             bool returnval = false; | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IDbCommand result = Query(sql, parameters); | ||||
| 
 | ||||
|                 if (result.ExecuteNonQuery() == 1) | ||||
|                     returnval = true; | ||||
| 
 | ||||
|                 result.Dispose(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             return returnval; | ||||
|         } | ||||
|         | ||||
|         /// <summary> | ||||
|         /// Execute a SQL statement stored in a resource, as a string | ||||
|         /// </summary> | ||||
|         /// <param name="name"></param> | ||||
|         public void ExecuteResourceSql(string name) | ||||
|         { | ||||
|             SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon); | ||||
|             cmd.ExecuteNonQuery(); | ||||
|             cmd.Dispose(); | ||||
|         } | ||||
| 
 | ||||
|         public SqlConnection getConnection() | ||||
|         { | ||||
|             return (SqlConnection)dbcon; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Given a list of tables, return the version of the tables, as seen in the database | ||||
|         /// </summary> | ||||
|         /// <param name="tableList"></param> | ||||
|         public void GetTableVersion(Dictionary<string, string> tableList) | ||||
|         { | ||||
|             lock (dbcon) | ||||
|             { | ||||
|                 Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                 param["dbname"] = dbcon.Database; | ||||
|                 IDbCommand tablesCmd = | ||||
|                     Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param); | ||||
|                 using (IDataReader tables = tablesCmd.ExecuteReader()) | ||||
|                 { | ||||
|                     while (tables.Read()) | ||||
|                     { | ||||
|                         try | ||||
|                         { | ||||
|                             string tableName = (string)tables["TABLE_NAME"]; | ||||
|                             if (tableList.ContainsKey(tableName)) | ||||
|                                 tableList[tableName] = tableName; | ||||
|                         } | ||||
|                         catch (Exception e) | ||||
|                         { | ||||
|                             m_log.Error(e.ToString()); | ||||
|                         } | ||||
|                     } | ||||
|                     tables.Close(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private string getResourceString(string name) | ||||
|         { | ||||
|             Assembly assem = GetType().Assembly; | ||||
|             string[] names = assem.GetManifestResourceNames(); | ||||
| 
 | ||||
|             foreach (string s in names) | ||||
|                 if (s.EndsWith(name)) | ||||
|                     using (Stream resource = assem.GetManifestResourceStream(s)) | ||||
|                     { | ||||
|                         using (StreamReader resourceReader = new StreamReader(resource)) | ||||
|                         { | ||||
|                             string resourceString = resourceReader.ReadToEnd(); | ||||
|                             return resourceString; | ||||
|                         } | ||||
|                     } | ||||
|             throw new Exception(string.Format("Resource '{0}' was not found", name)); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary>  | ||||
|         /// Returns the version of this DB provider | ||||
|         /// </summary> | ||||
|         /// <returns>A string containing the DB provider</returns> | ||||
|         public string getVersion() | ||||
|         { | ||||
|             Module module = GetType().Module; | ||||
|             string dllName = module.Assembly.ManifestModule.Name; | ||||
|             Version dllVersion = module.Assembly.GetName().Version; | ||||
| 
 | ||||
| 
 | ||||
|             return | ||||
|                 string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, | ||||
|                               dllVersion.Revision); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,771 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using System.Data.SqlClient; | ||||
| using libsecondlife; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MSSQL | ||||
| { | ||||
|     /// <summary> | ||||
|     /// A database interface class to a user profile storage system | ||||
|     /// </summary> | ||||
|     public class MSSQLUserData : IUserData | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database manager for MySQL | ||||
|         /// </summary> | ||||
|         public MSSQLManager database; | ||||
| 
 | ||||
|         private string m_agentsTableName; | ||||
|         private string m_usersTableName; | ||||
|         private string m_userFriendsTableName; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Loads and initialises the MySQL storage plugin | ||||
|         /// </summary> | ||||
|         public void Initialise() | ||||
|         { | ||||
|             // Load from an INI file connection details | ||||
|             // TODO: move this to XML? | ||||
|             IniFile iniFile = new IniFile("mssql_connection.ini"); | ||||
|             string settingDataSource = iniFile.ParseFileReadValue("data_source"); | ||||
|             string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog"); | ||||
|             string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info"); | ||||
|             string settingUserId = iniFile.ParseFileReadValue("user_id"); | ||||
|             string settingPassword = iniFile.ParseFileReadValue("password"); | ||||
| 
 | ||||
|             m_usersTableName = iniFile.ParseFileReadValue("userstablename"); | ||||
|             if (m_usersTableName == null) | ||||
|             { | ||||
|                 m_usersTableName = "users"; | ||||
|             } | ||||
| 
 | ||||
|             m_userFriendsTableName = iniFile.ParseFileReadValue("userfriendstablename"); | ||||
|             if (m_userFriendsTableName == null) | ||||
|             { | ||||
|                 m_userFriendsTableName = "userfriends"; | ||||
|             } | ||||
| 
 | ||||
|             m_agentsTableName = iniFile.ParseFileReadValue("agentstablename"); | ||||
|             if (m_agentsTableName == null) | ||||
|             { | ||||
|                 m_agentsTableName = "agents"; | ||||
|             } | ||||
| 
 | ||||
|             database = | ||||
|                 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, | ||||
|                                  settingPassword); | ||||
| 
 | ||||
|             TestTables(); | ||||
|         } | ||||
| 
 | ||||
|         private bool TestTables() | ||||
|         { | ||||
|             IDbCommand cmd; | ||||
| 
 | ||||
|             cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary<string, string>()); | ||||
|             try | ||||
|             { | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 database.ExecuteResourceSql("Mssql-users.sql"); | ||||
|             } | ||||
|         | ||||
|             cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary<string, string>()); | ||||
|             try | ||||
|             { | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 database.ExecuteResourceSql("Mssql-agents.sql"); | ||||
|             } | ||||
| 
 | ||||
|             cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary<string, string>()); | ||||
|             try | ||||
|             { | ||||
|                 cmd.ExecuteNonQuery(); | ||||
|             } | ||||
|             catch | ||||
|             { | ||||
|                 database.ExecuteResourceSql("CreateUserFriendsTable.sql"); | ||||
|             } | ||||
| 
 | ||||
|             return true; | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Searches the database for a specified user profile by name components | ||||
|         /// </summary> | ||||
|         /// <param name="user">The first part of the account name</param> | ||||
|         /// <param name="last">The second part of the account name</param> | ||||
|         /// <returns>A user profile</returns> | ||||
|         public UserProfileData GetUserByName(string user, string last) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["first"] = user; | ||||
|                     param["second"] = last; | ||||
| 
 | ||||
|                     IDbCommand result = | ||||
|                         database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     UserProfileData row = database.readUserRow(reader); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return row; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         #region User Friends List Data | ||||
| 
 | ||||
|         public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             int dtvalue = Util.UnixTimeSinceEpoch(); | ||||
| 
 | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["@ownerID"] = friendlistowner.UUID.ToString(); | ||||
|             param["@friendID"] = friend.UUID.ToString(); | ||||
|             param["@friendPerms"] = perms.ToString(); | ||||
|             param["@datetimestamp"] = dtvalue.ToString(); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     IDbCommand adder = | ||||
|                         database.Query( | ||||
|                         "INSERT INTO " + m_userFriendsTableName + " " + | ||||
|                         "(ownerID,friendID,friendPerms,datetimestamp) " + | ||||
|                         "VALUES " + | ||||
|                         "(@ownerID,@friendID,@friendPerms,@datetimestamp)", | ||||
|                             param); | ||||
| 
 | ||||
|                     adder.ExecuteNonQuery(); | ||||
| 
 | ||||
|                     adder = | ||||
|                         database.Query( | ||||
|                         "INSERT INTO " + m_userFriendsTableName + " " + | ||||
|                         "(ownerID,friendID,friendPerms,datetimestamp) " + | ||||
|                         "VALUES " + | ||||
|                         "(@friendID,@ownerID,@friendPerms,@datetimestamp)", | ||||
|                             param); | ||||
|                     adder.ExecuteNonQuery(); | ||||
| 
 | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend) | ||||
|         { | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["@ownerID"] = friendlistowner.UUID.ToString(); | ||||
|             param["@friendID"] = friend.UUID.ToString(); | ||||
| 
 | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     IDbCommand updater = | ||||
|                         database.Query( | ||||
|                         "delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID", | ||||
|                             param); | ||||
|                     updater.ExecuteNonQuery(); | ||||
| 
 | ||||
|                     updater = | ||||
|                         database.Query( | ||||
|                         "delete from " + m_userFriendsTableName + " where ownerID = @friendID and friendID = @ownerID", | ||||
|                             param); | ||||
|                     updater.ExecuteNonQuery(); | ||||
| 
 | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms) | ||||
|         { | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["@ownerID"] = friendlistowner.UUID.ToString(); | ||||
|             param["@friendID"] = friend.UUID.ToString(); | ||||
|             param["@friendPerms"] = perms.ToString(); | ||||
| 
 | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     IDbCommand updater = | ||||
|                         database.Query( | ||||
|                         "update " + m_userFriendsTableName + | ||||
|                         " SET friendPerms = @friendPerms " + | ||||
|                         "where ownerID = @ownerID and friendID = @friendID", | ||||
|                             param); | ||||
| 
 | ||||
|                     updater.ExecuteNonQuery(); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner) | ||||
|         { | ||||
|             List<FriendListItem> Lfli = new List<FriendListItem>(); | ||||
| 
 | ||||
|             Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|             param["@ownerID"] = friendlistowner.UUID.ToString(); | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     //Left Join userfriends to itself | ||||
|                     IDbCommand result = | ||||
|                         database.Query( | ||||
|                         "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" + | ||||
|                         " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID", | ||||
|                             param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
| 
 | ||||
|                     while (reader.Read()) | ||||
|                     { | ||||
|                         FriendListItem fli = new FriendListItem(); | ||||
|                         fli.FriendListOwner = new LLUUID((string)reader["ownerID"]); | ||||
|                         fli.Friend = new LLUUID((string)reader["friendID"]); | ||||
|                         fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]); | ||||
| 
 | ||||
|                         // This is not a real column in the database table, it's a joined column from the opposite record | ||||
|                         fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]); | ||||
| 
 | ||||
|                         Lfli.Add(fli); | ||||
|                     } | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return Lfli; | ||||
|             } | ||||
| 
 | ||||
|             return Lfli; | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid) | ||||
|         { | ||||
|             m_log.Info("[USER]: Stub UpdateUserCUrrentRegion called"); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
|         public List<Framework.AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query) | ||||
|         { | ||||
|             List<Framework.AvatarPickerAvatar> returnlist = new List<Framework.AvatarPickerAvatar>(); | ||||
|             string[] querysplit; | ||||
|             querysplit = query.Split(' '); | ||||
|             if (querysplit.Length == 2) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     lock (database) | ||||
|                     { | ||||
|                         Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                         param["first"] = querysplit[0]; | ||||
|                         param["second"] = querysplit[1]; | ||||
| 
 | ||||
|                         IDbCommand result = | ||||
|                             database.Query( | ||||
|                                 "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", | ||||
|                                 param); | ||||
|                         IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
| 
 | ||||
|                         while (reader.Read()) | ||||
|                         { | ||||
|                             Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); | ||||
|                             user.AvatarID = new LLUUID((string)reader["UUID"]); | ||||
|                             user.firstName = (string)reader["username"]; | ||||
|                             user.lastName = (string)reader["lastname"]; | ||||
|                             returnlist.Add(user); | ||||
|                         } | ||||
|                         reader.Close(); | ||||
|                         result.Dispose(); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     database.Reconnect(); | ||||
|                     m_log.Error(e.ToString()); | ||||
|                     return returnlist; | ||||
|                 } | ||||
|             } | ||||
|             else if (querysplit.Length == 1) | ||||
|             { | ||||
|                 try | ||||
|                 { | ||||
|                     lock (database) | ||||
|                     { | ||||
|                         Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                         param["first"] = querysplit[0]; | ||||
| 
 | ||||
|                         IDbCommand result = | ||||
|                             database.Query( | ||||
|                                 "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first OR lastname = @first", | ||||
|                                 param); | ||||
|                         IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
| 
 | ||||
|                         while (reader.Read()) | ||||
|                         { | ||||
|                             Framework.AvatarPickerAvatar user = new Framework.AvatarPickerAvatar(); | ||||
|                             user.AvatarID = new LLUUID((string)reader["UUID"]); | ||||
|                             user.firstName = (string)reader["username"]; | ||||
|                             user.lastName = (string)reader["lastname"]; | ||||
|                             returnlist.Add(user); | ||||
|                         } | ||||
|                         reader.Close(); | ||||
|                         result.Dispose(); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     database.Reconnect(); | ||||
|                     m_log.Error(e.ToString()); | ||||
|                     return returnlist; | ||||
|                 } | ||||
|             } | ||||
|             return returnlist; | ||||
|         } | ||||
| 
 | ||||
|         // See IUserData | ||||
|         public UserProfileData GetUserByUUID(LLUUID uuid) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["uuid"] = uuid.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     UserProfileData row = database.readUserRow(reader); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return row; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a user session searching by name | ||||
|         /// </summary> | ||||
|         /// <param name="name">The account name</param> | ||||
|         /// <returns>The users session</returns> | ||||
|         public UserAgentData GetAgentByName(string name) | ||||
|         { | ||||
|             return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns a user session by account name | ||||
|         /// </summary> | ||||
|         /// <param name="user">First part of the users account name</param> | ||||
|         /// <param name="last">Second part of the users account name</param> | ||||
|         /// <returns>The users session</returns> | ||||
|         public UserAgentData GetAgentByName(string user, string last) | ||||
|         { | ||||
|             UserProfileData profile = GetUserByName(user, last); | ||||
|             return GetAgentByUUID(profile.UUID); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Returns an agent session by account UUID | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">The accounts UUID</param> | ||||
|         /// <returns>The users session</returns> | ||||
|         public UserAgentData GetAgentByUUID(LLUUID uuid) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     Dictionary<string, string> param = new Dictionary<string, string>(); | ||||
|                     param["uuid"] = uuid.ToString(); | ||||
| 
 | ||||
|                     IDbCommand result = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid", param); | ||||
|                     IDataReader reader = result.ExecuteReader(); | ||||
| 
 | ||||
|                     UserAgentData row = database.readAgentRow(reader); | ||||
| 
 | ||||
|                     reader.Close(); | ||||
|                     result.Dispose(); | ||||
| 
 | ||||
|                     return row; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
|         public void StoreWebLoginKey(LLUUID AgentID, LLUUID WebLoginKey) | ||||
|         { | ||||
|             UserProfileData user = GetUserByUUID(AgentID); | ||||
|             user.webLoginKey = WebLoginKey; | ||||
|             UpdateUserProfile(user); | ||||
| 
 | ||||
|         } | ||||
|         /// <summary> | ||||
|         /// Creates a new users profile | ||||
|         /// </summary> | ||||
|         /// <param name="user">The user profile to create</param> | ||||
|         public void AddNewUserProfile(UserProfileData user) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 lock (database) | ||||
|                 { | ||||
|                     InsertUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt, | ||||
|                                            user.homeRegion, user.homeLocation.X, user.homeLocation.Y, | ||||
|                                            user.homeLocation.Z, | ||||
|                                            user.homeLookAt.X, user.homeLookAt.Y, user.homeLookAt.Z, user.created, | ||||
|                                            user.lastLogin, user.userInventoryURI, user.userAssetURI, | ||||
|                                            user.profileCanDoMask, user.profileWantDoMask, | ||||
|                                            user.profileAboutText, user.profileFirstText, user.profileImage, | ||||
|                                            user.profileFirstImage, user.webLoginKey); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 database.Reconnect(); | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new user and inserts it into the database | ||||
|         /// </summary> | ||||
|         /// <param name="uuid">User ID</param> | ||||
|         /// <param name="username">First part of the login</param> | ||||
|         /// <param name="lastname">Second part of the login</param> | ||||
|         /// <param name="passwordHash">A salted hash of the users password</param> | ||||
|         /// <param name="passwordSalt">The salt used for the password hash</param> | ||||
|         /// <param name="homeRegion">A regionHandle of the users home region</param> | ||||
|         /// <param name="homeLocX">Home region position vector</param> | ||||
|         /// <param name="homeLocY">Home region position vector</param> | ||||
|         /// <param name="homeLocZ">Home region position vector</param> | ||||
|         /// <param name="homeLookAtX">Home region 'look at' vector</param> | ||||
|         /// <param name="homeLookAtY">Home region 'look at' vector</param> | ||||
|         /// <param name="homeLookAtZ">Home region 'look at' vector</param> | ||||
|         /// <param name="created">Account created (unix timestamp)</param> | ||||
|         /// <param name="lastlogin">Last login (unix timestamp)</param> | ||||
|         /// <param name="inventoryURI">Users inventory URI</param> | ||||
|         /// <param name="assetURI">Users asset URI</param> | ||||
|         /// <param name="canDoMask">I can do mask</param> | ||||
|         /// <param name="wantDoMask">I want to do mask</param> | ||||
|         /// <param name="aboutText">Profile text</param> | ||||
|         /// <param name="firstText">Firstlife text</param> | ||||
|         /// <param name="profileImage">UUID for profile image</param> | ||||
|         /// <param name="firstImage">UUID for firstlife image</param> | ||||
|         /// <returns>Success?</returns> | ||||
|         private bool InsertUserRow(LLUUID uuid, string username, string lastname, string passwordHash, | ||||
|                                   string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ, | ||||
|                                   float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, | ||||
|                                   string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, | ||||
|                                   string aboutText, string firstText, | ||||
|                                   LLUUID profileImage, LLUUID firstImage, LLUUID webLoginKey) | ||||
|         { | ||||
|             string sql = "INSERT INTO "+m_usersTableName; | ||||
|             sql += " ([UUID], [username], [lastname], [passwordHash], [passwordSalt], [homeRegion], "; | ||||
|             sql += | ||||
|                 "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], "; | ||||
|             sql += | ||||
|                 "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], "; | ||||
|             sql += "[profileFirstText], [profileImage], [profileFirstImage], [webLoginKey]) VALUES "; | ||||
| 
 | ||||
|             sql += "(@UUID, @username, @lastname, @passwordHash, @passwordSalt, @homeRegion, "; | ||||
|             sql += | ||||
|                 "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, "; | ||||
|             sql += | ||||
|                 "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, "; | ||||
|             sql += "@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey);"; | ||||
| 
 | ||||
|             Dictionary<string, string> parameters = new Dictionary<string, string>(); | ||||
|             parameters["UUID"] = uuid.ToString(); | ||||
|             parameters["username"] = username.ToString(); | ||||
|             parameters["lastname"] = lastname.ToString(); | ||||
|             parameters["passwordHash"] = passwordHash.ToString(); | ||||
|             parameters["passwordSalt"] = passwordSalt.ToString(); | ||||
|             parameters["homeRegion"] = homeRegion.ToString(); | ||||
|             parameters["homeLocationX"] = homeLocX.ToString(); | ||||
|             parameters["homeLocationY"] = homeLocY.ToString(); | ||||
|             parameters["homeLocationZ"] = homeLocZ.ToString(); | ||||
|             parameters["homeLookAtX"] = homeLookAtX.ToString(); | ||||
|             parameters["homeLookAtY"] = homeLookAtY.ToString(); | ||||
|             parameters["homeLookAtZ"] = homeLookAtZ.ToString(); | ||||
|             parameters["created"] = created.ToString(); | ||||
|             parameters["lastLogin"] = lastlogin.ToString(); | ||||
|             parameters["userInventoryURI"] = String.Empty; | ||||
|             parameters["userAssetURI"] = String.Empty; | ||||
|             parameters["profileCanDoMask"] = "0"; | ||||
|             parameters["profileWantDoMask"] = "0"; | ||||
|             parameters["profileAboutText"] = String.Empty; | ||||
|             parameters["profileFirstText"] = String.Empty; | ||||
|             parameters["profileImage"] = LLUUID.Zero.ToString(); | ||||
|             parameters["profileFirstImage"] = LLUUID.Zero.ToString(); | ||||
|             parameters["webLoginKey"] = LLUUID.Random().ToString(); | ||||
| 
 | ||||
|             bool returnval = false; | ||||
| 
 | ||||
|             try | ||||
|             { | ||||
|                 IDbCommand result = database.Query(sql, parameters); | ||||
| 
 | ||||
|                 if (result.ExecuteNonQuery() == 1) | ||||
|                     returnval = true; | ||||
| 
 | ||||
|                 result.Dispose(); | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             return returnval; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Creates a new agent | ||||
|         /// </summary> | ||||
|         /// <param name="agent">The agent to create</param> | ||||
|         public void AddNewUserAgent(UserAgentData agent) | ||||
|         { | ||||
|             // Do nothing. | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         public bool UpdateUserProfile(UserProfileData user) | ||||
|         { | ||||
|             SqlCommand command = new SqlCommand("UPDATE " + m_usersTableName + " set UUID = @uuid, " + | ||||
|                                                 "username = @username, " + | ||||
|                                                 "lastname = @lastname," + | ||||
|                                                 "passwordHash = @passwordHash," + | ||||
|                                                 "passwordSalt = @passwordSalt," + | ||||
|                                                 "homeRegion = @homeRegion," + | ||||
|                                                 "homeLocationX = @homeLocationX," + | ||||
|                                                 "homeLocationY = @homeLocationY," + | ||||
|                                                 "homeLocationZ = @homeLocationZ," + | ||||
|                                                 "homeLookAtX = @homeLookAtX," + | ||||
|                                                 "homeLookAtY = @homeLookAtY," + | ||||
|                                                 "homeLookAtZ = @homeLookAtZ," + | ||||
|                                                 "created = @created," + | ||||
|                                                 "lastLogin = @lastLogin," + | ||||
|                                                 "userInventoryURI = @userInventoryURI," + | ||||
|                                                 "userAssetURI = @userAssetURI," + | ||||
|                                                 "profileCanDoMask = @profileCanDoMask," + | ||||
|                                                 "profileWantDoMask = @profileWantDoMask," + | ||||
|                                                 "profileAboutText = @profileAboutText," + | ||||
|                                                 "profileFirstText = @profileFirstText," + | ||||
|                                                 "profileImage = @profileImage," + | ||||
|                                                 "profileFirstImage = @profileFirstImage, " + | ||||
|                                                 "webLoginKey = @webLoginKey  where " + | ||||
|                                                 "UUID = @keyUUUID;", database.getConnection()); | ||||
|             SqlParameter param1 = new SqlParameter("@uuid", user.UUID.ToString()); | ||||
|             SqlParameter param2 = new SqlParameter("@username", user.username); | ||||
|             SqlParameter param3 = new SqlParameter("@lastname", user.surname); | ||||
|             SqlParameter param4 = new SqlParameter("@passwordHash", user.passwordHash); | ||||
|             SqlParameter param5 = new SqlParameter("@passwordSalt", user.passwordSalt); | ||||
|             SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.homeRegion)); | ||||
|             SqlParameter param7 = new SqlParameter("@homeLocationX", user.homeLocation.X); | ||||
|             SqlParameter param8 = new SqlParameter("@homeLocationY", user.homeLocation.Y); | ||||
|             SqlParameter param9 = new SqlParameter("@homeLocationZ", user.homeLocation.Y); | ||||
|             SqlParameter param10 = new SqlParameter("@homeLookAtX", user.homeLookAt.X); | ||||
|             SqlParameter param11 = new SqlParameter("@homeLookAtY", user.homeLookAt.Y); | ||||
|             SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.homeLookAt.Z); | ||||
|             SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.created)); | ||||
|             SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.lastLogin)); | ||||
|             SqlParameter param15 = new SqlParameter("@userInventoryURI", user.userInventoryURI); | ||||
|             SqlParameter param16 = new SqlParameter("@userAssetURI", user.userAssetURI); | ||||
|             SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.profileCanDoMask)); | ||||
|             SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask)); | ||||
|             SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText); | ||||
|             SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText); | ||||
|             SqlParameter param21 = new SqlParameter("@profileImage", LLUUID.Zero.ToString()); | ||||
|             SqlParameter param22 = new SqlParameter("@profileFirstImage", LLUUID.Zero.ToString()); | ||||
|             SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToString()); | ||||
|             SqlParameter param24 = new SqlParameter("@webLoginKey", user.webLoginKey.UUID.ToString()); | ||||
|             command.Parameters.Add(param1); | ||||
|             command.Parameters.Add(param2); | ||||
|             command.Parameters.Add(param3); | ||||
|             command.Parameters.Add(param4); | ||||
|             command.Parameters.Add(param5); | ||||
|             command.Parameters.Add(param6); | ||||
|             command.Parameters.Add(param7); | ||||
|             command.Parameters.Add(param8); | ||||
|             command.Parameters.Add(param9); | ||||
|             command.Parameters.Add(param10); | ||||
|             command.Parameters.Add(param11); | ||||
|             command.Parameters.Add(param12); | ||||
|             command.Parameters.Add(param13); | ||||
|             command.Parameters.Add(param14); | ||||
|             command.Parameters.Add(param15); | ||||
|             command.Parameters.Add(param16); | ||||
|             command.Parameters.Add(param17); | ||||
|             command.Parameters.Add(param18); | ||||
|             command.Parameters.Add(param19); | ||||
|             command.Parameters.Add(param20); | ||||
|             command.Parameters.Add(param21); | ||||
|             command.Parameters.Add(param22); | ||||
|             command.Parameters.Add(param23); | ||||
|             command.Parameters.Add(param24); | ||||
|             try | ||||
|             { | ||||
|                 int affected = command.ExecuteNonQuery(); | ||||
|                 if (affected != 0) | ||||
|                 { | ||||
|                     return true; | ||||
|                 } | ||||
|                 else | ||||
|                 { | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception e) | ||||
|             { | ||||
|                 m_log.Error(e.ToString()); | ||||
|             } | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Performs a money transfer request between two accounts | ||||
|         /// </summary> | ||||
|         /// <param name="from">The senders account ID</param> | ||||
|         /// <param name="to">The receivers account ID</param> | ||||
|         /// <param name="amount">The amount to transfer</param> | ||||
|         /// <returns>Success?</returns> | ||||
|         public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount) | ||||
|         { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Performs an inventory transfer request between two accounts | ||||
|         /// </summary> | ||||
|         /// <remarks>TODO: Move to inventory server</remarks> | ||||
|         /// <param name="from">The senders account ID</param> | ||||
|         /// <param name="to">The receivers account ID</param> | ||||
|         /// <param name="item">The item to transfer</param> | ||||
|         /// <returns>Success?</returns> | ||||
|         public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item) | ||||
|         { | ||||
|             return false; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database provider name | ||||
|         /// </summary> | ||||
|         /// <returns>Provider name</returns> | ||||
|         public string getName() | ||||
|         { | ||||
|             return "MSSQL Userdata Interface"; | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Database provider version | ||||
|         /// </summary> | ||||
|         /// <returns>provider version</returns> | ||||
|         public string GetVersion() | ||||
|         { | ||||
|             return database.getVersion(); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Not implemented | ||||
|         /// </summary> | ||||
|         /// <param name="query"></param> | ||||
|         public void runQuery(string query) | ||||
|         { | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -0,0 +1,66 @@ | |||
| /* | ||||
| * 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.Reflection; | ||||
| using System.Runtime.InteropServices; | ||||
| 
 | ||||
| // General Information about an assembly is controlled through the following  | ||||
| // set of attributes. Change these attribute values to modify the information | ||||
| // associated with an assembly. | ||||
| 
 | ||||
| [assembly : AssemblyTitle("OpenSim.Framework.Data.MSSQL")] | ||||
| [assembly : AssemblyDescription("")] | ||||
| [assembly : AssemblyConfiguration("")] | ||||
| [assembly : AssemblyCompany("")] | ||||
| [assembly : AssemblyProduct("OpenSim.Framework.Data.MSSQL")] | ||||
| [assembly : AssemblyCopyright("Copyright © OpenSimulator.org Developers 2007-2008")] | ||||
| [assembly : AssemblyTrademark("")] | ||||
| [assembly : AssemblyCulture("")] | ||||
| 
 | ||||
| // Setting ComVisible to false makes the types in this assembly not visible  | ||||
| // to COM components.  If you need to access a type in this assembly from  | ||||
| // COM, set the ComVisible attribute to true on that type. | ||||
| 
 | ||||
| [assembly : ComVisible(false)] | ||||
| 
 | ||||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||||
| 
 | ||||
| [assembly : Guid("0e1c1ca4-2cf2-4315-b0e7-432c02feea8a")] | ||||
| 
 | ||||
| // Version information for an assembly consists of the following four values: | ||||
| // | ||||
| //      Major Version | ||||
| //      Minor Version  | ||||
| //      Build Number | ||||
| //      Revision | ||||
| // | ||||
| // You can specify all the values or you can default the Revision and Build Numbers  | ||||
| // by using the '*' as shown below: | ||||
| 
 | ||||
| [assembly : AssemblyVersion("1.0.0.0")] | ||||
| [assembly : AssemblyFileVersion("1.0.0.0")] | ||||
|  | @ -0,0 +1,19 @@ | |||
| SET ANSI_NULLS ON | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| SET ANSI_PADDING ON | ||||
| CREATE TABLE [assets] ( | ||||
|   [id] [varchar](36) NOT NULL, | ||||
|   [name] [varchar](64) NOT NULL, | ||||
|   [description] [varchar](64) NOT NULL, | ||||
|   [assetType] [tinyint] NOT NULL, | ||||
|   [invType] [tinyint] NOT NULL, | ||||
|   [local] [tinyint] NOT NULL, | ||||
|   [temporary] [tinyint] NOT NULL, | ||||
|   [data] [image] NOT NULL, | ||||
| PRIMARY KEY CLUSTERED  | ||||
| ( | ||||
| 	[id] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
|  | @ -0,0 +1,27 @@ | |||
| SET ANSI_NULLS ON | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| SET ANSI_PADDING ON | ||||
| CREATE TABLE [inventoryfolders] ( | ||||
|   [folderID] [varchar](36) NOT NULL default '', | ||||
|   [agentID] [varchar](36) default NULL, | ||||
|   [parentFolderID] [varchar](36) default NULL, | ||||
|   [folderName] [varchar](64) default NULL, | ||||
|   [type] [smallint] NOT NULL default 0, | ||||
|   [version] [int] NOT NULL default 0,   | ||||
|   PRIMARY KEY CLUSTERED | ||||
| ( | ||||
| 	[folderID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [owner] ON [inventoryfolders] | ||||
| ( | ||||
| 	[agentID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [parent] ON [inventoryfolders] | ||||
| ( | ||||
| 	[parentFolderID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
|  | @ -0,0 +1,39 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [inventoryitems] ( | ||||
|   [inventoryID] [varchar](36) NOT NULL default '', | ||||
|   [assetID] [varchar](36) default NULL, | ||||
|   [assetType] [int] default NULL, | ||||
|   [parentFolderID] [varchar](36) default NULL, | ||||
|   [avatarID] [varchar](36) default NULL, | ||||
|   [inventoryName] [varchar](64) default NULL, | ||||
|   [inventoryDescription] [varchar](64) default NULL, | ||||
|   [inventoryNextPermissions] [int] default NULL, | ||||
|   [inventoryCurrentPermissions] [int] default NULL, | ||||
|   [invType] [int] default NULL, | ||||
|   [creatorID] [varchar](36) default NULL, | ||||
|   [inventoryBasePermissions] [int] NOT NULL default 0, | ||||
|   [inventoryEveryOnePermissions] [int] NOT NULL default 0,  | ||||
|   PRIMARY KEY CLUSTERED | ||||
| ( | ||||
| 	[inventoryID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [owner] ON [inventoryitems] | ||||
| ( | ||||
| 	[avatarID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [folder] ON [inventoryitems] | ||||
| ( | ||||
| 	[parentFolderID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
| 
 | ||||
|  | @ -0,0 +1,14 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [dbo].[userfriends]( | ||||
| [ownerID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL, | ||||
| [friendID] [varchar](50) COLLATE Latin1_General_CI_AS NOT NULL, | ||||
| [friendPerms] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, | ||||
| [datetimestamp] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
|  | @ -0,0 +1,37 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [agents] ( | ||||
|   [UUID] [varchar](36) NOT NULL, | ||||
|   [sessionID] [varchar](36) NOT NULL, | ||||
|   [secureSessionID] [varchar](36) NOT NULL, | ||||
|   [agentIP] [varchar](16) NOT NULL, | ||||
|   [agentPort] [int] NOT NULL, | ||||
|   [agentOnline] [tinyint] NOT NULL, | ||||
|   [loginTime] [int] NOT NULL, | ||||
|   [logoutTime] [int] NOT NULL, | ||||
|   [currentRegion] [varchar](36) NOT NULL, | ||||
|   [currentHandle] [bigint] NOT NULL, | ||||
|   [currentPos] [varchar](64) NOT NULL, | ||||
|   PRIMARY KEY CLUSTERED | ||||
| ( | ||||
| 	[UUID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [session] ON [agents] | ||||
| ( | ||||
| 	[sessionID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [ssession] ON [agents] | ||||
| ( | ||||
| 	[secureSessionID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
| 
 | ||||
|  | @ -0,0 +1,20 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [logs] ( | ||||
|   [logID] [int] NOT NULL, | ||||
|   [target] [varchar](36) default NULL, | ||||
|   [server] [varchar](64) default NULL, | ||||
|   [method] [varchar](64) default NULL, | ||||
|   [arguments] [varchar](255) default NULL, | ||||
|   [priority] [int] default NULL, | ||||
|   [message] [ntext], | ||||
|   PRIMARY KEY CLUSTERED | ||||
| ( | ||||
| 	[logID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
|  | @ -0,0 +1,40 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [dbo].[regions]( | ||||
|  [regionHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionName] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [uuid] [varchar](255) COLLATE Latin1_General_CI_AS NOT NULL, | ||||
|  [regionRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionSecret] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionDataURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [serverIP] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [serverPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [serverURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [locX] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [locY] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [locZ] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [eastOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [westOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [southOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [northOverrideHandle] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionAssetURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionAssetRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionAssetSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionUserURI] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionUserRecvKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionUserSendKey] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [regionMapTexture] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [serverHttpPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
|  [serverRemotingPort] [varchar](255) COLLATE Latin1_General_CI_AS NULL, | ||||
| PRIMARY KEY CLUSTERED  | ||||
| ( | ||||
|  [uuid] ASC | ||||
| )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| SET ANSI_PADDING OFF | ||||
|  | @ -0,0 +1,42 @@ | |||
| SET ANSI_NULLS ON | ||||
| 
 | ||||
| SET QUOTED_IDENTIFIER ON | ||||
| 
 | ||||
| SET ANSI_PADDING ON | ||||
| 
 | ||||
| CREATE TABLE [users] ( | ||||
|   [UUID] [varchar](36) NOT NULL default '', | ||||
|   [username] [varchar](32) NOT NULL, | ||||
|   [lastname] [varchar](32) NOT NULL, | ||||
|   [passwordHash] [varchar](32) NOT NULL, | ||||
|   [passwordSalt] [varchar](32) NOT NULL, | ||||
|   [homeRegion] [bigint] default NULL, | ||||
|   [homeLocationX] [float] default NULL, | ||||
|   [homeLocationY] [float] default NULL, | ||||
|   [homeLocationZ] [float] default NULL, | ||||
|   [homeLookAtX] [float] default NULL, | ||||
|   [homeLookAtY] [float] default NULL, | ||||
|   [homeLookAtZ] [float] default NULL, | ||||
|   [created] [int] NOT NULL, | ||||
|   [lastLogin] [int] NOT NULL, | ||||
|   [userInventoryURI] [varchar](255) default NULL, | ||||
|   [userAssetURI] [varchar](255) default NULL, | ||||
|   [profileCanDoMask] [int] default NULL, | ||||
|   [profileWantDoMask] [int] default NULL, | ||||
|   [profileAboutText] [ntext], | ||||
|   [profileFirstText] [ntext], | ||||
|   [profileImage] [varchar](36) default NULL, | ||||
|   [profileFirstImage] [varchar](36) default NULL, | ||||
|   [webLoginKey] [varchar](36) default NULL, | ||||
|   PRIMARY KEY CLUSTERED | ||||
| ( | ||||
| 	[UUID] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
| ) ON [PRIMARY] | ||||
| 
 | ||||
| 
 | ||||
| CREATE NONCLUSTERED INDEX [usernames] ON [users] | ||||
| ( | ||||
| 	[username] ASC, | ||||
| 	[lastname] ASC | ||||
| )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] | ||||
|  | @ -0,0 +1,199 @@ | |||
| /* | ||||
| * 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.Generic; | ||||
| using System.Data; | ||||
| using libsecondlife; | ||||
| using MySql.Data.MySqlClient; | ||||
| using OpenSim.Framework.Console; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MySQL | ||||
| { | ||||
|     internal class MySQLAssetData : IAssetProvider | ||||
|     { | ||||
|         private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||||
| 
 | ||||
|         private MySQLManager _dbConnection; | ||||
| 
 | ||||
|         #region IAssetProvider Members | ||||
| 
 | ||||
|         private void UpgradeAssetsTable(string oldVersion) | ||||
|         { | ||||
|             // null as the version, indicates that the table didn't exist | ||||
|             if (oldVersion == null) | ||||
|             { | ||||
|                 m_log.Info("[ASSETS]: Creating new database tables"); | ||||
|                 _dbConnection.ExecuteResourceSql("CreateAssetsTable.sql"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Ensure that the assets related tables exists and are at the latest version | ||||
|         /// </summary> | ||||
|         private void TestTables() | ||||
|         { | ||||
|             Dictionary<string, string> tableList = new Dictionary<string, string>(); | ||||
| 
 | ||||
|             tableList["assets"] = null; | ||||
|             _dbConnection.GetTableVersion(tableList); | ||||
| 
 | ||||
|             UpgradeAssetsTable(tableList["assets"]); | ||||
|         } | ||||
| 
 | ||||
|         public AssetBase FetchAsset(LLUUID assetID) | ||||
|         { | ||||
|             AssetBase asset = null; | ||||
|             lock (_dbConnection) | ||||
|             { | ||||
|                 MySqlCommand cmd = | ||||
|                     new MySqlCommand( | ||||
|                         "SELECT name, description, assetType, invType, local, temporary, data FROM assets WHERE id=?id", | ||||
|                         _dbConnection.Connection); | ||||
|                 MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); | ||||
|                 p.Value = assetID.GetBytes(); | ||||
|                  | ||||
|                 try | ||||
|                 { | ||||
|                     using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||||
|                     { | ||||
|                         if (dbReader.Read()) | ||||
|                         { | ||||
|                             asset = new AssetBase(); | ||||
|                             asset.Data = (byte[]) dbReader["data"]; | ||||
|                             asset.Description = (string) dbReader["description"]; | ||||
|                             asset.FullID = assetID; | ||||
|                             asset.InvType = (sbyte) dbReader["invType"]; | ||||
|                             asset.Local = ((sbyte) dbReader["local"]) != 0 ? true : false; | ||||
|                             asset.Name = (string) dbReader["name"]; | ||||
|                             asset.Type = (sbyte) dbReader["assetType"]; | ||||
|                         } | ||||
|                         dbReader.Close(); | ||||
|                         cmd.Dispose(); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.ErrorFormat( | ||||
|                         "[ASSETS]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString() | ||||
|                         + Environment.NewLine + "Attempting reconnection", assetID); | ||||
|                     _dbConnection.Reconnect(); | ||||
|                 } | ||||
|             } | ||||
|             return asset; | ||||
|         } | ||||
| 
 | ||||
|         public void CreateAsset(AssetBase asset) | ||||
|         {             | ||||
|             lock (_dbConnection) | ||||
|             { | ||||
|                 MySqlCommand cmd = | ||||
|                     new MySqlCommand( | ||||
|                         "REPLACE INTO assets(id, name, description, assetType, invType, local, temporary, data)" + | ||||
|                         "VALUES(?id, ?name, ?description, ?assetType, ?invType, ?local, ?temporary, ?data)", | ||||
|                         _dbConnection.Connection); | ||||
|              | ||||
|                 // need to ensure we dispose | ||||
|                 try | ||||
|                 {             | ||||
|                     using (cmd) | ||||
|                     { | ||||
|                         MySqlParameter p = cmd.Parameters.Add("?id", MySqlDbType.Binary, 16); | ||||
|                         p.Value = asset.FullID.GetBytes(); | ||||
|                         cmd.Parameters.AddWithValue("?name", asset.Name); | ||||
|                         cmd.Parameters.AddWithValue("?description", asset.Description); | ||||
|                         cmd.Parameters.AddWithValue("?assetType", asset.Type); | ||||
|                         cmd.Parameters.AddWithValue("?invType", asset.InvType); | ||||
|                         cmd.Parameters.AddWithValue("?local", asset.Local); | ||||
|                         cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | ||||
|                         cmd.Parameters.AddWithValue("?data", asset.Data); | ||||
|                         cmd.ExecuteNonQuery(); | ||||
|                         cmd.Dispose(); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (Exception e) | ||||
|                 { | ||||
|                     m_log.ErrorFormat( | ||||
|                         "[ASSETS]: " + | ||||
|                         "MySql failure creating asset {0} with name {1}" + Environment.NewLine + e.ToString() | ||||
|                         + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name); | ||||
|                     _dbConnection.Reconnect(); | ||||
|                 }    | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         public void UpdateAsset(AssetBase asset) | ||||
|         { | ||||
|             CreateAsset(asset); | ||||
|         } | ||||
| 
 | ||||
|         public bool ExistsAsset(LLUUID uuid) | ||||
|         { | ||||
|             throw new Exception("The method or operation is not implemented."); | ||||
|         } | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// All writes are immediately commited to the database, so this is a no-op | ||||
|         /// </summary> | ||||
|         public void CommitAssets() | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
| 
 | ||||
|         #region IPlugin Members | ||||
| 
 | ||||
|         public void Initialise() | ||||
|         { | ||||
|             IniFile GridDataMySqlFile = new IniFile("mysql_connection.ini"); | ||||
|             string hostname = GridDataMySqlFile.ParseFileReadValue("hostname"); | ||||
|             string database = GridDataMySqlFile.ParseFileReadValue("database"); | ||||
|             string username = GridDataMySqlFile.ParseFileReadValue("username"); | ||||
|             string password = GridDataMySqlFile.ParseFileReadValue("password"); | ||||
|             string pooling = GridDataMySqlFile.ParseFileReadValue("pooling"); | ||||
|             string port = GridDataMySqlFile.ParseFileReadValue("port"); | ||||
| 
 | ||||
|             _dbConnection = new MySQLManager(hostname, database, username, password, pooling, port); | ||||
| 
 | ||||
|             TestTables(); | ||||
|         } | ||||
| 
 | ||||
|         public string Version | ||||
|         { | ||||
|             get { return _dbConnection.getVersion(); } | ||||
|         } | ||||
| 
 | ||||
|         public string Name | ||||
|         { | ||||
|             get { return "MySQL Asset storage engine"; } | ||||
|         } | ||||
| 
 | ||||
|         #endregion | ||||
|     } | ||||
| } | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -0,0 +1,54 @@ | |||
| /* | ||||
| * 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.Data.Common; | ||||
| using MySql.Data.MySqlClient; | ||||
|  //using TribalMedia.Framework.Data; | ||||
| 
 | ||||
| namespace OpenSim.Framework.Data.MySQL | ||||
| { | ||||
|     /* | ||||
|     public class MySQLDatabaseMapper : OpenSimDatabaseConnector | ||||
|     { | ||||
|         public MySQLDatabaseMapper(string connectionString) | ||||
|             : base(connectionString) | ||||
|         { | ||||
|         } | ||||
| 
 | ||||
|         public override DbConnection GetNewConnection() | ||||
|         { | ||||
|             MySqlConnection connection = new MySqlConnection(m_connectionString); | ||||
|             return connection; | ||||
|         } | ||||
| 
 | ||||
|         public override string CreateParamName(string fieldName) | ||||
|         { | ||||
|             return "?" + fieldName; | ||||
|         } | ||||
|     }*/ | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
		Reference in New Issue
	
	 mikkopa
						mikkopa