RemoteAdminPlugin.cs 157 KB

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