/// <summary> /// Handle responses from the simulator that tell us a texture we have requested is unable to be located /// or no longer exists. This will remove the request from the pipeline and free up a slot if one is in use /// </summary> /// <param name="sender">The sender</param> /// <param name="e">The EventArgs object containing the packet data</param> protected void ImageNotInDatabaseHandler(object sender, PacketReceivedEventArgs e) { ImageNotInDatabasePacket imageNotFoundData = (ImageNotInDatabasePacket)e.Packet; TaskInfo task; if (TryGetTransferValue(imageNotFoundData.ImageID.ID, out task)) { // cancel acive request and free up the threadpool slot if (task.State == TextureRequestState.Progress) { resetEvents[task.RequestSlot].Set(); } // fire callback to inform the caller foreach (TextureDownloadCallback callback in task.Callbacks) { callback(TextureRequestState.NotFound, new AssetTexture(imageNotFoundData.ImageID.ID, Utils.EmptyBytes)); } resetEvents[task.RequestSlot].Set(); RemoveTransfer(imageNotFoundData.ImageID.ID); } else { Logger.Log("Received an ImageNotFound packet for an image we did not request: " + imageNotFoundData.ImageID.ID, Helpers.LogLevel.Warning); } }
void pipeline_OnDownloadFinished(UUID id, bool success) { ImageDownload download; if (currentDownloads.TryGetValue(id, out download)) { lock (currentDownloads) currentDownloads.Remove(id); if (success) { // Set the texture to the downloaded texture data AssetTexture texture = new AssetTexture(id, Pipeline.GetTextureToRender(id).AssetData); download.Texture = texture; Pipeline.RemoveFromPipeline(id); // Store this texture in the local asset store for later server.Assets.StoreAsset(texture); SendTexture(download.Agent, download.Texture, download.DiscardLevel, download.CurrentPacket, download.Priority); } else { Logger.Log("[Periscope] Failed to download texture " + id.ToString(), Helpers.LogLevel.Warning); ImageNotInDatabasePacket notfound = new ImageNotInDatabasePacket(); notfound.ImageID.ID = id; server.UDP.SendPacket(download.Agent.Avatar.ID, notfound, PacketCategory.Texture); } } else { Logger.Log("[Periscope] Pipeline downloaded a texture we're not tracking, " + id.ToString(), Helpers.LogLevel.Warning); } }
/// <summary> /// /// </summary> public void ImageNotInDatabaseCallbackHandler(Packet packet, Simulator simulator) { #if DEBUG_PACKETS slClient.DebugLog(packet); #endif ImageNotInDatabasePacket reply = (ImageNotInDatabasePacket)packet; LLUUID ImageID = reply.ImageID.ID; // Lookup the request for this packet TransferRequest tr = null; lock (htDownloadRequests) { if (htDownloadRequests.ContainsKey(ImageID)) { tr = (TransferRequest)htDownloadRequests[ImageID]; } else { // Received a packet that doesn't belong to any requests in our queue, strange... return; } } tr.Status = false; tr.StatusMsg = "Image not in database"; tr.Completed.Set(); // Fire off image downloaded event FireImageRetrieved(ImageID, null, false, tr.StatusMsg); }
public void SendImageNotFound(UUID imageid) { ImageNotInDatabasePacket p = new ImageNotInDatabasePacket(); p.ImageID.ID = imageid; SentImageNotInDatabasePackets.Add(p); }
/// <summary> /// The requested image does not exist on the asset server /// </summary> private void ImageNotInDatabaseHandler(Packet packet, Simulator simulator) { ImageNotInDatabasePacket notin = (ImageNotInDatabasePacket)packet; ImageDownload transfer = null; lock (Transfers) { if (Transfers.ContainsKey(notin.ImageID.ID)) { transfer = (ImageDownload)Transfers[notin.ImageID.ID]; transfer.NotFound = true; Transfers.Remove(transfer.ID); } } // Fire the event with our transfer that contains Success = false; if (transfer != null && OnImageReceived != null) { try { OnImageReceived(transfer, null); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
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); } } } }
private void EnqueueRequest(LLAgent agent, UUID textureID, sbyte discardLevel, float priority, uint packetNumber, uint sequenceNumber) { J2KImage image; // Look up this texture download lock (m_priorityQueue) m_queuedTextures.TryGetValue(textureID, out image); if (image != null) { // Update for an existing texture request if (discardLevel == -1 && priority == 0f) { //m_log.Debug("[TEX]: (CAN) ID=" + textureID); try { lock (m_priorityQueue) { m_priorityQueue.Delete(image.PriorityQueueHandle); m_queuedTextures.Remove(textureID); } } catch (Exception) { } } else { //m_log.DebugFormat("[TEX]: (UPD) ID={0}: D={1}, S={2}, P={3}", textureID, discardLevel, packetNumber, priority); // Check the packet sequence to make sure this update isn't older than // one we've already received if (sequenceNumber > image.LastSequence) { // Update the sequence number of the last RequestImage packet image.LastSequence = sequenceNumber; //Update the requested discard level image.DiscardLevel = discardLevel; //Update the requested packet number image.StartPacket = Math.Max(1, packetNumber); //Update the requested priority image.Priority = priority; // Update the start/end offsets for this request image.UpdateOffsets(); UpdateImageInQueue(image); } } } else { // New texture request if (discardLevel == -1 && priority == 0f) { //m_log.DebugFormat("[TEX]: (IGN) ID={0}", textureID); } else { //m_log.DebugFormat("[TEX]: (NEW) ID={0}: D={1}, S={2}, P={3}", textureID, discardLevel, packetNumber, priority); Asset asset; if (m_assetClient.TryGetAsset(textureID, "image/x-j2c", out asset)) { image = new J2KImage(m_udp, asset, agent, discardLevel, Math.Max(1, packetNumber), priority); // Update the start/end offsets for this request image.UpdateOffsets(); // Add this download to the priority queue UpdateImageInQueue(image); } else { ImageNotInDatabasePacket missing = new ImageNotInDatabasePacket(); missing.ImageID.ID = textureID; m_udp.SendPacket(agent, missing, ThrottleCategory.Asset, true); } } } }
private Packet ImageDataHandler(Packet packet, IPEndPoint simulator) { if (form.getEnabled()) { ImageDataPacket data = (ImageDataPacket)packet; //(ImageCodec)data.ImageID.Codec; byte[] data2 = new byte[(int)data.ImageID.Size]; Buffer.BlockCopy(data.ImageData.Data, 0, data2, 0, data.ImageData.Data.Length); //we now have it in data... /* * data += 8; * S32 xsiz = ntohl(((U32*)data)[0]); * S32 ysiz = ntohl(((U32*)data)[1]); * S32 xosiz = ntohl(((U32*)data)[2]); * S32 yosiz = ntohl(((U32*)data)[3]); * S32 xtsiz = ntohl(((U32*)data)[4]); * S32 ytsiz = ntohl(((U32*)data)[5]); * //S32 xtosiz = ntohl(((U32*)data)[6]); * //S32 ytosiz = ntohl(((U32*)data)[7]); * if(xsiz < 16 || xsiz > 2048 || ysiz < 16 || ysiz > 2048) { */ byte[] four = new byte[4]; bool flag = false; for (int location = 8; location < 30; location += 4) { Buffer.BlockCopy(data2, location, four, 0, 4); int size = BitConverter.ToInt32(ReadBytes(four, 4), 0); if (flag) { Console.WriteLine("Loc = " + location.ToString() + "| IMAGE SIZE = " + size.ToString()); } if (location == 16 || location == 20) { //seem to always be zero if (size != 0) { //SendUserAlert("Well, i really don't think you are ever suposed to get this error... so.. remeber this key and send it to me"); flag = true; } } else { if (IsPowerOfTwo((uint)size) && size <= 2048 && size >= 1) { ///cool } else { flag = true; } } } if (flag) { //SendUserAlert("We Got a evil Image\nIts key is " + data.ImageID.ID.ToString()); frame.SendUserAlert("Possible Image Crash Prevented"); ImageNotInDatabasePacket no = new ImageNotInDatabasePacket(); no.ImageID.ID = data.ImageID.ID; proxy.InjectPacket(no, Direction.Incoming); return(null); } } return(packet); }
private Packet ImageDataHandler(Packet packet, IPEndPoint simulator) { if (form.getEnabled()) { ImageDataPacket data = (ImageDataPacket)packet; //(ImageCodec)data.ImageID.Codec; byte[] data2 = new byte[(int)data.ImageID.Size]; Buffer.BlockCopy(data.ImageData.Data, 0, data2, 0, data.ImageData.Data.Length); //we now have it in data... /* * data += 8; S32 xsiz = ntohl(((U32*)data)[0]); S32 ysiz = ntohl(((U32*)data)[1]); S32 xosiz = ntohl(((U32*)data)[2]); S32 yosiz = ntohl(((U32*)data)[3]); S32 xtsiz = ntohl(((U32*)data)[4]); S32 ytsiz = ntohl(((U32*)data)[5]); //S32 xtosiz = ntohl(((U32*)data)[6]); //S32 ytosiz = ntohl(((U32*)data)[7]); if(xsiz < 16 || xsiz > 2048 || ysiz < 16 || ysiz > 2048) { */ byte[] four = new byte[4]; bool flag = false; for (int location = 8; location < 30; location += 4) { Buffer.BlockCopy(data2, location, four, 0, 4); int size = BitConverter.ToInt32(ReadBytes(four, 4), 0); if (flag) Console.WriteLine("Loc = " + location.ToString() + "| IMAGE SIZE = " + size.ToString()); if (location == 16 || location == 20) { //seem to always be zero if (size != 0) { //SendUserAlert("Well, i really don't think you are ever suposed to get this error... so.. remeber this key and send it to me"); flag = true; } } else { if (IsPowerOfTwo((uint)size) && size <= 2048 && size >= 1) { ///cool } else { flag = true; } } } if (flag) { //SendUserAlert("We Got a evil Image\nIts key is " + data.ImageID.ID.ToString()); frame.SendUserAlert("Possible Image Crash Prevented"); ImageNotInDatabasePacket no = new ImageNotInDatabasePacket(); no.ImageID.ID = data.ImageID.ID; proxy.InjectPacket(no, Direction.Incoming); return null; } } return packet; }