GridManager.cs 57 KB

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