From 921ac14e86fab329c3135b24b2a1be83813fce1b Mon Sep 17 00:00:00 2001 From: MW Date: Tue, 21 Aug 2007 21:03:18 +0000 Subject: Added OnRezScript event to Scene.EventManager.Which the script engine should subscribe to. This is triggered whenever a script is moved into a primitive (and includes the localid of the prim and the script text as params) . Currently though the script item isn't deleted from a users inventory, nor does it actually show up in the objects inventory (this will be fixed soon.) So that means that it isn't currently possible to edit a script (or delete it) once it has been added to a primitive. --- OpenSim/Framework/General/Interfaces/IClientAPI.cs | 2 + OpenSim/Framework/General/NullClientAPI.cs | 1 + OpenSim/Region/ClientStack/ClientView.API.cs | 1 + .../ClientStack/ClientView.ProcessPackets.cs | 5 +++ .../Region/Environment/Scenes/Scene.Inventory.cs | 44 +++++++++++++++++++++- OpenSim/Region/Environment/Scenes/Scene.cs | 1 + OpenSim/Region/Environment/Scenes/SceneEvents.cs | 11 ++++++ .../Region/Environment/Scenes/SceneObjectPart.cs | 9 +++++ .../Region/Examples/SimpleApp/MyNpcCharacter.cs | 1 + 9 files changed, 73 insertions(+), 2 deletions(-) diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index 8337a81..e30a49c 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs @@ -88,6 +88,7 @@ namespace OpenSim.Framework.Interfaces public delegate void FetchInventory(IClientAPI remoteClient, LLUUID itemID, LLUUID ownerID); public delegate void RequestTaskInventory(IClientAPI remoteClient, uint localID); public delegate void UpdateInventoryItemTransaction(IClientAPI remoteClient, LLUUID transactionID, LLUUID assetID, LLUUID itemID); + public delegate void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID); public delegate void UDPAssetUploadRequest(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data); public delegate void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data); @@ -146,6 +147,7 @@ namespace OpenSim.Framework.Interfaces event UDPAssetUploadRequest OnAssetUploadRequest; event XferReceive OnXferReceive; event RequestXfer OnRequestXfer; + event RezScript OnRezScript; event UUIDNameRequest OnNameFromUUIDRequest; diff --git a/OpenSim/Framework/General/NullClientAPI.cs b/OpenSim/Framework/General/NullClientAPI.cs index e6749fc..55a3f0b 100644 --- a/OpenSim/Framework/General/NullClientAPI.cs +++ b/OpenSim/Framework/General/NullClientAPI.cs @@ -62,6 +62,7 @@ namespace OpenSim.Framework public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; public event RequestXfer OnRequestXfer; + public event RezScript OnRezScript; public event UUIDNameRequest OnNameFromUUIDRequest; diff --git a/OpenSim/Region/ClientStack/ClientView.API.cs b/OpenSim/Region/ClientStack/ClientView.API.cs index 8729b58..cee18fe 100644 --- a/OpenSim/Region/ClientStack/ClientView.API.cs +++ b/OpenSim/Region/ClientStack/ClientView.API.cs @@ -91,6 +91,7 @@ namespace OpenSim.Region.ClientStack public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; public event RequestXfer OnRequestXfer; + public event RezScript OnRezScript; public event UUIDNameRequest OnNameFromUUIDRequest; diff --git a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs index 592254a..579b824 100644 --- a/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs +++ b/OpenSim/Region/ClientStack/ClientView.ProcessPackets.cs @@ -472,6 +472,11 @@ namespace OpenSim.Region.ClientStack break; case PacketType.RezScript: //Console.WriteLine(Pack.ToString()); + RezScriptPacket rezScript = (RezScriptPacket)Pack; + if (OnRezScript != null) + { + OnRezScript(this, rezScript.InventoryBlock.ItemID, rezScript.UpdateBlock.ObjectLocalID); + } break; case PacketType.MapLayerRequest: this.RequestMapLayer(); diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 3e2a97a..765fafc 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs @@ -111,8 +111,8 @@ namespace OpenSim.Region.Environment.Scenes { asset.Name = item.inventoryName; asset.Description = item.inventoryDescription; - asset.InvType = (sbyte) item.invType; - asset.Type = (sbyte) item.assetType; + asset.InvType = (sbyte)item.invType; + asset.Type = (sbyte)item.assetType; item.assetID = asset.FullID; if (addToCache) @@ -205,6 +205,44 @@ namespace OpenSim.Region.Environment.Scenes } } + public void RezScript(IClientAPI remoteClient, LLUUID itemID, uint localID) + { + CachedUserInfo userInfo = commsManager.UserProfiles.GetUserDetails(remoteClient.AgentId); + if (userInfo != null) + { + if (userInfo.RootFolder != null) + { + InventoryItemBase item = userInfo.RootFolder.HasItem(itemID); + if (item != null) + { + bool isTexture = false; + if (item.invType == 0) + { + isTexture = true; + } + AssetBase rezAsset = commsManager.AssetCache.GetAsset(item.assetID, isTexture); + if (rezAsset != null) + { + string script = Util.FieldToString(rezAsset.Data); + //Console.WriteLine("rez script "+script); + this.EventManager.TriggerRezScript(localID, script); + } + else + { + //lets try once more incase the asset cache is being slow getting the asset from server + rezAsset = commsManager.AssetCache.GetAsset(item.assetID, isTexture); + if (rezAsset != null) + { + string script = Util.FieldToString(rezAsset.Data); + // Console.WriteLine("rez script " + script); + this.EventManager.TriggerRezScript(localID, script); + } + } + } + } + } + } + /// /// /// @@ -320,6 +358,8 @@ namespace OpenSim.Region.Environment.Scenes this.AddEntity(group); group.AbsolutePosition = pos; } + + } } diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index cdf6788..d625dec 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -711,6 +711,7 @@ namespace OpenSim.Region.Environment.Scenes client.OnAssetUploadRequest += commsManager.TransactionsManager.HandleUDPUploadRequest; client.OnXferReceive += commsManager.TransactionsManager.HandleXfer; // client.OnRequestXfer += RequestXfer; + client.OnRezScript += RezScript; client.OnRequestAvatarProperties += RequestAvatarProperty; diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs index 050207c..89aeda6 100644 --- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs +++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs @@ -37,6 +37,9 @@ namespace OpenSim.Region.Environment.Scenes public event ObjectGrabDelegate OnObjectGrab; public event OnPermissionErrorDelegate OnPermissionError; + public delegate void NewRezScript(uint localID, string script); + public event NewRezScript OnRezScript; + public void TriggerPermissionError(LLUUID user, string reason) { @@ -106,5 +109,13 @@ namespace OpenSim.Region.Environment.Scenes if (OnObjectGrab != null) OnObjectGrab(localID, offsetPos, remoteClient); } + + public void TriggerRezScript(uint localID, string script) + { + if (OnRezScript != null) + { + OnRezScript(localID, script); + } + } } } diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index de3ad38..904b158 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -396,6 +396,15 @@ namespace OpenSim.Region.Environment.Scenes #endregion #region Inventory + public void AddInventoryItem() + { + + } + + public void RemoveInventoryItem() + { + + } /// /// /// diff --git a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs index 577eb93..4a9e652 100644 --- a/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs +++ b/OpenSim/Region/Examples/SimpleApp/MyNpcCharacter.cs @@ -76,6 +76,7 @@ namespace SimpleApp public event UDPAssetUploadRequest OnAssetUploadRequest; public event XferReceive OnXferReceive; public event RequestXfer OnRequestXfer; + public event RezScript OnRezScript; public event UUIDNameRequest OnNameFromUUIDRequest; -- cgit v1.1