aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenGridServices.GridServer
diff options
context:
space:
mode:
authorlbsa712007-04-11 20:07:58 +0000
committerlbsa712007-04-11 20:07:58 +0000
commit1a28ef6292a152a69d0f53803daacc7dad522cea (patch)
tree3d4e2eed288b208f1d0db7d37e8f1d9a1dfca1c5 /OpenGridServices.GridServer
parent* cleaning (diff)
downloadopensim-SC_OLD-1a28ef6292a152a69d0f53803daacc7dad522cea.zip
opensim-SC_OLD-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.gz
opensim-SC_OLD-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.bz2
opensim-SC_OLD-1a28ef6292a152a69d0f53803daacc7dad522cea.tar.xz
* Replaced GridHTTPServer and UserHTTPServer with BaseHttpServer
* Now dumping default value in config. *
Diffstat (limited to 'OpenGridServices.GridServer')
-rw-r--r--OpenGridServices.GridServer/GridHttp.cs307
-rw-r--r--OpenGridServices.GridServer/Main.cs132
-rw-r--r--OpenGridServices.GridServer/OpenGridServices.GridServer.csproj3
-rw-r--r--OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build1
-rw-r--r--OpenGridServices.GridServer/SimProfiles.cs196
5 files changed, 256 insertions, 383 deletions
diff --git a/OpenGridServices.GridServer/GridHttp.cs b/OpenGridServices.GridServer/GridHttp.cs
deleted file mode 100644
index 9e9246d..0000000
--- a/OpenGridServices.GridServer/GridHttp.cs
+++ /dev/null
@@ -1,307 +0,0 @@
1/*
2Copyright (c) OpenGrid project, http://osgrid.org/
3
4
5* All rights reserved.
6*
7* Redistribution and use in source and binary forms, with or without
8* modification, are permitted provided that the following conditions are met:
9* * Redistributions of source code must retain the above copyright
10* notice, this list of conditions and the following disclaimer.
11* * Redistributions in binary form must reproduce the above copyright
12* notice, this list of conditions and the following disclaimer in the
13* documentation and/or other materials provided with the distribution.
14* * Neither the name of the <organization> nor the
15* names of its contributors may be used to endorse or promote products
16* derived from this software without specific prior written permission.
17*
18* THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY
19* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21* DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
22* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*/
29
30using System;
31using System.Text;
32using Nwc.XmlRpc;
33using System.Threading;
34using System.Text.RegularExpressions;
35using System.Net;
36using System.Xml;
37using System.IO;
38using System.Collections;
39using System.Collections.Generic;
40using libsecondlife;
41using OpenSim.Framework.Sims;
42using OpenSim.Framework.Console;
43using OpenSim.Servers;
44
45namespace OpenGridServices.GridServer
46{
47 public class GridHTTPServer : BaseHttpServer {
48 public Thread HTTPD;
49 public HttpListener Listener;
50
51 public GridHTTPServer() : base( 8001 ) {
52 Start();
53 }
54
55 public void Start()
56 {
57 MainConsole.Instance.WriteLine("Starting up HTTP Server");
58 HTTPD = new Thread(new ThreadStart(StartHTTP));
59 HTTPD.Start();
60 }
61
62 public void StartHTTP() {
63 MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Spawned main thread OK");
64 Listener = new HttpListener();
65
66 Listener.Prefixes.Add("http://+:8001/");
67 Listener.Prefixes.Add("http://+:8001/sims/");
68 Listener.Prefixes.Add("http://+:8001/gods/");
69 Listener.Prefixes.Add("http://+:8001/highestuuid/");
70 Listener.Prefixes.Add("http://+:8001/uuidblocks/");
71 Listener.Start();
72
73 MainConsole.Instance.WriteLine("GridHttp.cs:StartHTTP() - Successfully bound to port 8001");
74
75 HttpListenerContext context;
76 while(true) {
77 context = Listener.GetContext();
78 ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), context);
79 }
80 }
81
82 static string ParseXMLRPC(string requestBody, string referrer) {
83 try{
84 XmlRpcRequest request = (XmlRpcRequest)(new XmlRpcRequestDeserializer()).Deserialize(requestBody);
85
86 Hashtable requestData = (Hashtable)request.Params[0];
87 switch(request.MethodName) {
88 case "simulator_login":
89
90 /*if(!((string)requestData["authkey"]==OpenGrid_Main.thegrid.SimRecvKey)) {
91 XmlRpcResponse ErrorResp = new XmlRpcResponse();
92 Hashtable ErrorRespData = new Hashtable();
93 ErrorRespData["error"]="invalid key";
94 ErrorResp.Value=ErrorRespData;
95 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8"));
96 }*/
97 SimProfileBase TheSim = null;
98
99 if(requestData.ContainsKey("UUID")) {
100 TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(new LLUUID((string)requestData["UUID"]));
101 } else if (requestData.ContainsKey("region_handle")){
102 TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"]));
103 }
104
105 if(TheSim==null) {
106 XmlRpcResponse ErrorResp = new XmlRpcResponse();
107 Hashtable ErrorRespData = new Hashtable();
108 ErrorRespData["error"]="sim not found";
109 ErrorResp.Value=ErrorRespData;
110 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(ErrorResp),"utf-16","utf-8"));
111 }
112
113 XmlRpcResponse SimLoginResp = new XmlRpcResponse();
114 Hashtable SimLoginRespData = new Hashtable();
115
116 ArrayList SimNeighboursData = new ArrayList();
117
118 SimProfileBase neighbour;
119 Hashtable NeighbourBlock;
120 for(int x=-1; x<2; x++) for(int y=-1; y<2; y++) {
121 if(OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX+x)*256), (uint)(TheSim.RegionLocY+y)*256))!=null) {
122 neighbour=OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX+x)*256), (uint)(TheSim.RegionLocY+y)*256));
123 NeighbourBlock = new Hashtable();
124 NeighbourBlock["sim_ip"] = neighbour.sim_ip;
125 NeighbourBlock["sim_port"] = neighbour.sim_port.ToString();
126 NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString();
127 NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString();
128 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
129 SimNeighboursData.Add(NeighbourBlock);
130 }
131 }
132
133 SimLoginRespData["UUID"]=TheSim.UUID;
134 SimLoginRespData["region_locx"]=TheSim.RegionLocX.ToString();
135 SimLoginRespData["region_locy"]=TheSim.RegionLocY.ToString();
136 SimLoginRespData["regionname"]=TheSim.regionname;
137 SimLoginRespData["estate_id"]="1";
138 SimLoginRespData["neighbours"]=SimNeighboursData;
139 SimLoginRespData["asset_url"]=OpenGrid_Main.thegrid.DefaultAssetServer;
140 SimLoginRespData["asset_sendkey"]=OpenGrid_Main.thegrid.AssetSendKey;
141 SimLoginRespData["asset_recvkey"]=OpenGrid_Main.thegrid.AssetRecvKey;
142 SimLoginRespData["user_url"]=OpenGrid_Main.thegrid.DefaultUserServer;
143 SimLoginRespData["user_sendkey"]=OpenGrid_Main.thegrid.UserSendKey;
144 SimLoginRespData["user_recvkey"]=OpenGrid_Main.thegrid.UserRecvKey;
145 SimLoginRespData["authkey"]=OpenGrid_Main.thegrid.SimSendKey;
146 SimLoginResp.Value=SimLoginRespData;
147 return(Regex.Replace(XmlRpcResponseSerializer.Singleton.Serialize(SimLoginResp),"utf-16","utf-8"));
148 break;
149 }
150 } catch(Exception e) {
151 Console.WriteLine(e.ToString());
152 }
153 return "";
154 }
155
156 static string ParseREST(string requestURL, string requestBody, string HTTPmethod) {
157 char[] splitter = {'/'};
158 string[] rest_params = requestURL.Split(splitter);
159 string req_type = rest_params[0]; // First part of the URL is the type of request -
160 string respstring="";
161 SimProfileBase TheSim;
162 Console.WriteLine(req_type);
163 switch(req_type) {
164 case "regions":
165 // DIRTY HACK ALERT
166 Console.WriteLine("/regions/ accessed");
167 TheSim=OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
168 respstring=ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
169 break;
170
171 case "sims":
172 LLUUID UUID = new LLUUID((string)rest_params[1]);
173 TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByLLUUID(UUID);
174 if(!(TheSim==null)) {
175 switch(HTTPmethod) {
176 case "GET":
177 respstring="<authkey>" + OpenGrid_Main.thegrid.SimSendKey + "</authkey>";
178 respstring+="<sim>";
179 respstring+="<uuid>" + TheSim.UUID.ToString() + "</uuid>";
180 respstring+="<regionname>" + TheSim.regionname + "</regionname>";
181 respstring+="<sim_ip>" + TheSim.sim_ip + "</sim_ip>";
182 respstring+="<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>";
183 respstring+="<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>";
184 respstring+="<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
185 respstring+="<estate_id>1</estate_id>";
186 respstring+="</sim>";
187 break;
188 case "POST":
189 Console.WriteLine("Updating sim details.....");
190 XmlDocument doc = new XmlDocument();
191 doc.LoadXml(requestBody);
192 XmlNode authkeynode = doc.FirstChild;
193 if (authkeynode.Name != "authkey") {
194 respstring = "ERROR! bad XML - expected authkey tag";
195 return respstring;
196 }
197 XmlNode simnode = doc.ChildNodes[1];
198 if (simnode.Name != "sim") {
199 respstring = "ERROR! bad XML - expected sim tag";
200 return respstring;
201 }
202 if (authkeynode.Name != OpenGrid_Main.thegrid.SimRecvKey) {
203 respstring = "ERROR! invalid key";
204 return respstring;
205 }
206
207 if (TheSim==null) {
208 respstring="ERROR! sim not found";
209 return respstring;
210 } else {
211 for(int i=0; i<= simnode.ChildNodes.Count; i++) {
212 switch(simnode.ChildNodes[i].Name) {
213 case "uuid":
214 // should a sim be able to update it's own UUID? To be decided
215 // watch next week for the exciting conclusion in "the adventures of OpenGridServices.GridServer/GridHttp.cs:ParseREST() at line 190!
216 break; // and line 190's arch-enemy - THE BREAK STATEMENT! OH NOES!!!!! (this code written at 6:57AM, no sleep, lots of caffeine)
217
218 case "regionname":
219 TheSim.regionname=simnode.ChildNodes[i].InnerText;
220 break;
221
222 case "sim_ip":
223 TheSim.sim_ip=simnode.ChildNodes[i].InnerText;
224 break;
225
226 case "sim_port":
227 TheSim.sim_port=Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
228 break;
229
230 case "region_locx":
231 TheSim.RegionLocX=Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
232 TheSim.regionhandle=Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
233 break;
234
235 case "region_locy":
236 TheSim.RegionLocY=Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
237 TheSim.regionhandle=Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
238 break;
239 }
240 }
241 respstring="OK";
242 }
243
244
245
246 break;
247 }
248 }
249 return respstring;
250 break;
251 }
252 return "";
253
254 }
255
256
257 static void HandleRequest(Object stateinfo) {
258 HttpListenerContext context=(HttpListenerContext)stateinfo;
259
260 HttpListenerRequest request = context.Request;
261 HttpListenerResponse response = context.Response;
262
263 response.KeepAlive=false;
264 response.SendChunked=false;
265
266 System.IO.Stream body = request.InputStream;
267 System.Text.Encoding encoding = System.Text.Encoding.UTF8;
268 System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
269
270 string requestBody = reader.ReadToEnd();
271 body.Close();
272 reader.Close();
273
274 // TODO: AUTHENTICATION!!!!!!!!! MUST ADD!!!!!!!!!! SCRIPT KIDDIES LOVE LACK OF IT!!!!!!!!!!
275
276 string responseString="";
277 switch(request.ContentType) {
278 case "text/xml":
279 // must be XML-RPC, so pass to the XML-RPC parser
280
281 responseString=ParseXMLRPC(requestBody,request.Headers["Referer"]);
282 response.AddHeader("Content-type","text/xml");
283 break;
284
285 case "text/plaintext":
286 // must be REST
287 responseString=ParseREST(request.RawUrl,requestBody,request.HttpMethod);
288 break;
289
290 case null:
291 // must be REST or invalid crap, so pass to the REST parser
292 responseString=ParseREST(request.RawUrl,requestBody,request.HttpMethod);
293 break;
294 }
295
296
297 byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
298 System.IO.Stream output = response.OutputStream;
299 response.SendChunked=false;
300 response.ContentLength64=buffer.Length;
301 output.Write(buffer,0,buffer.Length);
302 output.Close();
303 }
304 }
305
306
307}
diff --git a/OpenGridServices.GridServer/Main.cs b/OpenGridServices.GridServer/Main.cs
index 8c83bbf..5827227 100644
--- a/OpenGridServices.GridServer/Main.cs
+++ b/OpenGridServices.GridServer/Main.cs
@@ -38,16 +38,19 @@ using OpenSim.Framework;
38using OpenSim.Framework.Sims; 38using OpenSim.Framework.Sims;
39using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
40using OpenSim.Framework.Interfaces; 40using OpenSim.Framework.Interfaces;
41using OpenSim.Servers;
41 42
42namespace OpenGridServices.GridServer 43namespace OpenGridServices.GridServer
43{ 44{
44 /// <summary> 45 /// <summary>
45 /// </summary> 46 /// </summary>
46 public class OpenGrid_Main : conscmd_callback 47 public class OpenGrid_Main : BaseServer, conscmd_callback
47 { 48 {
48 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll"; 49 private string ConfigDll = "OpenGrid.Config.GridConfigDb4o.dll";
49 private GridConfig Cfg; 50 private GridConfig Cfg;
51
50 public static OpenGrid_Main thegrid; 52 public static OpenGrid_Main thegrid;
53
51 public string GridOwner; 54 public string GridOwner;
52 public string DefaultStartupMsg; 55 public string DefaultStartupMsg;
53 public string DefaultAssetServer; 56 public string DefaultAssetServer;
@@ -56,16 +59,14 @@ namespace OpenGridServices.GridServer
56 public string DefaultUserServer; 59 public string DefaultUserServer;
57 public string UserSendKey; 60 public string UserSendKey;
58 public string UserRecvKey; 61 public string UserRecvKey;
59 public string SimSendKey; 62 public string SimSendKey;
60 public string SimRecvKey; 63 public string SimRecvKey;
61 public LLUUID highestUUID; 64 //public LLUUID highestUUID;
62 65
63 public GridHTTPServer _httpd; 66 private SimProfileManager m_simProfileManager;
64 public SimProfileManager _regionmanager;
65 67
66 private ConsoleBase m_console; 68 private ConsoleBase m_console;
67 private Timer SimCheckTimer; 69
68
69 [STAThread] 70 [STAThread]
70 public static void Main(string[] args) 71 public static void Main(string[] args)
71 { 72 {
@@ -92,29 +93,49 @@ namespace OpenGridServices.GridServer
92 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this); 93 m_console = new ConsoleBase("opengrid-gridserver-console.log", "OpenGrid", this);
93 MainConsole.Instance = m_console; 94 MainConsole.Instance = m_console;
94 } 95 }
95 96
96 public void Startup() 97 public void Startup()
97 { 98 {
98 m_console.WriteLine("Main.cs:Startup() - Loading configuration"); 99 m_console.WriteLine("Main.cs:Startup() - Loading configuration");
99 Cfg = this.LoadConfigDll(this.ConfigDll); 100 Cfg = this.LoadConfigDll(this.ConfigDll);
100 Cfg.InitConfig(); 101 Cfg.InitConfig();
101 102
102 m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database"); 103 m_console.WriteLine("Main.cs:Startup() - Loading sim profiles from database");
103 this._regionmanager = new SimProfileManager(); 104 m_simProfileManager = new SimProfileManager( this );
104 _regionmanager.LoadProfiles(); 105 m_simProfileManager.LoadProfiles();
106
107 m_console.WriteLine("Main.cs:Startup() - Starting HTTP process");
108 BaseHttpServer httpServer = new BaseHttpServer(8001);
105 109
106 m_console.WriteLine("Main.cs:Startup() - Starting HTTP process"); 110 httpServer.AddXmlRPCHandler("simulator_login", m_simProfileManager.XmlRpcLoginToSimulatorMethod);
107 _httpd = new GridHTTPServer();
108 _httpd.Start();
109 111
110 m_console.WriteLine("Main.cs:Startup() - Starting sim status checker"); 112 httpServer.AddRestHandler("GET", "/sims/", m_simProfileManager.RestGetSimMethod);
111 SimCheckTimer = new Timer(); 113 httpServer.AddRestHandler("POST", "/sims/", m_simProfileManager.RestSetSimMethod);
112 SimCheckTimer.Interval = 300000; // 5 minutes 114
113 SimCheckTimer.Elapsed+=new ElapsedEventHandler(CheckSims); 115 // lbsa71 : This code snippet taken from old http server.
114 SimCheckTimer.Enabled=true; 116 // I have no idea what this was supposed to do - looks like an infinite recursion to me.
117 // case "regions":
118 //// DIRTY HACK ALERT
119 //Console.WriteLine("/regions/ accessed");
120 //TheSim = OpenGrid_Main.thegrid._regionmanager.GetProfileByHandle((ulong)Convert.ToUInt64(rest_params[1]));
121 //respstring = ParseREST("/regions/" + rest_params[1], requestBody, HTTPmethod);
122 //break;
123
124 // lbsa71 : I guess these were never used?
125 //Listener.Prefixes.Add("http://+:8001/gods/");
126 //Listener.Prefixes.Add("http://+:8001/highestuuid/");
127 //Listener.Prefixes.Add("http://+:8001/uuidblocks/");
128
129 httpServer.Start();
130
131 m_console.WriteLine("Main.cs:Startup() - Starting sim status checker");
132
133 Timer simCheckTimer = new Timer( 300000 ); // 5 minutes
134 simCheckTimer.Elapsed += new ElapsedEventHandler(CheckSims);
135 simCheckTimer.Enabled = true;
115 } 136 }
116 137
117 private GridConfig LoadConfigDll(string dllName) 138 private GridConfig LoadConfigDll(string dllName)
118 { 139 {
119 Assembly pluginAssembly = Assembly.LoadFrom(dllName); 140 Assembly pluginAssembly = Assembly.LoadFrom(dllName);
120 GridConfig config = null; 141 GridConfig config = null;
@@ -142,33 +163,42 @@ namespace OpenGridServices.GridServer
142 return config; 163 return config;
143 } 164 }
144 165
145 public void CheckSims(object sender, ElapsedEventArgs e) { 166 public void CheckSims(object sender, ElapsedEventArgs e)
146 foreach(SimProfileBase sim in _regionmanager.SimProfiles.Values) { 167 {
147 string SimResponse=""; 168 foreach (SimProfileBase sim in m_simProfileManager.SimProfiles.Values)
148 try { 169 {
149 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/"); 170 string SimResponse = "";
150 CheckSim.Method = "GET"; 171 try
151 CheckSim.ContentType = "text/plaintext"; 172 {
152 CheckSim.ContentLength = 0; 173 WebRequest CheckSim = WebRequest.Create("http://" + sim.sim_ip + ":" + sim.sim_port.ToString() + "/checkstatus/");
153 174 CheckSim.Method = "GET";
154 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII); 175 CheckSim.ContentType = "text/plaintext";
155 stOut.Write(""); 176 CheckSim.ContentLength = 0;
156 stOut.Close(); 177
157 178 StreamWriter stOut = new StreamWriter(CheckSim.GetRequestStream(), System.Text.Encoding.ASCII);
158 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream()); 179 stOut.Write("");
159 SimResponse = stIn.ReadToEnd(); 180 stOut.Close();
160 stIn.Close(); 181
161 } catch(Exception exception) { 182 StreamReader stIn = new StreamReader(CheckSim.GetResponse().GetResponseStream());
162 } 183 SimResponse = stIn.ReadToEnd();
163 if(SimResponse=="OK") { 184 stIn.Close();
164 _regionmanager.SimProfiles[sim.UUID].online=true; 185 }
165 } else { 186 catch
166 _regionmanager.SimProfiles[sim.UUID].online=false; 187 {
167 } 188 }
168 } 189
169 } 190 if (SimResponse == "OK")
170 191 {
171 public void RunCmd(string cmd, string[] cmdparams) 192 m_simProfileManager.SimProfiles[sim.UUID].online = true;
193 }
194 else
195 {
196 m_simProfileManager.SimProfiles[sim.UUID].online = false;
197 }
198 }
199 }
200
201 public void RunCmd(string cmd, string[] cmdparams)
172 { 202 {
173 switch (cmd) 203 switch (cmd)
174 { 204 {
diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj
index 2ce4c00..808886e 100644
--- a/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj
+++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.csproj
@@ -100,9 +100,6 @@
100 </ProjectReference> 100 </ProjectReference>
101 </ItemGroup> 101 </ItemGroup>
102 <ItemGroup> 102 <ItemGroup>
103 <Compile Include="GridHttp.cs">
104 <SubType>Code</SubType>
105 </Compile>
106 <Compile Include="Main.cs"> 103 <Compile Include="Main.cs">
107 <SubType>Code</SubType> 104 <SubType>Code</SubType>
108 </Compile> 105 </Compile>
diff --git a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build
index ece9986..316ebb3 100644
--- a/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build
+++ b/OpenGridServices.GridServer/OpenGridServices.GridServer.exe.build
@@ -11,7 +11,6 @@
11 <resources prefix="OpenGridServices.GridServer" dynamicprefix="true" > 11 <resources prefix="OpenGridServices.GridServer" dynamicprefix="true" >
12 </resources> 12 </resources>
13 <sources failonempty="true"> 13 <sources failonempty="true">
14 <include name="GridHttp.cs" />
15 <include name="Main.cs" /> 14 <include name="Main.cs" />
16 <include name="SimProfiles.cs" /> 15 <include name="SimProfiles.cs" />
17 <include name="Properties/AssemblyInfo.cs" /> 16 <include name="Properties/AssemblyInfo.cs" />
diff --git a/OpenGridServices.GridServer/SimProfiles.cs b/OpenGridServices.GridServer/SimProfiles.cs
index 7aff434..fd4ba99 100644
--- a/OpenGridServices.GridServer/SimProfiles.cs
+++ b/OpenGridServices.GridServer/SimProfiles.cs
@@ -36,6 +36,8 @@ using OpenSim.Framework.Utilities;
36using OpenSim.Framework.Console; 36using OpenSim.Framework.Console;
37using OpenSim.Framework.Sims; 37using OpenSim.Framework.Sims;
38using Db4objects.Db4o; 38using Db4objects.Db4o;
39using Nwc.XmlRpc;
40using System.Xml;
39 41
40namespace OpenGridServices.GridServer 42namespace OpenGridServices.GridServer
41{ 43{
@@ -44,9 +46,11 @@ namespace OpenGridServices.GridServer
44 public class SimProfileManager { 46 public class SimProfileManager {
45 47
46 public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>(); 48 public Dictionary<LLUUID, SimProfileBase> SimProfiles = new Dictionary<LLUUID, SimProfileBase>();
49 private OpenGrid_Main m_gridManager;
47 50
48 public SimProfileManager() { 51 public SimProfileManager(OpenGrid_Main gridManager) {
49 } 52 m_gridManager = gridManager;
53 }
50 54
51 public void LoadProfiles() { // should abstract this out 55 public void LoadProfiles() { // should abstract this out
52 IObjectContainer db; 56 IObjectContainer db;
@@ -117,26 +121,176 @@ namespace OpenGridServices.GridServer
117 return newprofile; 121 return newprofile;
118 } 122 }
119 123
124 public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request)
125 {
126 XmlRpcResponse response = new XmlRpcResponse();
127 Hashtable responseData = new Hashtable();
128 response.Value = responseData;
129
130 SimProfileBase TheSim = null;
131 Hashtable requestData = (Hashtable)request.Params[0];
132
133 if (requestData.ContainsKey("UUID"))
134 {
135 TheSim = GetProfileByLLUUID(new LLUUID((string)requestData["UUID"]));
136 }
137 else if (requestData.ContainsKey("region_handle"))
138 {
139 TheSim = GetProfileByHandle((ulong)Convert.ToUInt64(requestData["region_handle"]));
140 }
141
142 if (TheSim == null)
143 {
144 responseData["error"] = "sim not found";
145 }
146 else
147 {
148
149 ArrayList SimNeighboursData = new ArrayList();
150
151 SimProfileBase neighbour;
152 Hashtable NeighbourBlock;
153 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
154 {
155 if (GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256)) != null)
156 {
157 neighbour = GetProfileByHandle(Helpers.UIntsToLong((uint)((TheSim.RegionLocX + x) * 256), (uint)(TheSim.RegionLocY + y) * 256));
158 NeighbourBlock = new Hashtable();
159 NeighbourBlock["sim_ip"] = neighbour.sim_ip;
160 NeighbourBlock["sim_port"] = neighbour.sim_port.ToString();
161 NeighbourBlock["region_locx"] = neighbour.RegionLocX.ToString();
162 NeighbourBlock["region_locy"] = neighbour.RegionLocY.ToString();
163 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
164 SimNeighboursData.Add(NeighbourBlock);
165 }
166 }
167
168 responseData["UUID"] = TheSim.UUID;
169 responseData["region_locx"] = TheSim.RegionLocX.ToString();
170 responseData["region_locy"] = TheSim.RegionLocY.ToString();
171 responseData["regionname"] = TheSim.regionname;
172 responseData["estate_id"] = "1";
173 responseData["neighbours"] = SimNeighboursData;
174
175 responseData["asset_url"] = m_gridManager.DefaultAssetServer;
176 responseData["asset_sendkey"] = m_gridManager.AssetSendKey;
177 responseData["asset_recvkey"] = m_gridManager.AssetRecvKey;
178 responseData["user_url"] = m_gridManager.DefaultUserServer;
179 responseData["user_sendkey"] = m_gridManager.UserSendKey;
180 responseData["user_recvkey"] = m_gridManager.UserRecvKey;
181 responseData["authkey"] = m_gridManager.SimSendKey;
182 }
183
184 return response;
185 }
186
187 public string RestSetSimMethod(string request, string path, string param)
188 {
189 string respstring = String.Empty;
190
191 SimProfileBase TheSim;
192 LLUUID UUID = new LLUUID(param);
193 TheSim = GetProfileByLLUUID(UUID);
194
195 if (!(TheSim == null))
196 {
197 Console.WriteLine("Updating sim details.....");
198 XmlDocument doc = new XmlDocument();
199 doc.LoadXml(request);
200 XmlNode authkeynode = doc.FirstChild;
201 if (authkeynode.Name != "authkey")
202 {
203 respstring = "ERROR! bad XML - expected authkey tag";
204 }
205 else
206 {
207 XmlNode simnode = doc.ChildNodes[1];
208 if (simnode.Name != "sim")
209 {
210 respstring = "ERROR! bad XML - expected sim tag";
211 }
212 else
213 {
214 if (authkeynode.Name != m_gridManager.SimRecvKey)
215 {
216 respstring = "ERROR! invalid key";
217 }
218 else
219 {
220 if (TheSim == null)
221 {
222 respstring = "ERROR! sim not found";
223 }
224 else
225 {
226 for (int i = 0; i <= simnode.ChildNodes.Count; i++)
227 {
228 switch (simnode.ChildNodes[i].Name)
229 {
230 case "uuid":
231 // should a sim be able to update it's own UUID? To be decided
232 // watch next week for the exciting conclusion in "the adventures of OpenGridServices.GridServer/GridHttp.cs:ParseREST() at line 190!
233 break; // and line 190's arch-enemy - THE BREAK STATEMENT! OH NOES!!!!! (this code written at 6:57AM, no sleep, lots of caffeine)
234
235 case "regionname":
236 TheSim.regionname = simnode.ChildNodes[i].InnerText;
237 break;
238
239 case "sim_ip":
240 TheSim.sim_ip = simnode.ChildNodes[i].InnerText;
241 break;
242
243 case "sim_port":
244 TheSim.sim_port = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
245 break;
246
247 case "region_locx":
248 TheSim.RegionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
249 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
250 break;
251
252 case "region_locy":
253 TheSim.RegionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
254 TheSim.regionhandle = Helpers.UIntsToLong((TheSim.RegionLocX * 256), (TheSim.RegionLocY * 256));
255 break;
256 }
257 }
258 respstring = "OK";
259 }
260 }
261 }
262 }
263 }
264
265 return respstring;
266 }
267
268 public string RestGetSimMethod(string request, string path, string param )
269 {
270 string respstring = String.Empty;
271
272 SimProfileBase TheSim;
273 LLUUID UUID = new LLUUID(param);
274 TheSim = GetProfileByLLUUID(UUID);
275
276 if (!(TheSim == null))
277 {
278 respstring = "<authkey>" + m_gridManager.SimSendKey + "</authkey>";
279 respstring += "<sim>";
280 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
281 respstring += "<regionname>" + TheSim.regionname + "</regionname>";
282 respstring += "<sim_ip>" + TheSim.sim_ip + "</sim_ip>";
283 respstring += "<sim_port>" + TheSim.sim_port.ToString() + "</sim_port>";
284 respstring += "<region_locx>" + TheSim.RegionLocX.ToString() + "</region_locx>";
285 respstring += "<region_locy>" + TheSim.RegionLocY.ToString() + "</region_locy>";
286 respstring += "<estate_id>1</estate_id>";
287 respstring += "</sim>";
288 }
289
290 return respstring;
291 }
292
120 } 293 }
121 294
122 /* is in OpenSim.Framework
123 public class SimProfileBase {
124 public LLUUID UUID;
125 public ulong regionhandle;
126 public string regionname;
127 public string sim_ip;
128 public uint sim_port;
129 public string caps_url;
130 public uint RegionLocX;
131 public uint RegionLocY;
132 public string sendkey;
133 public string recvkey;
134
135
136 public SimProfileBase() {
137 }
138
139
140 }*/
141 295
142} 296}