aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Grid/GridServer/GridManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Grid/GridServer/GridManager.cs')
-rw-r--r--OpenSim/Grid/GridServer/GridManager.cs703
1 files changed, 703 insertions, 0 deletions
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
new file mode 100644
index 0000000..1f97f53
--- /dev/null
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -0,0 +1,703 @@
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*/
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Reflection;
32using System.Xml;
33using libsecondlife;
34using Nwc.XmlRpc;
35using OpenSim.Framework.Console;
36using OpenSim.Framework.Data;
37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Utilities;
39
40namespace OpenSim.Grid.GridServer
41{
42 class GridManager
43 {
44 Dictionary<string, IGridData> _plugins = new Dictionary<string, IGridData>();
45 Dictionary<string, ILogData> _logplugins = new Dictionary<string, ILogData>();
46
47 public GridConfig config;
48
49 /// <summary>
50 /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded.
51 /// </summary>
52 /// <param name="FileName">The filename to the grid server plugin DLL</param>
53 public void AddPlugin(string FileName)
54 {
55 MainLog.Instance.Verbose("Storage: Attempting to load " + FileName);
56 Assembly pluginAssembly = Assembly.LoadFrom(FileName);
57
58 MainLog.Instance.Verbose("Storage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
59 foreach (Type pluginType in pluginAssembly.GetTypes())
60 {
61 if (!pluginType.IsAbstract)
62 {
63 // Regions go here
64 Type typeInterface = pluginType.GetInterface("IGridData", true);
65
66 if (typeInterface != null)
67 {
68 IGridData plug = (IGridData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
69 plug.Initialise();
70 this._plugins.Add(plug.getName(), plug);
71 MainLog.Instance.Verbose("Storage: Added IGridData Interface");
72 }
73
74 typeInterface = null;
75
76 // Logs go here
77 typeInterface = pluginType.GetInterface("ILogData", true);
78
79 if (typeInterface != null)
80 {
81 ILogData plug = (ILogData)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
82 plug.Initialise();
83 this._logplugins.Add(plug.getName(), plug);
84 MainLog.Instance.Verbose( "Storage: Added ILogData Interface");
85 }
86
87 typeInterface = null;
88 }
89 }
90
91 pluginAssembly = null;
92 }
93
94 /// <summary>
95 /// Logs a piece of information to the database
96 /// </summary>
97 /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param>
98 /// <param name="method">Which method is being called?</param>
99 /// <param name="args">What arguments are being passed?</param>
100 /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param>
101 /// <param name="message">The message to log</param>
102 private void logToDB(string target, string method, string args, int priority, string message)
103 {
104 foreach (KeyValuePair<string, ILogData> kvp in _logplugins)
105 {
106 try
107 {
108 kvp.Value.saveLog("Gridserver", target, method, args, priority, message);
109 }
110 catch (Exception)
111 {
112 MainLog.Instance.Warn("Storage: unable to write log via " + kvp.Key);
113 }
114 }
115 }
116
117 /// <summary>
118 /// Returns a region by argument
119 /// </summary>
120 /// <param name="uuid">A UUID key of the region to return</param>
121 /// <returns>A SimProfileData for the region</returns>
122 public SimProfileData getRegion(LLUUID uuid)
123 {
124 foreach(KeyValuePair<string,IGridData> kvp in _plugins) {
125 try
126 {
127 return kvp.Value.GetProfileByLLUUID(uuid);
128 }
129 catch (Exception e)
130 {
131 MainLog.Instance.Warn("Message from Storage: " + e.Message);
132 }
133 }
134 return null;
135 }
136
137 /// <summary>
138 /// Returns a region by argument
139 /// </summary>
140 /// <param name="uuid">A regionHandle of the region to return</param>
141 /// <returns>A SimProfileData for the region</returns>
142 public SimProfileData getRegion(ulong handle)
143 {
144 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
145 {
146 try
147 {
148 return kvp.Value.GetProfileByHandle(handle);
149 }
150 catch
151 {
152 MainLog.Instance.Warn("Storage: Unable to find region " + handle.ToString() + " via " + kvp.Key);
153 }
154 }
155 return null;
156 }
157
158 public Dictionary<ulong, SimProfileData> getRegions(uint xmin, uint ymin, uint xmax, uint ymax)
159 {
160 Dictionary<ulong, SimProfileData> regions = new Dictionary<ulong, SimProfileData>();
161
162 SimProfileData[] neighbours;
163
164 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
165 {
166 try
167 {
168 neighbours = kvp.Value.GetProfilesInRange(xmin, ymin, xmax, ymax);
169 foreach (SimProfileData neighbour in neighbours)
170 {
171 regions[neighbour.regionHandle] = neighbour;
172 }
173 }
174 catch
175 {
176 MainLog.Instance.Warn("Storage: Unable to query regionblock via " + kvp.Key);
177 }
178 }
179
180 return regions;
181 }
182
183
184
185 /// <summary>
186 /// Returns a XML String containing a list of the neighbouring regions
187 /// </summary>
188 /// <param name="reqhandle">The regionhandle for the center sim</param>
189 /// <returns>An XML string containing neighbour entities</returns>
190 public string GetXMLNeighbours(ulong reqhandle)
191 {
192 string response = "";
193 SimProfileData central_region = getRegion(reqhandle);
194 SimProfileData neighbour;
195 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
196 {
197 if (getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256)) != null)
198 {
199 neighbour = getRegion(Util.UIntsToLong((uint)((central_region.regionLocX + x) * 256), (uint)(central_region.regionLocY + y) * 256));
200 response += "<neighbour>";
201 response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>";
202 response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>";
203 response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>";
204 response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>";
205 response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>";
206 response += "</neighbour>";
207
208 }
209 }
210 return response;
211 }
212
213 /// <summary>
214 /// Performed when a region connects to the grid server initially.
215 /// </summary>
216 /// <param name="request">The XMLRPC Request</param>
217 /// <returns>Startup parameters</returns>
218 public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request)
219 {
220
221 XmlRpcResponse response = new XmlRpcResponse();
222 Hashtable responseData = new Hashtable();
223 response.Value = responseData;
224
225 SimProfileData TheSim = null;
226 Hashtable requestData = (Hashtable)request.Params[0];
227
228 if (requestData.ContainsKey("UUID"))
229 {
230 TheSim = getRegion(new LLUUID((string)requestData["UUID"]));
231
232 logToDB((new LLUUID((string)requestData["UUID"])).ToStringHyphenated(),"XmlRpcSimulatorLoginMethod","", 5,"Region attempting login with UUID.");
233 }
234 else if (requestData.ContainsKey("region_handle"))
235 {
236
237 TheSim = getRegion((ulong)Convert.ToUInt64(requestData["region_handle"]));
238 logToDB((string)requestData["region_handle"], "XmlRpcSimulatorLoginMethod", "", 5, "Region attempting login with regionHandle.");
239 }
240 else
241 {
242 responseData["error"] = "No UUID or region_handle passed to grid server - unable to connect you";
243 return response;
244 }
245
246 if (TheSim == null) // Shouldnt this be in the REST Simulator Set method?
247 {
248 //NEW REGION
249 TheSim = new SimProfileData();
250
251 TheSim.regionRecvKey = config.SimRecvKey;
252 TheSim.regionSendKey = config.SimSendKey;
253 TheSim.regionSecret = config.SimRecvKey;
254 TheSim.regionDataURI = "";
255 TheSim.regionAssetURI = config.DefaultAssetServer;
256 TheSim.regionAssetRecvKey = config.AssetRecvKey;
257 TheSim.regionAssetSendKey = config.AssetSendKey;
258 TheSim.regionUserURI = config.DefaultUserServer;
259 TheSim.regionUserSendKey = config.UserSendKey;
260 TheSim.regionUserRecvKey = config.UserRecvKey;
261
262 TheSim.serverIP = (string)requestData["sim_ip"];
263 TheSim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]);
264 TheSim.httpPort = Convert.ToUInt32((string)requestData["http_port"]);
265 TheSim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]);
266 TheSim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]);
267 TheSim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]);
268 TheSim.regionLocZ = 0;
269 TheSim.regionMapTextureID = new LLUUID((string)requestData["map-image-id"]);
270
271 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
272 System.Console.WriteLine("adding region " + TheSim.regionLocX + " , " + TheSim.regionLocY + " , " + TheSim.regionHandle);
273 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
274 TheSim.httpServerURI = "http://" + TheSim.serverIP + ":" + TheSim.httpPort + "/";
275
276 Console.WriteLine("NEW SIM: " + TheSim.serverURI);
277 TheSim.regionName = (string)requestData["sim_name"];
278 TheSim.UUID = new LLUUID((string)requestData["UUID"]);
279
280 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
281 {
282 try
283 {
284 DataResponse insertResponse = kvp.Value.AddProfile(TheSim);
285 switch(insertResponse)
286 {
287 case DataResponse.RESPONSE_OK:
288 OpenSim.Framework.Console.MainLog.Instance.Verbose("New sim creation successful: " + TheSim.regionName);
289 break;
290 case DataResponse.RESPONSE_ERROR:
291 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Error): " + TheSim.regionName);
292 break;
293 case DataResponse.RESPONSE_INVALIDCREDENTIALS:
294 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Invalid Credentials): " + TheSim.regionName);
295 break;
296 case DataResponse.RESPONSE_AUTHREQUIRED:
297 OpenSim.Framework.Console.MainLog.Instance.Warn("New sim creation failed (Authentication Required): " + TheSim.regionName);
298 break;
299 }
300
301 }
302 catch (Exception e)
303 {
304 OpenSim.Framework.Console.MainLog.Instance.Warn("Storage: Unable to add region " + TheSim.UUID.ToStringHyphenated() + " via " + kvp.Key);
305 }
306 }
307
308
309 if (getRegion(TheSim.regionHandle) == null)
310 {
311 responseData["error"] = "Unable to add new region";
312 return response;
313 }
314 }
315
316
317 ArrayList SimNeighboursData = new ArrayList();
318
319 SimProfileData neighbour;
320 Hashtable NeighbourBlock;
321
322 bool fastMode = false; // Only compatible with MySQL right now
323
324 if (fastMode)
325 {
326 Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1);
327
328 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
329 {
330 NeighbourBlock = new Hashtable();
331 NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString();
332 NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString();
333 NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString();
334 NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString();
335 NeighbourBlock["UUID"] = aSim.Value.UUID.ToString();
336
337 if (aSim.Value.UUID != TheSim.UUID)
338 SimNeighboursData.Add(NeighbourBlock);
339 }
340 }
341 else
342 {
343 for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
344 {
345 if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null)
346 {
347 neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256));
348
349 NeighbourBlock = new Hashtable();
350 NeighbourBlock["sim_ip"] = neighbour.serverIP;
351 NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
352 NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
353 NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
354 NeighbourBlock["UUID"] = neighbour.UUID.ToString();
355
356 if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
357 }
358 }
359 }
360
361 responseData["UUID"] = TheSim.UUID.ToString();
362 responseData["region_locx"] = TheSim.regionLocX.ToString();
363 responseData["region_locy"] = TheSim.regionLocY.ToString();
364 responseData["regionname"] = TheSim.regionName;
365 responseData["estate_id"] = "1";
366 responseData["neighbours"] = SimNeighboursData;
367
368 responseData["sim_ip"] = TheSim.serverIP;
369 responseData["sim_port"] = TheSim.serverPort.ToString();
370 responseData["asset_url"] = TheSim.regionAssetURI;
371 responseData["asset_sendkey"] = TheSim.regionAssetSendKey;
372 responseData["asset_recvkey"] = TheSim.regionAssetRecvKey;
373 responseData["user_url"] = TheSim.regionUserURI;
374 responseData["user_sendkey"] = TheSim.regionUserSendKey;
375 responseData["user_recvkey"] = TheSim.regionUserRecvKey;
376 responseData["authkey"] = TheSim.regionSecret;
377
378 // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap)
379 responseData["data_uri"] = TheSim.regionDataURI;
380
381
382 return response;
383 }
384
385 public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request)
386 {
387 Hashtable requestData = (Hashtable)request.Params[0];
388 Hashtable responseData = new Hashtable();
389 SimProfileData simData = null;
390 if (requestData.ContainsKey("region_UUID"))
391 {
392 simData = getRegion(new LLUUID((string)requestData["region_UUID"]));
393 }
394 else if (requestData.ContainsKey("region_handle"))
395 {
396 Console.WriteLine("requesting data for region " + (string)requestData["region_handle"]);
397 simData = getRegion(Convert.ToUInt64((string)requestData["region_handle"]));
398 }
399
400 if (simData == null)
401 {
402 //Sim does not exist
403 Console.WriteLine("region not found");
404 responseData["error"] = "Sim does not exist";
405 }
406 else
407 {
408 Console.WriteLine("found region");
409 responseData["sim_ip"] = simData.serverIP;
410 responseData["sim_port"] = simData.serverPort.ToString();
411 responseData["http_port"] = simData.httpPort.ToString();
412 responseData["remoting_port"] = simData.remotingPort.ToString();
413 responseData["region_locx"] = simData.regionLocX.ToString() ;
414 responseData["region_locy"] = simData.regionLocY.ToString();
415 responseData["region_UUID"] = simData.UUID.UUID.ToString();
416 responseData["region_name"] = simData.regionName;
417 }
418
419 XmlRpcResponse response = new XmlRpcResponse();
420 response.Value = responseData;
421 return response;
422 }
423
424 public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request)
425 {
426 int xmin=980, ymin=980, xmax=1020, ymax=1020;
427
428 Hashtable requestData = (Hashtable)request.Params[0];
429 if (requestData.ContainsKey("xmin"))
430 {
431 xmin = (Int32)requestData["xmin"];
432 }
433 if (requestData.ContainsKey("ymin"))
434 {
435 ymin = (Int32)requestData["ymin"];
436 }
437 if (requestData.ContainsKey("xmax"))
438 {
439 xmax = (Int32)requestData["xmax"];
440 }
441 if (requestData.ContainsKey("ymax"))
442 {
443 ymax = (Int32)requestData["ymax"];
444 }
445
446 XmlRpcResponse response = new XmlRpcResponse();
447 Hashtable responseData = new Hashtable();
448 response.Value = responseData;
449 IList simProfileList = new ArrayList();
450
451 bool fastMode = false; // MySQL Only
452
453 if (fastMode)
454 {
455 Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax);
456
457 foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
458 {
459 Hashtable simProfileBlock = new Hashtable();
460 simProfileBlock["x"] = aSim.Value.regionLocX.ToString();
461 simProfileBlock["y"] = aSim.Value.regionLocY.ToString();
462 System.Console.WriteLine("send neighbour info for " + aSim.Value.regionLocX.ToString() + " , " + aSim.Value.regionLocY.ToString());
463 simProfileBlock["name"] = aSim.Value.regionName;
464 simProfileBlock["access"] = 21;
465 simProfileBlock["region-flags"] = 512;
466 simProfileBlock["water-height"] = 0;
467 simProfileBlock["agents"] = 1;
468 simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString();
469
470 // For Sugilite compatibility
471 simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString();
472 simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString();
473 simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString();
474 simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString();
475 simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated();
476
477 simProfileList.Add(simProfileBlock);
478 }
479 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode");
480 }
481 else
482 {
483 SimProfileData simProfile;
484 for (int x = xmin; x < xmax+1; x++)
485 {
486 for (int y = ymin; y < ymax+1; y++)
487 {
488 ulong regHandle = Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256));
489 simProfile = getRegion(regHandle);
490 if (simProfile != null)
491 {
492 Hashtable simProfileBlock = new Hashtable();
493 simProfileBlock["x"] = x;
494 simProfileBlock["y"] = y;
495 simProfileBlock["name"] = simProfile.regionName;
496 simProfileBlock["access"] = 0;
497 simProfileBlock["region-flags"] = 0;
498 simProfileBlock["water-height"] = 20;
499 simProfileBlock["agents"] = 1;
500 simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToStringHyphenated();
501
502 // For Sugilite compatibility
503 simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString();
504 simProfileBlock["sim_ip"] = simProfile.serverIP.ToString();
505 simProfileBlock["sim_port"] = simProfile.serverPort.ToString();
506 simProfileBlock["sim_uri"] = simProfile.serverURI.ToString();
507 simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated();
508
509 simProfileList.Add(simProfileBlock);
510 }
511 }
512 }
513 MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode");
514 }
515
516 responseData["sim-profiles"] = simProfileList;
517
518 return response;
519 }
520
521
522
523 /// <summary>
524 /// Performs a REST Get Operation
525 /// </summary>
526 /// <param name="request"></param>
527 /// <param name="path"></param>
528 /// <param name="param"></param>
529 /// <returns></returns>
530 public string RestGetRegionMethod(string request, string path, string param)
531 {
532 return RestGetSimMethod("", "/sims/", param);
533 }
534
535 /// <summary>
536 /// Performs a REST Set Operation
537 /// </summary>
538 /// <param name="request"></param>
539 /// <param name="path"></param>
540 /// <param name="param"></param>
541 /// <returns></returns>
542 public string RestSetRegionMethod(string request, string path, string param)
543 {
544 return RestSetSimMethod("", "/sims/", param);
545 }
546
547 /// <summary>
548 /// Returns information about a sim via a REST Request
549 /// </summary>
550 /// <param name="request"></param>
551 /// <param name="path"></param>
552 /// <param name="param"></param>
553 /// <returns>Information about the sim in XML</returns>
554 public string RestGetSimMethod(string request, string path, string param)
555 {
556 string respstring = String.Empty;
557
558 SimProfileData TheSim;
559 LLUUID UUID = new LLUUID(param);
560 TheSim = getRegion(UUID);
561
562 if (!(TheSim == null))
563 {
564 respstring = "<Root>";
565 respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
566 respstring += "<sim>";
567 respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
568 respstring += "<regionname>" + TheSim.regionName + "</regionname>";
569 respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>";
570 respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
571 respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
572 respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
573 respstring += "<estate_id>1</estate_id>";
574 respstring += "</sim>";
575 respstring += "</Root>";
576 }
577
578 return respstring;
579 }
580
581 /// <summary>
582 /// Creates or updates a sim via a REST Method Request
583 /// BROKEN with SQL Update
584 /// </summary>
585 /// <param name="request"></param>
586 /// <param name="path"></param>
587 /// <param name="param"></param>
588 /// <returns>"OK" or an error</returns>
589 public string RestSetSimMethod(string request, string path, string param)
590 {
591 Console.WriteLine("Processing region update via REST method");
592 SimProfileData TheSim;
593 TheSim = getRegion(new LLUUID(param));
594 if ((TheSim) == null)
595 {
596 TheSim = new SimProfileData();
597 LLUUID UUID = new LLUUID(param);
598 TheSim.UUID = UUID;
599 TheSim.regionRecvKey = config.SimRecvKey;
600 }
601
602 XmlDocument doc = new XmlDocument();
603 doc.LoadXml(request);
604 XmlNode rootnode = doc.FirstChild;
605 XmlNode authkeynode = rootnode.ChildNodes[0];
606 if (authkeynode.Name != "authkey")
607 {
608 return "ERROR! bad XML - expected authkey tag";
609 }
610
611 XmlNode simnode = rootnode.ChildNodes[1];
612 if (simnode.Name != "sim")
613 {
614 return "ERROR! bad XML - expected sim tag";
615 }
616
617 //TheSim.regionSendKey = Cfg;
618 TheSim.regionRecvKey = config.SimRecvKey;
619 TheSim.regionSendKey = config.SimSendKey;
620 TheSim.regionSecret = config.SimRecvKey;
621 TheSim.regionDataURI = "";
622 TheSim.regionAssetURI = config.DefaultAssetServer;
623 TheSim.regionAssetRecvKey = config.AssetRecvKey;
624 TheSim.regionAssetSendKey = config.AssetSendKey;
625 TheSim.regionUserURI = config.DefaultUserServer;
626 TheSim.regionUserSendKey = config.UserSendKey;
627 TheSim.regionUserRecvKey = config.UserRecvKey;
628
629
630 for (int i = 0; i < simnode.ChildNodes.Count; i++)
631 {
632 switch (simnode.ChildNodes[i].Name)
633 {
634 case "regionname":
635 TheSim.regionName = simnode.ChildNodes[i].InnerText;
636 break;
637
638 case "sim_ip":
639 TheSim.serverIP = simnode.ChildNodes[i].InnerText;
640 break;
641
642 case "sim_port":
643 TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
644 break;
645
646 case "region_locx":
647 TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
648 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
649 break;
650
651 case "region_locy":
652 TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
653 TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
654 break;
655 }
656 }
657
658 TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
659
660 bool requirePublic = false;
661
662 if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255.")))
663 {
664 return "ERROR! Servers must register with public addresses.";
665 }
666
667
668 try
669 {
670 MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered.");
671 foreach (KeyValuePair<string, IGridData> kvp in _plugins)
672 {
673 try
674 {
675 //Check reservations
676 ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY);
677 if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != TheSim.regionRecvKey))
678 {
679 kvp.Value.AddProfile(TheSim);
680 MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")");
681 logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid.");
682 }
683 else
684 {
685 MainLog.Instance.Warn("Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");// Wanted: " + reserveData.gridRecvKey + ", Got: " + TheSim.regionRecvKey + ".");
686 return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
687 }
688 }
689 catch (Exception e)
690 {
691 MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString());
692 }
693 }
694 return "OK";
695 }
696 catch (Exception e)
697 {
698 return "ERROR! Could not save to database! (" + e.ToString() + ")";
699 }
700 }
701
702 }
703}