示例#1
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);
            }
        }
示例#2
0
        /// <summary>
        /// Request an asset download through the almost deprecated Xfer system
        /// </summary>
        /// <param name="filename">Filename of the asset to request</param>
        /// <param name="deleteOnCompletion">Whether or not to delete the asset
        /// off the server after it is retrieved</param>
        /// <param name="useBigPackets">Use large transfer packets or not</param>
        /// <param name="vFileID">UUID of the file to request, if filename is
        /// left empty</param>
        /// <param name="vFileType">Asset type of <code>vFileID</code>, or
        /// <code>AssetType.Unknown</code> if filename is not empty</param>
        /// <returns></returns>
        public ulong RequestAssetXfer(string filename, bool deleteOnCompletion, bool useBigPackets, LLUUID vFileID, AssetType vFileType)
        {
            LLUUID uuid = LLUUID.Random();
            ulong  id   = uuid.ToULong();

            XferDownload transfer = new XferDownload();

            transfer.XferID    = id;
            transfer.ID        = new LLUUID(id); // Our dictionary tracks transfers with LLUUIDs, so convert the ulong back
            transfer.Filename  = filename;
            transfer.VFileID   = vFileID;
            transfer.AssetType = vFileType;

            // Add this transfer to the dictionary
            lock (Transfers) Transfers[transfer.ID] = transfer;

            RequestXferPacket request = new RequestXferPacket();

            request.XferID.ID       = id;
            request.XferID.Filename = Helpers.StringToField(filename);
            request.XferID.FilePath = 4; // "Cache". This is a horrible thing that hardcodes a file path enumeration in to the
                                         // protocol. For asset downloads we should only ever need this value
            request.XferID.DeleteOnCompletion = deleteOnCompletion;
            request.XferID.UseBigPackets      = useBigPackets;
            request.XferID.VFileID            = vFileID;
            request.XferID.VFileType          = (short)vFileType;

            Client.Network.SendPacket(request);

            return(id);
        }
        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);
            }
        }
示例#4
0
        /*private Packet ReplyTask(Packet packet, IPEndPoint sim)
         *  {
         *      Thread mythread = new Thread(new ThreadStart(delegate
         *      {
         *          ManualResetEvent finishevent = new ManualResetEvent(false);
         *          string filename = Utils.BytesToString(((ReplyTaskInventoryPacket)packet).InventoryData.Filename);
         *          ulong xferid = UUID.Random().GetULong();
         *          Dictionary<uint, byte[]> datapackets = new Dictionary<uint, byte[]>();
         *          bool datahasend = false;
         *          uint lastpacket = 0;
         *          PacketDelegate XferHandler = delegate(Packet packet3, IPEndPoint sim3)
         *          {
         *              SendXferPacketPacket xferpacket = (SendXferPacketPacket)packet3;
         *              if (xferpacket.XferID.ID == xferid)
         *              {
         *                  uint packetnumber = xferpacket.XferID.Packet & 0x7FFFFFFF;
         *                  if (!datapackets.ContainsKey(packetnumber))
         *                      datapackets[packetnumber] = xferpacket.DataPacket.Data;
         *                  if ((xferpacket.XferID.Packet & 0x80000000) != 0)
         *                  {
         *                      datahasend = true;
         *                      lastpacket = packetnumber;
         *                  }
         *                  if (datahasend)
         *                  {
         *                      if (datapackets.Count == (lastpacket + 1))
         *                      {
         *                          int size = 0;
         *                          foreach (KeyValuePair<uint, byte[]> kvp in datapackets)
         *                              size += kvp.Value.Length;
         *                          byte[] data = new byte[size - 4];
         *                          int offset = 0;
         *                          for (uint i = 0; i <= lastpacket; i++)
         *                          {
         *                              if (i == 0)
         *                              {
         *                                  Buffer.BlockCopy(datapackets[i], 4, data, offset, datapackets[i].Length - 4);
         *                                  offset += datapackets[i].Length - 4;
         *                              }
         *                              else
         *                              {
         *                                  Buffer.BlockCopy(datapackets[i], 0, data, offset, datapackets[i].Length);
         *                                  offset += datapackets[i].Length;
         *                              }
         *                          }
         *                          ReceiveInventoryFile(Utils.BytesToString(data));
         *                          finishevent.Set();
         *                      }
         *                  }
         *              }
         *              return packet3;
         *          };
         *          frame.proxy.AddDelegate(PacketType.SendXferPacket, Direction.Incoming, XferHandler);
         *          ManualResetEvent requestevent = new ManualResetEvent(false);
         *          PacketDelegate evtsetter = delegate(Packet packet2, IPEndPoint sim2)
         *          {
         *              if (Utils.BytesToString(((RequestXferPacket)packet2).XferID.Filename) == filename)
         *              {
         *                  xferid = ((RequestXferPacket)packet2).XferID.ID;
         *                  requestevent.Set();
         *              }
         *              return packet2;
         *          };
         *          frame.proxy.AddDelegate(PacketType.RequestXfer, Direction.Outgoing, evtsetter);
         *          bool needrequest = !requestevent.WaitOne(1000, false);
         *          frame.proxy.RemoveDelegate(PacketType.RequestXfer, Direction.Outgoing, evtsetter);
         *          if (needrequest)
         *          {
         *              RequestXferPacket request = new RequestXferPacket();
         *              request.XferID = new RequestXferPacket.XferIDBlock();
         *              request.XferID.ID = xferid;
         *              request.XferID.Filename = Utils.StringToBytes(filename);
         *              request.XferID.FilePath = 4;
         *              request.XferID.DeleteOnCompletion = true;
         *              request.XferID.UseBigPackets = false;
         *              request.XferID.VFileID = UUID.Zero;
         *              request.XferID.VFileType = -1;
         *              frame.proxy.InjectPacket(request, Direction.Outgoing);
         *          }
         *          finishevent.WaitOne(60000, false);
         *          frame.proxy.RemoveDelegate(PacketType.SendXferPacket, Direction.Incoming, XferHandler);
         *      }));
         *      mythread.Start();
         *      return packet;
         *
         * }*/
        /*private void ReceiveInventoryFile(string data)
         * {
         *  Console.Write("--------Received file:--------\n");
         *  Console.Write(data);
         *
         *  //UUID magic = new UUID("3c115e51-04f4-523c-9fa6-98aff1034730");
         *  string[] lines = data.Split('\n');
         *  UUID creatorid = UUID.Zero;
         *  string type = "";
         *  string inv_type = "";
         *  string name = "";
         *  string description = "";
         *  bool got = false;
         *  foreach (string line in lines)
         *  {
         *      string L = line.Trim();
         *      if (L.StartsWith("inv_item"))
         *      {
         *          if (got)
         *          {
         *              //ReceiveAssetInfo(name, description, creatorid, type, inv_type);
         *              return;
         *          }
         *          else
         *          {
         *              got = true;
         *              creatorid = UUID.Zero;
         *              name = "";
         *              inv_type = "";
         *              description = "";
         *          }
         *      }
         *      else if (L.StartsWith("creator_id\t"))
         *      {
         *          creatorid = new UUID(L.Substring(11).Trim());
         *      }
         *      else if (L.StartsWith("desc\t"))
         *      {
         *          description = L.Substring(5).Trim().TrimEnd('|');
         *      }
         *      else if (L.StartsWith("type\t"))
         *      {
         *          type = L.Substring(5).Trim();
         *      }
         *      else if (L.StartsWith("inv_type\t"))
         *      {
         *          inv_type = L.Substring(9).Trim();
         *      }
         *      else if (L.StartsWith("name\t"))
         *      {
         *          name = L.Substring(5).Trim().TrimEnd('|');
         *      }
         *  }
         * }*/
        /*private Packet TrasferReq(Packet packet, IPEndPoint sim)
         * {
         *  TransferRequestPacket trp = (TransferRequestPacket)packet;
         *  if (trp.TransferInfo.SourceType == 3)
         *  {
         *      /*smels
         *      Buffer.BlockCopy(frame.AgentID.GetBytes(), 0, paramField, 0, 16);
         *      Buffer.BlockCopy(frame.SessionID.GetBytes(), 0, paramField, 16, 16);
         *      Buffer.BlockCopy(item.OwnerID.GetBytes(), 0, paramField, 32, 16);
         *      Buffer.BlockCopy(UUID.Zero.GetBytes(), 0, paramField, 48, 16);
         *      Buffer.BlockCopy(item.UUID.GetBytes(), 0, paramField, 64, 16);
         *      Buffer.BlockCopy(item.AssetUUID.GetBytes(), 0, paramField, 80, 16);
         *      Buffer.BlockCopy(Helpers.IntToBytes((int)item.AssetType), 0, paramField, 96, 4);
         *      UUID itemid = new UUID(trp.TransferInfo.Params, 64);
         *      if (new List<string>(Directory.GetFiles("Scripts Cache")).Contains(itemid.ToString()))
         *      {
         *
         *          using (StreamReader r = new StreamReader("Scripts Cache\\"+itemid.ToString()))
         *          {
         *              byte[] data = Utils.StringToBytes(r.ReadToEnd());
         *              TransferPacketPacket tpp = new TransferPacketPacket();
         *              tpp.TransferData.ChannelType = trp.TransferInfo.ChannelType;
         *              tpp.TransferData.Status = (int)StatusCode.Done;
         *              tpp.TransferData.Packet = 0;
         *              tpp.TransferData.TransferID = trp.TransferInfo.TransferID;
         *              tpp.TransferData.Data = data;
         *              proxy.InjectPacket(tpp, Direction.Incoming);
         *
         *
         *              TransferInfoPacket tip = new TransferInfoPacket();
         *              tip.TransferInfo = new TransferInfoPacket.TransferInfoBlock();
         *              tip.TransferInfo.Params = trp.TransferInfo.Params;
         *              tip.TransferInfo.Size = 0;
         *              tip.TransferInfo.Status = (int)StatusCode.OK;
         *              tip.TransferInfo.TargetType = 3;
         *              tip.TransferInfo.TransferID = trp.TransferInfo.TransferID ;
         *              tip.TransferInfo.ChannelType = 2;
         *              tip.Header.Reliable = true;
         *              proxy.InjectPacket(tip, Direction.Incoming);
         *          }
         *      }
         *
         *
         *  }
         *  return packet;
         * }*/
        private void ProcessRequest(RequestXferPacket requestRecived)
        {
            form.log("precesing the read request packet now", System.Drawing.Color.Green, System.Drawing.Color.Black);

            currentuploads[requestRecived.XferID.ID].proxySending = true;
            byte[][] datapackets = OpenBytecode(requestRecived.XferID.ID);

            SendXferPacketPacket SendXferPacket;

            OutgoingXfers.Add(requestRecived.XferID.ID, new lsotoolXfer(requestRecived.XferID.VFileID));
            for (uint i = 0; i < (this.currentuploads[requestRecived.XferID.ID].size); i++)
            {
                SendXferPacket        = new SendXferPacketPacket();
                SendXferPacket.XferID = new SendXferPacketPacket.XferIDBlock();
                this.currentuploads[requestRecived.XferID.ID].xferID = requestRecived.XferID.ID;
                SendXferPacket.XferID.ID     = requestRecived.XferID.ID;
                SendXferPacket.XferID.Packet = i;
                if (i == (this.currentuploads[requestRecived.XferID.ID].size - 1))
                {
                    SendXferPacket.XferID.Packet = i | 0x80000000;
                }
                SendXferPacket.DataPacket      = new SendXferPacketPacket.DataPacketBlock();
                SendXferPacket.DataPacket.Data = datapackets[i];
                OutgoingXfers[requestRecived.XferID.ID].Packets.Add(i, SendXferPacket);
            }

            // Start sending the new packets to the sim
            OutgoingXfers[requestRecived.XferID.ID].PacketIndex = 0;
            form.log("sent first packet with data\n" + Utils.BytesToString(OutgoingXfers[requestRecived.XferID.ID].Packets[0].DataPacket.Data), System.Drawing.Color.Yellow, System.Drawing.Color.DarkGreen);
            proxy.InjectPacket(OutgoingXfers[requestRecived.XferID.ID].Packets[0], Direction.Outgoing);
            //this.Scriptdata = OpenBytecode(fileDest);
        }
示例#5
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);
            }
        }
 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);
     }
 }
示例#7
0
        private void RequestXferHandler(Packet packet, LLAgent agent)
        {
            RequestXferPacket request = (RequestXferPacket)packet;

            string filename = Utils.BytesToString(request.XferID.Filename);

            UUID taskInventoryID;

            if (filename.StartsWith("inventory_") && filename.EndsWith(".tmp") && UUID.TryParse(filename.Substring(10, 36), out taskInventoryID))
            {
                // This is a request for a task inventory listing, which we generate on demand
                ISceneEntity entity;
                if (m_scene.TryGetEntity(taskInventoryID, out entity) && entity is LLPrimitive)
                {
                    LLPrimitive prim      = (LLPrimitive)entity;
                    byte[]      assetData = Encoding.UTF8.GetBytes(prim.Inventory.GetTaskInventoryAsset());

                    SendXferPacketPacket xfer = new SendXferPacketPacket();
                    xfer.XferID.ID = request.XferID.ID;

                    if (assetData.Length < 1000)
                    {
                        xfer.XferID.Packet   = 0 | LAST_PACKET_MARKER;
                        xfer.DataPacket.Data = new byte[assetData.Length + 4];
                        Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
                        Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, assetData.Length);

                        m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
                        m_log.Debug("Completed single packet xfer download of " + filename);
                    }
                    else
                    {
                        xfer.XferID.Packet   = 0;
                        xfer.DataPacket.Data = new byte[1000 + 4];
                        Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
                        Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, 1000);

                        // We don't need the entire XferDownload class, just the asset data and the current packet number
                        XferDownload download = new XferDownload();
                        download.AssetData = assetData;
                        download.PacketNum = 1;
                        download.Filename  = filename;
                        lock (currentDownloads)
                            currentDownloads[request.XferID.ID] = download;

                        m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
                    }
                }
                else
                {
                    m_log.Warn("Could not find primitive " + taskInventoryID);
                }
            }
            else
            {
                m_log.Warn("Got a RequestXfer for an unknown file: " + filename);
            }
        }
示例#8
0
        private Packet ServerRequestsMyDataToStart(Packet packet, IPEndPoint sim)
        {
            RequestXferPacket requestRecived = (RequestXferPacket)packet;

            if (true)
            {
                if (requestRecived.XferID.VFileType == (short)AssetType.LSLText)
                {
                    form.log("Server requestd us to start something lsl " +
                             requestRecived.XferID.VFileType.ToString() + " and its vfile id was " + requestRecived.XferID.VFileID.ToString()
                             , System.Drawing.Color.Magenta, System.Drawing.Color.Black);

                    if (uploadsLookingForXferId.ContainsKey(requestRecived.XferID.VFileID))
                    {
                        form.log("We were expecting this! its vfile matches the asset id agreed upon , adding for later processing", System.Drawing.Color.Magenta, System.Drawing.Color.DarkGray);

                        uploadsLookingForXferId[requestRecived.XferID.VFileID].xferID = requestRecived.XferID.ID;
                        if (!currentuploads.ContainsKey(requestRecived.XferID.ID))
                        {
                            currentuploads.Add(requestRecived.XferID.ID, uploadsLookingForXferId[requestRecived.XferID.VFileID]);
                        }
                        else
                        {
                            currentuploads[requestRecived.XferID.ID] = uploadsLookingForXferId[requestRecived.XferID.VFileID];
                        }
                        uploadsLookingForXferId.Remove(requestRecived.XferID.VFileID);

                        //TODO: we need to do this AFTER we get the script;
                        if (requests2Process.ContainsKey(requestRecived.XferID.ID))
                        {
                            requests2Process[requestRecived.XferID.ID] = requestRecived;
                        }
                        else
                        {
                            requests2Process.Add(requestRecived.XferID.ID, requestRecived);
                        }

                        /*
                         * if (uploadsLookingForXferId[requestRecived.XferID.VFileID].oldscriptdata.Length > 0)
                         * {
                         *  form.log("Old Script data finished in first packet", System.Drawing.Color.Blue, System.Drawing.Color.Black);
                         *  if (requests2Process.ContainsKey(requestRecived.XferID.ID))
                         *  {
                         *      ProcessRequest(requests2Process[requestRecived.XferID.ID]);
                         *      requests2Process.Remove(requestRecived.XferID.ID);
                         *  }
                         * }*/

                        return(packet);
                    }
                }
            }
            return(packet);
        }
示例#9
0
        private void RequestXferCallbackHandler(Packet packet, Simulator simulator)
        {
            #if DEBUG_PACKETS
            slClient.DebugLog(packet);
            #endif

            RequestXferPacket reply = (RequestXferPacket)packet;

            ulong XferID = reply.XferID.ID;
            // LLUUID AssetID = reply.XferID.VFileID; //Not used...

            curUploadRequest.RequestXfer(XferID);
        }
示例#10
0
        private void RequestXferCallbackHandler(Packet packet, Simulator simulator)
        {
            #if DEBUG_PACKETS
            slClient.Log(packet.ToString(), Helpers.LogLevel.Info);
            #endif

            RequestXferPacket reply = (RequestXferPacket)packet;

            ulong XferID = reply.XferID.ID;
            // LLUUID AssetID = reply.XferID.VFileID; //Not used...

            if (curUploadRequest != null)
            {
                curUploadRequest.RequestXfer(XferID);
            }
        }
示例#11
0
        private Packet ServerRequestsMyDataToStart(Packet packet, IPEndPoint sim)
        {
            RequestXferPacket requestRecived = (RequestXferPacket)packet;

            /*SayToUser("vfile id is " + requestRecived.XferID.VFileID.UUID +
             *  " and id is " + requestRecived.XferID.ID.ToString()
             +" and uploadid is "+ uploadID
             + " and special id is "+specialID
             +" and filename is "+Utils.BytesToString(requestRecived.XferID.Filename)
             +" and filepath is "+requestRecived.XferID.FilePath.ToString());
             +
             */

            if (grabbed == 0)
            {
                grabbed++;
                Console.WriteLine("Server tells me to start data");

                byte[][] datapackets = OpenBytecode(curentUpload.data);


                SendXferPacketPacket SendXferPacket;
                OutgoingXfers.Add(requestRecived.XferID.ID, new lsotoolXfer(requestRecived.XferID.VFileID));
                for (uint i = 0; i < (curentUpload.size); i++)
                {
                    SendXferPacket               = new SendXferPacketPacket();
                    SendXferPacket.XferID        = new SendXferPacketPacket.XferIDBlock();
                    SendXferPacket.XferID.ID     = requestRecived.XferID.ID;
                    SendXferPacket.XferID.Packet = i;
                    if (i == (curentUpload.size - 1))
                    {
                        SendXferPacket.XferID.Packet = i | 0x80000000;
                    }
                    SendXferPacket.DataPacket      = new SendXferPacketPacket.DataPacketBlock();
                    SendXferPacket.DataPacket.Data = datapackets[i];
                    OutgoingXfers[requestRecived.XferID.ID].Packets.Add(i, SendXferPacket);
                }

                // Start sending the new packets to the sim
                OutgoingXfers[requestRecived.XferID.ID].PacketIndex = 0;
                proxy.InjectPacket(OutgoingXfers[requestRecived.XferID.ID].Packets[0], Direction.Outgoing);
                //this.Scriptdata = OpenBytecode(fileDest);

                return(null);
            }
            return(packet);
        }
示例#12
0
        private void RequestXferHandler(Packet packet, Simulator simulator)
        {
            if (PendingUpload == null)
            {
                Client.Log("Received a RequestXferPacket for an unknown asset upload", Helpers.LogLevel.Warning);
            }
            else
            {
                AssetUpload upload = PendingUpload;
                PendingUpload = null;
                PendingUploadEvent.Set();
                RequestXferPacket request = (RequestXferPacket)packet;

                upload.XferID = request.XferID.ID;
                upload.Type   = (AssetType)request.XferID.VFileType;

                LLUUID transferID = new LLUUID(upload.XferID);
                Transfers[transferID] = upload;

                // Send the first packet containing actual asset data
                SendNextUploadPacket(upload);
            }
        }
示例#13
0
        /// <summary>
        /// Request an asset download through the almost deprecated Xfer system
        /// </summary>
        /// <param name="filename">Filename of the asset to request</param>
        /// <param name="deleteOnCompletion">Whether or not to delete the asset
        /// off the server after it is retrieved</param>
        /// <param name="useBigPackets">Use large transfer packets or not</param>
        /// <param name="vFileID">UUID of the file to request, if filename is
        /// left empty</param>
        /// <param name="vFileType">Asset type of <code>vFileID</code>, or
        /// <code>AssetType.Unknown</code> if filename is not empty</param>
        /// <param name="fromCache">Sets the FilePath in the request to Cache
        /// (4) if true, otherwise Unknown (0) is used</param>
        /// <returns></returns>
        public ulong RequestAssetXfer(string filename, bool deleteOnCompletion, bool useBigPackets, UUID vFileID, AssetType vFileType,
            bool fromCache)
        {
            UUID uuid = UUID.Random();
            ulong id = uuid.GetULong();

            XferDownload transfer = new XferDownload();
            transfer.XferID = id;
            transfer.ID = new UUID(id); // Our dictionary tracks transfers with UUIDs, so convert the ulong back
            transfer.Filename = filename;
            transfer.VFileID = vFileID;
            transfer.AssetType = vFileType;

            // Add this transfer to the dictionary
            lock (Transfers) Transfers[transfer.ID] = transfer;

            RequestXferPacket request = new RequestXferPacket();
            request.XferID.ID = id;
            request.XferID.Filename = Utils.StringToBytes(filename);
            request.XferID.FilePath = fromCache ? (byte)4 : (byte)0;
            request.XferID.DeleteOnCompletion = deleteOnCompletion;
            request.XferID.UseBigPackets = useBigPackets;
            request.XferID.VFileID = vFileID;
            request.XferID.VFileType = (short)vFileType;

            Client.Network.SendPacket(request);

            return id;
        }
示例#14
0
        /// <summary>
        /// Request an asset download through the almost deprecated Xfer system
        /// </summary>
        /// <param name="filename">Filename of the asset to request</param>
        /// <param name="deleteOnCompletion">Whether or not to delete the asset
        /// off the server after it is retrieved</param>
        /// <param name="useBigPackets">Use large transfer packets or not</param>
        /// <param name="vFileID">UUID of the file to request, if filename is
        /// left empty</param>
        /// <param name="vFileType">Asset type of <code>vFileID</code>, or
        /// <code>AssetType.Unknown</code> if filename is not empty</param>
        /// <returns></returns>
        public ulong RequestAssetXfer(string filename, bool deleteOnCompletion, bool useBigPackets, LLUUID vFileID, AssetType vFileType)
        {
            LLUUID uuid = LLUUID.Random();
            ulong id = uuid.GetULong();

            XferDownload transfer = new XferDownload();
            transfer.XferID = id;
            transfer.ID = new LLUUID(id); // Our dictionary tracks transfers with LLUUIDs, so convert the ulong back
            transfer.Filename = filename;
            transfer.VFileID = vFileID;
            transfer.AssetType = vFileType;

            // Add this transfer to the dictionary
            lock (Transfers) Transfers[transfer.ID] = transfer;

            RequestXferPacket request = new RequestXferPacket();
            request.XferID.ID = id;
            request.XferID.Filename = Helpers.StringToField(filename);
            request.XferID.FilePath = 4; // "Cache". This is a horrible thing that hardcodes a file path enumeration in to the
                                         // protocol. For asset downloads we should only ever need this value
            request.XferID.DeleteOnCompletion = deleteOnCompletion;
            request.XferID.UseBigPackets = useBigPackets;
            request.XferID.VFileID = vFileID;
            request.XferID.VFileType = (short)vFileType;

            Client.Network.SendPacket(request);

            return id;
        }
示例#15
0
        protected void RequestStartXfer()
        {
            Console.WriteLine("[AssetReceiver]: RequestStartXfer for transaction " + transferID);

            XferID = Util.GetNextXferID();
            RequestXferPacket newPack = new RequestXferPacket();
            newPack.XferID.ID = XferID;
            newPack.XferID.VFileType = m_asset.Type;
            newPack.XferID.VFileID = assetID;
            newPack.XferID.FilePath = 0;
            newPack.XferID.Filename = new byte[0];
            newPack.Header.Zerocoded = true;
            //OutPacket(newPack, ThrottleOutPacketType.Asset);
            proxy.InjectPacket(newPack, Direction.Incoming);
        }
示例#16
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);
            }
        }
示例#17
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);
            }
        }
示例#18
0
        /*private Packet ReplyTask(Packet packet, IPEndPoint sim)
            {
                Thread mythread = new Thread(new ThreadStart(delegate
                {
                    ManualResetEvent finishevent = new ManualResetEvent(false);
                    string filename = Utils.BytesToString(((ReplyTaskInventoryPacket)packet).InventoryData.Filename);
                    ulong xferid = UUID.Random().GetULong();
                    Dictionary<uint, byte[]> datapackets = new Dictionary<uint, byte[]>();
                    bool datahasend = false;
                    uint lastpacket = 0;
                    PacketDelegate XferHandler = delegate(Packet packet3, IPEndPoint sim3)
                    {
                        SendXferPacketPacket xferpacket = (SendXferPacketPacket)packet3;
                        if (xferpacket.XferID.ID == xferid)
                        {
                            uint packetnumber = xferpacket.XferID.Packet & 0x7FFFFFFF;
                            if (!datapackets.ContainsKey(packetnumber))
                                datapackets[packetnumber] = xferpacket.DataPacket.Data;
                            if ((xferpacket.XferID.Packet & 0x80000000) != 0)
                            {
                                datahasend = true;
                                lastpacket = packetnumber;
                            }
                            if (datahasend)
                            {
                                if (datapackets.Count == (lastpacket + 1))
                                {
                                    int size = 0;
                                    foreach (KeyValuePair<uint, byte[]> kvp in datapackets)
                                        size += kvp.Value.Length;
                                    byte[] data = new byte[size - 4];
                                    int offset = 0;
                                    for (uint i = 0; i <= lastpacket; i++)
                                    {
                                        if (i == 0)
                                        {
                                            Buffer.BlockCopy(datapackets[i], 4, data, offset, datapackets[i].Length - 4);
                                            offset += datapackets[i].Length - 4;
                                        }
                                        else
                                        {
                                            Buffer.BlockCopy(datapackets[i], 0, data, offset, datapackets[i].Length);
                                            offset += datapackets[i].Length;
                                        }
                                    }
                                    ReceiveInventoryFile(Utils.BytesToString(data));
                                    finishevent.Set();
                                }
                            }
                        }
                        return packet3;
                    };
                    frame.proxy.AddDelegate(PacketType.SendXferPacket, Direction.Incoming, XferHandler);
                    ManualResetEvent requestevent = new ManualResetEvent(false);
                    PacketDelegate evtsetter = delegate(Packet packet2, IPEndPoint sim2)
                    {
                        if (Utils.BytesToString(((RequestXferPacket)packet2).XferID.Filename) == filename)
                        {
                            xferid = ((RequestXferPacket)packet2).XferID.ID;
                            requestevent.Set();
                        }
                        return packet2;
                    };
                    frame.proxy.AddDelegate(PacketType.RequestXfer, Direction.Outgoing, evtsetter);
                    bool needrequest = !requestevent.WaitOne(1000, false);
                    frame.proxy.RemoveDelegate(PacketType.RequestXfer, Direction.Outgoing, evtsetter);
                    if (needrequest)
                    {
                        RequestXferPacket request = new RequestXferPacket();
                        request.XferID = new RequestXferPacket.XferIDBlock();
                        request.XferID.ID = xferid;
                        request.XferID.Filename = Utils.StringToBytes(filename);
                        request.XferID.FilePath = 4;
                        request.XferID.DeleteOnCompletion = true;
                        request.XferID.UseBigPackets = false;
                        request.XferID.VFileID = UUID.Zero;
                        request.XferID.VFileType = -1;
                        frame.proxy.InjectPacket(request, Direction.Outgoing);
                    }
                    finishevent.WaitOne(60000, false);
                    frame.proxy.RemoveDelegate(PacketType.SendXferPacket, Direction.Incoming, XferHandler);
                }));
                mythread.Start();
                return packet;

        }*/
        /*private void ReceiveInventoryFile(string data)
        {
            Console.Write("--------Received file:--------\n");
            Console.Write(data);

            //UUID magic = new UUID("3c115e51-04f4-523c-9fa6-98aff1034730");
            string[] lines = data.Split('\n');
            UUID creatorid = UUID.Zero;
            string type = "";
            string inv_type = "";
            string name = "";
            string description = "";
            bool got = false;
            foreach (string line in lines)
            {
                string L = line.Trim();
                if (L.StartsWith("inv_item"))
                {
                    if (got)
                    {
                        //ReceiveAssetInfo(name, description, creatorid, type, inv_type);
                        return;
                    }
                    else
                    {
                        got = true;
                        creatorid = UUID.Zero;
                        name = "";
                        inv_type = "";
                        description = "";
                    }
                }
                else if (L.StartsWith("creator_id\t"))
                {
                    creatorid = new UUID(L.Substring(11).Trim());
                }
                else if (L.StartsWith("desc\t"))
                {
                    description = L.Substring(5).Trim().TrimEnd('|');
                }
                else if (L.StartsWith("type\t"))
                {
                    type = L.Substring(5).Trim();
                }
                else if (L.StartsWith("inv_type\t"))
                {
                    inv_type = L.Substring(9).Trim();
                }
                else if (L.StartsWith("name\t"))
                {
                    name = L.Substring(5).Trim().TrimEnd('|');
                }
            }
        }*/
        /*private Packet TrasferReq(Packet packet, IPEndPoint sim)
        {
            TransferRequestPacket trp = (TransferRequestPacket)packet;
            if (trp.TransferInfo.SourceType == 3)
            {
                /*smels
                Buffer.BlockCopy(frame.AgentID.GetBytes(), 0, paramField, 0, 16);
                Buffer.BlockCopy(frame.SessionID.GetBytes(), 0, paramField, 16, 16);
                Buffer.BlockCopy(item.OwnerID.GetBytes(), 0, paramField, 32, 16);
                Buffer.BlockCopy(UUID.Zero.GetBytes(), 0, paramField, 48, 16);
                Buffer.BlockCopy(item.UUID.GetBytes(), 0, paramField, 64, 16);
                Buffer.BlockCopy(item.AssetUUID.GetBytes(), 0, paramField, 80, 16);
                Buffer.BlockCopy(Helpers.IntToBytes((int)item.AssetType), 0, paramField, 96, 4);
                UUID itemid = new UUID(trp.TransferInfo.Params, 64);
                if (new List<string>(Directory.GetFiles("Scripts Cache")).Contains(itemid.ToString()))
                {

                    using (StreamReader r = new StreamReader("Scripts Cache\\"+itemid.ToString()))
                    {
                        byte[] data = Utils.StringToBytes(r.ReadToEnd());
                        TransferPacketPacket tpp = new TransferPacketPacket();
                        tpp.TransferData.ChannelType = trp.TransferInfo.ChannelType;
                        tpp.TransferData.Status = (int)StatusCode.Done;
                        tpp.TransferData.Packet = 0;
                        tpp.TransferData.TransferID = trp.TransferInfo.TransferID;
                        tpp.TransferData.Data = data;
                        proxy.InjectPacket(tpp, Direction.Incoming);

                        TransferInfoPacket tip = new TransferInfoPacket();
                        tip.TransferInfo = new TransferInfoPacket.TransferInfoBlock();
                        tip.TransferInfo.Params = trp.TransferInfo.Params;
                        tip.TransferInfo.Size = 0;
                        tip.TransferInfo.Status = (int)StatusCode.OK;
                        tip.TransferInfo.TargetType = 3;
                        tip.TransferInfo.TransferID = trp.TransferInfo.TransferID ;
                        tip.TransferInfo.ChannelType = 2;
                        tip.Header.Reliable = true;
                        proxy.InjectPacket(tip, Direction.Incoming);
                    }
                }

            }
            return packet;
        }*/
        private void ProcessRequest(RequestXferPacket requestRecived)
        {
            form.log("precesing the read request packet now", System.Drawing.Color.Green, System.Drawing.Color.Black);

            currentuploads[requestRecived.XferID.ID].proxySending = true;
            byte[][] datapackets = OpenBytecode(requestRecived.XferID.ID);

            SendXferPacketPacket SendXferPacket;

            OutgoingXfers.Add(requestRecived.XferID.ID, new lsotoolXfer(requestRecived.XferID.VFileID));
            for (uint i = 0; i < (this.currentuploads[requestRecived.XferID.ID].size); i++)
            {
                SendXferPacket = new SendXferPacketPacket();
                SendXferPacket.XferID = new SendXferPacketPacket.XferIDBlock();
                this.currentuploads[requestRecived.XferID.ID].xferID = requestRecived.XferID.ID;
                SendXferPacket.XferID.ID = requestRecived.XferID.ID;
                SendXferPacket.XferID.Packet = i;
                if (i == (this.currentuploads[requestRecived.XferID.ID].size - 1))
                    SendXferPacket.XferID.Packet = i | 0x80000000;
                SendXferPacket.DataPacket = new SendXferPacketPacket.DataPacketBlock();
                SendXferPacket.DataPacket.Data = datapackets[i];
                OutgoingXfers[requestRecived.XferID.ID].Packets.Add(i, SendXferPacket);
            }

            // Start sending the new packets to the sim
            OutgoingXfers[requestRecived.XferID.ID].PacketIndex = 0;
            form.log("sent first packet with data\n" + Utils.BytesToString(OutgoingXfers[requestRecived.XferID.ID].Packets[0].DataPacket.Data), System.Drawing.Color.Yellow, System.Drawing.Color.DarkGreen);
            proxy.InjectPacket(OutgoingXfers[requestRecived.XferID.ID].Packets[0], Direction.Outgoing);
            //this.Scriptdata = OpenBytecode(fileDest);
        }