RemoteAdminPlugin.cs 124 KB

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