RemoteAdminPlugin.cs 138 KB

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