Fixed weird XML/HTTP bugs

Can now update a sim profile at startup automatically! W00t!
Untested neighbours code (for sim crossings)
Didn't drink any red bull today :( Used liquid guarana extract + cola
0.1-prestable
gareth 2007-04-13 15:14:21 +00:00
parent cc53580ba4
commit dd5f4abdb9
4 changed files with 56 additions and 41 deletions

View File

@ -47,20 +47,10 @@ namespace OpenGridServices.GridServer
public class OpenGrid_Main : BaseServer, conscmd_callback
{
private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
private GridConfig Cfg;
public GridConfig Cfg;
public static OpenGrid_Main thegrid;
public string GridOwner;
public string DefaultStartupMsg;
public string DefaultAssetServer;
public string AssetSendKey;
public string AssetRecvKey;
public string DefaultUserServer;
public string UserSendKey;
public string UserRecvKey;
public string SimSendKey;
public string SimRecvKey;
//public LLUUID highestUUID;
private SimProfileManager m_simProfileManager;
@ -109,10 +99,10 @@ 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", "/regions", m_simProfileManager.RestGetRegionMethod);
httpServer.AddRestHandler("POST", "/regions", m_simProfileManager.RestSetRegionMethod);
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.

View File

@ -71,7 +71,10 @@ namespace OpenGridServices.GridServer
}
public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID) {
return SimProfiles[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) {
@ -172,13 +175,13 @@ namespace OpenGridServices.GridServer
responseData["estate_id"] = "1";
responseData["neighbours"] = SimNeighboursData;
responseData["asset_url"] = m_gridManager.DefaultAssetServer;
responseData["asset_sendkey"] = m_gridManager.AssetSendKey;
responseData["asset_recvkey"] = m_gridManager.AssetRecvKey;
responseData["user_url"] = m_gridManager.DefaultUserServer;
responseData["user_sendkey"] = m_gridManager.UserSendKey;
responseData["user_recvkey"] = m_gridManager.UserRecvKey;
responseData["authkey"] = m_gridManager.SimSendKey;
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;
@ -188,30 +191,33 @@ namespace OpenGridServices.GridServer
{
Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
SimProfileBase TheSim;
LLUUID UUID = new LLUUID(param);
TheSim = GetProfileByLLUUID(UUID);
if ((TheSim) == null) TheSim = new SimProfileBase();
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 authkeynode = doc.FirstChild;
XmlNode rootnode=doc.FirstChild;
XmlNode authkeynode = rootnode.ChildNodes[0];
if (authkeynode.Name != "authkey")
{
return "ERROR! bad XML - expected authkey tag";
}
XmlNode simnode = doc.ChildNodes[1];
XmlNode simnode = rootnode.ChildNodes[1];
if (simnode.Name != "sim")
{
return "ERROR! bad XML - expected sim tag";
}
if (authkeynode.InnerText != m_gridManager.SimRecvKey)
if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey)
{
return "ERROR! invalid key";
}
for (int i = 0; i <= simnode.ChildNodes.Count; i++) {
for (int i = 0; i < simnode.ChildNodes.Count; i++) {
switch (simnode.ChildNodes[i].Name) {
case "regionname":
TheSim.regionname = simnode.ChildNodes[i].InnerText;
@ -231,12 +237,23 @@ namespace OpenGridServices.GridServer
break;
case "region_locy":
TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
break;
}
}
}
return "OK";
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 )
@ -261,7 +278,8 @@ namespace OpenGridServices.GridServer
if (!(TheSim == null))
{
respstring = "<authkey>" + m_gridManager.SimSendKey + "</authkey>";
respstring = "<Root>";
respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>";
respstring += "<sim>";
respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
respstring += "<regionname>" + TheSim.regionname + "</regionname>";
@ -271,6 +289,7 @@ namespace OpenGridServices.GridServer
respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
respstring += "<estate_id>1</estate_id>";
respstring += "</sim>";
respstring += "</Root>";
}
return respstring;

View File

@ -44,7 +44,8 @@ namespace OpenSim
//we really want to keep any server connection code out of here and out of the code code
// and put it in the server connection classes (those inheriting from IGridServer etc)
string reqtext;
reqtext = "<authkey>" + this.GridSendKey + "</authkey>";
reqtext = "<Root>";
reqtext += "<authkey>" + this.GridSendKey + "</authkey>";
reqtext += "<sim>";
reqtext += "<uuid>" + this.SimUUID.ToString() + "</uuid>";
reqtext += "<regionname>" + this.RegionName + "</regionname>";
@ -54,6 +55,7 @@ namespace OpenSim
reqtext += "<region_locy>" + this.RegionLocY.ToString() + "</region_locy>";
reqtext += "<estate_id>1</estate_id>";
reqtext += "</sim>";
reqtext += "</Root>";
byte[] reqdata = (new System.Text.ASCIIEncoding()).GetBytes(reqtext);
@ -67,7 +69,7 @@ namespace OpenSim
stOut.Close();
WebResponse gridresp = GridSaveReq.GetResponse();
StreamReader stIn = new StreamReader(gridresp.GetResponseStream());
StreamReader stIn = new StreamReader(gridresp.GetResponseStream(), Encoding.ASCII);
string GridResponse = stIn.ReadToEnd();
stIn.Close();
gridresp.Close();

View File

@ -154,6 +154,7 @@ namespace OpenSim.Servers
public virtual void HandleRequest(Object stateinfo)
{
try {
HttpListenerContext context = (HttpListenerContext)stateinfo;
HttpListenerRequest request = context.Request;
@ -211,6 +212,9 @@ namespace OpenSim.Servers
response.ContentLength64 = buffer.Length;
output.Write(buffer, 0, buffer.Length);
output.Close();
} catch (Exception e) {
Console.WriteLine(e.ToString());
}
}
public void Start()