1
0

RemoteAdminPlugin.cs 141 KB

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