1
0

RemoteAdminPlugin.cs 158 KB

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