RemoteAdminPlugin.cs 158 KB

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