RemoteAdminPlugin.cs 158 KB

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