RemoteAdminPlugin.cs 138 KB

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