ArchiveReadRequest.cs 55 KB

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