GridManager.cs 52 KB

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