RemoteAdminPlugin.cs 146 KB

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