RemoteAdminPlugin.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  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.IO;
  30. using System.Net;
  31. using System.Reflection;
  32. using System.Timers;
  33. using libsecondlife;
  34. using log4net;
  35. using Mono.Addins;
  36. using Nwc.XmlRpc;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Region.Environment.Modules.World.Terrain;
  40. using OpenSim.Region.Environment.Scenes;
  41. [assembly : Addin]
  42. [assembly : AddinDependency("OpenSim", "0.5")]
  43. namespace OpenSim.ApplicationPlugins.RemoteController
  44. {
  45. [Extension("/OpenSim/Startup")]
  46. public class RemoteAdminPlugin : IApplicationPlugin
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private OpenSimMain m_app;
  50. private BaseHttpServer m_httpd;
  51. private string requiredPassword = String.Empty;
  52. public void Initialise(OpenSimMain openSim)
  53. {
  54. try
  55. {
  56. if (openSim.ConfigSource.Configs["RemoteAdmin"] != null &&
  57. openSim.ConfigSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  58. {
  59. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  60. requiredPassword = openSim.ConfigSource.Configs["RemoteAdmin"].GetString("access_password", String.Empty);
  61. m_app = openSim;
  62. m_httpd = openSim.HttpServer;
  63. m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod);
  64. m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod);
  65. m_httpd.AddXmlRPCHandler("admin_broadcast", XmlRpcAlertMethod);
  66. m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod);
  67. m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod);
  68. m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod);
  69. m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod);
  70. }
  71. }
  72. catch (NullReferenceException)
  73. {
  74. // Ignore.
  75. }
  76. }
  77. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  78. {
  79. XmlRpcResponse response = new XmlRpcResponse();
  80. Hashtable requestData = (Hashtable) request.Params[0];
  81. Hashtable responseData = new Hashtable();
  82. m_log.Info("[RADMIN]: Request to restart Region.");
  83. try {
  84. checkStringParameters(request, new string[] { "password", "regionID" });
  85. if (requiredPassword != String.Empty &&
  86. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  87. throw new Exception("wrong password");
  88. LLUUID regionID = new LLUUID((string) requestData["regionID"]);
  89. responseData["accepted"] = "true";
  90. response.Value = responseData;
  91. Scene rebootedScene;
  92. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  93. throw new Exception("region not found");
  94. responseData["rebooting"] = "true";
  95. rebootedScene.Restart(30);
  96. }
  97. catch(Exception e)
  98. {
  99. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  100. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  101. responseData["accepted"] = "false";
  102. responseData["success"] = "false";
  103. responseData["rebooting"] = "false";
  104. responseData["error"] = e.Message;
  105. response.Value = responseData;
  106. }
  107. return response;
  108. }
  109. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  110. {
  111. XmlRpcResponse response = new XmlRpcResponse();
  112. Hashtable requestData = (Hashtable) request.Params[0];
  113. Hashtable responseData = new Hashtable();
  114. try {
  115. checkStringParameters(request, new string[] { "password", "message" });
  116. if (requiredPassword != String.Empty &&
  117. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  118. throw new Exception("wrong password");
  119. string message = (string) requestData["message"];
  120. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  121. responseData["accepted"] = "true";
  122. response.Value = responseData;
  123. m_app.SceneManager.SendGeneralMessage(message);
  124. }
  125. catch(Exception e)
  126. {
  127. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  128. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  129. responseData["accepted"] = "false";
  130. responseData["success"] = "false";
  131. responseData["error"] = e.Message;
  132. response.Value = responseData;
  133. }
  134. return response;
  135. }
  136. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  137. {
  138. XmlRpcResponse response = new XmlRpcResponse();
  139. Hashtable requestData = (Hashtable)request.Params[0];
  140. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  141. foreach (string k in requestData.Keys)
  142. {
  143. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  144. k, (string)requestData[k], ((string)requestData[k]).Length);
  145. }
  146. Hashtable responseData = new Hashtable();
  147. try {
  148. checkStringParameters(request, new string[] { "password", "filename", "regionid"});
  149. if (requiredPassword != String.Empty &&
  150. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  151. throw new Exception("wrong password");
  152. string file = (string)requestData["filename"];
  153. LLUUID regionID = (string) requestData["regionid"];
  154. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  155. responseData["accepted"] = "true";
  156. Scene region = null;
  157. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  158. throw new Exception("1: unable to get a scene with that name");
  159. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  160. if (null == terrainModule) throw new Exception("terrain module not available");
  161. terrainModule.LoadFromFile(file);
  162. responseData["success"] = "true";
  163. response.Value = responseData;
  164. }
  165. catch (Exception e)
  166. {
  167. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  168. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  169. responseData["success"] = "false";
  170. responseData["error"] = e.Message;
  171. }
  172. return response;
  173. }
  174. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  175. {
  176. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  177. XmlRpcResponse response = new XmlRpcResponse();
  178. Hashtable requestData = (Hashtable) request.Params[0];
  179. Hashtable responseData = new Hashtable();
  180. try {
  181. if (requiredPassword != String.Empty &&
  182. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  183. throw new Exception("wrong password");
  184. responseData["accepted"] = "true";
  185. response.Value = responseData;
  186. int timeout = 2000;
  187. if (requestData.ContainsKey("shutdown") &&
  188. ((string) requestData["shutdown"] == "delayed") &&
  189. requestData.ContainsKey("milliseconds"))
  190. {
  191. timeout = (Int32) requestData["milliseconds"];
  192. m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() +
  193. " second(s). Please save what you are doing and log out.");
  194. }
  195. else
  196. {
  197. m_app.SceneManager.SendGeneralMessage("Region is going down now.");
  198. }
  199. // Perform shutdown
  200. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  201. shutdownTimer.AutoReset = false;
  202. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  203. shutdownTimer.Start();
  204. responseData["success"] = "true";
  205. }
  206. catch (Exception e)
  207. {
  208. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  209. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  210. responseData["accepted"] = "false";
  211. responseData["error"] = e.Message;
  212. response.Value = responseData;
  213. }
  214. return response;
  215. }
  216. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  217. {
  218. m_app.Shutdown();
  219. }
  220. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  221. {
  222. Hashtable requestData = (Hashtable) request.Params[0];
  223. foreach (string p in param)
  224. {
  225. if (!requestData.Contains(p))
  226. throw new Exception(String.Format("missing string parameter {0}", p));
  227. if (String.IsNullOrEmpty((string)requestData[p]))
  228. throw new Exception(String.Format("parameter {0} is empty", p));
  229. }
  230. }
  231. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  232. {
  233. Hashtable requestData = (Hashtable) request.Params[0];
  234. foreach (string p in param)
  235. {
  236. if (!requestData.Contains(p))
  237. throw new Exception(String.Format("missing integer parameter {0}", p));
  238. }
  239. }
  240. /// <summary>
  241. /// Create a new region.
  242. /// <summary>
  243. /// <param name="request">incoming XML RPC request</param>
  244. /// <remarks>
  245. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  246. /// parameters
  247. /// <list type="table">
  248. /// <listheader><term>parameter name</term><description>description</description></listheader>
  249. /// <item><term>password</term>
  250. /// <description>admin password as set in OpenSim.ini</description></item>
  251. /// <item><term>region_name</term>
  252. /// <description>desired region name</description></item>
  253. /// <item><term>region_id</term>
  254. /// <description>(optional) desired region UUID</description></item>
  255. /// <item><term>region_x</term>
  256. /// <description>desired region X coordinate (integer)</description></item>
  257. /// <item><term>region_y</term>
  258. /// <description>desired region Y coordinate (integer)</description></item>
  259. /// <item><term>region_master_first</term>
  260. /// <description>firstname of region master</description></item>
  261. /// <item><term>region_master_last</term>
  262. /// <description>lastname of region master</description></item>
  263. /// <item><term>listen_ip</term>
  264. /// <description>internal IP address (dotted quad)</description></item>
  265. /// <item><term>listen_port</term>
  266. /// <description>internal port (integer)</description></item>
  267. /// <item><term>external_address</term>
  268. /// <description>external IP address</description></item>
  269. /// <item><term>datastore</term>
  270. /// <description>datastore parameter (?)</description></item>
  271. /// <item><term>persist</term>
  272. /// <description>if true, persist the region info
  273. /// ('true' or 'false')</description></item>
  274. /// </list>
  275. ///
  276. /// XmlRpcCreateRegionMethod returns
  277. /// <list type="table">
  278. /// <listheader><term>name</term><description>description</description></listheader>
  279. /// <item><term>success</term>
  280. /// <description>true or false</description></item>
  281. /// <item><term>error</term>
  282. /// <description>error message if success is false</description></item>
  283. /// <item><term>region_uuid</term>
  284. /// <description>UUID of the newly created region</description></item>
  285. /// <item><term>region_name</term>
  286. /// <description>name of the newly created region</description></item>
  287. /// </list>
  288. /// </remarks>
  289. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  290. {
  291. m_log.Info("[RADMIN]: CreateRegion: new request");
  292. XmlRpcResponse response = new XmlRpcResponse();
  293. Hashtable requestData = (Hashtable) request.Params[0];
  294. Hashtable responseData = new Hashtable();
  295. try {
  296. checkStringParameters(request, new string[] { "password",
  297. "region_name",
  298. "region_master_first", "region_master_last",
  299. "region_master_password",
  300. "listen_ip", "external_address"});
  301. checkIntegerParams(request, new string[] { "region_x", "region_y", "listen_port"});
  302. // check password
  303. if (!String.IsNullOrEmpty(requiredPassword) &&
  304. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  305. // extract or generate region ID now
  306. Scene scene = null;
  307. LLUUID regionID = LLUUID.Zero;
  308. if (requestData.ContainsKey("region_id") &&
  309. !String.IsNullOrEmpty((string)requestData["region_id"]))
  310. {
  311. regionID = (string) requestData["region_id"];
  312. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  313. throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  314. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  315. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  316. }
  317. else
  318. {
  319. regionID = LLUUID.Random();
  320. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  321. }
  322. // create volatile or persistent region info
  323. RegionInfo region = new RegionInfo();
  324. region.RegionID = regionID;
  325. region.RegionName = (string) requestData["region_name"];
  326. region.RegionLocX = Convert.ToUInt32((Int32) requestData["region_x"]);
  327. region.RegionLocY = Convert.ToUInt32((Int32) requestData["region_y"]);
  328. // check for collisions: region name, region UUID,
  329. // region location
  330. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  331. throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  332. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  333. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  334. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  335. throw new Exception(String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  336. region.RegionLocX, region.RegionLocY,
  337. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  338. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  339. // Security risk [and apparently not used]
  340. // if (requestData.ContainsKey("datastore"))
  341. // region.DataStore = (string) requestData["datastore"];
  342. region.InternalEndPoint =
  343. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  344. region.InternalEndPoint.Port = (Int32) requestData["listen_port"];
  345. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  346. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  347. throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  348. region.InternalEndPoint.Address,
  349. region.InternalEndPoint.Port,
  350. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  351. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  352. region.ExternalHostName = (string) requestData["external_address"];
  353. region.MasterAvatarFirstName = (string) requestData["region_master_first"];
  354. region.MasterAvatarLastName = (string) requestData["region_master_last"];
  355. region.MasterAvatarSandboxPassword = (string) requestData["region_master_password"];
  356. bool persist = Convert.ToBoolean((string)requestData["persist"]);
  357. if (persist)
  358. {
  359. string regionConfigPath = Path.Combine(Path.Combine(Util.configDir(), "Regions"),
  360. String.Format("{0}x{1}-{2}.xml",
  361. region.RegionLocX.ToString(),
  362. region.RegionLocY.ToString(),
  363. regionID.ToString()));
  364. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  365. region.RegionID, regionConfigPath);
  366. region.SaveRegionToFile("dynamic region", regionConfigPath);
  367. }
  368. m_app.CreateRegion(region);
  369. responseData["success"] = "true";
  370. responseData["region_name"] = region.RegionName;
  371. responseData["region_uuid"] = region.RegionID.ToString();
  372. response.Value = responseData;
  373. }
  374. catch (Exception e)
  375. {
  376. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  377. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  378. responseData["success"] = "false";
  379. responseData["error"] = e.Message;
  380. response.Value = responseData;
  381. }
  382. return response;
  383. }
  384. /// <summary>
  385. /// Create a new user account.
  386. /// <summary>
  387. /// <param name="request">incoming XML RPC request</param>
  388. /// <remarks>
  389. /// XmlRpcCreateUserMethod takes the following XMLRPC
  390. /// parameters
  391. /// <list type="table">
  392. /// <listheader><term>parameter name</term><description>description</description></listheader>
  393. /// <item><term>password</term>
  394. /// <description>admin password as set in OpenSim.ini</description></item>
  395. /// <item><term>user_firstname</term>
  396. /// <description>avatar's first name</description></item>
  397. /// <item><term>user_lastname</term>
  398. /// <description>avatar's last name</description></item>
  399. /// <item><term>user_password</term>
  400. /// <description>avatar's password</description></item>
  401. /// <item><term>start_region_x</term>
  402. /// <description>avatar's start region coordinates, X value</description></item>
  403. /// <item><term>start_region_y</term>
  404. /// <description>avatar's start region coordinates, Y value</description></item>
  405. /// </list>
  406. ///
  407. /// XmlRpcCreateUserMethod returns
  408. /// <list type="table">
  409. /// <listheader><term>name</term><description>description</description></listheader>
  410. /// <item><term>success</term>
  411. /// <description>true or false</description></item>
  412. /// <item><term>error</term>
  413. /// <description>error message if success is false</description></item>
  414. /// <item><term>avatar_uuid</term>
  415. /// <description>UUID of the newly created avatar
  416. /// account; LLUUID.Zero if failed.
  417. /// </description></item>
  418. /// </list>
  419. /// </remarks>
  420. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  421. {
  422. m_log.Info("[RADMIN]: CreateUser: new request");
  423. XmlRpcResponse response = new XmlRpcResponse();
  424. Hashtable requestData = (Hashtable) request.Params[0];
  425. Hashtable responseData = new Hashtable();
  426. try
  427. {
  428. // check completeness
  429. checkStringParameters(request, new string[] { "password", "user_firstname",
  430. "user_lastname", "user_password" });
  431. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  432. // check password
  433. if (!String.IsNullOrEmpty(requiredPassword) &&
  434. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  435. // do the job
  436. string firstname = (string) requestData["user_firstname"];
  437. string lastname = (string) requestData["user_lastname"];
  438. string passwd = (string) requestData["user_password"];
  439. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  440. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  441. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  442. if (null != userProfile)
  443. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  444. LLUUID userID = m_app.CreateUser(firstname, lastname, passwd, regX, regY);
  445. if (userID == LLUUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  446. firstname, lastname));
  447. responseData["success"] = "true";
  448. responseData["avatar_uuid"] = userID.ToString();
  449. response.Value = responseData;
  450. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  451. }
  452. catch (Exception e)
  453. {
  454. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  455. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  456. responseData["success"] = "false";
  457. responseData["avatar_uuid"] = LLUUID.Zero.ToString();
  458. responseData["error"] = e.Message;
  459. response.Value = responseData;
  460. }
  461. return response;
  462. }
  463. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  464. {
  465. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  466. XmlRpcResponse response = new XmlRpcResponse();
  467. Hashtable requestData = (Hashtable) request.Params[0];
  468. Hashtable responseData = new Hashtable();
  469. try
  470. {
  471. // check completeness
  472. foreach (string p in new string[] { "password", "filename" })
  473. {
  474. if (!requestData.Contains(p))
  475. throw new Exception(String.Format("missing parameter {0}", p));
  476. if (String.IsNullOrEmpty((string)requestData[p]))
  477. throw new Exception(String.Format("parameter {0} is empty"));
  478. }
  479. // check password
  480. if (!String.IsNullOrEmpty(requiredPassword) &&
  481. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  482. string filename = (string)requestData["filename"];
  483. if (requestData.Contains("region_uuid"))
  484. {
  485. LLUUID region_uuid = (string)requestData["region_uuid"];
  486. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  487. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  488. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  489. }
  490. else if (requestData.Contains("region_name"))
  491. {
  492. string region_name = (string)requestData["region_name"];
  493. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  494. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  495. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  496. }
  497. else throw new Exception("neither region_name nor region_uuid given");
  498. responseData["switched"] = "true";
  499. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new LLVector3(0, 0, 0));
  500. responseData["loaded"] = "true";
  501. response.Value = responseData;
  502. }
  503. catch (Exception e)
  504. {
  505. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  506. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  507. responseData["loaded"] = "false";
  508. responseData["switched"] = "false";
  509. responseData["error"] = e.Message;
  510. response.Value = responseData;
  511. }
  512. return response;
  513. }
  514. public void Close()
  515. {
  516. }
  517. }
  518. }