From 110a9c4d7d478d2c1439971d28ce9c508b3f00da Mon Sep 17 00:00:00 2001 From: "OpenGenesis (EULA)" <153564363+opengenesislink@users.noreply.github.com> Date: Wed, 25 Nov 2026 16:18:32 +0100 Subject: [PATCH] feat(gen1): add guarded NexRent tenant parcel baseline and selective return OSSL API --- .../Shared/Api/Implementation/OSSL_Api.cs | 191 ++++++++++++++++-- 1 file changed, 179 insertions(+), 12 deletions(-) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 2bfa6c04..f78e736b 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -47,6 +47,8 @@ using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Security.Cryptography; +using System.IO; +using System.Text.Json; using GridRegion = OpenSim.Services.Interfaces.GridRegion; using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; @@ -1783,6 +1785,183 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api SetParcelDetails(pos, rules, functionName); } + + // NexRent safety: snapshot the scene before the paid tenant receives + // ownership; later return only new objects owned by that same tenant. + // Never exposed to ordinary scripts: Severe OSSL permission + estate + // authority + original ownership + exact parcel UUID are mandatory. + private sealed class NexRentObjectBaseline + { + public int Version { get; set; } = 1; + public string Region { get; set; } + public string Parcel { get; set; } + public string Owner { get; set; } + public string Tenant { get; set; } + public string Box { get; set; } + public List Existing { get; set; } + } + + private static readonly object m_NexRentSnapshotLock = new(); + + private static string NexRentSnapshotFile(UUID regionId, UUID parcelId) + { + string directory = Path.Combine(AppContext.BaseDirectory, + "ops-data", "nexrent-parcel-snapshots"); + Directory.CreateDirectory(directory); + return Path.Combine(directory, + regionId.ToString() + "_" + parcelId.ToString() + ".json"); + } + + private bool NexRentAuthorizedLand(LSL_Vector pos, string parcelText, + string tenantText, out ILandObject parcel, out UUID parcelId, + out UUID tenantId) + { + parcel = null; + parcelId = UUID.Zero; + tenantId = UUID.Zero; + if (!UUID.TryParse(parcelText, out parcelId) || parcelId.IsZero() || + !UUID.TryParse(tenantText, out tenantId) || tenantId.IsZero() || + tenantId.Equals(m_host.OwnerID) || + m_host.ParentGroup == null || + m_host.ParentGroup.IsAttachment || + World.RegionInfo.EstateSettings == null || + !World.RegionInfo.EstateSettings.IsEstateManagerOrOwner(m_host.OwnerID)) + return false; + parcel = World.LandChannel.GetLandObject((int)pos.x, (int)pos.y); + return parcel != null && + parcel.LandData.GlobalID.Equals(parcelId) && + !parcel.LandData.IsGroupOwned; + } + + public int osNexRentSnapshot(LSL_Vector pos, LSL_String parcelText, + LSL_String tenantText) + { + const string function = "osNexRentSnapshot"; + CheckThreatLevel(ThreatLevel.Severe, function); + if (!NexRentAuthorizedLand(pos, (string)parcelText, + (string)tenantText, out ILandObject land, + out UUID parcelId, out UUID tenantId) || + !land.LandData.OwnerID.Equals(m_host.OwnerID)) + { + OSSLShoutError("NexRent snapshot denied: invalid parcel/estate/ownership."); + return -1; + } + UUID boxId = m_host.ParentGroup.RootPart.UUID; + string path = NexRentSnapshotFile(World.RegionInfo.RegionID, parcelId); + lock (m_NexRentSnapshotLock) + { + if (File.Exists(path)) + { + NexRentObjectBaseline old; + try { old = JsonSerializer.Deserialize(File.ReadAllText(path)); } + catch { return -2; } + if (old == null || old.Version != 1 || + old.Parcel != parcelId.ToString() || + old.Region != World.RegionInfo.RegionID.ToString() || + old.Owner != m_host.OwnerID.ToString() || + old.Tenant != tenantId.ToString() || + old.Box != boxId.ToString()) + return -2; // a different lease must never overwrite baseline + return old.Existing?.Count ?? -2; + } + List baseline = new(); + foreach (ISceneObject obj in land.GetSceneObjectGroups()) + if (obj is SceneObjectGroup group && + !group.IsDeleted && !group.IsAttachment) + foreach (SceneObjectPart part in group.Parts) + baseline.Add(part.UUID.ToString()); + NexRentObjectBaseline record = new() + { + Region = World.RegionInfo.RegionID.ToString(), + Parcel = parcelId.ToString(), + Owner = m_host.OwnerID.ToString(), + Tenant = tenantId.ToString(), + Box = boxId.ToString(), + Existing = baseline + }; + string temp = path + "." + Guid.NewGuid().ToString("N") + ".tmp"; + try + { + File.WriteAllText(temp, JsonSerializer.Serialize(record)); + File.Move(temp, path, false); + } + catch (Exception e) + { + m_log.WarnFormat("[NEXRENT RETURN]: Snapshot persistence failed: {0}", e.Message); + return -3; + } + finally { if (File.Exists(temp)) File.Delete(temp); } + m_log.InfoFormat("[NEXRENT RETURN]: Captured baseline of {0} object IDs for parcel {1}.", + baseline.Count, parcelId); + return baseline.Count; + } + } + + public int osNexRentReturnNewObjects(LSL_Vector pos, LSL_String parcelText, + LSL_String tenantText) + { + const string function = "osNexRentReturnNewObjects"; + CheckThreatLevel(ThreatLevel.Severe, function); + if (!NexRentAuthorizedLand(pos, (string)parcelText, + (string)tenantText, out ILandObject land, + out UUID parcelId, out UUID tenantId) || + !land.LandData.OwnerID.Equals(m_host.OwnerID)) + { + OSSLShoutError("NexRent return denied: land must first be back with original owner."); + return -1; + } + lock (m_NexRentSnapshotLock) + { + string path = NexRentSnapshotFile(World.RegionInfo.RegionID, parcelId); + if (!File.Exists(path)) + return -2; + NexRentObjectBaseline record; + try { record = JsonSerializer.Deserialize(File.ReadAllText(path)); } + catch { return -2; } + if (record == null || record.Version != 1 || + record.Region != World.RegionInfo.RegionID.ToString() || + record.Parcel != parcelId.ToString() || + record.Owner != m_host.OwnerID.ToString() || + record.Tenant != tenantId.ToString() || + record.Box != m_host.ParentGroup.RootPart.UUID.ToString() || + record.Existing == null) + return -2; + HashSet baseline = new(record.Existing, StringComparer.OrdinalIgnoreCase); + List newTenantObjects = new(); + foreach (ISceneObject obj in land.GetSceneObjectGroups()) + { + if (obj is not SceneObjectGroup group || + group.IsDeleted || group.IsAttachment || group.IsSelected || + group.OwnerID != tenantId) + continue; + // A pre-existing prim might have been linked to another + // object. Never return a group containing ANY baseline part. + bool containsOldPart = false; + foreach (SceneObjectPart part in group.Parts) + if (baseline.Contains(part.UUID.ToString())) + { + containsOldPart = true; + break; + } + if (containsOldPart) + continue; + newTenantObjects.Add(group); + } + // A full batch is intentionally small. Retain baseline on failure. + if (newTenantObjects.Count > 500) + return -4; + if (newTenantObjects.Count > 0) + { + if (!World.returnObjects(newTenantObjects.ToArray(), null)) + return -5; + } + File.Delete(path); // never delete unless scene return accepted + m_log.InfoFormat("[NEXRENT RETURN]: Returned {0} newly rezzed tenant objects from parcel {1}; protected pre-existing objects.", + newTenantObjects.Count, parcelId); + return newTenantObjects.Count; + } + } + public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) { const string functionName = "osSetParcelDetails"; @@ -6636,15 +6815,3 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api blue = Math.Clamp(blue, 0f, 1.0f); return new LSL_Vector(1.0, green, blue); - } - - temp = 0.01f * (temp - 6000f); - float red = 1.897315f * MathF.Pow(temp, -0.346837f) + 0.0622044f; - red = Math.Clamp(red, 0, 1.0f); - - green = 1.261989f * MathF.Pow(temp, -0.251708f) + 0.200836f; - green = Math.Clamp(green, 0, 1.0f); - return new LSL_Vector(red, green, 1.0f); - } - } -} \ No newline at end of file