RemoteAdminPlugin.cs 149 KB

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