Merge pull request #472: guarded NexRent parcel object return
Introduce opt-in, disabled-by-default OSSL baseline and selective tenant object return. Builds and DLL preflight passed; inworld activation remains gated.
This commit is contained in:
5 files changed
+243
No files matched your search
@@ -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,186 @@ 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<string> 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<NexRentObjectBaseline>(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<string> 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<NexRentObjectBaseline>(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<string> baseline = new(record.Existing, StringComparer.OrdinalIgnoreCase);
|
||||
List<SceneObjectGroup> newTenantObjects = new();
|
||||
foreach (ISceneObject obj in land.GetSceneObjectGroups())
|
||||
{
|
||||
if (obj is not SceneObjectGroup group ||
|
||||
group.IsDeleted || group.IsAttachment ||
|
||||
group.OwnerID != tenantId)
|
||||
continue;
|
||||
// Selected objects cannot safely be returned yet; don't
|
||||
// discard the baseline and retry after deselection.
|
||||
if (group.IsSelected)
|
||||
return -6;
|
||||
// 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";
|
||||
|
||||
@@ -268,6 +268,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
||||
LSL_Integer osGetParcelDwell(vector pos);
|
||||
void osParcelJoin(vector pos1, vector pos2);
|
||||
void osParcelSubdivide(vector pos1, vector pos2);
|
||||
int osNexRentSnapshot(vector pos, LSL_String parcelUUID, LSL_String tenantUUID);
|
||||
int osNexRentReturnNewObjects(vector pos, LSL_String parcelUUID, LSL_String tenantUUID);
|
||||
void osSetParcelDetails(vector pos, LSL_List rules);
|
||||
void osParcelSetDetails(vector pos, LSL_List rules); // Deprecated
|
||||
|
||||
|
||||
@@ -143,6 +143,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int osNexRentSnapshot(vector pos, LSL_String parcelUUID, LSL_String tenantUUID)
|
||||
{
|
||||
return m_OSSL_Functions.osNexRentSnapshot(pos, parcelUUID, tenantUUID);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int osNexRentReturnNewObjects(vector pos, LSL_String parcelUUID, LSL_String tenantUUID)
|
||||
{
|
||||
return m_OSSL_Functions.osNexRentReturnNewObjects(pos, parcelUUID, tenantUUID);
|
||||
}
|
||||
|
||||
public void osSetParcelDetails(vector pos, LSL_List rules)
|
||||
{
|
||||
m_OSSL_Functions.osSetParcelDetails(pos, rules);
|
||||
|
||||
@@ -214,6 +214,9 @@
|
||||
Allow_osSetDynamicTextureURLBlend = ESTATE_MANAGER,ESTATE_OWNER
|
||||
Allow_osSetDynamicTextureURLBlendFace = ESTATE_MANAGER,ESTATE_OWNER
|
||||
Allow_osSetRot = false
|
||||
; NexRent destructive parcel object return: enable only on a test simulator.
|
||||
Allow_osNexRentSnapshot = false
|
||||
Allow_osNexRentReturnNewObjects = false
|
||||
Allow_osSetParcelDetails = ${OSSL|osslParcelO}ESTATE_MANAGER,ESTATE_OWNER
|
||||
|
||||
; ThreatLevel Severe
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
# NexRent – selektive Objektrückgabe (Gen 1, experimentell)
|
||||
|
||||
## Status
|
||||
|
||||
Nur im Branch `feature/nexrent-tenant-object-return` implementiert; **nicht produktiv freigegeben**. Der Code wurde unter .NET 10 kompiliert (0 Fehler/0 Warnungen). Ein Inworld-Test mit Inventarrückgabe und neu aufgebautem Simulator steht aus.
|
||||
|
||||
## Ablauf
|
||||
|
||||
1. NexRent-Webverwaltung bestätigt eine Mietbuchung. Das LSL-Skript muss die Parzelle über `PARCEL_UUID` und `PARCEL_POINT` identifizieren.
|
||||
2. **Vor** einem Eigentümerwechsel ruft die Mietbox `osNexRentSnapshot(PARCEL_POINT, PARCEL_UUID, TENANT_UUID)` auf. Die Funktion erzeugt eine persistente Baseline aller vorhandenen Prim-UUIDs auf dieser Parzelle (inklusive aller Child-Prims).
|
||||
3. Nur nach erfolgreicher Baseline-Speicherung erfolgt der bereits vorhandene Landtitelwechsel.
|
||||
4. Bei Vertragsende stellt die Mietbox **zuerst** den ursprünglichen Besitzer wieder her.
|
||||
5. Danach ruft sie `osNexRentReturnNewObjects(PARCEL_POINT, PARCEL_UUID, TENANT_UUID)` auf. Das Modul wählt nur Objektgruppen aus, deren Besitzer exakt dieser Mieter ist und die **keinen** vor Mietbeginn vorhandenen Prim enthalten. Nur diese Gruppen werden über den vorhandenen OpenSim-Inventar-Rückgabeweg zurückgegeben.
|
||||
6. Die Baseline-Datei wird erst nach erfolgreicher Rückgabeanforderung entfernt. Negative Rückgaben sind Fehler; die Mietbox soll dann den Lease-Escrow beibehalten und erneut versuchen.
|
||||
|
||||
## Sicherheitskontrollen
|
||||
|
||||
- Zugriff ausschließlich über OSSL ThreatLevel Severe und explizite Freigabe **je Funktion**.
|
||||
- Zusätzliche Prüfung: Skriptbesitzer ist Estate Owner/Manager, ist der ursprüngliche Parzelleneigentümer und nicht der Mieter.
|
||||
- Exakte `RegionID`, `GlobalParcelID`, `BoxID`, `OwnerID` und `TenantID` werden in der persistenten Baseline gebunden.
|
||||
- Vor dem Rückgeben muss der Landtitel bereits wieder beim ursprünglichen Eigentümer liegen.
|
||||
- Vorhandene Prims bleiben selbst dann geschützt, wenn sie nach Mietbeginn mit anderen Objekten verlinkt werden. Gemischte Linksets werden **nicht** automatisch zurückgegeben.
|
||||
- Objekte Dritter und sämtliche Objekte des ursprünglichen Eigentümers werden nie ausgewählt.
|
||||
- Keine automatische Rückgabe bei fehlender/inkonsistenter Baseline; keine stillschweigende Ersatz-Baseline.
|
||||
- Maximale automatische Rückgabe von 500 Objektgruppen pro Mietvorgang; größere Mengen benötigen administrative Prüfung.
|
||||
- Bei fehlenden Estate-Rechten, fremder Parzelle, Gruppenparzelle oder veränderter Eigentumszuordnung: keine Rückgabe.
|
||||
|
||||
## Konfiguration
|
||||
|
||||
In `bin/config-include/osslDefaultEnable.ini` bleiben die beiden Funktionen **deaktiviert**:
|
||||
|
||||
```ini
|
||||
Allow_osNexRentSnapshot = false
|
||||
Allow_osNexRentReturnNewObjects = false
|
||||
```
|
||||
|
||||
Erst nach lokalem Test auf einer dedizierten Testparzelle kann ein Betreiber beide Funktionen **gezielt für ESTATE_OWNER / ESTATE_MANAGER** freigeben. Das Mietbox-Skript v0.2.5-test benötigt dafür `PARCEL_RETURN_NEW_OBJECTS=1`; bis dahin bleibt dieser Wert `0`.
|
||||
|
||||
## Grenzen und nächste Schritte
|
||||
|
||||
- Die Baseline liegt pro Region/Parzelle in `ops-data/nexrent-parcel-snapshots`; diese Dateien sind Teil der Backups und dürfen bei einem Neustart nicht verloren gehen.
|
||||
- Im Moment stößt die Mietbox die Rückgabe an. Bei gelöschter Mietbox oder dauerhaftem Verbindungsabbruch gibt es noch keinen unabhängigen serverseitigen Ablaufwächter. Für regulären kommerziellen Betrieb muss ein autorisierter Estate-Watchdog hinzukommen.
|
||||
- Eine korrekt angeforderte Rückgabe ist nicht automatisch ein Nachweis, dass die Objekte im Inventar des Mieters angekommen sind; dies muss im Testviewer geprüft werden.
|
||||
- Zahlungen müssen serverseitig anhand des NV$-Ledgers belegt werden. Das vorhandene NexRent-PHP-Backend verlässt sich derzeit auf LSL-Ereignisse; das ist für produktive automatische Landoperationen noch keine ausreichende Grundlage.
|
||||
- Kein direkter Eingriff in die Produktionsdatenbank, keine Änderung bereits bestehender Landbesitzer und kein Neustart der 42 Regionen ist Teil dieses Branches.
|
||||
Reference in new issue
Block a user