RemoteAdminPlugin.cs 152 KB

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