From c89db49f3cd3bbd60577eb5a1787ccf8dea930e3 Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 19 Aug 2007 13:35:20 +0000 Subject: Sqlite datastore should now save the textures and extraparams data (used by sculpties) correctly. [Really need to add a ExtraParams field to the sqlite database though, but for now I have combined their data so that we don't lose backward compatibility, know a couple of people have been using the datastore already]. Now have a rough day/night cycle (the movement of the sun needs to be made smoother but for now it is better than we had I think). Added dalien's patch (issue 294) for saving and loading prims to a xml file (think he will be modifying these to be import/export functions and maybe writing a xml datastore for backups). Some preliminary work on task inventory (ie object's/prim's inventory). Added place holder data for AvatarProperties (ie a avatar's profile). Should we store this sort of data on the user server or have another server for it (a normal webserver should work). Added a few more method to IClientAPI. Sure there is something I'm forgeting. --- OpenSim/Region/Application/Application.cs | 2 - OpenSim/Region/Application/OpenSimMain.cs | 24 +++- OpenSim/Region/ClientStack/ClientView.API.cs | 126 ++++++++++++++----- .../ClientStack/ClientView.ProcessPackets.cs | 24 +++- .../Environment/Scenes/Scene.PacketHandlers.cs | 21 +++- OpenSim/Region/Environment/Scenes/Scene.cs | 92 +++++++++++++- .../Region/Environment/Scenes/SceneObjectGroup.cs | 24 ++-- .../Region/Environment/Scenes/SceneObjectPart.cs | 101 +++++++++++++-- OpenSim/Region/Environment/Scenes/ScenePresence.cs | 3 +- .../Region/Examples/SimpleApp/MyNpcCharacter.cs | 8 ++ .../MonoSqliteDataStore.cs | 138 +++++++++++++++------ 11 files changed, 472 insertions(+), 91 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/Application/Application.cs b/OpenSim/Region/Application/Application.cs index f16aca8..5da699b 100644 --- a/OpenSim/Region/Application/Application.cs +++ b/OpenSim/Region/Application/Application.cs @@ -62,10 +62,8 @@ namespace OpenSim ArgvConfigSource configSource = new ArgvConfigSource(args); configSource.AddSwitch("Startup", "inifile"); - configSource.AddSwitch("Startup", "configfile"); configSource.AddSwitch("Startup", "gridmode"); configSource.AddSwitch("Startup", "physics"); - configSource.AddSwitch("Startup", "config"); configSource.AddSwitch("Startup", "noverbose"); OpenSimMain sim = new OpenSimMain(configSource); diff --git a/OpenSim/Region/Application/OpenSimMain.cs b/OpenSim/Region/Application/OpenSimMain.cs index 3fc6662..327a3c2 100644 --- a/OpenSim/Region/Application/OpenSimMain.cs +++ b/OpenSim/Region/Application/OpenSimMain.cs @@ -340,6 +340,28 @@ namespace OpenSim } break; + case "save-xml": + if (cmdparams.Length > 0) + { + m_localScenes[0].SavePrimsToXml(cmdparams[0]); + } + else + { + m_localScenes[0].SavePrimsToXml("test.xml"); + } + break; + + case "load-xml": + if (cmdparams.Length > 0) + { + m_localScenes[0].LoadPrimsFromXml(cmdparams[0]); + } + else + { + m_localScenes[0].LoadPrimsFromXml("test.xml"); + } + break; + case "terrain": string result = ""; foreach (Scene scene in m_localScenes) @@ -357,7 +379,7 @@ namespace OpenSim if (scene.RegionInfo.RegionName.ToLower() == cmdparams[0].ToLower()) { string[] tmpCmdparams = new string[cmdparams.Length - 1]; - cmdparams.CopyTo(tmpCmdparams,1); + cmdparams.CopyTo(tmpCmdparams, 1); if (!scene.Terrain.RunTerrainCmd(tmpCmdparams, ref result2, scene.RegionInfo.RegionName)) { diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index f655674..c67ecb5 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -74,9 +74,9 @@ namespace OpenSim.Region.ClientStack public event UpdatePrimSingleRotation OnUpdatePrimSingleRotation; public event UpdatePrimGroupRotation OnUpdatePrimGroupMouseRotation; public event UpdateVector OnUpdatePrimScale; - public event StatusChange OnChildAgentStatus; - public event GenericCall2 OnStopMovement; - public event GenericCall6 OnRemoveAvatar; + public event StatusChange OnChildAgentStatus; + public event GenericCall2 OnStopMovement; + public event GenericCall6 OnRemoveAvatar; public event RequestMapBlocks OnRequestMapBlocks; public event TeleportLocationRequest OnTeleportLocationRequest; public event DisconnectUser OnDisconnectUser; @@ -88,6 +88,7 @@ namespace OpenSim.Region.ClientStack public event RequestTaskInventory OnRequestTaskInventory; public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; + public event RequestXfer OnRequestXfer; public event UUIDNameRequest OnNameFromUUIDRequest; @@ -410,7 +411,7 @@ namespace OpenSim.Region.ClientStack newSimPack.RegionData.SimPort = (ushort)externalIPEndPoint.Port; //newSimPack.RegionData.SeedCapability = new byte[0]; newSimPack.RegionData.SeedCapability = Helpers.StringToField(capsURL); - + this.OutPacket(newSimPack); } @@ -463,7 +464,7 @@ namespace OpenSim.Region.ClientStack ip += (uint)byteIP[2] << 16; ip += (uint)byteIP[1] << 8; ip += (uint)byteIP[0]; - + teleport.Info.SimIP = ip; teleport.Info.SimPort = (ushort)newRegionEndPoint.Port; teleport.Info.LocationID = 4; @@ -510,9 +511,9 @@ namespace OpenSim.Region.ClientStack pc.PingID.PingID = seq; pc.Header.Reliable = false; OutPacket(pc); - + } - + public void SendKillObject(ulong regionHandle, uint localID) { KillObjectPacket kill = new KillObjectPacket(); @@ -526,7 +527,7 @@ namespace OpenSim.Region.ClientStack { Encoding enc = Encoding.ASCII; uint FULL_MASK_PERMISSIONS = 2147483647; - InventoryDescendentsPacket descend = new InventoryDescendentsPacket(); + InventoryDescendentsPacket descend = new InventoryDescendentsPacket(); descend.AgentData.AgentID = this.AgentId; descend.AgentData.OwnerID = ownerID; descend.AgentData.FolderID = folderID; @@ -542,22 +543,22 @@ namespace OpenSim.Region.ClientStack descend.ItemData[i].CreatorID = item.creatorsID; descend.ItemData[i].BaseMask = item.inventoryBasePermissions; descend.ItemData[i].CreationDate = 1000; - descend.ItemData[i].Description = enc.GetBytes(item.inventoryDescription+ "\0"); + descend.ItemData[i].Description = enc.GetBytes(item.inventoryDescription + "\0"); descend.ItemData[i].EveryoneMask = item.inventoryEveryOnePermissions; descend.ItemData[i].Flags = 1; descend.ItemData[i].FolderID = item.parentFolderID; descend.ItemData[i].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); descend.ItemData[i].GroupMask = 0; descend.ItemData[i].InvType = (sbyte)item.invType; - descend.ItemData[i].Name = enc.GetBytes(item.inventoryName+ "\0"); + descend.ItemData[i].Name = enc.GetBytes(item.inventoryName + "\0"); descend.ItemData[i].NextOwnerMask = item.inventoryNextPermissions; descend.ItemData[i].OwnerID = item.avatarID; descend.ItemData[i].OwnerMask = item.inventoryCurrentPermissions; descend.ItemData[i].SalePrice = 0; descend.ItemData[i].SaleType = 0; descend.ItemData[i].Type = (sbyte)item.assetType; - descend.ItemData[i].CRC = Helpers.InventoryCRC(1000, 0, descend.ItemData[i].InvType, descend.ItemData[i].Type, descend.ItemData[i].AssetID, descend.ItemData[i].GroupID, 100,descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID, descend.ItemData[i].ItemID, descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); - + descend.ItemData[i].CRC = Helpers.InventoryCRC(1000, 0, descend.ItemData[i].InvType, descend.ItemData[i].Type, descend.ItemData[i].AssetID, descend.ItemData[i].GroupID, 100, descend.ItemData[i].OwnerID, descend.ItemData[i].CreatorID, descend.ItemData[i].ItemID, descend.ItemData[i].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); + i++; } @@ -617,14 +618,14 @@ namespace OpenSim.Region.ClientStack InventoryReply.InventoryData[0].FolderID = Item.parentFolderID; InventoryReply.InventoryData[0].GroupID = new LLUUID("00000000-0000-0000-0000-000000000000"); InventoryReply.InventoryData[0].GroupMask = 0; - InventoryReply.InventoryData[0].InvType =(sbyte) Item.invType; + InventoryReply.InventoryData[0].InvType = (sbyte)Item.invType; InventoryReply.InventoryData[0].Name = enc.GetBytes(Item.inventoryName + "\0"); InventoryReply.InventoryData[0].NextOwnerMask = Item.inventoryNextPermissions; InventoryReply.InventoryData[0].OwnerID = Item.avatarID; InventoryReply.InventoryData[0].OwnerMask = Item.inventoryCurrentPermissions; InventoryReply.InventoryData[0].SalePrice = 100; InventoryReply.InventoryData[0].SaleType = 0; - InventoryReply.InventoryData[0].Type =(sbyte) Item.assetType; + InventoryReply.InventoryData[0].Type = (sbyte)Item.assetType; InventoryReply.InventoryData[0].CRC = Helpers.InventoryCRC(1000, 0, InventoryReply.InventoryData[0].InvType, InventoryReply.InventoryData[0].Type, InventoryReply.InventoryData[0].AssetID, InventoryReply.InventoryData[0].GroupID, 100, InventoryReply.InventoryData[0].OwnerID, InventoryReply.InventoryData[0].CreatorID, InventoryReply.InventoryData[0].ItemID, InventoryReply.InventoryData[0].FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS); OutPacket(InventoryReply); @@ -651,6 +652,15 @@ namespace OpenSim.Region.ClientStack OutPacket(replytask); } + public void SendXferPacket(ulong xferID, uint packet, byte[] data) + { + SendXferPacketPacket sendXfer = new SendXferPacketPacket(); + sendXfer.XferID.ID = xferID; + sendXfer.XferID.Packet = packet; + sendXfer.DataPacket.Data = data; + OutPacket(sendXfer); + } + /// /// /// @@ -689,6 +699,66 @@ namespace OpenSim.Region.ClientStack OutPacket(loadURL); } + + public void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID) + { + PreloadSoundPacket preSound = new PreloadSoundPacket(); + preSound.DataBlock = new PreloadSoundPacket.DataBlockBlock[1]; + preSound.DataBlock[0] = new PreloadSoundPacket.DataBlockBlock(); + preSound.DataBlock[0].ObjectID = objectID; + preSound.DataBlock[0].OwnerID = ownerID; + preSound.DataBlock[0].SoundID = soundID; + OutPacket(preSound); + } + + public void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags) + { + AttachedSoundPacket sound = new AttachedSoundPacket(); + sound.DataBlock.SoundID = soundID; + sound.DataBlock.ObjectID = objectID; + sound.DataBlock.OwnerID = ownerID; + sound.DataBlock.Gain = gain; + sound.DataBlock.Flags = flags; + + OutPacket(sound); + } + + public void SendViewerTime(int phase) + { + + SimulatorViewerTimeMessagePacket viewertime = new SimulatorViewerTimeMessagePacket(); + //viewertime.TimeInfo.SecPerDay = 86400; + // viewertime.TimeInfo.SecPerYear = 31536000; + viewertime.TimeInfo.SecPerDay = 1000; + viewertime.TimeInfo.SecPerYear = 365000; + viewertime.TimeInfo.SunPhase = 1; + int sunPhase = (phase + 2) / 2; + if ((sunPhase < 12) || (sunPhase > 36)) + { + + viewertime.TimeInfo.SunDirection = new LLVector3(0f, 0.8f, -0.8f); + //Console.WriteLine("sending night"); + } + else + { + sunPhase = sunPhase - 12; + float yValue = 0.1f * (sunPhase); + if (yValue > 1.2f) { yValue = yValue - 1.2f; } + if (yValue > 1 ) { yValue = 1; } + if (yValue < 0) { yValue = 0; } + if (sunPhase < 14) + { + yValue = 1 - yValue; + } + if (sunPhase < 12) { yValue *= -1; } + viewertime.TimeInfo.SunDirection = new LLVector3(0f, yValue, 0.3f); + //Console.WriteLine("sending sun update " + yValue); + } + viewertime.TimeInfo.SunAngVelocity = new LLVector3(0, 0.0f, 10.0f); + viewertime.TimeInfo.UsecSinceStart = (ulong)Util.UnixTimeSinceEpoch(); + OutPacket(viewertime); + } + #endregion #region Appearance/ Wearables Methods @@ -782,7 +852,7 @@ namespace OpenSim.Region.ClientStack //give this avatar object a local id and assign the user a name objupdate.ObjectData[0].ID = avatarLocalID; objupdate.ObjectData[0].FullID = avatarID; - objupdate.ObjectData[0].NameValue = Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName ); + objupdate.ObjectData[0].NameValue = Helpers.StringToField("FirstName STRING RW SV " + firstName + "\nLastName STRING RW SV " + lastName); LLVector3 pos2 = new LLVector3((float)Pos.X, (float)Pos.Y, (float)Pos.Z); byte[] pb = pos2.GetBytes(); Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 16, pb.Length); @@ -834,28 +904,28 @@ namespace OpenSim.Region.ClientStack this.OutPacket(attach); } - + public void SendPrimitiveToClient( - ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, uint flags, + ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID, byte[] particleSystem, LLQuaternion rotation) { ObjectUpdatePacket outPacket = new ObjectUpdatePacket(); outPacket.RegionData.RegionHandle = regionHandle; outPacket.RegionData.TimeDilation = timeDilation; outPacket.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; - + outPacket.ObjectData[0] = this.CreatePrimUpdateBlock(primShape, flags); - + outPacket.ObjectData[0].ID = localID; outPacket.ObjectData[0].FullID = objectID; outPacket.ObjectData[0].OwnerID = ownerID; - outPacket.ObjectData[0].Text = Helpers.StringToField( text ); + outPacket.ObjectData[0].Text = Helpers.StringToField(text); outPacket.ObjectData[0].ParentID = parentID; outPacket.ObjectData[0].PSBlock = particleSystem; - + byte[] pb = pos.GetBytes(); Array.Copy(pb, 0, outPacket.ObjectData[0].ObjectData, 0, pb.Length); - + byte[] rot = rotation.GetBytes(); Array.Copy(rot, 0, outPacket.ObjectData[0].ObjectData, 36, rot.Length); @@ -1050,7 +1120,7 @@ namespace OpenSim.Region.ClientStack protected void SetPrimPacketShapeData(ObjectUpdatePacket.ObjectDataBlock objectData, PrimitiveBaseShape primData) { - + objectData.TextureEntry = primData.TextureEntry; objectData.PCode = primData.PCode; objectData.PathBegin = primData.PathBegin; @@ -1171,14 +1241,14 @@ namespace OpenSim.Region.ClientStack public void SendNameReply(LLUUID profileId, string firstname, string lastname) { UUIDNameReplyPacket packet = new UUIDNameReplyPacket(); - + packet.UUIDNameBlock = new UUIDNameReplyPacket.UUIDNameBlockBlock[1]; packet.UUIDNameBlock[0] = new UUIDNameReplyPacket.UUIDNameBlockBlock(); packet.UUIDNameBlock[0].ID = profileId; - packet.UUIDNameBlock[0].FirstName = Helpers.StringToField( firstname ); - packet.UUIDNameBlock[0].LastName = Helpers.StringToField( lastname ); - - OutPacket( packet ); + packet.UUIDNameBlock[0].FirstName = Helpers.StringToField(firstname); + packet.UUIDNameBlock[0].LastName = Helpers.StringToField(lastname); + + OutPacket(packet); } #endregion diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index 9ceb4cd..e73b2e2 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -95,6 +95,22 @@ namespace OpenSim.Region.ClientStack break; #region Scene/Avatar + case PacketType.AvatarPropertiesRequest: + AvatarPropertiesRequestPacket avatarProperties = (AvatarPropertiesRequestPacket)Pack; + AvatarPropertiesReplyPacket avatarReply = new AvatarPropertiesReplyPacket(); + avatarReply.AgentData.AgentID = this.AgentID; + avatarReply.AgentData.AvatarID = avatarProperties.AgentData.AvatarID; + avatarReply.PropertiesData.AboutText = Helpers.StringToField( "OpenSim crash test dummy"); + avatarReply.PropertiesData.BornOn = Helpers.StringToField("Before now"); + avatarReply.PropertiesData.CharterMember = new byte[0]; + avatarReply.PropertiesData.FLAboutText = Helpers.StringToField("First life? What is one of those? OpenSim is my life!"); + avatarReply.PropertiesData.Flags = 0; + avatarReply.PropertiesData.FLImageID = LLUUID.Zero; + avatarReply.PropertiesData.ImageID = LLUUID.Zero; + avatarReply.PropertiesData.ProfileURL = new byte[0]; + avatarReply.PropertiesData.PartnerID = new LLUUID("11111111-1111-0000-0000-000100bba000"); + OutPacket(avatarReply); + break; case PacketType.ChatFromViewer: ChatFromViewerPacket inchatpack = (ChatFromViewerPacket)Pack; if (Util.FieldToString(inchatpack.ChatData.Message) == "") @@ -128,7 +144,7 @@ namespace OpenSim.Region.ClientStack RezObjectPacket rezPacket = (RezObjectPacket)Pack; if (OnRezObject != null) { - this.OnRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd); + this.OnRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd); } break; case PacketType.DeRezObject: @@ -366,7 +382,11 @@ namespace OpenSim.Region.ClientStack } break; case PacketType.RequestXfer: - //Console.WriteLine(Pack.ToString()); + RequestXferPacket xferReq = (RequestXferPacket)Pack; + if (OnRequestXfer != null) + { + OnRequestXfer(this, xferReq.XferID.ID, Util.FieldToString(xferReq.XferID.Filename)); + } break; case PacketType.SendXferPacket: SendXferPacketPacket xferRec = (SendXferPacketPacket)Pack; diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index f0f73b0..6b8ddc6 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -472,7 +472,7 @@ namespace OpenSim.Region.Environment.Scenes hasPrim = ((SceneObjectGroup)ent).HasChildPrim(primLocalID); if (hasPrim != false) { - ((SceneObjectGroup)ent).GetPartInventory(remoteClient, primLocalID); + ((SceneObjectGroup)ent).GetPartInventoryFileName(remoteClient, primLocalID); break; } } @@ -758,6 +758,25 @@ namespace OpenSim.Region.Environment.Scenes } /// + /// + /// + /// + /// + /// + public void RequestXfer(IClientAPI remoteClient, ulong xferID, string fileName) + { + /* + foreach (EntityBase ent in Entities.Values) + { + if (ent is SceneObjectGroup) + { + ((SceneObjectGroup)ent).RequestInventoryFile(remoteClient, ((SceneObjectGroup)ent).LocalId, xferID); + break; + } + }*/ + } + + /// /// temporary method to test out creating new inventory items /// /// diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 01e58c7..85479a7 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -29,6 +29,8 @@ using System; using System.Collections.Generic; using System.Threading; using System.Timers; +using System.IO; +using System.Xml; using libsecondlife; using OpenSim.Framework; using OpenSim.Framework.Communications; @@ -65,6 +67,10 @@ namespace OpenSim.Region.Environment.Scenes private int storageCount; private int terrainCheckCount; private int landPrimCheckCount; + + private int m_timePhase = 24; + private int m_timeUpdateCount; + private Mutex updateLock; protected StorageManager storageManager; @@ -123,6 +129,11 @@ namespace OpenSim.Region.Environment.Scenes get { return Prims; } } + public int TimePhase + { + get { return this.m_timePhase; } + } + #endregion #region Constructors @@ -301,6 +312,26 @@ namespace OpenSim.Region.Environment.Scenes landPrimCheckCount = 0; } } + + m_timeUpdateCount++; + if (m_timeUpdateCount > 600) + { + List Avatars = this.RequestAvatarList(); + foreach (ScenePresence avatar in Avatars) + { + if (!avatar.childAgent) + { + //Console.WriteLine("sending time update " + timePhase + " from region " + m_regionHandle + " to avatar " + avatar.Firstname); + avatar.ControllingClient.SendViewerTime(m_timePhase); + } + } + m_timeUpdateCount = 0; + m_timePhase++; + if (m_timePhase > 94) + { + m_timePhase = 0; + } + } } catch (NotImplementedException) { @@ -538,7 +569,7 @@ namespace OpenSim.Region.Environment.Scenes public void AddEntity(SceneObjectGroup sceneObject) { - if(!Entities.ContainsKey(sceneObject.UUID)) + if (!Entities.ContainsKey(sceneObject.UUID)) { Entities.Add(sceneObject.UUID, sceneObject); } @@ -563,6 +594,52 @@ namespace OpenSim.Region.Environment.Scenes prim.OnPrimCountTainted += m_LandManager.setPrimsTainted; } + public void LoadPrimsFromXml(string fileName) + { + XmlDocument doc = new XmlDocument(); + XmlNode rootNode; + int primCount = 0; + if (File.Exists(fileName)) + { + XmlTextReader reader = new XmlTextReader(fileName); + reader.WhitespaceHandling = WhitespaceHandling.None; + doc.Load(reader); + reader.Close(); + rootNode = doc.FirstChild; + foreach (XmlNode aPrimNode in rootNode.ChildNodes) + { + SceneObjectGroup obj = new SceneObjectGroup(this, + this.m_regionHandle, aPrimNode.OuterXml); + AddEntity(obj); + primCount++; + } + } + else + { + throw new Exception("Could not open file " + fileName + " for reading"); + } + } + + public void SavePrimsToXml(string fileName) + { + FileStream file = new FileStream(fileName, FileMode.Create); + StreamWriter stream = new StreamWriter(file); + int primCount = 0; + stream.WriteLine("\n"); + foreach (EntityBase ent in Entities.Values) + { + if (ent is SceneObjectGroup) + { + stream.WriteLine(((SceneObjectGroup)ent).ToXmlString()); + primCount++; + } + } + stream.WriteLine("\n"); + stream.Close(); + file.Close(); + } + + #endregion #region Add/Remove Avatar Methods @@ -632,6 +709,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnFetchInventory += commsManager.UserProfiles.HandleFetchInventory; client.OnAssetUploadRequest += commsManager.TransactionsManager.HandleUDPUploadRequest; client.OnXferReceive += commsManager.TransactionsManager.HandleXfer; + // client.OnRequestXfer += RequestXfer; client.OnGrabObject += ProcessObjectGrab; } @@ -950,7 +1028,7 @@ namespace OpenSim.Region.Environment.Scenes AgentCircuitData agent = remoteClient.RequestClientInfo(); agent.BaseFolder = LLUUID.Zero; agent.InventoryFolder = LLUUID.Zero; -// agent.startpos = new LLVector3(128, 128, 70); + // agent.startpos = new LLVector3(128, 128, 70); agent.startpos = position; agent.child = true; commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent); @@ -1121,7 +1199,15 @@ namespace OpenSim.Region.Environment.Scenes item.assetID = asset.FullID; userInfo.UpdateItem(remoteClient.AgentId, item); - // remoteClient.SendInventoryItemUpdate(item); + // remoteClient.SendInventoryItemUpdate(item); + if (item.invType == 7) + { + //do we want to know about updated note cards? + } + else if (item.invType == 10) + { + // do we want to know about updated scripts + } return (asset.FullID); } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 421a981..1e6cd8f 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -212,7 +212,6 @@ namespace OpenSim.Region.Environment.Scenes public string ToXmlString() { StringWriter sw = new StringWriter(); - //StreamWriter st = new StreamWriter("testxml.txt"); XmlTextWriter writer = new XmlTextWriter(sw); writer.WriteStartElement(String.Empty, "SceneObjectGroup", String.Empty); writer.WriteStartElement(String.Empty, "RootPart", String.Empty); @@ -231,11 +230,7 @@ namespace OpenSim.Region.Environment.Scenes writer.WriteEndElement(); writer.WriteEndElement(); writer.Close(); - // System.Console.WriteLine("prim: " + sw.ToString()); return sw.ToString(); - // st.Close(); - // return ""; - } #region Copying @@ -557,12 +552,26 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - public void GetPartInventory(IClientAPI remoteClient, uint localID) + public void GetPartInventoryFileName(IClientAPI remoteClient, uint localID) { SceneObjectPart part = this.GetChildPrim(localID); if (part != null) { - part.GetInventory(remoteClient, localID); + part.GetInventoryFileName(remoteClient, localID); + } + } + + /// + /// + /// + /// + /// + public void RequestInventoryFile(IClientAPI remoteClient, uint localID, ulong xferID) + { + SceneObjectPart part = this.GetChildPrim(localID); + if (part != null) + { + part.RequestInventoryFile(remoteClient, xferID); } } @@ -636,6 +645,7 @@ namespace OpenSim.Region.Environment.Scenes public void UpdateGroupPosition(LLVector3 pos) { this.AbsolutePosition = pos; + } /// diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 1cfe9c8..c8a7515 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -31,7 +31,7 @@ namespace OpenSim.Region.Environment.Scenes public uint GroupMask = FULL_MASK_PERMISSIONS; public uint EveryoneMask = FULL_MASK_PERMISSIONS; public uint BaseMask = FULL_MASK_PERMISSIONS; - + protected byte[] m_particleSystem = new byte[0]; protected SceneObjectGroup m_parentGroup; @@ -47,7 +47,7 @@ namespace OpenSim.Region.Environment.Scenes public LLUUID UUID { get { return m_uuid; } - set { m_uuid = value ; } + set { m_uuid = value; } } protected uint m_localID; @@ -64,7 +64,7 @@ namespace OpenSim.Region.Environment.Scenes set { m_name = value; } } - protected LLObject.ObjectFlags m_flags = (LLObject.ObjectFlags)32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128; + protected LLObject.ObjectFlags m_flags = (LLObject.ObjectFlags)32 + 65536 + 131072 + 256 + 4 + 8 + 268435456 + 128; public uint ObjectFlags { get { return (uint)m_flags; } @@ -221,7 +221,6 @@ namespace OpenSim.Region.Environment.Scenes this.AngularVelocity = new LLVector3(0, 0, 0); this.Acceleration = new LLVector3(0, 0, 0); - //temporary code just so the m_flags field doesn't give a compiler warning if (m_flags == LLObject.ObjectFlags.AllowInventoryDrop) @@ -233,6 +232,7 @@ namespace OpenSim.Region.Environment.Scenes /// /// Re/create a SceneObjectPart (prim) + /// currently not used, and maybe won't be /// /// /// @@ -396,13 +396,59 @@ namespace OpenSim.Region.Environment.Scenes #endregion #region Inventory - public void GetInventory(IClientAPI client, uint localID) + /// + /// + /// + /// + /// + public void GetInventoryFileName(IClientAPI client, uint localID) { if (localID == this.m_localID) { + // client.SendTaskInventory(this.m_uuid, 0, Helpers.StringToField("primInventory")); client.SendTaskInventory(this.m_uuid, 0, new byte[0]); } } + + /// + /// + /// + /// + /// + public void RequestInventoryFile(IClientAPI client, ulong xferID) + { + // a test item + InventoryStringBuilder invString = new InventoryStringBuilder(); + invString.AddItemStart(); + invString.AddNameValueLine("item_id", LLUUID.Random().ToStringHyphenated()); + invString.AddNameValueLine("parent_id", this.UUID.ToStringHyphenated()); + + invString.AddPermissionsStart(); + invString.AddNameValueLine("base_mask", "0x7FFFFFFF"); + invString.AddNameValueLine("owner_mask", "0x7FFFFFFF"); + invString.AddNameValueLine("group_mask", "0x7FFFFFFF"); + invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF"); + invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF"); + invString.AddNameValueLine("creator_id", client.AgentId.ToStringHyphenated()); + invString.AddNameValueLine("owner_id", client.AgentId.ToStringHyphenated()); + invString.AddNameValueLine("last_owner_id", LLUUID.Zero.ToStringHyphenated()); + invString.AddNameValueLine("group_id", LLUUID.Zero.ToStringHyphenated()); + invString.AddSectionEnd(); + + invString.AddNameValueLine("asset_id", "00000000-0000-0000-9999-000000000002"); + invString.AddNameValueLine("type", "texture"); + invString.AddNameValueLine("inv_type" , "texture"); + invString.AddNameValueLine("flags", "0x00"); + invString.AddNameValueLine("name", "Test inventory" + "|"); + invString.AddNameValueLine("desc", "test description" + "|"); + invString.AddNameValueLine("creation_date", "10000"); + invString.AddSectionEnd(); + + byte[] fileInv = Helpers.StringToField(invString.BuildString); + byte[] data = new byte[fileInv.Length + 4]; + Array.Copy(fileInv, 0,data , 4, fileInv.Length); + client.SendXferPacket(xferID, 0 + 0x80000000, data); + } #endregion #region ExtraParams @@ -422,7 +468,7 @@ namespace OpenSim.Region.Environment.Scenes Array.Copy(data, 0, this.m_shape.ExtraParams, i, data.Length); this.ScheduleFullUpdate(); - + } #endregion @@ -497,7 +543,7 @@ namespace OpenSim.Region.Environment.Scenes /// public void SendFullUpdate(IClientAPI remoteClient) { - m_parentGroup.SendPartFullUpdate( remoteClient, this ); + m_parentGroup.SendPartFullUpdate(remoteClient, this); } /// @@ -580,7 +626,46 @@ namespace OpenSim.Region.Environment.Scenes public void SetText(string text, Vector3 color, double alpha) { - Text = text; + Text = text; + } + + public class InventoryStringBuilder + { + public string BuildString = ""; + + public InventoryStringBuilder() + { + + } + + public void AddItemStart() + { + BuildString += "\tinv_item\t0\n"; + BuildString += "\t{\n"; + } + + public void AddPermissionsStart() + { + BuildString += "\tpermissions 0\n"; + BuildString += "\t{\n"; + } + + public void AddSectionEnd() + { + BuildString += "\t}\n"; + } + + public void AddLine(string addLine) + { + BuildString += addLine; + } + + public void AddNameValueLine(string name, string value) + { + BuildString += "\t\t"; + BuildString += name + "\t"; + BuildString += value + "\n"; + } } } } diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs index 7dcb760..0393a2a 100644 --- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs +++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs @@ -59,7 +59,7 @@ namespace OpenSim.Region.Environment.Scenes private ulong m_regionHandle; - public bool childAgent = false; + public bool childAgent = true; public bool IsRestrictedToRegion = false; private bool newForce = false; @@ -495,6 +495,7 @@ namespace OpenSim.Region.Environment.Scenes this.SendArrearanceToAllOtherAgents(); this.m_scene.SendAllSceneObjectsToClient(this.ControllingClient); + this.ControllingClient.SendViewerTime(this.m_scene.TimePhase); } /// diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 25b62b8..ccb4d11 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -73,6 +73,7 @@ namespace SimpleApp public event RequestTaskInventory OnRequestTaskInventory; public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; + public event RequestXfer OnRequestXfer; public event UUIDNameRequest OnNameFromUUIDRequest; @@ -155,8 +156,13 @@ namespace SimpleApp public virtual void SendInventoryItemUpdate(InventoryItemBase Item) { } public virtual void SendRemoveInventoryItem(LLUUID itemID) { } public virtual void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName) { } + public virtual void SendXferPacket(ulong xferID, uint packet, byte[] data) { } + public virtual void SendNameReply(LLUUID profileId, string firstname, string lastname) { } + public virtual void SendPreLoadSound(LLUUID objectID, LLUUID ownerID, LLUUID soundID) { } + public virtual void SendPlayAttachedSound(LLUUID soundID, LLUUID objectID, LLUUID ownerID, float gain, byte flags) { } + public void SendAlertMessage(string message) { } public void SendAgentAlertMessage(string message, bool modal) { } public void SendLoadURL(string objectname, LLUUID objectID, LLUUID ownerID, bool groupOwned, string message, string url) { } @@ -208,5 +214,7 @@ namespace SimpleApp { return false; } + + public void SendViewerTime(int phase) { } } } diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs index 6f12c47..391ac84 100644 --- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs +++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; using System.Text; +using System.Xml; +using System.Xml.Serialization; +using System.IO; using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.LandManagement; @@ -38,7 +41,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage SqliteCommand primSelectCmd = new SqliteCommand(primSelect, conn); primDa = new SqliteDataAdapter(primSelectCmd); // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); - + SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, conn); shapeDa = new SqliteDataAdapter(shapeSelectCmd); // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); @@ -55,12 +58,12 @@ namespace OpenSim.DataStore.MonoSqliteStorage DataTable prims = ds.Tables["prims"]; prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] }; setupPrimCommands(primDa, conn); - + // shapeDa.FillSchema(ds, SchemaType.Source, "ShapeSchema"); DataTable shapes = ds.Tables["primshapes"]; shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] }; setupShapeCommands(shapeDa, conn); - + return; } @@ -158,7 +161,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage return data; } - private SqliteCommand createInsertCommand(string table, Dictionary defs) + private SqliteCommand createInsertCommand(string table, Dictionary defs) { /** * This is subtle enough to deserve some commentary. @@ -171,7 +174,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage */ string[] cols = new string[defs.Keys.Count]; defs.Keys.CopyTo(cols, 0); - + string sql = "insert into " + table + "("; sql += String.Join(", ", cols); // important, the first ':' needs to be here, the rest get added in the join @@ -179,21 +182,24 @@ namespace OpenSim.DataStore.MonoSqliteStorage sql += String.Join(", :", cols); sql += ")"; SqliteCommand cmd = new SqliteCommand(sql); - + // this provides the binding for all our parameters, so // much less code than it used to be - foreach (KeyValuePair kvp in defs) { + foreach (KeyValuePair kvp in defs) + { cmd.Parameters.Add(createSqliteParameter(kvp.Key, kvp.Value)); } return cmd; } - private SqliteCommand createUpdateCommand(string table, string pk, Dictionary defs) + private SqliteCommand createUpdateCommand(string table, string pk, Dictionary defs) { string sql = "update " + table + " set "; string subsql = ""; - foreach (string key in defs.Keys) { - if (subsql.Length > 0) { // a map function would rock so much here + foreach (string key in defs.Keys) + { + if (subsql.Length > 0) + { // a map function would rock so much here subsql += ", "; } subsql += key + "= :" + key; @@ -204,7 +210,8 @@ namespace OpenSim.DataStore.MonoSqliteStorage // this provides the binding for all our parameters, so // much less code than it used to be - foreach (KeyValuePair kvp in defs) { + foreach (KeyValuePair kvp in defs) + { cmd.Parameters.Add(createSqliteParameter(kvp.Key, kvp.Value)); } return cmd; @@ -213,13 +220,13 @@ namespace OpenSim.DataStore.MonoSqliteStorage private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn) { Dictionary primDataDefs = createPrimDataDefs(); - + da.InsertCommand = createInsertCommand("prims", primDataDefs); da.InsertCommand.Connection = conn; da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", primDataDefs); da.UpdateCommand.Connection = conn; - + SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID"); delete.Parameters.Add(createSqliteParameter("UUID", DbType.String)); delete.Connection = conn; @@ -229,13 +236,13 @@ namespace OpenSim.DataStore.MonoSqliteStorage private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) { Dictionary shapeDataDefs = createShapeDataDefs(); - + da.InsertCommand = createInsertCommand("primshapes", shapeDataDefs); da.InsertCommand.Connection = conn; da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", shapeDataDefs); da.UpdateCommand.Connection = conn; - + SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID"); delete.Parameters.Add(createSqliteParameter("UUID", DbType.String)); delete.Connection = conn; @@ -271,8 +278,8 @@ namespace OpenSim.DataStore.MonoSqliteStorage prim.BaseMask = Convert.ToUInt32(row["BaseMask"]); // vectors prim.OffsetPosition = new LLVector3( - Convert.ToSingle(row["PositionX"]), - Convert.ToSingle(row["PositionY"]), + Convert.ToSingle(row["PositionX"]), + Convert.ToSingle(row["PositionY"]), Convert.ToSingle(row["PositionZ"]) ); prim.GroupPosition = new LLVector3( @@ -306,7 +313,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage return prim; } - private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID) + private void fillPrimRow(DataRow row, SceneObjectPart prim, LLUUID sceneGroupID) { row["UUID"] = prim.UUID; row["ParentID"] = prim.ParentID; @@ -383,11 +390,22 @@ 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(); + + string texture = (string)row["Texture"]; + if (!texture.StartsWith("<")) + { + //here so that we can still work with old format database files (ie from before I added xml serialization) + LLObject.TextureEntry textureEntry = null; + textureEntry = new LLObject.TextureEntry(new LLUUID(texture)); + s.TextureEntry = textureEntry.ToBytes(); + } + else + { + TextureBlock textureEntry = TextureBlock.FromXmlString(texture); + s.TextureEntry = textureEntry.TextureData; + s.ExtraParams = textureEntry.ExtraParams; + } + return s; } @@ -428,34 +446,41 @@ namespace OpenSim.DataStore.MonoSqliteStorage // 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(); - + // Added following xml hack but not really ideal , also ExtraParams isn't currently part of the database + // am a bit worried about adding it now as some people will have old format databases, so for now including that data in this xml data + // MW[17-08-07] + TextureBlock textureBlock = new TextureBlock(s.TextureEntry); + textureBlock.ExtraParams = s.ExtraParams; + row["Texture"] = textureBlock.ToXMLString(); } private void addPrim(SceneObjectPart prim, LLUUID sceneGroupID) { DataTable prims = ds.Tables["prims"]; DataTable shapes = ds.Tables["primshapes"]; - + DataRow primRow = prims.Rows.Find(prim.UUID); - if (primRow == null) { + if (primRow == null) + { primRow = prims.NewRow(); fillPrimRow(primRow, prim, sceneGroupID); prims.Rows.Add(primRow); - } else { + } + else + { fillPrimRow(primRow, prim, sceneGroupID); } DataRow shapeRow = shapes.Rows.Find(prim.UUID); - if (shapeRow == null) { + if (shapeRow == null) + { shapeRow = shapes.NewRow(); fillShapeRow(shapeRow, prim); shapes.Rows.Add(shapeRow); - } else { + } + else + { fillShapeRow(shapeRow, prim); } } @@ -466,11 +491,11 @@ namespace OpenSim.DataStore.MonoSqliteStorage { addPrim(prim, obj.UUID); } - - // MainLog.Instance.Verbose("Attempting to do database update...."); + + // MainLog.Instance.Verbose("Attempting to do database update...."); primDa.Update(ds, "prims"); shapeDa.Update(ds, "primshapes"); - // MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); + // MainLog.Instance.Verbose("Dump of prims:", ds.GetXml()); } public void RemoveObject(LLUUID obj) @@ -502,7 +527,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage DataTable prims = ds.Tables["prims"]; DataTable shapes = ds.Tables["primshapes"]; - + foreach (DataRow primRow in prims.Rows) { string uuid = (string)primRow["UUID"]; @@ -548,7 +573,7 @@ namespace OpenSim.DataStore.MonoSqliteStorage return retvals; } - + public void StoreTerrain(double[,] ter) { @@ -578,5 +603,42 @@ namespace OpenSim.DataStore.MonoSqliteStorage { // TODO: DataSet commit } + + public class TextureBlock + { + public byte[] TextureData; + public byte[] ExtraParams = new byte[1]; + + public TextureBlock(byte[] data) + { + TextureData = data; + } + + public TextureBlock() + { + + } + + public string ToXMLString() + { + StringWriter sw = new StringWriter(); + XmlTextWriter writer = new XmlTextWriter(sw); + XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock)); + serializer.Serialize(writer, this); + return sw.ToString(); + } + + public static TextureBlock FromXmlString(string xmlData) + { + TextureBlock textureEntry = null; + StringReader sr = new StringReader(xmlData); + XmlTextReader reader = new XmlTextReader(sr); + XmlSerializer serializer = new XmlSerializer(typeof(TextureBlock)); + textureEntry = (TextureBlock)serializer.Deserialize(reader); + reader.Close(); + sr.Close(); + return textureEntry; + } + } } } -- cgit v1.1