RemoteAdminPlugin.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  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 OpenMetaverse;
  34. using log4net;
  35. using Nini.Config;
  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. using OpenSim.Region.Environment.Modules.World.Archiver;
  42. namespace OpenSim.ApplicationPlugins.RemoteController
  43. {
  44. public class RemoteAdminPlugin : IApplicationPlugin
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private OpenSimBase m_app;
  48. private BaseHttpServer m_httpd;
  49. private IConfig m_config;
  50. private IConfigSource m_configSource;
  51. private string requiredPassword = String.Empty;
  52. // TODO: required by IPlugin, but likely not at all right
  53. string m_name = "RemoteAdminPlugin";
  54. string m_version = "0.0";
  55. public string Version { get { return m_version; } }
  56. public string Name { get { return m_name; } }
  57. public void Initialise()
  58. {
  59. m_log.Info("[RADMIN]: " + Name + " cannot be default-initialized!");
  60. throw new PluginNotInitialisedException (Name);
  61. }
  62. public void Initialise(OpenSimBase openSim)
  63. {
  64. m_configSource = openSim.ConfigSource.Source;
  65. try
  66. {
  67. if (m_configSource.Configs["RemoteAdmin"] == null ||
  68. !m_configSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  69. {
  70. // No config or disabled
  71. }
  72. else
  73. {
  74. m_config = m_configSource.Configs["RemoteAdmin"];
  75. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  76. requiredPassword = m_config.GetString("access_password", String.Empty);
  77. m_app = openSim;
  78. m_httpd = openSim.HttpServer;
  79. m_httpd.AddXmlRPCHandler("admin_create_region", XmlRpcCreateRegionMethod, false);
  80. m_httpd.AddXmlRPCHandler("admin_delete_region", XmlRpcDeleteRegionMethod, false);
  81. m_httpd.AddXmlRPCHandler("admin_shutdown", XmlRpcShutdownMethod, false);
  82. m_httpd.AddXmlRPCHandler("admin_broadcast", XmlRpcAlertMethod, false);
  83. m_httpd.AddXmlRPCHandler("admin_restart", XmlRpcRestartMethod, false);
  84. m_httpd.AddXmlRPCHandler("admin_load_heightmap", XmlRpcLoadHeightmapMethod, false);
  85. m_httpd.AddXmlRPCHandler("admin_create_user", XmlRpcCreateUserMethod, false);
  86. m_httpd.AddXmlRPCHandler("admin_exists_user", XmlRpcUserExistsMethod, false);
  87. m_httpd.AddXmlRPCHandler("admin_update_user", XmlRpcUpdateUserAccountMethod, false);
  88. m_httpd.AddXmlRPCHandler("admin_load_xml", XmlRpcLoadXMLMethod, false);
  89. m_httpd.AddXmlRPCHandler("admin_save_xml", XmlRpcSaveXMLMethod, false);
  90. m_httpd.AddXmlRPCHandler("admin_load_oar", XmlRpcLoadOARMethod, false);
  91. m_httpd.AddXmlRPCHandler("admin_save_oar", XmlRpcSaveOARMethod, false);
  92. m_httpd.AddXmlRPCHandler("admin_region_query", XmlRpcRegionQueryMethod, false);
  93. }
  94. }
  95. catch (NullReferenceException)
  96. {
  97. // Ignore.
  98. }
  99. }
  100. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  101. {
  102. XmlRpcResponse response = new XmlRpcResponse();
  103. Hashtable responseData = new Hashtable();
  104. try {
  105. Hashtable requestData = (Hashtable) request.Params[0];
  106. m_log.Info("[RADMIN]: Request to restart Region.");
  107. checkStringParameters(request, new string[] { "password", "regionID" });
  108. if (requiredPassword != String.Empty &&
  109. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  110. {
  111. throw new Exception("wrong password");
  112. }
  113. UUID regionID = new UUID((string) requestData["regionID"]);
  114. responseData["accepted"] = "true";
  115. responseData["success"] = "true";
  116. response.Value = responseData;
  117. Scene rebootedScene;
  118. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  119. throw new Exception("region not found");
  120. responseData["rebooting"] = "true";
  121. response.Value = responseData;
  122. rebootedScene.Restart(30);
  123. }
  124. catch(Exception e)
  125. {
  126. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  127. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  128. responseData["accepted"] = "false";
  129. responseData["success"] = "false";
  130. responseData["rebooting"] = "false";
  131. responseData["error"] = e.Message;
  132. response.Value = responseData;
  133. }
  134. return response;
  135. }
  136. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  137. {
  138. XmlRpcResponse response = new XmlRpcResponse();
  139. Hashtable responseData = new Hashtable();
  140. try {
  141. Hashtable requestData = (Hashtable) request.Params[0];
  142. checkStringParameters(request, new string[] { "password", "message" });
  143. if (requiredPassword != String.Empty &&
  144. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  145. throw new Exception("wrong password");
  146. string message = (string) requestData["message"];
  147. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  148. responseData["accepted"] = "true";
  149. responseData["success"] = "true";
  150. response.Value = responseData;
  151. m_app.SceneManager.SendGeneralMessage(message);
  152. }
  153. catch(Exception e)
  154. {
  155. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  156. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  157. responseData["accepted"] = "false";
  158. responseData["success"] = "false";
  159. responseData["error"] = e.Message;
  160. response.Value = responseData;
  161. }
  162. return response;
  163. }
  164. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  165. {
  166. XmlRpcResponse response = new XmlRpcResponse();
  167. Hashtable responseData = new Hashtable();
  168. try {
  169. Hashtable requestData = (Hashtable)request.Params[0];
  170. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  171. // foreach (string k in requestData.Keys)
  172. // {
  173. // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  174. // k, (string)requestData[k], ((string)requestData[k]).Length);
  175. // }
  176. checkStringParameters(request, new string[] { "password", "filename", "regionid"});
  177. if (requiredPassword != String.Empty &&
  178. (!requestData.Contains("password") || (string)requestData["password"] != requiredPassword))
  179. throw new Exception("wrong password");
  180. string file = (string)requestData["filename"];
  181. UUID regionID = (UUID)(string) requestData["regionid"];
  182. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  183. responseData["accepted"] = "true";
  184. Scene region = null;
  185. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  186. throw new Exception("1: unable to get a scene with that name");
  187. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  188. if (null == terrainModule) throw new Exception("terrain module not available");
  189. terrainModule.LoadFromFile(file);
  190. responseData["success"] = "true";
  191. response.Value = responseData;
  192. }
  193. catch (Exception e)
  194. {
  195. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  196. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  197. responseData["success"] = "false";
  198. responseData["error"] = e.Message;
  199. }
  200. return response;
  201. }
  202. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  203. {
  204. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  205. XmlRpcResponse response = new XmlRpcResponse();
  206. Hashtable responseData = new Hashtable();
  207. try {
  208. Hashtable requestData = (Hashtable) request.Params[0];
  209. if (requiredPassword != String.Empty &&
  210. (!requestData.Contains("password") || (string) requestData["password"] != requiredPassword))
  211. throw new Exception("wrong password");
  212. responseData["accepted"] = "true";
  213. response.Value = responseData;
  214. int timeout = 2000;
  215. if (requestData.ContainsKey("shutdown") &&
  216. ((string) requestData["shutdown"] == "delayed") &&
  217. requestData.ContainsKey("milliseconds"))
  218. {
  219. timeout = (Int32) requestData["milliseconds"];
  220. m_app.SceneManager.SendGeneralMessage("Region is going down in " + ((int) (timeout/1000)).ToString() +
  221. " second(s). Please save what you are doing and log out.");
  222. }
  223. else
  224. {
  225. m_app.SceneManager.SendGeneralMessage("Region is going down now.");
  226. }
  227. // Perform shutdown
  228. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  229. shutdownTimer.AutoReset = false;
  230. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  231. shutdownTimer.Start();
  232. responseData["success"] = "true";
  233. }
  234. catch (Exception e)
  235. {
  236. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  237. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  238. responseData["accepted"] = "false";
  239. responseData["error"] = e.Message;
  240. response.Value = responseData;
  241. }
  242. return response;
  243. }
  244. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  245. {
  246. m_app.Shutdown();
  247. }
  248. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  249. {
  250. Hashtable requestData = (Hashtable) request.Params[0];
  251. foreach (string p in param)
  252. {
  253. if (!requestData.Contains(p))
  254. throw new Exception(String.Format("missing string parameter {0}", p));
  255. if (String.IsNullOrEmpty((string)requestData[p]))
  256. throw new Exception(String.Format("parameter {0} is empty", p));
  257. }
  258. }
  259. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  260. {
  261. Hashtable requestData = (Hashtable) request.Params[0];
  262. foreach (string p in param)
  263. {
  264. if (!requestData.Contains(p))
  265. throw new Exception(String.Format("missing integer parameter {0}", p));
  266. }
  267. }
  268. /// <summary>
  269. /// Create a new region.
  270. /// <summary>
  271. /// <param name="request">incoming XML RPC request</param>
  272. /// <remarks>
  273. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  274. /// parameters
  275. /// <list type="table">
  276. /// <listheader><term>parameter name</term><description>description</description></listheader>
  277. /// <item><term>password</term>
  278. /// <description>admin password as set in OpenSim.ini</description></item>
  279. /// <item><term>region_name</term>
  280. /// <description>desired region name</description></item>
  281. /// <item><term>region_id</term>
  282. /// <description>(optional) desired region UUID</description></item>
  283. /// <item><term>region_x</term>
  284. /// <description>desired region X coordinate (integer)</description></item>
  285. /// <item><term>region_y</term>
  286. /// <description>desired region Y coordinate (integer)</description></item>
  287. /// <item><term>region_master_first</term>
  288. /// <description>firstname of region master</description></item>
  289. /// <item><term>region_master_last</term>
  290. /// <description>lastname of region master</description></item>
  291. /// <item><term>region_master_uuid</term>
  292. /// <description>explicit UUID to use for master avatar (optional)</description></item>
  293. /// <item><term>listen_ip</term>
  294. /// <description>internal IP address (dotted quad)</description></item>
  295. /// <item><term>listen_port</term>
  296. /// <description>internal port (integer)</description></item>
  297. /// <item><term>external_address</term>
  298. /// <description>external IP address</description></item>
  299. /// <item><term>persist</term>
  300. /// <description>if true, persist the region info
  301. /// ('true' or 'false')</description></item>
  302. /// </list>
  303. ///
  304. /// XmlRpcCreateRegionMethod returns
  305. /// <list type="table">
  306. /// <listheader><term>name</term><description>description</description></listheader>
  307. /// <item><term>success</term>
  308. /// <description>true or false</description></item>
  309. /// <item><term>error</term>
  310. /// <description>error message if success is false</description></item>
  311. /// <item><term>region_uuid</term>
  312. /// <description>UUID of the newly created region</description></item>
  313. /// <item><term>region_name</term>
  314. /// <description>name of the newly created region</description></item>
  315. /// </list>
  316. /// </remarks>
  317. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  318. {
  319. m_log.Info("[RADMIN]: CreateRegion: new request");
  320. XmlRpcResponse response = new XmlRpcResponse();
  321. Hashtable responseData = new Hashtable();
  322. try {
  323. Hashtable requestData = (Hashtable) request.Params[0];
  324. checkStringParameters(request, new string[] { "password",
  325. "region_name",
  326. "region_master_first", "region_master_last",
  327. "region_master_password",
  328. "listen_ip", "external_address"});
  329. checkIntegerParams(request, new string[] {"region_x", "region_y", "listen_port"});
  330. // check password
  331. if (!String.IsNullOrEmpty(requiredPassword) &&
  332. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  333. // extract or generate region ID now
  334. Scene scene = null;
  335. UUID regionID = UUID.Zero;
  336. if (requestData.ContainsKey("region_id") &&
  337. !String.IsNullOrEmpty((string)requestData["region_id"]))
  338. {
  339. regionID = (UUID)(string)requestData["region_id"];
  340. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  341. throw new Exception(String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  342. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  343. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  344. }
  345. else
  346. {
  347. regionID = UUID.Random();
  348. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  349. }
  350. // create volatile or persistent region info
  351. RegionInfo region = new RegionInfo();
  352. region.RegionID = regionID;
  353. region.RegionName = (string) requestData["region_name"];
  354. region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
  355. region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
  356. // check for collisions: region name, region UUID,
  357. // region location
  358. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  359. throw new Exception(String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  360. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  361. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  362. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  363. throw new Exception(String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  364. region.RegionLocX, region.RegionLocY,
  365. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  366. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  367. region.InternalEndPoint =
  368. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  369. region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
  370. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  371. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  372. throw new Exception(String.Format("region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  373. region.InternalEndPoint.Address,
  374. region.InternalEndPoint.Port,
  375. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  376. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  377. region.ExternalHostName = (string)requestData["external_address"];
  378. string masterFirst = (string)requestData["region_master_first"];
  379. string masterLast = (string)requestData["region_master_last"];
  380. string masterPassword = (string)requestData["region_master_password"];
  381. UUID userID = UUID.Zero;
  382. if (requestData.ContainsKey("region_master_uuid"))
  383. {
  384. // ok, client wants us to use an explicit UUID
  385. // regardless of what the avatar name provided
  386. userID = new UUID((string)requestData["region_master_uuid"]);
  387. }
  388. else
  389. {
  390. // no client supplied UUID: look it up...
  391. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(masterFirst, masterLast);
  392. if (null == userProfile)
  393. {
  394. m_log.InfoFormat("master avatar does not exist, creating it");
  395. // ...or create new user
  396. userID = m_app.CreateUser(masterFirst, masterLast, masterPassword, region.RegionLocX, region.RegionLocY);
  397. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  398. masterFirst, masterLast));
  399. }
  400. else
  401. {
  402. userID = userProfile.ID;
  403. }
  404. }
  405. region.MasterAvatarFirstName = masterFirst;
  406. region.MasterAvatarLastName = masterLast;
  407. region.MasterAvatarSandboxPassword = masterPassword;
  408. region.MasterAvatarAssignedUUID = userID;
  409. bool persist = Convert.ToBoolean((string)requestData["persist"]);
  410. if (persist)
  411. {
  412. // default place for region XML files is in the
  413. // Regions directory of the config dir (aka /bin)
  414. string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
  415. try
  416. {
  417. // OpenSim.ini can specify a different regions dir
  418. IConfig startupConfig = (IConfig)m_configSource.Configs["Startup"];
  419. regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
  420. }
  421. catch (Exception)
  422. {
  423. // No INI setting recorded.
  424. }
  425. string regionXmlPath = Path.Combine(regionConfigPath,
  426. String.Format(m_config.GetString("region_file_template", "{0}x{1}-{2}.xml"),
  427. region.RegionLocX.ToString(),
  428. region.RegionLocY.ToString(),
  429. regionID.ToString(),
  430. region.InternalEndPoint.Port.ToString(),
  431. region.RegionName.Replace(" ", "_").Replace(":", "_").Replace("/", "_")));
  432. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  433. region.RegionID, regionXmlPath);
  434. region.SaveRegionToFile("dynamic region", regionXmlPath);
  435. }
  436. m_app.CreateRegion(region);
  437. responseData["success"] = "true";
  438. responseData["region_name"] = region.RegionName;
  439. responseData["region_uuid"] = region.RegionID.ToString();
  440. response.Value = responseData;
  441. }
  442. catch (Exception e)
  443. {
  444. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  445. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  446. responseData["success"] = "false";
  447. responseData["error"] = e.Message;
  448. response.Value = responseData;
  449. }
  450. return response;
  451. }
  452. /// <summary>
  453. /// Delete a new region.
  454. /// <summary>
  455. /// <param name="request">incoming XML RPC request</param>
  456. /// <remarks>
  457. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  458. /// parameters
  459. /// <list type="table">
  460. /// <listheader><term>parameter name</term><description>description</description></listheader>
  461. /// <item><term>password</term>
  462. /// <description>admin password as set in OpenSim.ini</description></item>
  463. /// <item><term>region_name</term>
  464. /// <description>desired region name</description></item>
  465. /// <item><term>region_id</term>
  466. /// <description>(optional) desired region UUID</description></item>
  467. /// </list>
  468. ///
  469. /// XmlRpcCreateRegionMethod returns
  470. /// <list type="table">
  471. /// <listheader><term>name</term><description>description</description></listheader>
  472. /// <item><term>success</term>
  473. /// <description>true or false</description></item>
  474. /// <item><term>error</term>
  475. /// <description>error message if success is false</description></item>
  476. /// </list>
  477. /// </remarks>
  478. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
  479. {
  480. m_log.Info("[RADMIN]: DeleteRegion: new request");
  481. XmlRpcResponse response = new XmlRpcResponse();
  482. Hashtable responseData = new Hashtable();
  483. try {
  484. Hashtable requestData = (Hashtable) request.Params[0];
  485. checkStringParameters(request, new string[] {"password", "region_name"});
  486. Scene scene = null;
  487. string regionName = (string)requestData["region_name"];
  488. if (!m_app.SceneManager.TryGetScene(regionName, out scene))
  489. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  490. m_app.RemoveRegion(scene, true);
  491. responseData["success"] = "true";
  492. responseData["region_name"] = regionName;
  493. response.Value = responseData;
  494. }
  495. catch (Exception e)
  496. {
  497. m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0}", e.Message);
  498. m_log.DebugFormat("[RADMIN] DeleteRegion: failed {0}", e.ToString());
  499. responseData["success"] = "false";
  500. responseData["error"] = e.Message;
  501. response.Value = responseData;
  502. }
  503. return response;
  504. }
  505. /// <summary>
  506. /// Create a new user account.
  507. /// <summary>
  508. /// <param name="request">incoming XML RPC request</param>
  509. /// <remarks>
  510. /// XmlRpcCreateUserMethod takes the following XMLRPC
  511. /// parameters
  512. /// <list type="table">
  513. /// <listheader><term>parameter name</term><description>description</description></listheader>
  514. /// <item><term>password</term>
  515. /// <description>admin password as set in OpenSim.ini</description></item>
  516. /// <item><term>user_firstname</term>
  517. /// <description>avatar's first name</description></item>
  518. /// <item><term>user_lastname</term>
  519. /// <description>avatar's last name</description></item>
  520. /// <item><term>user_password</term>
  521. /// <description>avatar's password</description></item>
  522. /// <item><term>start_region_x</term>
  523. /// <description>avatar's start region coordinates, X value</description></item>
  524. /// <item><term>start_region_y</term>
  525. /// <description>avatar's start region coordinates, Y value</description></item>
  526. /// </list>
  527. ///
  528. /// XmlRpcCreateUserMethod returns
  529. /// <list type="table">
  530. /// <listheader><term>name</term><description>description</description></listheader>
  531. /// <item><term>success</term>
  532. /// <description>true or false</description></item>
  533. /// <item><term>error</term>
  534. /// <description>error message if success is false</description></item>
  535. /// <item><term>avatar_uuid</term>
  536. /// <description>UUID of the newly created avatar
  537. /// account; UUID.Zero if failed.
  538. /// </description></item>
  539. /// </list>
  540. /// </remarks>
  541. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  542. {
  543. m_log.Info("[RADMIN]: CreateUser: new request");
  544. XmlRpcResponse response = new XmlRpcResponse();
  545. Hashtable responseData = new Hashtable();
  546. try
  547. {
  548. Hashtable requestData = (Hashtable) request.Params[0];
  549. // check completeness
  550. checkStringParameters(request, new string[] { "password", "user_firstname",
  551. "user_lastname", "user_password" });
  552. checkIntegerParams(request, new string[] { "start_region_x", "start_region_y" });
  553. // check password
  554. if (!String.IsNullOrEmpty(requiredPassword) &&
  555. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  556. // do the job
  557. string firstname = (string) requestData["user_firstname"];
  558. string lastname = (string) requestData["user_lastname"];
  559. string passwd = (string) requestData["user_password"];
  560. uint regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  561. uint regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  562. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  563. if (null != userProfile)
  564. throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
  565. UUID userID = m_app.CreateUser(firstname, lastname, passwd, regX, regY);
  566. if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
  567. firstname, lastname));
  568. responseData["success"] = "true";
  569. responseData["avatar_uuid"] = userID.ToString();
  570. response.Value = responseData;
  571. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  572. }
  573. catch (Exception e)
  574. {
  575. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  576. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  577. responseData["success"] = "false";
  578. responseData["avatar_uuid"] = UUID.Zero.ToString();
  579. responseData["error"] = e.Message;
  580. response.Value = responseData;
  581. }
  582. return response;
  583. }
  584. /// <summary>
  585. /// Check whether a certain user account exists.
  586. /// <summary>
  587. /// <param name="request">incoming XML RPC request</param>
  588. /// <remarks>
  589. /// XmlRpcUserExistsMethod takes the following XMLRPC
  590. /// parameters
  591. /// <list type="table">
  592. /// <listheader><term>parameter name</term><description>description</description></listheader>
  593. /// <item><term>password</term>
  594. /// <description>admin password as set in OpenSim.ini</description></item>
  595. /// <item><term>user_firstname</term>
  596. /// <description>avatar's first name</description></item>
  597. /// <item><term>user_lastname</term>
  598. /// <description>avatar's last name</description></item>
  599. /// </list>
  600. ///
  601. /// XmlRpcCreateUserMethod returns
  602. /// <list type="table">
  603. /// <listheader><term>name</term><description>description</description></listheader>
  604. /// <item><term>user_firstname</term>
  605. /// <description>avatar's first name</description></item>
  606. /// <item><term>user_lastname</term>
  607. /// <description>avatar's last name</description></item>
  608. /// <item><term>success</term>
  609. /// <description>true or false</description></item>
  610. /// <item><term>error</term>
  611. /// <description>error message if success is false</description></item>
  612. /// </list>
  613. /// </remarks>
  614. public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request)
  615. {
  616. m_log.Info("[RADMIN]: UserExists: new request");
  617. XmlRpcResponse response = new XmlRpcResponse();
  618. Hashtable responseData = new Hashtable();
  619. try
  620. {
  621. Hashtable requestData = (Hashtable) request.Params[0];
  622. // check completeness
  623. checkStringParameters(request, new string[] { "password", "user_firstname", "user_lastname"});
  624. string firstname = (string) requestData["user_firstname"];
  625. string lastname = (string) requestData["user_lastname"];
  626. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  627. responseData["user_firstname"] = firstname;
  628. responseData["user_lastname"] = lastname;
  629. if (null == userProfile)
  630. responseData["success"] = false;
  631. else
  632. responseData["success"] = true;
  633. response.Value = responseData;
  634. }
  635. catch (Exception e)
  636. {
  637. m_log.ErrorFormat("[RADMIN] UserExists: failed: {0}", e.Message);
  638. m_log.DebugFormat("[RADMIN] UserExists: failed: {0}", e.ToString());
  639. responseData["success"] = "false";
  640. responseData["error"] = e.Message;
  641. response.Value = responseData;
  642. }
  643. return response;
  644. }
  645. /// <summary>
  646. /// Update the password of a user account.
  647. /// <summary>
  648. /// <param name="request">incoming XML RPC request</param>
  649. /// <remarks>
  650. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  651. /// parameters
  652. /// <list type="table">
  653. /// <listheader><term>parameter name</term><description>description</description></listheader>
  654. /// <item><term>password</term>
  655. /// <description>admin password as set in OpenSim.ini</description></item>
  656. /// <item><term>user_firstname</term>
  657. /// <description>avatar's first name (cannot be changed)</description></item>
  658. /// <item><term>user_lastname</term>
  659. /// <description>avatar's last name (cannot be changed)</description></item>
  660. /// <item><term>user_password</term>
  661. /// <description>avatar's password (changeable)</description></item>
  662. /// <item><term>start_region_x</term>
  663. /// <description>avatar's start region coordinates, X
  664. /// value (changeable)</description></item>
  665. /// <item><term>start_region_y</term>
  666. /// <description>avatar's start region coordinates, Y
  667. /// value (changeable)</description></item>
  668. /// </list>
  669. ///
  670. /// XmlRpcCreateUserMethod returns
  671. /// <list type="table">
  672. /// <listheader><term>name</term><description>description</description></listheader>
  673. /// <item><term>success</term>
  674. /// <description>true or false</description></item>
  675. /// <item><term>error</term>
  676. /// <description>error message if success is false</description></item>
  677. /// </list>
  678. /// </remarks>
  679. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request)
  680. {
  681. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  682. XmlRpcResponse response = new XmlRpcResponse();
  683. Hashtable responseData = new Hashtable();
  684. try
  685. {
  686. Hashtable requestData = (Hashtable) request.Params[0];
  687. // check completeness
  688. checkStringParameters(request, new string[] { "password", "user_firstname",
  689. "user_lastname" });
  690. // check password
  691. if (!String.IsNullOrEmpty(requiredPassword) &&
  692. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  693. // do the job
  694. string firstname = (string) requestData["user_firstname"];
  695. string lastname = (string) requestData["user_lastname"];
  696. string passwd = String.Empty;
  697. uint? regX = null;
  698. uint? regY = null;
  699. uint? ulaX = null;
  700. uint? ulaY = null;
  701. uint? ulaZ = null;
  702. uint? usaX = null;
  703. uint? usaY = null;
  704. uint? usaZ = null;
  705. if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"];
  706. if (requestData.ContainsKey("start_region_x")) regX = Convert.ToUInt32((Int32)requestData["start_region_x"]);
  707. if (requestData.ContainsKey("start_region_y")) regY = Convert.ToUInt32((Int32)requestData["start_region_y"]);
  708. if (requestData.ContainsKey("start_lookat_x")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_x"]);
  709. if (requestData.ContainsKey("start_lookat_y")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_y"]);
  710. if (requestData.ContainsKey("start_lookat_z")) ulaY = Convert.ToUInt32((Int32)requestData["start_lookat_z"]);
  711. if (requestData.ContainsKey("start_standat_x")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_x"]);
  712. if (requestData.ContainsKey("start_standat_y")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_y"]);
  713. if (requestData.ContainsKey("start_standat_z")) usaY = Convert.ToUInt32((Int32)requestData["start_standat_z"]);
  714. UserProfileData userProfile = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  715. if (null == userProfile)
  716. throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname));
  717. if (null != passwd)
  718. {
  719. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty);
  720. userProfile.PasswordHash = md5PasswdHash;
  721. }
  722. if (null != regX) userProfile.HomeRegionX = (uint)regX;
  723. if (null != regY) userProfile.HomeRegionY = (uint)regY;
  724. if (null != usaX) userProfile.HomeLocationX = (uint)usaX;
  725. if (null != usaY) userProfile.HomeLocationY = (uint)usaY;
  726. if (null != usaZ) userProfile.HomeLocationZ = (uint)usaZ;
  727. if (null != ulaX) userProfile.HomeLookAtX = (uint)ulaX;
  728. if (null != ulaY) userProfile.HomeLookAtY = (uint)ulaY;
  729. if (null != ulaZ) userProfile.HomeLookAtZ = (uint)ulaZ;
  730. if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile))
  731. throw new Exception("did not manage to update user profile");
  732. responseData["success"] = "true";
  733. response.Value = responseData;
  734. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}", firstname, lastname,
  735. userProfile.ID);
  736. }
  737. catch (Exception e)
  738. {
  739. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message);
  740. m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString());
  741. responseData["success"] = "false";
  742. responseData["error"] = e.Message;
  743. response.Value = responseData;
  744. }
  745. return response;
  746. }
  747. /// <summary>
  748. /// Load an OAR file into a region..
  749. /// <summary>
  750. /// <param name="request">incoming XML RPC request</param>
  751. /// <remarks>
  752. /// XmlRpcLoadOARMethod takes the following XMLRPC
  753. /// parameters
  754. /// <list type="table">
  755. /// <listheader><term>parameter name</term><description>description</description></listheader>
  756. /// <item><term>password</term>
  757. /// <description>admin password as set in OpenSim.ini</description></item>
  758. /// <item><term>filename</term>
  759. /// <description>file name of the OAR file</description></item>
  760. /// <item><term>region_uuid</term>
  761. /// <description>UUID of the region</description></item>
  762. /// <item><term>region_name</term>
  763. /// <description>region name</description></item>
  764. /// </list>
  765. ///
  766. /// <code>region_uuid</code> takes precedence over
  767. /// <code>region_name</code> if both are present; one of both
  768. /// must be present.
  769. ///
  770. /// XmlRpcLoadOARMethod returns
  771. /// <list type="table">
  772. /// <listheader><term>name</term><description>description</description></listheader>
  773. /// <item><term>success</term>
  774. /// <description>true or false</description></item>
  775. /// <item><term>error</term>
  776. /// <description>error message if success is false</description></item>
  777. /// </list>
  778. /// </remarks>
  779. public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request)
  780. {
  781. m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
  782. XmlRpcResponse response = new XmlRpcResponse();
  783. Hashtable responseData = new Hashtable();
  784. try
  785. {
  786. Hashtable requestData = (Hashtable) request.Params[0];
  787. // check completeness
  788. foreach (string p in new string[] { "password", "filename" })
  789. {
  790. if (!requestData.Contains(p))
  791. throw new Exception(String.Format("missing parameter {0}", p));
  792. if (String.IsNullOrEmpty((string)requestData[p]))
  793. throw new Exception(String.Format("parameter {0} is empty"));
  794. }
  795. // check password
  796. if (!String.IsNullOrEmpty(requiredPassword) &&
  797. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  798. string filename = (string)requestData["filename"];
  799. Scene scene = null;
  800. if (requestData.Contains("region_uuid"))
  801. {
  802. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  803. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  804. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  805. }
  806. else if (requestData.Contains("region_name"))
  807. {
  808. string region_name = (string)requestData["region_name"];
  809. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  810. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  811. }
  812. else throw new Exception("neither region_name nor region_uuid given");
  813. new ArchiveReadRequest(scene, filename);
  814. responseData["loaded"] = "true";
  815. response.Value = responseData;
  816. }
  817. catch (Exception e)
  818. {
  819. m_log.InfoFormat("[RADMIN] LoadOAR: {0}", e.Message);
  820. m_log.DebugFormat("[RADMIN] LoadOAR: {0}", e.ToString());
  821. responseData["loaded"] = "false";
  822. responseData["error"] = e.Message;
  823. response.Value = responseData;
  824. }
  825. return response;
  826. }
  827. /// <summary>
  828. /// Save a region to an OAR file
  829. /// <summary>
  830. /// <param name="request">incoming XML RPC request</param>
  831. /// <remarks>
  832. /// XmlRpcSaveOARMethod takes the following XMLRPC
  833. /// parameters
  834. /// <list type="table">
  835. /// <listheader><term>parameter name</term><description>description</description></listheader>
  836. /// <item><term>password</term>
  837. /// <description>admin password as set in OpenSim.ini</description></item>
  838. /// <item><term>filename</term>
  839. /// <description>file name for the OAR file</description></item>
  840. /// <item><term>region_uuid</term>
  841. /// <description>UUID of the region</description></item>
  842. /// <item><term>region_name</term>
  843. /// <description>region name</description></item>
  844. /// </list>
  845. ///
  846. /// <code>region_uuid</code> takes precedence over
  847. /// <code>region_name</code> if both are present; one of both
  848. /// must be present.
  849. ///
  850. /// XmlRpcLoadOARMethod returns
  851. /// <list type="table">
  852. /// <listheader><term>name</term><description>description</description></listheader>
  853. /// <item><term>success</term>
  854. /// <description>true or false</description></item>
  855. /// <item><term>error</term>
  856. /// <description>error message if success is false</description></item>
  857. /// </list>
  858. /// </remarks>
  859. public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request)
  860. {
  861. m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
  862. XmlRpcResponse response = new XmlRpcResponse();
  863. Hashtable responseData = new Hashtable();
  864. try
  865. {
  866. Hashtable requestData = (Hashtable) request.Params[0];
  867. // check completeness
  868. foreach (string p in new string[] { "password", "filename" })
  869. {
  870. if (!requestData.Contains(p))
  871. throw new Exception(String.Format("missing parameter {0}", p));
  872. if (String.IsNullOrEmpty((string)requestData[p]))
  873. throw new Exception(String.Format("parameter {0} is empty"));
  874. }
  875. // check password
  876. if (!String.IsNullOrEmpty(requiredPassword) &&
  877. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  878. string filename = (string)requestData["filename"];
  879. Scene scene = null;
  880. if (requestData.Contains("region_uuid"))
  881. {
  882. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  883. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  884. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  885. }
  886. else if (requestData.Contains("region_name"))
  887. {
  888. string region_name = (string)requestData["region_name"];
  889. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  890. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  891. }
  892. else throw new Exception("neither region_name nor region_uuid given");
  893. scene.SavePrimsToArchive(filename);
  894. responseData["saved"] = "true";
  895. response.Value = responseData;
  896. }
  897. catch (Exception e)
  898. {
  899. m_log.InfoFormat("[RADMIN] SaveOAR: {0}", e.Message);
  900. m_log.DebugFormat("[RADMIN] SaveOAR: {0}", e.ToString());
  901. responseData["saved"] = "false";
  902. responseData["error"] = e.Message;
  903. response.Value = responseData;
  904. }
  905. return response;
  906. }
  907. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  908. {
  909. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  910. XmlRpcResponse response = new XmlRpcResponse();
  911. Hashtable responseData = new Hashtable();
  912. try
  913. {
  914. Hashtable requestData = (Hashtable) request.Params[0];
  915. // check completeness
  916. foreach (string p in new string[] { "password", "filename" })
  917. {
  918. if (!requestData.Contains(p))
  919. throw new Exception(String.Format("missing parameter {0}", p));
  920. if (String.IsNullOrEmpty((string)requestData[p]))
  921. throw new Exception(String.Format("parameter {0} is empty"));
  922. }
  923. // check password
  924. if (!String.IsNullOrEmpty(requiredPassword) &&
  925. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  926. string filename = (string)requestData["filename"];
  927. if (requestData.Contains("region_uuid"))
  928. {
  929. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  930. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  931. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  932. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  933. }
  934. else if (requestData.Contains("region_name"))
  935. {
  936. string region_name = (string)requestData["region_name"];
  937. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  938. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  939. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  940. }
  941. else throw new Exception("neither region_name nor region_uuid given");
  942. responseData["switched"] = "true";
  943. string xml_version = "1";
  944. if (requestData.Contains("xml_version"))
  945. {
  946. xml_version = (string)requestData["xml_version"];
  947. }
  948. switch (xml_version)
  949. {
  950. case "1":
  951. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  952. break;
  953. case "2":
  954. m_app.SceneManager.LoadCurrentSceneFromXml2(filename);
  955. break;
  956. default:
  957. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  958. }
  959. responseData["loaded"] = "true";
  960. response.Value = responseData;
  961. }
  962. catch (Exception e)
  963. {
  964. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  965. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  966. responseData["loaded"] = "false";
  967. responseData["switched"] = "false";
  968. responseData["error"] = e.Message;
  969. response.Value = responseData;
  970. }
  971. return response;
  972. }
  973. public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request)
  974. {
  975. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  976. XmlRpcResponse response = new XmlRpcResponse();
  977. Hashtable responseData = new Hashtable();
  978. try
  979. {
  980. Hashtable requestData = (Hashtable)request.Params[0];
  981. // check completeness
  982. foreach (string p in new string[] { "password", "filename" })
  983. {
  984. if (!requestData.Contains(p))
  985. throw new Exception(String.Format("missing parameter {0}", p));
  986. if (String.IsNullOrEmpty((string)requestData[p]))
  987. throw new Exception(String.Format("parameter {0} is empty"));
  988. }
  989. // check password
  990. if (!String.IsNullOrEmpty(requiredPassword) &&
  991. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  992. string filename = (string)requestData["filename"];
  993. if (requestData.Contains("region_uuid"))
  994. {
  995. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  996. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  997. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  998. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  999. }
  1000. else if (requestData.Contains("region_name"))
  1001. {
  1002. string region_name = (string)requestData["region_name"];
  1003. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1004. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1005. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1006. }
  1007. else throw new Exception("neither region_name nor region_uuid given");
  1008. responseData["switched"] = "true";
  1009. string xml_version = "1";
  1010. if (requestData.Contains("xml_version"))
  1011. {
  1012. xml_version = (string)requestData["xml_version"];
  1013. }
  1014. switch (xml_version)
  1015. {
  1016. case "1":
  1017. m_app.SceneManager.SaveCurrentSceneToXml(filename);
  1018. break;
  1019. case "2":
  1020. m_app.SceneManager.SaveCurrentSceneToXml2(filename);
  1021. break;
  1022. default:
  1023. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1024. }
  1025. responseData["saved"] = "true";
  1026. response.Value = responseData;
  1027. }
  1028. catch (Exception e)
  1029. {
  1030. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  1031. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  1032. responseData["loaded"] = "false";
  1033. responseData["switched"] = "false";
  1034. responseData["error"] = e.Message;
  1035. response.Value = responseData;
  1036. }
  1037. return response;
  1038. }
  1039. public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request)
  1040. {
  1041. m_log.Info("[RADMIN]: Received Query XML Administrator Request");
  1042. XmlRpcResponse response = new XmlRpcResponse();
  1043. Hashtable responseData = new Hashtable();
  1044. try
  1045. {
  1046. responseData["success"] = "true";
  1047. Hashtable requestData = (Hashtable)request.Params[0];
  1048. // check completeness
  1049. if (!requestData.Contains("password"))
  1050. throw new Exception(String.Format("missing required parameter"));
  1051. if (!String.IsNullOrEmpty(requiredPassword) &&
  1052. (string)requestData["password"] != requiredPassword) throw new Exception("wrong password");
  1053. if (requestData.Contains("region_uuid"))
  1054. {
  1055. UUID region_uuid = (UUID)(string)requestData["region_uuid"];
  1056. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1057. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1058. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1059. }
  1060. else if (requestData.Contains("region_name"))
  1061. {
  1062. string region_name = (string)requestData["region_name"];
  1063. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1064. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1065. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1066. }
  1067. else throw new Exception("neither region_name nor region_uuid given");
  1068. Scene s = m_app.SceneManager.CurrentScene;
  1069. int health = s.GetHealth();
  1070. responseData["health"] = health;
  1071. response.Value = responseData;
  1072. }
  1073. catch (Exception e)
  1074. {
  1075. m_log.InfoFormat("[RADMIN] RegionQuery: {0}", e.Message);
  1076. responseData["success"] = "false";
  1077. responseData["error"] = e.Message;
  1078. response.Value = responseData;
  1079. }
  1080. return response;
  1081. }
  1082. public void Dispose()
  1083. {
  1084. }
  1085. }
  1086. }