diff options
Diffstat (limited to 'OpenSim/Grid/GridServer/GridManager.cs')
-rw-r--r-- | OpenSim/Grid/GridServer/GridManager.cs | 599 |
1 files changed, 599 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs new file mode 100644 index 0000000..c78d14a --- /dev/null +++ b/OpenSim/Grid/GridServer/GridManager.cs | |||
@@ -0,0 +1,599 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Text; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework.Data; | ||
34 | using OpenSim.Framework.Utilities; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Framework.Sims; | ||
37 | using libsecondlife; | ||
38 | using Nwc.XmlRpc; | ||
39 | using System.Xml; | ||
40 | |||
41 | namespace OpenSim.Grid.GridServer | ||
42 | { | ||
43 | class GridManager | ||
44 | { | ||
45 | Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>(); | ||
46 | Dictionary<string, ILogData> _logplugins = new Dictionary<string, ILogData>(); | ||
47 | |||
48 | public OpenSim.Framework.Interfaces.GridConfig config; | ||
49 | |||
50 | /// <summary> | ||
51 | /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded. | ||
52 | /// </summary> | ||
53 | /// <param name="FileName">The filename to the grid server plugin DLL</param> | ||
54 | public void AddPlugin(string FileName) | ||
55 | { | ||
56 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Attempting to load " + FileName); | ||
57 | Assembly pluginAssembly = Assembly.LoadFrom(FileName); | ||
58 | |||
59 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces."); | ||
60 | foreach (Type pluginType in pluginAssembly.GetTypes()) | ||
61 | { | ||
62 | if (!pluginType.IsAbstract) | ||
63 | { | ||
64 | // Regions go here | ||
65 | Type typeInterface = pluginType.GetInterface("IGridData", true); | ||
66 | |||
67 | if (typeInterface != null) | ||
68 | { | ||
69 | IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
70 | plug.Initialise(); | ||
71 | this._plugins.Add(plug.getName(), plug); | ||
72 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Storage: Added IGridData Interface"); | ||
73 | } | ||
74 | |||
75 | typeInterface = null; | ||
76 | |||
77 | // Logs go here | ||
78 | typeInterface = pluginType.GetInterface("ILogData", true); | ||
79 | |||
80 | if (typeInterface != null) | ||
81 | { | ||
82 | ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString())); | ||
83 | plug.Initialise(); | ||
84 | this._logplugins.Add(plug.getName(), plug); | ||
85 | OpenSim.Framework.Console.MainLog.Instance.Verbose( "Storage: Added ILogData Interface"); | ||
86 | } | ||
87 | |||
88 | typeInterface = null; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | pluginAssembly = null; | ||
93 | } | ||
94 | |||
95 | /// <summary> | ||
96 | /// Logs a piece of information to the database | ||
97 | /// </summary> | ||
98 | /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param> | ||
99 | /// <param name="method">Which method is being called?</param> | ||
100 | /// <param name="args">What arguments are being passed?</param> | ||
101 | /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param> | ||
102 | /// <param name="message">The message to log</param> | ||
103 | private void logToDB(string target, string method, string args, int priority, string message) | ||
104 | { | ||
105 | foreach (KeyValuePair<string, ILogData> kvp in _logplugins) | ||
106 | { | ||
107 | try | ||
108 | { | ||
109 | kvp.Value.saveLog("Gridserver", target, method, args, priority, message); | ||
110 | } | ||
111 | catch (Exception e) | ||
112 | { | ||
113 | OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: unable to write log via " + kvp.Key); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// Returns a region by argument | ||
120 | /// </summary> | ||
121 | /// <param name="uuid">A UUID key of the region to return</param> | ||
122 | /// <returns>A SimProfileData for the region</returns> | ||
123 | public SimProfileData getRegion(libsecondlife.LLUUID uuid) | ||
124 | { | ||
125 | foreach(KeyValuePair<string,IGridData> kvp in _plugins) { | ||
126 | try | ||
127 | { | ||
128 | return kvp.Value.GetProfileByLLUUID(uuid); | ||
129 | } | ||
130 | catch (Exception e) | ||
131 | { | ||
132 | OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to find region " + uuid.ToStringHyphenated() + " via " + kvp.Key); | ||
133 | } | ||
134 | } | ||
135 | return null; | ||
136 | } | ||
137 | |||
138 | /// <summary> | ||
139 | /// Returns a region by argument | ||
140 | /// </summary> | ||
141 | /// <param name="uuid">A regionHandle of the region to return</param> | ||
142 | /// <returns>A SimProfileData for the region</returns> | ||
143 | public SimProfileData getRegion(ulong handle) | ||
144 | { | ||
145 | foreach (KeyValuePair<string, IGridData> kvp in _plugins) | ||
146 | { | ||
147 | try | ||
148 | { | ||
149 | return kvp.Value.GetProfileByHandle(handle); | ||
150 | } | ||
151 | catch (Exception e) | ||
152 | { | ||
153 | OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to find region " + handle.ToString() + " via " + kvp.Key); | ||
154 | } | ||
155 | } | ||
156 | return null; | ||
157 | } | ||
158 | |||
159 | public Dictionary<ulong, SimProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax) | ||
160 | { | ||
161 | Dictionary<ulong, SimProfileData> regions = new Dictionary<ulong, SimProfileData>(); | ||
162 | |||
163 | SimProfileData[] neighbours; | ||
164 | |||
165 | foreach (KeyValuePair<string, IGridData> kvp in _plugins) | ||
166 | { | ||
167 | try | ||
168 | { | ||
169 | neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax); | ||
170 | foreach (SimProfileData neighbour in neighbours) | ||
171 | { | ||
172 | regions[neighbour.regionHandle] = neighbour; | ||
173 | } | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to query regionblock via " + kvp.Key); | ||
178 | } | ||
179 | } | ||
180 | |||
181 | return regions; | ||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Returns a XML String containing a list of the neighbouring regions | ||
186 | /// </summary> | ||
187 | /// <param name="reqhandle">The regionhandle for the center sim</param> | ||
188 | /// <returns>An XML string containing neighbour entities</returns> | ||
189 | public string GetXMLNeighbours(ulong reqhandle) | ||
190 | { | ||
191 | string response = ""; | ||
192 | SimProfileData central_region = getRegion(reqhandle); | ||
193 | SimProfileData neighbour; | ||
194 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) | ||
195 | { | ||
196 | if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null) | ||
197 | { | ||
198 | neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)); | ||
199 | response += "<neighbour>"; | ||
200 | response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>"; | ||
201 | response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>"; | ||
202 | response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>"; | ||
203 | response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>"; | ||
204 | response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>"; | ||
205 | response += "</neighbour>"; | ||
206 | |||
207 | } | ||
208 | } | ||
209 | return response; | ||
210 | } | ||
211 | |||
212 | /// <summary> | ||
213 | /// Performed when a region connects to the grid server initially. | ||
214 | /// </summary> | ||
215 | /// <param name="request">The XMLRPC Request</param> | ||
216 | /// <returns>Startup parameters</returns> | ||
217 | public XmlRpcResponse XmlRpcLoginToSimulatorMethod(XmlRpcRequest request) | ||
218 | { | ||
219 | XmlRpcResponse response = new XmlRpcResponse(); | ||
220 | Hashtable responseData = new Hashtable(); | ||
221 | response.Value = responseData; | ||
222 | |||
223 | SimProfileData TheSim = null; | ||
224 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
225 | |||
226 | if (requestData.ContainsKey("UUID")) | ||
227 | { | ||
228 | TheSim = getRegion(new LLUUID((string)requestData["UUID"])); | ||
229 | logToDB((new LLUUID((string)requestData["UUID"])).ToStringHyphenated(),"XmlRpcLoginToSimulatorMethod","", 5,"Region attempting login with UUID."); | ||
230 | } | ||
231 | else if (requestData.ContainsKey("region_handle")) | ||
232 | { | ||
233 | TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"])); | ||
234 | logToDB((string)requestData["region_handle"], "XmlRpcLoginToSimulatorMethod", "", 5, "Region attempting login with regionHandle."); | ||
235 | } | ||
236 | else | ||
237 | { | ||
238 | responseData["error"] = "No UUID or region_handle passed to grid server - unable to connect you"; | ||
239 | return response; | ||
240 | } | ||
241 | |||
242 | if (TheSim == null) | ||
243 | { | ||
244 | responseData["error"] = "sim not found"; | ||
245 | return response; | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | |||
250 | ArrayList SimNeighboursData = new ArrayList(); | ||
251 | |||
252 | SimProfileData neighbour; | ||
253 | Hashtable NeighbourBlock; | ||
254 | |||
255 | bool fastMode = false; // Only compatible with MySQL right now | ||
256 | |||
257 | if (fastMode) | ||
258 | { | ||
259 | Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1); | ||
260 | |||
261 | foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours) | ||
262 | { | ||
263 | NeighbourBlock = new Hashtable(); | ||
264 | NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString(); | ||
265 | NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString(); | ||
266 | NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString(); | ||
267 | NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString(); | ||
268 | NeighbourBlock["UUID"] = aSim.Value.UUID.ToString(); | ||
269 | |||
270 | if (aSim.Value.UUID != TheSim.UUID) | ||
271 | SimNeighboursData.Add(NeighbourBlock); | ||
272 | } | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) | ||
277 | { | ||
278 | if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null) | ||
279 | { | ||
280 | neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)); | ||
281 | |||
282 | NeighbourBlock = new Hashtable(); | ||
283 | NeighbourBlock["sim_ip"] = neighbour.serverIP; | ||
284 | NeighbourBlock["sim_port"] = neighbour.serverPort.ToString(); | ||
285 | NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString(); | ||
286 | NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString(); | ||
287 | NeighbourBlock["UUID"] = neighbour.UUID.ToString(); | ||
288 | |||
289 | if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | |||
294 | responseData["UUID"] = TheSim.UUID.ToString(); | ||
295 | responseData["region_locx"] = TheSim.regionLocX.ToString(); | ||
296 | responseData["region_locy"] = TheSim.regionLocY.ToString(); | ||
297 | responseData["regionname"] = TheSim.regionName; | ||
298 | responseData["estate_id"] = "1"; | ||
299 | responseData["neighbours"] = SimNeighboursData; | ||
300 | |||
301 | responseData["sim_ip"] = TheSim.serverIP; | ||
302 | responseData["sim_port"] = TheSim.serverPort.ToString(); | ||
303 | responseData["asset_url"] = TheSim.regionAssetURI; | ||
304 | responseData["asset_sendkey"] = TheSim.regionAssetSendKey; | ||
305 | responseData["asset_recvkey"] = TheSim.regionAssetRecvKey; | ||
306 | responseData["user_url"] = TheSim.regionUserURI; | ||
307 | responseData["user_sendkey"] = TheSim.regionUserSendKey; | ||
308 | responseData["user_recvkey"] = TheSim.regionUserRecvKey; | ||
309 | responseData["authkey"] = TheSim.regionSecret; | ||
310 | |||
311 | // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap) | ||
312 | responseData["data_uri"] = TheSim.regionDataURI; | ||
313 | } | ||
314 | |||
315 | return response; | ||
316 | } | ||
317 | |||
318 | public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request) | ||
319 | { | ||
320 | int xmin=980, ymin=980, xmax=1020, ymax=1020; | ||
321 | |||
322 | Hashtable requestData = (Hashtable)request.Params[0]; | ||
323 | if (requestData.ContainsKey("xmin")) | ||
324 | { | ||
325 | xmin = (Int32)requestData["xmin"]; | ||
326 | } | ||
327 | if (requestData.ContainsKey("ymin")) | ||
328 | { | ||
329 | ymin = (Int32)requestData["ymin"]; | ||
330 | } | ||
331 | if (requestData.ContainsKey("xmax")) | ||
332 | { | ||
333 | xmax = (Int32)requestData["xmax"]; | ||
334 | } | ||
335 | if (requestData.ContainsKey("ymax")) | ||
336 | { | ||
337 | ymax = (Int32)requestData["ymax"]; | ||
338 | } | ||
339 | |||
340 | XmlRpcResponse response = new XmlRpcResponse(); | ||
341 | Hashtable responseData = new Hashtable(); | ||
342 | response.Value = responseData; | ||
343 | IList simProfileList = new ArrayList(); | ||
344 | |||
345 | bool fastMode = true; // MySQL Only | ||
346 | |||
347 | if (fastMode) | ||
348 | { | ||
349 | Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax); | ||
350 | |||
351 | foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours) | ||
352 | { | ||
353 | Hashtable simProfileBlock = new Hashtable(); | ||
354 | simProfileBlock["x"] = aSim.Value.regionLocX.ToString(); | ||
355 | simProfileBlock["y"] = aSim.Value.regionLocY.ToString(); | ||
356 | simProfileBlock["name"] = aSim.Value.regionName; | ||
357 | simProfileBlock["access"] = 21; | ||
358 | simProfileBlock["region-flags"] = 512; | ||
359 | simProfileBlock["water-height"] = 0; | ||
360 | simProfileBlock["agents"] = 1; | ||
361 | simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString(); | ||
362 | |||
363 | // For Sugilite compatibility | ||
364 | simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString(); | ||
365 | simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString(); | ||
366 | simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString(); | ||
367 | simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString(); | ||
368 | simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated(); | ||
369 | |||
370 | simProfileList.Add(simProfileBlock); | ||
371 | } | ||
372 | OpenSim.Framework.Console.MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode"); | ||
373 | } | ||
374 | else | ||
375 | { | ||
376 | SimProfileData simProfile; | ||
377 | for (int x = xmin; x < xmax; x++) | ||
378 | { | ||
379 | for (int y = ymin; y < ymax; y++) | ||
380 | { | ||
381 | simProfile = getRegion(Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256))); | ||
382 | if (simProfile != null) | ||
383 | { | ||
384 | Hashtable simProfileBlock = new Hashtable(); | ||
385 | simProfileBlock["x"] = x; | ||
386 | simProfileBlock["y"] = y; | ||
387 | simProfileBlock["name"] = simProfile.regionName; | ||
388 | simProfileBlock["access"] = 0; | ||
389 | simProfileBlock["region-flags"] = 0; | ||
390 | simProfileBlock["water-height"] = 20; | ||
391 | simProfileBlock["agents"] = 1; | ||
392 | simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToString(); | ||
393 | |||
394 | // For Sugilite compatibility | ||
395 | simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString(); | ||
396 | simProfileBlock["sim_ip"] = simProfile.serverIP.ToString(); | ||
397 | simProfileBlock["sim_port"] = simProfile.serverPort.ToString(); | ||
398 | simProfileBlock["sim_uri"] = simProfile.serverURI.ToString(); | ||
399 | simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated(); | ||
400 | |||
401 | simProfileList.Add(simProfileBlock); | ||
402 | } | ||
403 | } | ||
404 | } | ||
405 | OpenSim.Framework.Console.MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode"); | ||
406 | } | ||
407 | |||
408 | responseData["sim-profiles"] = simProfileList; | ||
409 | |||
410 | return response; | ||
411 | } | ||
412 | |||
413 | |||
414 | |||
415 | /// <summary> | ||
416 | /// Performs a REST Get Operation | ||
417 | /// </summary> | ||
418 | /// <param name="request"></param> | ||
419 | /// <param name="path"></param> | ||
420 | /// <param name="param"></param> | ||
421 | /// <returns></returns> | ||
422 | public string RestGetRegionMethod(string request, string path, string param) | ||
423 | { | ||
424 | return RestGetSimMethod("", "/sims/", param); | ||
425 | } | ||
426 | |||
427 | /// <summary> | ||
428 | /// Performs a REST Set Operation | ||
429 | /// </summary> | ||
430 | /// <param name="request"></param> | ||
431 | /// <param name="path"></param> | ||
432 | /// <param name="param"></param> | ||
433 | /// <returns></returns> | ||
434 | public string RestSetRegionMethod(string request, string path, string param) | ||
435 | { | ||
436 | return RestSetSimMethod("", "/sims/", param); | ||
437 | } | ||
438 | |||
439 | /// <summary> | ||
440 | /// Returns information about a sim via a REST Request | ||
441 | /// </summary> | ||
442 | /// <param name="request"></param> | ||
443 | /// <param name="path"></param> | ||
444 | /// <param name="param"></param> | ||
445 | /// <returns>Information about the sim in XML</returns> | ||
446 | public string RestGetSimMethod(string request, string path, string param) | ||
447 | { | ||
448 | string respstring = String.Empty; | ||
449 | |||
450 | SimProfileData TheSim; | ||
451 | LLUUID UUID = new LLUUID(param); | ||
452 | TheSim = getRegion(UUID); | ||
453 | |||
454 | if (!(TheSim == null)) | ||
455 | { | ||
456 | respstring = "<Root>"; | ||
457 | respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>"; | ||
458 | respstring += "<sim>"; | ||
459 | respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>"; | ||
460 | respstring += "<regionname>" + TheSim.regionName + "</regionname>"; | ||
461 | respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>"; | ||
462 | respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>"; | ||
463 | respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>"; | ||
464 | respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>"; | ||
465 | respstring += "<estate_id>1</estate_id>"; | ||
466 | respstring += "</sim>"; | ||
467 | respstring += "</Root>"; | ||
468 | } | ||
469 | |||
470 | return respstring; | ||
471 | } | ||
472 | |||
473 | /// <summary> | ||
474 | /// Creates or updates a sim via a REST Method Request | ||
475 | /// BROKEN with SQL Update | ||
476 | /// </summary> | ||
477 | /// <param name="request"></param> | ||
478 | /// <param name="path"></param> | ||
479 | /// <param name="param"></param> | ||
480 | /// <returns>"OK" or an error</returns> | ||
481 | public string RestSetSimMethod(string request, string path, string param) | ||
482 | { | ||
483 | Console.WriteLine("Processing region update"); | ||
484 | SimProfileData TheSim; | ||
485 | TheSim = getRegion(new LLUUID(param)); | ||
486 | if ((TheSim) == null) | ||
487 | { | ||
488 | TheSim = new SimProfileData(); | ||
489 | LLUUID UUID = new LLUUID(param); | ||
490 | TheSim.UUID = UUID; | ||
491 | TheSim.regionRecvKey = config.SimRecvKey; | ||
492 | } | ||
493 | |||
494 | XmlDocument doc = new XmlDocument(); | ||
495 | doc.LoadXml(request); | ||
496 | XmlNode rootnode = doc.FirstChild; | ||
497 | XmlNode authkeynode = rootnode.ChildNodes[0]; | ||
498 | if (authkeynode.Name != "authkey") | ||
499 | { | ||
500 | return "ERROR! bad XML - expected authkey tag"; | ||
501 | } | ||
502 | |||
503 | XmlNode simnode = rootnode.ChildNodes[1]; | ||
504 | if (simnode.Name != "sim") | ||
505 | { | ||
506 | return "ERROR! bad XML - expected sim tag"; | ||
507 | } | ||
508 | |||
509 | if (authkeynode.InnerText != TheSim.regionRecvKey) | ||
510 | { | ||
511 | return "ERROR! invalid key"; | ||
512 | } | ||
513 | |||
514 | //TheSim.regionSendKey = Cfg; | ||
515 | TheSim.regionRecvKey = config.SimRecvKey; | ||
516 | TheSim.regionSendKey = config.SimSendKey; | ||
517 | TheSim.regionSecret = config.SimRecvKey; | ||
518 | TheSim.regionDataURI = ""; | ||
519 | TheSim.regionAssetURI = config.DefaultAssetServer; | ||
520 | TheSim.regionAssetRecvKey = config.AssetRecvKey; | ||
521 | TheSim.regionAssetSendKey = config.AssetSendKey; | ||
522 | TheSim.regionUserURI = config.DefaultUserServer; | ||
523 | TheSim.regionUserSendKey = config.UserSendKey; | ||
524 | TheSim.regionUserRecvKey = config.UserRecvKey; | ||
525 | |||
526 | |||
527 | for (int i = 0; i < simnode.ChildNodes.Count; i++) | ||
528 | { | ||
529 | switch (simnode.ChildNodes[i].Name) | ||
530 | { | ||
531 | case "regionname": | ||
532 | TheSim.regionName = simnode.ChildNodes[i].InnerText; | ||
533 | break; | ||
534 | |||
535 | case "sim_ip": | ||
536 | TheSim.serverIP = simnode.ChildNodes[i].InnerText; | ||
537 | break; | ||
538 | |||
539 | case "sim_port": | ||
540 | TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText); | ||
541 | break; | ||
542 | |||
543 | case "region_locx": | ||
544 | TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
545 | TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); | ||
546 | break; | ||
547 | |||
548 | case "region_locy": | ||
549 | TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText); | ||
550 | TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256)); | ||
551 | break; | ||
552 | } | ||
553 | } | ||
554 | |||
555 | TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/"; | ||
556 | |||
557 | bool requirePublic = false; | ||
558 | |||
559 | if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255."))) | ||
560 | { | ||
561 | return "ERROR! Servers must register with public addresses."; | ||
562 | } | ||
563 | |||
564 | |||
565 | try | ||
566 | { | ||
567 | OpenSim.Framework.Console.MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered."); | ||
568 | foreach (KeyValuePair<string, IGridData> kvp in _plugins) | ||
569 | { | ||
570 | try | ||
571 | { | ||
572 | //Check reservations | ||
573 | ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY); | ||
574 | if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null)) | ||
575 | { | ||
576 | kvp.Value.AddProfile(TheSim); | ||
577 | OpenSim.Framework.Console.MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")"); | ||
578 | logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid."); | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | return "Unable to update region (RestSetSimMethod): Incorrect auth key."; | ||
583 | } | ||
584 | } | ||
585 | catch (Exception e) | ||
586 | { | ||
587 | OpenSim.Framework.Console.MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString()); | ||
588 | } | ||
589 | } | ||
590 | return "OK"; | ||
591 | } | ||
592 | catch (Exception e) | ||
593 | { | ||
594 | return "ERROR! Could not save to database! (" + e.ToString() + ")"; | ||
595 | } | ||
596 | } | ||
597 | |||
598 | } | ||
599 | } | ||