ArchiveReadRequest.cs 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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.Generic;
  29. using System.IO;
  30. using System.IO.Compression;
  31. using System.Net;
  32. using System.Reflection;
  33. using System.Text;
  34. using System.Xml;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Monitoring;
  39. using OpenSim.Framework.Serialization;
  40. using OpenSim.Framework.Serialization.External;
  41. using OpenSim.Region.CoreModules.World.Terrain;
  42. using OpenSim.Region.CoreModules.World.Land;
  43. using OpenSim.Region.Framework.Interfaces;
  44. using OpenSim.Region.Framework.Scenes;
  45. using OpenSim.Region.Framework.Scenes.Serialization;
  46. using OpenSim.Services.Interfaces;
  47. using System.Threading;
  48. namespace OpenSim.Region.CoreModules.World.Archiver
  49. {
  50. /// <summary>
  51. /// Handles an individual archive read request
  52. /// </summary>
  53. public class ArchiveReadRequest
  54. {
  55. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  56. /// <summary>
  57. /// Contains data used while dearchiving a single scene.
  58. /// </summary>
  59. private class DearchiveContext
  60. {
  61. public Scene Scene { get; set; }
  62. public List<string> SerialisedSceneObjects { get; set; }
  63. public List<string> SerialisedParcels { get; set; }
  64. public List<SceneObjectGroup> SceneObjects { get; set; }
  65. public DearchiveContext(Scene scene)
  66. {
  67. Scene = scene;
  68. SerialisedSceneObjects = new List<string>();
  69. SerialisedParcels = new List<string>();
  70. SceneObjects = new List<SceneObjectGroup>();
  71. }
  72. }
  73. /// <summary>
  74. /// The maximum major version of OAR that we can read. Minor versions shouldn't need a max number since version
  75. /// bumps here should be compatible.
  76. /// </summary>
  77. public static int MAX_MAJOR_VERSION = 1;
  78. /// <summary>
  79. /// Has the control file been loaded for this archive?
  80. /// </summary>
  81. public bool ControlFileLoaded { get; private set; }
  82. protected string m_loadPath;
  83. protected Scene m_rootScene;
  84. protected Stream m_loadStream;
  85. protected Guid m_requestId;
  86. protected string m_errorMessage;
  87. /// <value>
  88. /// Should the archive being loaded be merged with what is already on the region?
  89. /// Merging usually suppresses terrain and parcel loading
  90. /// </value>
  91. protected bool m_merge;
  92. /// <value>
  93. /// If true, force the loading of terrain from the oar file
  94. /// </value>
  95. protected bool m_forceTerrain;
  96. /// <value>
  97. /// If true, force the loading of parcels from the oar file
  98. /// </value>
  99. protected bool m_forceParcels;
  100. /// <value>
  101. /// Should we ignore any assets when reloading the archive?
  102. /// </value>
  103. protected bool m_skipAssets;
  104. /// <value>
  105. /// Displacement added to each object as it is added to the world
  106. /// </value>
  107. protected Vector3 m_displacement = Vector3.Zero;
  108. /// <value>
  109. /// Rotation (in radians) to apply to the objects as they are loaded.
  110. /// </value>
  111. protected float m_rotation = 0f;
  112. /// <value>
  113. /// original oar region size. not using Constants.RegionSize
  114. /// </value>
  115. protected Vector3 m_incomingRegionSize = new Vector3(256f, 256f, float.MaxValue);
  116. /// <value>
  117. /// Center around which to apply the rotation relative to the original oar position
  118. /// </value>
  119. protected Vector3 m_rotationCenter = new Vector3(128f, 128f, 0f);
  120. /// <value>
  121. /// Corner 1 of a bounding cuboid which specifies which objects we load from the oar
  122. /// </value>
  123. protected Vector3 m_boundingOrigin = Vector3.Zero;
  124. /// <value>
  125. /// Size of a bounding cuboid which specifies which objects we load from the oar
  126. /// </value>
  127. protected Vector3 m_boundingSize = new Vector3(Constants.MaximumRegionSize, Constants.MaximumRegionSize, float.MaxValue);
  128. protected bool m_noObjects = false;
  129. protected bool m_boundingBox = false;
  130. protected bool m_debug = false;
  131. /// <summary>
  132. /// Used to cache lookups for valid uuids.
  133. /// </summary>
  134. private IDictionary<UUID, bool> m_validUserUuids = new Dictionary<UUID, bool>();
  135. private IUserManagement m_UserMan;
  136. private IUserManagement UserManager
  137. {
  138. get
  139. {
  140. if (m_UserMan == null)
  141. {
  142. m_UserMan = m_rootScene.RequestModuleInterface<IUserManagement>();
  143. }
  144. return m_UserMan;
  145. }
  146. }
  147. /// <summary>
  148. /// Used to cache lookups for valid groups.
  149. /// </summary>
  150. private IDictionary<UUID, bool> m_validGroupUuids = new Dictionary<UUID, bool>();
  151. private IGroupsModule m_groupsModule;
  152. private IAssetService m_assetService = null;
  153. private UUID m_defaultUser;
  154. public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string, object> options)
  155. {
  156. m_rootScene = scene;
  157. if (options.ContainsKey("default-user"))
  158. {
  159. m_defaultUser = (UUID)options["default-user"];
  160. m_log.InfoFormat("Using User {0} as default user", m_defaultUser.ToString());
  161. }
  162. else
  163. {
  164. m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
  165. }
  166. m_loadPath = loadPath;
  167. try
  168. {
  169. m_loadStream = new GZipStream(ArchiveHelpers.GetStream(loadPath), CompressionMode.Decompress);
  170. }
  171. catch (EntryPointNotFoundException e)
  172. {
  173. m_log.ErrorFormat(
  174. "[ARCHIVER]: Mismatch between Mono and zlib1g library version when trying to create compression stream."
  175. + "If you've manually installed Mono, have you appropriately updated zlib1g as well?");
  176. m_log.Error(e);
  177. }
  178. m_errorMessage = String.Empty;
  179. m_merge = options.ContainsKey("merge");
  180. m_forceTerrain = options.ContainsKey("force-terrain");
  181. m_forceParcels = options.ContainsKey("force-parcels");
  182. m_noObjects = options.ContainsKey("no-objects");
  183. m_skipAssets = options.ContainsKey("skipAssets");
  184. m_requestId = requestId;
  185. m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero;
  186. m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f;
  187. m_boundingOrigin = Vector3.Zero;
  188. m_boundingSize = new Vector3(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY, float.MaxValue);
  189. if (options.ContainsKey("bounding-origin"))
  190. {
  191. Vector3 boOption = (Vector3)options["bounding-origin"];
  192. if (boOption != m_boundingOrigin)
  193. {
  194. m_boundingOrigin = boOption;
  195. }
  196. m_boundingBox = true;
  197. }
  198. if (options.ContainsKey("bounding-size"))
  199. {
  200. Vector3 bsOption = (Vector3)options["bounding-size"];
  201. bool clip = false;
  202. if (bsOption.X <= 0 || bsOption.X > m_boundingSize.X)
  203. {
  204. bsOption.X = m_boundingSize.X;
  205. clip = true;
  206. }
  207. if (bsOption.Y <= 0 || bsOption.Y > m_boundingSize.Y)
  208. {
  209. bsOption.Y = m_boundingSize.Y;
  210. clip = true;
  211. }
  212. if (bsOption != m_boundingSize)
  213. {
  214. m_boundingSize = bsOption;
  215. m_boundingBox = true;
  216. }
  217. if (clip) m_log.InfoFormat("[ARCHIVER]: The bounding cube specified is larger than the destination region! Clipping to {0}.", m_boundingSize.ToString());
  218. }
  219. m_debug = options.ContainsKey("debug");
  220. // Zero can never be a valid user id (or group)
  221. m_validUserUuids[UUID.Zero] = false;
  222. m_validGroupUuids[UUID.Zero] = false;
  223. m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
  224. m_assetService = m_rootScene.AssetService;
  225. }
  226. public ArchiveReadRequest(Scene scene, Stream loadStream, Guid requestId, Dictionary<string, object> options)
  227. {
  228. m_rootScene = scene;
  229. m_loadPath = null;
  230. m_loadStream = loadStream;
  231. m_skipAssets = options.ContainsKey("skipAssets");
  232. m_merge = options.ContainsKey("merge");
  233. m_requestId = requestId;
  234. m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
  235. // Zero can never be a valid user id
  236. m_validUserUuids[UUID.Zero] = false;
  237. m_groupsModule = m_rootScene.RequestModuleInterface<IGroupsModule>();
  238. m_assetService = m_rootScene.AssetService;
  239. }
  240. /// <summary>
  241. /// Dearchive the region embodied in this request.
  242. /// </summary>
  243. public void DearchiveRegion()
  244. {
  245. DearchiveRegion(true);
  246. }
  247. public void DearchiveRegion(bool shouldStartScripts)
  248. {
  249. int successfulAssetRestores = 0;
  250. int failedAssetRestores = 0;
  251. DearchiveScenesInfo dearchivedScenes;
  252. // We dearchive all the scenes at once, because the files in the TAR archive might be mixed.
  253. // Therefore, we have to keep track of the dearchive context of all the scenes.
  254. Dictionary<UUID, DearchiveContext> sceneContexts = new Dictionary<UUID, DearchiveContext>();
  255. string fullPath = "NONE";
  256. TarArchiveReader archive = null;
  257. byte[] data;
  258. TarArchiveReader.TarEntryType entryType;
  259. try
  260. {
  261. FindAndLoadControlFile(out archive, out dearchivedScenes);
  262. while ((data = archive.ReadEntry(out fullPath, out entryType)) != null)
  263. {
  264. //m_log.DebugFormat(
  265. // "[ARCHIVER]: Successfully read {0} ({1} bytes)", filePath, data.Length);
  266. if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
  267. continue;
  268. // Find the scene that this file belongs to
  269. Scene scene;
  270. string filePath;
  271. if (!dearchivedScenes.GetRegionFromPath(fullPath, out scene, out filePath))
  272. continue; // this file belongs to a region that we're not loading
  273. DearchiveContext sceneContext = null;
  274. if (scene != null)
  275. {
  276. if (!sceneContexts.TryGetValue(scene.RegionInfo.RegionID, out sceneContext))
  277. {
  278. sceneContext = new DearchiveContext(scene);
  279. sceneContexts.Add(scene.RegionInfo.RegionID, sceneContext);
  280. }
  281. }
  282. // Process the file
  283. if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH) && !m_noObjects)
  284. {
  285. sceneContext.SerialisedSceneObjects.Add(Encoding.UTF8.GetString(data));
  286. }
  287. else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH) && !m_skipAssets)
  288. {
  289. if (LoadAsset(filePath, data))
  290. successfulAssetRestores++;
  291. else
  292. failedAssetRestores++;
  293. if ((successfulAssetRestores + failedAssetRestores) % 250 == 0)
  294. m_log.Debug("[ARCHIVER]: Loaded " + successfulAssetRestores + " assets and failed to load " + failedAssetRestores + " assets...");
  295. }
  296. else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH) && (!m_merge || m_forceTerrain))
  297. {
  298. LoadTerrain(scene, filePath, data);
  299. }
  300. else if (!m_merge && filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
  301. {
  302. LoadRegionSettings(scene, filePath, data, dearchivedScenes);
  303. }
  304. else if (filePath.StartsWith(ArchiveConstants.LANDDATA_PATH) && (!m_merge || m_forceParcels))
  305. {
  306. sceneContext.SerialisedParcels.Add(Encoding.UTF8.GetString(data));
  307. }
  308. else if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
  309. {
  310. // Ignore, because we already read the control file
  311. }
  312. }
  313. //m_log.Debug("[ARCHIVER]: Reached end of archive");
  314. }
  315. catch (Exception e)
  316. {
  317. m_log.Error(
  318. String.Format("[ARCHIVER]: Aborting load with error in archive file {0} ", fullPath), e);
  319. m_errorMessage += e.ToString();
  320. m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage);
  321. return;
  322. }
  323. finally
  324. {
  325. if (archive != null)
  326. archive.Close();
  327. }
  328. if (!m_skipAssets)
  329. {
  330. m_log.InfoFormat("[ARCHIVER]: Restored {0} assets", successfulAssetRestores);
  331. if (failedAssetRestores > 0)
  332. {
  333. m_log.ErrorFormat("[ARCHIVER]: Failed to load {0} assets", failedAssetRestores);
  334. m_errorMessage += String.Format("Failed to load {0} assets", failedAssetRestores);
  335. }
  336. }
  337. foreach (DearchiveContext sceneContext in sceneContexts.Values)
  338. {
  339. m_log.InfoFormat("[ARCHIVER]: Loading region {0}", sceneContext.Scene.RegionInfo.RegionName);
  340. if (!m_merge)
  341. {
  342. m_log.Info("[ARCHIVER]: Clearing all existing scene objects");
  343. sceneContext.Scene.DeleteAllSceneObjects();
  344. }
  345. try
  346. {
  347. LoadParcels(sceneContext.Scene, sceneContext.SerialisedParcels);
  348. LoadObjects(sceneContext.Scene, sceneContext.SerialisedSceneObjects, sceneContext.SceneObjects);
  349. // Inform any interested parties that the region has changed. We waited until now so that all
  350. // of the region's objects will be loaded when we send this notification.
  351. IEstateModule estateModule = sceneContext.Scene.RequestModuleInterface<IEstateModule>();
  352. if (estateModule != null)
  353. estateModule.TriggerRegionInfoChange();
  354. }
  355. catch (Exception e)
  356. {
  357. m_log.Error("[ARCHIVER]: Error loading parcels or objects ", e);
  358. m_errorMessage += e.ToString();
  359. m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, new List<UUID>(), m_errorMessage);
  360. return;
  361. }
  362. }
  363. // Start the scripts. We delayed this because we want the OAR to finish loading ASAP, so
  364. // that users can enter the scene. If we allow the scripts to start in the loop above
  365. // then they significantly increase the time until the OAR finishes loading.
  366. if (shouldStartScripts)
  367. {
  368. WorkManager.RunInThread(o =>
  369. {
  370. Thread.Sleep(15000);
  371. m_log.Info("[ARCHIVER]: Starting scripts in scene objects");
  372. foreach (DearchiveContext sceneContext in sceneContexts.Values)
  373. {
  374. foreach (SceneObjectGroup sceneObject in sceneContext.SceneObjects)
  375. {
  376. sceneObject.CreateScriptInstances(0, false, sceneContext.Scene.DefaultScriptEngine, 0); // StateSource.RegionStart
  377. sceneObject.ResumeScripts();
  378. }
  379. sceneContext.SceneObjects.Clear();
  380. }
  381. }, null, string.Format("ReadArchiveStartScripts (request {0})", m_requestId));
  382. }
  383. m_log.InfoFormat("[ARCHIVER]: Successfully loaded archive");
  384. m_rootScene.EventManager.TriggerOarFileLoaded(m_requestId, dearchivedScenes.GetLoadedScenes(), m_errorMessage);
  385. }
  386. /// <summary>
  387. /// Searches through the files in the archive for the control file, and reads it.
  388. /// We must read the control file first, in order to know which regions are available.
  389. /// </summary>
  390. /// <remarks>
  391. /// In most cases the control file *is* first, since that's how we create archives. However,
  392. /// it's possible that someone rewrote the archive externally so we can't rely on this fact.
  393. /// </remarks>
  394. /// <param name="archive"></param>
  395. /// <param name="dearchivedScenes"></param>
  396. private void FindAndLoadControlFile(out TarArchiveReader archive, out DearchiveScenesInfo dearchivedScenes)
  397. {
  398. archive = new TarArchiveReader(m_loadStream);
  399. dearchivedScenes = new DearchiveScenesInfo();
  400. string filePath;
  401. byte[] data;
  402. TarArchiveReader.TarEntryType entryType;
  403. bool firstFile = true;
  404. while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
  405. {
  406. if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType)
  407. continue;
  408. if (filePath == ArchiveConstants.CONTROL_FILE_PATH)
  409. {
  410. LoadControlFile(filePath, data, dearchivedScenes);
  411. // Find which scenes are available in the simulator
  412. ArchiveScenesGroup simulatorScenes = new ArchiveScenesGroup();
  413. SceneManager.Instance.ForEachScene(delegate(Scene scene2)
  414. {
  415. simulatorScenes.AddScene(scene2);
  416. });
  417. simulatorScenes.CalcSceneLocations();
  418. dearchivedScenes.SetSimulatorScenes(m_rootScene, simulatorScenes);
  419. // If the control file wasn't the first file then reset the read pointer
  420. if (!firstFile)
  421. {
  422. m_log.Warn("[ARCHIVER]: Control file wasn't the first file in the archive");
  423. if (m_loadStream.CanSeek)
  424. {
  425. m_loadStream.Seek(0, SeekOrigin.Begin);
  426. }
  427. else if (m_loadPath != null)
  428. {
  429. archive.Close();
  430. archive = null;
  431. m_loadStream.Close();
  432. m_loadStream = null;
  433. m_loadStream = new GZipStream(ArchiveHelpers.GetStream(m_loadPath), CompressionMode.Decompress);
  434. archive = new TarArchiveReader(m_loadStream);
  435. }
  436. else
  437. {
  438. // There isn't currently a scenario where this happens, but it's best to add a check just in case
  439. throw new Exception("[ARCHIVER]: Error reading archive: control file wasn't the first file, and the input stream doesn't allow seeking");
  440. }
  441. }
  442. return;
  443. }
  444. firstFile = false;
  445. }
  446. throw new Exception("[ARCHIVER]: Control file not found");
  447. }
  448. /// <summary>
  449. /// Load serialized scene objects.
  450. /// </summary>
  451. protected void LoadObjects(Scene scene, List<string> serialisedSceneObjects, List<SceneObjectGroup> sceneObjects)
  452. {
  453. // Reload serialized prims
  454. m_log.InfoFormat("[ARCHIVER]: Loading {0} scene objects. Please wait.", serialisedSceneObjects.Count);
  455. // Convert rotation to radians
  456. double rotation = Math.PI * m_rotation / 180f;
  457. OpenMetaverse.Quaternion rot = OpenMetaverse.Quaternion.CreateFromAxisAngle(0, 0, 1, (float)rotation);
  458. UUID oldTelehubUUID = scene.RegionInfo.RegionSettings.TelehubObject;
  459. IRegionSerialiserModule serialiser = scene.RequestModuleInterface<IRegionSerialiserModule>();
  460. int sceneObjectsLoadedCount = 0;
  461. Vector3 boundingExtent = new Vector3(m_boundingOrigin.X + m_boundingSize.X, m_boundingOrigin.Y + m_boundingSize.Y, m_boundingOrigin.Z + m_boundingSize.Z);
  462. foreach (string serialisedSceneObject in serialisedSceneObjects)
  463. {
  464. /*
  465. m_log.DebugFormat("[ARCHIVER]: Loading xml with raw size {0}", serialisedSceneObject.Length);
  466. // Really large xml files (multi megabyte) appear to cause
  467. // memory problems
  468. // when loading the xml. But don't enable this check yet
  469. if (serialisedSceneObject.Length > 5000000)
  470. {
  471. m_log.Error("[ARCHIVER]: Ignoring xml since size > 5000000);");
  472. continue;
  473. }
  474. */
  475. SceneObjectGroup sceneObject = serialiser.DeserializeGroupFromXml2(serialisedSceneObject);
  476. Vector3 pos = sceneObject.AbsolutePosition;
  477. if (m_debug)
  478. m_log.DebugFormat("[ARCHIVER]: Loading object from OAR with original scene position {0}.", pos.ToString());
  479. // Happily this does not do much to the object since it hasn't been added to the scene yet
  480. if (!sceneObject.IsAttachment)
  481. {
  482. if (m_rotation != 0f)
  483. {
  484. //fix the rotation center to the middle of the incoming region now as it's otherwise hopelessly confusing on varRegions
  485. //as it only works with objects and terrain (using old Merge method) and not parcels
  486. m_rotationCenter.X = m_incomingRegionSize.X / 2;
  487. m_rotationCenter.Y = m_incomingRegionSize.Y / 2;
  488. // Rotate the object
  489. sceneObject.RootPart.RotationOffset = rot * sceneObject.GroupRotation;
  490. // Get object position relative to rotation axis
  491. Vector3 offset = pos - m_rotationCenter;
  492. // Rotate the object position
  493. offset *= rot;
  494. // Restore the object position back to relative to the region
  495. pos = m_rotationCenter + offset;
  496. if (m_debug) m_log.DebugFormat("[ARCHIVER]: After rotation, object from OAR is at scene position {0}.", pos.ToString());
  497. }
  498. if (m_boundingBox)
  499. {
  500. if (pos.X < m_boundingOrigin.X || pos.X >= boundingExtent.X
  501. || pos.Y < m_boundingOrigin.Y || pos.Y >= boundingExtent.Y
  502. || pos.Z < m_boundingOrigin.Z || pos.Z >= boundingExtent.Z)
  503. {
  504. if (m_debug) m_log.DebugFormat("[ARCHIVER]: Skipping object from OAR in scene because it's position {0} is outside of bounding cube.", pos.ToString());
  505. continue;
  506. }
  507. //adjust object position to be relative to <0,0> so we can apply the displacement
  508. pos.X -= m_boundingOrigin.X;
  509. pos.Y -= m_boundingOrigin.Y;
  510. }
  511. if (m_displacement != Vector3.Zero)
  512. {
  513. pos += m_displacement;
  514. if (m_debug) m_log.DebugFormat("[ARCHIVER]: After displacement, object from OAR is at scene position {0}.", pos.ToString());
  515. }
  516. sceneObject.AbsolutePosition = pos;
  517. }
  518. if (m_debug)
  519. m_log.DebugFormat("[ARCHIVER]: Placing object from OAR in scene at position {0}. ", pos.ToString());
  520. bool isTelehub = (sceneObject.UUID == oldTelehubUUID) && (oldTelehubUUID != UUID.Zero);
  521. // For now, give all incoming scene objects new uuids. This will allow scenes to be cloned
  522. // on the same region server and multiple examples a single object archive to be imported
  523. // to the same scene (when this is possible).
  524. sceneObject.ResetIDs();
  525. if (isTelehub)
  526. {
  527. // Change the Telehub Object to the new UUID
  528. scene.RegionInfo.RegionSettings.TelehubObject = sceneObject.UUID;
  529. scene.RegionInfo.RegionSettings.Save();
  530. oldTelehubUUID = UUID.Zero;
  531. }
  532. ModifySceneObject(scene, sceneObject);
  533. if (scene.AddRestoredSceneObject(sceneObject, true, false))
  534. {
  535. sceneObjectsLoadedCount++;
  536. sceneObject.CreateScriptInstances(0, false, scene.DefaultScriptEngine, 0);
  537. sceneObject.ResumeScripts();
  538. }
  539. }
  540. m_log.InfoFormat("[ARCHIVER]: Restored {0} scene objects to the scene", sceneObjectsLoadedCount);
  541. int ignoredObjects = serialisedSceneObjects.Count - sceneObjectsLoadedCount;
  542. if (ignoredObjects > 0)
  543. m_log.WarnFormat("[ARCHIVER]: Ignored {0} scene objects that already existed in the scene or were out of bounds", ignoredObjects);
  544. if (oldTelehubUUID != UUID.Zero)
  545. {
  546. m_log.WarnFormat("[ARCHIVER]: Telehub object not found: {0}", oldTelehubUUID);
  547. scene.RegionInfo.RegionSettings.TelehubObject = UUID.Zero;
  548. scene.RegionInfo.RegionSettings.ClearSpawnPoints();
  549. }
  550. }
  551. /// <summary>
  552. /// Optionally modify a loaded SceneObjectGroup. Currently this just ensures that the
  553. /// User IDs and Group IDs are valid, but other manipulations could be done as well.
  554. /// </summary>
  555. private void ModifySceneObject(Scene scene, SceneObjectGroup sceneObject)
  556. {
  557. // Try to retain the original creator/owner/lastowner if their uuid is present on this grid
  558. // or creator data is present. Otherwise, use the estate owner instead.
  559. foreach (SceneObjectPart part in sceneObject.Parts)
  560. {
  561. if (string.IsNullOrEmpty(part.CreatorData))
  562. {
  563. if (!ResolveUserUuid(scene, part.CreatorID))
  564. part.CreatorID = m_defaultUser;
  565. }
  566. if (UserManager != null)
  567. UserManager.AddUser(part.CreatorID, part.CreatorData);
  568. if (!(ResolveUserUuid(scene, part.OwnerID) || ResolveGroupUuid(part.OwnerID)))
  569. part.OwnerID = m_defaultUser;
  570. if (!(ResolveUserUuid(scene, part.LastOwnerID) || ResolveGroupUuid(part.LastOwnerID)))
  571. part.LastOwnerID = m_defaultUser;
  572. if (!ResolveGroupUuid(part.GroupID))
  573. part.GroupID = UUID.Zero;
  574. // And zap any troublesome sit target information
  575. // part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
  576. // part.SitTargetPosition = new Vector3(0, 0, 0);
  577. // Fix ownership/creator of inventory items
  578. // Not doing so results in inventory items
  579. // being no copy/no mod for everyone
  580. lock (part.TaskInventory)
  581. {
  582. /* avination code disabled for opensim
  583. // And zap any troublesome sit target information
  584. part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
  585. part.SitTargetPosition = new Vector3(0, 0, 0);
  586. */
  587. // Fix ownership/creator of inventory items
  588. // Not doing so results in inventory items
  589. // being no copy/no mod for everyone
  590. part.TaskInventory.LockItemsForRead(true);
  591. TaskInventoryDictionary inv = part.TaskInventory;
  592. foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
  593. {
  594. if (!(ResolveUserUuid(scene, kvp.Value.OwnerID) || ResolveGroupUuid(kvp.Value.OwnerID)))
  595. {
  596. kvp.Value.OwnerID = m_defaultUser;
  597. }
  598. if (string.IsNullOrEmpty(kvp.Value.CreatorData))
  599. {
  600. if (!ResolveUserUuid(scene, kvp.Value.CreatorID))
  601. kvp.Value.CreatorID = m_defaultUser;
  602. }
  603. if (UserManager != null)
  604. UserManager.AddUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
  605. if (!ResolveGroupUuid(kvp.Value.GroupID))
  606. kvp.Value.GroupID = UUID.Zero;
  607. }
  608. part.TaskInventory.LockItemsForRead(false);
  609. }
  610. }
  611. }
  612. /// <summary>
  613. /// Load serialized parcels.
  614. /// </summary>
  615. /// <param name="scene"></param>
  616. /// <param name="serialisedParcels"></param>
  617. protected void LoadParcels(Scene scene, List<string> serialisedParcels)
  618. {
  619. // Reload serialized parcels
  620. m_log.InfoFormat("[ARCHIVER]: Loading {0} parcels. Please wait.", serialisedParcels.Count);
  621. List<LandData> landData = new List<LandData>();
  622. ILandObject landObject = scene.RequestModuleInterface<ILandObject>();
  623. List<ILandObject> parcels;
  624. Vector3 parcelDisp = new Vector3(m_displacement.X, m_displacement.Y, 0f);
  625. Vector2 displacement = new Vector2(m_displacement.X, m_displacement.Y);
  626. Vector2 boundingOrigin = new Vector2(m_boundingOrigin.X, m_boundingOrigin.Y);
  627. Vector2 boundingSize = new Vector2(m_boundingSize.X, m_boundingSize.Y);
  628. Vector2 regionSize = new Vector2(scene.RegionInfo.RegionSizeX, scene.RegionInfo.RegionSizeY);
  629. // Gather any existing parcels before we add any more. Later as we add parcels we can check if the new parcel
  630. // data overlays any of the old data, and we can modify and remove (if empty) the old parcel so that there's no conflict
  631. parcels = scene.LandChannel.AllParcels();
  632. foreach (string serialisedParcel in serialisedParcels)
  633. {
  634. LandData parcel = LandDataSerializer.Deserialize(serialisedParcel);
  635. bool overrideRegionSize = true; //use the src land parcel data size not the dst region size
  636. bool isEmptyNow;
  637. Vector3 AABBMin;
  638. Vector3 AABBMax;
  639. // create a new LandObject that we can use to manipulate the incoming source parcel data
  640. // this is ok, but just beware that some of the LandObject functions (that we haven't used here) still
  641. // assume we're always using the destination region size
  642. LandData ld = new LandData();
  643. landObject = new LandObject(ld, scene);
  644. landObject.LandData = parcel;
  645. bool[,] srcLandBitmap = landObject.ConvertBytesToLandBitmap(overrideRegionSize);
  646. if (landObject.IsLandBitmapEmpty(srcLandBitmap))
  647. {
  648. m_log.InfoFormat("[ARCHIVER]: Skipping source parcel {0} with GlobalID: {1} LocalID: {2} that has no claimed land.",
  649. parcel.Name, parcel.GlobalID, parcel.LocalID);
  650. continue;
  651. }
  652. //m_log.DebugFormat("[ARCHIVER]: Showing claimed land for source parcel: {0} with GlobalID: {1} LocalID: {2}.",
  653. // parcel.Name, parcel.GlobalID, parcel.LocalID);
  654. //landObject.DebugLandBitmap(srcLandBitmap);
  655. bool[,] dstLandBitmap = landObject.RemapLandBitmap(srcLandBitmap, displacement, m_rotation, boundingOrigin, boundingSize, regionSize, out isEmptyNow, out AABBMin, out AABBMax);
  656. if (isEmptyNow)
  657. {
  658. m_log.WarnFormat("[ARCHIVER]: Not adding destination parcel {0} with GlobalID: {1} LocalID: {2} because, after applying rotation, bounding and displacement, it has no claimed land.",
  659. parcel.Name, parcel.GlobalID, parcel.LocalID);
  660. continue;
  661. }
  662. //m_log.DebugFormat("[ARCHIVER]: Showing claimed land for destination parcel: {0} with GlobalID: {1} LocalID: {2} after applying rotation, bounding and displacement.",
  663. // parcel.Name, parcel.GlobalID, parcel.LocalID);
  664. //landObject.DebugLandBitmap(dstLandBitmap);
  665. landObject.LandBitmap = dstLandBitmap;
  666. parcel.Bitmap = landObject.ConvertLandBitmapToBytes();
  667. parcel.AABBMin = AABBMin;
  668. parcel.AABBMax = AABBMax;
  669. if (m_merge)
  670. {
  671. // give the remapped parcel a new GlobalID, in case we're using the same OAR twice and a bounding cube, displacement and --merge
  672. parcel.GlobalID = UUID.Random();
  673. //now check if the area of this new incoming parcel overlays an area in any existing parcels
  674. //and if so modify or lose the existing parcels
  675. for (int i = 0; i < parcels.Count; i++)
  676. {
  677. if (parcels[i] != null)
  678. {
  679. bool[,] modLandBitmap = parcels[i].ConvertBytesToLandBitmap(overrideRegionSize);
  680. modLandBitmap = parcels[i].RemoveFromLandBitmap(modLandBitmap, dstLandBitmap, out isEmptyNow, out AABBMin, out AABBMax);
  681. if (isEmptyNow)
  682. {
  683. parcels[i] = null;
  684. }
  685. else
  686. {
  687. parcels[i].LandBitmap = modLandBitmap;
  688. parcels[i].LandData.Bitmap = parcels[i].ConvertLandBitmapToBytes();
  689. parcels[i].LandData.AABBMin = AABBMin;
  690. parcels[i].LandData.AABBMax = AABBMax;
  691. }
  692. }
  693. }
  694. }
  695. // Validate User and Group UUID's
  696. if (!ResolveGroupUuid(parcel.GroupID))
  697. parcel.GroupID = UUID.Zero;
  698. if (parcel.IsGroupOwned)
  699. {
  700. if (parcel.GroupID != UUID.Zero)
  701. {
  702. // In group-owned parcels, OwnerID=GroupID. This should already be the case, but let's make sure.
  703. parcel.OwnerID = parcel.GroupID;
  704. }
  705. else
  706. {
  707. parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
  708. parcel.IsGroupOwned = false;
  709. }
  710. }
  711. else
  712. {
  713. if (!ResolveUserUuid(scene, parcel.OwnerID))
  714. parcel.OwnerID = m_rootScene.RegionInfo.EstateSettings.EstateOwner;
  715. }
  716. List<LandAccessEntry> accessList = new List<LandAccessEntry>();
  717. foreach (LandAccessEntry entry in parcel.ParcelAccessList)
  718. {
  719. if (ResolveUserUuid(scene, entry.AgentID))
  720. accessList.Add(entry);
  721. // else, drop this access rule
  722. }
  723. parcel.ParcelAccessList = accessList;
  724. if (m_debug) m_log.DebugFormat("[ARCHIVER]: Adding parcel {0}, local id {1}, owner {2}, group {3}, isGroupOwned {4}, area {5}",
  725. parcel.Name, parcel.LocalID, parcel.OwnerID, parcel.GroupID, parcel.IsGroupOwned, parcel.Area);
  726. landData.Add(parcel);
  727. }
  728. if (m_merge)
  729. {
  730. for (int i = 0; i < parcels.Count; i++) //if merging then we need to also add back in any existing parcels
  731. {
  732. if (parcels[i] != null) landData.Add(parcels[i].LandData);
  733. }
  734. }
  735. m_log.InfoFormat("[ARCHIVER]: Clearing {0} parcels.", parcels.Count);
  736. bool setupDefaultParcel = (landData.Count == 0);
  737. scene.LandChannel.Clear(setupDefaultParcel);
  738. scene.EventManager.TriggerIncomingLandDataFromStorage(landData);
  739. m_log.InfoFormat("[ARCHIVER]: Restored {0} parcels.", landData.Count);
  740. }
  741. /// <summary>
  742. /// Look up the given user id to check whether it's one that is valid for this grid.
  743. /// </summary>
  744. /// <param name="scene"></param>
  745. /// <param name="uuid"></param>
  746. /// <returns></returns>
  747. private bool ResolveUserUuid(Scene scene, UUID uuid)
  748. {
  749. lock (m_validUserUuids)
  750. {
  751. if (!m_validUserUuids.ContainsKey(uuid))
  752. {
  753. // Note: we call GetUserAccount() inside the lock because this UserID is likely
  754. // to occur many times, and we only want to query the users service once.
  755. UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, uuid);
  756. m_validUserUuids.Add(uuid, account != null);
  757. }
  758. return m_validUserUuids[uuid];
  759. }
  760. }
  761. /// <summary>
  762. /// Look up the given group id to check whether it's one that is valid for this grid.
  763. /// </summary>
  764. /// <param name="uuid"></param>
  765. /// <returns></returns>
  766. private bool ResolveGroupUuid(UUID uuid)
  767. {
  768. lock (m_validGroupUuids)
  769. {
  770. if (!m_validGroupUuids.ContainsKey(uuid))
  771. {
  772. bool exists;
  773. if (m_groupsModule == null)
  774. {
  775. exists = false;
  776. }
  777. else
  778. {
  779. // Note: we call GetGroupRecord() inside the lock because this GroupID is likely
  780. // to occur many times, and we only want to query the groups service once.
  781. exists = (m_groupsModule.GetGroupRecord(uuid) != null);
  782. }
  783. m_validGroupUuids.Add(uuid, exists);
  784. }
  785. return m_validGroupUuids[uuid];
  786. }
  787. }
  788. /// Load an asset
  789. /// </summary>
  790. /// <param name="assetFilename"></param>
  791. /// <param name="data"></param>
  792. /// <returns>true if asset was successfully loaded, false otherwise</returns>
  793. private bool LoadAsset(string assetPath, byte[] data)
  794. {
  795. // Right now we're nastily obtaining the UUID from the filename
  796. string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
  797. int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
  798. if (i == -1)
  799. {
  800. m_log.ErrorFormat(
  801. "[ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}. Skipping",
  802. assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);
  803. return false;
  804. }
  805. string extension = filename.Substring(i);
  806. string uuid = filename.Remove(filename.Length - extension.Length);
  807. if (m_assetService.GetMetadata(uuid) != null)
  808. {
  809. sbyte asype = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
  810. if(asype == -2)
  811. {
  812. }
  813. // m_log.DebugFormat("[ARCHIVER]: found existing asset {0}",uuid);
  814. return true;
  815. }
  816. if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
  817. {
  818. sbyte assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
  819. if(assetType == -2)
  820. {
  821. }
  822. if (assetType == (sbyte)AssetType.Unknown)
  823. {
  824. m_log.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);
  825. }
  826. else if (assetType == (sbyte)AssetType.Object)
  827. {
  828. data = SceneObjectSerializer.ModifySerializedObject(UUID.Parse(uuid), data,
  829. sog =>
  830. {
  831. ModifySceneObject(m_rootScene, sog);
  832. return true;
  833. });
  834. if (data == null)
  835. return false;
  836. }
  837. //m_log.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
  838. AssetBase asset = new AssetBase(new UUID(uuid), String.Empty, assetType, UUID.Zero.ToString());
  839. asset.Data = data;
  840. // We're relying on the asset service to do the sensible thing and not store the asset if it already
  841. // exists.
  842. m_assetService.Store(asset);
  843. /**
  844. * Create layers on decode for image assets. This is likely to significantly increase the time to load archives so
  845. * it might be best done when dearchive takes place on a separate thread
  846. if (asset.Type=AssetType.Texture)
  847. {
  848. IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
  849. if (cacheLayerDecode != null)
  850. cacheLayerDecode.syncdecode(asset.FullID, asset.Data);
  851. }
  852. */
  853. return true;
  854. }
  855. else
  856. {
  857. m_log.ErrorFormat(
  858. "[ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}",
  859. assetPath, extension);
  860. return false;
  861. }
  862. }
  863. /// <summary>
  864. /// Load region settings data
  865. /// </summary>
  866. /// <param name="scene"></param>
  867. /// <param name="settingsPath"></param>
  868. /// <param name="data"></param>
  869. /// <param name="dearchivedScenes"></param>
  870. /// <returns>
  871. /// true if settings were loaded successfully, false otherwise
  872. /// </returns>
  873. private bool LoadRegionSettings(Scene scene, string settingsPath, byte[] data, DearchiveScenesInfo dearchivedScenes)
  874. {
  875. RegionSettings loadedRegionSettings;
  876. try
  877. {
  878. loadedRegionSettings = RegionSettingsSerializer.Deserialize(data);
  879. }
  880. catch (Exception e)
  881. {
  882. m_log.ErrorFormat(
  883. "[ARCHIVER]: Could not parse region settings file {0}. Ignoring. Exception was {1}",
  884. settingsPath, e);
  885. return false;
  886. }
  887. RegionSettings currentRegionSettings = scene.RegionInfo.RegionSettings;
  888. currentRegionSettings.AgentLimit = loadedRegionSettings.AgentLimit;
  889. currentRegionSettings.AllowDamage = loadedRegionSettings.AllowDamage;
  890. currentRegionSettings.AllowLandJoinDivide = loadedRegionSettings.AllowLandJoinDivide;
  891. currentRegionSettings.AllowLandResell = loadedRegionSettings.AllowLandResell;
  892. currentRegionSettings.BlockFly = loadedRegionSettings.BlockFly;
  893. currentRegionSettings.BlockShowInSearch = loadedRegionSettings.BlockShowInSearch;
  894. currentRegionSettings.BlockTerraform = loadedRegionSettings.BlockTerraform;
  895. currentRegionSettings.DisableCollisions = loadedRegionSettings.DisableCollisions;
  896. currentRegionSettings.DisablePhysics = loadedRegionSettings.DisablePhysics;
  897. currentRegionSettings.DisableScripts = loadedRegionSettings.DisableScripts;
  898. currentRegionSettings.Elevation1NE = loadedRegionSettings.Elevation1NE;
  899. currentRegionSettings.Elevation1NW = loadedRegionSettings.Elevation1NW;
  900. currentRegionSettings.Elevation1SE = loadedRegionSettings.Elevation1SE;
  901. currentRegionSettings.Elevation1SW = loadedRegionSettings.Elevation1SW;
  902. currentRegionSettings.Elevation2NE = loadedRegionSettings.Elevation2NE;
  903. currentRegionSettings.Elevation2NW = loadedRegionSettings.Elevation2NW;
  904. currentRegionSettings.Elevation2SE = loadedRegionSettings.Elevation2SE;
  905. currentRegionSettings.Elevation2SW = loadedRegionSettings.Elevation2SW;
  906. currentRegionSettings.FixedSun = loadedRegionSettings.FixedSun;
  907. currentRegionSettings.SunPosition = loadedRegionSettings.SunPosition;
  908. currentRegionSettings.ObjectBonus = loadedRegionSettings.ObjectBonus;
  909. currentRegionSettings.RestrictPushing = loadedRegionSettings.RestrictPushing;
  910. currentRegionSettings.TerrainLowerLimit = loadedRegionSettings.TerrainLowerLimit;
  911. currentRegionSettings.TerrainRaiseLimit = loadedRegionSettings.TerrainRaiseLimit;
  912. currentRegionSettings.TerrainTexture1 = loadedRegionSettings.TerrainTexture1;
  913. currentRegionSettings.TerrainTexture2 = loadedRegionSettings.TerrainTexture2;
  914. currentRegionSettings.TerrainTexture3 = loadedRegionSettings.TerrainTexture3;
  915. currentRegionSettings.TerrainTexture4 = loadedRegionSettings.TerrainTexture4;
  916. currentRegionSettings.UseEstateSun = loadedRegionSettings.UseEstateSun;
  917. currentRegionSettings.WaterHeight = loadedRegionSettings.WaterHeight;
  918. currentRegionSettings.TelehubObject = loadedRegionSettings.TelehubObject;
  919. currentRegionSettings.ClearSpawnPoints();
  920. foreach (SpawnPoint sp in loadedRegionSettings.SpawnPoints())
  921. currentRegionSettings.AddSpawnPoint(sp);
  922. currentRegionSettings.LoadedCreationDateTime = dearchivedScenes.LoadedCreationDateTime;
  923. currentRegionSettings.LoadedCreationID = dearchivedScenes.GetOriginalRegionID(scene.RegionInfo.RegionID).ToString();
  924. currentRegionSettings.Save();
  925. scene.TriggerEstateSunUpdate();
  926. IEstateModule estateModule = scene.RequestModuleInterface<IEstateModule>();
  927. if (estateModule != null)
  928. estateModule.sendRegionHandshakeToAll();
  929. return true;
  930. }
  931. /// <summary>
  932. /// Load terrain data
  933. /// </summary>
  934. /// <param name="scene"></param>
  935. /// <param name="terrainPath"></param>
  936. /// <param name="data"></param>
  937. /// <returns>
  938. /// true if terrain was resolved successfully, false otherwise.
  939. /// </returns>
  940. private bool LoadTerrain(Scene scene, string terrainPath, byte[] data)
  941. {
  942. ITerrainModule terrainModule = scene.RequestModuleInterface<ITerrainModule>();
  943. using (MemoryStream ms = new MemoryStream(data))
  944. {
  945. if (m_displacement != Vector3.Zero || m_rotation != 0f || m_boundingBox)
  946. {
  947. Vector2 boundingOrigin = new Vector2(m_boundingOrigin.X, m_boundingOrigin.Y);
  948. Vector2 boundingSize = new Vector2(m_boundingSize.X, m_boundingSize.Y);
  949. terrainModule.LoadFromStream(terrainPath, m_displacement, m_rotation, boundingOrigin, boundingSize, ms); ;
  950. }
  951. else
  952. {
  953. terrainModule.LoadFromStream(terrainPath, ms);
  954. }
  955. }
  956. m_log.DebugFormat("[ARCHIVER]: Restored terrain {0}", terrainPath);
  957. return true;
  958. }
  959. /// <summary>
  960. /// Load oar control file
  961. /// </summary>
  962. /// <param name="path"></param>
  963. /// <param name="data"></param>
  964. /// <param name="dearchivedScenes"></param>
  965. public DearchiveScenesInfo LoadControlFile(string path, byte[] data, DearchiveScenesInfo dearchivedScenes)
  966. {
  967. XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
  968. XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
  969. XmlTextReader xtr = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);
  970. xtr.ProhibitDtd = true;
  971. // Loaded metadata will be empty if no information exists in the archive
  972. dearchivedScenes.LoadedCreationDateTime = 0;
  973. dearchivedScenes.DefaultOriginalID = "";
  974. bool multiRegion = false;
  975. while (xtr.Read())
  976. {
  977. if (xtr.NodeType == XmlNodeType.Element)
  978. {
  979. if (xtr.Name.ToString() == "archive")
  980. {
  981. int majorVersion = int.Parse(xtr["major_version"]);
  982. int minorVersion = int.Parse(xtr["minor_version"]);
  983. string version = string.Format("{0}.{1}", majorVersion, minorVersion);
  984. if (majorVersion > MAX_MAJOR_VERSION)
  985. {
  986. throw new Exception(
  987. string.Format(
  988. "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
  989. majorVersion, MAX_MAJOR_VERSION));
  990. }
  991. m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
  992. }
  993. else if (xtr.Name.ToString() == "datetime")
  994. {
  995. int value;
  996. if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
  997. dearchivedScenes.LoadedCreationDateTime = value;
  998. }
  999. else if (xtr.Name.ToString() == "row")
  1000. {
  1001. multiRegion = true;
  1002. dearchivedScenes.StartRow();
  1003. }
  1004. else if (xtr.Name.ToString() == "region")
  1005. {
  1006. dearchivedScenes.StartRegion();
  1007. }
  1008. else if (xtr.Name.ToString() == "id")
  1009. {
  1010. string id = xtr.ReadElementContentAsString();
  1011. dearchivedScenes.DefaultOriginalID = id;
  1012. if(multiRegion)
  1013. dearchivedScenes.SetRegionOriginalID(id);
  1014. }
  1015. else if (xtr.Name.ToString() == "dir")
  1016. {
  1017. dearchivedScenes.SetRegionDirectory(xtr.ReadElementContentAsString());
  1018. }
  1019. else if (xtr.Name.ToString() == "size_in_meters")
  1020. {
  1021. Vector3 value;
  1022. string size = "<" + xtr.ReadElementContentAsString() + ",0>";
  1023. if (Vector3.TryParse(size, out value))
  1024. {
  1025. m_incomingRegionSize = value;
  1026. if(multiRegion)
  1027. dearchivedScenes.SetRegionSize(m_incomingRegionSize);
  1028. m_log.DebugFormat("[ARCHIVER]: Found region_size info {0}",
  1029. m_incomingRegionSize.ToString());
  1030. }
  1031. }
  1032. }
  1033. }
  1034. dearchivedScenes.MultiRegionFormat = multiRegion;
  1035. if (!multiRegion)
  1036. {
  1037. // Add the single scene
  1038. dearchivedScenes.StartRow();
  1039. dearchivedScenes.StartRegion();
  1040. dearchivedScenes.SetRegionOriginalID(dearchivedScenes.DefaultOriginalID);
  1041. dearchivedScenes.SetRegionDirectory("");
  1042. dearchivedScenes.SetRegionSize(m_incomingRegionSize);
  1043. }
  1044. ControlFileLoaded = true;
  1045. if(xtr != null)
  1046. xtr.Close();
  1047. return dearchivedScenes;
  1048. }
  1049. }
  1050. }