GridManager.cs 52 KB

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