From 3e75dede1b744fa9a6b7cad00039620de01fb2e2 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Mon, 7 Jan 2008 02:12:06 +0000 Subject: Persistent prim inventory phase 5. Restart scripts contained in persisted prims on region start. No user functionality exposed yet - no ini switch to enable persistence or restore. A bit more initial work to do. --- OpenSim/Region/Application/OpenSimMain.cs | 11 ++--- OpenSim/Region/Environment/Scenes/EntityBase.cs | 7 +++- .../Region/Environment/Scenes/Scene.Inventory.cs | 13 ++++++ OpenSim/Region/Environment/Scenes/Scene.cs | 8 ++-- OpenSim/Region/Environment/Scenes/SceneBase.cs | 4 +- .../Scenes/SceneObjectGroup.Inventory.cs | 15 ++++++- .../Scenes/SceneObjectPart.Inventory.cs | 48 ++++++++++++++++++++++ .../Region/Environment/Scenes/SceneObjectPart.cs | 32 +++++++-------- .../MonoSqliteDataStore.cs | 2 +- 9 files changed, 111 insertions(+), 29 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index f4e774b..c653192 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -426,23 +426,24 @@ namespace OpenSim UDPServer udpServer; Scene scene = SetupScene(regionInfo, out udpServer, m_permissions); - MainLog.Instance.Verbose("MODULES", "Loading Region's Modules"); + MainLog.Instance.Verbose("MODULES", "Loading Region's modules"); m_moduleLoader.PickupModules(scene, "."); //m_moduleLoader.PickupModules(scene, "ScriptEngines"); //m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); MainLog.Instance.Verbose("MODULES", "Loading scripting engine modules"); - m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); - - + m_moduleLoader.LoadRegionModules(Path.Combine("ScriptEngines", m_scriptEngine), scene); m_moduleLoader.InitialiseSharedModules(scene); scene.SetModuleInterfaces(); //Server side object editing permissions checking scene.PermissionsMngr.BypassPermissions = !m_permissions; + + // We need to do this after we've initialized the scripting engines. + scene.StartScripts(); - m_sceneManager.Add(scene); + m_sceneManager.Add(scene); m_udpServers.Add(udpServer); m_regionData.Add(regionInfo); diff --git a/OpenSim/Region/Environment/Scenes/EntityBase.cs b/OpenSim/Region/Environment/Scenes/EntityBase.cs index 18799e4..82f829d 100644 --- a/OpenSim/Region/Environment/Scenes/EntityBase.cs +++ b/OpenSim/Region/Environment/Scenes/EntityBase.cs @@ -36,7 +36,12 @@ namespace OpenSim.Region.Environment.Scenes { protected List m_children; - public Scene m_scene; + protected Scene m_scene; + + public Scene Scene + { + get { return m_scene; } + } public LLUUID m_uuid; diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 5b46040..f3673fc 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -37,6 +37,19 @@ namespace OpenSim.Region.Environment.Scenes { public partial class Scene { + /// + /// Start all the scripts in the scene which should be started. + /// + public void StartScripts() + { + MainLog.Instance.Verbose("PRIMINVENTORY", "Starting scripts in scene"); + + foreach (SceneObjectGroup group in Entities.Values) + { + group.StartScripts(); + } + } + //split these method into this partial as a lot of these (hopefully) are only temporary and won't be needed once Caps is more complete // or at least some of they can be moved somewhere else diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 215d30d..4156584 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -890,11 +890,12 @@ namespace OpenSim.Region.Environment.Scenes public virtual void LoadPrimsFromStorage(bool m_permissions) { MainLog.Instance.Verbose("SCENE", "Loading objects from datastore"); + List PrimsFromDB = m_storageManager.DataStore.LoadObjects(m_regInfo.RegionID); - foreach (SceneObjectGroup prim in PrimsFromDB) + foreach (SceneObjectGroup group in PrimsFromDB) { - AddEntityFromStorage(prim); - SceneObjectPart rootPart = prim.GetChildPart(prim.UUID); + AddEntityFromStorage(group); + SceneObjectPart rootPart = group.GetChildPart(group.UUID); rootPart.ApplySanePermissions(); bool UsePhysics = (((rootPart.ObjectFlags & (uint) LLObject.ObjectFlags.Physics) > 0) && m_physicalPrim); @@ -909,6 +910,7 @@ namespace OpenSim.Region.Environment.Scenes rootPart.RotationOffset.Y, rootPart.RotationOffset.Z), UsePhysics); rootPart.DoPhysicsPropertyUpdate(UsePhysics, true); } + MainLog.Instance.Verbose("SCENE", "Loaded " + PrimsFromDB.Count.ToString() + " SceneObject(s)"); } diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs index bf8bedc..d4a4bb0 100644 --- a/OpenSim/Region/Environment/Scenes/SceneBase.cs +++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs @@ -54,7 +54,6 @@ namespace OpenSim.Region.Environment.Scenes protected ulong m_regionHandle; protected string m_regionName; protected RegionInfo m_regInfo; - protected RegionStatus m_regStatus; public TerrainEngine Terrain; @@ -68,6 +67,7 @@ namespace OpenSim.Region.Environment.Scenes protected string m_datastore; private uint m_nextLocalId = 8880000; + private AssetCache m_assetCache; public AssetCache AssetCache @@ -75,6 +75,8 @@ namespace OpenSim.Region.Environment.Scenes get { return m_assetCache; } set { m_assetCache = value; } } + + protected RegionStatus m_regStatus; public RegionStatus Region_Status { diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs index 046e05b..50e3fa7 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.Inventory.cs @@ -37,7 +37,18 @@ using OpenSim.Region.Environment.Interfaces; namespace OpenSim.Region.Environment.Scenes { public partial class SceneObjectGroup : EntityBase - { + { + /// + /// Start the scripts contained in all the prims in this group. + /// + public void StartScripts() + { + foreach (SceneObjectPart part in m_parts.Values) + { + part.StartScripts(); + } + } + /// /// /// @@ -131,6 +142,6 @@ namespace OpenSim.Region.Environment.Scenes return part.RemoveInventoryItem(remoteClient, localID, itemID); } return -1; - } + } } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs index aab2291..5f93986 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs @@ -33,6 +33,7 @@ using System.Xml.Serialization; using libsecondlife; using OpenSim.Framework; +using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes.Scripting; @@ -79,6 +80,53 @@ namespace OpenSim.Region.Environment.Scenes { get { return m_inventorySerial; } } + + + /// + /// Start all the scripts contained in this prim's inventory + /// + public void StartScripts() + { + foreach (TaskInventoryItem item in m_taskInventory.Values) + { + if ("lsltext" == item.type) + { + StartScript(item); + } + } + } + + /// + /// Start a script in this prim + /// + /// + /// true if script asset was found, false if it wasn't + public bool StartScript(TaskInventoryItem item) + { +// MainLog.Instance.Verbose( +// "PRIMINVENTORY", +// "Starting script {0}, {1} in prim {2}, {3}", +// item.name, item.item_id, Name, UUID); + + AssetBase rezAsset = m_parentGroup.Scene.AssetCache.GetAsset(item.asset_id, false); + + if (rezAsset != null) + { + string script = Helpers.FieldToUTF8String(rezAsset.Data); + m_parentGroup.Scene.EventManager.TriggerRezScript(LocalID, item.item_id, script); + + return true; + } + else + { + MainLog.Instance.Error( + "PRIMINVENTORY", + "Couldn't start script {0}, {1} since asset ID {2} could not be found", + item.name, item.item_id, item.asset_id); + } + + return false; + } /// /// Add an item to this prim's inventory. diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index f82771b..9a7f28e 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -172,10 +172,10 @@ namespace OpenSim.Region.Environment.Scenes { try { - //lock (m_parentGroup.m_scene.SyncRoot) + //lock (m_parentGroup.Scene.SyncRoot) //{ PhysActor.Position = new PhysicsVector(value.X, value.Y, value.Z); - m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); + m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); //} } catch (Exception e) @@ -225,10 +225,10 @@ namespace OpenSim.Region.Environment.Scenes { try { - //lock (m_scene.SyncRoot) + //lock (Scene.SyncRoot) //{ PhysActor.Orientation = new Quaternion(value.W, value.X, value.Y, value.Z); - m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); + m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); //} } catch (Exception ex) @@ -554,7 +554,7 @@ namespace OpenSim.Region.Environment.Scenes if (usePhysics) { - PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( + PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( Name, Shape, new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, @@ -1044,7 +1044,7 @@ namespace OpenSim.Region.Environment.Scenes { i += 46; //IsLocked = (data[i++] != 0) ? true : false; - usePhysics = ((data[i++] != 0) && m_parentGroup.m_scene.m_physicalPrim) ? true : false; + usePhysics = ((data[i++] != 0) && m_parentGroup.Scene.m_physicalPrim) ? true : false; //System.Console.WriteLine("U" + packet.ToBytes().Length.ToString()); IsTemporary = (data[i++] != 0) ? true : false; IsPhantom = (data[i++] != 0) ? true : false; @@ -1079,8 +1079,8 @@ namespace OpenSim.Region.Environment.Scenes AddFlag(LLObject.ObjectFlags.Phantom); if (PhysActor != null) { - m_parentGroup.m_scene.PhysicsScene.RemovePrim(PhysActor); - /// that's not wholesome. Had to make m_scene public + m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); + /// that's not wholesome. Had to make Scene public PhysActor = null; } } @@ -1089,7 +1089,7 @@ namespace OpenSim.Region.Environment.Scenes RemFlag(LLObject.ObjectFlags.Phantom); if (PhysActor == null) { - PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( + PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( Name, Shape, new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, @@ -1127,7 +1127,7 @@ namespace OpenSim.Region.Environment.Scenes if (PhysActor.IsPhysical) { if (!isNew) - ParentGroup.m_scene.RemovePhysicalPrim(1); + ParentGroup.Scene.RemovePhysicalPrim(1); PhysActor.OnRequestTerseUpdate -= PhysicsRequestingTerseUpdate; PhysActor.OnOutOfBounds -= PhysicsOutOfBounds; @@ -1135,14 +1135,14 @@ namespace OpenSim.Region.Environment.Scenes PhysActor.IsPhysical = UsePhysics; // If we're not what we're supposed to be in the physics scene, recreate ourselves. - //m_parentGroup.m_scene.PhysicsScene.RemovePrim(PhysActor); - /// that's not wholesome. Had to make m_scene public + //m_parentGroup.Scene.PhysicsScene.RemovePrim(PhysActor); + /// that's not wholesome. Had to make Scene public //PhysActor = null; if ((ObjectFlags & (uint) LLObject.ObjectFlags.Phantom) == 0) { - //PhysActor = m_parentGroup.m_scene.PhysicsScene.AddPrimShape( + //PhysActor = m_parentGroup.Scene.PhysicsScene.AddPrimShape( //Name, //Shape, //new PhysicsVector(AbsolutePosition.X, AbsolutePosition.Y, @@ -1152,14 +1152,14 @@ namespace OpenSim.Region.Environment.Scenes //RotationOffset.Y, RotationOffset.Z), UsePhysics); if (UsePhysics) { - ParentGroup.m_scene.AddPhysicalPrim(1); + ParentGroup.Scene.AddPhysicalPrim(1); PhysActor.OnRequestTerseUpdate += PhysicsRequestingTerseUpdate; PhysActor.OnOutOfBounds += PhysicsOutOfBounds; } } } - m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); + m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); } } @@ -1517,7 +1517,7 @@ namespace OpenSim.Region.Environment.Scenes MainLog.Instance.Verbose("PHYSICS", "Physical Object went out of bounds."); RemFlag(LLObject.ObjectFlags.Physics); DoPhysicsPropertyUpdate(false, true); - m_parentGroup.m_scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); + m_parentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(PhysActor); } public virtual void OnGrab(LLVector3 offsetPos, IClientAPI remoteClient) diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index b99b819..ac22b42 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -243,7 +243,7 @@ namespace OpenSim.DataStore.MonoSqlite /// Load persisted objects from region storage. /// /// - /// + /// List of loaded groups public List LoadObjects(LLUUID regionUUID) { Dictionary createdObjects = new Dictionary(); -- cgit v1.1