Add is_megaregion flag into oar control file. Not currently read - for future use. Please do not rely on this remaining here.

An adaptation of part of Garmin's patch from http://opensimulator.org/mantis/view.php?id=5975, thanks!
Flag only written if the SW corner OAR is saved - this is the only one that captures object data presently (though not land or terrain data).
This adds an IRegionCombinerModule interface and the necessary methods on RegionCombinerModule
0.7.4.1
Justin Clark-Casey (justincc) 2012-05-19 02:45:17 +01:00
parent 9fa0577c7e
commit 2b60a5c5d6
4 changed files with 142 additions and 40 deletions

View File

@ -67,7 +67,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// Determine whether this archive will save assets. Default is true. /// Determine whether this archive will save assets. Default is true.
/// </summary> /// </summary>
public bool SaveAssets { get; set; } public bool SaveAssets { get; set; }
protected ArchiverModule m_module;
protected Scene m_scene; protected Scene m_scene;
protected Stream m_saveStream; protected Stream m_saveStream;
protected Guid m_requestId; protected Guid m_requestId;
@ -75,13 +76,13 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// <summary> /// <summary>
/// Constructor /// Constructor
/// </summary> /// </summary>
/// <param name="scene"></param> /// <param name="module">Calling module</param>
/// <param name="savePath">The path to which to save data.</param> /// <param name="savePath">The path to which to save data.</param>
/// <param name="requestId">The id associated with this request</param> /// <param name="requestId">The id associated with this request</param>
/// <exception cref="System.IO.IOException"> /// <exception cref="System.IO.IOException">
/// If there was a problem opening a stream for the file specified by the savePath /// If there was a problem opening a stream for the file specified by the savePath
/// </exception> /// </exception>
public ArchiveWriteRequestPreparation(Scene scene, string savePath, Guid requestId) : this(scene, requestId) public ArchiveWriteRequestPreparation(ArchiverModule module, string savePath, Guid requestId) : this(module, requestId)
{ {
try try
{ {
@ -99,17 +100,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// <summary> /// <summary>
/// Constructor. /// Constructor.
/// </summary> /// </summary>
/// <param name="scene"></param> /// <param name="module">Calling module</param>
/// <param name="saveStream">The stream to which to save data.</param> /// <param name="saveStream">The stream to which to save data.</param>
/// <param name="requestId">The id associated with this request</param> /// <param name="requestId">The id associated with this request</param>
public ArchiveWriteRequestPreparation(Scene scene, Stream saveStream, Guid requestId) : this(scene, requestId) public ArchiveWriteRequestPreparation(ArchiverModule module, Stream saveStream, Guid requestId) : this(module, requestId)
{ {
m_saveStream = saveStream; m_saveStream = saveStream;
} }
protected ArchiveWriteRequestPreparation(Scene scene, Guid requestId) protected ArchiveWriteRequestPreparation(ArchiverModule module, Guid requestId)
{ {
m_scene = scene; m_module = module;
// FIXME: This is only here for regression test purposes since they do not supply a module. Need to fix
// this.
if (m_module != null)
m_scene = m_module.Scene;
m_requestId = requestId; m_requestId = requestId;
SaveAssets = true; SaveAssets = true;
@ -364,32 +371,56 @@ namespace OpenSim.Region.CoreModules.World.Archiver
//if (majorVersion == 1) //if (majorVersion == 1)
//{ //{
// m_log.WarnFormat("[ARCHIVER]: Please be aware that version 1.0 OARs are not compatible with OpenSim 0.7.0.2 and earlier. Please use the --version=0 option if you want to produce a compatible OAR"); // m_log.WarnFormat("[ARCHIVER]: Please be aware that version 1.0 OARs are not compatible with OpenSim 0.7.0.2 and earlier. Please use the --version=0 option if you want to produce a compatible OAR");
//} //}
String s;
StringWriter sw = new StringWriter(); using (StringWriter sw = new StringWriter())
XmlTextWriter xtw = new XmlTextWriter(sw); {
xtw.Formatting = Formatting.Indented; using (XmlTextWriter xtw = new XmlTextWriter(sw))
xtw.WriteStartDocument(); {
xtw.WriteStartElement("archive"); xtw.Formatting = Formatting.Indented;
xtw.WriteAttributeString("major_version", majorVersion.ToString()); xtw.WriteStartDocument();
xtw.WriteAttributeString("minor_version", minorVersion.ToString()); xtw.WriteStartElement("archive");
xtw.WriteAttributeString("major_version", majorVersion.ToString());
xtw.WriteAttributeString("minor_version", minorVersion.ToString());
xtw.WriteStartElement("creation_info");
DateTime now = DateTime.UtcNow;
TimeSpan t = now - new DateTime(1970, 1, 1);
xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString());
xtw.WriteElementString("id", UUID.Random().ToString());
xtw.WriteEndElement();
xtw.WriteElementString("assets_included", SaveAssets.ToString());
bool isMegaregion;
xtw.WriteStartElement("creation_info"); // FIXME: This is only here for regression test purposes since they do not supply a module. Need to fix
DateTime now = DateTime.UtcNow; // this, possibly by doing control file creation somewhere else.
TimeSpan t = now - new DateTime(1970, 1, 1); if (m_module != null && m_module.RegionCombinerModule != null)
xtw.WriteElementString("datetime", ((int)t.TotalSeconds).ToString()); {
xtw.WriteElementString("id", UUID.Random().ToString()); IRegionCombinerModule mod = m_module.RegionCombinerModule;
xtw.WriteEndElement(); isMegaregion = mod.IsMegaregion && mod.IsRootRegion(m_scene.RegionInfo.RegionID);
}
else
{
isMegaregion = false;
}
xtw.WriteElementString("is_megaregion", isMegaregion.ToString());
xtw.WriteEndElement();
xtw.Flush();
xtw.Close();
}
xtw.WriteElementString("assets_included", SaveAssets.ToString()); s = sw.ToString();
}
xtw.WriteEndElement(); // Console.WriteLine(
// "[ARCHIVE WRITE REQUEST PREPARATION]: Control file for {0} is: {1}", m_scene.RegionInfo.RegionName, s);
xtw.Flush();
xtw.Close();
String s = sw.ToString();
sw.Close();
return s; return s;
} }

View File

@ -45,7 +45,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
private static readonly ILog m_log = private static readonly ILog m_log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private Scene m_scene; public Scene Scene { get; private set; }
public IRegionCombinerModule RegionCombinerModule { get; private set; }
/// <value> /// <value>
/// The file used to load and save an opensimulator archive if no filename has been specified /// The file used to load and save an opensimulator archive if no filename has been specified
@ -70,13 +71,14 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
{ {
m_scene = scene; Scene = scene;
m_scene.RegisterModuleInterface<IRegionArchiverModule>(this); Scene.RegisterModuleInterface<IRegionArchiverModule>(this);
//m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName); //m_log.DebugFormat("[ARCHIVER]: Enabled for region {0}", scene.RegionInfo.RegionName);
} }
public void RegionLoaded(Scene scene) public void RegionLoaded(Scene scene)
{ {
RegionCombinerModule = scene.RequestModuleInterface<IRegionCombinerModule>();
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -165,9 +167,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options) public void ArchiveRegion(string savePath, Guid requestId, Dictionary<string, object> options)
{ {
m_log.InfoFormat( m_log.InfoFormat(
"[ARCHIVER]: Writing archive for region {0} to {1}", m_scene.RegionInfo.RegionName, savePath); "[ARCHIVER]: Writing archive for region {0} to {1}", Scene.RegionInfo.RegionName, savePath);
new ArchiveWriteRequestPreparation(m_scene, savePath, requestId).ArchiveRegion(options); new ArchiveWriteRequestPreparation(this, savePath, requestId).ArchiveRegion(options);
} }
public void ArchiveRegion(Stream saveStream) public void ArchiveRegion(Stream saveStream)
@ -182,7 +184,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options) public void ArchiveRegion(Stream saveStream, Guid requestId, Dictionary<string, object> options)
{ {
new ArchiveWriteRequestPreparation(m_scene, saveStream, requestId).ArchiveRegion(options); new ArchiveWriteRequestPreparation(this, saveStream, requestId).ArchiveRegion(options);
} }
public void DearchiveRegion(string loadPath) public void DearchiveRegion(string loadPath)
@ -193,9 +195,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId) public void DearchiveRegion(string loadPath, bool merge, bool skipAssets, Guid requestId)
{ {
m_log.InfoFormat( m_log.InfoFormat(
"[ARCHIVER]: Loading archive to region {0} from {1}", m_scene.RegionInfo.RegionName, loadPath); "[ARCHIVER]: Loading archive to region {0} from {1}", Scene.RegionInfo.RegionName, loadPath);
new ArchiveReadRequest(m_scene, loadPath, merge, skipAssets, requestId).DearchiveRegion(); new ArchiveReadRequest(Scene, loadPath, merge, skipAssets, requestId).DearchiveRegion();
} }
public void DearchiveRegion(Stream loadStream) public void DearchiveRegion(Stream loadStream)
@ -205,7 +207,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId) public void DearchiveRegion(Stream loadStream, bool merge, bool skipAssets, Guid requestId)
{ {
new ArchiveReadRequest(m_scene, loadStream, merge, skipAssets, requestId).DearchiveRegion(); new ArchiveReadRequest(Scene, loadStream, merge, skipAssets, requestId).DearchiveRegion();
} }
} }
} }

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenSim.Region.Framework.Scenes;
using System.IO;
using OpenMetaverse;
namespace OpenSim.Region.Framework.Interfaces
{
public interface IRegionCombinerModule
{
/// <summary>
/// Is this simulator hosting a megaregion?
/// </summary>
/// <value></value>
bool IsMegaregion { get; }
/// <summary>
/// Does the given id belong to the root region of the megaregion?
/// </summary>
bool IsRootRegion(UUID sceneId);
}
}

View File

@ -43,9 +43,8 @@ using Mono.Addins;
[assembly: AddinDependency("OpenSim", "0.5")] [assembly: AddinDependency("OpenSim", "0.5")]
namespace OpenSim.Region.RegionCombinerModule namespace OpenSim.Region.RegionCombinerModule
{ {
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
public class RegionCombinerModule : ISharedRegionModule public class RegionCombinerModule : ISharedRegionModule, IRegionCombinerModule
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -59,6 +58,15 @@ namespace OpenSim.Region.RegionCombinerModule
get { return null; } get { return null; }
} }
public bool IsMegaregion
{
get
{
lock (m_startingScenes)
return m_startingScenes.Count > 1;
}
}
private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>(); private Dictionary<UUID, RegionConnections> m_regions = new Dictionary<UUID, RegionConnections>();
private bool enabledYN = false; private bool enabledYN = false;
private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>(); private Dictionary<UUID, Scene> m_startingScenes = new Dictionary<UUID, Scene>();
@ -69,9 +77,11 @@ namespace OpenSim.Region.RegionCombinerModule
enabledYN = myConfig.GetBoolean("CombineContiguousRegions", false); enabledYN = myConfig.GetBoolean("CombineContiguousRegions", false);
if (enabledYN) if (enabledYN)
{
MainConsole.Instance.Commands.AddCommand( MainConsole.Instance.Commands.AddCommand(
"RegionCombinerModule", false, "fix-phantoms", "fix-phantoms", "RegionCombinerModule", false, "fix-phantoms", "fix-phantoms",
"Fixes phantom objects after an import to megaregions", FixPhantoms); "Fixes phantom objects after an import to megaregions", FixPhantoms);
}
} }
public void Close() public void Close()
@ -80,6 +90,8 @@ namespace OpenSim.Region.RegionCombinerModule
public void AddRegion(Scene scene) public void AddRegion(Scene scene)
{ {
if (enabledYN)
scene.RegisterModuleInterface<IRegionCombinerModule>(this);
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -96,6 +108,12 @@ namespace OpenSim.Region.RegionCombinerModule
} }
} }
public bool IsRootRegion(UUID sceneId)
{
lock (m_regions)
return m_regions.ContainsKey(sceneId);
}
private void NewPresence(ScenePresence presence) private void NewPresence(ScenePresence presence)
{ {
if (presence.IsChildAgent) if (presence.IsChildAgent)