From 328c9ccb24053b6e8d9d4bba82cec2b433db7bcd Mon Sep 17 00:00:00 2001 From: gareth Date: Sun, 29 Apr 2007 23:58:57 +0000 Subject: Copied gridserver ready to convert to asset server I'M THAT NUTS!!!!!!!! --- OpenGridServices.AssetServer/Main.cs | 213 +++++++++++++ .../OpenGridServices.GridServer.csproj | 126 ++++++++ .../OpenGridServices.GridServer.exe.build | 49 +++ .../Properties/AssemblyInfo.cs | 33 +++ OpenGridServices.AssetServer/SimProfiles.cs | 328 +++++++++++++++++++++ 5 files changed, 749 insertions(+) create mode 100644 OpenGridServices.AssetServer/Main.cs create mode 100644 OpenGridServices.AssetServer/OpenGridServices.GridServer.csproj create mode 100644 OpenGridServices.AssetServer/OpenGridServices.GridServer.exe.build create mode 100644 OpenGridServices.AssetServer/Properties/AssemblyInfo.cs create mode 100644 OpenGridServices.AssetServer/SimProfiles.cs (limited to 'OpenGridServices.AssetServer') 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 @@ +/* +Copyright (c) OpenSim project, http://osgrid.org/ + + +* All rights reserved. +* +* 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 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 ``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 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.Text; +using System.Timers; +using System.Net; +using System.Reflection; +using libsecondlife; +using OpenSim.Framework; +using OpenSim.Framework.Sims; +using OpenSim.Framework.Console; +using OpenSim.Framework.Interfaces; +using OpenSim.Servers; + +namespace OpenGridServices.GridServer +{ + /// + /// + public class OpenGrid_Main : BaseServer, conscmd_callback + { + private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll"; + public GridConfig Cfg; + + public static OpenGrid_Main thegrid; + + //public LLUUID highestUUID; + + private SimProfileManager m_simProfileManager; + + private ConsoleBase m_console; + + [STAThread] + public static void Main(string[] args) + { + Console.WriteLine("Starting...\n"); + + thegrid = new OpenGrid_Main(); + thegrid.Startup(); + + thegrid.Work(); + } + + private void Work() + { + m_console.WriteLine("\nEnter help for a list of commands\n"); + + while (true) + { + m_console.MainConsolePrompt(); + } + } + + private OpenGrid_Main() + { + m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this, false); + MainConsole.Instance = m_console; + } + + public void Startup() + { + m_console.WriteLine("Main.cs:Startup() - Loading configuration"); + Cfg = this.LoadConfigDll(this.ConfigDll); + Cfg.InitConfig(); + + m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database"); + m_simProfileManager = new SimProfileManager( this ); + m_simProfileManager.LoadProfiles(); + + m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); + BaseHttpServer httpServer = new BaseHttpServer(8001); + + httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod); + + httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod); + httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod); + httpServer.AddRestHandler("GET", "/regions/", m_simProfileManager.RestGetRegionMethod); + httpServer.AddRestHandler("POST", "/regions/", m_simProfileManager.RestSetRegionMethod); + + + // lbsa71 : This code snippet taken from old http server. + // I have no idea what this was supposed to do - looks like an infinite recursion to me. + // case "regions": + //// DIRTY HACK ALERT + //Console.WriteLine("/regions/ accessed"); + //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1])); + //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod); + //break; + + // lbsa71 : I guess these were never used? + //Listener.Prefixes.Add("http://+:8001/gods/"); + //Listener.Prefixes.Add("http://+:8001/highestuuid/"); + //Listener.Prefixes.Add("http://+:8001/uuidblocks/"); + + httpServer.Start(); + + m_console.WriteLine("Main.cs:Startup() - Starting sim status checker"); + + Timer simCheckTimer = new Timer( 300000 ); // 5 minutes + simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims); + simCheckTimer.Enabled = true; + } + + private GridConfig LoadConfigDll(string dllName) + { + Assembly pluginAssembly = Assembly.LoadFrom(dllName); + GridConfig config = null; + + foreach (Type pluginType in pluginAssembly.GetTypes()) + { + if (pluginType.IsPublic) + { + if (!pluginType.IsAbstract) + { + Type typeInterface = pluginType.GetInterface("IGridConfig", true); + + if (typeInterface != null) + { + IGridConfig plug = (IGridConfig)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); + config = plug.GetConfigObject(); + break; + } + + typeInterface = null; + } + } + } + pluginAssembly = null; + return config; + } + + public void CheckSims(object sender, ElapsedEventArgs e) + { + foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values) + { + string SimResponse = ""; + try + { + WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/"); + CheckSim.Method = "GET"; + CheckSim.ContentType = "text/plaintext"; + CheckSim.ContentLength = 0; + + StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII); + stOut.Write(""); + stOut.Close(); + + StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream()); + SimResponse = stIn.ReadToEnd(); + stIn.Close(); + } + catch + { + } + + if (SimResponse == "OK") + { + m_simProfileManager.SimProfiles[sim.UUID].online = true; + } + else + { + m_simProfileManager.SimProfiles[sim.UUID].online = false; + } + } + } + + public void RunCmd(string cmd, string[] cmdparams) + { + switch (cmd) + { + case "help": + m_console.WriteLine("shutdown - shutdown the grid (USE CAUTION!)"); + break; + + case "shutdown": + m_console.Close(); + Environment.Exit(0); + break; + } + } + + public void Show(string ShowWhat) + { + } + } +} 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 @@ + + + Local + 8.0.50727 + 2.0 + {21BFC8E2-0000-0000-0000-000000000000} + Debug + AnyCPU + + + + OpenGridServices.GridServer + JScript + Grid + IE50 + false + Exe + + OpenGridServices.GridServer + + + + + + False + 285212672 + False + + + TRACE;DEBUG + + True + 4096 + False + ..\bin\ + False + False + False + 4 + + + + False + 285212672 + False + + + TRACE + + False + 4096 + True + ..\bin\ + False + False + False + 4 + + + + + System.dll + False + + + System.Data.dll + False + + + System.Xml.dll + False + + + ..\bin\libsecondlife.dll + False + + + ..\bin\Db4objects.Db4o.dll + False + + + + + OpenSim.Framework + {8ACA2445-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + OpenSim.Framework.Console + {A7CD0630-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + OpenSim.Servers + {8BB20F0A-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + XMLRPC + {8E81D43C-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + + + Code + + + Code + + + Code + + + + + + + + + + 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +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("OGS-GridServer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OGS-GridServer")] +[assembly: AssemblyCopyright("Copyright © 2007")] +[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("b541b244-3d1d-4625-9003-bc2a3a6a39a4")] + +// 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")] 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 @@ +/* +Copyright (c) OpenGrid project, http://osgrid.org/ + + +* All rights reserved. +* +* 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 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 ``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 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.Collections; +using System.Collections.Generic; +using libsecondlife; +using OpenSim.Framework.Utilities; +using OpenSim.Framework.Console; +using OpenSim.Framework.Sims; +using Db4objects.Db4o; +using Nwc.XmlRpc; +using System.Xml; + +namespace OpenGridServices.GridServer +{ + /// + /// + public class SimProfileManager + { + + public Dictionary SimProfiles = new Dictionary(); + private OpenGrid_Main m_gridManager; + + public SimProfileManager(OpenGrid_Main gridManager) + { + m_gridManager = gridManager; + } + + public void LoadProfiles() + { // should abstract this out + IObjectContainer db; + db = Db4oFactory.OpenFile("simprofiles.yap"); + IObjectSet result = db.Get(typeof(SimProfileBase)); + foreach (SimProfileBase simprof in result) + { + SimProfiles.Add(simprof.UUID, simprof); + } + MainConsole.Instance.WriteLine("SimProfiles.Cs:LoadProfiles() - Successfully loaded " + result.Count.ToString() + " from database"); + db.Close(); + } + + public SimProfileBase GetProfileByHandle(ulong reqhandle) + { + foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) + { + if (SimProfiles[UUID].regionhandle == reqhandle) return SimProfiles[UUID]; + } + return null; + } + + public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID) + { + foreach (libsecondlife.LLUUID UUID in SimProfiles.Keys) + { + if (SimProfiles[UUID].UUID == ProfileLLUUID) return SimProfiles[UUID]; + } + return null; + } + + public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) + { + SimProfileBase TheSim = GetProfileByHandle(regionhandle); + if (TheSim != null) + if (TheSim.recvkey == simrecvkey) + { + return true; + } + else + { + return false; + } + else return false; + + } + + public string GetXMLNeighbours(ulong reqhandle) + { + string response = ""; + SimProfileBase central_region = GetProfileByHandle(reqhandle); + SimProfileBase neighbour; + for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) + { + if (GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)) != null) + { + neighbour = GetProfileByHandle(Util.UIntsToLong((uint)((central_region.RegionLocX + x) * 256), (uint)(central_region.RegionLocY + y) * 256)); + response += ""; + response += "" + neighbour.sim_ip + ""; + response += "" + neighbour.sim_port.ToString() + ""; + response += "" + neighbour.RegionLocX.ToString() + ""; + response += "" + neighbour.RegionLocY.ToString() + ""; + response += "" + neighbour.regionhandle.ToString() + ""; + response += ""; + + } + } + return response; + } + + public SimProfileBase CreateNewProfile(string regionname, string caps_url, string sim_ip, uint sim_port, uint RegionLocX, uint RegionLocY, string sendkey, string recvkey) + { + SimProfileBase newprofile = new SimProfileBase(); + newprofile.regionname = regionname; + newprofile.sim_ip = sim_ip; + newprofile.sim_port = sim_port; + newprofile.RegionLocX = RegionLocX; + newprofile.RegionLocY = RegionLocY; + newprofile.caps_url = "http://" + sim_ip + ":9000/"; + newprofile.sendkey = sendkey; + newprofile.recvkey = recvkey; + newprofile.regionhandle = Util.UIntsToLong((RegionLocX * 256), (RegionLocY * 256)); + newprofile.UUID = LLUUID.Random(); + this.SimProfiles.Add(newprofile.UUID, newprofile); + return newprofile; + } + + public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) + { + XmlRpcResponse response = new XmlRpcResponse(); + Hashtable responseData = new Hashtable(); + response.Value = responseData; + + SimProfileBase TheSim = null; + Hashtable requestData = (Hashtable)request.Params[0]; + + if (requestData.ContainsKey("UUID")) + { + TheSim = GetProfileByLLUUID(new LLUUID((string)requestData["UUID"])); + } + else if (requestData.ContainsKey("region_handle")) + { + TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"])); + } + + if (TheSim == null) + { + responseData["error"] = "sim not found"; + } + else + { + + ArrayList SimNeighboursData = new ArrayList(); + + SimProfileBase neighbour; + Hashtable NeighbourBlock; + for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) + { + if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null) + { + neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)); + + NeighbourBlock = new Hashtable(); + NeighbourBlock["sim_ip"] = neighbour.sim_ip; + NeighbourBlock["sim_port"] = neighbour.sim_port.ToString(); + NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString(); + NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString(); + NeighbourBlock["UUID"] = neighbour.UUID.ToString(); + + if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); + } + } + + responseData["UUID"] = TheSim.UUID.ToString(); + responseData["region_locx"] = TheSim.RegionLocX.ToString(); + responseData["region_locy"] = TheSim.RegionLocY.ToString(); + responseData["regionname"] = TheSim.regionname; + responseData["estate_id"] = "1"; + responseData["neighbours"] = SimNeighboursData; + + responseData["sim_ip"] = TheSim.sim_ip; + responseData["sim_port"] = TheSim.sim_port.ToString(); + responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer; + responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey; + responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey; + responseData["user_url"] = m_gridManager.Cfg.DefaultUserServer; + responseData["user_sendkey"] = m_gridManager.Cfg.UserSendKey; + responseData["user_recvkey"] = m_gridManager.Cfg.UserRecvKey; + responseData["authkey"] = m_gridManager.Cfg.SimSendKey; + } + + return response; + } + + public string RestSetSimMethod(string request, string path, string param) + { + Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......"); + SimProfileBase TheSim; + TheSim = GetProfileByLLUUID(new LLUUID(param)); + if ((TheSim) == null) + { + TheSim = new SimProfileBase(); + LLUUID UUID = new LLUUID(param); + TheSim.UUID = UUID; + } + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(request); + XmlNode rootnode = doc.FirstChild; + XmlNode authkeynode = rootnode.ChildNodes[0]; + if (authkeynode.Name != "authkey") + { + return "ERROR! bad XML - expected authkey tag"; + } + + XmlNode simnode = rootnode.ChildNodes[1]; + if (simnode.Name != "sim") + { + return "ERROR! bad XML - expected sim tag"; + } + + if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey) + { + return "ERROR! invalid key"; + } + for (int i = 0; i < simnode.ChildNodes.Count; i++) + { + switch (simnode.ChildNodes[i].Name) + { + case "regionname": + TheSim.regionname = simnode.ChildNodes[i].InnerText; + break; + + case "sim_ip": + TheSim.sim_ip = simnode.ChildNodes[i].InnerText; + break; + + case "sim_port": + TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); + break; + + case "region_locx": + TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); + TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); + break; + + case "region_locy": + TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); + TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256)); + break; + } + } + + try + { + SimProfiles.Add(TheSim.UUID, TheSim); + IObjectContainer db; + db = Db4oFactory.OpenFile("simprofiles.yap"); + db.Set(TheSim); + db.Close(); + return "OK"; + } + catch (Exception e) + { + return "ERROR! could not save to database!"; + } + + } + + public string RestGetRegionMethod(string request, string path, string param) + { + SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); + return RestGetSimMethod("", "/sims/", param); + } + + public string RestSetRegionMethod(string request, string path, string param) + { + SimProfileBase TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(param)); + return RestSetSimMethod("", "/sims/", param); + } + + public string RestGetSimMethod(string request, string path, string param) + { + string respstring = String.Empty; + + SimProfileBase TheSim; + LLUUID UUID = new LLUUID(param); + TheSim = GetProfileByLLUUID(UUID); + + if (!(TheSim == null)) + { + respstring = ""; + respstring += "" + m_gridManager.Cfg.SimSendKey + ""; + respstring += ""; + respstring += "" + TheSim.UUID.ToString() + ""; + respstring += "" + TheSim.regionname + ""; + respstring += "" + TheSim.sim_ip + ""; + respstring += "" + TheSim.sim_port.ToString() + ""; + respstring += "" + TheSim.RegionLocX.ToString() + ""; + respstring += "" + TheSim.RegionLocY.ToString() + ""; + respstring += "1"; + respstring += ""; + respstring += ""; + } + + return respstring; + } + + } + + +} -- cgit v1.1