RemoteAdminPlugin.cs 151 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193
  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.LoadEstateSettings(region.RegionID, true);
  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. }
  635. else
  636. {
  637. int estateID = estateIDs[0];
  638. region.EstateSettings = m_application.EstateDataService.LoadEstateSettings(estateID);
  639. if (!m_application.EstateDataService.LinkRegion(region.RegionID, estateID))
  640. throw new Exception("Failed to join estate.");
  641. }
  642. // Create the region and perform any initial initialization
  643. IScene newScene;
  644. m_application.CreateRegion(region, out newScene);
  645. // If an access specification was provided, use it.
  646. // Otherwise accept the default.
  647. newScene.RegionInfo.EstateSettings.PublicAccess = GetBoolean(requestData, "public", m_publicAccess);
  648. newScene.RegionInfo.EstateSettings.Save();
  649. // enable voice on newly created region if
  650. // requested by either the XmlRpc request or the
  651. // configuration
  652. if (GetBoolean(requestData, "enable_voice", m_enableVoiceForNewRegions))
  653. {
  654. List<ILandObject> parcels = ((Scene)newScene).LandChannel.AllParcels();
  655. foreach (ILandObject parcel in parcels)
  656. {
  657. parcel.LandData.Flags |= (uint) ParcelFlags.AllowVoiceChat;
  658. parcel.LandData.Flags |= (uint) ParcelFlags.UseEstateVoiceChan;
  659. ((Scene)newScene).LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
  660. }
  661. }
  662. responseData["success"] = true;
  663. responseData["region_name"] = region.RegionName;
  664. responseData["region_uuid"] = region.RegionID.ToString();
  665. response.Value = responseData;
  666. }
  667. catch (Exception e)
  668. {
  669. m_log.ErrorFormat("[RADMIN] CreateRegion: failed {0} {1}", e.Message, e.StackTrace);
  670. responseData["success"] = false;
  671. responseData["error"] = e.Message;
  672. response.Value = responseData;
  673. }
  674. m_log.Info("[RADMIN]: CreateRegion: request complete");
  675. return response;
  676. }
  677. }
  678. /// <summary>
  679. /// Delete a new region.
  680. /// <summary>
  681. /// <param name="request">incoming XML RPC request</param>
  682. /// <remarks>
  683. /// XmlRpcDeleteRegionMethod takes the following XMLRPC
  684. /// parameters
  685. /// <list type="table">
  686. /// <listheader><term>parameter name</term><description>description</description></listheader>
  687. /// <item><term>password</term>
  688. /// <description>admin password as set in OpenSim.ini</description></item>
  689. /// <item><term>region_name</term>
  690. /// <description>desired region name</description></item>
  691. /// <item><term>region_id</term>
  692. /// <description>(optional) desired region UUID</description></item>
  693. /// </list>
  694. ///
  695. /// XmlRpcDeleteRegionMethod returns
  696. /// <list type="table">
  697. /// <listheader><term>name</term><description>description</description></listheader>
  698. /// <item><term>success</term>
  699. /// <description>true or false</description></item>
  700. /// <item><term>error</term>
  701. /// <description>error message if success is false</description></item>
  702. /// </list>
  703. /// </remarks>
  704. public XmlRpcResponse XmlRpcDeleteRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  705. {
  706. m_log.Info("[RADMIN]: DeleteRegion: new request");
  707. XmlRpcResponse response = new XmlRpcResponse();
  708. Hashtable responseData = new Hashtable();
  709. lock (m_requestLock)
  710. {
  711. try
  712. {
  713. Hashtable requestData = (Hashtable) request.Params[0];
  714. CheckStringParameters(request, new string[] {"password", "region_name"});
  715. Scene scene = null;
  716. string regionName = (string) requestData["region_name"];
  717. if (!m_application.SceneManager.TryGetScene(regionName, out scene))
  718. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  719. m_application.RemoveRegion(scene, true);
  720. responseData["success"] = true;
  721. responseData["region_name"] = regionName;
  722. response.Value = responseData;
  723. }
  724. catch (Exception e)
  725. {
  726. m_log.ErrorFormat("[RADMIN] DeleteRegion: failed {0} {1}", e.Message, e.StackTrace);
  727. responseData["success"] = false;
  728. responseData["error"] = e.Message;
  729. response.Value = responseData;
  730. }
  731. m_log.Info("[RADMIN]: DeleteRegion: request complete");
  732. return response;
  733. }
  734. }
  735. /// <summary>
  736. /// Close a region.
  737. /// <summary>
  738. /// <param name="request">incoming XML RPC request</param>
  739. /// <remarks>
  740. /// XmlRpcCloseRegionMethod takes the following XMLRPC
  741. /// parameters
  742. /// <list type="table">
  743. /// <listheader><term>parameter name</term><description>description</description></listheader>
  744. /// <item><term>password</term>
  745. /// <description>admin password as set in OpenSim.ini</description></item>
  746. /// <item><term>region_name</term>
  747. /// <description>desired region name</description></item>
  748. /// <item><term>region_id</term>
  749. /// <description>(optional) desired region UUID</description></item>
  750. /// </list>
  751. ///
  752. /// XmlRpcShutdownRegionMethod returns
  753. /// <list type="table">
  754. /// <listheader><term>name</term><description>description</description></listheader>
  755. /// <item><term>success</term>
  756. /// <description>true or false</description></item>
  757. /// <item><term>region_name</term>
  758. /// <description>the region name if success is true</description></item>
  759. /// <item><term>error</term>
  760. /// <description>error message if success is false</description></item>
  761. /// </list>
  762. /// </remarks>
  763. public XmlRpcResponse XmlRpcCloseRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  764. {
  765. m_log.Info("[RADMIN]: CloseRegion: new request");
  766. XmlRpcResponse response = new XmlRpcResponse();
  767. Hashtable responseData = new Hashtable();
  768. Scene scene = null;
  769. lock (m_requestLock)
  770. {
  771. try
  772. {
  773. Hashtable requestData = (Hashtable) request.Params[0];
  774. CheckStringParameters(request, new string[] {"password"});
  775. if (requestData.ContainsKey("region_id") &&
  776. !String.IsNullOrEmpty((string) requestData["region_id"]))
  777. {
  778. // Region specified by UUID
  779. UUID regionID = (UUID) (string) requestData["region_id"];
  780. if (!m_application.SceneManager.TryGetScene(regionID, out scene))
  781. throw new Exception(String.Format("region \"{0}\" does not exist", regionID));
  782. m_application.CloseRegion(scene);
  783. responseData["success"] = true;
  784. responseData["region_id"] = regionID;
  785. response.Value = responseData;
  786. }
  787. else if (requestData.ContainsKey("region_name") &&
  788. !String.IsNullOrEmpty((string) requestData["region_name"]))
  789. {
  790. // Region specified by name
  791. string regionName = (string) requestData["region_name"];
  792. if (!m_application.SceneManager.TryGetScene(regionName, out scene))
  793. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  794. m_application.CloseRegion(scene);
  795. responseData["success"] = true;
  796. responseData["region_name"] = regionName;
  797. response.Value = responseData;
  798. }
  799. else
  800. throw new Exception("no region specified");
  801. }
  802. catch (Exception e)
  803. {
  804. m_log.ErrorFormat("[RADMIN]: CloseRegion: failed {0} {1}", e.Message, e.StackTrace);
  805. responseData["success"] = false;
  806. responseData["error"] = e.Message;
  807. response.Value = responseData;
  808. }
  809. m_log.Info("[RADMIN]: CloseRegion: request complete");
  810. return response;
  811. }
  812. }
  813. /// <summary>
  814. /// Change characteristics of an existing region.
  815. /// <summary>
  816. /// <param name="request">incoming XML RPC request</param>
  817. /// <remarks>
  818. /// XmlRpcModifyRegionMethod takes the following XMLRPC
  819. /// parameters
  820. /// <list type="table">
  821. /// <listheader><term>parameter name</term><description>description</description></listheader>
  822. /// <item><term>password</term>
  823. /// <description>admin password as set in OpenSim.ini</description></item>
  824. /// <item><term>region_name</term>
  825. /// <description>desired region name</description></item>
  826. /// <item><term>region_id</term>
  827. /// <description>(optional) desired region UUID</description></item>
  828. /// <item><term>public</term>
  829. /// <description>if true, set the region to public
  830. /// ('true' or 'false'), else to private</description></item>
  831. /// <item><term>enable_voice</term>
  832. /// <description>if true, enable voice on all parcels of
  833. /// the region, else disable</description></item>
  834. /// </list>
  835. ///
  836. /// XmlRpcModifyRegionMethod returns
  837. /// <list type="table">
  838. /// <listheader><term>name</term><description>description</description></listheader>
  839. /// <item><term>success</term>
  840. /// <description>true or false</description></item>
  841. /// <item><term>error</term>
  842. /// <description>error message if success is false</description></item>
  843. /// </list>
  844. /// </remarks>
  845. public XmlRpcResponse XmlRpcModifyRegionMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  846. {
  847. m_log.Info("[RADMIN]: ModifyRegion: new request");
  848. XmlRpcResponse response = new XmlRpcResponse();
  849. Hashtable responseData = new Hashtable();
  850. lock (m_requestLock)
  851. {
  852. try
  853. {
  854. Hashtable requestData = (Hashtable) request.Params[0];
  855. CheckStringParameters(request, new string[] {"password", "region_name"});
  856. Scene scene = null;
  857. string regionName = (string) requestData["region_name"];
  858. if (!m_application.SceneManager.TryGetScene(regionName, out scene))
  859. throw new Exception(String.Format("region \"{0}\" does not exist", regionName));
  860. // Modify access
  861. scene.RegionInfo.EstateSettings.PublicAccess =
  862. GetBoolean(requestData,"public", scene.RegionInfo.EstateSettings.PublicAccess);
  863. if (scene.RegionInfo.Persistent)
  864. scene.RegionInfo.EstateSettings.Save();
  865. if (requestData.ContainsKey("enable_voice"))
  866. {
  867. bool enableVoice = GetBoolean(requestData, "enable_voice", true);
  868. List<ILandObject> parcels = ((Scene)scene).LandChannel.AllParcels();
  869. foreach (ILandObject parcel in parcels)
  870. {
  871. if (enableVoice)
  872. {
  873. parcel.LandData.Flags |= (uint)ParcelFlags.AllowVoiceChat;
  874. parcel.LandData.Flags |= (uint)ParcelFlags.UseEstateVoiceChan;
  875. }
  876. else
  877. {
  878. parcel.LandData.Flags &= ~(uint)ParcelFlags.AllowVoiceChat;
  879. parcel.LandData.Flags &= ~(uint)ParcelFlags.UseEstateVoiceChan;
  880. }
  881. scene.LandChannel.UpdateLandObject(parcel.LandData.LocalID, parcel.LandData);
  882. }
  883. }
  884. responseData["success"] = true;
  885. responseData["region_name"] = regionName;
  886. response.Value = responseData;
  887. }
  888. catch (Exception e)
  889. {
  890. m_log.ErrorFormat("[RADMIN] ModifyRegion: failed {0} {1}", e.Message, e.StackTrace);
  891. responseData["success"] = false;
  892. responseData["error"] = e.Message;
  893. response.Value = responseData;
  894. }
  895. m_log.Info("[RADMIN]: ModifyRegion: request complete");
  896. return response;
  897. }
  898. }
  899. /// <summary>
  900. /// Create a new user account.
  901. /// <summary>
  902. /// <param name="request">incoming XML RPC request</param>
  903. /// <remarks>
  904. /// XmlRpcCreateUserMethod takes the following XMLRPC
  905. /// parameters
  906. /// <list type="table">
  907. /// <listheader><term>parameter name</term><description>description</description></listheader>
  908. /// <item><term>password</term>
  909. /// <description>admin password as set in OpenSim.ini</description></item>
  910. /// <item><term>user_firstname</term>
  911. /// <description>avatar's first name</description></item>
  912. /// <item><term>user_lastname</term>
  913. /// <description>avatar's last name</description></item>
  914. /// <item><term>user_password</term>
  915. /// <description>avatar's password</description></item>
  916. /// <item><term>user_email</term>
  917. /// <description>email of the avatar's owner (optional)</description></item>
  918. /// <item><term>start_region_x</term>
  919. /// <description>avatar's start region coordinates, X value</description></item>
  920. /// <item><term>start_region_y</term>
  921. /// <description>avatar's start region coordinates, Y value</description></item>
  922. /// </list>
  923. ///
  924. /// XmlRpcCreateUserMethod returns
  925. /// <list type="table">
  926. /// <listheader><term>name</term><description>description</description></listheader>
  927. /// <item><term>success</term>
  928. /// <description>true or false</description></item>
  929. /// <item><term>error</term>
  930. /// <description>error message if success is false</description></item>
  931. /// <item><term>avatar_uuid</term>
  932. /// <description>UUID of the newly created avatar
  933. /// account; UUID.Zero if failed.
  934. /// </description></item>
  935. /// </list>
  936. /// </remarks>
  937. public XmlRpcResponse XmlRpcCreateUserMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  938. {
  939. m_log.Info("[RADMIN]: CreateUser: new request");
  940. FailIfRemoteAdminDisabled("CreateUser");
  941. XmlRpcResponse response = new XmlRpcResponse();
  942. Hashtable responseData = new Hashtable();
  943. lock (m_requestLock)
  944. {
  945. try
  946. {
  947. Hashtable requestData = (Hashtable) request.Params[0];
  948. // check completeness
  949. CheckStringParameters(request, new string[]
  950. {
  951. "password", "user_firstname",
  952. "user_lastname", "user_password",
  953. });
  954. CheckIntegerParams(request, new string[] {"start_region_x", "start_region_y"});
  955. // check password
  956. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  957. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  958. // do the job
  959. string firstName = (string) requestData["user_firstname"];
  960. string lastName = (string) requestData["user_lastname"];
  961. string password = (string) requestData["user_password"];
  962. uint regionXLocation = Convert.ToUInt32((Int32) requestData["start_region_x"]);
  963. uint regionYLocation = Convert.ToUInt32((Int32) requestData["start_region_y"]);
  964. string email = ""; // empty string for email
  965. if (requestData.Contains("user_email"))
  966. email = (string)requestData["user_email"];
  967. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  968. UUID scopeID = scene.RegionInfo.ScopeID;
  969. UserAccount account = CreateUser(scopeID, firstName, lastName, password, email);
  970. if (null == account)
  971. throw new Exception(String.Format("failed to create new user {0} {1}",
  972. firstName, lastName));
  973. // Set home position
  974. GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
  975. (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
  976. if (null == home) {
  977. m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", firstName, lastName);
  978. } else {
  979. scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  980. m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName);
  981. }
  982. // Establish the avatar's initial appearance
  983. UpdateUserAppearance(responseData, requestData, account.PrincipalID);
  984. responseData["success"] = true;
  985. responseData["avatar_uuid"] = account.PrincipalID.ToString();
  986. response.Value = responseData;
  987. m_log.InfoFormat("[RADMIN]: CreateUser: User {0} {1} created, UUID {2}", firstName, lastName, account.PrincipalID);
  988. }
  989. catch (Exception e)
  990. {
  991. m_log.ErrorFormat("[RADMIN]: CreateUser: failed: {0} {1}", e.Message, e.StackTrace);
  992. responseData["success"] = false;
  993. responseData["avatar_uuid"] = UUID.Zero.ToString();
  994. responseData["error"] = e.Message;
  995. response.Value = responseData;
  996. }
  997. m_log.Info("[RADMIN]: CreateUser: request complete");
  998. return response;
  999. }
  1000. }
  1001. /// <summary>
  1002. /// Check whether a certain user account exists.
  1003. /// <summary>
  1004. /// <param name="request">incoming XML RPC request</param>
  1005. /// <remarks>
  1006. /// XmlRpcUserExistsMethod takes the following XMLRPC
  1007. /// parameters
  1008. /// <list type="table">
  1009. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1010. /// <item><term>password</term>
  1011. /// <description>admin password as set in OpenSim.ini</description></item>
  1012. /// <item><term>user_firstname</term>
  1013. /// <description>avatar's first name</description></item>
  1014. /// <item><term>user_lastname</term>
  1015. /// <description>avatar's last name</description></item>
  1016. /// </list>
  1017. ///
  1018. /// XmlRpcCreateUserMethod returns
  1019. /// <list type="table">
  1020. /// <listheader><term>name</term><description>description</description></listheader>
  1021. /// <item><term>user_firstname</term>
  1022. /// <description>avatar's first name</description></item>
  1023. /// <item><term>user_lastname</term>
  1024. /// <description>avatar's last name</description></item>
  1025. /// <item><term>user_lastlogin</term>
  1026. /// <description>avatar's last login time (secs since UNIX epoch)</description></item>
  1027. /// <item><term>success</term>
  1028. /// <description>true or false</description></item>
  1029. /// <item><term>error</term>
  1030. /// <description>error message if success is false</description></item>
  1031. /// </list>
  1032. /// </remarks>
  1033. public XmlRpcResponse XmlRpcUserExistsMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  1034. {
  1035. m_log.Info("[RADMIN]: UserExists: new request");
  1036. FailIfRemoteAdminDisabled("UserExists");
  1037. XmlRpcResponse response = new XmlRpcResponse();
  1038. Hashtable responseData = new Hashtable();
  1039. try
  1040. {
  1041. Hashtable requestData = (Hashtable) request.Params[0];
  1042. // check completeness
  1043. CheckStringParameters(request, new string[] {"password", "user_firstname", "user_lastname"});
  1044. string firstName = (string) requestData["user_firstname"];
  1045. string lastName = (string) requestData["user_lastname"];
  1046. responseData["user_firstname"] = firstName;
  1047. responseData["user_lastname"] = lastName;
  1048. UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
  1049. UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, firstName, lastName);
  1050. if (null == account)
  1051. {
  1052. responseData["success"] = false;
  1053. responseData["lastlogin"] = 0;
  1054. }
  1055. else
  1056. {
  1057. GridUserInfo userInfo = m_application.SceneManager.CurrentOrFirstScene.GridUserService.GetGridUserInfo(account.PrincipalID.ToString());
  1058. if (userInfo != null)
  1059. responseData["lastlogin"] = userInfo.Login;
  1060. else
  1061. responseData["lastlogin"] = 0;
  1062. responseData["success"] = true;
  1063. }
  1064. response.Value = responseData;
  1065. }
  1066. catch (Exception e)
  1067. {
  1068. m_log.ErrorFormat("[RADMIN]: UserExists: failed: {0} {1}", e.Message, e.StackTrace);
  1069. responseData["success"] = false;
  1070. responseData["error"] = e.Message;
  1071. response.Value = responseData;
  1072. }
  1073. m_log.Info("[RADMIN]: UserExists: request complete");
  1074. return response;
  1075. }
  1076. /// <summary>
  1077. /// Update a user account.
  1078. /// <summary>
  1079. /// <param name="request">incoming XML RPC request</param>
  1080. /// <remarks>
  1081. /// XmlRpcUpdateUserAccountMethod takes the following XMLRPC
  1082. /// parameters (changeable ones are optional)
  1083. /// <list type="table">
  1084. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1085. /// <item><term>password</term>
  1086. /// <description>admin password as set in OpenSim.ini</description></item>
  1087. /// <item><term>user_firstname</term>
  1088. /// <description>avatar's first name (cannot be changed)</description></item>
  1089. /// <item><term>user_lastname</term>
  1090. /// <description>avatar's last name (cannot be changed)</description></item>
  1091. /// <item><term>user_password</term>
  1092. /// <description>avatar's password (changeable)</description></item>
  1093. /// <item><term>start_region_x</term>
  1094. /// <description>avatar's start region coordinates, X
  1095. /// value (changeable)</description></item>
  1096. /// <item><term>start_region_y</term>
  1097. /// <description>avatar's start region coordinates, Y
  1098. /// value (changeable)</description></item>
  1099. /// <item><term>about_real_world (not implemented yet)</term>
  1100. /// <description>"about" text of avatar owner (changeable)</description></item>
  1101. /// <item><term>about_virtual_world (not implemented yet)</term>
  1102. /// <description>"about" text of avatar (changeable)</description></item>
  1103. /// </list>
  1104. ///
  1105. /// XmlRpcCreateUserMethod returns
  1106. /// <list type="table">
  1107. /// <listheader><term>name</term><description>description</description></listheader>
  1108. /// <item><term>success</term>
  1109. /// <description>true or false</description></item>
  1110. /// <item><term>error</term>
  1111. /// <description>error message if success is false</description></item>
  1112. /// <item><term>avatar_uuid</term>
  1113. /// <description>UUID of the updated avatar
  1114. /// account; UUID.Zero if failed.
  1115. /// </description></item>
  1116. /// </list>
  1117. /// </remarks>
  1118. public XmlRpcResponse XmlRpcUpdateUserAccountMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  1119. {
  1120. m_log.Info("[RADMIN]: UpdateUserAccount: new request");
  1121. m_log.Warn("[RADMIN]: This method needs update for 0.7");
  1122. FailIfRemoteAdminDisabled("UpdateUserAccount");
  1123. XmlRpcResponse response = new XmlRpcResponse();
  1124. Hashtable responseData = new Hashtable();
  1125. lock (m_requestLock)
  1126. {
  1127. try
  1128. {
  1129. Hashtable requestData = (Hashtable) request.Params[0];
  1130. // check completeness
  1131. CheckStringParameters(request, new string[] {
  1132. "password", "user_firstname",
  1133. "user_lastname"});
  1134. // check password
  1135. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1136. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1137. // do the job
  1138. string firstName = (string) requestData["user_firstname"];
  1139. string lastName = (string) requestData["user_lastname"];
  1140. string password = String.Empty;
  1141. uint? regionXLocation = null;
  1142. uint? regionYLocation = null;
  1143. // uint? ulaX = null;
  1144. // uint? ulaY = null;
  1145. // uint? ulaZ = null;
  1146. // uint? usaX = null;
  1147. // uint? usaY = null;
  1148. // uint? usaZ = null;
  1149. // string aboutFirstLive = String.Empty;
  1150. // string aboutAvatar = String.Empty;
  1151. if (requestData.ContainsKey("user_password")) password = (string) requestData["user_password"];
  1152. if (requestData.ContainsKey("start_region_x"))
  1153. regionXLocation = Convert.ToUInt32((Int32) requestData["start_region_x"]);
  1154. if (requestData.ContainsKey("start_region_y"))
  1155. regionYLocation = Convert.ToUInt32((Int32) requestData["start_region_y"]);
  1156. // if (requestData.ContainsKey("start_lookat_x"))
  1157. // ulaX = Convert.ToUInt32((Int32) requestData["start_lookat_x"]);
  1158. // if (requestData.ContainsKey("start_lookat_y"))
  1159. // ulaY = Convert.ToUInt32((Int32) requestData["start_lookat_y"]);
  1160. // if (requestData.ContainsKey("start_lookat_z"))
  1161. // ulaZ = Convert.ToUInt32((Int32) requestData["start_lookat_z"]);
  1162. // if (requestData.ContainsKey("start_standat_x"))
  1163. // usaX = Convert.ToUInt32((Int32) requestData["start_standat_x"]);
  1164. // if (requestData.ContainsKey("start_standat_y"))
  1165. // usaY = Convert.ToUInt32((Int32) requestData["start_standat_y"]);
  1166. // if (requestData.ContainsKey("start_standat_z"))
  1167. // usaZ = Convert.ToUInt32((Int32) requestData["start_standat_z"]);
  1168. // if (requestData.ContainsKey("about_real_world"))
  1169. // aboutFirstLive = (string)requestData["about_real_world"];
  1170. // if (requestData.ContainsKey("about_virtual_world"))
  1171. // aboutAvatar = (string)requestData["about_virtual_world"];
  1172. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  1173. UUID scopeID = scene.RegionInfo.ScopeID;
  1174. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, firstName, lastName);
  1175. if (null == account)
  1176. throw new Exception(String.Format("avatar {0} {1} does not exist", firstName, lastName));
  1177. if (!String.IsNullOrEmpty(password))
  1178. {
  1179. m_log.DebugFormat("[RADMIN]: UpdateUserAccount: updating password for avatar {0} {1}", firstName, lastName);
  1180. ChangeUserPassword(firstName, lastName, password);
  1181. }
  1182. // if (null != usaX) userProfile.HomeLocationX = (uint) usaX;
  1183. // if (null != usaY) userProfile.HomeLocationY = (uint) usaY;
  1184. // if (null != usaZ) userProfile.HomeLocationZ = (uint) usaZ;
  1185. // if (null != ulaX) userProfile.HomeLookAtX = (uint) ulaX;
  1186. // if (null != ulaY) userProfile.HomeLookAtY = (uint) ulaY;
  1187. // if (null != ulaZ) userProfile.HomeLookAtZ = (uint) ulaZ;
  1188. // if (String.Empty != aboutFirstLive) userProfile.FirstLifeAboutText = aboutFirstLive;
  1189. // if (String.Empty != aboutAvatar) userProfile.AboutText = aboutAvatar;
  1190. // Set home position
  1191. if ((null != regionXLocation) && (null != regionYLocation))
  1192. {
  1193. GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
  1194. (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
  1195. if (null == home) {
  1196. m_log.WarnFormat("[RADMIN]: Unable to set home region for updated user account {0} {1}", firstName, lastName);
  1197. } else {
  1198. scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  1199. m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, firstName, lastName);
  1200. }
  1201. }
  1202. // User has been created. Now establish gender and appearance.
  1203. UpdateUserAppearance(responseData, requestData, account.PrincipalID);
  1204. responseData["success"] = true;
  1205. responseData["avatar_uuid"] = account.PrincipalID.ToString();
  1206. response.Value = responseData;
  1207. m_log.InfoFormat("[RADMIN]: UpdateUserAccount: account for user {0} {1} updated, UUID {2}",
  1208. firstName, lastName,
  1209. account.PrincipalID);
  1210. }
  1211. catch (Exception e)
  1212. {
  1213. m_log.ErrorFormat("[RADMIN] UpdateUserAccount: failed: {0} {1}", e.Message, e.StackTrace);
  1214. responseData["success"] = false;
  1215. responseData["avatar_uuid"] = UUID.Zero.ToString();
  1216. responseData["error"] = e.Message;
  1217. response.Value = responseData;
  1218. }
  1219. m_log.Info("[RADMIN]: UpdateUserAccount: request complete");
  1220. return response;
  1221. }
  1222. }
  1223. /// <summary>
  1224. /// This method is called by the user-create and user-modify methods to establish
  1225. /// or change, the user's appearance. Default avatar names can be specified via
  1226. /// the config file, but must correspond to avatars in the default appearance
  1227. /// file, or pre-existing in the user database.
  1228. /// This should probably get moved into somewhere more core eventually.
  1229. /// </summary>
  1230. private void UpdateUserAppearance(Hashtable responseData, Hashtable requestData, UUID userid)
  1231. {
  1232. m_log.DebugFormat("[RADMIN]: updateUserAppearance");
  1233. string defaultMale = m_config.GetString("default_male", "Default Male");
  1234. string defaultFemale = m_config.GetString("default_female", "Default Female");
  1235. string defaultNeutral = m_config.GetString("default_female", "Default Default");
  1236. string model = String.Empty;
  1237. // Has a gender preference been supplied?
  1238. if (requestData.Contains("gender"))
  1239. {
  1240. switch ((string)requestData["gender"])
  1241. {
  1242. case "m" :
  1243. case "male" :
  1244. model = defaultMale;
  1245. break;
  1246. case "f" :
  1247. case "female" :
  1248. model = defaultFemale;
  1249. break;
  1250. case "n" :
  1251. case "neutral" :
  1252. default :
  1253. model = defaultNeutral;
  1254. break;
  1255. }
  1256. }
  1257. // Has an explicit model been specified?
  1258. if (requestData.Contains("model") && (String.IsNullOrEmpty((string)requestData["gender"])))
  1259. {
  1260. model = (string)requestData["model"];
  1261. }
  1262. // No appearance attributes were set
  1263. if (String.IsNullOrEmpty(model))
  1264. {
  1265. m_log.DebugFormat("[RADMIN]: Appearance update not requested");
  1266. return;
  1267. }
  1268. m_log.DebugFormat("[RADMIN]: Setting appearance for avatar {0}, using model <{1}>", userid, model);
  1269. string[] modelSpecifiers = model.Split();
  1270. if (modelSpecifiers.Length != 2)
  1271. {
  1272. m_log.WarnFormat("[RADMIN]: User appearance not set for {0}. Invalid model name : <{1}>", userid, model);
  1273. // modelSpecifiers = dmodel.Split();
  1274. return;
  1275. }
  1276. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  1277. UUID scopeID = scene.RegionInfo.ScopeID;
  1278. UserAccount modelProfile = scene.UserAccountService.GetUserAccount(scopeID, modelSpecifiers[0], modelSpecifiers[1]);
  1279. if (modelProfile == null)
  1280. {
  1281. m_log.WarnFormat("[RADMIN]: Requested model ({0}) not found. Appearance unchanged", model);
  1282. return;
  1283. }
  1284. // Set current user's appearance. This bit is easy. The appearance structure is populated with
  1285. // actual asset ids, however to complete the magic we need to populate the inventory with the
  1286. // assets in question.
  1287. EstablishAppearance(userid, modelProfile.PrincipalID);
  1288. m_log.DebugFormat("[RADMIN]: Finished setting appearance for avatar {0}, using model {1}",
  1289. userid, model);
  1290. }
  1291. /// <summary>
  1292. /// This method is called by updateAvatarAppearance once any specified model has been
  1293. /// ratified, or an appropriate default value has been adopted. The intended prototype
  1294. /// is known to exist, as is the target avatar.
  1295. /// </summary>
  1296. private void EstablishAppearance(UUID destination, UUID source)
  1297. {
  1298. m_log.DebugFormat("[RADMIN]: Initializing inventory for {0} from {1}", destination, source);
  1299. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  1300. // If the model has no associated appearance we're done.
  1301. AvatarAppearance avatarAppearance = scene.AvatarService.GetAppearance(source);
  1302. if (avatarAppearance == null)
  1303. return;
  1304. // Simple appearance copy or copy Clothing and Bodyparts folders?
  1305. bool copyFolders = m_config.GetBoolean("copy_folders", false);
  1306. if (!copyFolders)
  1307. {
  1308. // Simple copy of wearables and appearance update
  1309. try
  1310. {
  1311. CopyWearablesAndAttachments(destination, source, avatarAppearance);
  1312. scene.AvatarService.SetAppearance(destination, avatarAppearance);
  1313. }
  1314. catch (Exception e)
  1315. {
  1316. m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}",
  1317. destination, e.Message);
  1318. }
  1319. return;
  1320. }
  1321. // Copy Clothing and Bodypart folders and appearance update
  1322. try
  1323. {
  1324. Dictionary<UUID,UUID> inventoryMap = new Dictionary<UUID,UUID>();
  1325. CopyInventoryFolders(destination, source, AssetType.Clothing, inventoryMap, avatarAppearance);
  1326. CopyInventoryFolders(destination, source, AssetType.Bodypart, inventoryMap, avatarAppearance);
  1327. AvatarWearable[] wearables = avatarAppearance.Wearables;
  1328. for (int i=0; i<wearables.Length; i++)
  1329. {
  1330. if (inventoryMap.ContainsKey(wearables[i][0].ItemID))
  1331. {
  1332. AvatarWearable wearable = new AvatarWearable();
  1333. wearable.Wear(inventoryMap[wearables[i][0].ItemID],
  1334. wearables[i][0].AssetID);
  1335. avatarAppearance.SetWearable(i, wearable);
  1336. }
  1337. }
  1338. scene.AvatarService.SetAppearance(destination, avatarAppearance);
  1339. }
  1340. catch (Exception e)
  1341. {
  1342. m_log.WarnFormat("[RADMIN]: Error transferring appearance for {0} : {1}",
  1343. destination, e.Message);
  1344. }
  1345. return;
  1346. }
  1347. /// <summary>
  1348. /// This method is called by establishAppearance to do a copy all inventory items
  1349. /// worn or attached to the Clothing inventory folder of the receiving avatar.
  1350. /// In parallel the avatar wearables and attachments are updated.
  1351. /// </summary>
  1352. private void CopyWearablesAndAttachments(UUID destination, UUID source, AvatarAppearance avatarAppearance)
  1353. {
  1354. IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;
  1355. // Get Clothing folder of receiver
  1356. InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, AssetType.Clothing);
  1357. if (destinationFolder == null)
  1358. throw new Exception("Cannot locate folder(s)");
  1359. // Missing destination folder? This should *never* be the case
  1360. if (destinationFolder.Type != (short)AssetType.Clothing)
  1361. {
  1362. destinationFolder = new InventoryFolderBase();
  1363. destinationFolder.ID = UUID.Random();
  1364. destinationFolder.Name = "Clothing";
  1365. destinationFolder.Owner = destination;
  1366. destinationFolder.Type = (short)AssetType.Clothing;
  1367. destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
  1368. destinationFolder.Version = 1;
  1369. inventoryService.AddFolder(destinationFolder); // store base record
  1370. m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
  1371. }
  1372. // Wearables
  1373. AvatarWearable[] wearables = avatarAppearance.Wearables;
  1374. AvatarWearable wearable;
  1375. for (int i=0; i<wearables.Length; i++)
  1376. {
  1377. wearable = wearables[i];
  1378. if (wearable[0].ItemID != UUID.Zero)
  1379. {
  1380. // Get inventory item and copy it
  1381. InventoryItemBase item = new InventoryItemBase(wearable[0].ItemID, source);
  1382. item = inventoryService.GetItem(item);
  1383. if (item != null)
  1384. {
  1385. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  1386. destinationItem.Name = item.Name;
  1387. destinationItem.Owner = destination;
  1388. destinationItem.Description = item.Description;
  1389. destinationItem.InvType = item.InvType;
  1390. destinationItem.CreatorId = item.CreatorId;
  1391. destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
  1392. destinationItem.CreatorData = item.CreatorData;
  1393. destinationItem.NextPermissions = item.NextPermissions;
  1394. destinationItem.CurrentPermissions = item.CurrentPermissions;
  1395. destinationItem.BasePermissions = item.BasePermissions;
  1396. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  1397. destinationItem.GroupPermissions = item.GroupPermissions;
  1398. destinationItem.AssetType = item.AssetType;
  1399. destinationItem.AssetID = item.AssetID;
  1400. destinationItem.GroupID = item.GroupID;
  1401. destinationItem.GroupOwned = item.GroupOwned;
  1402. destinationItem.SalePrice = item.SalePrice;
  1403. destinationItem.SaleType = item.SaleType;
  1404. destinationItem.Flags = item.Flags;
  1405. destinationItem.CreationDate = item.CreationDate;
  1406. destinationItem.Folder = destinationFolder.ID;
  1407. ApplyNextOwnerPermissions(destinationItem);
  1408. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  1409. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
  1410. // Wear item
  1411. AvatarWearable newWearable = new AvatarWearable();
  1412. newWearable.Wear(destinationItem.ID, wearable[0].AssetID);
  1413. avatarAppearance.SetWearable(i, newWearable);
  1414. }
  1415. else
  1416. {
  1417. m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", wearable[0].ItemID, destinationFolder.ID);
  1418. }
  1419. }
  1420. }
  1421. // Attachments
  1422. List<AvatarAttachment> attachments = avatarAppearance.GetAttachments();
  1423. foreach (AvatarAttachment attachment in attachments)
  1424. {
  1425. int attachpoint = attachment.AttachPoint;
  1426. UUID itemID = attachment.ItemID;
  1427. if (itemID != UUID.Zero)
  1428. {
  1429. // Get inventory item and copy it
  1430. InventoryItemBase item = new InventoryItemBase(itemID, source);
  1431. item = inventoryService.GetItem(item);
  1432. if (item != null)
  1433. {
  1434. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  1435. destinationItem.Name = item.Name;
  1436. destinationItem.Owner = destination;
  1437. destinationItem.Description = item.Description;
  1438. destinationItem.InvType = item.InvType;
  1439. destinationItem.CreatorId = item.CreatorId;
  1440. destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
  1441. destinationItem.CreatorData = item.CreatorData;
  1442. destinationItem.NextPermissions = item.NextPermissions;
  1443. destinationItem.CurrentPermissions = item.CurrentPermissions;
  1444. destinationItem.BasePermissions = item.BasePermissions;
  1445. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  1446. destinationItem.GroupPermissions = item.GroupPermissions;
  1447. destinationItem.AssetType = item.AssetType;
  1448. destinationItem.AssetID = item.AssetID;
  1449. destinationItem.GroupID = item.GroupID;
  1450. destinationItem.GroupOwned = item.GroupOwned;
  1451. destinationItem.SalePrice = item.SalePrice;
  1452. destinationItem.SaleType = item.SaleType;
  1453. destinationItem.Flags = item.Flags;
  1454. destinationItem.CreationDate = item.CreationDate;
  1455. destinationItem.Folder = destinationFolder.ID;
  1456. ApplyNextOwnerPermissions(destinationItem);
  1457. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  1458. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, destinationFolder.ID);
  1459. // Attach item
  1460. avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
  1461. m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
  1462. }
  1463. else
  1464. {
  1465. m_log.WarnFormat("[RADMIN]: Error transferring {0} to folder {1}", itemID, destinationFolder.ID);
  1466. }
  1467. }
  1468. }
  1469. }
  1470. /// <summary>
  1471. /// This method is called by establishAppearance to copy inventory folders to make
  1472. /// copies of Clothing and Bodyparts inventory folders and attaches worn attachments
  1473. /// </summary>
  1474. private void CopyInventoryFolders(UUID destination, UUID source, AssetType assetType, Dictionary<UUID,UUID> inventoryMap,
  1475. AvatarAppearance avatarAppearance)
  1476. {
  1477. IInventoryService inventoryService = m_application.SceneManager.CurrentOrFirstScene.InventoryService;
  1478. InventoryFolderBase sourceFolder = inventoryService.GetFolderForType(source, assetType);
  1479. InventoryFolderBase destinationFolder = inventoryService.GetFolderForType(destination, assetType);
  1480. if (sourceFolder == null || destinationFolder == null)
  1481. throw new Exception("Cannot locate folder(s)");
  1482. // Missing source folder? This should *never* be the case
  1483. if (sourceFolder.Type != (short)assetType)
  1484. {
  1485. sourceFolder = new InventoryFolderBase();
  1486. sourceFolder.ID = UUID.Random();
  1487. if (assetType == AssetType.Clothing) {
  1488. sourceFolder.Name = "Clothing";
  1489. } else {
  1490. sourceFolder.Name = "Body Parts";
  1491. }
  1492. sourceFolder.Owner = source;
  1493. sourceFolder.Type = (short)assetType;
  1494. sourceFolder.ParentID = inventoryService.GetRootFolder(source).ID;
  1495. sourceFolder.Version = 1;
  1496. inventoryService.AddFolder(sourceFolder); // store base record
  1497. m_log.ErrorFormat("[RADMIN] Created folder for source {0}", source);
  1498. }
  1499. // Missing destination folder? This should *never* be the case
  1500. if (destinationFolder.Type != (short)assetType)
  1501. {
  1502. destinationFolder = new InventoryFolderBase();
  1503. destinationFolder.ID = UUID.Random();
  1504. if (assetType == AssetType.Clothing) {
  1505. destinationFolder.Name = "Clothing";
  1506. } else {
  1507. destinationFolder.Name = "Body Parts";
  1508. }
  1509. destinationFolder.Owner = destination;
  1510. destinationFolder.Type = (short)assetType;
  1511. destinationFolder.ParentID = inventoryService.GetRootFolder(destination).ID;
  1512. destinationFolder.Version = 1;
  1513. inventoryService.AddFolder(destinationFolder); // store base record
  1514. m_log.ErrorFormat("[RADMIN]: Created folder for destination {0}", source);
  1515. }
  1516. InventoryFolderBase extraFolder;
  1517. List<InventoryFolderBase> folders = inventoryService.GetFolderContent(source, sourceFolder.ID).Folders;
  1518. foreach (InventoryFolderBase folder in folders)
  1519. {
  1520. extraFolder = new InventoryFolderBase();
  1521. extraFolder.ID = UUID.Random();
  1522. extraFolder.Name = folder.Name;
  1523. extraFolder.Owner = destination;
  1524. extraFolder.Type = folder.Type;
  1525. extraFolder.Version = folder.Version;
  1526. extraFolder.ParentID = destinationFolder.ID;
  1527. inventoryService.AddFolder(extraFolder);
  1528. m_log.DebugFormat("[RADMIN]: Added folder {0} to folder {1}", extraFolder.ID, sourceFolder.ID);
  1529. List<InventoryItemBase> items = inventoryService.GetFolderContent(source, folder.ID).Items;
  1530. foreach (InventoryItemBase item in items)
  1531. {
  1532. InventoryItemBase destinationItem = new InventoryItemBase(UUID.Random(), destination);
  1533. destinationItem.Name = item.Name;
  1534. destinationItem.Owner = destination;
  1535. destinationItem.Description = item.Description;
  1536. destinationItem.InvType = item.InvType;
  1537. destinationItem.CreatorId = item.CreatorId;
  1538. destinationItem.CreatorIdAsUuid = item.CreatorIdAsUuid;
  1539. destinationItem.CreatorData = item.CreatorData;
  1540. destinationItem.NextPermissions = item.NextPermissions;
  1541. destinationItem.CurrentPermissions = item.CurrentPermissions;
  1542. destinationItem.BasePermissions = item.BasePermissions;
  1543. destinationItem.EveryOnePermissions = item.EveryOnePermissions;
  1544. destinationItem.GroupPermissions = item.GroupPermissions;
  1545. destinationItem.AssetType = item.AssetType;
  1546. destinationItem.AssetID = item.AssetID;
  1547. destinationItem.GroupID = item.GroupID;
  1548. destinationItem.GroupOwned = item.GroupOwned;
  1549. destinationItem.SalePrice = item.SalePrice;
  1550. destinationItem.SaleType = item.SaleType;
  1551. destinationItem.Flags = item.Flags;
  1552. destinationItem.CreationDate = item.CreationDate;
  1553. destinationItem.Folder = extraFolder.ID;
  1554. ApplyNextOwnerPermissions(destinationItem);
  1555. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(destinationItem);
  1556. inventoryMap.Add(item.ID, destinationItem.ID);
  1557. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", destinationItem.ID, extraFolder.ID);
  1558. // Attach item, if original is attached
  1559. int attachpoint = avatarAppearance.GetAttachpoint(item.ID);
  1560. if (attachpoint != 0)
  1561. {
  1562. avatarAppearance.SetAttachment(attachpoint, destinationItem.ID, destinationItem.AssetID);
  1563. m_log.DebugFormat("[RADMIN]: Attached {0}", destinationItem.ID);
  1564. }
  1565. }
  1566. }
  1567. }
  1568. /// <summary>
  1569. /// Apply next owner permissions.
  1570. /// </summary>
  1571. private void ApplyNextOwnerPermissions(InventoryItemBase item)
  1572. {
  1573. if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0)
  1574. {
  1575. if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0)
  1576. item.CurrentPermissions &= ~(uint)PermissionMask.Copy;
  1577. if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0)
  1578. item.CurrentPermissions &= ~(uint)PermissionMask.Transfer;
  1579. if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0)
  1580. item.CurrentPermissions &= ~(uint)PermissionMask.Modify;
  1581. }
  1582. item.CurrentPermissions &= item.NextPermissions;
  1583. item.BasePermissions &= item.NextPermissions;
  1584. item.EveryOnePermissions &= item.NextPermissions;
  1585. // item.OwnerChanged = true;
  1586. // item.PermsMask = 0;
  1587. // item.PermsGranter = UUID.Zero;
  1588. }
  1589. /// <summary>
  1590. /// This method is called if a given model avatar name can not be found. If the external
  1591. /// file has already been loaded once, then control returns immediately. If not, then it
  1592. /// looks for a default appearance file. This file contains XML definitions of zero or more named
  1593. /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection
  1594. /// of items that together, define a particular ensemble for the avatar. Each avatar should
  1595. /// indicate which outfit is the default, and this outfit will be automatically worn. The
  1596. /// other outfits are provided to allow "real" avatars a way to easily change their outfits.
  1597. /// </summary>
  1598. private bool CreateDefaultAvatars()
  1599. {
  1600. // Only load once
  1601. if (m_defaultAvatarsLoaded)
  1602. {
  1603. return false;
  1604. }
  1605. m_log.DebugFormat("[RADMIN]: Creating default avatar entries");
  1606. m_defaultAvatarsLoaded = true;
  1607. // Load processing starts here...
  1608. try
  1609. {
  1610. string defaultAppearanceFileName = null;
  1611. //m_config may be null if RemoteAdmin configuration secition is missing or disabled in OpenSim.ini
  1612. if (m_config != null)
  1613. {
  1614. defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml");
  1615. }
  1616. if (File.Exists(defaultAppearanceFileName))
  1617. {
  1618. XmlDocument doc = new XmlDocument();
  1619. string name = "*unknown*";
  1620. string email = "anon@anon";
  1621. uint regionXLocation = 1000;
  1622. uint regionYLocation = 1000;
  1623. string password = UUID.Random().ToString(); // No requirement to sign-in.
  1624. UUID ID = UUID.Zero;
  1625. AvatarAppearance avatarAppearance;
  1626. XmlNodeList avatars;
  1627. XmlNodeList assets;
  1628. XmlNode perms = null;
  1629. bool include = false;
  1630. bool select = false;
  1631. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  1632. IInventoryService inventoryService = scene.InventoryService;
  1633. IAssetService assetService = scene.AssetService;
  1634. doc.LoadXml(File.ReadAllText(defaultAppearanceFileName));
  1635. // Load up any included assets. Duplicates will be ignored
  1636. assets = doc.GetElementsByTagName("RequiredAsset");
  1637. foreach (XmlNode assetNode in assets)
  1638. {
  1639. AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""), SByte.Parse(GetStringAttribute(assetNode, "type", "")), UUID.Zero.ToString());
  1640. asset.Description = GetStringAttribute(assetNode,"desc","");
  1641. asset.Local = Boolean.Parse(GetStringAttribute(assetNode,"local",""));
  1642. asset.Temporary = Boolean.Parse(GetStringAttribute(assetNode,"temporary",""));
  1643. asset.Data = Convert.FromBase64String(assetNode.InnerText);
  1644. assetService.Store(asset);
  1645. }
  1646. avatars = doc.GetElementsByTagName("Avatar");
  1647. // The document may contain multiple avatars
  1648. foreach (XmlElement avatar in avatars)
  1649. {
  1650. m_log.DebugFormat("[RADMIN]: Loading appearance for {0}, gender = {1}",
  1651. GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?"));
  1652. // Create the user identified by the avatar entry
  1653. try
  1654. {
  1655. // Only the name value is mandatory
  1656. name = GetStringAttribute(avatar,"name",name);
  1657. email = GetStringAttribute(avatar,"email",email);
  1658. regionXLocation = GetUnsignedAttribute(avatar,"regx",regionXLocation);
  1659. regionYLocation = GetUnsignedAttribute(avatar,"regy",regionYLocation);
  1660. password = GetStringAttribute(avatar,"password",password);
  1661. string[] names = name.Split();
  1662. UUID scopeID = scene.RegionInfo.ScopeID;
  1663. UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]);
  1664. if (null == account)
  1665. {
  1666. account = CreateUser(scopeID, names[0], names[1], password, email);
  1667. if (null == account)
  1668. {
  1669. m_log.ErrorFormat("[RADMIN]: Avatar {0} {1} was not created", names[0], names[1]);
  1670. return false;
  1671. }
  1672. }
  1673. // Set home position
  1674. GridRegion home = scene.GridService.GetRegionByPosition(scopeID,
  1675. (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
  1676. if (null == home) {
  1677. m_log.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]);
  1678. } else {
  1679. scene.GridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  1680. m_log.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]);
  1681. }
  1682. ID = account.PrincipalID;
  1683. m_log.DebugFormat("[RADMIN]: User {0}[{1}] created or retrieved", name, ID);
  1684. include = true;
  1685. }
  1686. catch (Exception e)
  1687. {
  1688. m_log.DebugFormat("[RADMIN]: Error creating user {0} : {1}", name, e.Message);
  1689. include = false;
  1690. }
  1691. // OK, User has been created OK, now we can install the inventory.
  1692. // First retrieve the current inventory (the user may already exist)
  1693. // Note that althought he inventory is retrieved, the hierarchy has
  1694. // not been interpreted at all.
  1695. if (include)
  1696. {
  1697. // Setup for appearance processing
  1698. avatarAppearance = scene.AvatarService.GetAppearance(ID);
  1699. if (avatarAppearance == null)
  1700. avatarAppearance = new AvatarAppearance();
  1701. AvatarWearable[] wearables = avatarAppearance.Wearables;
  1702. for (int i=0; i<wearables.Length; i++)
  1703. {
  1704. wearables[i] = new AvatarWearable();
  1705. }
  1706. try
  1707. {
  1708. // m_log.DebugFormat("[RADMIN] {0} folders, {1} items in inventory",
  1709. // uic.folders.Count, uic.items.Count);
  1710. InventoryFolderBase clothingFolder = inventoryService.GetFolderForType(ID, AssetType.Clothing);
  1711. // This should *never* be the case
  1712. if (clothingFolder == null || clothingFolder.Type != (short)AssetType.Clothing)
  1713. {
  1714. clothingFolder = new InventoryFolderBase();
  1715. clothingFolder.ID = UUID.Random();
  1716. clothingFolder.Name = "Clothing";
  1717. clothingFolder.Owner = ID;
  1718. clothingFolder.Type = (short)AssetType.Clothing;
  1719. clothingFolder.ParentID = inventoryService.GetRootFolder(ID).ID;
  1720. clothingFolder.Version = 1;
  1721. inventoryService.AddFolder(clothingFolder); // store base record
  1722. m_log.ErrorFormat("[RADMIN]: Created clothing folder for {0}/{1}", name, ID);
  1723. }
  1724. // OK, now we have an inventory for the user, read in the outfits from the
  1725. // default appearance XMl file.
  1726. XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble");
  1727. InventoryFolderBase extraFolder;
  1728. string outfitName;
  1729. UUID assetid;
  1730. foreach (XmlElement outfit in outfits)
  1731. {
  1732. m_log.DebugFormat("[RADMIN]: Loading outfit {0} for {1}",
  1733. GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?"));
  1734. outfitName = GetStringAttribute(outfit,"name","");
  1735. select = (GetStringAttribute(outfit,"default","no") == "yes");
  1736. // If the folder already exists, re-use it. The defaults may
  1737. // change over time. Augment only.
  1738. List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders;
  1739. extraFolder = null;
  1740. foreach (InventoryFolderBase folder in folders)
  1741. {
  1742. if (folder.Name == outfitName)
  1743. {
  1744. extraFolder = folder;
  1745. break;
  1746. }
  1747. }
  1748. // Otherwise, we must create the folder.
  1749. if (extraFolder == null)
  1750. {
  1751. m_log.DebugFormat("[RADMIN]: Creating outfit folder {0} for {1}", outfitName, name);
  1752. extraFolder = new InventoryFolderBase();
  1753. extraFolder.ID = UUID.Random();
  1754. extraFolder.Name = outfitName;
  1755. extraFolder.Owner = ID;
  1756. extraFolder.Type = (short)AssetType.Clothing;
  1757. extraFolder.Version = 1;
  1758. extraFolder.ParentID = clothingFolder.ID;
  1759. inventoryService.AddFolder(extraFolder);
  1760. m_log.DebugFormat("[RADMIN]: Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID);
  1761. }
  1762. // Now get the pieces that make up the outfit
  1763. XmlNodeList items = outfit.GetElementsByTagName("Item");
  1764. foreach (XmlElement item in items)
  1765. {
  1766. assetid = UUID.Zero;
  1767. XmlNodeList children = item.ChildNodes;
  1768. foreach (XmlNode child in children)
  1769. {
  1770. switch (child.Name)
  1771. {
  1772. case "Permissions" :
  1773. m_log.DebugFormat("[RADMIN]: Permissions specified");
  1774. perms = child;
  1775. break;
  1776. case "Asset" :
  1777. assetid = new UUID(child.InnerText);
  1778. break;
  1779. }
  1780. }
  1781. InventoryItemBase inventoryItem = null;
  1782. // Check if asset is in inventory already
  1783. inventoryItem = null;
  1784. List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items;
  1785. foreach (InventoryItemBase listItem in inventoryItems)
  1786. {
  1787. if (listItem.AssetID == assetid)
  1788. {
  1789. inventoryItem = listItem;
  1790. break;
  1791. }
  1792. }
  1793. // Create inventory item
  1794. if (inventoryItem == null)
  1795. {
  1796. inventoryItem = new InventoryItemBase(UUID.Random(), ID);
  1797. inventoryItem.Name = GetStringAttribute(item,"name","");
  1798. inventoryItem.Description = GetStringAttribute(item,"desc","");
  1799. inventoryItem.InvType = GetIntegerAttribute(item,"invtype",-1);
  1800. inventoryItem.CreatorId = GetStringAttribute(item,"creatorid","");
  1801. inventoryItem.CreatorIdAsUuid = (UUID)GetStringAttribute(item,"creatoruuid","");
  1802. inventoryItem.CreatorData = GetStringAttribute(item, "creatordata", "");
  1803. inventoryItem.NextPermissions = GetUnsignedAttribute(perms, "next", 0x7fffffff);
  1804. inventoryItem.CurrentPermissions = GetUnsignedAttribute(perms,"current",0x7fffffff);
  1805. inventoryItem.BasePermissions = GetUnsignedAttribute(perms,"base",0x7fffffff);
  1806. inventoryItem.EveryOnePermissions = GetUnsignedAttribute(perms,"everyone",0x7fffffff);
  1807. inventoryItem.GroupPermissions = GetUnsignedAttribute(perms,"group",0x7fffffff);
  1808. inventoryItem.AssetType = GetIntegerAttribute(item,"assettype",-1);
  1809. inventoryItem.AssetID = assetid; // associated asset
  1810. inventoryItem.GroupID = (UUID)GetStringAttribute(item,"groupid","");
  1811. inventoryItem.GroupOwned = (GetStringAttribute(item,"groupowned","false") == "true");
  1812. inventoryItem.SalePrice = GetIntegerAttribute(item,"saleprice",0);
  1813. inventoryItem.SaleType = (byte)GetIntegerAttribute(item,"saletype",0);
  1814. inventoryItem.Flags = GetUnsignedAttribute(item,"flags",0);
  1815. inventoryItem.CreationDate = GetIntegerAttribute(item,"creationdate",Util.UnixTimeSinceEpoch());
  1816. inventoryItem.Folder = extraFolder.ID; // Parent folder
  1817. m_application.SceneManager.CurrentOrFirstScene.AddInventoryItem(inventoryItem);
  1818. m_log.DebugFormat("[RADMIN]: Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID);
  1819. }
  1820. // Attach item, if attachpoint is specified
  1821. int attachpoint = GetIntegerAttribute(item,"attachpoint",0);
  1822. if (attachpoint != 0)
  1823. {
  1824. avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID);
  1825. m_log.DebugFormat("[RADMIN]: Attached {0}", inventoryItem.ID);
  1826. }
  1827. // Record whether or not the item is to be initially worn
  1828. try
  1829. {
  1830. if (select && (GetStringAttribute(item, "wear", "false") == "true"))
  1831. {
  1832. avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID);
  1833. }
  1834. }
  1835. catch (Exception e)
  1836. {
  1837. m_log.WarnFormat("[RADMIN]: Error wearing item {0} : {1}", inventoryItem.ID, e.Message);
  1838. }
  1839. } // foreach item in outfit
  1840. m_log.DebugFormat("[RADMIN]: Outfit {0} load completed", outfitName);
  1841. } // foreach outfit
  1842. m_log.DebugFormat("[RADMIN]: Inventory update complete for {0}", name);
  1843. scene.AvatarService.SetAppearance(ID, avatarAppearance);
  1844. }
  1845. catch (Exception e)
  1846. {
  1847. m_log.WarnFormat("[RADMIN]: Inventory processing incomplete for user {0} : {1}",
  1848. name, e.Message);
  1849. }
  1850. } // End of include
  1851. }
  1852. m_log.DebugFormat("[RADMIN]: Default avatar loading complete");
  1853. }
  1854. else
  1855. {
  1856. m_log.DebugFormat("[RADMIN]: No default avatar information available");
  1857. return false;
  1858. }
  1859. }
  1860. catch (Exception e)
  1861. {
  1862. m_log.WarnFormat("[RADMIN]: Exception whilst loading default avatars ; {0}", e.Message);
  1863. return false;
  1864. }
  1865. return true;
  1866. }
  1867. /// <summary>
  1868. /// Load an OAR file into a region..
  1869. /// <summary>
  1870. /// <param name="request">incoming XML RPC request</param>
  1871. /// <remarks>
  1872. /// XmlRpcLoadOARMethod takes the following XMLRPC
  1873. /// parameters
  1874. /// <list type="table">
  1875. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1876. /// <item><term>password</term>
  1877. /// <description>admin password as set in OpenSim.ini</description></item>
  1878. /// <item><term>filename</term>
  1879. /// <description>file name of the OAR file</description></item>
  1880. /// <item><term>region_uuid</term>
  1881. /// <description>UUID of the region</description></item>
  1882. /// <item><term>region_name</term>
  1883. /// <description>region name</description></item>
  1884. /// <item><term>merge</term>
  1885. /// <description>true if oar should be merged</description></item>
  1886. /// <item><term>skip-assets</term>
  1887. /// <description>true if assets should be skiped</description></item>
  1888. /// </list>
  1889. ///
  1890. /// <code>region_uuid</code> takes precedence over
  1891. /// <code>region_name</code> if both are present; one of both
  1892. /// must be present.
  1893. ///
  1894. /// XmlRpcLoadOARMethod returns
  1895. /// <list type="table">
  1896. /// <listheader><term>name</term><description>description</description></listheader>
  1897. /// <item><term>success</term>
  1898. /// <description>true or false</description></item>
  1899. /// <item><term>error</term>
  1900. /// <description>error message if success is false</description></item>
  1901. /// </list>
  1902. /// </remarks>
  1903. public XmlRpcResponse XmlRpcLoadOARMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  1904. {
  1905. m_log.Info("[RADMIN]: Received Load OAR Administrator Request");
  1906. FailIfRemoteAdminDisabled("Load OAR");
  1907. XmlRpcResponse response = new XmlRpcResponse();
  1908. Hashtable responseData = new Hashtable();
  1909. lock (m_requestLock)
  1910. {
  1911. try
  1912. {
  1913. Hashtable requestData = (Hashtable) request.Params[0];
  1914. // check completeness
  1915. foreach (string parameter in new string[] {"password", "filename"})
  1916. {
  1917. if (!requestData.Contains(parameter))
  1918. throw new Exception(String.Format("missing parameter {0}", parameter));
  1919. if (String.IsNullOrEmpty((string) requestData[parameter]))
  1920. throw new Exception(String.Format("parameter {0} is empty", parameter));
  1921. }
  1922. // check password
  1923. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  1924. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  1925. string filename = (string) requestData["filename"];
  1926. Scene scene = null;
  1927. if (requestData.Contains("region_uuid"))
  1928. {
  1929. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  1930. if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
  1931. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  1932. }
  1933. else if (requestData.Contains("region_name"))
  1934. {
  1935. string region_name = (string) requestData["region_name"];
  1936. if (!m_application.SceneManager.TryGetScene(region_name, out scene))
  1937. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  1938. }
  1939. else throw new Exception("neither region_name nor region_uuid given");
  1940. bool mergeOar = false;
  1941. bool skipAssets = false;
  1942. if ((string)requestData["merge"] == "true")
  1943. {
  1944. mergeOar = true;
  1945. }
  1946. if ((string)requestData["skip-assets"] == "true")
  1947. {
  1948. skipAssets = true;
  1949. }
  1950. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  1951. if (archiver != null)
  1952. archiver.DearchiveRegion(filename, mergeOar, skipAssets, Guid.Empty);
  1953. else
  1954. throw new Exception("Archiver module not present for scene");
  1955. responseData["loaded"] = true;
  1956. response.Value = responseData;
  1957. }
  1958. catch (Exception e)
  1959. {
  1960. m_log.ErrorFormat("[RADMIN]: LoadOAR: {0} {1}", e.Message, e.StackTrace);
  1961. responseData["loaded"] = false;
  1962. responseData["error"] = e.Message;
  1963. response.Value = responseData;
  1964. }
  1965. m_log.Info("[RADMIN]: Load OAR Administrator Request complete");
  1966. return response;
  1967. }
  1968. }
  1969. /// <summary>
  1970. /// Save a region to an OAR file
  1971. /// <summary>
  1972. /// <param name="request">incoming XML RPC request</param>
  1973. /// <remarks>
  1974. /// XmlRpcSaveOARMethod takes the following XMLRPC
  1975. /// parameters
  1976. /// <list type="table">
  1977. /// <listheader><term>parameter name</term><description>description</description></listheader>
  1978. /// <item><term>password</term>
  1979. /// <description>admin password as set in OpenSim.ini</description></item>
  1980. /// <item><term>filename</term>
  1981. /// <description>file name for the OAR file</description></item>
  1982. /// <item><term>region_uuid</term>
  1983. /// <description>UUID of the region</description></item>
  1984. /// <item><term>region_name</term>
  1985. /// <description>region name</description></item>
  1986. /// <item><term>profile</term>
  1987. /// <description>profile url</description></item>
  1988. /// <item><term>noassets</term>
  1989. /// <description>true if no assets should be saved</description></item>
  1990. /// </list>
  1991. ///
  1992. /// <code>region_uuid</code> takes precedence over
  1993. /// <code>region_name</code> if both are present; one of both
  1994. /// must be present.
  1995. ///
  1996. /// XmlRpcLoadOARMethod returns
  1997. /// <list type="table">
  1998. /// <listheader><term>name</term><description>description</description></listheader>
  1999. /// <item><term>success</term>
  2000. /// <description>true or false</description></item>
  2001. /// <item><term>error</term>
  2002. /// <description>error message if success is false</description></item>
  2003. /// </list>
  2004. /// </remarks>
  2005. public XmlRpcResponse XmlRpcSaveOARMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  2006. {
  2007. m_log.Info("[RADMIN]: Received Save OAR Administrator Request");
  2008. FailIfRemoteAdminDisabled("Save OAR");
  2009. XmlRpcResponse response = new XmlRpcResponse();
  2010. Hashtable responseData = new Hashtable();
  2011. try
  2012. {
  2013. Hashtable requestData = (Hashtable) request.Params[0];
  2014. // check completeness
  2015. foreach (string p in new string[] {"password", "filename"})
  2016. {
  2017. if (!requestData.Contains(p))
  2018. throw new Exception(String.Format("missing parameter {0}", p));
  2019. if (String.IsNullOrEmpty((string) requestData[p]))
  2020. throw new Exception(String.Format("parameter {0} is empty"));
  2021. }
  2022. // check password
  2023. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2024. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2025. string filename = (string) requestData["filename"];
  2026. Scene scene = null;
  2027. if (requestData.Contains("region_uuid"))
  2028. {
  2029. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2030. if (!m_application.SceneManager.TryGetScene(region_uuid, out scene))
  2031. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2032. }
  2033. else if (requestData.Contains("region_name"))
  2034. {
  2035. string region_name = (string) requestData["region_name"];
  2036. if (!m_application.SceneManager.TryGetScene(region_name, out scene))
  2037. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2038. }
  2039. else throw new Exception("neither region_name nor region_uuid given");
  2040. Dictionary<string, object> options = new Dictionary<string, object>();
  2041. //if (requestData.Contains("version"))
  2042. //{
  2043. // options["version"] = (string)requestData["version"];
  2044. //}
  2045. if (requestData.Contains("profile"))
  2046. {
  2047. options["profile"] = (string)requestData["profile"];
  2048. }
  2049. if (requestData["noassets"] == "true")
  2050. {
  2051. options["noassets"] = (string)requestData["noassets"] ;
  2052. }
  2053. IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
  2054. if (archiver != null)
  2055. {
  2056. scene.EventManager.OnOarFileSaved += RemoteAdminOarSaveCompleted;
  2057. archiver.ArchiveRegion(filename, options);
  2058. lock (m_saveOarLock) Monitor.Wait(m_saveOarLock,5000);
  2059. scene.EventManager.OnOarFileSaved -= RemoteAdminOarSaveCompleted;
  2060. }
  2061. else
  2062. throw new Exception("Archiver module not present for scene");
  2063. responseData["saved"] = true;
  2064. response.Value = responseData;
  2065. }
  2066. catch (Exception e)
  2067. {
  2068. m_log.ErrorFormat("[RADMIN]: SaveOAR: {0} {1}", e.Message, e.StackTrace);
  2069. responseData["saved"] = false;
  2070. responseData["error"] = e.Message;
  2071. response.Value = responseData;
  2072. }
  2073. m_log.Info("[RADMIN]: Save OAR Administrator Request complete");
  2074. return response;
  2075. }
  2076. private void RemoteAdminOarSaveCompleted(Guid uuid, string name)
  2077. {
  2078. m_log.DebugFormat("[RADMIN]: File processing complete for {0}", name);
  2079. lock (m_saveOarLock) Monitor.Pulse(m_saveOarLock);
  2080. }
  2081. public XmlRpcResponse XmlRpcLoadXMLMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  2082. {
  2083. m_log.Info("[RADMIN]: Received Load XML Administrator Request");
  2084. FailIfRemoteAdminDisabled("Load XML");
  2085. XmlRpcResponse response = new XmlRpcResponse();
  2086. Hashtable responseData = new Hashtable();
  2087. lock (m_requestLock)
  2088. {
  2089. try
  2090. {
  2091. Hashtable requestData = (Hashtable) request.Params[0];
  2092. // check completeness
  2093. foreach (string p in new string[] {"password", "filename"})
  2094. {
  2095. if (!requestData.Contains(p))
  2096. throw new Exception(String.Format("missing parameter {0}", p));
  2097. if (String.IsNullOrEmpty((string) requestData[p]))
  2098. throw new Exception(String.Format("parameter {0} is empty"));
  2099. }
  2100. // check password
  2101. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2102. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2103. string filename = (string) requestData["filename"];
  2104. if (requestData.Contains("region_uuid"))
  2105. {
  2106. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2107. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2108. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2109. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2110. }
  2111. else if (requestData.Contains("region_name"))
  2112. {
  2113. string region_name = (string) requestData["region_name"];
  2114. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2115. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2116. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2117. }
  2118. else throw new Exception("neither region_name nor region_uuid given");
  2119. responseData["switched"] = true;
  2120. string xml_version = "1";
  2121. if (requestData.Contains("xml_version"))
  2122. {
  2123. xml_version = (string) requestData["xml_version"];
  2124. }
  2125. switch (xml_version)
  2126. {
  2127. case "1":
  2128. m_application.SceneManager.LoadCurrentSceneFromXml(filename, true, new Vector3(0, 0, 0));
  2129. break;
  2130. case "2":
  2131. m_application.SceneManager.LoadCurrentSceneFromXml2(filename);
  2132. break;
  2133. default:
  2134. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  2135. }
  2136. responseData["loaded"] = true;
  2137. response.Value = responseData;
  2138. }
  2139. catch (Exception e)
  2140. {
  2141. m_log.ErrorFormat("[RADMIN] LoadXml: {0} {1}", e.Message, e.StackTrace);
  2142. responseData["loaded"] = false;
  2143. responseData["switched"] = false;
  2144. responseData["error"] = e.Message;
  2145. response.Value = responseData;
  2146. }
  2147. m_log.Info("[RADMIN]: Load XML Administrator Request complete");
  2148. return response;
  2149. }
  2150. }
  2151. public XmlRpcResponse XmlRpcSaveXMLMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  2152. {
  2153. m_log.Info("[RADMIN]: Received Save XML Administrator Request");
  2154. FailIfRemoteAdminDisabled("Save XML");
  2155. XmlRpcResponse response = new XmlRpcResponse();
  2156. Hashtable responseData = new Hashtable();
  2157. try
  2158. {
  2159. Hashtable requestData = (Hashtable) request.Params[0];
  2160. // check completeness
  2161. foreach (string p in new string[] {"password", "filename"})
  2162. {
  2163. if (!requestData.Contains(p))
  2164. throw new Exception(String.Format("missing parameter {0}", p));
  2165. if (String.IsNullOrEmpty((string) requestData[p]))
  2166. throw new Exception(String.Format("parameter {0} is empty"));
  2167. }
  2168. // check password
  2169. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2170. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2171. string filename = (string) requestData["filename"];
  2172. if (requestData.Contains("region_uuid"))
  2173. {
  2174. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2175. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2176. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2177. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2178. }
  2179. else if (requestData.Contains("region_name"))
  2180. {
  2181. string region_name = (string) requestData["region_name"];
  2182. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2183. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2184. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2185. }
  2186. else throw new Exception("neither region_name nor region_uuid given");
  2187. responseData["switched"] = true;
  2188. string xml_version = "1";
  2189. if (requestData.Contains("xml_version"))
  2190. {
  2191. xml_version = (string) requestData["xml_version"];
  2192. }
  2193. switch (xml_version)
  2194. {
  2195. case "1":
  2196. m_application.SceneManager.SaveCurrentSceneToXml(filename);
  2197. break;
  2198. case "2":
  2199. m_application.SceneManager.SaveCurrentSceneToXml2(filename);
  2200. break;
  2201. default:
  2202. throw new Exception(String.Format("unknown Xml{0} format", xml_version));
  2203. }
  2204. responseData["saved"] = true;
  2205. response.Value = responseData;
  2206. }
  2207. catch (Exception e)
  2208. {
  2209. m_log.ErrorFormat("[RADMIN]: SaveXml: {0} {1}", e.Message, e.StackTrace);
  2210. responseData["saved"] = false;
  2211. responseData["switched"] = false;
  2212. responseData["error"] = e.Message;
  2213. response.Value = responseData;
  2214. }
  2215. m_log.Info("[RADMIN]: Save XML Administrator Request complete");
  2216. return response;
  2217. }
  2218. public XmlRpcResponse XmlRpcRegionQueryMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  2219. {
  2220. m_log.Info("[RADMIN]: Received Query XML Administrator Request");
  2221. FailIfRemoteAdminDisabled("Query XML");
  2222. XmlRpcResponse response = new XmlRpcResponse();
  2223. Hashtable responseData = new Hashtable();
  2224. try
  2225. {
  2226. responseData["success"] = true;
  2227. Hashtable requestData = (Hashtable) request.Params[0];
  2228. // check completeness
  2229. if (!requestData.Contains("password"))
  2230. throw new Exception(String.Format("missing required parameter"));
  2231. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2232. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2233. if (requestData.Contains("region_uuid"))
  2234. {
  2235. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2236. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2237. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2238. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2239. }
  2240. else if (requestData.Contains("region_name"))
  2241. {
  2242. string region_name = (string) requestData["region_name"];
  2243. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2244. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2245. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2246. }
  2247. else throw new Exception("neither region_name nor region_uuid given");
  2248. Scene scene = m_application.SceneManager.CurrentScene;
  2249. int health = scene.GetHealth();
  2250. responseData["health"] = health;
  2251. response.Value = responseData;
  2252. }
  2253. catch (Exception e)
  2254. {
  2255. m_log.InfoFormat("[RADMIN]: RegionQuery: {0}", e.Message);
  2256. responseData["success"] = false;
  2257. responseData["error"] = e.Message;
  2258. response.Value = responseData;
  2259. }
  2260. m_log.Info("[RADMIN]: Query XML Administrator Request complete");
  2261. return response;
  2262. }
  2263. public XmlRpcResponse XmlRpcConsoleCommandMethod(XmlRpcRequest request, IPEndPoint remoteClient)
  2264. {
  2265. m_log.Info("[RADMIN]: Received Command XML Administrator Request");
  2266. FailIfRemoteAdminDisabled("Command XML");
  2267. XmlRpcResponse response = new XmlRpcResponse();
  2268. Hashtable responseData = new Hashtable();
  2269. try
  2270. {
  2271. responseData["success"] = true;
  2272. Hashtable requestData = (Hashtable) request.Params[0];
  2273. // check completeness
  2274. if (!requestData.Contains("password"))
  2275. throw new Exception(String.Format("missing required parameter"));
  2276. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2277. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2278. if (!requestData.Contains("command"))
  2279. throw new Exception(String.Format("missing required parameter"));
  2280. MainConsole.Instance.RunCommand(requestData["command"].ToString());
  2281. response.Value = responseData;
  2282. }
  2283. catch (Exception e)
  2284. {
  2285. m_log.InfoFormat("[RADMIN]: ConsoleCommand: {0}", e.Message);
  2286. responseData["success"] = false;
  2287. responseData["error"] = e.Message;
  2288. response.Value = responseData;
  2289. }
  2290. m_log.Info("[RADMIN]: Command XML Administrator Request complete");
  2291. return response;
  2292. }
  2293. public XmlRpcResponse XmlRpcAccessListClear(XmlRpcRequest request, IPEndPoint remoteClient)
  2294. {
  2295. m_log.Info("[RADMIN]: Received Access List Clear Request");
  2296. FailIfRemoteAdminDisabled("Access List Clear");
  2297. XmlRpcResponse response = new XmlRpcResponse();
  2298. Hashtable responseData = new Hashtable();
  2299. try
  2300. {
  2301. responseData["success"] = true;
  2302. Hashtable requestData = (Hashtable) request.Params[0];
  2303. if (!requestData.Contains("password"))
  2304. throw new Exception(String.Format("missing required parameter"));
  2305. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2306. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2307. if (requestData.Contains("region_uuid"))
  2308. {
  2309. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2310. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2311. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2312. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2313. }
  2314. else if (requestData.Contains("region_name"))
  2315. {
  2316. string region_name = (string) requestData["region_name"];
  2317. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2318. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2319. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2320. }
  2321. else throw new Exception("neither region_name nor region_uuid given");
  2322. Scene scene = m_application.SceneManager.CurrentScene;
  2323. scene.RegionInfo.EstateSettings.EstateAccess = new UUID[]{};
  2324. if (scene.RegionInfo.Persistent)
  2325. scene.RegionInfo.EstateSettings.Save();
  2326. }
  2327. catch (Exception e)
  2328. {
  2329. m_log.ErrorFormat("[RADMIN]: Access List Clear Request: {0} {1}", e.Message, e.StackTrace);
  2330. responseData["success"] = false;
  2331. responseData["error"] = e.Message;
  2332. }
  2333. finally
  2334. {
  2335. response.Value = responseData;
  2336. }
  2337. m_log.Info("[RADMIN]: Access List Clear Request complete");
  2338. return response;
  2339. }
  2340. public XmlRpcResponse XmlRpcAccessListAdd(XmlRpcRequest request, IPEndPoint remoteClient)
  2341. {
  2342. m_log.Info("[RADMIN]: Received Access List Add Request");
  2343. FailIfRemoteAdminDisabled("Access List Add");
  2344. XmlRpcResponse response = new XmlRpcResponse();
  2345. Hashtable responseData = new Hashtable();
  2346. try
  2347. {
  2348. responseData["success"] = true;
  2349. Hashtable requestData = (Hashtable) request.Params[0];
  2350. if (!requestData.Contains("password"))
  2351. throw new Exception(String.Format("missing required parameter"));
  2352. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2353. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2354. if (requestData.Contains("region_uuid"))
  2355. {
  2356. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2357. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2358. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2359. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2360. }
  2361. else if (requestData.Contains("region_name"))
  2362. {
  2363. string region_name = (string) requestData["region_name"];
  2364. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2365. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2366. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2367. }
  2368. else throw new Exception("neither region_name nor region_uuid given");
  2369. int addedUsers = 0;
  2370. if (requestData.Contains("users"))
  2371. {
  2372. UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
  2373. IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
  2374. Scene scene = m_application.SceneManager.CurrentScene;
  2375. Hashtable users = (Hashtable) requestData["users"];
  2376. List<UUID> uuids = new List<UUID>();
  2377. foreach (string name in users.Values)
  2378. {
  2379. string[] parts = name.Split();
  2380. UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
  2381. if (account != null)
  2382. {
  2383. uuids.Add(account.PrincipalID);
  2384. m_log.DebugFormat("[RADMIN]: adding \"{0}\" to ACL for \"{1}\"", name, scene.RegionInfo.RegionName);
  2385. }
  2386. }
  2387. List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
  2388. foreach (UUID uuid in uuids)
  2389. {
  2390. if (!accessControlList.Contains(uuid))
  2391. {
  2392. accessControlList.Add(uuid);
  2393. addedUsers++;
  2394. }
  2395. }
  2396. scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
  2397. if (scene.RegionInfo.Persistent)
  2398. scene.RegionInfo.EstateSettings.Save();
  2399. }
  2400. responseData["added"] = addedUsers;
  2401. }
  2402. catch (Exception e)
  2403. {
  2404. m_log.ErrorFormat("[RADMIN]: Access List Add Request: {0} {1}", e.Message, e.StackTrace);
  2405. responseData["success"] = false;
  2406. responseData["error"] = e.Message;
  2407. }
  2408. finally
  2409. {
  2410. response.Value = responseData;
  2411. }
  2412. m_log.Info("[RADMIN]: Access List Add Request complete");
  2413. return response;
  2414. }
  2415. public XmlRpcResponse XmlRpcAccessListRemove(XmlRpcRequest request, IPEndPoint remoteClient)
  2416. {
  2417. m_log.Info("[RADMIN]: Received Access List Remove Request");
  2418. FailIfRemoteAdminDisabled("Access List Remove");
  2419. XmlRpcResponse response = new XmlRpcResponse();
  2420. Hashtable responseData = new Hashtable();
  2421. try
  2422. {
  2423. responseData["success"] = true;
  2424. Hashtable requestData = (Hashtable) request.Params[0];
  2425. if (!requestData.Contains("password"))
  2426. throw new Exception(String.Format("missing required parameter"));
  2427. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2428. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2429. if (requestData.Contains("region_uuid"))
  2430. {
  2431. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2432. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2433. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2434. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2435. }
  2436. else if (requestData.Contains("region_name"))
  2437. {
  2438. string region_name = (string) requestData["region_name"];
  2439. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2440. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2441. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2442. }
  2443. else throw new Exception("neither region_name nor region_uuid given");
  2444. int removedUsers = 0;
  2445. if (requestData.Contains("users"))
  2446. {
  2447. UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
  2448. IUserAccountService userService = m_application.SceneManager.CurrentOrFirstScene.UserAccountService;
  2449. //UserProfileCacheService ups = m_application.CommunicationsManager.UserProfileCacheService;
  2450. Scene scene = m_application.SceneManager.CurrentScene;
  2451. Hashtable users = (Hashtable) requestData["users"];
  2452. List<UUID> uuids = new List<UUID>();
  2453. foreach (string name in users.Values)
  2454. {
  2455. string[] parts = name.Split();
  2456. UserAccount account = userService.GetUserAccount(scopeID, parts[0], parts[1]);
  2457. if (account != null)
  2458. {
  2459. uuids.Add(account.PrincipalID);
  2460. }
  2461. }
  2462. List<UUID> accessControlList = new List<UUID>(scene.RegionInfo.EstateSettings.EstateAccess);
  2463. foreach (UUID uuid in uuids)
  2464. {
  2465. if (accessControlList.Contains(uuid))
  2466. {
  2467. accessControlList.Remove(uuid);
  2468. removedUsers++;
  2469. }
  2470. }
  2471. scene.RegionInfo.EstateSettings.EstateAccess = accessControlList.ToArray();
  2472. if (scene.RegionInfo.Persistent)
  2473. scene.RegionInfo.EstateSettings.Save();
  2474. }
  2475. responseData["removed"] = removedUsers;
  2476. }
  2477. catch (Exception e)
  2478. {
  2479. m_log.ErrorFormat("[RADMIN]: Access List Remove Request: {0} {1}", e.Message, e.StackTrace);
  2480. responseData["success"] = false;
  2481. responseData["error"] = e.Message;
  2482. }
  2483. finally
  2484. {
  2485. response.Value = responseData;
  2486. }
  2487. m_log.Info("[RADMIN]: Access List Remove Request complete");
  2488. return response;
  2489. }
  2490. public XmlRpcResponse XmlRpcAccessListList(XmlRpcRequest request, IPEndPoint remoteClient)
  2491. {
  2492. m_log.Info("[RADMIN]: Received Access List List Request");
  2493. FailIfRemoteAdminDisabled("Access List List");
  2494. XmlRpcResponse response = new XmlRpcResponse();
  2495. Hashtable responseData = new Hashtable();
  2496. try
  2497. {
  2498. responseData["success"] = true;
  2499. Hashtable requestData = (Hashtable) request.Params[0];
  2500. if (!requestData.Contains("password"))
  2501. throw new Exception(String.Format("missing required parameter"));
  2502. if (!String.IsNullOrEmpty(m_requiredPassword) &&
  2503. (string) requestData["password"] != m_requiredPassword) throw new Exception("wrong password");
  2504. if (requestData.Contains("region_uuid"))
  2505. {
  2506. UUID region_uuid = (UUID) (string) requestData["region_uuid"];
  2507. if (!m_application.SceneManager.TrySetCurrentScene(region_uuid))
  2508. throw new Exception(String.Format("failed to switch to region {0}", region_uuid.ToString()));
  2509. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_uuid.ToString());
  2510. }
  2511. else if (requestData.Contains("region_name"))
  2512. {
  2513. string region_name = (string) requestData["region_name"];
  2514. if (!m_application.SceneManager.TrySetCurrentScene(region_name))
  2515. throw new Exception(String.Format("failed to switch to region {0}", region_name));
  2516. m_log.InfoFormat("[RADMIN]: Switched to region {0}", region_name);
  2517. }
  2518. else throw new Exception("neither region_name nor region_uuid given");
  2519. Scene scene = m_application.SceneManager.CurrentScene;
  2520. UUID[] accessControlList = scene.RegionInfo.EstateSettings.EstateAccess;
  2521. Hashtable users = new Hashtable();
  2522. foreach (UUID user in accessControlList)
  2523. {
  2524. UUID scopeID = m_application.SceneManager.CurrentOrFirstScene.RegionInfo.ScopeID;
  2525. UserAccount account = m_application.SceneManager.CurrentOrFirstScene.UserAccountService.GetUserAccount(scopeID, user);
  2526. if (account != null)
  2527. {
  2528. users[user.ToString()] = account.FirstName + " " + account.LastName;
  2529. }
  2530. }
  2531. responseData["users"] = users;
  2532. }
  2533. catch (Exception e)
  2534. {
  2535. m_log.ErrorFormat("[RADMIN]: Access List List: {0} {1}", e.Message, e.StackTrace);
  2536. responseData["success"] = false;
  2537. responseData["error"] = e.Message;
  2538. }
  2539. finally
  2540. {
  2541. response.Value = responseData;
  2542. }
  2543. m_log.Info("[RADMIN]: Access List List Request complete");
  2544. return response;
  2545. }
  2546. private static void CheckStringParameters(XmlRpcRequest request, string[] param)
  2547. {
  2548. Hashtable requestData = (Hashtable) request.Params[0];
  2549. foreach (string parameter in param)
  2550. {
  2551. if (!requestData.Contains(parameter))
  2552. throw new Exception(String.Format("missing string parameter {0}", parameter));
  2553. if (String.IsNullOrEmpty((string) requestData[parameter]))
  2554. throw new Exception(String.Format("parameter {0} is empty", parameter));
  2555. }
  2556. }
  2557. private static void CheckIntegerParams(XmlRpcRequest request, string[] param)
  2558. {
  2559. Hashtable requestData = (Hashtable) request.Params[0];
  2560. foreach (string parameter in param)
  2561. {
  2562. if (!requestData.Contains(parameter))
  2563. throw new Exception(String.Format("missing integer parameter {0}", parameter));
  2564. }
  2565. }
  2566. private bool GetBoolean(Hashtable requestData, string tag, bool defaultValue)
  2567. {
  2568. // If an access value has been provided, apply it.
  2569. if (requestData.Contains(tag))
  2570. {
  2571. switch (((string)requestData[tag]).ToLower())
  2572. {
  2573. case "true" :
  2574. case "t" :
  2575. case "1" :
  2576. return true;
  2577. case "false" :
  2578. case "f" :
  2579. case "0" :
  2580. return false;
  2581. default :
  2582. return defaultValue;
  2583. }
  2584. }
  2585. else
  2586. return defaultValue;
  2587. }
  2588. private int GetIntegerAttribute(XmlNode node, string attribute, int defaultValue)
  2589. {
  2590. try { return Convert.ToInt32(node.Attributes[attribute].Value); } catch{}
  2591. return defaultValue;
  2592. }
  2593. private uint GetUnsignedAttribute(XmlNode node, string attribute, uint defaultValue)
  2594. {
  2595. try { return Convert.ToUInt32(node.Attributes[attribute].Value); } catch{}
  2596. return defaultValue;
  2597. }
  2598. private string GetStringAttribute(XmlNode node, string attribute, string defaultValue)
  2599. {
  2600. try { return node.Attributes[attribute].Value; } catch{}
  2601. return defaultValue;
  2602. }
  2603. public void Dispose()
  2604. {
  2605. }
  2606. /// <summary>
  2607. /// Create a user
  2608. /// </summary>
  2609. /// <param name="scopeID"></param>
  2610. /// <param name="firstName"></param>
  2611. /// <param name="lastName"></param>
  2612. /// <param name="password"></param>
  2613. /// <param name="email"></param>
  2614. private UserAccount CreateUser(UUID scopeID, string firstName, string lastName, string password, string email)
  2615. {
  2616. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2617. IUserAccountService userAccountService = scene.UserAccountService;
  2618. IGridService gridService = scene.GridService;
  2619. IAuthenticationService authenticationService = scene.AuthenticationService;
  2620. IGridUserService gridUserService = scene.GridUserService;
  2621. IInventoryService inventoryService = scene.InventoryService;
  2622. UserAccount account = userAccountService.GetUserAccount(scopeID, firstName, lastName);
  2623. if (null == account)
  2624. {
  2625. account = new UserAccount(scopeID, firstName, lastName, email);
  2626. if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0))
  2627. {
  2628. account.ServiceURLs = new Dictionary<string, object>();
  2629. account.ServiceURLs["HomeURI"] = string.Empty;
  2630. account.ServiceURLs["GatekeeperURI"] = string.Empty;
  2631. account.ServiceURLs["InventoryServerURI"] = string.Empty;
  2632. account.ServiceURLs["AssetServerURI"] = string.Empty;
  2633. }
  2634. if (userAccountService.StoreUserAccount(account))
  2635. {
  2636. bool success;
  2637. if (authenticationService != null)
  2638. {
  2639. success = authenticationService.SetPassword(account.PrincipalID, password);
  2640. if (!success)
  2641. m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
  2642. firstName, lastName);
  2643. }
  2644. GridRegion home = null;
  2645. if (gridService != null)
  2646. {
  2647. List<GridRegion> defaultRegions = gridService.GetDefaultRegions(UUID.Zero);
  2648. if (defaultRegions != null && defaultRegions.Count >= 1)
  2649. home = defaultRegions[0];
  2650. if (gridUserService != null && home != null)
  2651. gridUserService.SetHome(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
  2652. else
  2653. m_log.WarnFormat("[RADMIN]: Unable to set home for account {0} {1}.",
  2654. firstName, lastName);
  2655. }
  2656. else
  2657. m_log.WarnFormat("[RADMIN]: Unable to retrieve home region for account {0} {1}.",
  2658. firstName, lastName);
  2659. if (inventoryService != null)
  2660. {
  2661. success = inventoryService.CreateUserInventory(account.PrincipalID);
  2662. if (!success)
  2663. m_log.WarnFormat("[RADMIN]: Unable to create inventory for account {0} {1}.",
  2664. firstName, lastName);
  2665. }
  2666. m_log.InfoFormat("[RADMIN]: Account {0} {1} created successfully", firstName, lastName);
  2667. return account;
  2668. } else {
  2669. m_log.ErrorFormat("[RADMIN]: Account creation failed for account {0} {1}", firstName, lastName);
  2670. }
  2671. }
  2672. else
  2673. {
  2674. m_log.ErrorFormat("[RADMIN]: A user with the name {0} {1} already exists!", firstName, lastName);
  2675. }
  2676. return null;
  2677. }
  2678. /// <summary>
  2679. /// Change password
  2680. /// </summary>
  2681. /// <param name="firstName"></param>
  2682. /// <param name="lastName"></param>
  2683. /// <param name="password"></param>
  2684. private bool ChangeUserPassword(string firstName, string lastName, string password)
  2685. {
  2686. Scene scene = m_application.SceneManager.CurrentOrFirstScene;
  2687. IUserAccountService userAccountService = scene.UserAccountService;
  2688. IAuthenticationService authenticationService = scene.AuthenticationService;
  2689. UserAccount account = userAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
  2690. if (null != account)
  2691. {
  2692. bool success = false;
  2693. if (authenticationService != null)
  2694. success = authenticationService.SetPassword(account.PrincipalID, password);
  2695. if (!success) {
  2696. m_log.WarnFormat("[RADMIN]: Unable to set password for account {0} {1}.",
  2697. firstName, lastName);
  2698. return false;
  2699. }
  2700. return true;
  2701. }
  2702. else
  2703. {
  2704. m_log.ErrorFormat("[RADMIN]: No such user");
  2705. return false;
  2706. }
  2707. }
  2708. }
  2709. }