Add options to OAR handling to allow disabling use of a defaultUser if no local user is found and to resolve from an alias if one is defined. Default should work as an oar currently does.

This commit is contained in:
Mike Dickson 2024-09-20 16:15:48 -04:00
parent d978ab12b4
commit cfd4742a29
4 changed files with 132 additions and 41 deletions

View file

@ -1645,8 +1645,8 @@ namespace OpenSim.ApplicationPlugins.RemoteController
bool mergeOar = false;
bool skipAssets = false;
// bool lookupAliases = false;
// bool allowReassign = false;
bool lookupAliases = false;
bool noDefaultUser = false;
if ((string)requestData["merge"] == "true")
{
@ -1656,22 +1656,22 @@ namespace OpenSim.ApplicationPlugins.RemoteController
{
skipAssets = true;
}
// if ((string)requestData["lookup-aliases"] == "true")
// {
// lookupAliases = true;
// }
// if ((string)requestData["allow-reassign"] == "true")
// {
// allowReassign = true;
// }
if ((string)requestData["lookup-aliases"] == "true")
{
lookupAliases = true;
}
if ((string)requestData["no-defaultuser"] == "true")
{
noDefaultUser = true;
}
IRegionArchiverModule archiver = scene.RequestModuleInterface<IRegionArchiverModule>();
Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
if (mergeOar) archiveOptions.Add("merge", null);
if (skipAssets) archiveOptions.Add("skipAssets", null);
// if (lookupAliases) archiveOptions.Add("lookupAliases", null);
// if (allowReassign) archiveOptions.Add("allowReassign", null);
if (lookupAliases) archiveOptions.Add("lookup-aliases", null);
if (noDefaultUser) archiveOptions.Add("no-defaultuser", null);
if (archiver != null)
archiver.DearchiveRegion(filename, Guid.Empty, archiveOptions);

View file

@ -280,11 +280,16 @@ namespace OpenSim
SavePrimsXml2);
m_console.Commands.AddCommand("Archiving", false, "load oar",
"load oar [-m|--merge] [-s|--skip-assets]"
"load oar"
+ " [-m|--merge]"
+ " [-s|--skip-assets]"
+ " [--default-user \"User Name\"]"
+ " [--merge-terrain] [--merge-parcels]"
+ " [--merge-terrain]"
+ " [--merge-parcels]"
+ " [--mergeReplaceObjects]"
+ " [--no-objects]"
+ " [--no-defaultuser]"
+ " [--lookup-aliases]"
+ " [--rotation degrees]"
+ " [--bounding-origin \"<x,y,z>\"]"
+ " [--bounding-size \"<x,y,z>\"]"
@ -299,9 +304,9 @@ namespace OpenSim
+ " --mergeReplaceObjects if scene as a object with same id, replace it\n"
+ " without this option, skip loading that object\n"
+ "--skip-assets will load the OAR but ignore the assets it contains.\n"
// + "--lookup-aliases will lookup aliases for local users and update creator/owner/last owner information accordingly.\n"
// + "--allow-reassign allow reassignment of creator/owner/lastowner to the region owner/default user\n"
// + " if no local user (or alias) is found. Default is false\n"
+ "--no-defaultuser don't perform reassignment of creator/owner/lastowner to the region owner/default user\n"
+ " if no local user (or alias if enabled) is found.\n"
+ "--lookup-aliases will lookup aliases for local users and update creator/owner/last owner information accordingly.\n"
+ "--default-user will use this user for any objects with an owner whose UUID is not found in the grid.\n"
+ "--no-objects suppresses the addition of any objects (good for loading only the terrain).\n"
+ "--rotation specified rotation to be applied to the oar. Specified in degrees.\n"

View file

@ -25,11 +25,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Reflection;
using System.Text;
using System.Xml;
@ -39,13 +35,11 @@ using OpenSim.Framework;
using OpenSim.Framework.Monitoring;
using OpenSim.Framework.Serialization;
using OpenSim.Framework.Serialization.External;
using OpenSim.Region.CoreModules.World.Terrain;
using OpenSim.Region.CoreModules.World.Land;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes;
using OpenSim.Region.Framework.Scenes.Serialization;
using OpenSim.Services.Interfaces;
using System.Threading;
namespace OpenSim.Region.CoreModules.World.Archiver
{
@ -156,7 +150,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
/// Used to cache lookups for valid uuids.
/// </summary>
private readonly Dictionary<UUID, bool> m_validUserUuids = new();
private IUserManagement m_UserMan;
private IUserManagement UserManager
{
@ -178,6 +172,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver
private UUID m_defaultUser;
protected bool m_noDefaultUser = false;
protected bool m_lookupAliases = false;
private IUserAliasService m_UserAliasService = null;
private IUserAliasService UserAliasService
{
get
{
m_UserAliasService ??= m_rootScene.RequestModuleInterface<IUserAliasService>();
return m_UserAliasService;
}
}
/// <summary>
/// Cache aliased user lookups since we will likely have many instances
/// </summary>
private readonly Dictionary<UUID, UserAlias> m_userAliases = new();
public ArchiveReadRequest(Scene scene, string loadPath, Guid requestId, Dictionary<string, object> options)
{
m_rootScene = scene;
@ -213,6 +227,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_mergeParcels = options.ContainsKey("merge-parcels");
m_noObjects = options.ContainsKey("no-objects");
m_skipAssets = options.ContainsKey("skipAssets");
m_noDefaultUser = options.ContainsKey("no-defaultuser");
m_lookupAliases = options.ContainsKey("lookup-aliases");
m_requestId = requestId;
m_displacement = options.ContainsKey("displacement") ? (Vector3)options["displacement"] : Vector3.Zero;
m_rotation = options.ContainsKey("rotation") ? (float)options["rotation"] : 0f;
@ -274,6 +292,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_requestId = requestId;
m_defaultUser = scene.RegionInfo.EstateSettings.EstateOwner;
m_noDefaultUser = options.ContainsKey("no-defaultuser");
m_lookupAliases = options.ContainsKey("lookup-aliases");
// Zero can never be a valid user id
m_validUserUuids[UUID.Zero] = false;
@ -770,24 +790,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver
{
if (string.IsNullOrEmpty(part.CreatorData))
{
if (!ResolveUserUuid(scene, part.CreatorID))
part.CreatorID = m_defaultUser;
// Creators can't be groups.
part.CreatorID = ResolveUserAliasOrDefault(scene, part.CreatorID, checkGroup: false);
}
if (UserManager is not null)
{
UserManager.AddCreatorUser(part.CreatorID, part.CreatorData);
}
if (!(ResolveUserUuid(scene, part.OwnerID) || ResolveGroupUuid(part.OwnerID)))
part.OwnerID = m_defaultUser;
part.OwnerID = ResolveUserAliasOrDefault(scene, part.OwnerID, checkGroup: true);
part.LastOwnerID = ResolveUserAliasOrDefault(scene, part.LastOwnerID, checkGroup: true);
if (!(ResolveUserUuid(scene, part.LastOwnerID) || ResolveGroupUuid(part.LastOwnerID)))
part.LastOwnerID = m_defaultUser;
if (!ResolveGroupUuid(part.GroupID))
// If there is no matching local group initialize it to a null key
if (ResolveGroupUuid(part.GroupID) is false)
part.GroupID = UUID.Zero;
// And zap any troublesome sit target information
// part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
// part.SitTargetPosition = new Vector3(0, 0, 0);
// part.SitTargetOrientation = new Quaternion(0, 0, 0, 1);
// part.SitTargetPosition = new Vector3(0, 0, 0);
// Fix ownership/creator of inventory items
// Not doing so results in inventory items
@ -802,23 +823,23 @@ namespace OpenSim.Region.CoreModules.World.Archiver
TaskInventoryDictionary inv = part.TaskInventory;
foreach (KeyValuePair<UUID, TaskInventoryItem> kvp in inv)
{
if (!(ResolveUserUuid(scene, kvp.Value.OwnerID) || ResolveGroupUuid(kvp.Value.OwnerID)))
{
kvp.Value.OwnerID = m_defaultUser;
}
if (string.IsNullOrEmpty(kvp.Value.CreatorData))
{
if (!ResolveUserUuid(scene, kvp.Value.CreatorID))
kvp.Value.CreatorID = m_defaultUser;
// Creator can't be a group
kvp.Value.CreatorID = ResolveUserAliasOrDefault(scene, kvp.Value.CreatorID, checkGroup: false);
}
if (UserManager is not null)
{
UserManager.AddCreatorUser(kvp.Value.CreatorID, kvp.Value.CreatorData);
}
kvp.Value.OwnerID = ResolveUserAliasOrDefault(scene, kvp.Value.OwnerID, checkGroup: true);
if (!ResolveGroupUuid(kvp.Value.GroupID))
kvp.Value.GroupID = UUID.Zero;
}
part.TaskInventory.LockItemsForRead(false);
}
}
@ -1028,6 +1049,59 @@ namespace OpenSim.Region.CoreModules.World.Archiver
}
}
/// <summary>
/// Look up and return the original user, the default user or a user alias if one is found
/// based on the options passed in at run time.
/// </summary>
/// <param name="scene">The scene we are loading this OAR into.</param>
/// <param name="aliasID">The id we are locally for locally or as an alias</param>
/// <param name="checkGroup">The incoming ID may be a group so check for that as well</param>
/// <returns>UUID - the ID to use based on incoming ID and settings</returns>
private UUID ResolveUserAliasOrDefault(Scene scene, UUID aliasID, bool checkGroup)
{
if (ResolveUserUuid(scene, aliasID) is true)
{
return aliasID;
}
if (checkGroup && ResolveGroupUuid(aliasID) is true)
{
return aliasID;
}
if (m_lookupAliases is true)
{
UserAlias aliasUser = null;
lock (m_userAliases)
{
if (m_userAliases.TryGetValue(aliasID, out aliasUser) is false)
{
aliasUser = UserAliasService?.GetUserForAlias(aliasID);
if (aliasUser is not null)
{
m_userAliases[aliasID] = aliasUser;
}
}
}
if (aliasUser != null)
{
if (ResolveUserUuid(scene, aliasUser.UserID) is true)
return aliasUser.UserID;
}
}
if (m_noDefaultUser is false)
{
return m_defaultUser;
}
else
{
return aliasID;
}
}
private bool TryUploadAsset(UUID assetID, sbyte assetType, byte[] data)
{
if (assetType == (sbyte)AssetType.Unknown)

View file

@ -106,6 +106,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver
bool mergeTerrain = false;
bool mergeParcels = false;
bool noObjects = false;
bool noDefaultUser = false;
bool lookupAliases = false;
Vector3 displacement = new Vector3(0f, 0f, 0f);
String defaultUser = "";
float rotation = 0f;
@ -115,6 +118,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
bool debug = false;
OptionSet options = new OptionSet();
options.Add("m|merge", delegate(string v) { mergeOar = (v != null); });
options.Add("mergeReplaceObjects", delegate (string v) { mergeReplaceObjects = (v != null); });
options.Add("s|skip-assets", delegate(string v) { skipAssets = (v != null); });
@ -126,6 +130,8 @@ namespace OpenSim.Region.CoreModules.World.Archiver
options.Add("forceparcels", delegate (string v) { mergeParcels = (v != null); }); // downward compatibility
options.Add("no-objects", delegate(string v) { noObjects = (v != null); });
options.Add("default-user=", delegate(string v) { defaultUser = (v == null) ? "" : v; });
options.Add("no-defaultuser", delegate(string v) { noDefaultUser = (v != null); });
options.Add("lookup-aliases", delegate(string v) { lookupAliases = (v != null); });
options.Add("displacement=", delegate(string v)
{
try
@ -151,6 +157,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
m_log.ErrorFormat("[ARCHIVER MODULE] Must be an angle in degrees between -360 and +360: --rotation 45");
return;
}
//pass this in as degrees now, convert to radians later during actual work phase
rotation = Math.Clamp(rotation, -359f, 359f);
});
@ -214,6 +221,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver
// m_log.DebugFormat("GOT PARAM [{0}]", param);
Dictionary<string, object> archiveOptions = new Dictionary<string, object>();
if (mergeOar) archiveOptions.Add("merge", null);
if (skipAssets) archiveOptions.Add("skipAssets", null);
if (mergeReplaceObjects) archiveOptions.Add("mReplaceObjects", null);
@ -241,11 +249,15 @@ namespace OpenSim.Region.CoreModules.World.Archiver
archiveOptions.Add("default-user", defaultUserUUID);
}
}
if (noDefaultUser) archiveOptions.Add("no-defaultuser", null);
if (lookupAliases) archiveOptions.Add("lookup-aliases", null);
archiveOptions.Add("displacement", displacement);
archiveOptions.Add("rotation", rotation);
archiveOptions.Add("rotation-center", rotationCenter);
archiveOptions.Add("bounding-origin", boundingOrigin);
archiveOptions.Add("bounding-size", boundingSize);
if (debug) archiveOptions.Add("debug", null);
if (mainParams.Count > 2)