aaaaaaarrrrrrrrrggggghhhhhhhh why oh why?

0.1-prestable
gareth 2007-04-12 18:34:17 +00:00
parent 1a28ef6292
commit cc53580ba4
3 changed files with 69 additions and 76 deletions

View File

@ -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.

View File

@ -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) TheSim = new SimProfileBase();
if (!(TheSim == null))
{
Console.WriteLine("Updating sim details.....");
XmlDocument doc = new XmlDocument();
doc.LoadXml(request);
XmlNode authkeynode = doc.FirstChild;
if (authkeynode.Name != "authkey")
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")
{
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";
}
}
}
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;

View File

@ -55,18 +55,22 @@ namespace OpenSim
reqtext += "<estate_id>1</estate_id>";
reqtext += "</sim>";
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);
}