RemoteAdminPlugin.cs 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Xml;
  32. using System.Net;
  33. using System.Reflection;
  34. using System.Timers;
  35. using log4net;
  36. using Nini.Config;
  37. using Nwc.XmlRpc;
  38. using OpenMetaverse;
  39. using OpenSim;
  40. using OpenSim.Framework;
  41. using OpenSim.Framework.Communications;
  42. using OpenSim.Framework.Communications.Cache;
  43. using OpenSim.Framework.Console;
  44. using OpenSim.Framework.Servers;
  45. using OpenSim.Framework.Servers.HttpServer;
  46. using OpenSim.Region.CoreModules.World.Terrain;
  47. using OpenSim.Region.Framework.Interfaces;
  48. using OpenSim.Region.Framework.Scenes;
  49. namespace OpenSim.ApplicationPlugins.RemoteController
  50. {
  51. public class RemoteAdminPlugin : IApplicationPlugin
  52. {
  53. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  54. private static bool daload = false;
  55. private static Object rslock = new Object();
  56. private OpenSimBase m_app;
  57. private BaseHttpServer m_httpd;
  58. private IConfig m_config;
  59. private IConfigSource m_configSource;
  60. private string m_requiredPassword = String.Empty;
  61. private string m_name = "RemoteAdminPlugin";
  62. private string m_version = "0.0";
  63. public string Version
  64. {
  65. get { return m_version; }
  66. }
  67. public string Name
  68. {
  69. get { return m_name; }
  70. }
  71. public void Initialise()
  72. {
  73. m_log.Info("[RADMIN]: " + Name + " cannot be default-initialized!");
  74. throw new PluginNotInitialisedException(Name);
  75. }
  76. public void Initialise(OpenSimBase openSim)
  77. {
  78. m_configSource = openSim.ConfigSource.Source;
  79. try
  80. {
  81. if (m_configSource.Configs["RemoteAdmin"] == null ||
  82. !m_configSource.Configs["RemoteAdmin"].GetBoolean("enabled", false))
  83. {
  84. // No config or disabled
  85. }
  86. else
  87. {
  88. m_config = m_configSource.Configs["RemoteAdmin"];
  89. m_log.Info("[RADMIN]: Remote Admin Plugin Enabled");
  90. m_requiredPassword = m_config.GetString("access_password", String.Empty);
  91. m_app = openSim;
  92. m_httpd = openSim.HttpServer;
  93. Dictionary<string, XmlRpcMethod> availableMethods = new Dictionary<string, XmlRpcMethod>();
  94. availableMethods["admin_create_region"] = XmlRpcCreateRegionMethod;
  95. availableMethods["admin_delete_region"] = XmlRpcDeleteRegionMethod;
  96. availableMethods["admin_modify_region"] = XmlRpcModifyRegionMethod;
  97. availableMethods["admin_region_query"] = XmlRpcRegionQueryMethod;
  98. availableMethods["admin_shutdown"] = XmlRpcShutdownMethod;
  99. availableMethods["admin_broadcast"] = XmlRpcAlertMethod;
  100. availableMethods["admin_restart"] = XmlRpcRestartMethod;
  101. availableMethods["admin_load_heightmap"] = XmlRpcLoadHeightmapMethod;
  102. // User management
  103. availableMethods["admin_create_user"] = XmlRpcCreateUserMethod;
  104. availableMethods["admin_create_user_email"] = XmlRpcCreateUserMethod;
  105. availableMethods["admin_exists_user"] = XmlRpcUserExistsMethod;
  106. availableMethods["admin_update_user"] = XmlRpcUpdateUserAccountMethod;
  107. // Region state management
  108. availableMethods["admin_load_xml"] = XmlRpcLoadXMLMethod;
  109. availableMethods["admin_save_xml"] = XmlRpcSaveXMLMethod;
  110. availableMethods["admin_load_oar"] = XmlRpcLoadOARMethod;
  111. availableMethods["admin_save_oar"] = XmlRpcSaveOARMethod;
  112. // Estate access list management
  113. availableMethods["admin_acl_clear"] = XmlRpcAccessListClear;
  114. availableMethods["admin_acl_add"] = XmlRpcAccessListAdd;
  115. availableMethods["admin_acl_remove"] = XmlRpcAccessListRemove;
  116. availableMethods["admin_acl_list"] = XmlRpcAccessListList;
  117. // Either enable full remote functionality or just selected features
  118. string enabledMethods = m_config.GetString("enabled_methods", "all");
  119. // To get this, you must explicitly specify "all" or
  120. // mention it in a whitelist. It won't be available
  121. // If you just leave the option out!
  122. //
  123. if (!String.IsNullOrEmpty(enabledMethods))
  124. availableMethods["admin_console_command"] = XmlRpcConsoleCommandMethod;
  125. // The assumption here is that simply enabling Remote Admin as before will produce the same
  126. // behavior - enable all methods unless the whitelist is in place for backward-compatibility.
  127. if (enabledMethods.ToLower() == "all" || String.IsNullOrEmpty(enabledMethods))
  128. {
  129. foreach (string method in availableMethods.Keys)
  130. {
  131. m_httpd.AddXmlRPCHandler(method, availableMethods[method], false);
  132. }
  133. }
  134. else
  135. {
  136. foreach (string enabledMethod in enabledMethods.Split('|'))
  137. {
  138. m_httpd.AddXmlRPCHandler(enabledMethod, availableMethods[enabledMethod]);
  139. }
  140. }
  141. }
  142. }
  143. catch (NullReferenceException)
  144. {
  145. // Ignore.
  146. }
  147. }
  148. public void PostInitialise()
  149. {
  150. if (!createDefaultAvatars())
  151. {
  152. m_log.Info("[RADMIN]: Default avatars not loaded");
  153. }
  154. }
  155. public XmlRpcResponse XmlRpcRestartMethod(XmlRpcRequest request)
  156. {
  157. XmlRpcResponse response = new XmlRpcResponse();
  158. Hashtable responseData = new Hashtable();
  159. try
  160. {
  161. Hashtable requestData = (Hashtable) request.Params[0];
  162. m_log.Info("[RADMIN]: Request to restart Region.");
  163. checkStringParameters(request, new string[] {"password", "regionID"});
  164. if (m_requiredPassword != String.Empty &&
  165. (!requestData.Contains("password") || (string) requestData["password"] != m_requiredPassword))
  166. {
  167. throw new Exception("wrong password");
  168. }
  169. UUID regionID = new UUID((string) requestData["regionID"]);
  170. responseData["accepted"] = true;
  171. responseData["success"] = true;
  172. response.Value = responseData;
  173. Scene rebootedScene;
  174. if (!m_app.SceneManager.TryGetScene(regionID, out rebootedScene))
  175. throw new Exception("region not found");
  176. responseData["rebooting"] = true;
  177. response.Value = responseData;
  178. rebootedScene.Restart(30);
  179. }
  180. catch (Exception e)
  181. {
  182. m_log.ErrorFormat("[RADMIN]: Restart region: failed: {0}", e.Message);
  183. m_log.DebugFormat("[RADMIN]: Restart region: failed: {0}", e.ToString());
  184. responseData["accepted"] = false;
  185. responseData["success"] = false;
  186. responseData["rebooting"] = false;
  187. responseData["error"] = e.Message;
  188. response.Value = responseData;
  189. }
  190. m_log.Info("[RADMIN]: Restart Region request complete");
  191. return response;
  192. }
  193. public XmlRpcResponse XmlRpcAlertMethod(XmlRpcRequest request)
  194. {
  195. XmlRpcResponse response = new XmlRpcResponse();
  196. Hashtable responseData = new Hashtable();
  197. m_log.Info("[RADMIN]: Alert request started");
  198. try
  199. {
  200. Hashtable requestData = (Hashtable) request.Params[0];
  201. checkStringParameters(request, new string[] {"password", "message"});
  202. if (m_requiredPassword != String.Empty &&
  203. (!requestData.Contains("password") || (string) requestData["password"] != m_requiredPassword))
  204. throw new Exception("wrong password");
  205. string message = (string) requestData["message"];
  206. m_log.InfoFormat("[RADMIN]: Broadcasting: {0}", message);
  207. responseData["accepted"] = true;
  208. responseData["success"] = true;
  209. response.Value = responseData;
  210. m_app.SceneManager.ForEachScene(
  211. delegate(Scene scene)
  212. {
  213. IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
  214. if (dialogModule != null)
  215. dialogModule.SendGeneralAlert(message);
  216. });
  217. }
  218. catch (Exception e)
  219. {
  220. m_log.ErrorFormat("[RADMIN]: Broadcasting: failed: {0}", e.Message);
  221. m_log.DebugFormat("[RADMIN]: Broadcasting: failed: {0}", e.ToString());
  222. responseData["accepted"] = false;
  223. responseData["success"] = false;
  224. responseData["error"] = e.Message;
  225. response.Value = responseData;
  226. }
  227. m_log.Info("[RADMIN]: Alert request complete");
  228. return response;
  229. }
  230. public XmlRpcResponse XmlRpcLoadHeightmapMethod(XmlRpcRequest request)
  231. {
  232. XmlRpcResponse response = new XmlRpcResponse();
  233. Hashtable responseData = new Hashtable();
  234. m_log.Info("[RADMIN]: Load height maps request started");
  235. try
  236. {
  237. Hashtable requestData = (Hashtable) request.Params[0];
  238. m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}", request.ToString());
  239. // foreach (string k in requestData.Keys)
  240. // {
  241. // m_log.DebugFormat("[RADMIN]: Load Terrain: XmlRpc {0}: >{1}< {2}",
  242. // k, (string)requestData[k], ((string)requestData[k]).Length);
  243. // }
  244. checkStringParameters(request, new string[] {"password", "filename", "regionid"});
  245. if (m_requiredPassword != String.Empty &&
  246. (!requestData.Contains("password") || (string) requestData["password"] != m_requiredPassword))
  247. throw new Exception("wrong password");
  248. string file = (string) requestData["filename"];
  249. UUID regionID = (UUID) (string) requestData["regionid"];
  250. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  251. responseData["accepted"] = true;
  252. Scene region = null;
  253. if (!m_app.SceneManager.TryGetScene(regionID, out region))
  254. throw new Exception("1: unable to get a scene with that name");
  255. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  256. if (null == terrainModule) throw new Exception("terrain module not available");
  257. terrainModule.LoadFromFile(file);
  258. responseData["success"] = false;
  259. response.Value = responseData;
  260. }
  261. catch (Exception e)
  262. {
  263. m_log.ErrorFormat("[RADMIN] Terrain Loading: failed: {0}", e.Message);
  264. m_log.DebugFormat("[RADMIN] Terrain Loading: failed: {0}", e.ToString());
  265. responseData["success"] = false;
  266. responseData["error"] = e.Message;
  267. }
  268. m_log.Info("[RADMIN]: Load height maps request complete");
  269. return response;
  270. }
  271. public XmlRpcResponse XmlRpcShutdownMethod(XmlRpcRequest request)
  272. {
  273. m_log.Info("[RADMIN]: Received Shutdown Administrator Request");
  274. XmlRpcResponse response = new XmlRpcResponse();
  275. Hashtable responseData = new Hashtable();
  276. try
  277. {
  278. Hashtable requestData = (Hashtable) request.Params[0];
  279. if (m_requiredPassword != String.Empty &&
  280. (!requestData.Contains("password") || (string) requestData["password"] != m_requiredPassword))
  281. throw new Exception("wrong password");
  282. responseData["accepted"] = true;
  283. response.Value = responseData;
  284. int timeout = 2000;
  285. string message;
  286. if (requestData.ContainsKey("shutdown")
  287. && ((string) requestData["shutdown"] == "delayed")
  288. && requestData.ContainsKey("milliseconds"))
  289. {
  290. timeout = (Int32) requestData["milliseconds"];
  291. message
  292. = "Region is going down in " + ((int) (timeout/1000)).ToString()
  293. + " second(s). Please save what you are doing and log out.";
  294. }
  295. else
  296. {
  297. message = "Region is going down now.";
  298. }
  299. m_app.SceneManager.ForEachScene(
  300. delegate(Scene scene)
  301. {
  302. IDialogModule dialogModule = scene.RequestModuleInterface<IDialogModule>();
  303. if (dialogModule != null)
  304. dialogModule.SendGeneralAlert(message);
  305. });
  306. // Perform shutdown
  307. Timer shutdownTimer = new Timer(timeout); // Wait before firing
  308. shutdownTimer.AutoReset = false;
  309. shutdownTimer.Elapsed += new ElapsedEventHandler(shutdownTimer_Elapsed);
  310. shutdownTimer.Start();
  311. responseData["success"] = true;
  312. }
  313. catch (Exception e)
  314. {
  315. m_log.ErrorFormat("[RADMIN] Shutdown: failed: {0}", e.Message);
  316. m_log.DebugFormat("[RADMIN] Shutdown: failed: {0}", e.ToString());
  317. responseData["accepted"] = false;
  318. responseData["error"] = e.Message;
  319. response.Value = responseData;
  320. }
  321. m_log.Info("[RADMIN]: Shutdown Administrator Request complete");
  322. return response;
  323. }
  324. private void shutdownTimer_Elapsed(object sender, ElapsedEventArgs e)
  325. {
  326. m_app.Shutdown();
  327. }
  328. /// <summary>
  329. /// Create a new region.
  330. /// <summary>
  331. /// <param name="request">incoming XML RPC request</param>
  332. /// <remarks>
  333. /// XmlRpcCreateRegionMethod takes the following XMLRPC
  334. /// parameters
  335. /// <list type="table">
  336. /// <listheader><term>parameter name</term><description>description</description></listheader>
  337. /// <item><term>password</term>
  338. /// <description>admin password as set in OpenSim.ini</description></item>
  339. /// <item><term>region_name</term>
  340. /// <description>desired region name</description></item>
  341. /// <item><term>region_id</term>
  342. /// <description>(optional) desired region UUID</description></item>
  343. /// <item><term>region_x</term>
  344. /// <description>desired region X coordinate (integer)</description></item>
  345. /// <item><term>region_y</term>
  346. /// <description>desired region Y coordinate (integer)</description></item>
  347. /// <item><term>region_master_first</term>
  348. /// <description>firstname of region master</description></item>
  349. /// <item><term>region_master_last</term>
  350. /// <description>lastname of region master</description></item>
  351. /// <item><term>region_master_uuid</term>
  352. /// <description>explicit UUID to use for master avatar (optional)</description></item>
  353. /// <item><term>listen_ip</term>
  354. /// <description>internal IP address (dotted quad)</description></item>
  355. /// <item><term>listen_port</term>
  356. /// <description>internal port (integer)</description></item>
  357. /// <item><term>external_address</term>
  358. /// <description>external IP address</description></item>
  359. /// <item><term>persist</term>
  360. /// <description>if true, persist the region info
  361. /// ('true' or 'false')</description></item>
  362. /// <item><term>public</term>
  363. /// <description>if true, the region is public
  364. /// ('true' or 'false') (optional, default: true)</description></item>
  365. /// <item><term>enable_voice</term>
  366. /// <description>if true, enable voice on all parcels,
  367. /// ('true' or 'false') (optional, default: false)</description></item>
  368. /// </list>
  369. ///
  370. /// XmlRpcCreateRegionMethod returns
  371. /// <list type="table">
  372. /// <listheader><term>name</term><description>description</description></listheader>
  373. /// <item><term>success</term>
  374. /// <description>true or false</description></item>
  375. /// <item><term>error</term>
  376. /// <description>error message if success is false</description></item>
  377. /// <item><term>region_uuid</term>
  378. /// <description>UUID of the newly created region</description></item>
  379. /// <item><term>region_name</term>
  380. /// <description>name of the newly created region</description></item>
  381. /// </list>
  382. /// </remarks>
  383. public XmlRpcResponse XmlRpcCreateRegionMethod(XmlRpcRequest request)
  384. {
  385. m_log.Info("[RADMIN]: CreateRegion: new request");
  386. XmlRpcResponse response = new XmlRpcResponse();
  387. Hashtable responseData = new Hashtable();
  388. lock (rslock)
  389. {
  390. int m_regionLimit = m_config.GetInt("region_limit", 0);
  391. bool m_enableVoiceForNewRegions = m_config.GetBoolean("create_region_enable_voice", false);
  392. bool m_publicAccess = m_config.GetBoolean("create_region_public", true);
  393. try
  394. {
  395. Hashtable requestData = (Hashtable) request.Params[0];
  396. checkStringParameters(request, new string[]
  397. {
  398. "password",
  399. "region_name",
  400. "region_master_first", "region_master_last",
  401. "region_master_password",
  402. "listen_ip", "external_address"
  403. });
  404. checkIntegerParams(request, new string[] {"region_x", "region_y", "listen_port"});
  405. // check password
  406. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  407. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  408. // check whether we still have space left (iff we are using limits)
  409. if (m_regionLimit != 0 && m_app.SceneManager.Scenes.Count >= m_regionLimit)
  410. throw new Exception(String.Format("cannot instantiate new region, server capacity {0} already reached; delete regions first",
  411. m_regionLimit));
  412. // extract or generate region ID now
  413. Scene scene = null;
  414. UUID regionID = UUID.Zero;
  415. if (requestData.ContainsKey("region_id") &&
  416. !String.IsNullOrEmpty((string) requestData["region_id"]))
  417. {
  418. regionID = (UUID) (string) requestData["region_id"];
  419. if (m_app.SceneManager.TryGetScene(regionID, out scene))
  420. throw new Exception(
  421. String.Format("region UUID already in use by region {0}, UUID {1}, <{2},{3}>",
  422. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  423. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  424. }
  425. else
  426. {
  427. regionID = UUID.Random();
  428. m_log.DebugFormat("[RADMIN] CreateRegion: new region UUID {0}", regionID);
  429. }
  430. // create volatile or persistent region info
  431. RegionInfo region = new RegionInfo();
  432. region.RegionID = regionID;
  433. region.RegionName = (string) requestData["region_name"];
  434. region.RegionLocX = Convert.ToUInt32(requestData["region_x"]);
  435. region.RegionLocY = Convert.ToUInt32(requestData["region_y"]);
  436. // check for collisions: region name, region UUID,
  437. // region location
  438. if (m_app.SceneManager.TryGetScene(region.RegionName, out scene))
  439. throw new Exception(
  440. String.Format("region name already in use by region {0}, UUID {1}, <{2},{3}>",
  441. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  442. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  443. if (m_app.SceneManager.TryGetScene(region.RegionLocX, region.RegionLocY, out scene))
  444. throw new Exception(
  445. String.Format("region location <{0},{1}> already in use by region {2}, UUID {3}, <{4},{5}>",
  446. region.RegionLocX, region.RegionLocY,
  447. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  448. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  449. region.InternalEndPoint =
  450. new IPEndPoint(IPAddress.Parse((string) requestData["listen_ip"]), 0);
  451. region.InternalEndPoint.Port = Convert.ToInt32(requestData["listen_port"]);
  452. if (0 == region.InternalEndPoint.Port) throw new Exception("listen_port is 0");
  453. if (m_app.SceneManager.TryGetScene(region.InternalEndPoint, out scene))
  454. throw new Exception(
  455. String.Format(
  456. "region internal IP {0} and port {1} already in use by region {2}, UUID {3}, <{4},{5}>",
  457. region.InternalEndPoint.Address,
  458. region.InternalEndPoint.Port,
  459. scene.RegionInfo.RegionName, scene.RegionInfo.RegionID,
  460. scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY));
  461. region.ExternalHostName = (string) requestData["external_address"];
  462. string masterFirst = (string) requestData["region_master_first"];
  463. string masterLast = (string) requestData["region_master_last"];
  464. string masterPassword = (string) requestData["region_master_password"];
  465. UUID userID = UUID.Zero;
  466. if (requestData.ContainsKey("region_master_uuid"))
  467. {
  468. // ok, client wants us to use an explicit UUID
  469. // regardless of what the avatar name provided
  470. userID = new UUID((string) requestData["region_master_uuid"]);
  471. }
  472. else
  473. {
  474. // no client supplied UUID: look it up...
  475. CachedUserInfo userInfo
  476. = m_app.CommunicationsManager.UserProfileCacheService.GetUserDetails(
  477. masterFirst, masterLast);
  478. if (null == userInfo)
  479. {
  480. m_log.InfoFormat("master avatar does not exist, creating it");
  481. // ...or create new user
  482. userID = m_app.CommunicationsManager.UserAdminService.AddUser(
  483. masterFirst, masterLast, masterPassword, "", region.RegionLocX, region.RegionLocY);
  484. if (userID == UUID.Zero)
  485. throw new Exception(String.Format("failed to create new user {0} {1}",
  486. masterFirst, masterLast));
  487. }
  488. else
  489. {
  490. userID = userInfo.UserProfile.ID;
  491. }
  492. }
  493. region.MasterAvatarFirstName = masterFirst;
  494. region.MasterAvatarLastName = masterLast;
  495. region.MasterAvatarSandboxPassword = masterPassword;
  496. region.MasterAvatarAssignedUUID = userID;
  497. bool persist = Convert.ToBoolean((string) requestData["persist"]);
  498. if (persist)
  499. {
  500. // default place for region XML files is in the
  501. // Regions directory of the config dir (aka /bin)
  502. string regionConfigPath = Path.Combine(Util.configDir(), "Regions");
  503. try
  504. {
  505. // OpenSim.ini can specify a different regions dir
  506. IConfig startupConfig = (IConfig) m_configSource.Configs["Startup"];
  507. regionConfigPath = startupConfig.GetString("regionload_regionsdir", regionConfigPath).Trim();
  508. }
  509. catch (Exception)
  510. {
  511. // No INI setting recorded.
  512. }
  513. string regionXmlPath = Path.Combine(regionConfigPath,
  514. String.Format(
  515. m_config.GetString("region_file_template",
  516. "{0}x{1}-{2}.xml"),
  517. region.RegionLocX.ToString(),
  518. region.RegionLocY.ToString(),
  519. regionID.ToString(),
  520. region.InternalEndPoint.Port.ToString(),
  521. region.RegionName.Replace(" ", "_").Replace(":", "_").
  522. Replace("/", "_")));
  523. m_log.DebugFormat("[RADMIN] CreateRegion: persisting region {0} to {1}",
  524. region.RegionID, regionXmlPath);
  525. region.SaveRegionToFile("dynamic region", regionXmlPath);
  526. }
  527. // Create the region and perform any initial initialization
  528. IScene newscene;
  529. m_app.CreateRegion(region, out newscene);
  530. // If an access specification was provided, use it.
  531. // Otherwise accept the default.
  532. newscene.RegionInfo.EstateSettings.PublicAccess = getBoolean(requestData, "public", m_publicAccess);
  533. // enable voice on newly created region if
  534. // requested by either the XmlRpc request or the
  535. // configuration
  536. if (getBoolean(requestData, "enable_voice", m_enableVoiceForNewRegions))
  537. {
  538. List<ILandObject> parcels = ((Scene)newscene).LandChannel.AllParcels();
  539. foreach (ILandObject parcel in parcels)
  540. {
  541. parcel.landData.Flags |= (uint) Parcel.ParcelFlags.AllowVoiceChat;
  542. parcel.landData.Flags |= (uint) Parcel.ParcelFlags.UseEstateVoiceChan;
  543. }
  544. }
  545. responseData["success"] = true;
  546. responseData["region_name"] = region.RegionName;
  547. responseData["region_uuid"] = region.RegionID.ToString();
  548. response.Value = responseData;
  549. }
  550. catch (Exception e)
  551. {
  552. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0}", e.Message);
  553. m_log.DebugFormat("[RADMIN] CreateRegion: failed {0}", e.ToString());
  554. responseData["success"] = false;
  555. responseData["error"] = e.Message;
  556. response.Value = responseData;
  557. }
  558. m_log.Info("[RADMIN]: CreateRegion: request complete");
  559. return response;
  560. }
  561. }
  562. /// <summary>
  563. /// Delete a new region.
  564. /// <summary>
  565. /// <param name="request">incoming XML RPC request</param>
  566. /// <remarks>
  567. /// XmlRpcDeleteRegionMethod takes the following XMLRPC
  568. /// parameters
  569. /// <list type="table">
  570. /// <listheader><term>parameter name</term><description>description</description></listheader>
  571. /// <item><term>password</term>
  572. /// <description>admin password as set in OpenSim.ini</description></item>
  573. /// <item><term>region_name</term>
  574. /// <description>desired region name</description></item>
  575. /// <item><term>region_id</term>
  576. /// <description>(optional) desired region UUID</description></item>
  577. /// </list>
  578. ///
  579. /// XmlRpcDeleteRegionMethod returns
  580. /// <list type="table">
  581. /// <listheader><term>name</term><description>description</description></listheader>
  582. /// <item><term>success</term>
  583. /// <description>true or false</description></item>
  584. /// <item><term>error</term>
  585. /// <description>error message if success is false</description></item>
  586. /// </list>
  587. /// </remarks>
  588. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request)
  589. {
  590. m_log.Info("[RADMIN]: DeleteRegion: new request");
  591. XmlRpcResponse response = new XmlRpcResponse();
  592. Hashtable responseData = new Hashtable();
  593. lock (rslock)
  594. {
  595. try
  596. {
  597. Hashtable requestData = (Hashtable) request.Params[0];
  598. checkStringParameters(request, new string[] {"password", "region_name"});
  599. Scene scene = null;
  600. string regionName = (string) requestData["region_name"];
  601. if (!m_app.SceneManager.TryGetScene(regionName, out scene))
  602. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  603. m_app.RemoveRegion(scene, true);
  604. responseData["success"] = true;
  605. responseData["region_name"] = regionName;
  606. response.Value = responseData;
  607. }
  608. catch (Exception e)
  609. {
  610. m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0}", e.Message);
  611. m_log.DebugFormat("[RADMIN] DeleteRegion: failed {0}", e.ToString());
  612. responseData["success"] = false;
  613. responseData["error"] = e.Message;
  614. response.Value = responseData;
  615. }
  616. m_log.Info("[RADMIN]: DeleteRegion: request complete");
  617. return response;
  618. }
  619. }
  620. /// <summary>
  621. /// Change characteristics of an existing region.
  622. /// <summary>
  623. /// <param name="request">incoming XML RPC request</param>
  624. /// <remarks>
  625. /// XmlRpcModifyRegionMethod takes the following XMLRPC
  626. /// parameters
  627. /// <list type="table">
  628. /// <listheader><term>parameter name</term><description>description</description></listheader>
  629. /// <item><term>password</term>
  630. /// <description>admin password as set in OpenSim.ini</description></item>
  631. /// <item><term>region_name</term>
  632. /// <description>desired region name</description></item>
  633. /// <item><term>region_id</term>
  634. /// <description>(optional) desired region UUID</description></item>
  635. /// <item><term>public</term>
  636. /// <description>if true, set the region to public
  637. /// ('true' or 'false'), else to private</description></item>
  638. /// <item><term>enable_voice</term>
  639. /// <description>if true, enable voice on all parcels of
  640. /// the region, else disable</description></item>
  641. /// </list>
  642. ///
  643. /// XmlRpcModifyRegionMethod returns
  644. /// <list type="table">
  645. /// <listheader><term>name</term><description>description</description></listheader>
  646. /// <item><term>success</term>
  647. /// <description>true or false</description></item>
  648. /// <item><term>error</term>
  649. /// <description>error message if success is false</description></item>
  650. /// </list>
  651. /// </remarks>
  652. public XmlRpcResponse XmlRpcModifyRegionMethod(XmlRpcRequest request)
  653. {
  654. m_log.Info("[RADMIN]: ModifyRegion: new request");
  655. XmlRpcResponse response = new XmlRpcResponse();
  656. Hashtable responseData = new Hashtable();
  657. lock (rslock)
  658. {
  659. try
  660. {
  661. Hashtable requestData = (Hashtable) request.Params[0];
  662. checkStringParameters(request, new string[] {"password", "region_name"});
  663. Scene scene = null;
  664. string regionName = (string) requestData["region_name"];
  665. if (!m_app.SceneManager.TryGetScene(regionName, out scene))
  666. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  667. // Modify access
  668. scene.RegionInfo.EstateSettings.PublicAccess =
  669. getBoolean(requestData,"public", scene.RegionInfo.EstateSettings.PublicAccess);
  670. if (requestData.ContainsKey("enable_voice"))
  671. {
  672. bool enableVoice = getBoolean(requestData, "enable_voice", true);
  673. List<ILandObject> parcels = ((Scene)scene).LandChannel.AllParcels();
  674. foreach (ILandObject parcel in parcels)
  675. {
  676. if (enableVoice)
  677. {
  678. parcel.landData.Flags |= (uint)Parcel.ParcelFlags.AllowVoiceChat;
  679. parcel.landData.Flags |= (uint)Parcel.ParcelFlags.UseEstateVoiceChan;
  680. }
  681. else
  682. {
  683. parcel.landData.Flags &= ~(uint)Parcel.ParcelFlags.AllowVoiceChat;
  684. parcel.landData.Flags &= ~(uint)Parcel.ParcelFlags.UseEstateVoiceChan;
  685. }
  686. }
  687. }
  688. responseData["success"] = true;
  689. responseData["region_name"] = regionName;
  690. response.Value = responseData;
  691. }
  692. catch (Exception e)
  693. {
  694. m_log.ErrorFormat("[RADMIN] ModifyRegion: failed {0}", e.Message);
  695. m_log.DebugFormat("[RADMIN] ModifyRegion: failed {0}", e.ToString());
  696. responseData["success"] = false;
  697. responseData["error"] = e.Message;
  698. response.Value = responseData;
  699. }
  700. m_log.Info("[RADMIN]: ModifyRegion: request complete");
  701. return response;
  702. }
  703. }
  704. /// <summary>
  705. /// Create a new user account.
  706. /// <summary>
  707. /// <param name="request">incoming XML RPC request</param>
  708. /// <remarks>
  709. /// XmlRpcCreateUserMethod takes the following XMLRPC
  710. /// parameters
  711. /// <list type="table">
  712. /// <listheader><term>parameter name</term><description>description</description></listheader>
  713. /// <item><term>password</term>
  714. /// <description>admin password as set in OpenSim.ini</description></item>
  715. /// <item><term>user_firstname</term>
  716. /// <description>avatar's first name</description></item>
  717. /// <item><term>user_lastname</term>
  718. /// <description>avatar's last name</description></item>
  719. /// <item><term>user_password</term>
  720. /// <description>avatar's password</description></item>
  721. /// <item><term>user_email</term>
  722. /// <description>email of the avatar's owner (optional)</description></item>
  723. /// <item><term>start_region_x</term>
  724. /// <description>avatar's start region coordinates, X value</description></item>
  725. /// <item><term>start_region_y</term>
  726. /// <description>avatar's start region coordinates, Y value</description></item>
  727. /// </list>
  728. ///
  729. /// XmlRpcCreateUserMethod returns
  730. /// <list type="table">
  731. /// <listheader><term>name</term><description>description</description></listheader>
  732. /// <item><term>success</term>
  733. /// <description>true or false</description></item>
  734. /// <item><term>error</term>
  735. /// <description>error message if success is false</description></item>
  736. /// <item><term>avatar_uuid</term>
  737. /// <description>UUID of the newly created avatar
  738. /// account; UUID.Zero if failed.
  739. /// </description></item>
  740. /// </list>
  741. /// </remarks>
  742. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request)
  743. {
  744. m_log.Info("[RADMIN]: CreateUser: new request");
  745. XmlRpcResponse response = new XmlRpcResponse();
  746. Hashtable responseData = new Hashtable();
  747. lock (rslock)
  748. {
  749. try
  750. {
  751. Hashtable requestData = (Hashtable) request.Params[0];
  752. // check completeness
  753. checkStringParameters(request, new string[]
  754. {
  755. "password", "user_firstname",
  756. "user_lastname", "user_password",
  757. });
  758. checkIntegerParams(request, new string[] {"start_region_x", "start_region_y"});
  759. // check password
  760. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  761. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  762. // do the job
  763. string firstname = (string) requestData["user_firstname"];
  764. string lastname = (string) requestData["user_lastname"];
  765. string passwd = (string) requestData["user_password"];
  766. uint regX = Convert.ToUInt32((Int32) requestData["start_region_x"]);
  767. uint regY = Convert.ToUInt32((Int32) requestData["start_region_y"]);
  768. string email = ""; // empty string for email
  769. if (requestData.Contains("user_email"))
  770. email = (string)requestData["user_email"];
  771. CachedUserInfo userInfo =
  772. m_app.CommunicationsManager.UserProfileCacheService.GetUserDetails(firstname, lastname);
  773. if (null != userInfo)
  774. throw new Exception(String.Format("Avatar {0} {1} already exists", firstname, lastname));
  775. UUID userID =
  776. m_app.CommunicationsManager.UserAdminService.AddUser(firstname, lastname,
  777. passwd, email, regX, regY);
  778. if (userID == UUID.Zero)
  779. throw new Exception(String.Format("failed to create new user {0} {1}",
  780. firstname, lastname));
  781. // Establish the avatar's initial appearance
  782. updateUserAppearance(responseData, requestData, userID);
  783. responseData["success"] = true;
  784. responseData["avatar_uuid"] = userID.ToString();
  785. response.Value = responseData;
  786. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstname, lastname, userID);
  787. }
  788. catch (Exception e)
  789. {
  790. m_log.ErrorFormat("[RADMIN] CreateUser: failed: {0}", e.Message);
  791. m_log.DebugFormat("[RADMIN] CreateUser: failed: {0}", e.ToString());
  792. responseData["success"] = false;
  793. responseData["avatar_uuid"] = UUID.Zero.ToString();
  794. responseData["error"] = e.Message;
  795. response.Value = responseData;
  796. }
  797. m_log.Info("[RADMIN]: CreateUser: request complete");
  798. return response;
  799. }
  800. }
  801. /// <summary>
  802. /// Check whether a certain user account exists.
  803. /// <summary>
  804. /// <param name="request">incoming XML RPC request</param>
  805. /// <remarks>
  806. /// XmlRpcUserExistsMethod takes the following XMLRPC
  807. /// parameters
  808. /// <list type="table">
  809. /// <listheader><term>parameter name</term><description>description</description></listheader>
  810. /// <item><term>password</term>
  811. /// <description>admin password as set in OpenSim.ini</description></item>
  812. /// <item><term>user_firstname</term>
  813. /// <description>avatar's first name</description></item>
  814. /// <item><term>user_lastname</term>
  815. /// <description>avatar's last name</description></item>
  816. /// </list>
  817. ///
  818. /// XmlRpcCreateUserMethod returns
  819. /// <list type="table">
  820. /// <listheader><term>name</term><description>description</description></listheader>
  821. /// <item><term>user_firstname</term>
  822. /// <description>avatar's first name</description></item>
  823. /// <item><term>user_lastname</term>
  824. /// <description>avatar's last name</description></item>
  825. /// <item><term>success</term>
  826. /// <description>true or false</description></item>
  827. /// <item><term>error</term>
  828. /// <description>error message if success is false</description></item>
  829. /// </list>
  830. /// </remarks>
  831. public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request)
  832. {
  833. m_log.Info("[RADMIN]: UserExists: new request");
  834. XmlRpcResponse response = new XmlRpcResponse();
  835. Hashtable responseData = new Hashtable();
  836. try
  837. {
  838. Hashtable requestData = (Hashtable) request.Params[0];
  839. // check completeness
  840. checkStringParameters(request, new string[] {"password", "user_firstname", "user_lastname"});
  841. string firstname = (string) requestData["user_firstname"];
  842. string lastname = (string) requestData["user_lastname"];
  843. CachedUserInfo userInfo
  844. = m_app.CommunicationsManager.UserProfileCacheService.GetUserDetails(firstname, lastname);
  845. responseData["user_firstname"] = firstname;
  846. responseData["user_lastname"] = lastname;
  847. if (null == userInfo)
  848. responseData["success"] = false;
  849. else
  850. responseData["success"] = true;
  851. response.Value = responseData;
  852. }
  853. catch (Exception e)
  854. {
  855. m_log.ErrorFormat("[RADMIN] UserExists: failed: {0}", e.Message);
  856. m_log.DebugFormat("[RADMIN] UserExists: failed: {0}", e.ToString());
  857. responseData["success"] = false;
  858. responseData["error"] = e.Message;
  859. response.Value = responseData;
  860. }
  861. m_log.Info("[RADMIN]: UserExists: request complete");
  862. return response;
  863. }
  864. /// <summary>
  865. /// Update a user account.
  866. /// <summary>
  867. /// <param name="request">incoming XML RPC request</param>
  868. /// <remarks>
  869. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  870. /// parameters (changeable ones are optional)
  871. /// <list type="table">
  872. /// <listheader><term>parameter name</term><description>description</description></listheader>
  873. /// <item><term>password</term>
  874. /// <description>admin password as set in OpenSim.ini</description></item>
  875. /// <item><term>user_firstname</term>
  876. /// <description>avatar's first name (cannot be changed)</description></item>
  877. /// <item><term>user_lastname</term>
  878. /// <description>avatar's last name (cannot be changed)</description></item>
  879. /// <item><term>user_password</term>
  880. /// <description>avatar's password (changeable)</description></item>
  881. /// <item><term>start_region_x</term>
  882. /// <description>avatar's start region coordinates, X
  883. /// value (changeable)</description></item>
  884. /// <item><term>start_region_y</term>
  885. /// <description>avatar's start region coordinates, Y
  886. /// value (changeable)</description></item>
  887. /// <item><term>about_real_world</term>
  888. /// <description>"about" text of avatar owner (changeable)</description></item>
  889. /// <item><term>about_virtual_world</term>
  890. /// <description>"about" text of avatar (changeable)</description></item>
  891. /// </list>
  892. ///
  893. /// XmlRpcCreateUserMethod returns
  894. /// <list type="table">
  895. /// <listheader><term>name</term><description>description</description></listheader>
  896. /// <item><term>success</term>
  897. /// <description>true or false</description></item>
  898. /// <item><term>error</term>
  899. /// <description>error message if success is false</description></item>
  900. /// </list>
  901. /// </remarks>
  902. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request)
  903. {
  904. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  905. XmlRpcResponse response = new XmlRpcResponse();
  906. Hashtable responseData = new Hashtable();
  907. lock (rslock)
  908. {
  909. try
  910. {
  911. Hashtable requestData = (Hashtable) request.Params[0];
  912. // check completeness
  913. checkStringParameters(request, new string[] {
  914. "password", "user_firstname",
  915. "user_lastname"});
  916. // check password
  917. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  918. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  919. // do the job
  920. string firstname = (string) requestData["user_firstname"];
  921. string lastname = (string) requestData["user_lastname"];
  922. string passwd = String.Empty;
  923. uint? regX = null;
  924. uint? regY = null;
  925. uint? ulaX = null;
  926. uint? ulaY = null;
  927. uint? ulaZ = null;
  928. uint? usaX = null;
  929. uint? usaY = null;
  930. uint? usaZ = null;
  931. string aboutFirstLive = String.Empty;
  932. string aboutAvatar = String.Empty;
  933. if (requestData.ContainsKey("user_password")) passwd = (string) requestData["user_password"];
  934. if (requestData.ContainsKey("start_region_x"))
  935. regX = Convert.ToUInt32((Int32) requestData["start_region_x"]);
  936. if (requestData.ContainsKey("start_region_y"))
  937. regY = Convert.ToUInt32((Int32) requestData["start_region_y"]);
  938. if (requestData.ContainsKey("start_lookat_x"))
  939. ulaX = Convert.ToUInt32((Int32) requestData["start_lookat_x"]);
  940. if (requestData.ContainsKey("start_lookat_y"))
  941. ulaY = Convert.ToUInt32((Int32) requestData["start_lookat_y"]);
  942. if (requestData.ContainsKey("start_lookat_z"))
  943. ulaZ = Convert.ToUInt32((Int32) requestData["start_lookat_z"]);
  944. if (requestData.ContainsKey("start_standat_x"))
  945. usaX = Convert.ToUInt32((Int32) requestData["start_standat_x"]);
  946. if (requestData.ContainsKey("start_standat_y"))
  947. usaY = Convert.ToUInt32((Int32) requestData["start_standat_y"]);
  948. if (requestData.ContainsKey("start_standat_z"))
  949. usaZ = Convert.ToUInt32((Int32) requestData["start_standat_z"]);
  950. if (requestData.ContainsKey("about_real_world"))
  951. aboutFirstLive = (string)requestData["about_real_world"];
  952. if (requestData.ContainsKey("about_virtual_world"))
  953. aboutAvatar = (string)requestData["about_virtual_world"];
  954. UserProfileData userProfile
  955. = m_app.CommunicationsManager.UserService.GetUserProfile(firstname, lastname);
  956. if (null == userProfile)
  957. throw new Exception(String.Format("avatar {0} {1} does not exist", firstname, lastname));
  958. if (null != passwd)
  959. {
  960. string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(passwd) + ":" + String.Empty);
  961. userProfile.PasswordHash = md5PasswdHash;
  962. }
  963. if (null != regX) userProfile.HomeRegionX = (uint) regX;
  964. if (null != regY) userProfile.HomeRegionY = (uint) regY;
  965. if (null != usaX) userProfile.HomeLocationX = (uint) usaX;
  966. if (null != usaY) userProfile.HomeLocationY = (uint) usaY;
  967. if (null != usaZ) userProfile.HomeLocationZ = (uint) usaZ;
  968. if (null != ulaX) userProfile.HomeLookAtX = (uint) ulaX;
  969. if (null != ulaY) userProfile.HomeLookAtY = (uint) ulaY;
  970. if (null != ulaZ) userProfile.HomeLookAtZ = (uint) ulaZ;
  971. if (String.Empty != aboutFirstLive) userProfile.FirstLifeAboutText = aboutFirstLive;
  972. if (String.Empty != aboutAvatar) userProfile.AboutText = aboutAvatar;
  973. // User has been created. Now establish gender and appearance.
  974. updateUserAppearance(responseData, requestData, userProfile.ID);
  975. if (!m_app.CommunicationsManager.UserService.UpdateUserProfile(userProfile))
  976. throw new Exception("did not manage to update user profile");
  977. responseData["success"] = true;
  978. response.Value = responseData;
  979. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}",
  980. firstname, lastname,
  981. userProfile.ID);
  982. }
  983. catch (Exception e)
  984. {
  985. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.Message);
  986. m_log.DebugFormat("[RADMIN] UpdateUserAccount: failed: {0}", e.ToString());
  987. responseData["success"] = false;
  988. responseData["error"] = e.Message;
  989. response.Value = responseData;
  990. }
  991. }
  992. m_log.Info("[RADMIN]: UpdateUserAccount: request complete");
  993. return response;
  994. }
  995. /// <summary>
  996. /// This method is called by the user-create and user-modify methods to establish
  997. /// or change, the user's appearance. Default avatar names can be specified via
  998. /// the config file, but must correspond to avatars in the default appearance
  999. /// file, or pre-existing in the user database.
  1000. /// This should probably get moved into somewhere more core eventually.
  1001. /// </summary>
  1002. private void updateUserAppearance(Hashtable responseData, Hashtable requestData, UUID userid)
  1003. {
  1004. m_log.DebugFormat("[RADMIN] updateUserAppearance");
  1005. string dmale = m_config.GetString("default_male", "Default Male");
  1006. string dfemale = m_config.GetString("default_female", "Default Female");
  1007. string dneut = m_config.GetString("default_female", "Default Default");
  1008. string model = String.Empty;
  1009. // Has a gender preference been supplied?
  1010. if (requestData.Contains("gender"))
  1011. {
  1012. switch((string)requestData["gender"])
  1013. {
  1014. case "m" :
  1015. model = dmale;
  1016. break;
  1017. case "f" :
  1018. model = dfemale;
  1019. break;
  1020. case "n" :
  1021. default :
  1022. model = dneut;
  1023. break;
  1024. }
  1025. }
  1026. // Has an explicit model been specified?
  1027. if (requestData.Contains("model"))
  1028. {
  1029. model = (string)requestData["model"];
  1030. }
  1031. // No appearance attributes were set
  1032. if(model == String.Empty)
  1033. {
  1034. m_log.DebugFormat("[RADMIN] Appearance update not requested");
  1035. return;
  1036. }
  1037. m_log.DebugFormat("[RADMIN] Setting appearance for avatar {0}, using model {1}", userid, model);
  1038. string[] nomens = model.Split();
  1039. if (nomens.Length != 2)
  1040. {
  1041. m_log.WarnFormat("[RADMIN] User appearance not set for {0}. Invalid model name : <{1}>", userid, model);
  1042. // nomens = dmodel.Split();
  1043. return;
  1044. }
  1045. UserProfileData mprof = m_app.CommunicationsManager.UserService.GetUserProfile(nomens[0], nomens[1]);
  1046. // Is this the first time one of the default models has been used? Create it if that is the case
  1047. // otherwise default to male.
  1048. if (mprof == null)
  1049. {
  1050. m_log.WarnFormat("[RADMIN] Requested model ({0}) not found. Appearance unchanged", model);
  1051. return;
  1052. }
  1053. // Set current user's appearance. This bit is easy. The appearance structure is populated with
  1054. // actual asset ids, however to complete the magic we need to populate the inventory with the
  1055. // assets in question.
  1056. establishAppearance(userid, mprof.ID);
  1057. m_log.DebugFormat("[RADMIN] Finished setting appearance for avatar {0}, using model {1}",
  1058. userid, model);
  1059. }
  1060. /// <summary>
  1061. /// This method is called by updateAvatarAppearance once any specified model has been
  1062. /// ratified, or an appropriate default value has been adopted. The intended prototype
  1063. /// is known to exist, as is the target avatar.
  1064. /// </summary>
  1065. private void establishAppearance(UUID dest, UUID srca)
  1066. {
  1067. m_log.DebugFormat("[RADMIN] Initializing inventory for {0} from {1}", dest, srca);
  1068. AvatarAppearance ava = m_app.CommunicationsManager.AvatarService.GetUserAppearance(srca);
  1069. // If the model has no associated appearance we're done.
  1070. // if (ava == null)
  1071. // {
  1072. // return new AvatarAppearance();
  1073. // }
  1074. if (ava == null)
  1075. return;
  1076. UICallback sic = new UICallback();
  1077. UICallback dic = new UICallback();
  1078. IInventoryServices iserv = m_app.CommunicationsManager.InventoryService;
  1079. try
  1080. {
  1081. Dictionary<UUID,UUID> imap = new Dictionary<UUID,UUID>();
  1082. iserv.RequestInventoryForUser(dest, dic.callback);
  1083. iserv.RequestInventoryForUser(srca, sic.callback);
  1084. dic.GetInventory();
  1085. sic.GetInventory();
  1086. if (sic.OK && dic.OK)
  1087. {
  1088. InventoryFolderImpl efolder;
  1089. InventoryFolderImpl srcf = sic.root.FindFolderForType(5);
  1090. InventoryFolderImpl dstf = dic.root.FindFolderForType(5);
  1091. if (srcf == null || dstf == null)
  1092. throw new Exception("Cannot locate clothing folder(s)");
  1093. foreach (InventoryFolderImpl folder in sic.folders)
  1094. {
  1095. if (folder.ParentID == srcf.ID)
  1096. {
  1097. efolder = new InventoryFolderImpl();
  1098. efolder.ID = UUID.Random();
  1099. efolder.Name = folder.Name;
  1100. efolder.Type = folder.Type;
  1101. efolder.Version = folder.Version;
  1102. efolder.Owner = dest;
  1103. dstf.AddChildFolder(efolder);
  1104. iserv.AddFolder(efolder);
  1105. m_log.DebugFormat("[RADMIN] Added outfile folder {0} to folder {1}", efolder.ID, srcf.ID);
  1106. foreach (InventoryItemBase item in sic.items)
  1107. {
  1108. if (item.Folder == folder.ID)
  1109. {
  1110. InventoryItemBase dsti = new InventoryItemBase();
  1111. dsti.ID = UUID.Random();
  1112. dsti.Name = item.Name;
  1113. dsti.Description = item.Description;
  1114. dsti.InvType = item.InvType;
  1115. dsti.AssetType = item.AssetType;
  1116. dsti.Flags = item.Flags;
  1117. dsti.AssetID = item.AssetID;
  1118. dsti.Folder = efolder.ID;
  1119. dsti.Owner = dest;
  1120. dsti.BasePermissions = item.BasePermissions;
  1121. dsti.NextPermissions = item.NextPermissions;
  1122. dsti.CurrentPermissions = item.CurrentPermissions;
  1123. dsti.GroupPermissions = item.GroupPermissions;
  1124. dsti.EveryOnePermissions = item.EveryOnePermissions;
  1125. iserv.AddItem(dsti);
  1126. imap.Add(item.ID, dsti.ID);
  1127. m_log.DebugFormat("[RADMIN] Added item {0} to folder {1}", dsti.ID, efolder.ID);
  1128. }
  1129. }
  1130. }
  1131. }
  1132. // Update appearance tables
  1133. AvatarWearable[] wearables = ava.Wearables;
  1134. for (int i=0; i<wearables.Length; i++)
  1135. {
  1136. if (imap.ContainsKey(wearables[i].ItemID))
  1137. {
  1138. AvatarWearable dw = new AvatarWearable();
  1139. dw.AssetID = wearables[i].AssetID;
  1140. dw.ItemID = imap[wearables[i].ItemID];
  1141. ava.SetWearable(i, dw);
  1142. }
  1143. }
  1144. }
  1145. else
  1146. {
  1147. throw new Exception("Unable to load both inventories");
  1148. }
  1149. m_app.CommunicationsManager.AvatarService.UpdateUserAppearance(dest, ava);
  1150. }
  1151. catch (Exception e)
  1152. {
  1153. m_log.WarnFormat("[RADMIN] Error transferring inventory for {0} : {1}",
  1154. dest, e.Message);
  1155. return;
  1156. }
  1157. return;
  1158. }
  1159. ///<summary>
  1160. /// This method is called if a given model avatar name can not be found. If the external
  1161. /// file has already been loaded once, then control returns immediately. If not, then it
  1162. /// looks for a default appearance file. This file contains XML definitions of zero or more named
  1163. /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection
  1164. /// of items that together, define a particular ensemble for the avatar. Each avatar should
  1165. /// indicate which outfit is the default, and this outfit will be automatically worn. The
  1166. /// other outfits are provided to allow "real" avatars a way to easily change their outfits.
  1167. /// </summary>
  1168. private bool createDefaultAvatars()
  1169. {
  1170. // Only load once
  1171. if (daload)
  1172. {
  1173. return false;
  1174. }
  1175. m_log.DebugFormat("[RADMIN] Creating default avatar entries");
  1176. daload = true;
  1177. // Load processing starts here...
  1178. try
  1179. {
  1180. string dafn = m_config.GetString("default_appearance", "default_appearance.xml");
  1181. if (File.Exists(dafn))
  1182. {
  1183. XmlDocument doc = new XmlDocument();
  1184. string name = "*unknown*";
  1185. string email = "anon@anon";
  1186. uint regX = 1000;
  1187. uint regY = 1000;
  1188. string passwd = UUID.Random().ToString(); // No requirement to sign-in.
  1189. CachedUserInfo UI;
  1190. UUID ID = UUID.Zero;
  1191. AvatarAppearance mava;
  1192. XmlNodeList avatars;
  1193. XmlNodeList assets;
  1194. XmlNode perms = null;
  1195. bool include = false;
  1196. bool select = false;
  1197. UICallback uic;
  1198. IInventoryServices iserv = m_app.CommunicationsManager.InventoryService;
  1199. IAssetCache aserv = m_app.CommunicationsManager.AssetCache;
  1200. doc.LoadXml(File.ReadAllText(dafn));
  1201. // Load up any included assets. Duplicates will be ignored
  1202. assets = doc.GetElementsByTagName("RequiredAsset");
  1203. foreach(XmlNode asset in assets)
  1204. {
  1205. AssetBase rass = new AssetBase();
  1206. rass.FullID = UUID.Random();
  1207. rass.Name = GetStringAttribute(asset,"name","");
  1208. rass.Description = GetStringAttribute(asset,"desc","");
  1209. rass.Type = SByte.Parse(GetStringAttribute(asset,"type",""));
  1210. rass.Local = Boolean.Parse(GetStringAttribute(asset,"local",""));
  1211. rass.Temporary = Boolean.Parse(GetStringAttribute(asset,"temporary",""));
  1212. rass.Data = Convert.FromBase64String(asset.InnerText);
  1213. aserv.AddAsset(rass);
  1214. }
  1215. avatars = doc.GetElementsByTagName("Avatar");
  1216. // The document may contain multiple avatars
  1217. foreach (XmlElement avatar in avatars)
  1218. {
  1219. m_log.DebugFormat("[RADMIN] Loading appearance for {0}, gender = {1}",
  1220. GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?"));
  1221. // Create the user identified by the avatar entry
  1222. try
  1223. {
  1224. // Only the name value is mandatory
  1225. name = GetStringAttribute(avatar,"name",name);
  1226. email = GetStringAttribute(avatar,"email",email);
  1227. regX = GetUnsignedAttribute(avatar,"regx",regX);
  1228. regY = GetUnsignedAttribute(avatar,"regy",regY);
  1229. passwd = GetStringAttribute(avatar,"password",passwd);
  1230. string[] nomens = name.Split();
  1231. UI = m_app.CommunicationsManager.UserProfileCacheService.GetUserDetails(nomens[0], nomens[1]);
  1232. if (null == UI)
  1233. {
  1234. ID = m_app.CommunicationsManager.UserAdminService.AddUser(nomens[0], nomens[1],
  1235. passwd, email, regX, regY);
  1236. if (ID == UUID.Zero)
  1237. {
  1238. m_log.ErrorFormat("[RADMIN] Avatar {0} {1} was not created", nomens[0], nomens[1]);
  1239. return false;
  1240. }
  1241. }
  1242. else
  1243. {
  1244. ID = UI.UserProfile.ID;
  1245. }
  1246. m_log.DebugFormat("[RADMIN] User {0}[{1}] created or retrieved", name, ID);
  1247. include = true;
  1248. }
  1249. catch (Exception e)
  1250. {
  1251. m_log.DebugFormat("[RADMIN] Error creating user {0} : {1}", name, e.Message);
  1252. include = false;
  1253. }
  1254. // OK, User has been created OK, now we can install the inventory.
  1255. // First retrieve the current inventory (the user may already exist)
  1256. // Note that althought he inventory is retrieved, the hierarchy has
  1257. // not been interpreted at all.
  1258. if (include)
  1259. {
  1260. uic = new UICallback();
  1261. // Request the inventory
  1262. iserv.RequestInventoryForUser(ID, uic.callback);
  1263. // While the inventory is being fetched, setup for appearance processing
  1264. if ((mava = m_app.CommunicationsManager.AvatarService.GetUserAppearance(ID)) == null)
  1265. {
  1266. mava = new AvatarAppearance();
  1267. }
  1268. {
  1269. AvatarWearable[] wearables = mava.Wearables;
  1270. for (int i=0; i<wearables.Length; i++)
  1271. {
  1272. wearables[i] = new AvatarWearable();
  1273. }
  1274. }
  1275. // Wait for the inventory to arrive
  1276. uic.GetInventory();
  1277. // We can only get dresssed if an inventory is forthcoming
  1278. if (uic.OK)
  1279. try
  1280. {
  1281. m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory",
  1282. uic.folders.Count, uic.items.Count);
  1283. InventoryFolderImpl cfolder = uic.root.FindFolderForType(5);
  1284. // This should *never* be the case
  1285. if (cfolder == null)
  1286. {
  1287. cfolder = new InventoryFolderImpl();
  1288. cfolder.Name = "Clothing";
  1289. cfolder.Type = 5;
  1290. cfolder.Version = 1;
  1291. cfolder.Owner = ID;
  1292. uic.root.AddChildFolder(cfolder); // make connection
  1293. iserv.AddFolder(cfolder); // store base record
  1294. m_log.ErrorFormat("[RADMIN] Created clothing folder for {0}/{1}", name, ID);
  1295. }
  1296. // OK, now we have an inventory for the user, read in the outfits from the
  1297. // default appearance XMl file.
  1298. XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble");
  1299. InventoryFolderImpl efolder;
  1300. string oname;
  1301. UUID assetid;
  1302. foreach (XmlElement outfit in outfits)
  1303. {
  1304. m_log.DebugFormat("[RADMIN] Loading outfit {0} for {1}",
  1305. GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?"));
  1306. oname = GetStringAttribute(outfit,"name","");
  1307. select = (GetStringAttribute(outfit,"default","no") == "yes");
  1308. efolder = null;
  1309. // If the folder already exists, re-use it. The defaults may
  1310. // change over time. Augment only.
  1311. foreach (InventoryFolderImpl folder in uic.folders)
  1312. {
  1313. if (folder.Name == oname && folder.ParentID == cfolder.ID)
  1314. {
  1315. efolder = folder;
  1316. break;
  1317. }
  1318. }
  1319. // Otherwise, we must create the folder.
  1320. if (efolder == null)
  1321. {
  1322. m_log.DebugFormat("[RADMIN] Creating outfit folder {0} for {1}", oname, name);
  1323. efolder = new InventoryFolderImpl();
  1324. efolder.ID = UUID.Random();
  1325. efolder.Name = oname;
  1326. efolder.Type = 5;
  1327. efolder.Version = 1;
  1328. efolder.Owner = ID;
  1329. cfolder.AddChildFolder(efolder); // make connection
  1330. iserv.AddFolder(efolder); // store base record
  1331. m_log.DebugFormat("[RADMIN] Adding outfile folder {0} to folder {1}", efolder.ID, cfolder.ID);
  1332. }
  1333. // Now get the pieces that make up the outfit
  1334. XmlNodeList items = outfit.GetElementsByTagName("Item");
  1335. foreach (XmlElement item in items)
  1336. {
  1337. assetid = UUID.Zero;
  1338. XmlNodeList children = item.ChildNodes;
  1339. foreach (XmlNode child in children)
  1340. {
  1341. switch (child.Name)
  1342. {
  1343. case "Permissions" :
  1344. m_log.DebugFormat("[RADMIN] Permissions specified");
  1345. perms = child;
  1346. break;
  1347. case "Asset" :
  1348. assetid = new UUID(child.InnerText);
  1349. break;
  1350. }
  1351. }
  1352. InventoryItemBase iitem = null;
  1353. if ((iitem = efolder.FindAsset(assetid)) == null)
  1354. {
  1355. iitem = new InventoryItemBase();
  1356. iitem.ID = UUID.Random();
  1357. iitem.Name = GetStringAttribute(item,"name","");
  1358. iitem.Description = GetStringAttribute(item,"desc","");
  1359. iitem.InvType = GetIntegerAttribute(item,"invtype",-1);
  1360. iitem.AssetType = GetIntegerAttribute(item,"assettype",-1);
  1361. iitem.Flags = GetUnsignedAttribute(item,"flags",0);
  1362. iitem.AssetID = assetid; // associated asset
  1363. iitem.Folder = efolder.ID; // Parent folder
  1364. iitem.Owner = ID; // Agent ID
  1365. iitem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff);
  1366. iitem.NextPermissions = GetUnsignedAttribute(perms,"next",0x7fffffff);
  1367. iitem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff);
  1368. iitem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff);
  1369. iitem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff);
  1370. m_log.DebugFormat("[RADMIN] Adding item {0} to folder {1}", iitem.ID, efolder.ID);
  1371. iserv.AddItem(iitem);
  1372. }
  1373. // Record whether or not the item is to be initially worn
  1374. try
  1375. {
  1376. if (select && (GetStringAttribute(item, "wear", "false") == "true"))
  1377. {
  1378. mava.Wearables[iitem.Flags].ItemID = iitem.ID;
  1379. mava.Wearables[iitem.Flags].AssetID = iitem.AssetID;
  1380. }
  1381. }
  1382. catch {}
  1383. } // foreach item in outfit
  1384. m_log.DebugFormat("[RADMIN] Outfit {0} load completed", oname);
  1385. } // foreach outfit
  1386. m_log.DebugFormat("[RADMIN] Inventory update complete for {0}", name);
  1387. m_app.CommunicationsManager.AvatarService.UpdateUserAppearance(ID, mava);
  1388. }
  1389. catch (Exception e)
  1390. {
  1391. m_log.WarnFormat("[RADMIN] Inventory processing incomplete for user {0} : {1}",
  1392. name, e.Message);
  1393. }
  1394. else
  1395. {
  1396. m_log.WarnFormat("[RADMIN] Unable to retrieve inventory for {0}[{1}]",
  1397. name, ID);
  1398. // continue to next avatar
  1399. }
  1400. } // End of include
  1401. }
  1402. m_log.DebugFormat("[RADMIN] Default avatar loading complete");
  1403. }
  1404. else
  1405. {
  1406. m_log.DebugFormat("[RADMIN] No default avatar information available");
  1407. return false;
  1408. }
  1409. }
  1410. catch (Exception e)
  1411. {
  1412. m_log.WarnFormat("[RADMIN] Exception whilst loading default avatars ; {0}", e.Message);
  1413. return false;
  1414. }
  1415. return true;
  1416. }
  1417. /// <summary>
  1418. /// Load an OAR file into a region..
  1419. /// <summary>
  1420. /// <param name="request">incoming XML RPC request</param>
  1421. /// <remarks>
  1422. /// XmlRpcLoadOARMethod takes the following XMLRPC
  1423. /// parameters
  1424. /// <list type="table">
  1425. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1426. /// <item><term>password</term>
  1427. /// <description>admin password as set in OpenSim.ini</description></item>
  1428. /// <item><term>filename</term>
  1429. /// <description>file name of the OAR file</description></item>
  1430. /// <item><term>region_uuid</term>
  1431. /// <description>UUID of the region</description></item>
  1432. /// <item><term>region_name</term>
  1433. /// <description>region name</description></item>
  1434. /// </list>
  1435. ///
  1436. /// <code>region_uuid</code> takes precedence over
  1437. /// <code>region_name</code> if both are present; one of both
  1438. /// must be present.
  1439. ///
  1440. /// XmlRpcLoadOARMethod returns
  1441. /// <list type="table">
  1442. /// <listheader><term>name</term><description>description</description></listheader>
  1443. /// <item><term>success</term>
  1444. /// <description>true or false</description></item>
  1445. /// <item><term>error</term>
  1446. /// <description>error message if success is false</description></item>
  1447. /// </list>
  1448. /// </remarks>
  1449. public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request)
  1450. {
  1451. m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
  1452. XmlRpcResponse response = new XmlRpcResponse();
  1453. Hashtable responseData = new Hashtable();
  1454. lock (rslock)
  1455. {
  1456. try
  1457. {
  1458. Hashtable requestData = (Hashtable) request.Params[0];
  1459. // check completeness
  1460. foreach (string p in new string[] {"password", "filename"})
  1461. {
  1462. if (!requestData.Contains(p))
  1463. throw new Exception(String.Format("missing parameter {0}", p));
  1464. if (String.IsNullOrEmpty((string) requestData[p]))
  1465. throw new Exception(String.Format("parameter {0} is empty"));
  1466. }
  1467. // check password
  1468. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1469. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1470. string filename = (string) requestData["filename"];
  1471. Scene scene = null;
  1472. if (requestData.Contains("region_uuid"))
  1473. {
  1474. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1475. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  1476. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1477. }
  1478. else if (requestData.Contains("region_name"))
  1479. {
  1480. string region_name = (string) requestData["region_name"];
  1481. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  1482. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1483. }
  1484. else throw new Exception("neither region_name nor region_uuid given");
  1485. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1486. if (archiver != null)
  1487. archiver.DearchiveRegion(filename);
  1488. else
  1489. throw new Exception("Archiver module not present for scene");
  1490. responseData["loaded"] = true;
  1491. response.Value = responseData;
  1492. }
  1493. catch (Exception e)
  1494. {
  1495. m_log.InfoFormat("[RADMIN] LoadOAR: {0}", e.Message);
  1496. m_log.DebugFormat("[RADMIN] LoadOAR: {0}", e.ToString());
  1497. responseData["loaded"] = false;
  1498. responseData["error"] = e.Message;
  1499. response.Value = responseData;
  1500. }
  1501. m_log.Info("[RADMIN]: Load OAR Administrator Request complete");
  1502. return response;
  1503. }
  1504. }
  1505. /// <summary>
  1506. /// Save a region to an OAR file
  1507. /// <summary>
  1508. /// <param name="request">incoming XML RPC request</param>
  1509. /// <remarks>
  1510. /// XmlRpcSaveOARMethod takes the following XMLRPC
  1511. /// parameters
  1512. /// <list type="table">
  1513. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1514. /// <item><term>password</term>
  1515. /// <description>admin password as set in OpenSim.ini</description></item>
  1516. /// <item><term>filename</term>
  1517. /// <description>file name for the OAR file</description></item>
  1518. /// <item><term>region_uuid</term>
  1519. /// <description>UUID of the region</description></item>
  1520. /// <item><term>region_name</term>
  1521. /// <description>region name</description></item>
  1522. /// </list>
  1523. ///
  1524. /// <code>region_uuid</code> takes precedence over
  1525. /// <code>region_name</code> if both are present; one of both
  1526. /// must be present.
  1527. ///
  1528. /// XmlRpcLoadOARMethod returns
  1529. /// <list type="table">
  1530. /// <listheader><term>name</term><description>description</description></listheader>
  1531. /// <item><term>success</term>
  1532. /// <description>true or false</description></item>
  1533. /// <item><term>error</term>
  1534. /// <description>error message if success is false</description></item>
  1535. /// </list>
  1536. /// </remarks>
  1537. public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request)
  1538. {
  1539. m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
  1540. XmlRpcResponse response = new XmlRpcResponse();
  1541. Hashtable responseData = new Hashtable();
  1542. try
  1543. {
  1544. Hashtable requestData = (Hashtable) request.Params[0];
  1545. // check completeness
  1546. foreach (string p in new string[] {"password", "filename"})
  1547. {
  1548. if (!requestData.Contains(p))
  1549. throw new Exception(String.Format("missing parameter {0}", p));
  1550. if (String.IsNullOrEmpty((string) requestData[p]))
  1551. throw new Exception(String.Format("parameter {0} is empty"));
  1552. }
  1553. // check password
  1554. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1555. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1556. string filename = (string) requestData["filename"];
  1557. Scene scene = null;
  1558. if (requestData.Contains("region_uuid"))
  1559. {
  1560. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1561. if (!m_app.SceneManager.TryGetScene(region_uuid, out scene))
  1562. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1563. }
  1564. else if (requestData.Contains("region_name"))
  1565. {
  1566. string region_name = (string) requestData["region_name"];
  1567. if (!m_app.SceneManager.TryGetScene(region_name, out scene))
  1568. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1569. }
  1570. else throw new Exception("neither region_name nor region_uuid given");
  1571. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1572. if (archiver != null)
  1573. archiver.ArchiveRegion(filename);
  1574. else
  1575. throw new Exception("Archiver module not present for scene");
  1576. responseData["saved"] = true;
  1577. response.Value = responseData;
  1578. }
  1579. catch (Exception e)
  1580. {
  1581. m_log.InfoFormat("[RADMIN] SaveOAR: {0}", e.Message);
  1582. m_log.DebugFormat("[RADMIN] SaveOAR: {0}", e.ToString());
  1583. responseData["saved"] = false;
  1584. responseData["error"] = e.Message;
  1585. response.Value = responseData;
  1586. }
  1587. m_log.Info("[RADMIN]: Save OAR Administrator Request complete");
  1588. return response;
  1589. }
  1590. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request)
  1591. {
  1592. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  1593. XmlRpcResponse response = new XmlRpcResponse();
  1594. Hashtable responseData = new Hashtable();
  1595. lock (rslock)
  1596. {
  1597. try
  1598. {
  1599. Hashtable requestData = (Hashtable) request.Params[0];
  1600. // check completeness
  1601. foreach (string p in new string[] {"password", "filename"})
  1602. {
  1603. if (!requestData.Contains(p))
  1604. throw new Exception(String.Format("missing parameter {0}", p));
  1605. if (String.IsNullOrEmpty((string) requestData[p]))
  1606. throw new Exception(String.Format("parameter {0} is empty"));
  1607. }
  1608. // check password
  1609. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1610. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1611. string filename = (string) requestData["filename"];
  1612. if (requestData.Contains("region_uuid"))
  1613. {
  1614. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1615. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1616. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1617. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1618. }
  1619. else if (requestData.Contains("region_name"))
  1620. {
  1621. string region_name = (string) requestData["region_name"];
  1622. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1623. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1624. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1625. }
  1626. else throw new Exception("neither region_name nor region_uuid given");
  1627. responseData["switched"] = true;
  1628. string xml_version = "1";
  1629. if (requestData.Contains("xml_version"))
  1630. {
  1631. xml_version = (string) requestData["xml_version"];
  1632. }
  1633. switch (xml_version)
  1634. {
  1635. case "1":
  1636. m_app.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  1637. break;
  1638. case "2":
  1639. m_app.SceneManager.LoadCurrentSceneFromXml2(filename);
  1640. break;
  1641. default:
  1642. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1643. }
  1644. responseData["loaded"] = true;
  1645. response.Value = responseData;
  1646. }
  1647. catch (Exception e)
  1648. {
  1649. m_log.InfoFormat("[RADMIN] LoadXml: {0}", e.Message);
  1650. m_log.DebugFormat("[RADMIN] LoadXml: {0}", e.ToString());
  1651. responseData["loaded"] = false;
  1652. responseData["switched"] = false;
  1653. responseData["error"] = e.Message;
  1654. response.Value = responseData;
  1655. }
  1656. m_log.Info("[RADMIN]: Load XML Administrator Request complete");
  1657. return response;
  1658. }
  1659. }
  1660. public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request)
  1661. {
  1662. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  1663. XmlRpcResponse response = new XmlRpcResponse();
  1664. Hashtable responseData = new Hashtable();
  1665. try
  1666. {
  1667. Hashtable requestData = (Hashtable) request.Params[0];
  1668. // check completeness
  1669. foreach (string p in new string[] {"password", "filename"})
  1670. {
  1671. if (!requestData.Contains(p))
  1672. throw new Exception(String.Format("missing parameter {0}", p));
  1673. if (String.IsNullOrEmpty((string) requestData[p]))
  1674. throw new Exception(String.Format("parameter {0} is empty"));
  1675. }
  1676. // check password
  1677. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1678. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1679. string filename = (string) requestData["filename"];
  1680. if (requestData.Contains("region_uuid"))
  1681. {
  1682. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1683. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1684. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1685. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1686. }
  1687. else if (requestData.Contains("region_name"))
  1688. {
  1689. string region_name = (string) requestData["region_name"];
  1690. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1691. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1692. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1693. }
  1694. else throw new Exception("neither region_name nor region_uuid given");
  1695. responseData["switched"] = true;
  1696. string xml_version = "1";
  1697. if (requestData.Contains("xml_version"))
  1698. {
  1699. xml_version = (string) requestData["xml_version"];
  1700. }
  1701. switch (xml_version)
  1702. {
  1703. case "1":
  1704. m_app.SceneManager.SaveCurrentSceneToXml(filename);
  1705. break;
  1706. case "2":
  1707. m_app.SceneManager.SaveCurrentSceneToXml2(filename);
  1708. break;
  1709. default:
  1710. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1711. }
  1712. responseData["saved"] = true;
  1713. response.Value = responseData;
  1714. }
  1715. catch (Exception e)
  1716. {
  1717. m_log.InfoFormat("[RADMIN] SaveXml: {0}", e.Message);
  1718. m_log.DebugFormat("[RADMIN] SaveXml: {0}", e.ToString());
  1719. responseData["saved"] = false;
  1720. responseData["switched"] = false;
  1721. responseData["error"] = e.Message;
  1722. response.Value = responseData;
  1723. }
  1724. m_log.Info("[RADMIN]: Save XML Administrator Request complete");
  1725. return response;
  1726. }
  1727. public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request)
  1728. {
  1729. m_log.Info("[RADMIN]: Received Query XML Administrator Request");
  1730. XmlRpcResponse response = new XmlRpcResponse();
  1731. Hashtable responseData = new Hashtable();
  1732. try
  1733. {
  1734. responseData["success"] = true;
  1735. Hashtable requestData = (Hashtable) request.Params[0];
  1736. // check completeness
  1737. if (!requestData.Contains("password"))
  1738. throw new Exception(String.Format("missing required parameter"));
  1739. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1740. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1741. if (requestData.Contains("region_uuid"))
  1742. {
  1743. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1744. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1745. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1746. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1747. }
  1748. else if (requestData.Contains("region_name"))
  1749. {
  1750. string region_name = (string) requestData["region_name"];
  1751. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1752. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1753. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1754. }
  1755. else throw new Exception("neither region_name nor region_uuid given");
  1756. Scene s = m_app.SceneManager.CurrentScene;
  1757. int health = s.GetHealth();
  1758. responseData["health"] = health;
  1759. response.Value = responseData;
  1760. }
  1761. catch (Exception e)
  1762. {
  1763. m_log.InfoFormat("[RADMIN] RegionQuery: {0}", e.Message);
  1764. responseData["success"] = false;
  1765. responseData["error"] = e.Message;
  1766. response.Value = responseData;
  1767. }
  1768. m_log.Info("[RADMIN]: Query XML Administrator Request complete");
  1769. return response;
  1770. }
  1771. public XmlRpcResponse XmlRpcConsoleCommandMethod(XmlRpcRequest request)
  1772. {
  1773. m_log.Info("[RADMIN]: Received Command XML Administrator Request");
  1774. XmlRpcResponse response = new XmlRpcResponse();
  1775. Hashtable responseData = new Hashtable();
  1776. try
  1777. {
  1778. responseData["success"] = true;
  1779. Hashtable requestData = (Hashtable) request.Params[0];
  1780. // check completeness
  1781. if (!requestData.Contains("password"))
  1782. throw new Exception(String.Format("missing required parameter"));
  1783. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1784. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1785. if (!requestData.Contains("command"))
  1786. throw new Exception(String.Format("missing required parameter"));
  1787. MainConsole.Instance.RunCommand(requestData["command"].ToString());
  1788. response.Value = responseData;
  1789. }
  1790. catch (Exception e)
  1791. {
  1792. m_log.InfoFormat("[RADMIN] ConsoleCommand: {0}", e.Message);
  1793. responseData["success"] = false;
  1794. responseData["error"] = e.Message;
  1795. response.Value = responseData;
  1796. }
  1797. m_log.Info("[RADMIN]: Command XML Administrator Request complete");
  1798. return response;
  1799. }
  1800. public XmlRpcResponse XmlRpcAccessListClear(XmlRpcRequest request)
  1801. {
  1802. m_log.Info("[RADMIN]: Received Access List Clear Request");
  1803. XmlRpcResponse response = new XmlRpcResponse();
  1804. Hashtable responseData = new Hashtable();
  1805. try
  1806. {
  1807. responseData["success"] = true;
  1808. Hashtable requestData = (Hashtable) request.Params[0];
  1809. if (!requestData.Contains("password"))
  1810. throw new Exception(String.Format("missing required parameter"));
  1811. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1812. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1813. if (requestData.Contains("region_uuid"))
  1814. {
  1815. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1816. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1817. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1818. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1819. }
  1820. else if (requestData.Contains("region_name"))
  1821. {
  1822. string region_name = (string) requestData["region_name"];
  1823. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1824. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1825. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1826. }
  1827. else throw new Exception("neither region_name nor region_uuid given");
  1828. Scene s = m_app.SceneManager.CurrentScene;
  1829. s.RegionInfo.EstateSettings.EstateAccess = new UUID[]{};
  1830. }
  1831. catch (Exception e)
  1832. {
  1833. m_log.InfoFormat("[RADMIN] Access List Clear Request: {0}", e.Message);
  1834. responseData["success"] = false;
  1835. responseData["error"] = e.Message;
  1836. }
  1837. finally
  1838. {
  1839. response.Value = responseData;
  1840. }
  1841. m_log.Info("[RADMIN]: Access List Clear Request complete");
  1842. return response;
  1843. }
  1844. public XmlRpcResponse XmlRpcAccessListAdd(XmlRpcRequest request)
  1845. {
  1846. m_log.Info("[RADMIN]: Received Access List Add Request");
  1847. XmlRpcResponse response = new XmlRpcResponse();
  1848. Hashtable responseData = new Hashtable();
  1849. try
  1850. {
  1851. responseData["success"] = true;
  1852. Hashtable requestData = (Hashtable) request.Params[0];
  1853. if (!requestData.Contains("password"))
  1854. throw new Exception(String.Format("missing required parameter"));
  1855. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1856. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1857. if (requestData.Contains("region_uuid"))
  1858. {
  1859. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1860. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1861. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1862. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1863. }
  1864. else if (requestData.Contains("region_name"))
  1865. {
  1866. string region_name = (string) requestData["region_name"];
  1867. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1868. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1869. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1870. }
  1871. else throw new Exception("neither region_name nor region_uuid given");
  1872. int addk = 0;
  1873. if (requestData.Contains("users"))
  1874. {
  1875. UserProfileCacheService ups = m_app.CommunicationsManager.UserProfileCacheService;
  1876. Scene s = m_app.SceneManager.CurrentScene;
  1877. Hashtable users = (Hashtable) requestData["users"];
  1878. List<UUID> uuids = new List<UUID>();
  1879. foreach (string name in users.Values)
  1880. {
  1881. string[] parts = name.Split();
  1882. CachedUserInfo udata = ups.GetUserDetails(parts[0],parts[1]);
  1883. if (udata != null)
  1884. {
  1885. uuids.Add(udata.UserProfile.ID);
  1886. }
  1887. }
  1888. List<UUID> acl = new List<UUID>(s.RegionInfo.EstateSettings.EstateAccess);
  1889. foreach (UUID uuid in uuids)
  1890. {
  1891. if (!acl.Contains(uuid))
  1892. {
  1893. acl.Add(uuid);
  1894. addk++;
  1895. }
  1896. }
  1897. s.RegionInfo.EstateSettings.EstateAccess = acl.ToArray();
  1898. }
  1899. responseData["added"] = addk;
  1900. }
  1901. catch (Exception e)
  1902. {
  1903. m_log.InfoFormat("[RADMIN] Access List Add Request: {0}", e.Message);
  1904. responseData["success"] = false;
  1905. responseData["error"] = e.Message;
  1906. }
  1907. finally
  1908. {
  1909. response.Value = responseData;
  1910. }
  1911. m_log.Info("[RADMIN]: Access List Add Request complete");
  1912. return response;
  1913. }
  1914. public XmlRpcResponse XmlRpcAccessListRemove(XmlRpcRequest request)
  1915. {
  1916. m_log.Info("[RADMIN]: Received Access List Remove Request");
  1917. XmlRpcResponse response = new XmlRpcResponse();
  1918. Hashtable responseData = new Hashtable();
  1919. try
  1920. {
  1921. responseData["success"] = true;
  1922. Hashtable requestData = (Hashtable) request.Params[0];
  1923. if (!requestData.Contains("password"))
  1924. throw new Exception(String.Format("missing required parameter"));
  1925. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1926. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1927. if (requestData.Contains("region_uuid"))
  1928. {
  1929. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1930. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  1931. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1932. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  1933. }
  1934. else if (requestData.Contains("region_name"))
  1935. {
  1936. string region_name = (string) requestData["region_name"];
  1937. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  1938. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1939. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  1940. }
  1941. else throw new Exception("neither region_name nor region_uuid given");
  1942. int remk = 0;
  1943. if (requestData.Contains("users"))
  1944. {
  1945. UserProfileCacheService ups = m_app.CommunicationsManager.UserProfileCacheService;
  1946. Scene s = m_app.SceneManager.CurrentScene;
  1947. Hashtable users = (Hashtable) requestData["users"];
  1948. List<UUID> uuids = new List<UUID>();
  1949. foreach (string name in users.Values)
  1950. {
  1951. string[] parts = name.Split();
  1952. CachedUserInfo udata = ups.GetUserDetails(parts[0],parts[1]);
  1953. if (udata != null)
  1954. {
  1955. uuids.Add(udata.UserProfile.ID);
  1956. }
  1957. }
  1958. List<UUID> acl = new List<UUID>(s.RegionInfo.EstateSettings.EstateAccess);
  1959. foreach (UUID uuid in uuids)
  1960. {
  1961. if (acl.Contains(uuid))
  1962. {
  1963. acl.Remove(uuid);
  1964. remk++;
  1965. }
  1966. }
  1967. s.RegionInfo.EstateSettings.EstateAccess = acl.ToArray();
  1968. }
  1969. responseData["added"] = remk;
  1970. }
  1971. catch (Exception e)
  1972. {
  1973. m_log.InfoFormat("[RADMIN] Access List Remove Request: {0}", e.Message);
  1974. responseData["success"] = false;
  1975. responseData["error"] = e.Message;
  1976. }
  1977. finally
  1978. {
  1979. response.Value = responseData;
  1980. }
  1981. m_log.Info("[RADMIN]: Access List Remove Request complete");
  1982. return response;
  1983. }
  1984. public XmlRpcResponse XmlRpcAccessListList(XmlRpcRequest request)
  1985. {
  1986. m_log.Info("[RADMIN]: Received Access List List Request");
  1987. XmlRpcResponse response = new XmlRpcResponse();
  1988. Hashtable responseData = new Hashtable();
  1989. try
  1990. {
  1991. responseData["success"] = true;
  1992. Hashtable requestData = (Hashtable) request.Params[0];
  1993. if (!requestData.Contains("password"))
  1994. throw new Exception(String.Format("missing required parameter"));
  1995. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1996. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1997. if (requestData.Contains("region_uuid"))
  1998. {
  1999. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2000. if (!m_app.SceneManager.TrySetCurrentScene(region_uuid))
  2001. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2002. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_uuid.ToString());
  2003. }
  2004. else if (requestData.Contains("region_name"))
  2005. {
  2006. string region_name = (string) requestData["region_name"];
  2007. if (!m_app.SceneManager.TrySetCurrentScene(region_name))
  2008. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2009. m_log.InfoFormat("[RADMIN] Switched to region {0}", region_name);
  2010. }
  2011. else throw new Exception("neither region_name nor region_uuid given");
  2012. Scene s = m_app.SceneManager.CurrentScene;
  2013. UUID[] acl = s.RegionInfo.EstateSettings.EstateAccess;
  2014. Hashtable users = new Hashtable();
  2015. foreach (UUID user in acl)
  2016. {
  2017. CachedUserInfo udata = m_app.CommunicationsManager.UserProfileCacheService.GetUserDetails(user);
  2018. if (udata != null)
  2019. {
  2020. users[user.ToString()] = udata.UserProfile.Name;
  2021. }
  2022. }
  2023. responseData["users"] = users;
  2024. }
  2025. catch (Exception e)
  2026. {
  2027. m_log.InfoFormat("[RADMIN] Acces List List: {0}", e.Message);
  2028. responseData["success"] = false;
  2029. responseData["error"] = e.Message;
  2030. }
  2031. finally
  2032. {
  2033. response.Value = responseData;
  2034. }
  2035. m_log.Info("[RADMIN]: Access List List Request complete");
  2036. return response;
  2037. }
  2038. private static void checkStringParameters(XmlRpcRequest request, string[] param)
  2039. {
  2040. Hashtable requestData = (Hashtable) request.Params[0];
  2041. foreach (string p in param)
  2042. {
  2043. if (!requestData.Contains(p))
  2044. throw new Exception(String.Format("missing string parameter {0}", p));
  2045. if (String.IsNullOrEmpty((string) requestData[p]))
  2046. throw new Exception(String.Format("parameter {0} is empty", p));
  2047. }
  2048. }
  2049. private static void checkIntegerParams(XmlRpcRequest request, string[] param)
  2050. {
  2051. Hashtable requestData = (Hashtable) request.Params[0];
  2052. foreach (string p in param)
  2053. {
  2054. if (!requestData.Contains(p))
  2055. throw new Exception(String.Format("missing integer parameter {0}", p));
  2056. }
  2057. }
  2058. private bool getBoolean(Hashtable requestData, string tag, bool defv)
  2059. {
  2060. // If an access value has been provided, apply it.
  2061. if (requestData.Contains(tag))
  2062. {
  2063. switch (((string)requestData[tag]).ToLower())
  2064. {
  2065. case "true" :
  2066. case "t" :
  2067. case "1" :
  2068. return true;
  2069. case "false" :
  2070. case "f" :
  2071. case "0" :
  2072. return false;
  2073. default :
  2074. return defv;
  2075. }
  2076. }
  2077. else
  2078. return defv;
  2079. }
  2080. private int GetIntegerAttribute(XmlNode node, string attr, int dv)
  2081. {
  2082. try { return Convert.ToInt32(node.Attributes[attr].Value); } catch{}
  2083. return dv;
  2084. }
  2085. private uint GetUnsignedAttribute(XmlNode node, string attr, uint dv)
  2086. {
  2087. try { return Convert.ToUInt32(node.Attributes[attr].Value); } catch{}
  2088. return dv;
  2089. }
  2090. private string GetStringAttribute(XmlNode node, string attr, string dv)
  2091. {
  2092. try { return node.Attributes[attr].Value; } catch{}
  2093. return dv;
  2094. }
  2095. public void Dispose()
  2096. {
  2097. }
  2098. }
  2099. class UICallback
  2100. {
  2101. private Object uilock = new Object();
  2102. internal InventoryFolderImpl root = null;
  2103. internal List<InventoryFolderImpl> folders;
  2104. internal List<InventoryItemBase> items;
  2105. internal bool OK = false;
  2106. public void callback(ICollection<InventoryFolderImpl> p_folders, ICollection<InventoryItemBase> p_items)
  2107. {
  2108. lock (uilock)
  2109. {
  2110. folders = (List<InventoryFolderImpl>) p_folders;
  2111. items = (List<InventoryItemBase>) p_items;
  2112. OK = true;
  2113. System.Threading.Monitor.Pulse(uilock);
  2114. }
  2115. }
  2116. public void GetInventory()
  2117. {
  2118. Dictionary<UUID, InventoryFolderImpl> fmap = new Dictionary<UUID, InventoryFolderImpl>();
  2119. if (OK == false)
  2120. {
  2121. lock (uilock)
  2122. {
  2123. if (OK == false)
  2124. System.Threading.Monitor.Wait(uilock);
  2125. }
  2126. }
  2127. // Got the inventory OK. So now merge the content of the default appearance
  2128. // file with whatever we already have in-world. For convenience we initialize
  2129. // the inventory hierarchy.
  2130. // Find root and build an index
  2131. foreach (InventoryFolderImpl folder in folders)
  2132. {
  2133. if (folder.ParentID == UUID.Zero)
  2134. {
  2135. if (root == null)
  2136. {
  2137. root = folder;
  2138. }
  2139. else
  2140. {
  2141. throw new Exception("Multiple root folders found");
  2142. }
  2143. }
  2144. fmap.Add(folder.ID, folder);
  2145. }
  2146. // Hard to continue if the root folder is not there
  2147. if (root == null)
  2148. {
  2149. throw new Exception("Root folder not found");
  2150. }
  2151. // Construct the folder hierarchy
  2152. foreach (InventoryFolderImpl folder in folders)
  2153. {
  2154. if (folder.ID != root.ID)
  2155. {
  2156. fmap[folder.ParentID].AddChildFolder(folder);
  2157. }
  2158. }
  2159. // Find a home for every pre-existing item
  2160. foreach (InventoryItemBase item in items)
  2161. {
  2162. fmap[item.Folder].Items.Add(item.ID, item);
  2163. }
  2164. }
  2165. }
  2166. }