RemoteAdminPlugin.cs 138 KB

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