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 + cola0.1-prestable
parent
cc53580ba4
commit
dd5f4abdb9
|
@ -47,20 +47,10 @@ namespace OpenGridServices.GridServer
|
||||||
public class OpenGrid_Main : BaseServer, conscmd_callback
|
public class OpenGrid_Main : BaseServer, conscmd_callback
|
||||||
{
|
{
|
||||||
private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
|
private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
|
||||||
private GridConfig Cfg;
|
public GridConfig Cfg;
|
||||||
|
|
||||||
public static OpenGrid_Main thegrid;
|
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;
|
//public LLUUID highestUUID;
|
||||||
|
|
||||||
private SimProfileManager m_simProfileManager;
|
private SimProfileManager m_simProfileManager;
|
||||||
|
@ -109,10 +99,10 @@ namespace OpenGridServices.GridServer
|
||||||
|
|
||||||
httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod);
|
httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod);
|
||||||
|
|
||||||
httpServer.AddRestHandler("GET", "/sims", m_simProfileManager.RestGetSimMethod);
|
httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod);
|
||||||
httpServer.AddRestHandler("POST", "/sims", m_simProfileManager.RestSetSimMethod);
|
httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod);
|
||||||
httpServer.AddRestHandler("GET", "/regions", m_simProfileManager.RestGetRegionMethod);
|
httpServer.AddRestHandler("GET", "/regions/", m_simProfileManager.RestGetRegionMethod);
|
||||||
httpServer.AddRestHandler("POST", "/regions", m_simProfileManager.RestSetRegionMethod);
|
httpServer.AddRestHandler("POST", "/regions/", m_simProfileManager.RestSetRegionMethod);
|
||||||
|
|
||||||
|
|
||||||
// lbsa71 : This code snippet taken from old http server.
|
// lbsa71 : This code snippet taken from old http server.
|
||||||
|
|
|
@ -71,7 +71,10 @@ namespace OpenGridServices.GridServer
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimProfileBase GetProfileByLLUUID(LLUUID ProfileLLUUID) {
|
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) {
|
public bool AuthenticateSim(LLUUID RegionUUID, uint regionhandle, string simrecvkey) {
|
||||||
|
@ -172,13 +175,13 @@ namespace OpenGridServices.GridServer
|
||||||
responseData["estate_id"] = "1";
|
responseData["estate_id"] = "1";
|
||||||
responseData["neighbours"] = SimNeighboursData;
|
responseData["neighbours"] = SimNeighboursData;
|
||||||
|
|
||||||
responseData["asset_url"] = m_gridManager.DefaultAssetServer;
|
responseData["asset_url"] = m_gridManager.Cfg.DefaultAssetServer;
|
||||||
responseData["asset_sendkey"] = m_gridManager.AssetSendKey;
|
responseData["asset_sendkey"] = m_gridManager.Cfg.AssetSendKey;
|
||||||
responseData["asset_recvkey"] = m_gridManager.AssetRecvKey;
|
responseData["asset_recvkey"] = m_gridManager.Cfg.AssetRecvKey;
|
||||||
responseData["user_url"] = m_gridManager.DefaultUserServer;
|
responseData["user_url"] = m_gridManager.Cfg.DefaultUserServer;
|
||||||
responseData["user_sendkey"] = m_gridManager.UserSendKey;
|
responseData["user_sendkey"] = m_gridManager.Cfg.UserSendKey;
|
||||||
responseData["user_recvkey"] = m_gridManager.UserRecvKey;
|
responseData["user_recvkey"] = m_gridManager.Cfg.UserRecvKey;
|
||||||
responseData["authkey"] = m_gridManager.SimSendKey;
|
responseData["authkey"] = m_gridManager.Cfg.SimSendKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -188,30 +191,33 @@ namespace OpenGridServices.GridServer
|
||||||
{
|
{
|
||||||
Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
|
Console.WriteLine("SimProfiles.cs:RestSetSimMethod() - processing request......");
|
||||||
SimProfileBase TheSim;
|
SimProfileBase TheSim;
|
||||||
LLUUID UUID = new LLUUID(param);
|
TheSim = GetProfileByLLUUID(new LLUUID(param));
|
||||||
TheSim = GetProfileByLLUUID(UUID);
|
if ((TheSim) == null) {
|
||||||
if ((TheSim) == null) TheSim = new SimProfileBase();
|
TheSim = new SimProfileBase();
|
||||||
|
LLUUID UUID = new LLUUID(param);
|
||||||
|
TheSim.UUID=UUID;
|
||||||
|
}
|
||||||
|
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument doc = new XmlDocument();
|
||||||
doc.LoadXml(request);
|
doc.LoadXml(request);
|
||||||
XmlNode authkeynode = doc.FirstChild;
|
XmlNode rootnode=doc.FirstChild;
|
||||||
|
XmlNode authkeynode = rootnode.ChildNodes[0];
|
||||||
if (authkeynode.Name != "authkey")
|
if (authkeynode.Name != "authkey")
|
||||||
{
|
{
|
||||||
return "ERROR! bad XML - expected authkey tag";
|
return "ERROR! bad XML - expected authkey tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlNode simnode = doc.ChildNodes[1];
|
XmlNode simnode = rootnode.ChildNodes[1];
|
||||||
if (simnode.Name != "sim")
|
if (simnode.Name != "sim")
|
||||||
{
|
{
|
||||||
return "ERROR! bad XML - expected sim tag";
|
return "ERROR! bad XML - expected sim tag";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (authkeynode.InnerText != m_gridManager.SimRecvKey)
|
if (authkeynode.InnerText != m_gridManager.Cfg.SimRecvKey)
|
||||||
{
|
{
|
||||||
return "ERROR! invalid key";
|
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) {
|
switch (simnode.ChildNodes[i].Name) {
|
||||||
case "regionname":
|
case "regionname":
|
||||||
TheSim.regionname = simnode.ChildNodes[i].InnerText;
|
TheSim.regionname = simnode.ChildNodes[i].InnerText;
|
||||||
|
@ -231,12 +237,23 @@ namespace OpenGridServices.GridServer
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "region_locy":
|
case "region_locy":
|
||||||
TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
|
TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
|
||||||
TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
|
TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
|
||||||
break;
|
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 )
|
public string RestGetRegionMethod(string request, string path, string param )
|
||||||
|
@ -261,7 +278,8 @@ namespace OpenGridServices.GridServer
|
||||||
|
|
||||||
if (!(TheSim == null))
|
if (!(TheSim == null))
|
||||||
{
|
{
|
||||||
respstring = "<authkey>" + m_gridManager.SimSendKey + "</authkey>";
|
respstring = "<Root>";
|
||||||
|
respstring += "<authkey>" + m_gridManager.Cfg.SimSendKey + "</authkey>";
|
||||||
respstring += "<sim>";
|
respstring += "<sim>";
|
||||||
respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
|
respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
|
||||||
respstring += "<regionname>" + TheSim.regionname + "</regionname>";
|
respstring += "<regionname>" + TheSim.regionname + "</regionname>";
|
||||||
|
@ -271,6 +289,7 @@ namespace OpenGridServices.GridServer
|
||||||
respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
|
respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
|
||||||
respstring += "<estate_id>1</estate_id>";
|
respstring += "<estate_id>1</estate_id>";
|
||||||
respstring += "</sim>";
|
respstring += "</sim>";
|
||||||
|
respstring += "</Root>";
|
||||||
}
|
}
|
||||||
|
|
||||||
return respstring;
|
return respstring;
|
||||||
|
|
|
@ -44,7 +44,8 @@ namespace OpenSim
|
||||||
//we really want to keep any server connection code out of here and out of the code code
|
//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)
|
// and put it in the server connection classes (those inheriting from IGridServer etc)
|
||||||
string reqtext;
|
string reqtext;
|
||||||
reqtext = "<authkey>" + this.GridSendKey + "</authkey>";
|
reqtext = "<Root>";
|
||||||
|
reqtext += "<authkey>" + this.GridSendKey + "</authkey>";
|
||||||
reqtext += "<sim>";
|
reqtext += "<sim>";
|
||||||
reqtext += "<uuid>" + this.SimUUID.ToString() + "</uuid>";
|
reqtext += "<uuid>" + this.SimUUID.ToString() + "</uuid>";
|
||||||
reqtext += "<regionname>" + this.RegionName + "</regionname>";
|
reqtext += "<regionname>" + this.RegionName + "</regionname>";
|
||||||
|
@ -54,6 +55,7 @@ namespace OpenSim
|
||||||
reqtext += "<region_locy>" + this.RegionLocY.ToString() + "</region_locy>";
|
reqtext += "<region_locy>" + this.RegionLocY.ToString() + "</region_locy>";
|
||||||
reqtext += "<estate_id>1</estate_id>";
|
reqtext += "<estate_id>1</estate_id>";
|
||||||
reqtext += "</sim>";
|
reqtext += "</sim>";
|
||||||
|
reqtext += "</Root>";
|
||||||
|
|
||||||
byte[] reqdata = (new System.Text.ASCIIEncoding()).GetBytes(reqtext);
|
byte[] reqdata = (new System.Text.ASCIIEncoding()).GetBytes(reqtext);
|
||||||
|
|
||||||
|
@ -67,7 +69,7 @@ namespace OpenSim
|
||||||
stOut.Close();
|
stOut.Close();
|
||||||
|
|
||||||
WebResponse gridresp = GridSaveReq.GetResponse();
|
WebResponse gridresp = GridSaveReq.GetResponse();
|
||||||
StreamReader stIn = new StreamReader(gridresp.GetResponseStream());
|
StreamReader stIn = new StreamReader(gridresp.GetResponseStream(), Encoding.ASCII);
|
||||||
string GridResponse = stIn.ReadToEnd();
|
string GridResponse = stIn.ReadToEnd();
|
||||||
stIn.Close();
|
stIn.Close();
|
||||||
gridresp.Close();
|
gridresp.Close();
|
||||||
|
|
|
@ -154,6 +154,7 @@ namespace OpenSim.Servers
|
||||||
|
|
||||||
public virtual void HandleRequest(Object stateinfo)
|
public virtual void HandleRequest(Object stateinfo)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
HttpListenerContext context = (HttpListenerContext)stateinfo;
|
HttpListenerContext context = (HttpListenerContext)stateinfo;
|
||||||
|
|
||||||
HttpListenerRequest request = context.Request;
|
HttpListenerRequest request = context.Request;
|
||||||
|
@ -211,6 +212,9 @@ namespace OpenSim.Servers
|
||||||
response.ContentLength64 = buffer.Length;
|
response.ContentLength64 = buffer.Length;
|
||||||
output.Write(buffer, 0, buffer.Length);
|
output.Write(buffer, 0, buffer.Length);
|
||||||
output.Close();
|
output.Close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine(e.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
|
Loading…
Reference in New Issue