1
0

RemoteAdminPlugin.cs 157 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426
  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(new char[] { ',' });
  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( new char[] {','});
  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 (Exception e)
  1037. {
  1038. responseData["avatar_uuid"] = UUID.Zero.ToString();
  1039. throw e;
  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 (Exception e)
  1235. {
  1236. responseData["avatar_uuid"] = UUID.Zero.ToString();
  1237. throw e;
  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 e;
  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 (Exception e)
  1429. {
  1430. responseData["loaded"] = false;
  1431. throw e;
  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. {
  1495. options["home"] = (string)requestData["home"];
  1496. }
  1497. if ((string)requestData["noassets"] == "true")
  1498. {
  1499. options["noassets"] = (string)requestData["noassets"] ;
  1500. }
  1501. if (requestData.Contains("perm"))
  1502. {
  1503. options["checkPermissions"] = (string)requestData["perm"];
  1504. }
  1505. if ((string)requestData["all"] == "true")
  1506. {
  1507. options["all"] = (string)requestData["all"];
  1508. }
  1509. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1510. if (archiver != null)
  1511. {
  1512. Guid requestId = Guid.NewGuid();
  1513. scene.EventManager.OnOarFileSaved += RemoteAdminOarSaveCompleted;
  1514. m_log.InfoFormat(
  1515. "[RADMIN]: Submitting save OAR request for {0} to file {1}, request ID {2}",
  1516. scene.Name, filename, requestId);
  1517. archiver.ArchiveRegion(filename, requestId, options);
  1518. lock (m_saveOarLock)
  1519. Monitor.Wait(m_saveOarLock,5000);
  1520. scene.EventManager.OnOarFileSaved -= RemoteAdminOarSaveCompleted;
  1521. }
  1522. else
  1523. {
  1524. throw new Exception("Archiver module not present for scene");
  1525. }
  1526. responseData["saved"] = true;
  1527. }
  1528. catch (Exception e)
  1529. {
  1530. responseData["saved"] = false;
  1531. throw e;
  1532. }
  1533. m_log.Info("[RADMIN]: Save OAR Request complete");
  1534. }
  1535. private void RemoteAdminOarSaveCompleted(Guid uuid, string name)
  1536. {
  1537. if (name != "")
  1538. m_log.ErrorFormat("[RADMIN]: Saving of OAR file with request ID {0} failed with message {1}", uuid, name);
  1539. else
  1540. m_log.DebugFormat("[RADMIN]: Saved OAR file for request {0}", uuid);
  1541. lock (m_saveOarLock)
  1542. Monitor.Pulse(m_saveOarLock);
  1543. }
  1544. private void XmlRpcLoadXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1545. {
  1546. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  1547. Hashtable responseData = (Hashtable)response.Value;
  1548. Hashtable requestData = (Hashtable)request.Params[0];
  1549. lock (m_requestLock)
  1550. {
  1551. try
  1552. {
  1553. CheckStringParameters(requestData, responseData, new string[] {"filename"});
  1554. CheckRegionParams(requestData, responseData);
  1555. Scene scene = null;
  1556. GetSceneFromRegionParams(requestData, responseData, out scene);
  1557. string filename = (string) requestData["filename"];
  1558. responseData["switched"] = true;
  1559. string xml_version = "1";
  1560. if (requestData.Contains("xml_version"))
  1561. {
  1562. xml_version = (string) requestData["xml_version"];
  1563. }
  1564. switch (xml_version)
  1565. {
  1566. case "1":
  1567. m_application.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  1568. break;
  1569. case "2":
  1570. m_application.SceneManager.LoadCurrentSceneFromXml2(filename);
  1571. break;
  1572. default:
  1573. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1574. }
  1575. responseData["loaded"] = true;
  1576. }
  1577. catch (Exception e)
  1578. {
  1579. responseData["loaded"] = false;
  1580. responseData["switched"] = false;
  1581. throw e;
  1582. }
  1583. m_log.Info("[RADMIN]: Load XML Administrator Request complete");
  1584. }
  1585. }
  1586. private void XmlRpcSaveXMLMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1587. {
  1588. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  1589. Hashtable responseData = (Hashtable)response.Value;
  1590. Hashtable requestData = (Hashtable)request.Params[0];
  1591. try
  1592. {
  1593. CheckStringParameters(requestData, responseData, new string[] {"filename"});
  1594. CheckRegionParams(requestData, responseData);
  1595. Scene scene = null;
  1596. GetSceneFromRegionParams(requestData, responseData, out scene);
  1597. string filename = (string) requestData["filename"];
  1598. responseData["switched"] = true;
  1599. string xml_version = "1";
  1600. if (requestData.Contains("xml_version"))
  1601. {
  1602. xml_version = (string) requestData["xml_version"];
  1603. }
  1604. switch (xml_version)
  1605. {
  1606. case "1":
  1607. m_application.SceneManager.SaveCurrentSceneToXml(filename);
  1608. break;
  1609. case "2":
  1610. m_application.SceneManager.SaveCurrentSceneToXml2(filename);
  1611. break;
  1612. default:
  1613. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  1614. }
  1615. responseData["saved"] = true;
  1616. }
  1617. catch (Exception e)
  1618. {
  1619. responseData["saved"] = false;
  1620. responseData["switched"] = false;
  1621. throw e;
  1622. }
  1623. m_log.Info("[RADMIN]: Save XML Administrator Request complete");
  1624. }
  1625. private void XmlRpcRegionQueryMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1626. {
  1627. Hashtable responseData = (Hashtable)response.Value;
  1628. Hashtable requestData = (Hashtable)request.Params[0];
  1629. int flags = 0;
  1630. string text = String.Empty;
  1631. int health = 0;
  1632. responseData["success"] = true;
  1633. CheckRegionParams(requestData, responseData);
  1634. Scene scene = null;
  1635. try
  1636. {
  1637. GetSceneFromRegionParams(requestData, responseData, out scene);
  1638. health = scene.GetHealth(out flags, out text);
  1639. }
  1640. catch
  1641. {
  1642. responseData["error"] = null;
  1643. }
  1644. responseData["success"] = true;
  1645. responseData["health"] = health;
  1646. responseData["flags"] = flags;
  1647. responseData["message"] = text;
  1648. }
  1649. private void XmlRpcConsoleCommandMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1650. {
  1651. m_log.Info("[RADMIN]: Received Command XML Administrator Request");
  1652. Hashtable responseData = (Hashtable)response.Value;
  1653. Hashtable requestData = (Hashtable)request.Params[0];
  1654. CheckStringParameters(requestData, responseData, new string[] {"command"});
  1655. MainConsole.Instance.RunCommand(requestData["command"].ToString());
  1656. m_log.Info("[RADMIN]: Command XML Administrator Request complete");
  1657. }
  1658. private void XmlRpcAccessListClear(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1659. {
  1660. m_log.Info("[RADMIN]: Received Access List Clear Request");
  1661. Hashtable responseData = (Hashtable)response.Value;
  1662. Hashtable requestData = (Hashtable)request.Params[0];
  1663. responseData["success"] = true;
  1664. CheckRegionParams(requestData, responseData);
  1665. Scene scene = null;
  1666. GetSceneFromRegionParams(requestData, responseData, out scene);
  1667. scene.RegionInfo.EstateSettings.EstateAccess = new UUID[]{};
  1668. if (scene.RegionInfo.Persistent)
  1669. m_application.EstateDataService.StoreEstateSettings(scene.RegionInfo.EstateSettings);
  1670. m_log.Info("[RADMIN]: Access List Clear Request complete");
  1671. }
  1672. private void XmlRpcAccessListAdd(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1673. {
  1674. m_log.Info("[RADMIN]: Received Access List Add Request");
  1675. Hashtable responseData = (Hashtable)response.Value;
  1676. Hashtable requestData = (Hashtable)request.Params[0];
  1677. CheckRegionParams(requestData, responseData);
  1678. Scene scene = null;
  1679. GetSceneFromRegionParams(requestData, responseData, out scene);
  1680. int addedUsers = 0;
  1681. if (requestData.Contains("users"))
  1682. {
  1683. UUID scopeID = scene.RegionInfo.ScopeID;
  1684. IUserAccountService userService = scene.UserAccountService;
  1685. Hashtable users = (Hashtable) requestData["users"];
  1686. List<UUID> uuids = new List<UUID>();
  1687. foreach (string name in users.Values)
  1688. {
  1689. string[] parts = name.Split();
  1690. UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
  1691. if (account != null)
  1692. {
  1693. uuids.Add(account.PrincipalID);
  1694. m_log.DebugFormat("[RADMIN]: adding \"{0}\" to ACL for \"{1}\"", name, scene.RegionInfo.RegionName);
  1695. }
  1696. }
  1697. List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
  1698. foreach (UUID uuid in uuids)
  1699. {
  1700. if (!accessControlList.Contains(uuid))
  1701. {
  1702. accessControlList.Add(uuid);
  1703. addedUsers++;
  1704. }
  1705. }
  1706. scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
  1707. if (scene.RegionInfo.Persistent)
  1708. m_application.EstateDataService.StoreEstateSettings(scene.RegionInfo.EstateSettings);
  1709. }
  1710. responseData["added"] = addedUsers;
  1711. m_log.Info("[RADMIN]: Access List Add Request complete");
  1712. }
  1713. private void XmlRpcAccessListRemove(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1714. {
  1715. m_log.Info("[RADMIN]: Received Access List Remove Request");
  1716. Hashtable responseData = (Hashtable)response.Value;
  1717. Hashtable requestData = (Hashtable)request.Params[0];
  1718. CheckRegionParams(requestData, responseData);
  1719. Scene scene = null;
  1720. GetSceneFromRegionParams(requestData, responseData, out scene);
  1721. int removedUsers = 0;
  1722. if (requestData.Contains("users"))
  1723. {
  1724. UUID scopeID = scene.RegionInfo.ScopeID;
  1725. IUserAccountService userService = scene.UserAccountService;
  1726. //UserProfileCacheService ups = m_application.CommunicationsManager.UserProfileCacheService;
  1727. Hashtable users = (Hashtable) requestData["users"];
  1728. List<UUID> uuids = new List<UUID>();
  1729. foreach (string name in users.Values)
  1730. {
  1731. string[] parts = name.Split();
  1732. UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
  1733. if (account != null)
  1734. {
  1735. uuids.Add(account.PrincipalID);
  1736. }
  1737. }
  1738. List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
  1739. foreach (UUID uuid in uuids)
  1740. {
  1741. if (accessControlList.Contains(uuid))
  1742. {
  1743. accessControlList.Remove(uuid);
  1744. removedUsers++;
  1745. }
  1746. }
  1747. scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
  1748. if (scene.RegionInfo.Persistent)
  1749. m_application.EstateDataService.StoreEstateSettings(scene.RegionInfo.EstateSettings);
  1750. }
  1751. responseData["removed"] = removedUsers;
  1752. responseData["success"] = true;
  1753. m_log.Info("[RADMIN]: Access List Remove Request complete");
  1754. }
  1755. private void XmlRpcAccessListList(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1756. {
  1757. m_log.Info("[RADMIN]: Received Access List List Request");
  1758. Hashtable responseData = (Hashtable)response.Value;
  1759. Hashtable requestData = (Hashtable)request.Params[0];
  1760. CheckRegionParams(requestData, responseData);
  1761. Scene scene = null;
  1762. GetSceneFromRegionParams(requestData, responseData, out scene);
  1763. UUID[] accessControlList = scene.RegionInfo.EstateSettings.EstateAccess;
  1764. Hashtable users = new Hashtable();
  1765. foreach (UUID user in accessControlList)
  1766. {
  1767. UUID scopeID = scene.RegionInfo.ScopeID;
  1768. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, user);
  1769. if (account != null)
  1770. {
  1771. users[user.ToString()] = account.FirstName + " " + account.LastName;
  1772. }
  1773. }
  1774. responseData["users"] = users;
  1775. responseData["success"] = true;
  1776. m_log.Info("[RADMIN]: Access List List Request complete");
  1777. }
  1778. private void XmlRpcEstateReload(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1779. {
  1780. m_log.Info("[RADMIN]: Received Estate Reload Request");
  1781. Hashtable responseData = (Hashtable)response.Value;
  1782. // Hashtable requestData = (Hashtable)request.Params[0];
  1783. m_application.SceneManager.ForEachScene(s =>
  1784. s.RegionInfo.EstateSettings = m_application.EstateDataService.LoadEstateSettings(s.RegionInfo.RegionID, false)
  1785. );
  1786. responseData["success"] = true;
  1787. m_log.Info("[RADMIN]: Estate Reload Request complete");
  1788. }
  1789. private void XmlRpcGetAgentsMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1790. {
  1791. Hashtable responseData = (Hashtable)response.Value;
  1792. Hashtable requestData = (Hashtable)request.Params[0];
  1793. bool includeChildren = false;
  1794. if (requestData.Contains("include_children"))
  1795. bool.TryParse((string)requestData["include_children"], out includeChildren);
  1796. Scene scene;
  1797. GetSceneFromRegionParams(requestData, responseData, out scene);
  1798. ArrayList xmlRpcRegions = new ArrayList();
  1799. responseData["regions"] = xmlRpcRegions;
  1800. Hashtable xmlRpcRegion = new Hashtable();
  1801. xmlRpcRegions.Add(xmlRpcRegion);
  1802. xmlRpcRegion["name"] = scene.Name;
  1803. xmlRpcRegion["id"] = scene.RegionInfo.RegionID.ToString();
  1804. List<ScenePresence> agents = scene.GetScenePresences();
  1805. ArrayList xmlrpcAgents = new ArrayList();
  1806. foreach (ScenePresence agent in agents)
  1807. {
  1808. if (agent.IsChildAgent && !includeChildren)
  1809. continue;
  1810. Hashtable xmlRpcAgent = new Hashtable();
  1811. xmlRpcAgent.Add("name", agent.Name);
  1812. xmlRpcAgent.Add("id", agent.UUID.ToString());
  1813. xmlRpcAgent.Add("type", agent.PresenceType.ToString());
  1814. xmlRpcAgent.Add("current_parcel_id", agent.currentParcelUUID.ToString());
  1815. Vector3 pos = agent.AbsolutePosition;
  1816. xmlRpcAgent.Add("pos_x", pos.X.ToString());
  1817. xmlRpcAgent.Add("pos_y", pos.Y.ToString());
  1818. xmlRpcAgent.Add("pos_z", pos.Z.ToString());
  1819. Vector3 lookAt = agent.Lookat;
  1820. xmlRpcAgent.Add("lookat_x", lookAt.X.ToString());
  1821. xmlRpcAgent.Add("lookat_y", lookAt.Y.ToString());
  1822. xmlRpcAgent.Add("lookat_z", lookAt.Z.ToString());
  1823. Vector3 vel = agent.Velocity;
  1824. xmlRpcAgent.Add("vel_x", vel.X.ToString());
  1825. xmlRpcAgent.Add("vel_y", vel.Y.ToString());
  1826. xmlRpcAgent.Add("vel_z", vel.Z.ToString());
  1827. xmlRpcAgent.Add("is_flying", agent.Flying.ToString());
  1828. xmlRpcAgent.Add("is_sat_on_ground", agent.SitGround.ToString());
  1829. xmlRpcAgent.Add("is_sat_on_object", agent.IsSatOnObject.ToString());
  1830. xmlrpcAgents.Add(xmlRpcAgent);
  1831. }
  1832. m_log.DebugFormat(
  1833. "[REMOTE ADMIN]: XmlRpcGetAgents found {0} agents in {1}", xmlrpcAgents.Count, scene.Name);
  1834. xmlRpcRegion["agents"] = xmlrpcAgents;
  1835. responseData["success"] = true;
  1836. }
  1837. private void XmlRpcTeleportAgentMethod(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1838. {
  1839. Hashtable responseData = (Hashtable)response.Value;
  1840. Hashtable requestData = (Hashtable)request.Params[0];
  1841. UUID agentId;
  1842. string regionName = null;
  1843. Vector3 pos, lookAt;
  1844. ScenePresence sp = null;
  1845. if (requestData.Contains("agent_first_name") && requestData.Contains("agent_last_name"))
  1846. {
  1847. string firstName = requestData["agent_first_name"].ToString();
  1848. string lastName = requestData["agent_last_name"].ToString();
  1849. m_application.SceneManager.TryGetRootScenePresenceByName(firstName, lastName, out sp);
  1850. if (sp == null)
  1851. throw new Exception(
  1852. string.Format(
  1853. "No agent found with agent_first_name {0} and agent_last_name {1}", firstName, lastName));
  1854. }
  1855. else if (requestData.Contains("agent_id"))
  1856. {
  1857. string rawAgentId = (string)requestData["agent_id"];
  1858. if (!UUID.TryParse(rawAgentId, out agentId))
  1859. throw new Exception(string.Format("agent_id {0} does not have the correct id format", rawAgentId));
  1860. m_application.SceneManager.TryGetRootScenePresence(agentId, out sp);
  1861. if (sp == null)
  1862. throw new Exception(string.Format("No agent with agent_id {0} found in this simulator", agentId));
  1863. }
  1864. else
  1865. {
  1866. throw new Exception("No agent_id or agent_first_name and agent_last_name parameters specified");
  1867. }
  1868. if (requestData.Contains("region_name"))
  1869. regionName = (string)requestData["region_name"];
  1870. pos.X = ParseFloat(requestData, "pos_x", sp.AbsolutePosition.X);
  1871. pos.Y = ParseFloat(requestData, "pos_y", sp.AbsolutePosition.Y);
  1872. pos.Z = ParseFloat(requestData, "pos_z", sp.AbsolutePosition.Z);
  1873. lookAt.X = ParseFloat(requestData, "lookat_x", sp.Lookat.X);
  1874. lookAt.Y = ParseFloat(requestData, "lookat_y", sp.Lookat.Y);
  1875. lookAt.Z = ParseFloat(requestData, "lookat_z", sp.Lookat.Z);
  1876. sp.Scene.RequestTeleportLocation(
  1877. sp.ControllingClient, regionName, pos, lookAt, (uint)Constants.TeleportFlags.ViaLocation);
  1878. // We have no way of telling the failure of the actual teleport
  1879. responseData["success"] = true;
  1880. }
  1881. private void XmlRpcResetLand(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1882. {
  1883. Hashtable requestData = (Hashtable)request.Params[0];
  1884. Hashtable responseData = (Hashtable)response.Value;
  1885. string musicURL = string.Empty;
  1886. UUID groupID = UUID.Zero;
  1887. uint flags = 0;
  1888. bool set_group = false, set_music = false, set_flags = false;
  1889. if (requestData.Contains("group") && requestData["group"] != null)
  1890. set_group = UUID.TryParse(requestData["group"].ToString(), out groupID);
  1891. if (requestData.Contains("music") && requestData["music"] != null)
  1892. {
  1893. musicURL = requestData["music"].ToString();
  1894. set_music = true;
  1895. }
  1896. if (requestData.Contains("flags") && requestData["flags"] != null)
  1897. set_flags = UInt32.TryParse(requestData["flags"].ToString(), out flags);
  1898. m_log.InfoFormat("[RADMIN]: Received Reset Land Request group={0} musicURL={1} flags={2}",
  1899. (set_group ? groupID.ToString() : "unchanged"),
  1900. (set_music ? musicURL : "unchanged"),
  1901. (set_flags ? flags.ToString() : "unchanged"));
  1902. m_application.SceneManager.ForEachScene(delegate (Scene s)
  1903. {
  1904. List<ILandObject> parcels = s.LandChannel.AllParcels();
  1905. foreach (ILandObject p in parcels)
  1906. {
  1907. if (set_music)
  1908. p.LandData.MusicURL = musicURL;
  1909. if (set_group)
  1910. p.LandData.GroupID = groupID;
  1911. if (set_flags)
  1912. p.LandData.Flags = flags;
  1913. s.LandChannel.UpdateLandObject(p.LandData.LocalID, p.LandData);
  1914. }
  1915. }
  1916. );
  1917. responseData["success"] = true;
  1918. m_log.Info("[RADMIN]: Reset Land Request complete");
  1919. }
  1920. private void XmlRpcRefreshSearch(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1921. {
  1922. m_log.Info("[RADMIN]: Received Refresh Search Request");
  1923. Hashtable responseData = (Hashtable)response.Value;
  1924. Hashtable requestData = (Hashtable)request.Params[0];
  1925. CheckRegionParams(requestData, responseData);
  1926. Scene scene = null;
  1927. GetSceneFromRegionParams(requestData, responseData, out scene);
  1928. ISearchModule searchModule = scene.RequestModuleInterface<ISearchModule>();
  1929. if (searchModule != null)
  1930. {
  1931. searchModule.Refresh();
  1932. responseData["success"] = true;
  1933. }
  1934. else
  1935. {
  1936. responseData["success"] = false;
  1937. }
  1938. m_log.Info("[RADMIN]: Refresh Search Request complete");
  1939. }
  1940. private void XmlRpcRefreshMap(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1941. {
  1942. m_log.Info("[RADMIN]: Received Refresh Map Request");
  1943. Hashtable responseData = (Hashtable)response.Value;
  1944. Hashtable requestData = (Hashtable)request.Params[0];
  1945. CheckRegionParams(requestData, responseData);
  1946. Scene scene = null;
  1947. GetSceneFromRegionParams(requestData, responseData, out scene);
  1948. IMapImageUploadModule mapTileModule = scene.RequestModuleInterface<IMapImageUploadModule>();
  1949. if (mapTileModule != null)
  1950. {
  1951. Util.FireAndForget((x) =>
  1952. {
  1953. mapTileModule.UploadMapTile(scene);
  1954. });
  1955. responseData["success"] = true;
  1956. }
  1957. else
  1958. {
  1959. responseData["success"] = false;
  1960. }
  1961. m_log.Info("[RADMIN]: Refresh Map Request complete");
  1962. }
  1963. private void XmlRpcGetOpenSimVersion(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1964. {
  1965. m_log.Info("[RADMIN]: Received Get OpenSim Version Request");
  1966. Hashtable responseData = (Hashtable)response.Value;
  1967. responseData["version"] = m_openSimVersion;
  1968. responseData["success"] = true;
  1969. m_log.Info("[RADMIN]: Get OpenSim Version Request complete");
  1970. }
  1971. private void XmlRpcGetAgentCount(XmlRpcRequest request, XmlRpcResponse response, IPEndPoint remoteClient)
  1972. {
  1973. m_log.Info("[RADMIN]: Received Get Agent Count Request");
  1974. Hashtable responseData = (Hashtable)response.Value;
  1975. Hashtable requestData = (Hashtable)request.Params[0];
  1976. CheckRegionParams(requestData, responseData);
  1977. Scene scene = null;
  1978. GetSceneFromRegionParams(requestData, responseData, out scene);
  1979. if (scene == null)
  1980. {
  1981. responseData["success"] = false;
  1982. }
  1983. else
  1984. {
  1985. responseData["count"] = scene.GetRootAgentCount();
  1986. responseData["success"] = true;
  1987. }
  1988. m_log.Info("[RADMIN]: Get Agent Count Request complete");
  1989. }
  1990. /// <summary>
  1991. /// Parse a float with the given parameter name from a request data hash table.
  1992. /// </summary>
  1993. /// <remarks>
  1994. /// Will throw an exception if parameter is not a float.
  1995. /// Will not throw if parameter is not found, passes back default value instead.
  1996. /// </remarks>
  1997. /// <param name="requestData"></param>
  1998. /// <param name="paramName"></param>
  1999. /// <param name="defaultVal"></param>
  2000. /// <returns></returns>
  2001. private static float ParseFloat(Hashtable requestData, string paramName, float defaultVal)
  2002. {
  2003. if (requestData.Contains(paramName))
  2004. {
  2005. string rawVal = (string)requestData[paramName];
  2006. float val;
  2007. if (!float.TryParse(rawVal, out val))
  2008. throw new Exception(string.Format("{0} {1} is not a valid float", paramName, rawVal));
  2009. else
  2010. return val;
  2011. }
  2012. else
  2013. {
  2014. return defaultVal;
  2015. }
  2016. }
  2017. private static void CheckStringParameters(Hashtable requestData, Hashtable responseData, string[] param)
  2018. {
  2019. foreach (string parameter in param)
  2020. {
  2021. if (!requestData.Contains(parameter))
  2022. {
  2023. responseData["accepted"] = false;
  2024. throw new Exception(String.Format("missing string parameter {0}", parameter));
  2025. }
  2026. if (String.IsNullOrEmpty((string) requestData[parameter]))
  2027. {
  2028. responseData["accepted"] = false;
  2029. throw new Exception(String.Format("parameter {0} is empty", parameter));
  2030. }
  2031. }
  2032. }
  2033. private static void CheckIntegerParams(Hashtable requestData, Hashtable responseData, string[] param)
  2034. {
  2035. foreach (string parameter in param)
  2036. {
  2037. if (!requestData.Contains(parameter))
  2038. {
  2039. responseData["accepted"] = false;
  2040. throw new Exception(String.Format("missing integer parameter {0}", parameter));
  2041. }
  2042. }
  2043. }
  2044. private void CheckRegionParams(Hashtable requestData, Hashtable responseData)
  2045. {
  2046. //Checks if region parameters exist and gives exeption if no parameters are given
  2047. if ((requestData.ContainsKey("region_id") && !String.IsNullOrEmpty((string)requestData["region_id"])) ||
  2048. (requestData.ContainsKey("region_name") && !String.IsNullOrEmpty((string)requestData["region_name"])))
  2049. {
  2050. return;
  2051. }
  2052. else
  2053. {
  2054. responseData["accepted"] = false;
  2055. throw new Exception("no region_name or region_id given");
  2056. }
  2057. }
  2058. private void GetSceneFromRegionParams(Hashtable requestData, Hashtable responseData, out Scene scene)
  2059. {
  2060. scene = null;
  2061. if (requestData.ContainsKey("region_id") &&
  2062. !String.IsNullOrEmpty((string)requestData["region_id"]))
  2063. {
  2064. UUID regionID = (UUID)(string)requestData["region_id"];
  2065. if (!m_application.SceneManager.TryGetScene(regionID, out scene))
  2066. {
  2067. responseData["error"] = String.Format("Region ID {0} not found", regionID);
  2068. throw new Exception(String.Format("Region ID {0} not found", regionID));
  2069. }
  2070. }
  2071. else if (requestData.ContainsKey("region_name") &&
  2072. !String.IsNullOrEmpty((string)requestData["region_name"]))
  2073. {
  2074. string regionName = (string)requestData["region_name"];
  2075. if (!m_application.SceneManager.TryGetScene(regionName, out scene))
  2076. {
  2077. responseData["error"] = String.Format("Region {0} not found", regionName);
  2078. throw new Exception(String.Format("Region {0} not found", regionName));
  2079. }
  2080. }
  2081. else
  2082. {
  2083. responseData["error"] = "no region_name or region_id given";
  2084. throw new Exception("no region_name or region_id given");
  2085. }
  2086. return;
  2087. }
  2088. private bool GetBoolean(Hashtable requestData, string tag, bool defaultValue)
  2089. {
  2090. // If an access value has been provided, apply it.
  2091. if (requestData.Contains(tag))
  2092. {
  2093. switch (((string)requestData[tag]).ToLower())
  2094. {
  2095. case "true" :
  2096. case "t" :
  2097. case "1" :
  2098. return true;
  2099. case "false" :
  2100. case "f" :
  2101. case "0" :
  2102. return false;
  2103. default :
  2104. return defaultValue;
  2105. }
  2106. }
  2107. else
  2108. return defaultValue;
  2109. }
  2110. private int GetIntegerAttribute(XmlNode node, string attribute, int defaultValue)
  2111. {
  2112. try { return Convert.ToInt32(node.Attributes[attribute].Value); } catch{}
  2113. return defaultValue;
  2114. }
  2115. private uint GetUnsignedAttribute(XmlNode node, string attribute, uint defaultValue)
  2116. {
  2117. try { return Convert.ToUInt32(node.Attributes[attribute].Value); } catch{}
  2118. return defaultValue;
  2119. }
  2120. private string GetStringAttribute(XmlNode node, string attribute, string defaultValue)
  2121. {
  2122. try { return node.Attributes[attribute].Value; } catch{}
  2123. return defaultValue;
  2124. }
  2125. public void Dispose()
  2126. {
  2127. }
  2128. /// <summary>
  2129. /// Create a user
  2130. /// </summary>
  2131. /// <param name="scopeID"></param>
  2132. /// <param name="firstName"></param>
  2133. /// <param name="lastName"></param>
  2134. /// <param name="password"></param>
  2135. /// <param name="email"></param>
  2136. private UserAccount CreateUser(UUID scopeID, string firstName, string lastName, string password, string email)
  2137. {
  2138. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2139. IUserAccountService userAccountService = scene.UserAccountService;
  2140. IGridService gridService = scene.GridService;
  2141. IAuthenticationService authenticationService = scene.AuthenticationService;
  2142. IGridUserService gridUserService = scene.GridUserService;
  2143. IInventoryService inventoryService = scene.InventoryService;
  2144. UserAccount account = userAccountService.GetUserAccount(scopeID, firstName, lastName);
  2145. if (null == account)
  2146. {
  2147. account = new UserAccount(scopeID, UUID.Random(), firstName, lastName, email);
  2148. if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
  2149. {
  2150. account.ServiceURLs = new Dictionary<string, object>();
  2151. account.ServiceURLs["HomeURI"] = string.Empty;
  2152. account.ServiceURLs["InventoryServerURI"] = string.Empty;
  2153. account.ServiceURLs["AssetServerURI"] = string.Empty;
  2154. }
  2155. if (userAccountService.StoreUserAccount(account))
  2156. {
  2157. bool success;
  2158. if (authenticationService != null)
  2159. {
  2160. success = authenticationService.SetPassword(account.PrincipalID, password);
  2161. if (!success)
  2162. m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
  2163. firstName, lastName);
  2164. }
  2165. GridRegion home = null;
  2166. if (gridService != null)
  2167. {
  2168. List<GridRegion> defaultRegions = gridService.GetDefaultRegions(UUID.Zero);
  2169. if (defaultRegions != null && defaultRegions.Count >= 1)
  2170. home = defaultRegions[0];
  2171. if (gridUserService != null && home != null)
  2172. gridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  2173. else
  2174. m_log.WarnFormat("[RADMIN]: Unable to set home for account {0} {1}.",
  2175. firstName, lastName);
  2176. }
  2177. else
  2178. m_log.WarnFormat("[RADMIN]: Unable to retrieve home region for account {0} {1}.",
  2179. firstName, lastName);
  2180. if (inventoryService != null)
  2181. {
  2182. success = inventoryService.CreateUserInventory(account.PrincipalID);
  2183. if (!success)
  2184. m_log.WarnFormat("[RADMIN]: Unable to create inventory for account {0} {1}.",
  2185. firstName, lastName);
  2186. }
  2187. m_log.InfoFormat("[RADMIN]: Account {0} {1} created successfully", firstName, lastName);
  2188. return account;
  2189. } else {
  2190. m_log.ErrorFormat("[RADMIN]: Account creation failed for account {0} {1}", firstName, lastName);
  2191. }
  2192. }
  2193. else
  2194. {
  2195. m_log.ErrorFormat("[RADMIN]: A user with the name {0} {1} already exists!", firstName, lastName);
  2196. }
  2197. return null;
  2198. }
  2199. /// <summary>
  2200. /// Change password
  2201. /// </summary>
  2202. /// <param name="firstName"></param>
  2203. /// <param name="lastName"></param>
  2204. /// <param name="password"></param>
  2205. private bool ChangeUserPassword(string firstName, string lastName, string password)
  2206. {
  2207. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2208. IUserAccountService userAccountService = scene.UserAccountService;
  2209. IAuthenticationService authenticationService = scene.AuthenticationService;
  2210. UserAccount account = userAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
  2211. if (null != account)
  2212. {
  2213. bool success = false;
  2214. if (authenticationService != null)
  2215. success = authenticationService.SetPassword(account.PrincipalID, password);
  2216. if (!success)
  2217. {
  2218. m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
  2219. firstName, lastName);
  2220. return false;
  2221. }
  2222. return true;
  2223. }
  2224. else
  2225. {
  2226. m_log.ErrorFormat("[RADMIN]: No such user");
  2227. return false;
  2228. }
  2229. }
  2230. private bool LoadHeightmap(string file, UUID regionID)
  2231. {
  2232. m_log.InfoFormat("[RADMIN]: Terrain Loading: {0}", file);
  2233. Scene region = null;
  2234. if (!m_application.SceneManager.TryGetScene(regionID, out region))
  2235. {
  2236. m_log.InfoFormat("[RADMIN]: unable to get a scene with that name: {0}", regionID.ToString());
  2237. return false;
  2238. }
  2239. ITerrainModule terrainModule = region.RequestModuleInterface<ITerrainModule>();
  2240. if (null == terrainModule) throw new Exception("terrain module not available");
  2241. if (Uri.IsWellFormedUriString(file, UriKind.Absolute))
  2242. {
  2243. m_log.Info("[RADMIN]: Terrain path is URL");
  2244. Uri result;
  2245. if (Uri.TryCreate(file, UriKind.RelativeOrAbsolute, out result))
  2246. {
  2247. // the url is valid
  2248. string fileType = file.Substring(file.LastIndexOf('/') + 1);
  2249. terrainModule.LoadFromStream(fileType, result);
  2250. }
  2251. }
  2252. else
  2253. {
  2254. terrainModule.LoadFromFile(file);
  2255. }
  2256. m_log.Info("[RADMIN]: Load height maps request complete");
  2257. return true;
  2258. }
  2259. /// <summary>
  2260. /// This method is called by the user-create and user-modify methods to establish
  2261. /// or change, the user's appearance. Default avatar names can be specified via
  2262. /// the config file, but must correspond to avatars in the default appearance
  2263. /// file, or pre-existing in the user database.
  2264. /// This should probably get moved into somewhere more core eventually.
  2265. /// </summary>
  2266. private void UpdateUserAppearance(Hashtable responseData, Hashtable requestData, UUID userid)
  2267. {
  2268. m_log.DebugFormat("[RADMIN]: updateUserAppearance");
  2269. string defaultMale = m_config.GetString("default_male", "Default Male");
  2270. string defaultFemale = m_config.GetString("default_female", "Default Female");
  2271. string defaultNeutral = m_config.GetString("default_female", "Default Default");
  2272. string model = String.Empty;
  2273. // Has a gender preference been supplied?
  2274. if (requestData.Contains("gender"))
  2275. {
  2276. switch ((string)requestData["gender"])
  2277. {
  2278. case "m" :
  2279. case "male" :
  2280. model = defaultMale;
  2281. break;
  2282. case "f" :
  2283. case "female" :
  2284. model = defaultFemale;
  2285. break;
  2286. case "n" :
  2287. case "neutral" :
  2288. default :
  2289. model = defaultNeutral;
  2290. break;
  2291. }
  2292. }
  2293. // Has an explicit model been specified?
  2294. if (requestData.Contains("model") && (String.IsNullOrEmpty((string)requestData["gender"])))
  2295. {
  2296. model = (string)requestData["model"];
  2297. }
  2298. // No appearance attributes were set
  2299. if (String.IsNullOrEmpty(model))
  2300. {
  2301. m_log.DebugFormat("[RADMIN]: Appearance update not requested");
  2302. return;
  2303. }
  2304. m_log.DebugFormat("[RADMIN]: Setting appearance for avatar {0}, using model <{1}>", userid, model);
  2305. string[] modelSpecifiers = model.Split();
  2306. if (modelSpecifiers.Length != 2)
  2307. {
  2308. m_log.WarnFormat("[RADMIN]: User appearance not set for {0}. Invalid model name : <{1}>", userid, model);
  2309. // modelSpecifiers = dmodel.Split();
  2310. return;
  2311. }
  2312. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2313. UUID scopeID = scene.RegionInfo.ScopeID;
  2314. UserAccount modelProfile = scene.UserAccountService.GetUserAccount(scopeID, modelSpecifiers[0], modelSpecifiers[1]);
  2315. if (modelProfile == null)
  2316. {
  2317. m_log.WarnFormat("[RADMIN]: Requested model ({0}) not found. Appearance unchanged", model);
  2318. return;
  2319. }
  2320. // Set current user's appearance. This bit is easy. The appearance structure is populated with
  2321. // actual asset ids, however to complete the magic we need to populate the inventory with the
  2322. // assets in question.
  2323. EstablishAppearance(userid, modelProfile.PrincipalID);
  2324. m_log.DebugFormat("[RADMIN]: Finished setting appearance for avatar {0}, using model {1}",
  2325. userid, model);
  2326. }
  2327. /// <summary>
  2328. /// This method is called by updateAvatarAppearance once any specified model has been
  2329. /// ratified, or an appropriate default value has been adopted. The intended prototype
  2330. /// is known to exist, as is the target avatar.
  2331. /// </summary>
  2332. private void EstablishAppearance(UUID destination, UUID source)
  2333. {
  2334. m_log.DebugFormat("[RADMIN]: Initializing inventory for {0} from {1}", destination, source);
  2335. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2336. // If the model has no associated appearance we're done.
  2337. AvatarAppearance avatarAppearance = scene.AvatarService.GetAppearance(source);
  2338. if (avatarAppearance == null)
  2339. return;
  2340. // Simple appearance copy or copy Clothing and Bodyparts folders?
  2341. bool copyFolders = m_config.GetBoolean("copy_folders", false);
  2342. if (!copyFolders)
  2343. {
  2344. // Simple copy of wearables and appearance update
  2345. try
  2346. {
  2347. CopyWearablesAndAttachments(destination, source, avatarAppearance);
  2348. scene.AvatarService.SetAppearance(destination, avatarAppearance);
  2349. }
  2350. catch (Exception e)
  2351. {
  2352. m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}",
  2353. destination, e.Message);
  2354. }
  2355. return;
  2356. }
  2357. // Copy Clothing and Bodypart folders and appearance update
  2358. try
  2359. {
  2360. Dictionary<UUID,UUID> inventoryMap = new Dictionary<UUID,UUID>();
  2361. CopyInventoryFolders(destination, source, FolderType.Clothing, inventoryMap, avatarAppearance);
  2362. CopyInventoryFolders(destination, source, FolderType.BodyPart, inventoryMap, avatarAppearance);
  2363. AvatarWearable[] wearables = avatarAppearance.Wearables;
  2364. for (int i=0; i<wearables.Length; i++)
  2365. {
  2366. if (inventoryMap.ContainsKey(wearables[i][0].ItemID))
  2367. {
  2368. AvatarWearable wearable = new AvatarWearable();
  2369. wearable.Wear(inventoryMap[wearables[i][0].ItemID],
  2370. wearables[i][0].AssetID);
  2371. avatarAppearance.SetWearable(i, wearable);
  2372. }
  2373. }
  2374. scene.AvatarService.SetAppearance(destination, avatarAppearance);
  2375. }
  2376. catch (Exception e)
  2377. {
  2378. m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}",
  2379. destination, e.Message);
  2380. }
  2381. return;
  2382. }
  2383. /// <summary>
  2384. /// This method is called by establishAppearance to do a copy all inventory items
  2385. /// worn or attached to the Clothing inventory folder of the receiving avatar.
  2386. /// In parallel the avatar wearables and attachments are updated.
  2387. /// </summary>
  2388. private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance)
  2389. {
  2390. IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;
  2391. // Get Clothing folder of receiver
  2392. InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, FolderType.Clothing);
  2393. if (destinationFolder == null)
  2394. throw new Exception("Cannot locate folder(s)");
  2395. // Missing destination folder? This should *never* be the case
  2396. if (destinationFolder.Type != (short)FolderType.Clothing)
  2397. {
  2398. destinationFolder = new InventoryFolderBase();
  2399. destinationFolder.ID = UUID.Random();
  2400. destinationFolder.Name = "Clothing";
  2401. destinationFolder.Owner = destination;
  2402. destinationFolder.Type = (short)FolderType.Clothing;
  2403. destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
  2404. destinationFolder.Version = 1;
  2405. inventoryService.AddFolder(destinationFolder); // store base record
  2406. m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
  2407. }
  2408. // Wearables
  2409. AvatarWearable[] wearables = avatarAppearance.Wearables;
  2410. AvatarWearable wearable;
  2411. for (int i = 0; i<wearables.Length; i++)
  2412. {
  2413. wearable = wearables[i];
  2414. if (wearable[0].ItemID != UUID.Zero)
  2415. {
  2416. // Get inventory item and copy it
  2417. InventoryItemBase item = inventoryService.GetItem(source, wearable[0].ItemID);
  2418. if (item != null)
  2419. {
  2420. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  2421. destinationItem.Name = item.Name;
  2422. destinationItem.Owner = destination;
  2423. destinationItem.Description = item.Description;
  2424. destinationItem.InvType = item.InvType;
  2425. destinationItem.CreatorId = item.CreatorId;
  2426. destinationItem.CreatorData = item.CreatorData;
  2427. destinationItem.NextPermissions = item.NextPermissions;
  2428. destinationItem.CurrentPermissions = item.CurrentPermissions;
  2429. destinationItem.BasePermissions = item.BasePermissions;
  2430. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  2431. destinationItem.GroupPermissions = item.GroupPermissions;
  2432. destinationItem.AssetType = item.AssetType;
  2433. destinationItem.AssetID = item.AssetID;
  2434. destinationItem.GroupID = item.GroupID;
  2435. destinationItem.GroupOwned = item.GroupOwned;
  2436. destinationItem.SalePrice = item.SalePrice;
  2437. destinationItem.SaleType = item.SaleType;
  2438. destinationItem.Flags = item.Flags;
  2439. destinationItem.CreationDate = item.CreationDate;
  2440. destinationItem.Folder = destinationFolder.ID;
  2441. ApplyNextOwnerPermissions(destinationItem);
  2442. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  2443. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
  2444. // Wear item
  2445. AvatarWearable newWearable = new AvatarWearable();
  2446. newWearable.Wear(destinationItem.ID, wearable[0].AssetID);
  2447. avatarAppearance.SetWearable(i, newWearable);
  2448. }
  2449. else
  2450. {
  2451. m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID);
  2452. }
  2453. }
  2454. }
  2455. // Attachments
  2456. List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();
  2457. foreach (AvatarAttachment attachment in attachments)
  2458. {
  2459. int attachpoint = attachment.AttachPoint;
  2460. UUID itemID = attachment.ItemID;
  2461. if (itemID != UUID.Zero)
  2462. {
  2463. // Get inventory item and copy it
  2464. InventoryItemBase item = inventoryService.GetItem(source, itemID);
  2465. if (item != null)
  2466. {
  2467. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  2468. destinationItem.Name = item.Name;
  2469. destinationItem.Owner = destination;
  2470. destinationItem.Description = item.Description;
  2471. destinationItem.InvType = item.InvType;
  2472. destinationItem.CreatorId = item.CreatorId;
  2473. destinationItem.CreatorData = item.CreatorData;
  2474. destinationItem.NextPermissions = item.NextPermissions;
  2475. destinationItem.CurrentPermissions = item.CurrentPermissions;
  2476. destinationItem.BasePermissions = item.BasePermissions;
  2477. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  2478. destinationItem.GroupPermissions = item.GroupPermissions;
  2479. destinationItem.AssetType = item.AssetType;
  2480. destinationItem.AssetID = item.AssetID;
  2481. destinationItem.GroupID = item.GroupID;
  2482. destinationItem.GroupOwned = item.GroupOwned;
  2483. destinationItem.SalePrice = item.SalePrice;
  2484. destinationItem.SaleType = item.SaleType;
  2485. destinationItem.Flags = item.Flags;
  2486. destinationItem.CreationDate = item.CreationDate;
  2487. destinationItem.Folder = destinationFolder.ID;
  2488. ApplyNextOwnerPermissions(destinationItem);
  2489. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  2490. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
  2491. // Attach item
  2492. avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
  2493. m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
  2494. }
  2495. else
  2496. {
  2497. m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
  2498. }
  2499. }
  2500. }
  2501. }
  2502. /// <summary>
  2503. /// This method is called by establishAppearance to copy inventory folders to make
  2504. /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments
  2505. /// </summary>
  2506. private void CopyInventoryFolders(UUID destination, UUID source, FolderType assetType, Dictionary<UUID, UUID> inventoryMap,
  2507. AvatarAppearance avatarAppearance)
  2508. {
  2509. IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;
  2510. InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType);
  2511. InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType);
  2512. if (sourceFolder == null || destinationFolder == null)
  2513. throw new Exception("Cannot locate folder(s)");
  2514. // Missing source folder? This should *never* be the case
  2515. if (sourceFolder.Type != (short)assetType)
  2516. {
  2517. sourceFolder = new InventoryFolderBase();
  2518. sourceFolder.ID = UUID.Random();
  2519. if (assetType == FolderType.Clothing)
  2520. {
  2521. sourceFolder.Name = "Clothing";
  2522. }
  2523. else
  2524. {
  2525. sourceFolder.Name = "Body Parts";
  2526. }
  2527. sourceFolder.Owner = source;
  2528. sourceFolder.Type = (short)assetType;
  2529. sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID;
  2530. sourceFolder.Version = 1;
  2531. inventoryService.AddFolder(sourceFolder); // store base record
  2532. m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source);
  2533. }
  2534. // Missing destination folder? This should *never* be the case
  2535. if (destinationFolder.Type != (short)assetType)
  2536. {
  2537. destinationFolder = new InventoryFolderBase();
  2538. destinationFolder.ID = UUID.Random();
  2539. if (assetType == FolderType.Clothing)
  2540. {
  2541. destinationFolder.Name = "Clothing";
  2542. }
  2543. else
  2544. {
  2545. destinationFolder.Name = "Body Parts";
  2546. }
  2547. destinationFolder.Owner = destination;
  2548. destinationFolder.Type = (short)assetType;
  2549. destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
  2550. destinationFolder.Version = 1;
  2551. inventoryService.AddFolder(destinationFolder); // store base record
  2552. m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
  2553. }
  2554. InventoryFolderBase extraFolder;
  2555. List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders;
  2556. foreach (InventoryFolderBase folder in folders)
  2557. {
  2558. extraFolder = new InventoryFolderBase();
  2559. extraFolder.ID = UUID.Random();
  2560. extraFolder.Name = folder.Name;
  2561. extraFolder.Owner = destination;
  2562. extraFolder.Type = folder.Type;
  2563. extraFolder.Version = folder.Version;
  2564. extraFolder.ParentID = destinationFolder.ID;
  2565. inventoryService.AddFolder(extraFolder);
  2566. m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID);
  2567. List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items;
  2568. foreach (InventoryItemBase item in items)
  2569. {
  2570. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  2571. destinationItem.Name = item.Name;
  2572. destinationItem.Owner = destination;
  2573. destinationItem.Description = item.Description;
  2574. destinationItem.InvType = item.InvType;
  2575. destinationItem.CreatorId = item.CreatorId;
  2576. destinationItem.CreatorData = item.CreatorData;
  2577. destinationItem.NextPermissions = item.NextPermissions;
  2578. destinationItem.CurrentPermissions = item.CurrentPermissions;
  2579. destinationItem.BasePermissions = item.BasePermissions;
  2580. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  2581. destinationItem.GroupPermissions = item.GroupPermissions;
  2582. destinationItem.AssetType = item.AssetType;
  2583. destinationItem.AssetID = item.AssetID;
  2584. destinationItem.GroupID = item.GroupID;
  2585. destinationItem.GroupOwned = item.GroupOwned;
  2586. destinationItem.SalePrice = item.SalePrice;
  2587. destinationItem.SaleType = item.SaleType;
  2588. destinationItem.Flags = item.Flags;
  2589. destinationItem.CreationDate = item.CreationDate;
  2590. destinationItem.Folder = extraFolder.ID;
  2591. ApplyNextOwnerPermissions(destinationItem);
  2592. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  2593. inventoryMap.Add(item.ID, destinationItem.ID);
  2594. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID);
  2595. // Attach item, if original is attached
  2596. int attachpoint = avatarAppearance.GetAttachpoint(item.ID);
  2597. if (attachpoint != 0)
  2598. {
  2599. avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
  2600. m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
  2601. }
  2602. }
  2603. }
  2604. }
  2605. /// <summary>
  2606. /// Apply next owner permissions.
  2607. /// </summary>
  2608. private void ApplyNextOwnerPermissions(InventoryItemBase item)
  2609. {
  2610. if (item.InvType == (int)InventoryType.Object)
  2611. {
  2612. uint perms = item.CurrentPermissions;
  2613. PermissionsUtil.ApplyFoldedPermissions(item.CurrentPermissions, ref perms);
  2614. item.CurrentPermissions = perms;
  2615. }
  2616. item.CurrentPermissions &= item.NextPermissions;
  2617. item.BasePermissions &= item.NextPermissions;
  2618. item.EveryOnePermissions &= item.NextPermissions;
  2619. // item.OwnerChanged = true;
  2620. // item.PermsMask = 0;
  2621. // item.PermsGranter = UUID.Zero;
  2622. }
  2623. /// <summary>
  2624. /// This method is called if a given model avatar name can not be found. If the external
  2625. /// file has already been loaded once, then control returns immediately. If not, then it
  2626. /// looks for a default appearance file. This file contains XML definitions of zero or more named
  2627. /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection
  2628. /// of items that together, define a particular ensemble for the avatar. Each avatar should
  2629. /// indicate which outfit is the default, and this outfit will be automatically worn. The
  2630. /// other outfits are provided to allow "real" avatars a way to easily change their outfits.
  2631. /// </summary>
  2632. private bool CreateDefaultAvatars()
  2633. {
  2634. // Only load once
  2635. if (m_defaultAvatarsLoaded)
  2636. {
  2637. return false;
  2638. }
  2639. m_log.DebugFormat("[RADMIN]: Creating default avatar entries");
  2640. m_defaultAvatarsLoaded = true;
  2641. // Load processing starts here...
  2642. try
  2643. {
  2644. string defaultAppearanceFileName = null;
  2645. //m_config may be null if RemoteAdmin configuration secition is missing or disabled in OpenSim.ini
  2646. if (m_config != null)
  2647. {
  2648. defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml");
  2649. }
  2650. if (File.Exists(defaultAppearanceFileName))
  2651. {
  2652. XmlDocument doc = new XmlDocument();
  2653. string name = "*unknown*";
  2654. string email = "anon@anon";
  2655. uint regionXLocation = 1000;
  2656. uint regionYLocation = 1000;
  2657. string password = UUID.Random().ToString(); // No requirement to sign-in.
  2658. UUID ID = UUID.Zero;
  2659. AvatarAppearance avatarAppearance;
  2660. XmlNodeList avatars;
  2661. XmlNodeList assets;
  2662. XmlNode perms = null;
  2663. bool include = false;
  2664. bool select = false;
  2665. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2666. IInventoryService inventoryService = scene.InventoryService;
  2667. IAssetService assetService = scene.AssetService;
  2668. doc.LoadXml(File.ReadAllText(defaultAppearanceFileName));
  2669. // Load up any included assets. Duplicates will be ignored
  2670. assets = doc.GetElementsByTagName("RequiredAsset");
  2671. foreach (XmlNode assetNode in assets)
  2672. {
  2673. AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""), SByte.Parse(GetStringAttribute(assetNode, "type", "")), UUID.Zero.ToString());
  2674. asset.Description = GetStringAttribute(assetNode,"desc","");
  2675. asset.Local = Boolean.Parse(GetStringAttribute(assetNode,"local",""));
  2676. asset.Temporary = Boolean.Parse(GetStringAttribute(assetNode,"temporary",""));
  2677. asset.Data = Convert.FromBase64String(assetNode.InnerText);
  2678. assetService.Store(asset);
  2679. }
  2680. avatars = doc.GetElementsByTagName("Avatar");
  2681. // The document may contain multiple avatars
  2682. foreach (XmlElement avatar in avatars)
  2683. {
  2684. m_log.DebugFormat("[RADMIN]: Loading appearance for {0}, gender = {1}",
  2685. GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?"));
  2686. // Create the user identified by the avatar entry
  2687. try
  2688. {
  2689. // Only the name value is mandatory
  2690. name = GetStringAttribute(avatar,"name",name);
  2691. email = GetStringAttribute(avatar,"email",email);
  2692. regionXLocation = GetUnsignedAttribute(avatar,"regx",regionXLocation);
  2693. regionYLocation = GetUnsignedAttribute(avatar,"regy",regionYLocation);
  2694. password = GetStringAttribute(avatar,"password",password);
  2695. string[] names = name.Split();
  2696. UUID scopeID = scene.RegionInfo.ScopeID;
  2697. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]);
  2698. if (null == account)
  2699. {
  2700. account = CreateUser(scopeID, names[0], names[1], password, email);
  2701. if (null == account)
  2702. {
  2703. m_log.ErrorFormat("[RADMIN]: Avatar {0} {1} was not created", names[0], names[1]);
  2704. return false;
  2705. }
  2706. }
  2707. // Set home position
  2708. GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
  2709. (int)Util.RegionToWorldLoc(regionXLocation), (int)Util.RegionToWorldLoc(regionYLocation));
  2710. if (null == home) {
  2711. m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]);
  2712. } else {
  2713. scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  2714. m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]);
  2715. }
  2716. ID = account.PrincipalID;
  2717. m_log.DebugFormat("[RADMIN]: User {0}[{1}] created or retrieved", name, ID);
  2718. include = true;
  2719. }
  2720. catch (Exception e)
  2721. {
  2722. m_log.DebugFormat("[RADMIN]: Error creating user {0} : {1}", name, e.Message);
  2723. include = false;
  2724. }
  2725. // OK, User has been created OK, now we can install the inventory.
  2726. // First retrieve the current inventory (the user may already exist)
  2727. // Note that althought he inventory is retrieved, the hierarchy has
  2728. // not been interpreted at all.
  2729. if (include)
  2730. {
  2731. // Setup for appearance processing
  2732. avatarAppearance = scene.AvatarService.GetAppearance(ID);
  2733. if (avatarAppearance == null)
  2734. avatarAppearance = new AvatarAppearance();
  2735. AvatarWearable[] wearables = avatarAppearance.Wearables;
  2736. for (int i=0; i<wearables.Length; i++)
  2737. {
  2738. wearables[i] = new AvatarWearable();
  2739. }
  2740. try
  2741. {
  2742. // m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory",
  2743. // uic.folders.Count, uic.items.Count);
  2744. InventoryFolderBase clothingFolder = inventoryService.GetFolderForType(ID, FolderType.Clothing);
  2745. // This should *never* be the case
  2746. if (clothingFolder == null || clothingFolder.Type != (short)FolderType.Clothing)
  2747. {
  2748. clothingFolder = new InventoryFolderBase();
  2749. clothingFolder.ID = UUID.Random();
  2750. clothingFolder.Name = "Clothing";
  2751. clothingFolder.Owner = ID;
  2752. clothingFolder.Type = (short)FolderType.Clothing;
  2753. clothingFolder.ParentID = inventoryService.GetRootFolder(ID).ID;
  2754. clothingFolder.Version = 1;
  2755. inventoryService.AddFolder(clothingFolder); // store base record
  2756. m_log.ErrorFormat("[RADMIN]: Created clothing folder for {0}/{1}", name, ID);
  2757. }
  2758. // OK, now we have an inventory for the user, read in the outfits from the
  2759. // default appearance XMl file.
  2760. XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble");
  2761. InventoryFolderBase extraFolder;
  2762. string outfitName;
  2763. UUID assetid;
  2764. foreach (XmlElement outfit in outfits)
  2765. {
  2766. m_log.DebugFormat("[RADMIN]: Loading outfit {0} for {1}",
  2767. GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?"));
  2768. outfitName = GetStringAttribute(outfit,"name","");
  2769. select = (GetStringAttribute(outfit,"default","no") == "yes");
  2770. // If the folder already exists, re-use it. The defaults may
  2771. // change over time. Augment only.
  2772. List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders;
  2773. extraFolder = null;
  2774. foreach (InventoryFolderBase folder in folders)
  2775. {
  2776. if (folder.Name == outfitName)
  2777. {
  2778. extraFolder = folder;
  2779. break;
  2780. }
  2781. }
  2782. // Otherwise, we must create the folder.
  2783. if (extraFolder == null)
  2784. {
  2785. m_log.DebugFormat("[RADMIN]: Creating outfit folder {0} for {1}", outfitName, name);
  2786. extraFolder = new InventoryFolderBase();
  2787. extraFolder.ID = UUID.Random();
  2788. extraFolder.Name = outfitName;
  2789. extraFolder.Owner = ID;
  2790. extraFolder.Type = (short)FolderType.Clothing;
  2791. extraFolder.Version = 1;
  2792. extraFolder.ParentID = clothingFolder.ID;
  2793. inventoryService.AddFolder(extraFolder);
  2794. m_log.DebugFormat("[RADMIN]: Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID);
  2795. }
  2796. // Now get the pieces that make up the outfit
  2797. XmlNodeList items = outfit.GetElementsByTagName("Item");
  2798. foreach (XmlElement item in items)
  2799. {
  2800. assetid = UUID.Zero;
  2801. XmlNodeList children = item.ChildNodes;
  2802. foreach (XmlNode child in children)
  2803. {
  2804. switch (child.Name)
  2805. {
  2806. case "Permissions" :
  2807. m_log.DebugFormat("[RADMIN]: Permissions specified");
  2808. perms = child;
  2809. break;
  2810. case "Asset" :
  2811. assetid = new UUID(child.InnerText);
  2812. break;
  2813. }
  2814. }
  2815. InventoryItemBase inventoryItem = null;
  2816. // Check if asset is in inventory already
  2817. inventoryItem = null;
  2818. List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items;
  2819. foreach (InventoryItemBase listItem in inventoryItems)
  2820. {
  2821. if (listItem.AssetID == assetid)
  2822. {
  2823. inventoryItem = listItem;
  2824. break;
  2825. }
  2826. }
  2827. // Create inventory item
  2828. if (inventoryItem == null)
  2829. {
  2830. inventoryItem = new InventoryItemBase(UUID.Random(), ID);
  2831. inventoryItem.Name = GetStringAttribute(item,"name","");
  2832. inventoryItem.Description = GetStringAttribute(item,"desc","");
  2833. inventoryItem.InvType = GetIntegerAttribute(item,"invtype",-1);
  2834. inventoryItem.CreatorId = GetStringAttribute(item,"creatorid","");
  2835. inventoryItem.CreatorData = GetStringAttribute(item, "creatordata", "");
  2836. inventoryItem.NextPermissions = GetUnsignedAttribute(perms, "next", 0x7fffffff);
  2837. inventoryItem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff);
  2838. inventoryItem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff);
  2839. inventoryItem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff);
  2840. inventoryItem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff);
  2841. inventoryItem.AssetType = GetIntegerAttribute(item,"assettype",-1);
  2842. inventoryItem.AssetID = assetid; // associated asset
  2843. inventoryItem.GroupID = (UUID)GetStringAttribute(item,"groupid","");
  2844. inventoryItem.GroupOwned = (GetStringAttribute(item,"groupowned","false") == "true");
  2845. inventoryItem.SalePrice = GetIntegerAttribute(item,"saleprice",0);
  2846. inventoryItem.SaleType = (byte)GetIntegerAttribute(item,"saletype",0);
  2847. inventoryItem.Flags = GetUnsignedAttribute(item,"flags",0);
  2848. inventoryItem.CreationDate = GetIntegerAttribute(item,"creationdate",Util.UnixTimeSinceEpoch());
  2849. inventoryItem.Folder = extraFolder.ID; // Parent folder
  2850. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(inventoryItem);
  2851. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID);
  2852. }
  2853. // Attach item, if attachpoint is specified
  2854. int attachpoint = GetIntegerAttribute(item,"attachpoint",0);
  2855. if (attachpoint != 0)
  2856. {
  2857. avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID);
  2858. m_log.DebugFormat("[RADMIN]: Attached {0}", inventoryItem.ID);
  2859. }
  2860. // Record whether or not the item is to be initially worn
  2861. try
  2862. {
  2863. if (select && (GetStringAttribute(item, "wear", "false") == "true"))
  2864. {
  2865. avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID);
  2866. }
  2867. }
  2868. catch (Exception e)
  2869. {
  2870. m_log.WarnFormat("[RADMIN]: Error wearing item {0} : {1}", inventoryItem.ID, e.Message);
  2871. }
  2872. } // foreach item in outfit
  2873. m_log.DebugFormat("[RADMIN]: Outfit {0} load completed", outfitName);
  2874. } // foreach outfit
  2875. m_log.DebugFormat("[RADMIN]: Inventory update complete for {0}", name);
  2876. scene.AvatarService.SetAppearance(ID, avatarAppearance);
  2877. }
  2878. catch (Exception e)
  2879. {
  2880. m_log.WarnFormat("[RADMIN]: Inventory processing incomplete for user {0} : {1}",
  2881. name, e.Message);
  2882. }
  2883. } // End of include
  2884. }
  2885. m_log.DebugFormat("[RADMIN]: Default avatar loading complete");
  2886. }
  2887. else
  2888. {
  2889. m_log.DebugFormat("[RADMIN]: No default avatar information available");
  2890. return false;
  2891. }
  2892. }
  2893. catch (Exception e)
  2894. {
  2895. m_log.WarnFormat("[RADMIN]: Exception whilst loading default avatars ; {0}", e.Message);
  2896. return false;
  2897. }
  2898. return true;
  2899. }
  2900. }
  2901. }