GridManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. OpenSim.Framework.Console.MainLog.Instance.Warn(e.ToString());
  272. }
  273. }
  274. if (getRegion(TheSim.regionHandle) == null)
  275. {
  276. responseData["error"] = "Unable to add new region";
  277. return response;
  278. }
  279. }
  280. ArrayList SimNeighboursData = new ArrayList();
  281. SimProfileData neighbour;
  282. Hashtable NeighbourBlock;
  283. bool fastMode = false; // Only compatible with MySQL right now
  284. if (fastMode)
  285. {
  286. Dictionary<ulong, SimProfileData> neighbours = getRegions(TheSim.regionLocX - 1, TheSim.regionLocY - 1, TheSim.regionLocX + 1, TheSim.regionLocY + 1);
  287. foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
  288. {
  289. NeighbourBlock = new Hashtable();
  290. NeighbourBlock["sim_ip"] = aSim.Value.serverIP.ToString();
  291. NeighbourBlock["sim_port"] = aSim.Value.serverPort.ToString();
  292. NeighbourBlock["region_locx"] = aSim.Value.regionLocX.ToString();
  293. NeighbourBlock["region_locy"] = aSim.Value.regionLocY.ToString();
  294. NeighbourBlock["UUID"] = aSim.Value.UUID.ToString();
  295. if (aSim.Value.UUID != TheSim.UUID)
  296. SimNeighboursData.Add(NeighbourBlock);
  297. }
  298. }
  299. else
  300. {
  301. for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++)
  302. {
  303. if (getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256)) != null)
  304. {
  305. neighbour = getRegion(Helpers.UIntsToLong((uint)((TheSim.regionLocX + x) * 256), (uint)(TheSim.regionLocY + y) * 256));
  306. NeighbourBlock = new Hashtable();
  307. NeighbourBlock["sim_ip"] = neighbour.serverIP;
  308. NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
  309. NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
  310. NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
  311. NeighbourBlock["UUID"] = neighbour.UUID.ToString();
  312. if (neighbour.UUID != TheSim.UUID) SimNeighboursData.Add(NeighbourBlock);
  313. }
  314. }
  315. }
  316. responseData["UUID"] = TheSim.UUID.ToString();
  317. responseData["region_locx"] = TheSim.regionLocX.ToString();
  318. responseData["region_locy"] = TheSim.regionLocY.ToString();
  319. responseData["regionname"] = TheSim.regionName;
  320. responseData["estate_id"] = "1";
  321. responseData["neighbours"] = SimNeighboursData;
  322. responseData["sim_ip"] = TheSim.serverIP;
  323. responseData["sim_port"] = TheSim.serverPort.ToString();
  324. responseData["asset_url"] = TheSim.regionAssetURI;
  325. responseData["asset_sendkey"] = TheSim.regionAssetSendKey;
  326. responseData["asset_recvkey"] = TheSim.regionAssetRecvKey;
  327. responseData["user_url"] = TheSim.regionUserURI;
  328. responseData["user_sendkey"] = TheSim.regionUserSendKey;
  329. responseData["user_recvkey"] = TheSim.regionUserRecvKey;
  330. responseData["authkey"] = TheSim.regionSecret;
  331. // New! If set, use as URL to local sim storage (ie http://remotehost/region.yap)
  332. responseData["data_uri"] = TheSim.regionDataURI;
  333. return response;
  334. }
  335. public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request)
  336. {
  337. Hashtable requestData = (Hashtable)request.Params[0];
  338. Hashtable responseData = new Hashtable();
  339. SimProfileData simData = null;
  340. if (requestData.ContainsKey("region_UUID"))
  341. {
  342. simData = getRegion(new LLUUID((string)requestData["region_UUID"]));
  343. }
  344. else if (requestData.ContainsKey("region_handle"))
  345. {
  346. Console.WriteLine("requesting data for region " + (string)requestData["region_handle"]);
  347. simData = getRegion(Convert.ToUInt64((string)requestData["region_handle"]));
  348. }
  349. if (simData == null)
  350. {
  351. //Sim does not exist
  352. Console.WriteLine("region not found");
  353. responseData["error"] = "Sim does not exist";
  354. }
  355. else
  356. {
  357. Console.WriteLine("found region");
  358. responseData["sim_ip"] = simData.serverIP;
  359. responseData["sim_port"] = simData.serverPort.ToString();
  360. responseData["http_port"] = simData.httpPort.ToString();
  361. responseData["remoting_port"] = simData.remotingPort.ToString();
  362. responseData["region_locx"] = simData.regionLocX.ToString() ;
  363. responseData["region_locy"] = simData.regionLocY.ToString();
  364. responseData["region_UUID"] = simData.UUID.UUID.ToString();
  365. responseData["region_name"] = simData.regionName;
  366. }
  367. XmlRpcResponse response = new XmlRpcResponse();
  368. response.Value = responseData;
  369. return response;
  370. }
  371. public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request)
  372. {
  373. int xmin=980, ymin=980, xmax=1020, ymax=1020;
  374. Hashtable requestData = (Hashtable)request.Params[0];
  375. if (requestData.ContainsKey("xmin"))
  376. {
  377. xmin = (Int32)requestData["xmin"];
  378. }
  379. if (requestData.ContainsKey("ymin"))
  380. {
  381. ymin = (Int32)requestData["ymin"];
  382. }
  383. if (requestData.ContainsKey("xmax"))
  384. {
  385. xmax = (Int32)requestData["xmax"];
  386. }
  387. if (requestData.ContainsKey("ymax"))
  388. {
  389. ymax = (Int32)requestData["ymax"];
  390. }
  391. XmlRpcResponse response = new XmlRpcResponse();
  392. Hashtable responseData = new Hashtable();
  393. response.Value = responseData;
  394. IList simProfileList = new ArrayList();
  395. bool fastMode = false; // MySQL Only
  396. if (fastMode)
  397. {
  398. Dictionary<ulong, SimProfileData> neighbours = getRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax);
  399. foreach (KeyValuePair<ulong, SimProfileData> aSim in neighbours)
  400. {
  401. Hashtable simProfileBlock = new Hashtable();
  402. simProfileBlock["x"] = aSim.Value.regionLocX.ToString();
  403. simProfileBlock["y"] = aSim.Value.regionLocY.ToString();
  404. System.Console.WriteLine("send neighbour info for " + aSim.Value.regionLocX.ToString() + " , " + aSim.Value.regionLocY.ToString());
  405. simProfileBlock["name"] = aSim.Value.regionName;
  406. simProfileBlock["access"] = 21;
  407. simProfileBlock["region-flags"] = 512;
  408. simProfileBlock["water-height"] = 0;
  409. simProfileBlock["agents"] = 1;
  410. simProfileBlock["map-image-id"] = aSim.Value.regionMapTextureID.ToString();
  411. // For Sugilite compatibility
  412. simProfileBlock["regionhandle"] = aSim.Value.regionHandle.ToString();
  413. simProfileBlock["sim_ip"] = aSim.Value.serverIP.ToString();
  414. simProfileBlock["sim_port"] = aSim.Value.serverPort.ToString();
  415. simProfileBlock["sim_uri"] = aSim.Value.serverURI.ToString();
  416. simProfileBlock["uuid"] = aSim.Value.UUID.ToStringHyphenated();
  417. simProfileList.Add(simProfileBlock);
  418. }
  419. MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via FastMode");
  420. }
  421. else
  422. {
  423. SimProfileData simProfile;
  424. for (int x = xmin; x < xmax+1; x++)
  425. {
  426. for (int y = ymin; y < ymax+1; y++)
  427. {
  428. ulong regHandle = Helpers.UIntsToLong((uint)(x * 256), (uint)(y * 256));
  429. simProfile = getRegion(regHandle);
  430. if (simProfile != null)
  431. {
  432. Hashtable simProfileBlock = new Hashtable();
  433. simProfileBlock["x"] = x;
  434. simProfileBlock["y"] = y;
  435. simProfileBlock["name"] = simProfile.regionName;
  436. simProfileBlock["access"] = 0;
  437. simProfileBlock["region-flags"] = 0;
  438. simProfileBlock["water-height"] = 20;
  439. simProfileBlock["agents"] = 1;
  440. simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToStringHyphenated();
  441. // For Sugilite compatibility
  442. simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString();
  443. simProfileBlock["sim_ip"] = simProfile.serverIP.ToString();
  444. simProfileBlock["sim_port"] = simProfile.serverPort.ToString();
  445. simProfileBlock["sim_uri"] = simProfile.serverURI.ToString();
  446. simProfileBlock["uuid"] = simProfile.UUID.ToStringHyphenated();
  447. simProfileList.Add(simProfileBlock);
  448. }
  449. }
  450. }
  451. MainLog.Instance.Verbose("World map request processed, returned " + simProfileList.Count.ToString() + " region(s) in range via Standard Mode");
  452. }
  453. responseData["sim-profiles"] = simProfileList;
  454. return response;
  455. }
  456. /// <summary>
  457. /// Performs a REST Get Operation
  458. /// </summary>
  459. /// <param name="request"></param>
  460. /// <param name="path"></param>
  461. /// <param name="param"></param>
  462. /// <returns></returns>
  463. public string RestGetRegionMethod(string request, string path, string param)
  464. {
  465. return RestGetSimMethod("", "/sims/", param);
  466. }
  467. /// <summary>
  468. /// Performs a REST Set Operation
  469. /// </summary>
  470. /// <param name="request"></param>
  471. /// <param name="path"></param>
  472. /// <param name="param"></param>
  473. /// <returns></returns>
  474. public string RestSetRegionMethod(string request, string path, string param)
  475. {
  476. return RestSetSimMethod("", "/sims/", param);
  477. }
  478. /// <summary>
  479. /// Returns information about a sim via a REST Request
  480. /// </summary>
  481. /// <param name="request"></param>
  482. /// <param name="path"></param>
  483. /// <param name="param"></param>
  484. /// <returns>Information about the sim in XML</returns>
  485. public string RestGetSimMethod(string request, string path, string param)
  486. {
  487. string respstring = String.Empty;
  488. SimProfileData TheSim;
  489. LLUUID UUID = new LLUUID(param);
  490. TheSim = getRegion(UUID);
  491. if (!(TheSim == null))
  492. {
  493. respstring = "<Root>";
  494. respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
  495. respstring += "<sim>";
  496. respstring += "<uuid>" + TheSim.UUID.ToString() + "</uuid>";
  497. respstring += "<regionname>" + TheSim.regionName + "</regionname>";
  498. respstring += "<sim_ip>" + TheSim.serverIP + "</sim_ip>";
  499. respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
  500. respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
  501. respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
  502. respstring += "<estate_id>1</estate_id>";
  503. respstring += "</sim>";
  504. respstring += "</Root>";
  505. }
  506. return respstring;
  507. }
  508. /// <summary>
  509. /// Creates or updates a sim via a REST Method Request
  510. /// BROKEN with SQL Update
  511. /// </summary>
  512. /// <param name="request"></param>
  513. /// <param name="path"></param>
  514. /// <param name="param"></param>
  515. /// <returns>"OK" or an error</returns>
  516. public string RestSetSimMethod(string request, string path, string param)
  517. {
  518. Console.WriteLine("Processing region update via REST method");
  519. SimProfileData TheSim;
  520. TheSim = getRegion(new LLUUID(param));
  521. if ((TheSim) == null)
  522. {
  523. TheSim = new SimProfileData();
  524. LLUUID UUID = new LLUUID(param);
  525. TheSim.UUID = UUID;
  526. TheSim.regionRecvKey = config.SimRecvKey;
  527. }
  528. XmlDocument doc = new XmlDocument();
  529. doc.LoadXml(request);
  530. XmlNode rootnode = doc.FirstChild;
  531. XmlNode authkeynode = rootnode.ChildNodes[0];
  532. if (authkeynode.Name != "authkey")
  533. {
  534. return "ERROR! bad XML - expected authkey tag";
  535. }
  536. XmlNode simnode = rootnode.ChildNodes[1];
  537. if (simnode.Name != "sim")
  538. {
  539. return "ERROR! bad XML - expected sim tag";
  540. }
  541. //TheSim.regionSendKey = Cfg;
  542. TheSim.regionRecvKey = config.SimRecvKey;
  543. TheSim.regionSendKey = config.SimSendKey;
  544. TheSim.regionSecret = config.SimRecvKey;
  545. TheSim.regionDataURI = "";
  546. TheSim.regionAssetURI = config.DefaultAssetServer;
  547. TheSim.regionAssetRecvKey = config.AssetRecvKey;
  548. TheSim.regionAssetSendKey = config.AssetSendKey;
  549. TheSim.regionUserURI = config.DefaultUserServer;
  550. TheSim.regionUserSendKey = config.UserSendKey;
  551. TheSim.regionUserRecvKey = config.UserRecvKey;
  552. for (int i = 0; i < simnode.ChildNodes.Count; i++)
  553. {
  554. switch (simnode.ChildNodes[i].Name)
  555. {
  556. case "regionname":
  557. TheSim.regionName = simnode.ChildNodes[i].InnerText;
  558. break;
  559. case "sim_ip":
  560. TheSim.serverIP = simnode.ChildNodes[i].InnerText;
  561. break;
  562. case "sim_port":
  563. TheSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
  564. break;
  565. case "region_locx":
  566. TheSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
  567. TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
  568. break;
  569. case "region_locy":
  570. TheSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
  571. TheSim.regionHandle = Helpers.UIntsToLong((TheSim.regionLocX * 256), (TheSim.regionLocY * 256));
  572. break;
  573. }
  574. }
  575. TheSim.serverURI = "http://" + TheSim.serverIP + ":" + TheSim.serverPort + "/";
  576. bool requirePublic = false;
  577. bool requireValid = true;
  578. if (requirePublic && (TheSim.serverIP.StartsWith("172.16") || TheSim.serverIP.StartsWith("192.168") || TheSim.serverIP.StartsWith("10.") || TheSim.serverIP.StartsWith("0.") || TheSim.serverIP.StartsWith("255.")))
  579. {
  580. return "ERROR! Servers must register with public addresses.";
  581. }
  582. if (requireValid && (TheSim.serverIP.StartsWith("0.")))
  583. {
  584. return "ERROR! 0.*.*.* Addresses are invalid, please check your server config and try again";
  585. }
  586. try
  587. {
  588. MainLog.Instance.Verbose("Updating / adding via " + _plugins.Count + " storage provider(s) registered.");
  589. foreach (KeyValuePair<string, IGridData> kvp in _plugins)
  590. {
  591. try
  592. {
  593. //Check reservations
  594. ReservationData reserveData = kvp.Value.GetReservationAtPoint(TheSim.regionLocX, TheSim.regionLocY);
  595. if ((reserveData != null && reserveData.gridRecvKey == TheSim.regionRecvKey) || (reserveData == null && authkeynode.InnerText != TheSim.regionRecvKey))
  596. {
  597. kvp.Value.AddProfile(TheSim);
  598. MainLog.Instance.Verbose("New sim added to grid (" + TheSim.regionName + ")");
  599. logToDB(TheSim.UUID.ToStringHyphenated(), "RestSetSimMethod", "", 5, "Region successfully updated and connected to grid.");
  600. }
  601. else
  602. {
  603. MainLog.Instance.Warn("Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");// Wanted: " + reserveData.gridRecvKey + ", Got: " + TheSim.regionRecvKey + ".");
  604. return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
  605. }
  606. }
  607. catch (Exception e)
  608. {
  609. MainLog.Instance.Verbose("getRegionPlugin Handle " + kvp.Key + " unable to add new sim: " + e.ToString());
  610. }
  611. }
  612. return "OK";
  613. }
  614. catch (Exception e)
  615. {
  616. return "ERROR! Could not save to database! (" + e.ToString() + ")";
  617. }
  618. }
  619. }
  620. }