GridManager.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.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. using System;
  28. using System.Text;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Xml;
  34. using OpenMetaverse;
  35. using log4net;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Data;
  38. using OpenSim.Framework;
  39. using OpenSim.Framework.Communications;
  40. using OpenSim.Framework.Servers;
  41. namespace OpenSim.Grid.GridServer
  42. {
  43. public class GridManager
  44. {
  45. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private List<IGridDataPlugin> _plugins = new List<IGridDataPlugin>();
  47. private List<ILogDataPlugin> _logplugins = new List<ILogDataPlugin>();
  48. // This is here so that the grid server can hand out MessageServer settings to regions on registration
  49. private List<MessageServerInfo> _MessageServers = new List<MessageServerInfo>();
  50. public GridConfig Config;
  51. /// <summary>
  52. /// Adds a new grid server plugin - grid servers will be requested in the order they were loaded.
  53. /// </summary>
  54. /// <param name="provider">The name of the grid server plugin DLL</param>
  55. public void AddPlugin(string provider, string connect)
  56. {
  57. PluginLoader<IGridDataPlugin> gridloader =
  58. new PluginLoader<IGridDataPlugin> (new GridDataInitialiser (connect));
  59. PluginLoader<ILogDataPlugin> logloader =
  60. new PluginLoader<ILogDataPlugin> (new LogDataInitialiser (connect));
  61. // loader will try to load all providers (MySQL, MSSQL, etc)
  62. // unless it is constrainted to the correct "Provider" entry in the addin.xml
  63. gridloader.Add ("/OpenSim/GridData", new PluginProviderFilter (provider));
  64. logloader.Add ("/OpenSim/LogData", new PluginProviderFilter (provider));
  65. gridloader.Load();
  66. logloader.Load();
  67. _plugins = gridloader.Plugins;
  68. _logplugins = logloader.Plugins;
  69. }
  70. /// <summary>
  71. /// Logs a piece of information to the database
  72. /// </summary>
  73. /// <param name="target">What you were operating on (in grid server, this will likely be the region UUIDs)</param>
  74. /// <param name="method">Which method is being called?</param>
  75. /// <param name="args">What arguments are being passed?</param>
  76. /// <param name="priority">How high priority is this? 1 = Max, 6 = Verbose</param>
  77. /// <param name="message">The message to log</param>
  78. private void logToDB(string target, string method, string args, int priority, string message)
  79. {
  80. foreach (ILogDataPlugin plugin in _logplugins)
  81. {
  82. try
  83. {
  84. plugin.saveLog("Gridserver", target, method, args, priority, message);
  85. }
  86. catch (Exception)
  87. {
  88. m_log.Warn("[storage]: Unable to write log via " + plugin.Name);
  89. }
  90. }
  91. }
  92. /// <summary>
  93. /// Returns a region by argument
  94. /// </summary>
  95. /// <param name="uuid">A UUID key of the region to return</param>
  96. /// <returns>A SimProfileData for the region</returns>
  97. public RegionProfileData GetRegion(UUID uuid)
  98. {
  99. foreach (IGridDataPlugin plugin in _plugins)
  100. {
  101. try
  102. {
  103. return plugin.GetProfileByUUID(uuid);
  104. }
  105. catch (Exception e)
  106. {
  107. m_log.Warn("[storage]: GetRegion - " + e.Message);
  108. }
  109. }
  110. return null;
  111. }
  112. /// <summary>
  113. /// Returns a region by argument
  114. /// </summary>
  115. /// <param name="uuid">A regionHandle of the region to return</param>
  116. /// <returns>A SimProfileData for the region</returns>
  117. public RegionProfileData GetRegion(ulong handle)
  118. {
  119. foreach (IGridDataPlugin plugin in _plugins)
  120. {
  121. try
  122. {
  123. return plugin.GetProfileByHandle(handle);
  124. }
  125. catch (Exception ex)
  126. {
  127. m_log.Debug("[storage]: " + ex.Message);
  128. m_log.Warn("[storage]: Unable to find region " + handle.ToString() + " via " + plugin.Name);
  129. }
  130. }
  131. return null;
  132. }
  133. /// <summary>
  134. /// Returns a region by argument
  135. /// </summary>
  136. /// <param name="regionName">A partial regionName of the region to return</param>
  137. /// <returns>A SimProfileData for the region</returns>
  138. public RegionProfileData GetRegion(string regionName)
  139. {
  140. foreach (IGridDataPlugin plugin in _plugins)
  141. {
  142. try
  143. {
  144. return plugin.GetProfileByString(regionName);
  145. }
  146. catch
  147. {
  148. m_log.Warn("[storage]: Unable to find region " + regionName + " via " + plugin.Name);
  149. }
  150. }
  151. return null;
  152. }
  153. public List<RegionProfileData> GetRegions(uint xmin, uint ymin, uint xmax, uint ymax)
  154. {
  155. List<RegionProfileData> regions = new List<RegionProfileData>();
  156. foreach (IGridDataPlugin plugin in _plugins)
  157. {
  158. try
  159. {
  160. regions.AddRange(plugin.GetProfilesInRange(xmin, ymin, xmax, ymax));
  161. }
  162. catch
  163. {
  164. m_log.Warn("[storage]: Unable to query regionblock via " + plugin.Name);
  165. }
  166. }
  167. return regions;
  168. }
  169. public List<RegionProfileData> GetRegions(string name, int maxNum)
  170. {
  171. List<RegionProfileData> regions = new List<RegionProfileData>();
  172. foreach (IGridDataPlugin plugin in _plugins)
  173. {
  174. try
  175. {
  176. int num = maxNum - regions.Count;
  177. List <RegionProfileData> profiles = plugin.GetRegionsByName(name, (uint)num);
  178. if (profiles != null) regions.AddRange(profiles);
  179. }
  180. catch
  181. {
  182. m_log.Warn("[storage]: Unable to query regionblock via " + plugin.Name);
  183. }
  184. }
  185. return regions;
  186. }
  187. /// <summary>
  188. /// Returns a XML String containing a list of the neighbouring regions
  189. /// </summary>
  190. /// <param name="reqhandle">The regionhandle for the center sim</param>
  191. /// <returns>An XML string containing neighbour entities</returns>
  192. public string GetXMLNeighbours(ulong reqhandle)
  193. {
  194. string response = String.Empty;
  195. RegionProfileData central_region = GetRegion(reqhandle);
  196. RegionProfileData neighbour;
  197. for (int x = -1; x < 2; x++)
  198. {
  199. for (int y = -1; y < 2; y++)
  200. {
  201. if (
  202. GetRegion(
  203. Util.UIntsToLong((uint)((central_region.regionLocX + x) * Constants.RegionSize),
  204. (uint)(central_region.regionLocY + y) * Constants.RegionSize)) != null)
  205. {
  206. neighbour =
  207. GetRegion(
  208. Util.UIntsToLong((uint)((central_region.regionLocX + x) * Constants.RegionSize),
  209. (uint)(central_region.regionLocY + y) * Constants.RegionSize));
  210. response += "<neighbour>";
  211. response += "<sim_ip>" + neighbour.serverIP + "</sim_ip>";
  212. response += "<sim_port>" + neighbour.serverPort.ToString() + "</sim_port>";
  213. response += "<locx>" + neighbour.regionLocX.ToString() + "</locx>";
  214. response += "<locy>" + neighbour.regionLocY.ToString() + "</locy>";
  215. response += "<regionhandle>" + neighbour.regionHandle.ToString() + "</regionhandle>";
  216. response += "</neighbour>";
  217. }
  218. }
  219. }
  220. return response;
  221. }
  222. /// <summary>
  223. /// Checks that it's valid to replace the existing region data with new data
  224. ///
  225. /// Currently, this means ensure that the keys passed in by the new region
  226. /// match those in the original region. (XXX Is this correct? Shouldn't we simply check
  227. /// against the keys in the current configuration?)
  228. /// </summary>
  229. /// <param name="sim"></param>
  230. /// <returns></returns>
  231. protected virtual void ValidateOverwriteKeys(RegionProfileData sim, RegionProfileData existingSim)
  232. {
  233. if (!(existingSim.regionRecvKey == sim.regionRecvKey && existingSim.regionSendKey == sim.regionSendKey))
  234. {
  235. throw new LoginException(
  236. String.Format(
  237. "Authentication failed when trying to login existing region {0} at location {1} {2} currently occupied by {3}"
  238. + " with the region's send key {4} (expected {5}) and the region's receive key {6} (expected {7})",
  239. sim.regionName, sim.regionLocX, sim.regionLocY, existingSim.regionName,
  240. sim.regionSendKey, existingSim.regionSendKey, sim.regionRecvKey, existingSim.regionRecvKey),
  241. "The keys required to login your region did not match the grid server keys. Please check your grid send and receive keys.");
  242. }
  243. }
  244. /// <summary>
  245. /// Checks that the new region data is valid.
  246. ///
  247. /// Currently, this means checking that the keys passed in by the new region
  248. /// match those in the grid server's configuration.
  249. /// </summary>
  250. ///
  251. /// <param name="sim"></param>
  252. /// <exception cref="LoginException">Thrown if region login failed</exception>
  253. protected virtual void ValidateNewRegionKeys(RegionProfileData sim)
  254. {
  255. if (!(sim.regionRecvKey == Config.SimSendKey && sim.regionSendKey == Config.SimRecvKey))
  256. {
  257. throw new LoginException(
  258. String.Format(
  259. "Authentication failed when trying to login new region {0} at location {1} {2}"
  260. + " with the region's send key {3} (expected {4}) and the region's receive key {5} (expected {6})",
  261. sim.regionName, sim.regionLocX, sim.regionLocY,
  262. sim.regionSendKey, Config.SimRecvKey, sim.regionRecvKey, Config.SimSendKey),
  263. "The keys required to login your region did not match your existing region keys. Please check your grid send and receive keys.");
  264. }
  265. }
  266. /// <summary>
  267. /// Check that a region's http uri is externally contactable.
  268. /// </summary>
  269. /// <param name="sim"></param>
  270. /// <exception cref="LoginException">Thrown if the region is not contactable</exception>
  271. protected virtual void ValidateRegionContactable(RegionProfileData sim)
  272. {
  273. string regionStatusUrl = String.Format("{0}{1}", sim.httpServerURI, "simstatus/");
  274. string regionStatusResponse;
  275. RestClient rc = new RestClient(regionStatusUrl);
  276. rc.RequestMethod = "GET";
  277. m_log.DebugFormat("[LOGIN]: Contacting {0} for status of region {1}", regionStatusUrl, sim.regionName);
  278. try
  279. {
  280. Stream rs = rc.Request();
  281. StreamReader sr = new StreamReader(rs);
  282. regionStatusResponse = sr.ReadToEnd();
  283. sr.Close();
  284. }
  285. catch (Exception e)
  286. {
  287. throw new LoginException(
  288. String.Format("Region status request to {0} failed", regionStatusUrl),
  289. String.Format(
  290. "The grid service could not contact the http url {0} at your region. Please make sure this url is reachable by the grid service",
  291. regionStatusUrl),
  292. e);
  293. }
  294. if (!regionStatusResponse.Equals("OK"))
  295. {
  296. throw new LoginException(
  297. String.Format(
  298. "Region {0} at {1} returned status response {2} rather than {3}",
  299. sim.regionName, regionStatusUrl, regionStatusResponse, "OK"),
  300. String.Format(
  301. "When the grid service asked for the status of your region, it received the response {0} rather than {1}. Please check your status",
  302. regionStatusResponse, "OK"));
  303. }
  304. }
  305. /// <summary>
  306. /// Construct an XMLRPC error response
  307. /// </summary>
  308. /// <param name="error"></param>
  309. /// <returns></returns>
  310. public static XmlRpcResponse ErrorResponse(string error)
  311. {
  312. XmlRpcResponse errorResponse = new XmlRpcResponse();
  313. Hashtable errorResponseData = new Hashtable();
  314. errorResponse.Value = errorResponseData;
  315. errorResponseData["error"] = error;
  316. return errorResponse;
  317. }
  318. /// <summary>
  319. /// Performed when a region connects to the grid server initially.
  320. /// </summary>
  321. /// <param name="request">The XML RPC Request</param>
  322. /// <returns>Startup parameters</returns>
  323. public XmlRpcResponse XmlRpcSimulatorLoginMethod(XmlRpcRequest request)
  324. {
  325. RegionProfileData sim;
  326. RegionProfileData existingSim;
  327. Hashtable requestData = (Hashtable)request.Params[0];
  328. UUID uuid;
  329. if (!requestData.ContainsKey("UUID") || !UUID.TryParse((string)requestData["UUID"], out uuid))
  330. {
  331. m_log.Warn("[LOGIN PRELUDE]: Region connected without a UUID, sending back error response.");
  332. return ErrorResponse("No UUID passed to grid server - unable to connect you");
  333. }
  334. try
  335. {
  336. sim = RegionFromRequest(requestData);
  337. }
  338. catch (FormatException e)
  339. {
  340. m_log.Warn("[LOGIN PRELUDE]: Invalid login parameters, sending back error response.");
  341. return ErrorResponse("Wrong format in login parameters. Please verify parameters." + e.ToString());
  342. }
  343. if (!Config.AllowRegionRegistration)
  344. {
  345. m_log.InfoFormat(
  346. "[LOGIN END]: Disabled region registration blocked login request from simulator: {0}",
  347. sim.regionName);
  348. return ErrorResponse("The grid is currently not accepting region registrations.");
  349. }
  350. m_log.InfoFormat("[LOGIN BEGIN]: Received login request from simulator: {0}", sim.regionName);
  351. existingSim = GetRegion(sim.regionHandle);
  352. if (existingSim == null || existingSim.UUID == sim.UUID || sim.UUID != sim.originUUID)
  353. {
  354. try
  355. {
  356. if (existingSim == null)
  357. {
  358. ValidateNewRegionKeys(sim);
  359. }
  360. else
  361. {
  362. ValidateOverwriteKeys(sim, existingSim);
  363. }
  364. ValidateRegionContactable(sim);
  365. }
  366. catch (LoginException e)
  367. {
  368. string logMsg = e.Message;
  369. if (e.InnerException != null)
  370. logMsg += ", " + e.InnerException.Message;
  371. m_log.WarnFormat("[LOGIN END]: {0}", logMsg);
  372. return e.XmlRpcErrorResponse;
  373. }
  374. foreach (IGridDataPlugin plugin in _plugins)
  375. {
  376. try
  377. {
  378. DataResponse insertResponse;
  379. if (existingSim == null)
  380. {
  381. insertResponse = plugin.AddProfile(sim);
  382. }
  383. else
  384. {
  385. insertResponse = plugin.UpdateProfile(sim);
  386. }
  387. switch (insertResponse)
  388. {
  389. case DataResponse.RESPONSE_OK:
  390. m_log.Info("[LOGIN END]: " + (existingSim == null ? "New" : "Existing") + " sim login successful: " + sim.regionName);
  391. break;
  392. case DataResponse.RESPONSE_ERROR:
  393. m_log.Warn("[LOGIN END]: Sim login failed (Error): " + sim.regionName);
  394. break;
  395. case DataResponse.RESPONSE_INVALIDCREDENTIALS:
  396. m_log.Warn("[LOGIN END]: " +
  397. "Sim login failed (Invalid Credentials): " + sim.regionName);
  398. break;
  399. case DataResponse.RESPONSE_AUTHREQUIRED:
  400. m_log.Warn("[LOGIN END]: " +
  401. "Sim login failed (Authentication Required): " +
  402. sim.regionName);
  403. break;
  404. }
  405. }
  406. catch (Exception e)
  407. {
  408. m_log.Warn("[LOGIN END]: " +
  409. "Unable to login region " + sim.ToString() + " via " + plugin.Name);
  410. m_log.Warn("[LOGIN END]: " + e.ToString());
  411. }
  412. }
  413. XmlRpcResponse response = CreateLoginResponse(sim);
  414. return response;
  415. }
  416. else
  417. {
  418. m_log.Warn("[LOGIN END]: Failed to login region " + sim.regionName + " at location " + sim.regionLocX + " " + sim.regionLocY + " currently occupied by " + existingSim.regionName);
  419. return ErrorResponse("Another region already exists at that location. Please try another.");
  420. }
  421. }
  422. /// <summary>
  423. /// Construct a successful response to a simulator's login attempt.
  424. /// </summary>
  425. /// <param name="sim"></param>
  426. /// <returns></returns>
  427. private XmlRpcResponse CreateLoginResponse(RegionProfileData sim)
  428. {
  429. XmlRpcResponse response = new XmlRpcResponse();
  430. Hashtable responseData = new Hashtable();
  431. response.Value = responseData;
  432. ArrayList SimNeighboursData = GetSimNeighboursData(sim);
  433. responseData["UUID"] = sim.UUID.ToString();
  434. responseData["region_locx"] = sim.regionLocX.ToString();
  435. responseData["region_locy"] = sim.regionLocY.ToString();
  436. responseData["regionname"] = sim.regionName;
  437. responseData["estate_id"] = "1";
  438. responseData["neighbours"] = SimNeighboursData;
  439. responseData["sim_ip"] = sim.serverIP;
  440. responseData["sim_port"] = sim.serverPort.ToString();
  441. responseData["asset_url"] = sim.regionAssetURI;
  442. responseData["asset_sendkey"] = sim.regionAssetSendKey;
  443. responseData["asset_recvkey"] = sim.regionAssetRecvKey;
  444. responseData["user_url"] = sim.regionUserURI;
  445. responseData["user_sendkey"] = sim.regionUserSendKey;
  446. responseData["user_recvkey"] = sim.regionUserRecvKey;
  447. responseData["authkey"] = sim.regionSecret;
  448. // New! If set, use as URL to local sim storage (ie http://remotehost/region.Yap)
  449. responseData["data_uri"] = sim.regionDataURI;
  450. responseData["allow_forceful_banlines"] = Config.AllowForcefulBanlines;
  451. // Instead of sending a multitude of message servers to the registering sim
  452. // we should probably be sending a single one and parhaps it's backup
  453. // that has responsibility over routing it's messages.
  454. // The Sim won't be contacting us again about any of the message server stuff during it's time up.
  455. responseData["messageserver_count"] = _MessageServers.Count;
  456. for (int i = 0; i < _MessageServers.Count; i++)
  457. {
  458. responseData["messageserver_uri" + i] = _MessageServers[i].URI;
  459. responseData["messageserver_sendkey" + i] = _MessageServers[i].sendkey;
  460. responseData["messageserver_recvkey" + i] = _MessageServers[i].recvkey;
  461. }
  462. return response;
  463. }
  464. private ArrayList GetSimNeighboursData(RegionProfileData sim)
  465. {
  466. ArrayList SimNeighboursData = new ArrayList();
  467. RegionProfileData neighbour;
  468. Hashtable NeighbourBlock;
  469. //First use the fast method. (not implemented in SQLLite)
  470. List<RegionProfileData> neighbours = GetRegions(sim.regionLocX - 1, sim.regionLocY - 1, sim.regionLocX + 1, sim.regionLocY + 1);
  471. if (neighbours.Count > 0)
  472. {
  473. foreach (RegionProfileData aSim in neighbours)
  474. {
  475. NeighbourBlock = new Hashtable();
  476. NeighbourBlock["sim_ip"] = Util.GetHostFromDNS(aSim.serverIP.ToString()).ToString();
  477. NeighbourBlock["sim_port"] = aSim.serverPort.ToString();
  478. NeighbourBlock["region_locx"] = aSim.regionLocX.ToString();
  479. NeighbourBlock["region_locy"] = aSim.regionLocY.ToString();
  480. NeighbourBlock["UUID"] = aSim.ToString();
  481. NeighbourBlock["regionHandle"] = aSim.regionHandle.ToString();
  482. if (aSim.UUID != sim.UUID)
  483. {
  484. SimNeighboursData.Add(NeighbourBlock);
  485. }
  486. }
  487. }
  488. else
  489. {
  490. for (int x = -1; x < 2; x++)
  491. {
  492. for (int y = -1; y < 2; y++)
  493. {
  494. if (
  495. GetRegion(
  496. Helpers.UIntsToLong((uint)((sim.regionLocX + x) * Constants.RegionSize),
  497. (uint)(sim.regionLocY + y) * Constants.RegionSize)) != null)
  498. {
  499. neighbour =
  500. GetRegion(
  501. Helpers.UIntsToLong((uint)((sim.regionLocX + x) * Constants.RegionSize),
  502. (uint)(sim.regionLocY + y) * Constants.RegionSize));
  503. NeighbourBlock = new Hashtable();
  504. NeighbourBlock["sim_ip"] = Util.GetHostFromDNS(neighbour.serverIP).ToString();
  505. NeighbourBlock["sim_port"] = neighbour.serverPort.ToString();
  506. NeighbourBlock["region_locx"] = neighbour.regionLocX.ToString();
  507. NeighbourBlock["region_locy"] = neighbour.regionLocY.ToString();
  508. NeighbourBlock["UUID"] = neighbour.UUID.ToString();
  509. NeighbourBlock["regionHandle"] = neighbour.regionHandle.ToString();
  510. if (neighbour.UUID != sim.UUID) SimNeighboursData.Add(NeighbourBlock);
  511. }
  512. }
  513. }
  514. }
  515. return SimNeighboursData;
  516. }
  517. /// <summary>
  518. /// Loads the grid's own RegionProfileData object with data from the XMLRPC simulator_login request from a region
  519. /// </summary>
  520. /// <param name="requestData"></param>
  521. /// <returns></returns>
  522. private RegionProfileData RegionFromRequest(Hashtable requestData)
  523. {
  524. RegionProfileData sim;
  525. sim = new RegionProfileData();
  526. sim.UUID = new UUID((string)requestData["UUID"]);
  527. sim.originUUID = new UUID((string)requestData["originUUID"]);
  528. sim.regionRecvKey = String.Empty;
  529. sim.regionSendKey = String.Empty;
  530. if (requestData.ContainsKey("region_secret"))
  531. {
  532. string regionsecret = (string)requestData["region_secret"];
  533. if (regionsecret.Length > 0)
  534. sim.regionSecret = regionsecret;
  535. else
  536. sim.regionSecret = Config.SimRecvKey;
  537. }
  538. else
  539. {
  540. sim.regionSecret = Config.SimRecvKey;
  541. }
  542. sim.regionDataURI = String.Empty;
  543. sim.regionAssetURI = Config.DefaultAssetServer;
  544. sim.regionAssetRecvKey = Config.AssetRecvKey;
  545. sim.regionAssetSendKey = Config.AssetSendKey;
  546. sim.regionUserURI = Config.DefaultUserServer;
  547. sim.regionUserSendKey = Config.UserSendKey;
  548. sim.regionUserRecvKey = Config.UserRecvKey;
  549. sim.serverIP = (string)requestData["sim_ip"];
  550. sim.serverPort = Convert.ToUInt32((string)requestData["sim_port"]);
  551. sim.httpPort = Convert.ToUInt32((string)requestData["http_port"]);
  552. sim.remotingPort = Convert.ToUInt32((string)requestData["remoting_port"]);
  553. sim.regionLocX = Convert.ToUInt32((string)requestData["region_locx"]);
  554. sim.regionLocY = Convert.ToUInt32((string)requestData["region_locy"]);
  555. sim.regionLocZ = 0;
  556. UUID textureID;
  557. if (UUID.TryParse((string)requestData["map-image-id"], out textureID))
  558. {
  559. sim.regionMapTextureID = textureID;
  560. }
  561. // part of an initial brutish effort to provide accurate information (as per the xml region spec)
  562. // wrt the ownership of a given region
  563. // the (very bad) assumption is that this value is being read and handled inconsistently or
  564. // not at all. Current strategy is to put the code in place to support the validity of this information
  565. // and to roll forward debugging any issues from that point
  566. //
  567. // this particular section of the mod attempts to receive a value from the region's xml file by way of
  568. // OSG1GridServices for the region's owner
  569. sim.owner_uuid = (UUID)(string)requestData["master_avatar_uuid"];
  570. try
  571. {
  572. sim.regionRecvKey = (string)requestData["recvkey"];
  573. sim.regionSendKey = (string)requestData["authkey"];
  574. }
  575. catch (KeyNotFoundException) { }
  576. sim.regionHandle = Helpers.UIntsToLong((sim.regionLocX * Constants.RegionSize), (sim.regionLocY * Constants.RegionSize));
  577. sim.serverURI = (string)requestData["server_uri"];
  578. sim.httpServerURI = "http://" + sim.serverIP + ":" + sim.httpPort + "/";
  579. sim.regionName = (string)requestData["sim_name"];
  580. return sim;
  581. }
  582. /// <summary>
  583. /// Returns an XML RPC response to a simulator profile request
  584. /// Performed after moving a region.
  585. /// </summary>
  586. /// <param name="request"></param>
  587. /// <returns></returns>
  588. /// <param name="request">The XMLRPC Request</param>
  589. /// <returns>Processing parameters</returns>
  590. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
  591. {
  592. XmlRpcResponse response = new XmlRpcResponse();
  593. Hashtable responseData = new Hashtable();
  594. response.Value = responseData;
  595. //RegionProfileData TheSim = null;
  596. string uuid;
  597. Hashtable requestData = (Hashtable)request.Params[0];
  598. if (requestData.ContainsKey("UUID"))
  599. {
  600. //TheSim = GetRegion(new UUID((string) requestData["UUID"]));
  601. uuid = requestData["UUID"].ToString();
  602. m_log.InfoFormat("[LOGOUT]: Logging out region: {0}", uuid);
  603. // logToDB((new LLUUID((string)requestData["UUID"])).ToString(),"XmlRpcDeleteRegionMethod","", 5,"Attempting delete with UUID.");
  604. }
  605. else
  606. {
  607. responseData["error"] = "No UUID or region_handle passed to grid server - unable to delete";
  608. return response;
  609. }
  610. foreach (IGridDataPlugin plugin in _plugins)
  611. {
  612. //OpenSim.Data.MySQL.MySQLGridData dbengine = new OpenSim.Data.MySQL.MySQLGridData();
  613. try
  614. {
  615. //Nice are we not using multiple databases?
  616. //MySQLGridData mysqldata = (MySQLGridData)(plugin);
  617. //DataResponse insertResponse = mysqldata.DeleteProfile(TheSim);
  618. DataResponse insertResponse = plugin.DeleteProfile(uuid);
  619. switch (insertResponse)
  620. {
  621. case DataResponse.RESPONSE_OK:
  622. //MainLog.Instance.Verbose("grid", "Deleting region successful: " + uuid);
  623. responseData["status"] = "Deleting region successful: " + uuid;
  624. break;
  625. case DataResponse.RESPONSE_ERROR:
  626. //MainLog.Instance.Warn("storage", "Deleting region failed (Error): " + uuid);
  627. responseData["status"] = "Deleting region failed (Error): " + uuid;
  628. break;
  629. case DataResponse.RESPONSE_INVALIDCREDENTIALS:
  630. //MainLog.Instance.Warn("storage", "Deleting region failed (Invalid Credentials): " + uuid);
  631. responseData["status"] = "Deleting region (Invalid Credentials): " + uuid;
  632. break;
  633. case DataResponse.RESPONSE_AUTHREQUIRED:
  634. //MainLog.Instance.Warn("storage", "Deleting region failed (Authentication Required): " + uuid);
  635. responseData["status"] = "Deleting region (Authentication Required): " + uuid;
  636. break;
  637. }
  638. }
  639. catch (Exception)
  640. {
  641. m_log.Error("storage Unable to delete region " + uuid + " via " + plugin.Name);
  642. //MainLog.Instance.Warn("storage", e.ToString());
  643. }
  644. }
  645. return response;
  646. }
  647. /// <summary>
  648. /// Returns an XML RPC response to a simulator profile request
  649. /// </summary>
  650. /// <param name="request"></param>
  651. /// <returns></returns>
  652. public XmlRpcResponse XmlRpcSimulatorDataRequestMethod(XmlRpcRequest request)
  653. {
  654. Hashtable requestData = (Hashtable)request.Params[0];
  655. Hashtable responseData = new Hashtable();
  656. RegionProfileData simData = null;
  657. if (requestData.ContainsKey("region_UUID"))
  658. {
  659. UUID regionID = new UUID((string)requestData["region_UUID"]);
  660. simData = GetRegion(regionID);
  661. if (simData == null)
  662. {
  663. m_log.WarnFormat("[DATA] didn't find region for regionID {0} from {1}",
  664. regionID, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  665. }
  666. }
  667. else if (requestData.ContainsKey("region_handle"))
  668. {
  669. //CFK: The if/else below this makes this message redundant.
  670. //CFK: Console.WriteLine("requesting data for region " + (string) requestData["region_handle"]);
  671. ulong regionHandle = Convert.ToUInt64((string)requestData["region_handle"]);
  672. simData = GetRegion(regionHandle);
  673. if (simData == null)
  674. {
  675. m_log.WarnFormat("[DATA] didn't find region for regionHandle {0} from {1}",
  676. regionHandle, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  677. }
  678. }
  679. else if (requestData.ContainsKey("region_name_search"))
  680. {
  681. string regionName = (string)requestData["region_name_search"];
  682. simData = GetRegion(regionName);
  683. if (simData == null)
  684. {
  685. m_log.WarnFormat("[DATA] didn't find region for regionName {0} from {1}",
  686. regionName, request.Params.Count > 1 ? request.Params[1] : "unknwon source");
  687. }
  688. }
  689. else m_log.Warn("[DATA] regionlookup without regionID, regionHandle or regionHame");
  690. if (simData == null)
  691. {
  692. //Sim does not exist
  693. responseData["error"] = "Sim does not exist";
  694. }
  695. else
  696. {
  697. m_log.Info("[DATA]: found " + (string)simData.regionName + " regionHandle = " +
  698. (string)requestData["region_handle"]);
  699. responseData["sim_ip"] = Util.GetHostFromDNS(simData.serverIP).ToString();
  700. responseData["sim_port"] = simData.serverPort.ToString();
  701. responseData["server_uri"] = simData.serverURI;
  702. responseData["http_port"] = simData.httpPort.ToString();
  703. responseData["remoting_port"] = simData.remotingPort.ToString();
  704. responseData["region_locx"] = simData.regionLocX.ToString();
  705. responseData["region_locy"] = simData.regionLocY.ToString();
  706. responseData["region_UUID"] = simData.UUID.Guid.ToString();
  707. responseData["region_name"] = simData.regionName;
  708. responseData["regionHandle"] = simData.regionHandle.ToString();
  709. }
  710. XmlRpcResponse response = new XmlRpcResponse();
  711. response.Value = responseData;
  712. return response;
  713. }
  714. public XmlRpcResponse XmlRpcMapBlockMethod(XmlRpcRequest request)
  715. {
  716. int xmin = 980, ymin = 980, xmax = 1020, ymax = 1020;
  717. Hashtable requestData = (Hashtable)request.Params[0];
  718. if (requestData.ContainsKey("xmin"))
  719. {
  720. xmin = (Int32)requestData["xmin"];
  721. }
  722. if (requestData.ContainsKey("ymin"))
  723. {
  724. ymin = (Int32)requestData["ymin"];
  725. }
  726. if (requestData.ContainsKey("xmax"))
  727. {
  728. xmax = (Int32)requestData["xmax"];
  729. }
  730. if (requestData.ContainsKey("ymax"))
  731. {
  732. ymax = (Int32)requestData["ymax"];
  733. }
  734. //CFK: The second log is more meaningful and either standard or fast generally occurs.
  735. //CFK: m_log.Info("[MAP]: World map request for range (" + xmin + "," + ymin + ")..(" + xmax + "," + ymax + ")");
  736. XmlRpcResponse response = new XmlRpcResponse();
  737. Hashtable responseData = new Hashtable();
  738. response.Value = responseData;
  739. IList simProfileList = new ArrayList();
  740. bool fastMode = (Config.DatabaseProvider == "OpenSim.Data.MySQL.dll" || Config.DatabaseProvider == "OpenSim.Data.MSSQL.dll");
  741. if (fastMode)
  742. {
  743. List<RegionProfileData> neighbours = GetRegions((uint)xmin, (uint)ymin, (uint)xmax, (uint)ymax);
  744. foreach (RegionProfileData aSim in neighbours)
  745. {
  746. Hashtable simProfileBlock = new Hashtable();
  747. simProfileBlock["x"] = aSim.regionLocX.ToString();
  748. simProfileBlock["y"] = aSim.regionLocY.ToString();
  749. //m_log.DebugFormat("[MAP]: Sending neighbour info for {0},{1}", aSim.regionLocX, aSim.regionLocY);
  750. simProfileBlock["name"] = aSim.regionName;
  751. simProfileBlock["access"] = 21;
  752. simProfileBlock["region-flags"] = 512;
  753. simProfileBlock["water-height"] = 0;
  754. simProfileBlock["agents"] = 1;
  755. simProfileBlock["map-image-id"] = aSim.regionMapTextureID.ToString();
  756. // For Sugilite compatibility
  757. simProfileBlock["regionhandle"] = aSim.regionHandle.ToString();
  758. simProfileBlock["sim_ip"] = aSim.serverIP.ToString();
  759. simProfileBlock["sim_port"] = aSim.serverPort.ToString();
  760. simProfileBlock["sim_uri"] = aSim.serverURI.ToString();
  761. simProfileBlock["uuid"] = aSim.UUID.ToString();
  762. simProfileBlock["remoting_port"] = aSim.remotingPort;
  763. simProfileList.Add(simProfileBlock);
  764. }
  765. m_log.Info("[MAP]: Fast map " + simProfileList.Count.ToString() +
  766. " regions @ (" + xmin + "," + ymin + ")..(" + xmax + "," + ymax + ")");
  767. }
  768. else
  769. {
  770. RegionProfileData simProfile;
  771. for (int x = xmin; x < xmax + 1; x++)
  772. {
  773. for (int y = ymin; y < ymax + 1; y++)
  774. {
  775. ulong regHandle = Helpers.UIntsToLong((uint)(x * Constants.RegionSize), (uint)(y * Constants.RegionSize));
  776. simProfile = GetRegion(regHandle);
  777. if (simProfile != null)
  778. {
  779. Hashtable simProfileBlock = new Hashtable();
  780. simProfileBlock["x"] = x;
  781. simProfileBlock["y"] = y;
  782. simProfileBlock["name"] = simProfile.regionName;
  783. simProfileBlock["access"] = 0;
  784. simProfileBlock["region-flags"] = 0;
  785. simProfileBlock["water-height"] = 20;
  786. simProfileBlock["agents"] = 1;
  787. simProfileBlock["map-image-id"] = simProfile.regionMapTextureID.ToString();
  788. // For Sugilite compatibility
  789. simProfileBlock["regionhandle"] = simProfile.regionHandle.ToString();
  790. simProfileBlock["sim_ip"] = simProfile.serverIP.ToString();
  791. simProfileBlock["sim_port"] = simProfile.serverPort.ToString();
  792. simProfileBlock["sim_uri"] = simProfile.serverURI.ToString();
  793. simProfileBlock["uuid"] = simProfile.UUID.ToString();
  794. simProfileList.Add(simProfileBlock);
  795. }
  796. }
  797. }
  798. m_log.Info("[MAP]: Std map " + simProfileList.Count.ToString() +
  799. " regions @ (" + xmin + "," + ymin + ")..(" + xmax + "," + ymax + ")");
  800. }
  801. responseData["sim-profiles"] = simProfileList;
  802. return response;
  803. }
  804. /// <summary>
  805. /// Returns up to <code>maxNumber</code> profiles of regions that have a name starting with <code>name</code>
  806. /// </summary>
  807. /// <param name="request"></param>
  808. /// <returns></returns>
  809. public XmlRpcResponse XmlRpcSearchForRegionMethod(XmlRpcRequest request)
  810. {
  811. Hashtable requestData = (Hashtable)request.Params[0];
  812. if (!requestData.ContainsKey("name") || !requestData.Contains("maxNumber"))
  813. {
  814. m_log.Warn("[DATA] Invalid region-search request; missing name or maxNumber");
  815. return new XmlRpcResponse(500, "Missing name or maxNumber in region search request");
  816. }
  817. Hashtable responseData = new Hashtable();
  818. string name = (string)requestData["name"];
  819. int maxNumber = Convert.ToInt32((string)requestData["maxNumber"]);
  820. if (maxNumber == 0 || name.Length < 3)
  821. {
  822. // either we didn't want any, or we were too unspecific
  823. responseData["numFound"] = 0;
  824. }
  825. else
  826. {
  827. List<RegionProfileData> sims = GetRegions(name, maxNumber);
  828. responseData["numFound"] = sims.Count;
  829. for (int i = 0; i < sims.Count; ++i)
  830. {
  831. RegionProfileData sim = sims[i];
  832. string prefix = "region" + i + ".";
  833. responseData[prefix + "region_name"] = sim.regionName;
  834. responseData[prefix + "region_UUID"] = sim.UUID.ToString();
  835. responseData[prefix + "region_locx"] = sim.regionLocX.ToString();
  836. responseData[prefix + "region_locy"] = sim.regionLocY.ToString();
  837. responseData[prefix + "sim_ip"] = sim.serverIP.ToString();
  838. responseData[prefix + "sim_port"] = sim.serverPort.ToString();
  839. responseData[prefix + "remoting_port"] = sim.remotingPort.ToString();
  840. responseData[prefix + "http_port"] = sim.httpPort.ToString();
  841. responseData[prefix + "map_UUID"] = sim.regionMapTextureID.ToString();
  842. }
  843. }
  844. XmlRpcResponse response = new XmlRpcResponse();
  845. response.Value = responseData;
  846. return response;
  847. }
  848. /// <summary>
  849. /// Performs a REST Get Operation
  850. /// </summary>
  851. /// <param name="request"></param>
  852. /// <param name="path"></param>
  853. /// <param name="param"></param>
  854. /// <param name="httpRequest">HTTP request header object</param>
  855. /// <param name="httpResponse">HTTP response header object</param>
  856. /// <returns></returns>
  857. public string RestGetRegionMethod(string request, string path, string param,
  858. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  859. {
  860. return RestGetSimMethod(String.Empty, "/sims/", param, httpRequest, httpResponse);
  861. }
  862. /// <summary>
  863. /// Performs a REST Set Operation
  864. /// </summary>
  865. /// <param name="request"></param>
  866. /// <param name="path"></param>
  867. /// <param name="param"></param>
  868. /// <param name="httpRequest">HTTP request header object</param>
  869. /// <param name="httpResponse">HTTP response header object</param>
  870. /// <returns></returns>
  871. public string RestSetRegionMethod(string request, string path, string param,
  872. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  873. {
  874. return RestSetSimMethod(String.Empty, "/sims/", param, httpRequest, httpResponse);
  875. }
  876. /// <summary>
  877. /// Returns information about a sim via a REST Request
  878. /// </summary>
  879. /// <param name="request"></param>
  880. /// <param name="path"></param>
  881. /// <param name="param">A string representing the sim's UUID</param>
  882. /// <param name="httpRequest">HTTP request header object</param>
  883. /// <param name="httpResponse">HTTP response header object</param>
  884. /// <returns>Information about the sim in XML</returns>
  885. public string RestGetSimMethod(string request, string path, string param,
  886. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  887. {
  888. string respstring = String.Empty;
  889. RegionProfileData TheSim;
  890. UUID UUID;
  891. if (UUID.TryParse(param, out UUID))
  892. {
  893. TheSim = GetRegion(UUID);
  894. if (!(TheSim == null))
  895. {
  896. respstring = "<Root>";
  897. respstring += "<authkey>" + TheSim.regionSendKey + "</authkey>";
  898. respstring += "<sim>";
  899. respstring += "<uuid>" + TheSim.ToString() + "</uuid>";
  900. respstring += "<regionname>" + TheSim.regionName + "</regionname>";
  901. respstring += "<sim_ip>" + Util.GetHostFromDNS(TheSim.serverIP).ToString() + "</sim_ip>";
  902. respstring += "<sim_port>" + TheSim.serverPort.ToString() + "</sim_port>";
  903. respstring += "<region_locx>" + TheSim.regionLocX.ToString() + "</region_locx>";
  904. respstring += "<region_locy>" + TheSim.regionLocY.ToString() + "</region_locy>";
  905. respstring += "<estate_id>1</estate_id>";
  906. respstring += "</sim>";
  907. respstring += "</Root>";
  908. }
  909. }
  910. else
  911. {
  912. respstring = "<Root>";
  913. respstring += "<error>Param must be a UUID</error>";
  914. respstring += "</Root>";
  915. }
  916. return respstring;
  917. }
  918. /// <summary>
  919. /// Creates or updates a sim via a REST Method Request
  920. /// BROKEN with SQL Update
  921. /// </summary>
  922. /// <param name="request"></param>
  923. /// <param name="path"></param>
  924. /// <param name="param"></param>
  925. /// <param name="httpRequest">HTTP request header object</param>
  926. /// <param name="httpResponse">HTTP response header object</param>
  927. /// <returns>"OK" or an error</returns>
  928. public string RestSetSimMethod(string request, string path, string param,
  929. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  930. {
  931. Console.WriteLine("Processing region update via REST method");
  932. RegionProfileData theSim;
  933. theSim = GetRegion(new UUID(param));
  934. if (theSim == null)
  935. {
  936. theSim = new RegionProfileData();
  937. UUID UUID = new UUID(param);
  938. theSim.UUID = UUID;
  939. theSim.regionRecvKey = Config.SimRecvKey;
  940. }
  941. XmlDocument doc = new XmlDocument();
  942. doc.LoadXml(request);
  943. XmlNode rootnode = doc.FirstChild;
  944. XmlNode authkeynode = rootnode.ChildNodes[0];
  945. if (authkeynode.Name != "authkey")
  946. {
  947. return "ERROR! bad XML - expected authkey tag";
  948. }
  949. XmlNode simnode = rootnode.ChildNodes[1];
  950. if (simnode.Name != "sim")
  951. {
  952. return "ERROR! bad XML - expected sim tag";
  953. }
  954. //theSim.regionSendKey = Cfg;
  955. theSim.regionRecvKey = Config.SimRecvKey;
  956. theSim.regionSendKey = Config.SimSendKey;
  957. theSim.regionSecret = Config.SimRecvKey;
  958. theSim.regionDataURI = String.Empty;
  959. theSim.regionAssetURI = Config.DefaultAssetServer;
  960. theSim.regionAssetRecvKey = Config.AssetRecvKey;
  961. theSim.regionAssetSendKey = Config.AssetSendKey;
  962. theSim.regionUserURI = Config.DefaultUserServer;
  963. theSim.regionUserSendKey = Config.UserSendKey;
  964. theSim.regionUserRecvKey = Config.UserRecvKey;
  965. for (int i = 0; i < simnode.ChildNodes.Count; i++)
  966. {
  967. switch (simnode.ChildNodes[i].Name)
  968. {
  969. case "regionname":
  970. theSim.regionName = simnode.ChildNodes[i].InnerText;
  971. break;
  972. case "sim_ip":
  973. theSim.serverIP = simnode.ChildNodes[i].InnerText;
  974. break;
  975. case "sim_port":
  976. theSim.serverPort = Convert.ToUInt32(simnode.ChildNodes[i].InnerText);
  977. break;
  978. case "region_locx":
  979. theSim.regionLocX = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
  980. theSim.regionHandle = Helpers.UIntsToLong((theSim.regionLocX * Constants.RegionSize), (theSim.regionLocY * Constants.RegionSize));
  981. break;
  982. case "region_locy":
  983. theSim.regionLocY = Convert.ToUInt32((string)simnode.ChildNodes[i].InnerText);
  984. theSim.regionHandle = Helpers.UIntsToLong((theSim.regionLocX * Constants.RegionSize), (theSim.regionLocY * Constants.RegionSize));
  985. break;
  986. }
  987. }
  988. theSim.serverURI = "http://" + theSim.serverIP + ":" + theSim.serverPort + "/";
  989. bool requirePublic = false;
  990. bool requireValid = true;
  991. if (requirePublic &&
  992. (theSim.serverIP.StartsWith("172.16") || theSim.serverIP.StartsWith("192.168") ||
  993. theSim.serverIP.StartsWith("10.") || theSim.serverIP.StartsWith("0.") ||
  994. theSim.serverIP.StartsWith("255.")))
  995. {
  996. return "ERROR! Servers must register with public addresses.";
  997. }
  998. if (requireValid && (theSim.serverIP.StartsWith("0.") || theSim.serverIP.StartsWith("255.")))
  999. {
  1000. return "ERROR! 0.*.*.* / 255.*.*.* Addresses are invalid, please check your server config and try again";
  1001. }
  1002. try
  1003. {
  1004. m_log.Info("[DATA]: " +
  1005. "Updating / adding via " + _plugins.Count + " storage provider(s) registered.");
  1006. foreach (IGridDataPlugin plugin in _plugins)
  1007. {
  1008. try
  1009. {
  1010. //Check reservations
  1011. ReservationData reserveData =
  1012. plugin.GetReservationAtPoint(theSim.regionLocX, theSim.regionLocY);
  1013. if ((reserveData != null && reserveData.gridRecvKey == theSim.regionRecvKey) ||
  1014. (reserveData == null && authkeynode.InnerText != theSim.regionRecvKey))
  1015. {
  1016. plugin.AddProfile(theSim);
  1017. m_log.Info("[grid]: New sim added to grid (" + theSim.regionName + ")");
  1018. logToDB(theSim.ToString(), "RestSetSimMethod", String.Empty, 5,
  1019. "Region successfully updated and connected to grid.");
  1020. }
  1021. else
  1022. {
  1023. m_log.Warn("[grid]: " +
  1024. "Unable to update region (RestSetSimMethod): Incorrect reservation auth key.");
  1025. // Wanted: " + reserveData.gridRecvKey + ", Got: " + theSim.regionRecvKey + ".");
  1026. return "Unable to update region (RestSetSimMethod): Incorrect auth key.";
  1027. }
  1028. }
  1029. catch (Exception e)
  1030. {
  1031. m_log.Warn("[GRID]: GetRegionPlugin Handle " + plugin.Name + " unable to add new sim: " +
  1032. e.ToString());
  1033. }
  1034. }
  1035. return "OK";
  1036. }
  1037. catch (Exception e)
  1038. {
  1039. return "ERROR! Could not save to database! (" + e.ToString() + ")";
  1040. }
  1041. }
  1042. public XmlRpcResponse XmlRPCRegisterMessageServer(XmlRpcRequest request)
  1043. {
  1044. XmlRpcResponse response = new XmlRpcResponse();
  1045. Hashtable requestData = (Hashtable)request.Params[0];
  1046. Hashtable responseData = new Hashtable();
  1047. if (requestData.Contains("uri"))
  1048. {
  1049. string URI = (string)requestData["URI"];
  1050. string sendkey = (string)requestData["sendkey"];
  1051. string recvkey = (string)requestData["recvkey"];
  1052. MessageServerInfo m = new MessageServerInfo();
  1053. m.URI = URI;
  1054. m.sendkey = sendkey;
  1055. m.recvkey = recvkey;
  1056. if (!_MessageServers.Contains(m))
  1057. _MessageServers.Add(m);
  1058. responseData["responsestring"] = "TRUE";
  1059. response.Value = responseData;
  1060. }
  1061. return response;
  1062. }
  1063. public XmlRpcResponse XmlRPCDeRegisterMessageServer(XmlRpcRequest request)
  1064. {
  1065. XmlRpcResponse response = new XmlRpcResponse();
  1066. Hashtable requestData = (Hashtable)request.Params[0];
  1067. Hashtable responseData = new Hashtable();
  1068. if (requestData.Contains("uri"))
  1069. {
  1070. string URI = (string)requestData["uri"];
  1071. string sendkey = (string)requestData["sendkey"];
  1072. string recvkey = (string)requestData["recvkey"];
  1073. MessageServerInfo m = new MessageServerInfo();
  1074. m.URI = URI;
  1075. m.sendkey = sendkey;
  1076. m.recvkey = recvkey;
  1077. if (_MessageServers.Contains(m))
  1078. _MessageServers.Remove(m);
  1079. responseData["responsestring"] = "TRUE";
  1080. response.Value = responseData;
  1081. }
  1082. return response;
  1083. }
  1084. /// <summary>
  1085. /// Construct an XMLRPC registration disabled response
  1086. /// </summary>
  1087. /// <param name="error"></param>
  1088. /// <returns></returns>
  1089. public static XmlRpcResponse XmlRPCRegionRegistrationDisabledResponse(string error)
  1090. {
  1091. XmlRpcResponse errorResponse = new XmlRpcResponse();
  1092. Hashtable errorResponseData = new Hashtable();
  1093. errorResponse.Value = errorResponseData;
  1094. errorResponseData["restricted"] = error;
  1095. return errorResponse;
  1096. }
  1097. }
  1098. /// <summary>
  1099. /// Exception generated when a simulator fails to login to the grid
  1100. /// </summary>
  1101. public class LoginException : Exception
  1102. {
  1103. /// <summary>
  1104. /// Return an XmlRpcResponse version of the exception message suitable for sending to a client
  1105. /// </summary>
  1106. /// <param name="message"></param>
  1107. /// <param name="xmlRpcMessage"></param>
  1108. public XmlRpcResponse XmlRpcErrorResponse
  1109. {
  1110. get { return m_xmlRpcErrorResponse; }
  1111. }
  1112. private XmlRpcResponse m_xmlRpcErrorResponse;
  1113. public LoginException(string message, string xmlRpcMessage) : base(message)
  1114. {
  1115. // FIXME: Might be neater to refactor and put the method inside here
  1116. m_xmlRpcErrorResponse = GridManager.ErrorResponse(xmlRpcMessage);
  1117. }
  1118. public LoginException(string message, string xmlRpcMessage, Exception e) : base(message, e)
  1119. {
  1120. // FIXME: Might be neater to refactor and put the method inside here
  1121. m_xmlRpcErrorResponse = GridManager.ErrorResponse(xmlRpcMessage);
  1122. }
  1123. }
  1124. }