From 40af8c256165eb6fb56f58e3c13ee9293e052f66 Mon Sep 17 00:00:00 2001 From: MW Date: Sun, 25 Mar 2007 17:34:58 +0000 Subject: You want large textures, you shall have! - Xfer system now working for large asset uploads Fixed the VS solution file. Now forwars ViewerEffect messages onto the other clients Renamed OpenSim.Framework/Inventory.cs to OpenSim.Framework/AgentInventory.cs --- OpenSim.RegionServer/AgentAssetUpload.cs | 212 +++++++++++++++++++++++ OpenSim.RegionServer/Assets/AssetCache.cs | 79 ++++----- OpenSim.RegionServer/Assets/InventoryCache.cs | 27 ++- OpenSim.RegionServer/OpenSim.RegionServer.csproj | 42 +++-- OpenSim.RegionServer/OpenSim.exe.build | 1 + OpenSim.RegionServer/SimClient.cs | 61 +++++-- 6 files changed, 343 insertions(+), 79 deletions(-) create mode 100644 OpenSim.RegionServer/AgentAssetUpload.cs (limited to 'OpenSim.RegionServer') diff --git a/OpenSim.RegionServer/AgentAssetUpload.cs b/OpenSim.RegionServer/AgentAssetUpload.cs new file mode 100644 index 0000000..2b4d78f --- /dev/null +++ b/OpenSim.RegionServer/AgentAssetUpload.cs @@ -0,0 +1,212 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Framework.Assets; +using OpenSim.Framework.Utilities; +using libsecondlife; +using libsecondlife.Packets; + +namespace OpenSim +{ + public class AgentAssetUpload + { + private Dictionary transactions = new Dictionary(); + private SimClient ourClient; + + public AgentAssetUpload(SimClient client) + { + this.ourClient = client; + } + + public void AddUpload(LLUUID transactionID, AssetBase asset) + { + Console.WriteLine("adding upload asset"); + AssetTransaction upload = new AssetTransaction(); + lock (this.transactions) + { + upload.Asset = asset; + upload.TransactionID = transactionID; + this.transactions.Add(transactionID, upload); + } + if (upload.Asset.Data.Length > 2) + { + //is complete + upload.UploadComplete = true; + AssetUploadCompletePacket response = new AssetUploadCompletePacket(); + response.AssetBlock.Type = asset.Type; + response.AssetBlock.Success = true; + response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID); + this.ourClient.OutPacket(response); + } + else + { + Console.WriteLine(" no data in upload request so use xfer system"); + upload.UploadComplete = false; + upload.XferID = Util.GetNextXferID(); + RequestXferPacket xfer = new RequestXferPacket(); + xfer.XferID.ID = upload.XferID; + xfer.XferID.VFileType = upload.Asset.Type; + xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID); + xfer.XferID.FilePath = 0; + xfer.XferID.Filename = new byte[0]; + this.ourClient.OutPacket(xfer); + } + + } + + public AssetBase GetUpload(LLUUID transactionID) + { + if (this.transactions.ContainsKey(transactionID)) + { + return this.transactions[transactionID].Asset; + } + + return null; + } + + public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID) + { + + AssetBase asset = null; + if (pack.AssetBlock.Type == 0) + { + + //first packet for transaction + asset = new AssetBase(); + asset.FullID = assetID; + asset.Type = pack.AssetBlock.Type; + asset.InvType = asset.Type; + asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000"); + asset.Data = pack.AssetBlock.AssetData; + + + } + /* for now we will only support uploading of textures + else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5) + { + + asset = new AssetBase(); + asset.FullID = assetID; + Console.WriteLine("skin asset id is " + assetID.ToStringHyphenated()); + asset.Type = pack.AssetBlock.Type; + asset.InvType = asset.Type; + asset.Name = "NewClothing" + Util.RandomClass.Next(1, 1000).ToString("000"); + asset.Data = pack.AssetBlock.AssetData; + + + }*/ + + if (asset != null) + { + this.AddUpload(pack.AssetBlock.TransactionID, asset); + } + else + { + + //currently we don't support this asset type + //so lets just tell the client that the upload is complete + AssetUploadCompletePacket response = new AssetUploadCompletePacket(); + response.AssetBlock.Type = pack.AssetBlock.Type; + response.AssetBlock.Success = true; + response.AssetBlock.UUID = pack.AssetBlock.TransactionID.Combine(this.ourClient.SecureSessionID); + this.ourClient.OutPacket(response); + } + + } + + #region Xfer packet system for larger uploads + + public void HandleXferPacket(SendXferPacketPacket xferPacket) + { + lock (this.transactions) + { + foreach (AssetTransaction trans in this.transactions.Values) + { + if (trans.XferID == xferPacket.XferID.ID) + { + if (trans.Asset.Data.Length > 1) + { + byte[] newArray = new byte[trans.Asset.Data.Length + xferPacket.DataPacket.Data.Length]; + Array.Copy(trans.Asset.Data, 0, newArray, 0, trans.Asset.Data.Length); + Array.Copy(xferPacket.DataPacket.Data, 0, newArray, trans.Asset.Data.Length, xferPacket.DataPacket.Data.Length); + trans.Asset.Data = newArray; + } + else + { + byte[] newArray = new byte[xferPacket.DataPacket.Data.Length-4]; + Array.Copy(xferPacket.DataPacket.Data, 4, newArray, 0, xferPacket.DataPacket.Data.Length-4); + trans.Asset.Data = newArray; + } + + if ((xferPacket.XferID.Packet & 2147483648) != 0) + { + //end of transfer + trans.UploadComplete = true; + AssetUploadCompletePacket response = new AssetUploadCompletePacket(); + response.AssetBlock.Type = trans.Asset.Type; + response.AssetBlock.Success = true; + response.AssetBlock.UUID = trans.TransactionID.Combine(this.ourClient.SecureSessionID); + this.ourClient.OutPacket(response); + + //check if we should add it to inventory + if (trans.AddToInventory) + { + OpenSimRoot.Instance.AssetCache.AddAsset(trans.Asset); + OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset); + } + + Console.WriteLine(Helpers.FieldToString(trans.Asset.Data)); + } + break; + } + + } + } + + ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket(); + confirmXfer.XferID.ID = xferPacket.XferID.ID; + confirmXfer.XferID.Packet = xferPacket.XferID.Packet; + this.ourClient.OutPacket(confirmXfer); + } + + #endregion + + public void CreateInventoryItem(CreateInventoryItemPacket packet) + { + if(this.transactions.ContainsKey(packet.InventoryBlock.TransactionID)) + { + AssetTransaction trans = this.transactions[packet.InventoryBlock.TransactionID]; + trans.Asset.Description = Helpers.FieldToString(packet.InventoryBlock.Description); + trans.Asset.Name = Helpers.FieldToString(packet.InventoryBlock.Name); + trans.Asset.Type = packet.InventoryBlock.Type; + if (trans.UploadComplete) + { + //already complete so we can add it to the inventory + OpenSimRoot.Instance.AssetCache.AddAsset(trans.Asset); + OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this.ourClient, packet.InventoryBlock.FolderID, trans.Asset); + } + else + { + trans.AddToInventory = true; + trans.InventFolder = packet.InventoryBlock.FolderID; + } + } + } + + } + + public class AssetTransaction + { + public uint XferID; + public AssetBase Asset; + public bool AddToInventory; + public LLUUID InventFolder = LLUUID.Zero; + public bool UploadComplete = false; + public LLUUID TransactionID = LLUUID.Zero; + + public AssetTransaction() + { + + } + } +} diff --git a/OpenSim.RegionServer/Assets/AssetCache.cs b/OpenSim.RegionServer/Assets/AssetCache.cs index 4149cb2..c1b3472 100644 --- a/OpenSim.RegionServer/Assets/AssetCache.cs +++ b/OpenSim.RegionServer/Assets/AssetCache.cs @@ -123,6 +123,36 @@ namespace OpenSim.Assets return inventorySet; } + public AssetBase GetAsset(LLUUID assetID) + { + AssetBase asset = null; + if(this.Textures.ContainsKey(assetID)) + { + asset = this.Textures[assetID]; + } + else if (this.Assets.ContainsKey(assetID)) + { + asset = this.Assets[assetID]; + } + return asset; + } + + public void AddAsset(AssetBase asset) + { + this._assetServer.UploadNewAsset(asset); + if (asset.Type == 0) + { + //texture + TextureImage textur = new TextureImage(asset); + this.Textures.Add(textur.FullID, textur); + } + else + { + AssetInfo assetInf = new AssetInfo(asset); + this.Assets.Add(assetInf.FullID, assetInf); + } + } + /// /// /// @@ -150,7 +180,7 @@ namespace OpenSim.Assets req = (AssetRequest)this.TextureRequests[i]; if (req.PacketCounter != req.NumPackets) { - + // if (req.ImageInfo.FullID == new LLUUID("00000000-0000-0000-5005-000000000005")) if (req.PacketCounter == 0) { //first time for this request so send imagedata packet @@ -186,7 +216,7 @@ namespace OpenSim.Assets } else { - //send imagepacket + //send imagepacket //more than one packet so split file up ImagePacketPacket im = new ImagePacketPacket(); im.ImageID.Packet = (ushort)req.PacketCounter; @@ -461,7 +491,6 @@ namespace OpenSim.Assets { req.NumPackets = 1; } - this.TextureRequests.Add(req); } @@ -477,50 +506,6 @@ namespace OpenSim.Assets } #endregion - #region viewer asset uploading - public AssetBase UploadPacket(AssetUploadRequestPacket pack, LLUUID assetID) - { - - AssetBase asset = null; - if (pack.AssetBlock.Type == 0) - { - if (pack.AssetBlock.AssetData.Length > 0) - { - //first packet for transaction - asset = new AssetBase(); - asset.FullID = assetID; - asset.Type = pack.AssetBlock.Type; - asset.InvType = asset.Type; - asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000"); - asset.Data = pack.AssetBlock.AssetData; - this._assetServer.UploadNewAsset(asset); - TextureImage image = new TextureImage(asset); - this.Textures.Add(image.FullID, image); - } - } - - return asset; - } - - /* - public AssetBase TransactionComplete(LLUUID transactionID) - { - AssetBase asset = null; - if(this.IncomingAssets.ContainsKey(transactionID)) - { - // not the first packet of this transaction - asset = this.IncomingAssets[transactionID]; - if(asset.Type == 0) - { - TextureImage image = new TextureImage(asset); - this.Textures.Add(image.FullID, image); - } - } - return asset; - }*/ - - #endregion - } public class AssetRequest diff --git a/OpenSim.RegionServer/Assets/InventoryCache.cs b/OpenSim.RegionServer/Assets/InventoryCache.cs index e4d0a90..9e73fe5 100644 --- a/OpenSim.RegionServer/Assets/InventoryCache.cs +++ b/OpenSim.RegionServer/Assets/InventoryCache.cs @@ -65,14 +65,20 @@ namespace OpenSim.Assets } } + public bool CreateNewInventoryFolder(SimClient remoteClient, LLUUID folderID) { + return this.CreateNewInventoryFolder(remoteClient, folderID, 0); + } + + public bool CreateNewInventoryFolder(SimClient remoteClient, LLUUID folderID, ushort type) + { bool res = false; if (folderID != LLUUID.Zero) //don't create a folder with a zero id { if (this._agentsInventory.ContainsKey(remoteClient.AgentID)) { - res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID); + res = this._agentsInventory[remoteClient.AgentID].CreateNewFolder(folderID, type); } } return res; @@ -94,6 +100,22 @@ namespace OpenSim.Assets return newItem; } + public bool UpdateInventoryItem(SimClient remoteClient, LLUUID itemID, OpenSim.Framework.Assets.AssetBase asset) + { + if (this._agentsInventory.ContainsKey(remoteClient.AgentID)) + { + bool res = _agentsInventory[remoteClient.AgentID].UpdateItem(itemID, asset); + if (res) + { + InventoryItem Item = this._agentsInventory[remoteClient.AgentID].InventoryItems[itemID]; + this.SendItemUpdateCreate(remoteClient, Item); + } + return res; + } + + return false; + } + public void FetchInventoryDescendents(SimClient userInfo, FetchInventoryDescendentsPacket FetchDescend) { if (this._agentsInventory.ContainsKey(userInfo.AgentID)) @@ -190,6 +212,7 @@ namespace OpenSim.Assets } } } + private void SendItemUpdateCreate(SimClient remoteClient, InventoryItem Item) { @@ -223,7 +246,7 @@ namespace OpenSim.Assets } } - + public class UserServerRequest { diff --git a/OpenSim.RegionServer/OpenSim.RegionServer.csproj b/OpenSim.RegionServer/OpenSim.RegionServer.csproj index b191922..cc58347 100644 --- a/OpenSim.RegionServer/OpenSim.RegionServer.csproj +++ b/OpenSim.RegionServer/OpenSim.RegionServer.csproj @@ -1,4 +1,4 @@ - + Local 8.0.50727 @@ -6,7 +6,8 @@ {457CE564-0922-4F15-846F-147E5BE62D67} Debug AnyCPU - + + OpenSim.RegionServer @@ -15,9 +16,11 @@ IE50 false Library - + + OpenSim.RegionServer - + + @@ -28,7 +31,8 @@ TRACE;DEBUG - + + True 4096 False @@ -37,7 +41,8 @@ False False 4 - + + False @@ -46,7 +51,8 @@ TRACE - + + False 4096 True @@ -55,26 +61,27 @@ False False 4 - + + - + System.dll False - + System.Xml.dll False - + ..\bin\libsecondlife.dll False - + ..\bin\Axiom.MathLib.dll False - + ..\bin\Db4objects.Db4o.dll False @@ -84,22 +91,23 @@ OpenSim.Framework.Console {CE124F22-69FC-4499-AE68-1B877C5898C4} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - False + False OpenSim.Physics.Manager {79C8C9A7-EF80-426D-B815-AC88E7998DFE} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - False + False OpenSim.Framework {71848571-2BC0-41DC-A69C-28B6DDB8C8CE} {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - False + False + Code @@ -177,4 +185,4 @@ - + \ No newline at end of file diff --git a/OpenSim.RegionServer/OpenSim.exe.build b/OpenSim.RegionServer/OpenSim.exe.build index 2b5e012..529f5fb 100644 --- a/OpenSim.RegionServer/OpenSim.exe.build +++ b/OpenSim.RegionServer/OpenSim.exe.build @@ -11,6 +11,7 @@ + diff --git a/OpenSim.RegionServer/SimClient.cs b/OpenSim.RegionServer/SimClient.cs index d271ea9..9ae1baf 100644 --- a/OpenSim.RegionServer/SimClient.cs +++ b/OpenSim.RegionServer/SimClient.cs @@ -68,6 +68,7 @@ namespace OpenSim private const int MAX_APPENDED_ACKS = 10; private const int RESEND_TIMEOUT = 4000; private const int MAX_SEQUENCE = 0xFFFFFF; + private AgentAssetUpload UploadAssets; private LLUUID newAssetFolder = LLUUID.Zero; private bool debug = false; @@ -278,28 +279,37 @@ namespace OpenSim break; case PacketType.AssetUploadRequest: + //this.debug = true; AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack; - AssetBase newAsset = OpenSimRoot.Instance.AssetCache.UploadPacket(request, LLUUID.Random()); - if ((newAsset != null) && (this.newAssetFolder != LLUUID.Zero)) + Console.WriteLine(Pack.ToString()); + if (request.AssetBlock.Type == 0) { - OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this, this.newAssetFolder, newAsset); + this.UploadAssets.HandleUploadPacket(request, LLUUID.Random()); + } + else + { + this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID)); } - - AssetUploadCompletePacket response = new AssetUploadCompletePacket(); - response.AssetBlock.Type =request.AssetBlock.Type; - response.AssetBlock.Success = true; - response.AssetBlock.UUID = request.AssetBlock.TransactionID.Combine(this.SecureSessionID); - - this.OutPacket(response); + break; + case PacketType.SendXferPacket: + Console.WriteLine(Pack.ToString()); + this.UploadAssets.HandleXferPacket((SendXferPacketPacket)Pack); break; case PacketType.CreateInventoryFolder: - //Console.WriteLine(Pack.ToString()); + CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack; + OpenSimRoot.Instance.InventoryCache.CreateNewInventoryFolder(this, invFolder.FolderData.FolderID, (ushort)invFolder.FolderData.Type); + Console.WriteLine(Pack.ToString()); break; case PacketType.CreateInventoryItem: - //Console.WriteLine(Pack.ToString()); + Console.WriteLine(Pack.ToString()); + CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack; + if (createItem.InventoryBlock.TransactionID != LLUUID.Zero) + { + this.UploadAssets.CreateInventoryItem(createItem); + } break; case PacketType.FetchInventory: - Console.WriteLine("fetch item packet"); + //Console.WriteLine("fetch item packet"); FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack; OpenSimRoot.Instance.InventoryCache.FetchInventory(this, FetchInventory); break; @@ -307,6 +317,29 @@ namespace OpenSim FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack; OpenSimRoot.Instance.InventoryCache.FetchInventoryDescendents(this, Fetch); break; + case PacketType.UpdateInventoryItem: + /* UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack; + for (int i = 0; i < update.InventoryData.Length; i++) + { + if (update.InventoryData[i].TransactionID != LLUUID.Zero) + { + AssetBase asset = OpenSimRoot.Instance.AssetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID)); + OpenSimRoot.Instance.InventoryCache.UpdateInventoryItem(this, update.InventoryData[i].ItemID, asset); + } + }*/ + break; + case PacketType.ViewerEffect: + ViewerEffectPacket viewer = (ViewerEffectPacket)Pack; + foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values) + { + if (client.AgentID != this.AgentID) + { + viewer.AgentData.AgentID = client.AgentID; + viewer.AgentData.SessionID = client.SessionID; + client.OutPacket(viewer); + } + } + break; case PacketType.DeRezObject: //OpenSim.Framework.Console.MainConsole.Instance.WriteLine("Received DeRezObject packet"); OpenSimRoot.Instance.LocalWorld.DeRezObject((DeRezObjectPacket)Pack, this); @@ -522,6 +555,8 @@ namespace OpenSim cirpack = initialcirpack; userEP = remoteEP; PacketQueue = new BlockingQueue(); + + this.UploadAssets = new AgentAssetUpload(this); AckTimer = new System.Timers.Timer(500); AckTimer.Elapsed += new ElapsedEventHandler(AckTimer_Elapsed); AckTimer.Start(); -- cgit v1.1