RemoteAdminPlugin.cs 148 KB

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