RemoteAdminPlugin.cs 123 KB

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