From e985e05a5ad7df4c5f01763dfe6b82cc1b37ab83 Mon Sep 17 00:00:00 2001 From: gareth Date: Mon, 2 Apr 2007 00:48:25 +0000 Subject: Added new REST protocol (partially complete) Made sim profiles load from DB Updated build files for grid server Added sim login --- OpenGridServices.GridServer/GridHttp.cs | 152 +++++++++----- OpenGridServices.GridServer/Main.cs | 15 +- .../OpenGridServices.GridServer.csproj | 230 +++++++++++---------- .../OpenGridServices.GridServer.exe.build | 95 ++++----- OpenGridServices.GridServer/SimProfiles.cs | 13 +- 5 files changed, 283 insertions(+), 222 deletions(-) (limited to 'OpenGridServices.GridServer') diff --git a/OpenGridServices.GridServer/GridHttp.cs b/OpenGridServices.GridServer/GridHttp.cs index c9cda61..33e1e71 100644 --- a/OpenGridServices.GridServer/GridHttp.cs +++ b/OpenGridServices.GridServer/GridHttp.cs @@ -56,8 +56,13 @@ namespace OpenGridServices.GridServer MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK"); Listener = new HttpListener(); - Listener.Prefixes.Add("http://+:8001/gridserver/"); + Listener.Prefixes.Add("http://+:8001/sims/"); + Listener.Prefixes.Add("http://+:8001/gods/"); + Listener.Prefixes.Add("http://+:8001/highestuuid/"); + Listener.Prefixes.Add("http://+:8001/uuidblocks/"); Listener.Start(); + + MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Successfully bound to port 8001"); HttpListenerContext context; while(true) { @@ -66,72 +71,105 @@ namespace OpenGridServices.GridServer } } - static string ParseXMLRPC(string requestBody) { + static string ParseXMLRPC(string requestBody, string referrer) { try{ - XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); + XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody); - Hashtable requestData = (Hashtable)request.Params[0]; - switch(request.MethodName) { - case "get_sim_info": - ulong req_handle=(ulong)Convert.ToInt64(requestData["region_handle"]); - SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(req_handle); - string RecvKey=""; - string caller=(string)requestData["caller"]; - switch(caller) { - case "userserver": - RecvKey=OpenGrid_Main.thegrid.UserRecvKey; - break; - case "assetserver": - RecvKey=OpenGrid_Main.thegrid.AssetRecvKey; - break; - } - if((TheSim!=null) && (string)requestData["authkey"]==RecvKey) { - XmlRpcResponse SimInfoResp = new XmlRpcResponse(); - Hashtable SimInfoData = new Hashtable(); - SimInfoData["UUID"]=TheSim.UUID.ToString(); - SimInfoData["regionhandle"]=TheSim.regionhandle.ToString(); - SimInfoData["regionname"]=TheSim.regionname; - SimInfoData["sim_ip"]=TheSim.sim_ip; - SimInfoData["sim_port"]=TheSim.sim_port.ToString(); - SimInfoData["caps_url"]=TheSim.caps_url; - SimInfoData["RegionLocX"]=TheSim.RegionLocX.ToString(); - SimInfoData["RegionLocY"]=TheSim.RegionLocY.ToString(); - SimInfoData["sendkey"]=TheSim.sendkey; - SimInfoData["recvkey"]=TheSim.recvkey; - SimInfoResp.Value=SimInfoData; - return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(SimInfoResp),"utf-16","utf-8")); - } else { - XmlRpcResponse SimErrorResp = new XmlRpcResponse(); - Hashtable SimErrorData = new Hashtable(); - SimErrorData["error"]="sim not found"; - SimErrorResp.Value=SimErrorData; - return(XmlRpcResponseSerializer.Singleton.Serialize(SimErrorResp)); - } - break; - } + Hashtable requestData = (Hashtable)request.Params[0]; + switch(request.MethodName) { + case "simulator_login": + if(!(referrer=="simulator")) { + XmlRpcResponse ErrorResp = new XmlRpcResponse(); + Hashtable ErrorRespData = new Hashtable(); + ErrorRespData["error"]="Only simulators can login with this method"; + ErrorResp.Value=ErrorRespData; + return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); + } + + if(!((string)requestData["authkey"]==OpenGrid_Main.thegrid.SimRecvKey)) { + XmlRpcResponse ErrorResp = new XmlRpcResponse(); + Hashtable ErrorRespData = new Hashtable(); + ErrorRespData["error"]="invalid key"; + ErrorResp.Value=ErrorRespData; + return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8")); + } + + SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(new LLUUID((string)requestData["UUID"])); + XmlRpcResponse SimLoginResp = new XmlRpcResponse(); + Hashtable SimLoginRespData = new Hashtable(); + + ArrayList SimNeighboursData = new ArrayList(); + + SimProfileBase neighbour; + Hashtable NeighbourBlock; + for(int x=-1; x<2; x++) for(int y=-1; y<2; y++) { + if(OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX+x)*256), (uint)(TheSim.RegionLocY+y)*256))!=null) { + neighbour=OpenGrid_Main.thegrid._regionmanager.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(); + SimNeighboursData.Add(NeighbourBlock); + } + } + + + SimLoginRespData["region_locx"]=TheSim.RegionLocX.ToString(); + SimLoginRespData["region_locy"]=TheSim.RegionLocY.ToString(); + SimLoginRespData["regionname"]=TheSim.regionname; + SimLoginRespData["estate_id"]="1"; + SimLoginRespData["neighbours"]=SimNeighboursData; + SimLoginRespData["asset_url"]=OpenGrid_Main.thegrid.DefaultAssetServer; + SimLoginRespData["asset_sendkey"]=OpenGrid_Main.thegrid.AssetSendKey; + SimLoginRespData["asset_recvkey"]=OpenGrid_Main.thegrid.AssetRecvKey; + SimLoginRespData["user_url"]=OpenGrid_Main.thegrid.DefaultUserServer; + SimLoginRespData["user_sendkey"]=OpenGrid_Main.thegrid.UserSendKey; + SimLoginRespData["user_recvkey"]=OpenGrid_Main.thegrid.UserRecvKey; + SimLoginRespData["authkey"]=OpenGrid_Main.thegrid.SimSendKey; + SimLoginResp.Value=SimLoginRespData; + return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(SimLoginResp),"utf-16","utf-8")); + break; + } } catch(Exception e) { Console.WriteLine(e.ToString()); } return ""; } - static string ParseREST(string requestBody, string requestURL) { + static string ParseREST(string requestBody, string requestURL, string HTTPmethod) { char[] splitter = {'/'}; string[] rest_params = requestURL.Split(splitter); - string req_type = rest_params[1]; // First part of the URL is the type of request - - switch(req_type) { - case "regions": - ulong regionhandle = (ulong)Convert.ToInt64(rest_params[2]); // get usersessions/sessionid - switch(rest_params[3]) { - case "neighbours": - return OpenGrid_Main.thegrid._regionmanager.GetXMLNeighbours(regionhandle); - break; + string req_type = rest_params[0]; // First part of the URL is the type of request - + string respstring; + switch(req_type) { + case "sims": + LLUUID UUID = new LLUUID((string)rest_params[1]); + SimProfileBase TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(UUID); + if(!(TheSim==null)) { + switch(HTTPmethod) { + case "GET": + respstring="" + OpenGrid_Main.thegrid.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+=""; + break; + } } - return "OK"; break; - } + case "highestuuid": + + break; + } return ""; - + } @@ -152,18 +190,20 @@ namespace OpenGridServices.GridServer body.Close(); reader.Close(); + // TODO: AUTHENTICATION!!!!!!!!! MUST ADD!!!!!!!!!! SCRIPT KIDDIES LOVE LACK OF IT!!!!!!!!!! + string responseString=""; switch(request.ContentType) { case "text/xml": // must be XML-RPC, so pass to the XML-RPC parser - responseString=ParseXMLRPC(requestBody); + responseString=ParseXMLRPC(requestBody,request.Headers["Referer"]); response.AddHeader("Content-type","text/xml"); break; case null: // must be REST or invalid crap, so pass to the REST parser - responseString=ParseREST(request.Url.OriginalString,requestBody); + responseString=ParseREST(request.Url.OriginalString,requestBody,request.HttpMethod); break; } diff --git a/OpenGridServices.GridServer/Main.cs b/OpenGridServices.GridServer/Main.cs index 2382fd7..46041d9 100644 --- a/OpenGridServices.GridServer/Main.cs +++ b/OpenGridServices.GridServer/Main.cs @@ -39,7 +39,6 @@ namespace OpenGridServices.GridServer /// public class OpenGrid_Main : conscmd_callback { - public static OpenGrid_Main thegrid; public string GridOwner; public string DefaultStartupMsg; @@ -49,6 +48,9 @@ namespace OpenGridServices.GridServer public string DefaultUserServer; public string UserSendKey; public string UserRecvKey; + public string SimSendKey; + public string SimRecvKey; + public LLUUID highestUUID; public GridHTTPServer _httpd; public SimProfileManager _regionmanager; @@ -97,11 +99,16 @@ namespace OpenGridServices.GridServer this.UserSendKey = m_console.CmdPrompt("Key to send to user server: "); this.UserRecvKey = m_console.CmdPrompt("Key to expect from user server: "); - m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); + this.SimSendKey = m_console.CmdPrompt("Key to send to sims: "); + this.SimRecvKey = m_console.CmdPrompt("Key to expect from sims: "); + + m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database"); + this._regionmanager = new SimProfileManager(); + _regionmanager.LoadProfiles(); + + m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); _httpd = new GridHTTPServer(); - this._regionmanager = new SimProfileManager(); - _regionmanager.CreateNewProfile("OpenSim Test", "http://there-is-no-caps.com", "4.78.190.75", 9000, 997, 996, this.UserSendKey, this.UserRecvKey); } public void RunCmd(string cmd, string[] cmdparams) diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj index 71d603e..12b4933 100644 --- a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj +++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj @@ -1,113 +1,117 @@ - - - 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 - - - - - 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 - - - - - Code - - - Code - - - Code - - - Code - - - - - - - - - - + + + Local + 8.0.50727 + 2.0 + {53A65EE9-0000-0000-0000-000000000000} + Debug + AnyCPU + + + + OpenGridServices.GridServer + JScript + Grid + IE50 + false + Exe + + OpenGridServices.GridServer + + + + + + False + 285212672 + False + + + TRACE + + False + 4096 + True + ../bin/ + False + False + False + 4 + + + + False + 285212672 + False + + + TRACE;DEBUG + + True + 4096 + False + ../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 + {7404933D-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + OpenSim.Framework.Console + {16759386-0000-0000-0000-000000000000} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + False + + + + + Code + + + Code + + + Code + + + Code + + + + + + + + + + diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build index a25536e..111e2f7 100644 --- a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build +++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build @@ -1,47 +1,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs index 253c2d4..7aff434 100644 --- a/OpenGridServices.GridServer/SimProfiles.cs +++ b/OpenGridServices.GridServer/SimProfiles.cs @@ -33,7 +33,9 @@ using System.Collections; using System.Collections.Generic; using libsecondlife; using OpenSim.Framework.Utilities; +using OpenSim.Framework.Console; using OpenSim.Framework.Sims; +using Db4objects.Db4o; namespace OpenGridServices.GridServer { @@ -46,8 +48,15 @@ namespace OpenGridServices.GridServer public SimProfileManager() { } - public void InitSimProfiles() { - // TODO: need to load from database + 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) { -- cgit v1.1