1
0

RemoteAdminPlugin.cs 150 KB

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