GridManager.cs 32 KB

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