From cc53580ba4bb688baf75159d728c03ccfc568aec Mon Sep 17 00:00:00 2001 From: gareth Date: Thu, 12 Apr 2007 18:34:17 +0000 Subject: aaaaaaarrrrrrrrrggggghhhhhhhh why oh why? --- OpenGridServices.GridServer/Main.cs | 7 +- OpenGridServices.GridServer/SimProfiles.cs | 128 +++++++++++++---------------- OpenSim.RegionServer/RegionInfo.cs | 14 ++-- 3 files changed, 71 insertions(+), 78 deletions(-) diff --git a/OpenGridServices.GridServer/Main.cs b/OpenGridServices.GridServer/Main.cs index 5827227..c69b6dc 100644 --- a/OpenGridServices.GridServer/Main.cs +++ b/OpenGridServices.GridServer/Main.cs @@ -109,8 +109,11 @@ namespace OpenGridServices.GridServer httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod); - httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod); - httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod); + 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. diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs index fd4ba99..9e93db0 100644 --- a/OpenGridServices.GridServer/SimProfiles.cs +++ b/OpenGridServices.GridServer/SimProfiles.cs @@ -186,85 +186,71 @@ namespace OpenGridServices.GridServer public string RestSetSimMethod(string request, string path, string param) { - string respstring = String.Empty; - + Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......"); SimProfileBase TheSim; LLUUID UUID = new LLUUID(param); TheSim = GetProfileByLLUUID(UUID); - - if (!(TheSim == null)) - { - Console.WriteLine("Updating sim details....."); - XmlDocument doc = new XmlDocument(); - doc.LoadXml(request); - XmlNode authkeynode = doc.FirstChild; - if (authkeynode.Name != "authkey") + if ((TheSim) == null) TheSim = new SimProfileBase(); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(request); + XmlNode authkeynode = doc.FirstChild; + if (authkeynode.Name != "authkey") { - respstring = "ERROR! bad XML - expected authkey tag"; + return "ERROR! bad XML - expected authkey tag"; } - else - { - XmlNode simnode = doc.ChildNodes[1]; - if (simnode.Name != "sim") - { - respstring = "ERROR! bad XML - expected sim tag"; - } - else - { - if (authkeynode.Name != m_gridManager.SimRecvKey) - { - respstring = "ERROR! invalid key"; - } - else - { - if (TheSim == null) - { - respstring = "ERROR! sim not found"; - } - else - { - for (int i = 0; i <= simnode.ChildNodes.Count; i++) - { - switch (simnode.ChildNodes[i].Name) - { - case "uuid": - // should a sim be able to update it's own UUID? To be decided - // watch next week for the exciting conclusion in "the adventures of OpenGridServices.GridServer/GridHttp.cs:ParseREST() at line 190! - break; // and line 190's arch-enemy - THE BREAK STATEMENT! OH NOES!!!!! (this code written at 6:57AM, no sleep, lots of caffeine) - - 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; - } - } - respstring = "OK"; - } - } - } + XmlNode simnode = doc.ChildNodes[1]; + if (simnode.Name != "sim") + { + return "ERROR! bad XML - expected sim tag"; } - } - - return respstring; + + if (authkeynode.InnerText != m_gridManager.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; + } + } + return "OK"; } - + + 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; diff --git a/OpenSim.RegionServer/RegionInfo.cs b/OpenSim.RegionServer/RegionInfo.cs index 1256b50..9958f1a 100644 --- a/OpenSim.RegionServer/RegionInfo.cs +++ b/OpenSim.RegionServer/RegionInfo.cs @@ -54,19 +54,23 @@ namespace OpenSim reqtext += "" + this.RegionLocY.ToString() + ""; reqtext += "1"; reqtext += ""; + + byte[] reqdata = (new System.Text.ASCIIEncoding()).GetBytes(reqtext); WebRequest GridSaveReq = WebRequest.Create(this.GridURL + "sims/" + this.SimUUID.ToString()); GridSaveReq.Method = "POST"; - GridSaveReq.ContentType = "text/plaintext"; - GridSaveReq.ContentLength = reqtext.Length; + GridSaveReq.ContentType = "application/x-www-form-urlencoded"; + GridSaveReq.ContentLength = reqdata.Length; - StreamWriter stOut = new StreamWriter(GridSaveReq.GetRequestStream(), System.Text.Encoding.ASCII); - stOut.Write(reqtext); + Stream stOut = GridSaveReq.GetRequestStream(); + stOut.Write(reqdata,0,reqdata.Length); stOut.Close(); - StreamReader stIn = new StreamReader(GridSaveReq.GetResponse().GetResponseStream()); + WebResponse gridresp = GridSaveReq.GetResponse(); + StreamReader stIn = new StreamReader(gridresp.GetResponseStream()); string GridResponse = stIn.ReadToEnd(); stIn.Close(); + gridresp.Close(); OpenSim.Framework.Console.MainConsole.Instance.WriteLine("RegionInfo.CS:SaveToGrid() - Grid said: " + GridResponse); } -- cgit v1.1