Ejemplo n.º 1
0
        public bool GetImage(RequestImagePacket imgPacket)
        {
            RequestImagePacket.RequestImageBlock[] invImgBlocks = new RequestImagePacket.RequestImageBlock[imgPacket.RequestImage.Length];
            for (int i = 0; i < imgPacket.RequestImage.Length; i++)
            {
                invImgBlocks[i] = imgPacket.RequestImage[i];

                lock (textureSenders)
                {
                    if (!textureSenders.ContainsKey(imgPacket.RequestImage[i].Image))
                    {
                        TextureSender sender = new TextureSender(this, proxy, imgPacket.RequestImage[i].DiscardLevel, imgPacket.RequestImage[i].Packet);
                        textureSenders.Add(imgPacket.RequestImage[i].Image, sender);
                        m_RegionAssetService.Get(imgPacket.RequestImage[i].Image.ToString(), sender, TextureReceived);
                        //old: assClient.RequestAsset(imgPacket.RequestImage[i].Image, true);
                        //older: assDownloader.RequestAsset(imgPacket.RequestImage[i].Image, true, AuthToken);
                    }
                    else
                    {
                        TextureSender sender = textureSenders[imgPacket.RequestImage[i].Image];
                        sender.UpdateRequest(imgPacket.RequestImage[i].DiscardLevel, imgPacket.RequestImage[i].Packet);
                    }
                }
                Console.WriteLine("  >> Image is region asset");
            }

            // Don't forward
            return true;
        }
Ejemplo n.º 2
0
        private void RequestImageHandler(Packet packet, LLAgent agent)
        {
            RequestImagePacket request = (RequestImagePacket)packet;

            for (int i = 0; i < request.RequestImage.Length; i++)
            {
                RequestImagePacket.RequestImageBlock block = request.RequestImage[i];
                EnqueueRequest(agent, block.Image, block.DiscardLevel, block.DownloadPriority, block.Packet, packet.Header.Sequence);
            }
        }
Ejemplo n.º 3
0
        void RequestImageHandler(Packet packet, Agent agent)
        {
            RequestImagePacket request = (RequestImagePacket)packet;

            for (int i = 0; i < request.RequestImage.Length; i++)
            {
                RequestImagePacket.RequestImageBlock block = request.RequestImage[i];

                ImageDownload download;
                bool          downloadFound = CurrentDownloads.TryGetValue(block.Image, out download);

                if (downloadFound)
                {
                    lock (download)
                    {
                        if (block.DiscardLevel == -1 && block.DownloadPriority == 0.0f)
                        {
                            Logger.DebugLog(String.Format("Image download {0} is aborting", block.Image));
                        }
                        else
                        {
                            if (block.DiscardLevel < download.DiscardLevel)
                            {
                                Logger.DebugLog(String.Format("Image download {0} is changing from DiscardLevel {1} to {2}",
                                                              block.Image, download.DiscardLevel, block.DiscardLevel));
                            }

                            if (block.DownloadPriority != download.Priority)
                            {
                                Logger.DebugLog(String.Format("Image download {0} is changing from Priority {1} to {2}",
                                                              block.Image, download.Priority, block.DownloadPriority));
                            }

                            if (block.Packet != download.CurrentPacket)
                            {
                                Logger.DebugLog(String.Format("Image download {0} is changing from Packet {1} to {2}",
                                                              block.Image, download.CurrentPacket, block.Packet));
                            }
                        }

                        // Update download
                        download.Update(block.DiscardLevel, block.DownloadPriority, (int)block.Packet);
                    }
                }
                else if (block.DiscardLevel == -1 && block.DownloadPriority == 0.0f)
                {
                    // Aborting a download we are not tracking, ignore
                    Logger.DebugLog(String.Format("Aborting an image download for untracked image " + block.Image.ToString()));
                }
                else
                {
                    bool bake = ((ImageType)block.Type == ImageType.Baked);

                    // New download, check if we have this image
                    Asset asset;
                    if (server.Assets.TryGetAsset(block.Image, out asset) && asset is AssetTexture)
                    {
                        download = new ImageDownload((AssetTexture)asset, block.DiscardLevel, block.DownloadPriority,
                                                     (int)block.Packet);

                        Logger.DebugLog(String.Format(
                                            "Starting new download for {0}, DiscardLevel: {1}, Priority: {2}, Start: {3}, End: {4}, Total: {5}",
                                            block.Image, block.DiscardLevel, block.DownloadPriority, download.CurrentPacket, download.StopPacket,
                                            download.TexturePacketCount()));

                        // Send initial data
                        ImageDataPacket data = new ImageDataPacket();
                        data.ImageID.Codec   = (byte)ImageCodec.J2C;
                        data.ImageID.ID      = download.Texture.AssetID;
                        data.ImageID.Packets = (ushort)download.TexturePacketCount();
                        data.ImageID.Size    = (uint)download.Texture.AssetData.Length;

                        // The first bytes of the image are always sent in the ImageData packet
                        data.ImageData = new ImageDataPacket.ImageDataBlock();
                        int imageDataSize = (download.Texture.AssetData.Length >= ImageDownload.FIRST_IMAGE_PACKET_SIZE) ?
                                            ImageDownload.FIRST_IMAGE_PACKET_SIZE : download.Texture.AssetData.Length;
                        data.ImageData.Data = new byte[imageDataSize];
                        Buffer.BlockCopy(download.Texture.AssetData, 0, data.ImageData.Data, 0, imageDataSize);

                        server.UDP.SendPacket(agent.AgentID, data, PacketCategory.Texture);

                        // Check if ImagePacket packets need to be sent to complete this transfer
                        if (download.CurrentPacket <= download.StopPacket)
                        {
                            // Insert this download into the dictionary
                            lock (CurrentDownloads)
                                CurrentDownloads[block.Image] = download;

                            // Send all of the remaining packets
                            ThreadPool.QueueUserWorkItem(
                                delegate(object obj)
                            {
                                while (download.CurrentPacket <= download.StopPacket)
                                {
                                    if (download.Priority == 0.0f && download.DiscardLevel == -1)
                                    {
                                        break;
                                    }

                                    lock (download)
                                    {
                                        int imagePacketSize = (download.CurrentPacket == download.TexturePacketCount() - 1) ?
                                                              download.LastPacketSize() : ImageDownload.IMAGE_PACKET_SIZE;

                                        ImagePacketPacket transfer = new ImagePacketPacket();
                                        transfer.ImageID.ID        = block.Image;
                                        transfer.ImageID.Packet    = (ushort)download.CurrentPacket;
                                        transfer.ImageData.Data    = new byte[imagePacketSize];
                                        Buffer.BlockCopy(download.Texture.AssetData, download.CurrentBytePosition(),
                                                         transfer.ImageData.Data, 0, imagePacketSize);

                                        server.UDP.SendPacket(agent.AgentID, transfer, PacketCategory.Texture);

                                        ++download.CurrentPacket;
                                    }
                                }

                                Logger.DebugLog("Completed image transfer for " + block.Image.ToString());

                                // Transfer is complete, remove the reference
                                lock (CurrentDownloads)
                                    CurrentDownloads.Remove(block.Image);
                            }
                                );
                        }
                    }
                    else
                    {
                        Logger.Log("Request for a missing texture " + block.Image.ToString(), Helpers.LogLevel.Warning);

                        ImageNotInDatabasePacket notfound = new ImageNotInDatabasePacket();
                        notfound.ImageID.ID = block.Image;
                        server.UDP.SendPacket(agent.AgentID, notfound, PacketCategory.Texture);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public bool GetImage(RequestImagePacket imgPacket)
        {
            if (imgPacket.AgentData.AgentID.Equals(libOwner))
                // Tell grid surfer to forward request to region, because the Library is served from there (!)
                return false;

            RequestImagePacket.RequestImageBlock[] invImgBlocks = new RequestImagePacket.RequestImageBlock[imgPacket.RequestImage.Length];
            int count = 0;
            for (int i = 0; i < imgPacket.RequestImage.Length; i++)
            {
                //Console.WriteLine("  >> Requested image " + imgPacket.RequestImage[i].Image);
                if (IsInventoryAsset(imgPacket.RequestImage[i].Image))
                {
                    if (connected)
                    {
                        invImgBlocks[i] = imgPacket.RequestImage[i];
                        InventoryItemBase item = GetInventoryItem(imgPacket.RequestImage[i].Image);

                        if (item != null)
                        {
                            lock (textureSenders)
                            {
                                if (!textureSenders.ContainsKey(imgPacket.RequestImage[i].Image))
                                {
                                    lock (textureSenders)
                                        textureSenders.Add(imgPacket.RequestImage[i].Image, new TextureSender(this, proxy, imgPacket.RequestImage[i].DiscardLevel, imgPacket.RequestImage[i].Packet));
                                    assDownloader.RequestAsset(item, true);
                                }
                            }
                        }
                        count++;
                        Console.WriteLine("  >> Image is inventory item");
                    }
                }
                else
                    invImgBlocks[i] = null;
            }

            if (count == imgPacket.RequestImage.Length)
            {
                // They were all inventory images
                Console.WriteLine("  >> All images were inventory items");
                return true;
            }
            else if (count == 0)
            {
                // None of them were inventory items
                Console.WriteLine("  >> No images were inventory items");
                return false;
            }
            else
            {
                RequestImagePacket.RequestImageBlock[] iblocks = new RequestImagePacket.RequestImageBlock[imgPacket.RequestImage.Length - count];
                int j = 0;
                for (int i = 0; i < invImgBlocks.Length; i++)
                {
                    if (invImgBlocks[i] != null)
                        iblocks[j++] = imgPacket.RequestImage[i];
                }

                imgPacket.RequestImage = iblocks;
                Console.WriteLine("  >> Some images were inventory items " + (imgPacket.RequestImage.Length - count));

                // Forward this altered packet
                return false;
            }
        }
Ejemplo n.º 5
0
        public bool GetImage(RequestImagePacket imgPacket)
        {
            RequestImagePacket.RequestImageBlock[] invImgBlocks = new RequestImagePacket.RequestImageBlock[imgPacket.RequestImage.Length];
            for (int i = 0; i < imgPacket.RequestImage.Length; i++)
            {
                invImgBlocks[i] = imgPacket.RequestImage[i];

                lock (textureSenders)
                {
                    if (!textureSenders.ContainsKey(imgPacket.RequestImage[i].Image))
                    {
                        lock (textureSenders)
                            textureSenders.Add(imgPacket.RequestImage[i].Image, new TextureSender(proxy, imgPacket.RequestImage[i].DiscardLevel, imgPacket.RequestImage[i].Packet));
                        assClient.RequestAsset(imgPacket.RequestImage[i].Image, true);
                        //assDownloader.RequestAsset(imgPacket.RequestImage[i].Image, true, AuthToken);
                    }
                }
                Console.WriteLine("  >> Image is region asset");
            }

            // Don't forward
            return true;
        }