public void AddUpload(LLUUID transactionID, AssetBase 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);
         m_assetCache.AddAsset(asset);
     }
     else
     {
         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);
     }
 }
        void AssetUploadRequestHandler(Packet packet, Agent agent)
        {
            AssetUploadRequestPacket request = (AssetUploadRequestPacket)packet;
            UUID assetID = UUID.Combine(request.AssetBlock.TransactionID, agent.SecureSessionID);

            // Check if the asset is small enough to fit in a single packet
            if (request.AssetBlock.AssetData.Length != 0)
            {
                // Create a new asset from the completed upload
                Asset asset = CreateAsset((AssetType)request.AssetBlock.Type, assetID, request.AssetBlock.AssetData);
                if (asset == null)
                {
                    Logger.Log("Failed to create asset from uploaded data", Helpers.LogLevel.Warning);
                    return;
                }

                Logger.DebugLog(String.Format("Storing uploaded asset {0} ({1})", assetID, asset.AssetType));

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);

                // Store the asset
                scene.Server.Assets.StoreAsset(asset);

                // Send a success response
                AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                complete.AssetBlock.Success = true;
                complete.AssetBlock.Type = request.AssetBlock.Type;
                complete.AssetBlock.UUID = assetID;
                scene.UDP.SendPacket(agent.ID, complete, PacketCategory.Inventory);
            }
            else
            {
                // Create a new (empty) asset for the upload
                Asset asset = CreateAsset((AssetType)request.AssetBlock.Type, assetID, null);
                if (asset == null)
                {
                    Logger.Log("Failed to create asset from uploaded data", Helpers.LogLevel.Warning);
                    return;
                }

                Logger.DebugLog(String.Format("Starting upload for {0} ({1})", assetID, asset.AssetType));

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);

                RequestXferPacket xfer = new RequestXferPacket();
                xfer.XferID.DeleteOnCompletion = request.AssetBlock.Tempfile;
                xfer.XferID.FilePath = 0;
                xfer.XferID.Filename = Utils.EmptyBytes;
                xfer.XferID.ID = request.AssetBlock.TransactionID.GetULong();
                xfer.XferID.UseBigPackets = false;
                xfer.XferID.VFileID = asset.AssetID;
                xfer.XferID.VFileType = request.AssetBlock.Type;

                // Add this asset to the current upload list
                lock (CurrentUploads)
                    CurrentUploads[xfer.XferID.ID] = asset;

                scene.UDP.SendPacket(agent.ID, xfer, PacketCategory.Inventory);
            }
        }
示例#3
0
        void AssetUploadRequestHandler(Packet packet, Agent agent)
        {
            AssetUploadRequestPacket request = (AssetUploadRequestPacket)packet;
            UUID assetID = UUID.Combine(request.AssetBlock.TransactionID, agent.SecureSessionID);

            // Check if the asset is small enough to fit in a single packet
            if (request.AssetBlock.AssetData.Length != 0)
            {
                // Create a new asset from the completed upload
                Asset asset = CreateAsset((AssetType)request.AssetBlock.Type, assetID, request.AssetBlock.AssetData);
                if (asset == null)
                {
                    Logger.Log("Failed to create asset from uploaded data", Helpers.LogLevel.Warning);
                    return;
                }

                Logger.DebugLog(String.Format("Storing uploaded asset {0} ({1})", assetID, asset.AssetType));

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);

                // Store the asset
                StoreAsset(asset);

                // Send a success response
                AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                complete.AssetBlock.Success = true;
                complete.AssetBlock.Type    = request.AssetBlock.Type;
                complete.AssetBlock.UUID    = assetID;
                server.UDP.SendPacket(agent.AgentID, complete, PacketCategory.Inventory);
            }
            else
            {
                // Create a new (empty) asset for the upload
                Asset asset = CreateAsset((AssetType)request.AssetBlock.Type, assetID, null);
                if (asset == null)
                {
                    Logger.Log("Failed to create asset from uploaded data", Helpers.LogLevel.Warning);
                    return;
                }

                Logger.DebugLog(String.Format("Starting upload for {0} ({1})", assetID, asset.AssetType));

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);

                RequestXferPacket xfer = new RequestXferPacket();
                xfer.XferID.DeleteOnCompletion = request.AssetBlock.Tempfile;
                xfer.XferID.FilePath           = 0;
                xfer.XferID.Filename           = new byte[0];
                xfer.XferID.ID            = request.AssetBlock.TransactionID.GetULong();
                xfer.XferID.UseBigPackets = false;
                xfer.XferID.VFileID       = asset.AssetID;
                xfer.XferID.VFileType     = request.AssetBlock.Type;

                // Add this asset to the current upload list
                lock (CurrentUploads)
                    CurrentUploads[xfer.XferID.ID] = asset;

                server.UDP.SendPacket(agent.AgentID, xfer, PacketCategory.Inventory);
            }
        }
示例#4
0
        public void AddUpload(LLUUID transactionID, AssetBase 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);
                m_assetCache.AddAsset(asset);
            }
            else
            {
                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);
            }
        }
示例#5
0
 public void AssetPostCallback(bool result)
 {
     AssetUploadCompletePacket newPack = new AssetUploadCompletePacket();
     newPack.AssetBlock.Type = m_asset.Type;
     newPack.AssetBlock.Success = result;
     newPack.AssetBlock.UUID = assetID;
     newPack.Header.Zerocoded = true;
     //OutPacket(newPack, ThrottleOutPacketType.Asset);
     proxy.InjectPacket(newPack, Direction.Incoming);
 }
示例#6
0
        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);

                            m_assetCache.AddAsset(trans.Asset);
                            //check if we should add it to inventory
                            if (trans.AddToInventory)
                            {
                                // m_assetCache.AddAsset(trans.Asset);
                                m_inventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset);
                            }
                        }
                        break;
                    }
                }
            }

            ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();

            confirmXfer.XferID.ID     = xferPacket.XferID.ID;
            confirmXfer.XferID.Packet = xferPacket.XferID.Packet;
            this.ourClient.OutPacket(confirmXfer);
        }
示例#7
0
        public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID)
        {
            // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString());
            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;
            }
            else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7)
            {
                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);
            }
        }
示例#8
0
        private void AssetUploadCompleteHandler(Packet packet, Simulator simulator)
        {
            AssetUploadCompletePacket complete = (AssetUploadCompletePacket)packet;

            if (OnAssetUploaded != null)
            {
                bool found = false;
                KeyValuePair <LLUUID, Transfer> foundTransfer = new KeyValuePair <LLUUID, Transfer>();

                // Xfer system sucks really really bad. Where is the damn XferID?
                lock (Transfers)
                {
                    foreach (KeyValuePair <LLUUID, Transfer> transfer in Transfers)
                    {
                        if (transfer.Value.GetType() == typeof(AssetUpload))
                        {
                            AssetUpload upload = (AssetUpload)transfer.Value;

                            if ((upload).AssetID == complete.AssetBlock.UUID)
                            {
                                found          = true;
                                foundTransfer  = transfer;
                                upload.Success = complete.AssetBlock.Success;
                                upload.Type    = (AssetType)complete.AssetBlock.Type;
                                found          = true;
                                break;
                            }
                        }
                    }
                }

                if (found)
                {
                    lock (Transfers) Transfers.Remove(foundTransfer.Key);

                    try { OnAssetUploaded((AssetUpload)foundTransfer.Value); }
                    catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); }
                }
            }
        }
        void SendXferPacketHandler(Packet packet, Agent agent)
        {
            SendXferPacketPacket xfer = (SendXferPacketPacket)packet;

            Asset asset;
            if (CurrentUploads.TryGetValue(xfer.XferID.ID, out asset))
            {
                if (asset.AssetData == null)
                {
                    if (xfer.XferID.Packet != 0)
                    {
                        Logger.Log(String.Format("Received Xfer packet {0} before the first packet!",
                            xfer.XferID.Packet), Helpers.LogLevel.Error);
                        return;
                    }

                    uint size = Utils.BytesToUInt(xfer.DataPacket.Data);
                    asset.AssetData = new byte[size];

                    Buffer.BlockCopy(xfer.DataPacket.Data, 4, asset.AssetData, 0, xfer.DataPacket.Data.Length - 4);

                    // Confirm the first upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    scene.UDP.SendPacket(agent.ID, confirm, PacketCategory.Asset);
                }
                else
                {
                    Buffer.BlockCopy(xfer.DataPacket.Data, 0, asset.AssetData, (int)xfer.XferID.Packet * 1000,
                        xfer.DataPacket.Data.Length);

                    // Confirm this upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    scene.UDP.SendPacket(agent.ID, confirm, PacketCategory.Asset);

                    if ((xfer.XferID.Packet & (uint)0x80000000) != 0)
                    {
                        // Asset upload finished
                        Logger.DebugLog(String.Format("Completed Xfer upload of asset {0} ({1}", asset.AssetID, asset.AssetType));

                        lock (CurrentUploads)
                            CurrentUploads.Remove(xfer.XferID.ID);

                        scene.Server.Assets.StoreAsset(asset);

                        AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                        complete.AssetBlock.Success = true;
                        complete.AssetBlock.Type = (sbyte)asset.AssetType;
                        complete.AssetBlock.UUID = asset.AssetID;
                        scene.UDP.SendPacket(agent.ID, complete, PacketCategory.Asset);
                    }
                }
            }
            else
            {
                Logger.DebugLog("Received a SendXferPacket for an unknown upload");
            }
        }
示例#10
0
        private void SendXferPacketHandler(Packet packet, LLAgent agent)
        {
            SendXferPacketPacket xfer = (SendXferPacketPacket)packet;

            uint packetID   = xfer.XferID.Packet & ~LAST_PACKET_MARKER;
            bool lastPacket = (xfer.XferID.Packet & LAST_PACKET_MARKER) != 0;

            Asset asset;

            if (currentUploads.TryGetValue(xfer.XferID.ID, out asset))
            {
                if (packetID == 0)
                {
                    uint size = Utils.BytesToUInt(xfer.DataPacket.Data);
                    asset.Data = new byte[size];

                    Buffer.BlockCopy(xfer.DataPacket.Data, 4, asset.Data, 0, xfer.DataPacket.Data.Length - 4);

                    // Confirm the first upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID     = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    m_udp.SendPacket(agent, confirm, ThrottleCategory.Asset, false);
                }
                else if (asset.Data != null)
                {
                    AssetType type = (AssetType)LLUtil.ContentTypeToLLAssetType(asset.ContentType);

                    Buffer.BlockCopy(xfer.DataPacket.Data, 0, asset.Data, (int)packetID * 1000, xfer.DataPacket.Data.Length);

                    // Confirm this upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID     = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    m_udp.SendPacket(agent, confirm, ThrottleCategory.Asset, false);

                    if (lastPacket)
                    {
                        // Asset upload finished
                        lock (currentUploads)
                            currentUploads.Remove(xfer.XferID.ID);

                        if (type != AssetType.LSLBytecode)
                        {
                            // Store the uploaded asset
                            m_log.DebugFormat("Storing uploaded asset {0} ({1})", asset.ID, asset.ContentType);
                            if (!m_assets.StoreAsset(asset))
                            {
                                m_log.ErrorFormat("Failed to store uploaded asset {0} ({1})", asset.ID, asset.ContentType);
                            }
                        }
                        else
                        {
                            m_log.Debug("Ignoring LSL bytecode upload " + asset.ID);
                        }

                        AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                        complete.AssetBlock.Success = true;
                        complete.AssetBlock.Type    = (sbyte)type;
                        complete.AssetBlock.UUID    = asset.ID;
                        m_udp.SendPacket(agent, complete, ThrottleCategory.Asset, false);
                    }
                }
                else
                {
                    m_log.Error("Received SendXferPacket #" + xfer.XferID.Packet + " when asset.AssetData is still null");
                }
            }
            else
            {
                m_log.Debug("Received a SendXferPacket for an unknown upload");
            }
        }
示例#11
0
        private void AssetUploadRequestHandler(Packet packet, LLAgent agent)
        {
            AssetUploadRequestPacket request = (AssetUploadRequestPacket)packet;
            UUID      assetID = UUID.Combine(request.AssetBlock.TransactionID, agent.SecureSessionID);
            AssetType type    = (AssetType)request.AssetBlock.Type;

            // Check if the agent is allowed to upload an asset
            string uploadError;

            if (m_permissions != null && !m_permissions.TryUploadOneAsset(agent, out uploadError))
            {
                m_scene.PresenceAlert(this, agent, uploadError);
                return;
            }

            bool local = request.AssetBlock.StoreLocal | type == AssetType.LSLBytecode;
            bool temp  = request.AssetBlock.Tempfile;

            // Check if the asset is small enough to fit in a single packet
            if (request.AssetBlock.AssetData.Length != 0)
            {
                // Create a new asset from the completed upload

                Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, request.AssetBlock.AssetData);

                if (asset == null)
                {
                    m_log.Warn("Failed to create asset from uploaded data");
                    return;
                }

                if (type != AssetType.LSLBytecode)
                {
                    // Store the asset
                    m_log.DebugFormat("Storing uploaded asset {0} ({1})", assetID, asset.ContentType);
                    if (!m_assets.StoreAsset(asset))
                    {
                        m_log.ErrorFormat("Failed to store uploaded asset {0} ({1})", assetID, asset.ContentType);
                    }
                }
                else
                {
                    m_log.Debug("Ignoring LSL bytecode upload " + assetID);
                }

                // Send a success response
                AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                complete.AssetBlock.Success = true;
                complete.AssetBlock.Type    = request.AssetBlock.Type;
                complete.AssetBlock.UUID    = assetID;
                m_udp.SendPacket(agent, complete, ThrottleCategory.Task, false);
            }
            else
            {
                // Create a new (empty) asset for the upload
                Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, null);

                if (asset == null)
                {
                    m_log.Warn("Failed to create asset from uploaded data");
                    return;
                }

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);
                ulong transferID = request.AssetBlock.TransactionID.GetULong();

                // Prevent LSL bytecode transfers from colliding with LSL source transfers, which
                // use a colliding UUID
                if (type == AssetType.LSLBytecode)
                {
                    ++transferID;
                }

                RequestXferPacket xfer = new RequestXferPacket();
                xfer.XferID.DeleteOnCompletion = request.AssetBlock.Tempfile;
                xfer.XferID.FilePath           = 0;
                xfer.XferID.Filename           = Utils.EmptyBytes;
                xfer.XferID.ID            = transferID;
                xfer.XferID.UseBigPackets = false;
                xfer.XferID.VFileID       = asset.ID;
                xfer.XferID.VFileType     = request.AssetBlock.Type;

                m_log.DebugFormat("Starting upload for {0} / {1} ({2})", assetID, transferID, asset.ContentType);

                // Add this asset to the current upload list
                lock (currentUploads)
                    currentUploads[transferID] = asset;

                m_udp.SendPacket(agent, xfer, ThrottleCategory.Task, false);
            }
        }
示例#12
0
文件: Assets.cs 项目: thoys/simian
        private void SendXferPacketHandler(Packet packet, LLAgent agent)
        {
            SendXferPacketPacket xfer = (SendXferPacketPacket)packet;

            uint packetID = xfer.XferID.Packet & ~LAST_PACKET_MARKER;
            bool lastPacket = (xfer.XferID.Packet & LAST_PACKET_MARKER) != 0;

            Asset asset;
            if (currentUploads.TryGetValue(xfer.XferID.ID, out asset))
            {
                if (packetID == 0)
                {
                    uint size = Utils.BytesToUInt(xfer.DataPacket.Data);
                    asset.Data = new byte[size];

                    Buffer.BlockCopy(xfer.DataPacket.Data, 4, asset.Data, 0, xfer.DataPacket.Data.Length - 4);

                    // Confirm the first upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    m_udp.SendPacket(agent, confirm, ThrottleCategory.Asset, false);
                }
                else if (asset.Data != null)
                {
                    AssetType type = (AssetType)LLUtil.ContentTypeToLLAssetType(asset.ContentType);

                    Buffer.BlockCopy(xfer.DataPacket.Data, 0, asset.Data, (int)packetID * 1000, xfer.DataPacket.Data.Length);

                    // Confirm this upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    m_udp.SendPacket(agent, confirm, ThrottleCategory.Asset, false);

                    if (lastPacket)
                    {
                        // Asset upload finished
                        lock (currentUploads)
                            currentUploads.Remove(xfer.XferID.ID);

                        if (type != AssetType.LSLBytecode)
                        {
                            // Store the uploaded asset
                            m_log.DebugFormat("Storing uploaded asset {0} ({1})", asset.ID, asset.ContentType);
                            if (!m_assets.StoreAsset(asset))
                                m_log.ErrorFormat("Failed to store uploaded asset {0} ({1})", asset.ID, asset.ContentType);
                        }
                        else
                        {
                            m_log.Debug("Ignoring LSL bytecode upload " + asset.ID);
                        }

                        AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                        complete.AssetBlock.Success = true;
                        complete.AssetBlock.Type = (sbyte)type;
                        complete.AssetBlock.UUID = asset.ID;
                        m_udp.SendPacket(agent, complete, ThrottleCategory.Asset, false);
                    }
                }
                else
                {
                    m_log.Error("Received SendXferPacket #" + xfer.XferID.Packet + " when asset.AssetData is still null");
                }
            }
            else
            {
                m_log.Debug("Received a SendXferPacket for an unknown upload");
            }
        }
示例#13
0
文件: Assets.cs 项目: thoys/simian
        private void AssetUploadRequestHandler(Packet packet, LLAgent agent)
        {
            AssetUploadRequestPacket request = (AssetUploadRequestPacket)packet;
            UUID assetID = UUID.Combine(request.AssetBlock.TransactionID, agent.SecureSessionID);
            AssetType type = (AssetType)request.AssetBlock.Type;

            // Check if the agent is allowed to upload an asset
            string uploadError;
            if (m_permissions != null && !m_permissions.TryUploadOneAsset(agent, out uploadError))
            {
                m_scene.PresenceAlert(this, agent, uploadError);
                return;
            }

            bool local = request.AssetBlock.StoreLocal | type == AssetType.LSLBytecode;
            bool temp = request.AssetBlock.Tempfile;

            // Check if the asset is small enough to fit in a single packet
            if (request.AssetBlock.AssetData.Length != 0)
            {
                // Create a new asset from the completed upload

                Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, request.AssetBlock.AssetData);

                if (asset == null)
                {
                    m_log.Warn("Failed to create asset from uploaded data");
                    return;
                }

                if (type != AssetType.LSLBytecode)
                {
                    // Store the asset
                    m_log.DebugFormat("Storing uploaded asset {0} ({1})", assetID, asset.ContentType);
                    if (!m_assets.StoreAsset(asset))
                        m_log.ErrorFormat("Failed to store uploaded asset {0} ({1})", assetID, asset.ContentType);
                }
                else
                {
                    m_log.Debug("Ignoring LSL bytecode upload " + assetID);
                }

                // Send a success response
                AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                complete.AssetBlock.Success = true;
                complete.AssetBlock.Type = request.AssetBlock.Type;
                complete.AssetBlock.UUID = assetID;
                m_udp.SendPacket(agent, complete, ThrottleCategory.Task, false);
            }
            else
            {
                // Create a new (empty) asset for the upload
                Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, null);

                if (asset == null)
                {
                    m_log.Warn("Failed to create asset from uploaded data");
                    return;
                }

                asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);
                ulong transferID = request.AssetBlock.TransactionID.GetULong();

                // Prevent LSL bytecode transfers from colliding with LSL source transfers, which
                // use a colliding UUID
                if (type == AssetType.LSLBytecode)
                    ++transferID;

                RequestXferPacket xfer = new RequestXferPacket();
                xfer.XferID.DeleteOnCompletion = request.AssetBlock.Tempfile;
                xfer.XferID.FilePath = 0;
                xfer.XferID.Filename = Utils.EmptyBytes;
                xfer.XferID.ID = transferID;
                xfer.XferID.UseBigPackets = false;
                xfer.XferID.VFileID = asset.ID;
                xfer.XferID.VFileType = request.AssetBlock.Type;

                m_log.DebugFormat("Starting upload for {0} / {1} ({2})", assetID, transferID, asset.ContentType);

                // Add this asset to the current upload list
                lock (currentUploads)
                    currentUploads[transferID] = asset;

                m_udp.SendPacket(agent, xfer, ThrottleCategory.Task, false);
            }
        }
        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);

                            m_assetCache.AddAsset(trans.Asset);
                            //check if we should add it to inventory
                            if (trans.AddToInventory)
                            {
                                // m_assetCache.AddAsset(trans.Asset);
                                m_inventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset);
                            }

                        }
                        break;
                    }

                }
            }

            ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket();
            confirmXfer.XferID.ID = xferPacket.XferID.ID;
            confirmXfer.XferID.Packet = xferPacket.XferID.Packet;
            this.ourClient.OutPacket(confirmXfer);
        }
        public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID)
        {
            // Console.Write("asset upload request , type = " + pack.AssetBlock.Type.ToString());
            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;

            }
            else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5 | pack.AssetBlock.Type == 7)
            {

                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);
            }
        }
示例#16
0
        void SendXferPacketHandler(Packet packet, Agent agent)
        {
            SendXferPacketPacket xfer = (SendXferPacketPacket)packet;

            Asset asset;

            if (CurrentUploads.TryGetValue(xfer.XferID.ID, out asset))
            {
                if (asset.AssetData == null)
                {
                    if (xfer.XferID.Packet != 0)
                    {
                        Logger.Log(String.Format("Received Xfer packet {0} before the first packet!",
                                                 xfer.XferID.Packet), Helpers.LogLevel.Error);
                        return;
                    }

                    uint size = Utils.BytesToUInt(xfer.DataPacket.Data);
                    asset.AssetData = new byte[size];

                    Buffer.BlockCopy(xfer.DataPacket.Data, 4, asset.AssetData, 0, xfer.DataPacket.Data.Length - 4);

                    // Confirm the first upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID     = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    server.UDP.SendPacket(agent.AgentID, confirm, PacketCategory.Asset);
                }
                else
                {
                    Buffer.BlockCopy(xfer.DataPacket.Data, 0, asset.AssetData, (int)xfer.XferID.Packet * 1000,
                                     xfer.DataPacket.Data.Length);

                    // Confirm this upload packet
                    ConfirmXferPacketPacket confirm = new ConfirmXferPacketPacket();
                    confirm.XferID.ID     = xfer.XferID.ID;
                    confirm.XferID.Packet = xfer.XferID.Packet;
                    server.UDP.SendPacket(agent.AgentID, confirm, PacketCategory.Asset);

                    if ((xfer.XferID.Packet & (uint)0x80000000) != 0)
                    {
                        // Asset upload finished
                        Logger.DebugLog(String.Format("Completed Xfer upload of asset {0} ({1}", asset.AssetID, asset.AssetType));

                        lock (CurrentUploads)
                            CurrentUploads.Remove(xfer.XferID.ID);

                        StoreAsset(asset);

                        AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
                        complete.AssetBlock.Success = true;
                        complete.AssetBlock.Type    = (sbyte)asset.AssetType;
                        complete.AssetBlock.UUID    = asset.AssetID;
                        server.UDP.SendPacket(agent.AgentID, complete, PacketCategory.Asset);
                    }
                }
            }
            else
            {
                Logger.DebugLog("Received a SendXferPacket for an unknown upload");
            }
        }