From 94c7e41ef1978a5be21e1a063c68ffc1c8a89b97 Mon Sep 17 00:00:00 2001 From: MW Date: Fri, 10 Aug 2007 13:59:19 +0000 Subject: Made a few changes so that once we enable the sqlite data store (simple line change in OpenSimMain), then basic ( with a few limits at moment) prim database backup will work. --- OpenSim/Region/ClientStack/ClientView.API.cs | 2 +- .../Region/ClientStack/RegionApplicationBase.cs | 2 +- OpenSim/Region/Environment/Scenes/Scene.cs | 33 +++++++------ .../Region/Environment/Scenes/SceneObjectGroup.cs | 56 ++++++++++++++++++++-- .../Region/Environment/Scenes/SceneObjectPart.cs | 8 ++++ OpenSim/Region/Environment/Scenes/ScenePresence.cs | 1 + .../MonoSqliteDataStore.cs | 49 +++++++++++++++---- 7 files changed, 123 insertions(+), 28 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index 8a2db98..81c20e8 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -844,7 +844,7 @@ namespace OpenSim.Region.ClientStack byte[] rot = rotation.GetBytes(); Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length); - + OutPacket(outPacket); } diff --git a/OpenSim/Region/ClientStack/RegionApplicationBase.cs b/OpenSim/Region/ClientStack/RegionApplicationBase.cs index c67ae66..05c970a 100644 --- a/OpenSim/Region/ClientStack/RegionApplicationBase.cs +++ b/OpenSim/Region/ClientStack/RegionApplicationBase.cs @@ -115,7 +115,7 @@ namespace OpenSim.Region.ClientStack scene.PhysScene = GetPhysicsScene( ); scene.PhysScene.SetTerrain(scene.Terrain.GetHeights1D()); - scene.LoadPrimsFromStorage(); + scene.LoadPrimsFromStorage(); //Master Avatar Setup UserProfileData masterAvatar = m_commsManager.UserServer.SetupMasterUser(scene.RegionInfo.MasterAvatarFirstName, scene.RegionInfo.MasterAvatarLastName, scene.RegionInfo.MasterAvatarSandboxPassword); diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index c2eac60..ef7346d 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -151,15 +151,6 @@ namespace OpenSim.Region.Environment.Scenes Avatars = new Dictionary(); Prims = new Dictionary(); - MainLog.Instance.Verbose("Loading objects from datastore"); - List PrimsFromDB = storageManager.DataStore.LoadObjects(); - foreach (SceneObjectGroup prim in PrimsFromDB) - { - AddEntity(prim); - } - MainLog.Instance.Verbose("Loaded " + PrimsFromDB.Count.ToString() + " object(s)"); - - MainLog.Instance.Verbose("Creating LandMap"); Terrain = new TerrainEngine((int)this.RegionInfo.RegionLocX, (int)this.RegionInfo.RegionLocY); @@ -238,7 +229,7 @@ namespace OpenSim.Region.Environment.Scenes //backup scene data storageCount++; - if (storageCount > 1200) //set to how often you want to backup + if (storageCount > 600) //set to how often you want to backup { Backup(); storageCount = 0; @@ -462,12 +453,13 @@ namespace OpenSim.Region.Environment.Scenes /// public void LoadPrimsFromStorage() { - MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives"); - List NewObjectsList = storageManager.DataStore.LoadObjects(); - foreach (SceneObjectGroup obj in NewObjectsList) + MainLog.Instance.Verbose("Loading objects from datastore"); + List PrimsFromDB = storageManager.DataStore.LoadObjects(); + foreach (SceneObjectGroup prim in PrimsFromDB) { - this.Objects.Add(obj.UUID, obj); + AddEntityFromStorage(prim); } + MainLog.Instance.Verbose("Loaded " + PrimsFromDB.Count.ToString() + " object(s)"); } /// @@ -520,6 +512,17 @@ namespace OpenSim.Region.Environment.Scenes } } + public void AddEntityFromStorage(SceneObjectGroup sceneObject) + { + sceneObject.RegionHandle = this.m_regionHandle; + sceneObject.SetScene(this); + foreach (SceneObjectPart part in sceneObject.Children.Values) + { + part.LocalID = this.PrimIDAllocate(); + } + this.AddEntity(sceneObject); + } + public void AddEntity(SceneObjectGroup sceneObject) { Entities.Add(sceneObject.UUID, sceneObject); @@ -781,7 +784,7 @@ namespace OpenSim.Region.Environment.Scenes { if (ent is SceneObjectGroup) { - // ((SceneObject) ent).SendAllChildPrimsToClient(client); + ((SceneObjectGroup) ent).SendFullUpdateToClient(client); } } } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 78dd69c..8b761f6 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -44,6 +44,27 @@ namespace OpenSim.Region.Environment.Scenes set { m_parts = value; } } + public SceneObjectPart RootPart + { + set { m_rootPart = value; } + } + + public ulong RegionHandle + { + get { return m_regionHandle; } + set + { + m_regionHandle = value; + lock (this.m_parts) + { + foreach (SceneObjectPart part in this.m_parts.Values) + { + part.RegionHandle = m_regionHandle; + } + } + } + } + public override LLVector3 Pos { get { return m_rootPart.GroupPosition; } @@ -79,9 +100,9 @@ namespace OpenSim.Region.Environment.Scenes /// /// Added because the Parcel code seems to use it /// but not sure a object should have this - /// as what does it tell us? that some avatar has selected it + /// as what does it tell us? that some avatar has selected it (but not what Avatar/user) /// think really there should be a list (or whatever) in each scenepresence - /// saying what prim(s) that user has selected at any time. + /// saying what prim(s) that user has selected. /// protected bool m_isSelected = false; public bool IsSelected @@ -114,7 +135,7 @@ namespace OpenSim.Region.Environment.Scenes m_regionHandle = regionHandle; m_scene = scene; - this.Pos = pos; + // this.Pos = pos; LLVector3 rootOffset = new LLVector3(0, 0, 0); SceneObjectPart newPart = new SceneObjectPart(m_regionHandle, this, ownerID, localID, shape, pos, rootOffset); this.m_parts.Add(newPart.UUID, newPart); @@ -136,6 +157,7 @@ namespace OpenSim.Region.Environment.Scenes dupe.m_regionHandle = this.m_regionHandle; dupe.CopyRootPart(this.m_rootPart); + m_scene.EventManager.OnBackup += dupe.ProcessBackup; foreach (SceneObjectPart part in this.m_parts.Values) { @@ -148,6 +170,23 @@ namespace OpenSim.Region.Environment.Scenes } /// + /// Added as a way for the storage provider to reset the scene, + /// most likely a better way to do this sort of thing but for now... + /// + /// + public void SetScene(Scene scene) + { + m_scene = scene; + m_scene.EventManager.OnBackup += this.ProcessBackup; + } + + public void AddPart(SceneObjectPart part) + { + part.SetParent(this); + this.m_parts.Add(part.UUID, part); + } + + /// /// /// /// @@ -619,6 +658,17 @@ namespace OpenSim.Region.Environment.Scenes return m_scene.RequestAvatarList(); } + public void SendFullUpdateToClient(IClientAPI remoteClient) + { + lock (this.m_parts) + { + foreach (SceneObjectPart part in this.m_parts.Values) + { + this.SendPartFullUpdate(remoteClient, part); + } + } + } + /// /// /// diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 5e62082..1b373aa 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -249,6 +249,14 @@ namespace OpenSim.Region.Environment.Scenes } #endregion + /// + /// + /// + public void SetParent(SceneObjectGroup parent) + { + m_parentGroup = parent; + } + #region Copying /// /// diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index b021b44..114623a 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -556,6 +556,7 @@ namespace OpenSim.Region.Environment.Scenes } } #endregion + #region Border Crossing Methods /// /// diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index 66ca56d..18ff54d 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using System.IO; using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.LandManagement; @@ -8,11 +9,12 @@ using OpenSim.Region.Environment; using OpenSim.Region.Interfaces; using OpenSim.Framework.Console; using OpenSim.Framework.Types; +using OpenSim.Framework.Utilities; using libsecondlife; using System.Data; using System.Data.SqlTypes; -// Yes, this won't compile on MS, need to deal with that later + using Mono.Data.SqliteClient; namespace OpenSim.DataStore.MonoSqliteStorage @@ -47,6 +49,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage // TODO: see if the linkage actually holds. // primDa.FillSchema(ds, SchemaType.Source, "PrimSchema"); primDa.Fill(ds, "prims"); + shapeDa.Fill(ds, "primshapes"); ds.AcceptChanges(); DataTable prims = ds.Tables["prims"]; @@ -54,7 +57,6 @@ namespace OpenSim.DataStore.MonoSqliteStorage setupPrimCommands(primDa, conn); // shapeDa.FillSchema(ds, SchemaType.Source, "ShapeSchema"); - shapeDa.Fill(ds, "primshapes"); DataTable shapes = ds.Tables["primshapes"]; shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] }; setupShapeCommands(shapeDa, conn); @@ -378,6 +380,11 @@ namespace OpenSim.DataStore.MonoSqliteStorage // text TODO: this isn't right] = but I'm not sure the right // way to specify this as a blob atm // s.TextureEntry = (byte[])row["Texture"]; + + //following hack will only save the default face texture, any other textures on other faces + //won't be saved or restored. + LLObject.TextureEntry texture = new LLObject.TextureEntry( new LLUUID((string)row["Texture"])); + s.TextureEntry = texture.ToBytes(); return s; } @@ -414,7 +421,15 @@ namespace OpenSim.DataStore.MonoSqliteStorage row["ProfileHollow"] = s.ProfileHollow; // text TODO: this isn't right] = but I'm not sure the right // way to specify this as a blob atm - row["Texture"] = s.TextureEntry; + + // And I couldn't work out how to save binary data either + // seems that the texture colum is being treated as a string in the Datarow + // if you do a .getType() on it, it returns string, while the other columns return correct type + //following hack will only save the default face texture, any other textures on other faces + //won't be saved or restored. + // MW[10-08-07] + LLObject.TextureEntry text = new LLObject.TextureEntry(s.TextureEntry, 0, s.TextureEntry.Length); + row["Texture"] = text.DefaultTexture.TextureID.ToStringHyphenated(); } @@ -449,9 +464,10 @@ namespace OpenSim.DataStore.MonoSqliteStorage addPrim(prim); } - MainLog.Instance.Verbose("Attempting to do update...."); + MainLog.Instance.Verbose("Attempting to do database update...."); primDa.Update(ds, "prims"); - MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); + shapeDa.Update(ds, "primshapes"); + // MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); } public void RemoveObject(LLUUID obj) @@ -472,15 +488,23 @@ namespace OpenSim.DataStore.MonoSqliteStorage SceneObjectGroup group = new SceneObjectGroup(); SceneObjectPart prim = buildPrim(primRow); DataRow shapeRow = shapes.Rows.Find(prim.UUID); - if (shapeRow != null) { + if (shapeRow != null) + { prim.Shape = buildShape(shapeRow); } - group.Children.Add(prim.UUID, prim); + else + { + Console.WriteLine("No shape found for prim in storage, so setting default box shape"); + prim.Shape = BoxShape.Default; + } + group.AddPart(prim); // TODO: there are a couple of known issues to get this to work // * While we can add Children, we can't set the root part (or // or even figure out which should be the root part) // * region handle may need to be persisted, it isn't now - // retvals.Add(group); + group.RootPart = prim; + + retvals.Add(group); } MainLog.Instance.Verbose("DATASTORE", "Sqlite - LoadObjects found " + prims.Rows.Count + " objects"); @@ -517,5 +541,14 @@ namespace OpenSim.DataStore.MonoSqliteStorage { // TODO: DataSet commit } + + private void SaveAssetToFile(string filename, byte[] data) + { + FileStream fs = File.Create(filename); + BinaryWriter bw = new BinaryWriter(fs); + bw.Write(data); + bw.Close(); + fs.Close(); + } } } -- cgit v1.1