RemoteAdminPlugin.cs 146 KB

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