aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.AssetServer
diff options
context:
space:
mode:
authorgareth2007-04-29 23:58:57 +0000
committergareth2007-04-29 23:58:57 +0000
commit328c9ccb24053b6e8d9d4bba82cec2b433db7bcd (patch)
tree1a9c74e69d3d244b0c58a786296d743aef2572e6 /OpenGridServices.AssetServer
parentBugfixes (diff)
downloadopensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.zip
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.gz
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.bz2
opensim-SC_OLD-328c9ccb24053b6e8d9d4bba82cec2b433db7bcd.tar.xz
Copied gridserver ready to convert to asset server
I'M THAT NUTS!!!!!!!!
Diffstat (limited to '')
-rw-r--r--OpenGridServices.AssetServer/Main.cs213
-rw-r--r--OpenGridServices.AssetServer/OpenGridServices.GridServer.csproj126
-rw-r--r--OpenGridServices.AssetServer/OpenGridServices.GridServer.exe.build49
-rw-r--r--OpenGridServices.AssetServer/Properties/AssemblyInfo.cs33
-rw-r--r--OpenGridServices.AssetServer/SimProfiles.cs328
5 files changed, 749 insertions, 0 deletions
diff --git a/OpenGridServices.AssetServer/Main.cs b/OpenGridServices.AssetServer/Main.cs
new file mode 100644
index 0000000..69cba9c
--- /dev/null
+++ b/OpenGridServices.AssetServer/Main.cs
@@ -0,0 +1,213 @@
1/*
2Copyright (c) OpenSim project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.IO;
32using System.Text;
33using System.Timers;
34using System.Net;
35using System.Reflection;
36using libsecondlife;
37using OpenSim.Framework;
38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Console;
40using OpenSim.Framework.Interfaces;
41using OpenSim.Servers;
42
43namespace OpenGridServices.GridServer
44{
45 /// <summary>
46 /// </summary>
47 public class OpenGrid_Main : BaseServer, conscmd_callback
48 {
49 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
50 public GridConfig Cfg;
51
52 public static OpenGrid_Main thegrid;
53
54 //public LLUUID highestUUID;
55
56 private SimProfileManager m_simProfileManager;
57
58 private ConsoleBase m_console;
59
60 [STAThread]
61 public static void Main(string[] args)
62 {
63 Console.WriteLine("Starting...\n");
64
65 thegrid = new OpenGrid_Main();
66 thegrid.Startup();
67
68 thegrid.Work();
69 }
70
71 private void Work()
72 {
73 m_console.WriteLine("\nEnter help for a list of commands\n");
74
75 while (true)
76 {
77 m_console.MainConsolePrompt();
78 }
79 }
80
81 private OpenGrid_Main()
82 {
83 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false);
84 MainConsole.Instance = m_console;
85 }
86
87 public void Startup()
88 {
89 m_console.WriteLine("Main.cs:Startup() - Loading configuration");
90 Cfg = this.LoadConfigDll(this.ConfigDll);
91 Cfg.InitConfig();
92
93 m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database");
94 m_simProfileManager = new SimProfileManager( this );
95 m_simProfileManager.LoadProfiles();
96
97 m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
98 BaseHttpServer httpServer = new BaseHttpServer(8001);
99
100 httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod);
101
102 httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod);
103 httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod);
104 httpServer.AddRestHandler("GET", "/regions/", m_simProfileManager.RestGetRegionMethod);
105 httpServer.AddRestHandler("POST", "/regions/", m_simProfileManager.RestSetRegionMethod);
106
107
108 // lbsa71 : This code snippet taken from old http server.
109 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
110 // case "regions":
111 //// DIRTY HACK ALERT
112 //Console.WriteLine("/regions/ accessed");
113 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
114 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
115 //break;
116
117 // lbsa71 : I guess these were never used?
118 //Listener.Prefixes.Add("http://+:8001/gods/");
119 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
120 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
121
122 httpServer.Start();
123
124 m_console.WriteLine("Main.cs:Startup() - Starting sim status checker");
125
126 Timer simCheckTimer = new Timer( 300000 ); // 5 minutes
127 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
128 simCheckTimer.Enabled = true;
129 }
130
131 private GridConfig LoadConfigDll(string dllName)
132 {
133 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
134 GridConfig config = null;
135
136 foreach (Type pluginType in pluginAssembly.GetTypes())
137 {
138 if (pluginType.IsPublic)
139 {
140 if (!pluginType.IsAbstract)
141 {
142 Type typeInterface = pluginType.GetInterface("IGridConfig", true);
143
144 if (typeInterface != null)
145 {
146 IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
147 config = plug.GetConfigObject();
148 break;
149 }
150
151 typeInterface = null;
152 }
153 }
154 }
155 pluginAssembly = null;
156 return config;
157 }
158
159 public void CheckSims(object sender, ElapsedEventArgs e)
160 {
161 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
162 {
163 string SimResponse = "";
164 try
165 {
166 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
167 CheckSim.Method = "GET";
168 CheckSim.ContentType = "text/plaintext";
169 CheckSim.ContentLength = 0;
170
171 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
172 stOut.Write("");
173 stOut.Close();
174
175 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
176 SimResponse = stIn.ReadToEnd();
177 stIn.Close();
178 }
179 catch
180 {
181 }
182
183 if (SimResponse == "OK")
184 {
185 m_simProfileManager.SimProfiles[sim.UUID].online = true;
186 }
187 else
188 {
189 m_simProfileManager.SimProfiles[sim.UUID].online = false;
190 }
191 }
192 }
193
194 public void RunCmd(string cmd, string[] cmdparams)
195 {
196 switch (cmd)
197 {
198 case "help":
199 m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)");
200 break;
201
202 case "shutdown":
203 m_console.Close();
204 Environment.Exit(0);
205 break;
206 }
207 }
208
209 public void Show(string ShowWhat)
210 {
211 }
212 }
213}
diff --git a/OpenGridServices.AssetServer/OpenGridServices.GridServer.csproj b/OpenGridServices.AssetServer/OpenGridServices.GridServer.csproj
new file mode 100644
index 0000000..9b8cc87
--- /dev/null
+++ b/OpenGridServices.AssetServer/OpenGridServices.GridServer.csproj
@@ -0,0 +1,126 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <ProjectType>Local</ProjectType>
4 <ProductVersion>8.0.50727</ProductVersion>
5 <SchemaVersion>2.0</SchemaVersion>
6 <ProjectGuid>{21BFC8E2-0000-0000-0000-000000000000}</ProjectGuid>
7 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
8 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
9 <ApplicationIcon></ApplicationIcon>
10 <AssemblyKeyContainerName>
11 </AssemblyKeyContainerName>
12 <AssemblyName>OpenGridServices.GridServer</AssemblyName>
13 <DefaultClientScript>JScript</DefaultClientScript>
14 <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
15 <DefaultTargetSchema>IE50</DefaultTargetSchema>
16 <DelaySign>false</DelaySign>
17 <OutputType>Exe</OutputType>
18 <AppDesignerFolder></AppDesignerFolder>
19 <RootNamespace>OpenGridServices.GridServer</RootNamespace>
20 <StartupObject></StartupObject>
21 <FileUpgradeFlags>
22 </FileUpgradeFlags>
23 </PropertyGroup>
24 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
25 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
26 <BaseAddress>285212672</BaseAddress>
27 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
28 <ConfigurationOverrideFile>
29 </ConfigurationOverrideFile>
30 <DefineConstants>TRACE;DEBUG</DefineConstants>
31 <DocumentationFile></DocumentationFile>
32 <DebugSymbols>True</DebugSymbols>
33 <FileAlignment>4096</FileAlignment>
34 <Optimize>False</Optimize>
35 <OutputPath>..\bin\</OutputPath>
36 <RegisterForComInterop>False</RegisterForComInterop>
37 <RemoveIntegerChecks>False</RemoveIntegerChecks>
38 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
39 <WarningLevel>4</WarningLevel>
40 <NoWarn></NoWarn>
41 </PropertyGroup>
42 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
43 <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
44 <BaseAddress>285212672</BaseAddress>
45 <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
46 <ConfigurationOverrideFile>
47 </ConfigurationOverrideFile>
48 <DefineConstants>TRACE</DefineConstants>
49 <DocumentationFile></DocumentationFile>
50 <DebugSymbols>False</DebugSymbols>
51 <FileAlignment>4096</FileAlignment>
52 <Optimize>True</Optimize>
53 <OutputPath>..\bin\</OutputPath>
54 <RegisterForComInterop>False</RegisterForComInterop>
55 <RemoveIntegerChecks>False</RemoveIntegerChecks>
56 <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
57 <WarningLevel>4</WarningLevel>
58 <NoWarn></NoWarn>
59 </PropertyGroup>
60 <ItemGroup>
61 <Reference Include="System" >
62 <HintPath>System.dll</HintPath>
63 <Private>False</Private>
64 </Reference>
65 <Reference Include="System.Data" >
66 <HintPath>System.Data.dll</HintPath>
67 <Private>False</Private>
68 </Reference>
69 <Reference Include="System.Xml" >
70 <HintPath>System.Xml.dll</HintPath>
71 <Private>False</Private>
72 </Reference>
73 <Reference Include="libsecondlife.dll" >
74 <HintPath>..\bin\libsecondlife.dll</HintPath>
75 <Private>False</Private>
76 </Reference>
77 <Reference Include="Db4objects.Db4o.dll" >
78 <HintPath>..\bin\Db4objects.Db4o.dll</HintPath>
79 <Private>False</Private>
80 </Reference>
81 </ItemGroup>
82 <ItemGroup>
83 <ProjectReference Include="..\OpenSim.Framework\OpenSim.Framework.csproj">
84 <Name>OpenSim.Framework</Name>
85 <Project>{8ACA2445-0000-0000-0000-000000000000}</Project>
86 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
87 <Private>False</Private>
88 </ProjectReference>
89 <ProjectReference Include="..\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj">
90 <Name>OpenSim.Framework.Console</Name>
91 <Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
92 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
93 <Private>False</Private>
94 </ProjectReference>
95 <ProjectReference Include="..\OpenSim.Servers\OpenSim.Servers.csproj">
96 <Name>OpenSim.Servers</Name>
97 <Project>{8BB20F0A-0000-0000-0000-000000000000}</Project>
98 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
99 <Private>False</Private>
100 </ProjectReference>
101 <ProjectReference Include="..\XmlRpcCS\XMLRPC.csproj">
102 <Name>XMLRPC</Name>
103 <Project>{8E81D43C-0000-0000-0000-000000000000}</Project>
104 <Package>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</Package>
105 <Private>False</Private>
106 </ProjectReference>
107 </ItemGroup>
108 <ItemGroup>
109 <Compile Include="Main.cs">
110 <SubType>Code</SubType>
111 </Compile>
112 <Compile Include="SimProfiles.cs">
113 <SubType>Code</SubType>
114 </Compile>
115 <Compile Include="Properties\AssemblyInfo.cs">
116 <SubType>Code</SubType>
117 </Compile>
118 </ItemGroup>
119 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
120 <PropertyGroup>
121 <PreBuildEvent>
122 </PreBuildEvent>
123 <PostBuildEvent>
124 </PostBuildEvent>
125 </PropertyGroup>
126</Project>
diff --git a/OpenGridServices.AssetServer/OpenGridServices.GridServer.exe.build b/OpenGridServices.AssetServer/OpenGridServices.GridServer.exe.build
new file mode 100644
index 0000000..6bef534
--- /dev/null
+++ b/OpenGridServices.AssetServer/OpenGridServices.GridServer.exe.build
@@ -0,0 +1,49 @@
1<?xml version="1.0" ?>
2<project name="OpenGridServices.GridServer" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="exe" debug="${build.debug}" unsafe="False" define="TRACE" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.exe">
11 <resources prefix="OpenGridServices.GridServer" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="Main.cs" />
15 <include name="SimProfiles.cs" />
16 <include name="Properties/AssemblyInfo.cs" />
17 </sources>
18 <references basedir="${project::get-base-directory()}">
19 <lib>
20 <include name="${project::get-base-directory()}" />
21 <include name="${project::get-base-directory()}/${build.dir}" />
22 </lib>
23 <include name="System.dll" />
24 <include name="System.Data.dll" />
25 <include name="System.Xml.dll" />
26 <include name="../bin/OpenSim.Framework.dll" />
27 <include name="../bin/OpenSim.Framework.Console.dll" />
28 <include name="../bin/OpenSim.Servers.dll" />
29 <include name="../bin/libsecondlife.dll" />
30 <include name="../bin/Db4objects.Db4o.dll" />
31 <include name="../bin/XMLRPC.dll" />
32 </references>
33 </csc>
34 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../bin/" />
35 <mkdir dir="${project::get-base-directory()}/../bin/"/>
36 <copy todir="${project::get-base-directory()}/../bin/">
37 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
38 <include name="*.dll"/>
39 <include name="*.exe"/>
40 </fileset>
41 </copy>
42 </target>
43 <target name="clean">
44 <delete dir="${bin.dir}" failonerror="false" />
45 <delete dir="${obj.dir}" failonerror="false" />
46 </target>
47 <target name="doc" description="Creates documentation.">
48 </target>
49</project>
diff --git a/OpenGridServices.AssetServer/Properties/AssemblyInfo.cs b/OpenGridServices.AssetServer/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..8471e6b
--- /dev/null
+++ b/OpenGridServices.AssetServer/Properties/AssemblyInfo.cs
@@ -0,0 +1,33 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OGS-GridServer")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("OGS-GridServer")]
13[assembly: AssemblyCopyright("Copyright © 2007")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("b541b244-3d1d-4625-9003-bc2a3a6a39a4")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32[assembly: AssemblyVersion("1.0.0.0")]
33[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenGridServices.AssetServer/SimProfiles.cs b/OpenGridServices.AssetServer/SimProfiles.cs
new file mode 100644
index 0000000..ae40133
--- /dev/null
+++ b/OpenGridServices.AssetServer/SimProfiles.cs
@@ -0,0 +1,328 @@
1/*
2Copyright (c) OpenGrid project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using System.Collections;
33using System.Collections.Generic;
34using libsecondlife;
35using OpenSim.Framework.Utilities;
36using OpenSim.Framework.Console;
37using OpenSim.Framework.Sims;
38using Db4objects.Db4o;
39using Nwc.XmlRpc;
40using System.Xml;
41
42namespace OpenGridServices.GridServer
43{
44 /// <summary>
45 /// </summary>
46 public class SimProfileManager
47 {
48
49 public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>();
50 private OpenGrid_Main m_gridManager;
51
52 public SimProfileManager(OpenGrid_Main gridManager)
53 {
54 m_gridManager = gridManager;
55 }
56
57 public void LoadProfiles()
58 { // should abstract this out
59 IObjectContainer db;
60 db = Db4oFactory.OpenFile("simprofiles.yap");
61 IObjectSet result = db.Get(typeof(SimProfileBase));
62 foreach (SimProfileBase simprof in result)
63 {
64 SimProfiles.Add(simprof.UUID, simprof);
65 }
66 MainConsole.Instance.WriteLine("SimProfiles.Cs:LoadProfiles() - Successfully loaded " + result.Count.ToString() + " from database");
67 db.Close();
68 }
69
70 public SimProfileBase GetProfileByHandle(ulong reqhandle)
71 {
72 foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys)
73 {
74 if (SimProfiles[UUID].regionhandle == reqhandle) return SimProfiles[UUID];
75 }
76 return null;
77 }
78
79 public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID)
80 {
81 foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys)
82 {
83 if (SimProfiles[UUID].UUID == ProfileLLUUID) return SimProfiles[UUID];
84 }
85 return null;
86 }
87
88 public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey)
89 {
90 SimProfileBase TheSim = GetProfileByHandle(regionhandle);
91 if (TheSim != null)
92 if (TheSim.recvkey == simrecvkey)
93 {
94 return true;
95 }
96 else
97 {
98 return false;
99 }
100 else return false;
101
102 }
103
104 public string GetXMLNeighbours(ulong reqhandle)
105 {
106 string response = "";
107 SimProfileBase central_region = GetProfileByHandle(reqhandle);
108 SimProfileBase neighbour;
109 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
110 {
111 if (GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)) != null)
112 {
113 neighbour = GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256));
114 response += "<neighbour>";
115 response += "<sim_ip>" + neighbour.sim_ip + "</sim_ip>";
116 response += "<sim_port>" + neighbour.sim_port.ToString() + "</sim_port>";
117 response += "<locx>" + neighbour.RegionLocX.ToString() + "</locx>";
118 response += "<locy>" + neighbour.RegionLocY.ToString() + "</locy>";
119 response += "<regionhandle>" + neighbour.regionhandle.ToString() + "</regionhandle>";
120 response += "</neighbour>";
121
122 }
123 }
124 return response;
125 }
126
127 public SimProfileBase CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey)
128 {
129 SimProfileBase newprofile = new SimProfileBase();
130 newprofile.regionname = regionname;
131 newprofile.sim_ip = sim_ip;
132 newprofile.sim_port = sim_port;
133 newprofile.RegionLocX = RegionLocX;
134 newprofile.RegionLocY = RegionLocY;
135 newprofile.caps_url = "http://" + sim_ip + ":9000/";
136 newprofile.sendkey = sendkey;
137 newprofile.recvkey = recvkey;
138 newprofile.regionhandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256));
139 newprofile.UUID = LLUUID.Random();
140 this.SimProfiles.Add(newprofile.UUID, newprofile);
141 return newprofile;
142 }
143
144 public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request)
145 {
146 XmlRpcResponse response = new XmlRpcResponse();
147 Hashtable responseData = new Hashtable();
148 response.Value = responseData;
149
150 SimProfileBase TheSim = null;
151 Hashtable requestData = (Hashtable)request.Params[0];
152
153 if (requestData.ContainsKey("UUID"))
154 {
155 TheSim = GetProfileByLLUUID(new LLUUID((string)requestData["UUID"]));
156 }
157 else if (requestData.ContainsKey("region_handle"))
158 {
159 TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"]));
160 }
161
162 if (TheSim == null)
163 {
164 responseData["error"] = "sim not found";
165 }
166 else
167 {
168
169 ArrayList SimNeighboursData = new ArrayList();
170
171 SimProfileBase neighbour;
172 Hashtable NeighbourBlock;
173 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
174 {
175 if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null)
176 {
177 neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256));
178
179 NeighbourBlock = new Hashtable();
180 NeighbourBlock["sim_ip"] = neighbour.sim_ip;
181 NeighbourBlock["sim_port"] = neighbour.sim_port.ToString();
182 NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString();
183 NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString();
184 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
185
186 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
187 }
188 }
189
190 responseData["UUID"] = TheSim.UUID.ToString();
191 responseData["region_locx"] = TheSim.RegionLocX.ToString();
192 responseData["region_locy"] = TheSim.RegionLocY.ToString();
193 responseData["regionname"] = TheSim.regionname;
194 responseData["estate_id"] = "1";
195 responseData["neighbours"] = SimNeighboursData;
196
197 responseData["sim_ip"] = TheSim.sim_ip;
198 responseData["sim_port"] = TheSim.sim_port.ToString();
199 responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer;
200 responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey;
201 responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey;
202 responseData["user_url"] = m_gridManager.Cfg.DefaultUserServer;
203 responseData["user_sendkey"] = m_gridManager.Cfg.UserSendKey;
204 responseData["user_recvkey"] = m_gridManager.Cfg.UserRecvKey;
205 responseData["authkey"] = m_gridManager.Cfg.SimSendKey;
206 }
207
208 return response;
209 }
210
211 public string RestSetSimMethod(string request, string path, string param)
212 {
213 Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
214 SimProfileBase TheSim;
215 TheSim = GetProfileByLLUUID(new LLUUID(param));
216 if ((TheSim) == null)
217 {
218 TheSim = new SimProfileBase();
219 LLUUID UUID = new LLUUID(param);
220 TheSim.UUID = UUID;
221 }
222
223 XmlDocument doc = new XmlDocument();
224 doc.LoadXml(request);
225 XmlNode rootnode = doc.FirstChild;
226 XmlNode authkeynode = rootnode.ChildNodes[0];
227 if (authkeynode.Name != "authkey")
228 {
229 return "ERROR! bad XML - expected authkey tag";
230 }
231
232 XmlNode simnode = rootnode.ChildNodes[1];
233 if (simnode.Name != "sim")
234 {
235 return "ERROR! bad XML - expected sim tag";
236 }
237
238 if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey)
239 {
240 return "ERROR! invalid key";
241 }
242 for (int i = 0; i < simnode.ChildNodes.Count; i++)
243 {
244 switch (simnode.ChildNodes[i].Name)
245 {
246 case "regionname":
247 TheSim.regionname = simnode.ChildNodes[i].InnerText;
248 break;
249
250 case "sim_ip":
251 TheSim.sim_ip = simnode.ChildNodes[i].InnerText;
252 break;
253
254 case "sim_port":
255 TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
256 break;
257
258 case "region_locx":
259 TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
260 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
261 break;
262
263 case "region_locy":
264 TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
265 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
266 break;
267 }
268 }
269
270 try
271 {
272 SimProfiles.Add(TheSim.UUID, TheSim);
273 IObjectContainer db;
274 db = Db4oFactory.OpenFile("simprofiles.yap");
275 db.Set(TheSim);
276 db.Close();
277 return "OK";
278 }
279 catch (Exception e)
280 {
281 return "ERROR! could not save to database!";
282 }
283
284 }
285
286 public string RestGetRegionMethod(string request, string path, string param)
287 {
288 SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param));
289 return RestGetSimMethod("", "/sims/", param);
290 }
291
292 public string RestSetRegionMethod(string request, string path, string param)
293 {
294 SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param));
295 return RestSetSimMethod("", "/sims/", param);
296 }
297
298 public string RestGetSimMethod(string request, string path, string param)
299 {
300 string respstring = String.Empty;
301
302 SimProfileBase TheSim;
303 LLUUID UUID = new LLUUID(param);
304 TheSim = GetProfileByLLUUID(UUID);
305
306 if (!(TheSim == null))
307 {
308 respstring = "<Root>";
309 respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>";
310 respstring += "<sim>";
311 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
312 respstring += "<regionname>" + TheSim.regionname + "</regionname>";
313 respstring += "<sim_ip>" + TheSim.sim_ip + "</sim_ip>";
314 respstring += "<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>";
315 respstring += "<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>";
316 respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
317 respstring += "<estate_id>1</estate_id>";
318 respstring += "</sim>";
319 respstring += "</Root>";
320 }
321
322 return respstring;
323 }
324
325 }
326
327
328}