From 531f64a53bbd084dd8d0b33ae6c49821c74d718a Mon Sep 17 00:00:00 2001 From: MW Date: Thu, 16 Aug 2007 16:31:32 +0000 Subject: Taking Prims (SceneObjectGroups) in and out of inventory should now work and if left in inventory will still be there after restarts. (as with the rest of inventory it will only fully work in standalone mode with account authentication turned on). --- OpenSim/Region/ClientStack/ClientView.API.cs | 12 +++ .../ClientStack/ClientView.ProcessPackets.cs | 24 ++--- .../Communications/Local/LocalInventoryService.cs | 5 + .../Communications/OGS1/OGS1InventoryService.cs | 5 + .../Environment/Scenes/Scene.PacketHandlers.cs | 107 ++++++++++++++++----- OpenSim/Region/Environment/Scenes/Scene.cs | 8 +- .../Region/Environment/Scenes/SceneObjectGroup.cs | 104 ++++++++++++++++---- .../Region/Examples/SimpleApp/MyNpcCharacter.cs | 1 + 8 files changed, 201 insertions(+), 65 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index d7962dc..f655674 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -630,6 +630,18 @@ namespace OpenSim.Region.ClientStack OutPacket(InventoryReply); } + public void SendRemoveInventoryItem(LLUUID itemID) + { + RemoveInventoryItemPacket remove = new RemoveInventoryItemPacket(); + remove.AgentData.AgentID = this.AgentID; + remove.AgentData.SessionID = this.SessionID; + remove.InventoryData = new RemoveInventoryItemPacket.InventoryDataBlock[1]; + remove.InventoryData[0] = new RemoveInventoryItemPacket.InventoryDataBlock(); + remove.InventoryData[0].ItemID = itemID; + + OutPacket(remove); + } + public void SendTaskInventory(LLUUID taskID, short serial, byte[] fileName) { ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket(); diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index f380c25..89df290 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -45,12 +45,12 @@ namespace OpenSim.Region.ClientStack get { return m_moneyBalance; } } - public bool AddMoney( int debit ) + public bool AddMoney(int debit) { - if( m_moneyBalance + debit >= 0 ) + if (m_moneyBalance + debit >= 0) { m_moneyBalance += debit; - SendMoneyBalance( LLUUID.Zero, true, Helpers.StringToField("Poof Poof!"), m_moneyBalance ); + SendMoneyBalance(LLUUID.Zero, true, Helpers.StringToField("Poof Poof!"), m_moneyBalance); return true; } else @@ -58,7 +58,7 @@ namespace OpenSim.Region.ClientStack return false; } } - + protected override void ProcessInPacket(Packet Pack) { ack_pack(Pack); @@ -126,21 +126,9 @@ namespace OpenSim.Region.ClientStack break; case PacketType.RezObject: RezObjectPacket rezPacket = (RezObjectPacket)Pack; - AgentInventory inven = this.m_inventoryCache.GetAgentsInventory(this.AgentID); - if (inven != null) + if (OnRezObject != null) { - if (inven.InventoryItems.ContainsKey(rezPacket.InventoryData.ItemID)) - { - AssetBase asset = this.m_assetCache.GetAsset(inven.InventoryItems[rezPacket.InventoryData.ItemID].AssetID); - if (asset != null) - { - if (OnRezObject != null) - { - this.OnRezObject(asset, rezPacket.RezData.RayEnd); - this.m_inventoryCache.DeleteInventoryItem(this, rezPacket.InventoryData.ItemID); - } - } - } + this.OnRezObject(this, rezPacket.InventoryData.ItemID, rezPacket.RezData.RayEnd); } break; case PacketType.DeRezObject: diff --git a/OpenSim/Region/Communications/Local/LocalInventoryService.cs b/OpenSim/Region/Communications/Local/LocalInventoryService.cs index 8295cfa..af58d33 100644 --- a/OpenSim/Region/Communications/Local/LocalInventoryService.cs +++ b/OpenSim/Region/Communications/Local/LocalInventoryService.cs @@ -63,5 +63,10 @@ namespace OpenSim.Region.Communications.Local { this.AddItem(item); } + + public void DeleteInventoryItem(LLUUID userID, InventoryItemBase item) + { + this.deleteItem(item); + } } } diff --git a/OpenSim/Region/Communications/OGS1/OGS1InventoryService.cs b/OpenSim/Region/Communications/OGS1/OGS1InventoryService.cs index a98684e..70ab75e 100644 --- a/OpenSim/Region/Communications/OGS1/OGS1InventoryService.cs +++ b/OpenSim/Region/Communications/OGS1/OGS1InventoryService.cs @@ -29,5 +29,10 @@ namespace OpenSim.Region.Communications.OGS1 { } + + public void DeleteInventoryItem(LLUUID userID, InventoryItemBase item) + { + + } } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs index 10bdd54..b901d23 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs @@ -34,6 +34,7 @@ using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Framework.Communications.Caches; using OpenSim.Framework.Data; +using OpenSim.Framework.Utilities; namespace OpenSim.Region.Environment.Scenes { @@ -209,23 +210,13 @@ namespace OpenSim.Region.Environment.Scenes /// /// /// - /// - /// - public void RezObject(AssetBase primAsset, LLVector3 pos) - { - - } - - /// - /// - /// /// /// - public void DeRezObject(Packet packet, IClientAPI simClient) + public void DeRezObject(Packet packet, IClientAPI remoteClient) { DeRezObjectPacket DeRezPacket = (DeRezObjectPacket)packet; - + if (DeRezPacket.AgentBlock.DestinationID == LLUUID.Zero) { //currently following code not used (or don't know of any case of destination being zero @@ -246,17 +237,76 @@ namespace OpenSim.Region.Environment.Scenes } if (selectedEnt != null) { - if (PermissionsMngr.CanDeRezObject(simClient.AgentId, selectedEnt.m_uuid)) + if (PermissionsMngr.CanDeRezObject(remoteClient.AgentId,((SceneObjectGroup)selectedEnt).UUID)) { - List avatars = this.RequestAvatarList(); - foreach (ScenePresence avatar in avatars) + string sceneObjectXml = ((SceneObjectGroup)selectedEnt).ToXmlString(); + CachedUserInfo userInfo = commsManager.UserProfiles.GetUserDetails(remoteClient.AgentId); + if (userInfo != null) { - avatar.ControllingClient.SendKillObject(this.m_regionHandle, selectedEnt.LocalId); + AssetBase asset = new AssetBase(); + asset.Name = ((SceneObjectGroup)selectedEnt).GetPartName(selectedEnt.LocalId); + asset.Description = ((SceneObjectGroup)selectedEnt).GetPartDescription(selectedEnt.LocalId); + asset.InvType = 6; + asset.Type = 6; + asset.FullID = LLUUID.Random(); + asset.Data = Helpers.StringToField(sceneObjectXml); + this.assetCache.AddAsset(asset); + + + InventoryItemBase item = new InventoryItemBase(); + item.avatarID = remoteClient.AgentId; + item.creatorsID = remoteClient.AgentId; + item.inventoryID = LLUUID.Random(); + item.assetID = asset.FullID; + item.inventoryDescription = asset.Description; + item.inventoryName = asset.Name; + item.assetType = asset.Type; + item.invType = asset.InvType; + item.parentFolderID = DeRezPacket.AgentBlock.DestinationID; + item.inventoryCurrentPermissions = 2147483647; + item.inventoryNextPermissions = 2147483647; + + userInfo.AddItem(remoteClient.AgentId, item); + remoteClient.SendInventoryItemUpdate(item); } + ((SceneObjectGroup)selectedEnt).DeleteGroup(); + lock (Entities) { - Entities.Remove(selectedEnt.m_uuid); + Entities.Remove(((SceneObjectGroup) selectedEnt).UUID); + } + } + } + } + } + } + + public void RezObject(IClientAPI remoteClient, LLUUID itemID, LLVector3 pos) + { + CachedUserInfo userInfo = commsManager.UserProfiles.GetUserDetails(remoteClient.AgentId); + if (userInfo != null) + { + if(userInfo.RootFolder != null) + { + InventoryItemBase item = userInfo.RootFolder.HasItem(itemID); + if (item != null) + { + AssetBase rezAsset = this.assetCache.GetAsset(item.assetID, false); + if (rezAsset != null) + { + this.AddRezObject(Util.FieldToString(rezAsset.Data), pos); + userInfo.DeleteItem(remoteClient.AgentId, item); + remoteClient.SendRemoveInventoryItem(itemID); + } + else + { + rezAsset = this.assetCache.GetAsset(item.assetID, false); + if (rezAsset != null) + { + this.AddRezObject(Util.FieldToString(rezAsset.Data), pos); + userInfo.DeleteItem(remoteClient.AgentId, item); + remoteClient.SendRemoveInventoryItem(itemID); } } } @@ -264,6 +314,13 @@ namespace OpenSim.Region.Environment.Scenes } } + private void AddRezObject(string xmlData, LLVector3 pos) + { + SceneObjectGroup group = new SceneObjectGroup(this, this.m_regionHandle, xmlData); + this.AddEntity(group); + group.Pos = pos; + } + /// /// /// @@ -301,11 +358,11 @@ namespace OpenSim.Region.Environment.Scenes this.Entities.Add(copy.UUID, copy); copy.ScheduleGroupForFullUpdate(); - /* List avatars = this.RequestAvatarList(); - for (int i = 0; i < avatars.Count; i++) - { - // copy.SendAllChildPrimsToClient(avatars[i].ControllingClient); - }*/ + /* List avatars = this.RequestAvatarList(); + for (int i = 0; i < avatars.Count; i++) + { + // copy.SendAllChildPrimsToClient(avatars[i].ControllingClient); + }*/ } else @@ -620,7 +677,7 @@ namespace OpenSim.Region.Environment.Scenes if (hasPrim != false) { ((SceneObjectGroup)ent).UpdateGroupRotation(pos, rot); - // prim.UpdateGroupMouseRotation(pos, rot); + // prim.UpdateGroupMouseRotation(pos, rot); break; } } @@ -665,7 +722,7 @@ namespace OpenSim.Region.Environment.Scenes { if (ent is SceneObjectGroup) { - // prim = ((SceneObject)ent).HasChildPrim(localID); + // prim = ((SceneObject)ent).HasChildPrim(localID); if (prim != null) { prim.UpdateSingleRotation(rot); @@ -692,7 +749,7 @@ namespace OpenSim.Region.Environment.Scenes if (hasPrim != false) { ((SceneObjectGroup)ent).Resize(scale, localID); - // prim.ResizeGoup(scale); + // prim.ResizeGoup(scale); break; } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 378acf9..96bb97a 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -538,7 +538,10 @@ namespace OpenSim.Region.Environment.Scenes public void AddEntity(SceneObjectGroup sceneObject) { - Entities.Add(sceneObject.UUID, sceneObject); + if(!Entities.ContainsKey(sceneObject.UUID)) + { + Entities.Add(sceneObject.UUID, sceneObject); + } } public void RemoveEntity(SceneObjectGroup sceneObject) @@ -604,6 +607,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnObjectDeselect += DeselectPrim; client.OnGrabUpdate += MoveObject; client.OnDeRezObject += DeRezObject; + client.OnRezObject += RezObject; client.OnNameFromUUIDRequest += commsManager.HandleUUIDNameRequest; client.OnObjectDescription += PrimDescription; client.OnObjectName += PrimName; @@ -1114,7 +1118,7 @@ namespace OpenSim.Region.Environment.Scenes this.assetCache.AddAsset(asset); item.assetID = asset.FullID; - userInfo.updateItem(remoteClient.AgentId, item); + userInfo.UpdateItem(remoteClient.AgentId, item); // remoteClient.SendInventoryItemUpdate(item); diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs index 77d936d..73f199e 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs @@ -39,7 +39,7 @@ namespace OpenSim.Region.Environment.Scenes { get { return m_rootPart.RotationOffset; } } - + /// /// @@ -108,6 +108,12 @@ namespace OpenSim.Region.Environment.Scenes get { return m_rootPart.OwnerID; } } + public string Text + { + get { return m_rootPart.Text; } + set { m_rootPart.Text = value; } + } + /// /// Added because the Parcel code seems to use it /// but not sure a object should have this @@ -143,19 +149,40 @@ namespace OpenSim.Region.Environment.Scenes StringReader sr = new StringReader(xmlData); XmlTextReader reader = new XmlTextReader(sr); + reader.Read(); reader.ReadStartElement("SceneObjectGroup"); reader.ReadStartElement("RootPart"); this.m_rootPart = SceneObjectPart.FromXml(reader); reader.ReadEndElement(); - //TODO: read and create rest of the parts - reader.ReadEndElement(); + + while (reader.Read()) + { + switch (reader.NodeType) + { + case XmlNodeType.Element: + if (reader.Name == "Part") + { + reader.Read(); + SceneObjectPart Part = SceneObjectPart.FromXml(reader); + Part.LocalID = m_scene.PrimIDAllocate(); + this.AddPart(Part); + Part.RegionHandle = m_regionHandle; + } + break; + case XmlNodeType.EndElement: + break; + } + } reader.Close(); sr.Close(); - + this.m_rootPart.SetParent(this); this.m_parts.Add(m_rootPart.UUID, m_rootPart); this.m_rootPart.LocalID = m_scene.PrimIDAllocate(); + this.m_rootPart.ParentID = 0; this.m_rootPart.RegionHandle = m_regionHandle; + this.UpdateParentIDs(); m_scene.EventManager.OnBackup += this.ProcessBackup; + this.ScheduleGroupForFullUpdate(); } /// @@ -192,6 +219,17 @@ namespace OpenSim.Region.Environment.Scenes writer.WriteStartElement(String.Empty, "RootPart", String.Empty); m_rootPart.ToXml(writer); writer.WriteEndElement(); + writer.WriteStartElement(String.Empty, "OtherParts", String.Empty); + foreach (SceneObjectPart part in this.m_parts.Values) + { + if (part.UUID != this.m_rootPart.UUID) + { + writer.WriteStartElement(String.Empty, "Part", String.Empty); + part.ToXml(writer); + writer.WriteEndElement(); + } + } + writer.WriteEndElement(); writer.WriteEndElement(); writer.Close(); // System.Console.WriteLine("prim: " + sw.ToString()); @@ -215,11 +253,11 @@ namespace OpenSim.Region.Environment.Scenes dupe.m_regionHandle = this.m_regionHandle; dupe.CopyRootPart(this.m_rootPart); - + List partList = new List(this.m_parts.Values); foreach (SceneObjectPart part in partList) { - if (part.UUID != this.m_rootPart.UUID) + if (part.UUID != this.m_rootPart.UUID) { dupe.CopyPart(part); } @@ -477,13 +515,6 @@ namespace OpenSim.Region.Environment.Scenes } } - public string Text - { - get { return m_rootPart.Text; } - set { m_rootPart.Text = value; } - } - - public void SetPartText(string text, uint localID) { SceneObjectPart part = this.GetChildPrim(localID); @@ -502,6 +533,26 @@ namespace OpenSim.Region.Environment.Scenes } } + public string GetPartName(uint localID) + { + SceneObjectPart part = this.GetChildPrim(localID); + if (part != null) + { + return part.PartName; + } + return ""; + } + + public string GetPartDescription(uint localID) + { + SceneObjectPart part = this.GetChildPrim(localID); + if (part != null) + { + return part.Description; + } + return ""; + } + /// /// /// @@ -598,7 +649,7 @@ namespace OpenSim.Region.Environment.Scenes SceneObjectPart part = this.GetChildPrim(localID); if (part != null) { - if (part.UUID== this.m_rootPart.UUID) + if (part.UUID == this.m_rootPart.UUID) { this.UpdateRootPosition(pos); } @@ -805,14 +856,14 @@ namespace OpenSim.Region.Environment.Scenes public override void UpdateMovement() { - foreach( SceneObjectPart part in m_parts.Values ) + foreach (SceneObjectPart part in m_parts.Values) { part.UpdateMovement(); } - + base.UpdateMovement(); } - + /// /// 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... @@ -857,8 +908,8 @@ namespace OpenSim.Region.Environment.Scenes } return null; } - - public void UpdateText( string text ) + + public void UpdateText(string text) { m_rootPart.Text = text; m_rootPart.ScheduleTerseUpdate(); @@ -866,7 +917,7 @@ namespace OpenSim.Region.Environment.Scenes public void ObjectGrabHandler(uint localId, LLVector3 offsetPos, IClientAPI remoteClient) { - if( m_rootPart.LocalID == localId ) + if (m_rootPart.LocalID == localId) { OnGrabGroup(offsetPos, remoteClient); } @@ -886,5 +937,18 @@ namespace OpenSim.Region.Environment.Scenes { } + + public void DeleteGroup() + { + m_scene.EventManager.OnBackup -= this.ProcessBackup; + foreach (SceneObjectPart part in this.m_parts.Values) + { + List avatars = this.RequestSceneAvatars(); + for (int i = 0; i < avatars.Count; i++) + { + avatars[i].ControllingClient.SendKillObject(this.m_regionHandle, part.LocalID); + } + } + } } } diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 8bd7496..25b62b8 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -153,6 +153,7 @@ namespace SimpleApp public virtual void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List items) { } public virtual void SendInventoryItemDetails(LLUUID ownerID, InventoryItemBase item) { } 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 SendNameReply(LLUUID profileId, string firstname, string lastname) { } -- cgit v1.1