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); } }
/*private Packet UpdateInventory(Packet packet, IPEndPoint sim) * { * /* * UpdateInventoryItemPacket uip = (UpdateInventoryItemPacket)packet; * foreach (UpdateInventoryItemPacket.InventoryDataBlock block in uip.InventoryData) * { * if (block.Type == 10) * { * if(trans2Item.ContainsKey(block.TransactionID)) * { * trans2Item[block.TransactionID]=block.ItemID; * }else * trans2Item.Add(block.TransactionID, block.ItemID); * } * } * foreach (CurrentUploadType cu in name2SaveBuffer) * { * if (trans2Item.ContainsKey(cu.uploadID)) * { * string filename = trans2Item[curentUpload.uploadID].ToString(); * * File.WriteAllBytes("Scripts Cache\\" + filename, curentUpload.oldscriptdata); * } * } * name2SaveBuffer.Clear(); * return packet; * }*/ private Packet TryToSendAsset(Packet packet, IPEndPoint sim) { if (Enabled) { AssetUploadRequestPacket ass = (AssetUploadRequestPacket)packet; if (ass.AssetBlock.Type == (sbyte)AssetType.LSLText) { Console.WriteLine("Atempting to save to inv with asset type " + ass.AssetBlock.Type.ToString()); CurrentUploadType curentUpload = new CurrentUploadType(); curentUpload.proxySending = false; curentUpload.local = ass.AssetBlock.StoreLocal; curentUpload.temp = ass.AssetBlock.Tempfile; curentUpload.uploadID = ass.AssetBlock.TransactionID; curentUpload.type = ass.AssetBlock.Type; curentUpload.data = new byte[] { }; curentUpload.paid = false; curentUpload.oldscriptdata = new byte[300000]; /*uint newperms = 0; * newperms |= (uint)PermissionMask.Modify; * newperms |= (uint)PermissionMask.Copy; * newperms |= (uint)PermissionMask.Transfer; * * curentUpload.ownerMask = newperms;*/ curentUpload.curentdatalenght = 0; curentUpload.oldmaxsize = 90000; //Buffer.BlockCopy(ass.AssetBlock.AssetData, 0, curentUpload.oldscriptdata, 0, curentUpload.curentdatalenght); AssetUploadRequestPacket asetUp = new AssetUploadRequestPacket(); asetUp.AssetBlock.StoreLocal = curentUpload.local; asetUp.AssetBlock.Tempfile = false; asetUp.AssetBlock.TransactionID = curentUpload.uploadID; asetUp.AssetBlock.Type = (sbyte)AssetType.LSLText; asetUp.AssetBlock.AssetData = new byte[] { }; //proxy.InjectPacket(asetUp, Direction.Outgoing); //proxy curentUpload.VFileAssetID = UUID.Combine(curentUpload.uploadID, frame.SecureSessionID); form.log("We are expecintg a vfile id of " + curentUpload.VFileAssetID.ToString(), System.Drawing.Color.Black, System.Drawing.Color.Magenta); if (this.uploadsLookingForXferId.ContainsKey(curentUpload.VFileAssetID)) { this.uploadsLookingForXferId[curentUpload.VFileAssetID] = curentUpload; } else { this.uploadsLookingForXferId.Add(curentUpload.VFileAssetID, curentUpload); } } } return(packet); }
/// <summary> /// Send header to SL to let it know that a large asset upload is about to proceed. /// </summary> /// <param name="asset"></param> public static Packet AssetUploadRequestHeaderOnly(Asset asset, LLUUID TransactionID) { AssetUploadRequestPacket p = new AssetUploadRequestPacket(); p.AssetBlock.TransactionID = TransactionID; p.AssetBlock.Type = asset.Type; p.AssetBlock.Tempfile = asset.Tempfile; p.AssetBlock.AssetData = new byte[0]; p.AssetBlock.StoreLocal = false; return p; }
/// <summary> /// Send header to SL to let it know that a large asset upload is about to proceed. /// </summary> /// <param name="asset"></param> public static Packet AssetUploadRequestHeaderOnly(Asset asset, LLUUID TransactionID) { AssetUploadRequestPacket p = new AssetUploadRequestPacket(); p.AssetBlock.TransactionID = TransactionID; p.AssetBlock.Type = asset.Type; p.AssetBlock.Tempfile = asset.Tempfile; p.AssetBlock.AssetData = new byte[0]; p.AssetBlock.StoreLocal = false; return(p); }
public void SaveToSLInventory(byte[] uploaddata, String nname, sbyte type, bool copy, bool mod, bool trans, bool pay, bool local, bool temp) { Console.WriteLine("Atempting to save to inv"); uploadID = UUID.Random(); AssetUploadRequestPacket asetUp = new AssetUploadRequestPacket(); asetUp.AssetBlock.StoreLocal = local; asetUp.AssetBlock.Tempfile = temp; asetUp.AssetBlock.TransactionID = uploadID; specialID = UUID.Combine(uploadID, frame.SessionID); asetUp.AssetBlock.Type = (sbyte)type; asetUp.AssetBlock.AssetData = new byte[] { }; proxy.InjectPacket(asetUp, Direction.Outgoing); this.curentUpload = new CurrentUploadType(); curentUpload.name = nname; curentUpload.data = uploaddata; curentUpload.temp = temp; curentUpload.type = (sbyte)type; curentUpload.local = local; curentUpload.paid = pay; grabbed = 0; if (pay) { payMoney(10); } uint newperms = 0; if (mod) { newperms |= (uint)PermissionMask.Modify; } if (copy) { newperms |= (uint)PermissionMask.Copy; } if (trans) { newperms |= (uint)PermissionMask.Transfer; } curentUpload.ownerMask = newperms; //generate owner mask }
/// <summary> /// Upload a small asset where the entire asset will fit in a single packet (less then 500 bytes) /// </summary> /// <param name="asset"></param> public static Packet AssetUploadRequest(Asset asset, LLUUID TransactionID) { if (asset._AssetData.Length > 1000) { throw new Exception("Asset too large to use AssetUploadRequest, use AssetUploadRequestHaderOnly() instead."); } AssetUploadRequestPacket p = new AssetUploadRequestPacket(); p.AssetBlock.TransactionID = TransactionID; p.AssetBlock.Type = asset.Type; p.AssetBlock.Tempfile = asset.Tempfile; p.AssetBlock.AssetData = asset._AssetData; p.AssetBlock.StoreLocal = false; return p; }
/// <summary> /// Upload a small asset where the entire asset will fit in a single packet (less then 500 bytes) /// </summary> /// <param name="asset"></param> public static Packet AssetUploadRequest(Asset asset, LLUUID TransactionID) { if (asset.AssetData.Length > 1000) { throw new Exception("Asset too large to use AssetUploadRequest, use AssetUploadRequestHaderOnly() instead."); } AssetUploadRequestPacket p = new AssetUploadRequestPacket(); p.AssetBlock.TransactionID = TransactionID; p.AssetBlock.Type = asset.Type; p.AssetBlock.Tempfile = asset.Tempfile; p.AssetBlock.AssetData = asset.AssetData; p.AssetBlock.StoreLocal = false; return(p); }
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); } }
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); } }
/*private Packet UpdateInventory(Packet packet, IPEndPoint sim) { /* UpdateInventoryItemPacket uip = (UpdateInventoryItemPacket)packet; foreach (UpdateInventoryItemPacket.InventoryDataBlock block in uip.InventoryData) { if (block.Type == 10) { if(trans2Item.ContainsKey(block.TransactionID)) { trans2Item[block.TransactionID]=block.ItemID; }else trans2Item.Add(block.TransactionID, block.ItemID); } } foreach (CurrentUploadType cu in name2SaveBuffer) { if (trans2Item.ContainsKey(cu.uploadID)) { string filename = trans2Item[curentUpload.uploadID].ToString(); File.WriteAllBytes("Scripts Cache\\" + filename, curentUpload.oldscriptdata); } } name2SaveBuffer.Clear(); return packet; }*/ private Packet TryToSendAsset(Packet packet, IPEndPoint sim) { if (Enabled) { AssetUploadRequestPacket ass = (AssetUploadRequestPacket)packet; if (ass.AssetBlock.Type == (sbyte)AssetType.LSLText) { Console.WriteLine("Atempting to save to inv with asset type " + ass.AssetBlock.Type.ToString()); CurrentUploadType curentUpload = new CurrentUploadType(); curentUpload.proxySending = false; curentUpload.local = ass.AssetBlock.StoreLocal; curentUpload.temp = ass.AssetBlock.Tempfile; curentUpload.uploadID = ass.AssetBlock.TransactionID; curentUpload.type = ass.AssetBlock.Type; curentUpload.data = new byte[] { }; curentUpload.paid = false; curentUpload.oldscriptdata = new byte[300000]; /*uint newperms = 0; newperms |= (uint)PermissionMask.Modify; newperms |= (uint)PermissionMask.Copy; newperms |= (uint)PermissionMask.Transfer; curentUpload.ownerMask = newperms;*/ curentUpload.curentdatalenght = 0; curentUpload.oldmaxsize = 90000; //Buffer.BlockCopy(ass.AssetBlock.AssetData, 0, curentUpload.oldscriptdata, 0, curentUpload.curentdatalenght); AssetUploadRequestPacket asetUp = new AssetUploadRequestPacket(); asetUp.AssetBlock.StoreLocal = curentUpload.local; asetUp.AssetBlock.Tempfile = false; asetUp.AssetBlock.TransactionID = curentUpload.uploadID; asetUp.AssetBlock.Type = (sbyte)AssetType.LSLText; asetUp.AssetBlock.AssetData = new byte[] { }; //proxy.InjectPacket(asetUp, Direction.Outgoing); //proxy curentUpload.VFileAssetID = UUID.Combine(curentUpload.uploadID, frame.SecureSessionID); form.log("We are expecintg a vfile id of " + curentUpload.VFileAssetID.ToString(), System.Drawing.Color.Black, System.Drawing.Color.Magenta); if (this.uploadsLookingForXferId.ContainsKey(curentUpload.VFileAssetID)) { this.uploadsLookingForXferId[curentUpload.VFileAssetID] = curentUpload; } else this.uploadsLookingForXferId.Add(curentUpload.VFileAssetID, curentUpload); } } return packet; }
public bool PostAsset(AssetUploadRequestPacket assUpload, UUID secureSessionID) { if (connected) { UUID assetID = UUID.Combine(assUpload.AssetBlock.TransactionID, secureSessionID); Console.WriteLine(" ------- RequestTransfer -----"); Console.WriteLine("assetID=" + assetID + "; data.length=" + assUpload.AssetBlock.AssetData.Length + "; local=" + assUpload.AssetBlock.StoreLocal + "; temp=" + assUpload.AssetBlock.Tempfile); if (!assUpload.AssetBlock.StoreLocal) { Console.WriteLine("[UserInventory]: AssetUploadRequest to inventory."); AssetReceiver assReceiver = new AssetReceiver(proxy, assetID, assUpload.AssetBlock.TransactionID); lock (assetReceivers) assetReceivers.Add(assUpload.AssetBlock.TransactionID, assReceiver); string uri = InventoryServerURL + "/" + AuthToken + "/PostAsset/"; assReceiver.ReceiveAndPostAsset(assUpload.AssetBlock.Type, assUpload.AssetBlock.AssetData, assUpload.AssetBlock.StoreLocal, assUpload.AssetBlock.Tempfile, uri); return true; } // Else, StoreLocal=true, seems to be an asset upload for the sim Console.WriteLine("[UserInventory]: Forwarding AssetUploadRequest to simulator."); } return false; }
/// <summary> /// Initiate an asset upload /// </summary> /// <param name="transactionID">The ID this asset will have if the /// upload succeeds</param> /// <param name="type">Asset type to upload this data as</param> /// <param name="data">Raw asset data to upload</param> /// <param name="tempFile">Whether this is a temporary file or not</param> /// <param name="storeLocal">Whether to store this asset on the local /// simulator or the grid-wide asset server</param> /// <param name="isPriority">Give this upload a higher priority</param> /// <returns>The transaction ID of this transfer</returns> public LLUUID RequestUpload(out LLUUID assetID, AssetType type, byte[] data, bool tempFile, bool storeLocal, bool isPriority) { AssetUpload upload = new AssetUpload(); upload.AssetData = data; upload.AssetType = type; upload.ID = LLUUID.Random(); assetID = LLUUID.Combine(upload.ID, Client.Self.SecureSessionID); upload.AssetID = assetID; upload.Size = data.Length; upload.XferID = 0; // Build and send the upload packet AssetUploadRequestPacket request = new AssetUploadRequestPacket(); request.AssetBlock.StoreLocal = storeLocal; request.AssetBlock.Tempfile = tempFile; request.AssetBlock.TransactionID = upload.ID; request.AssetBlock.Type = (sbyte)type; if (data.Length + 100 < Settings.MAX_PACKET_SIZE) { Client.Log( String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info); // The whole asset will fit in this packet, makes things easy request.AssetBlock.AssetData = data; upload.Transferred = data.Length; } else { Client.Log( String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info); // Asset is too big, send in multiple packets request.AssetBlock.AssetData = new byte[0]; } //Client.DebugLog(request.ToString()); /* * // Add this upload to the Transfers dictionary using the assetID as the key. * // Once the simulator assigns an actual identifier for this upload it will be * // removed from Transfers and reinserted with the proper identifier * lock (Transfers) Transfers[upload.AssetID] = upload; */ // Wait for the previous upload to receive a RequestXferPacket if (PendingUploadEvent.WaitOne(10000, false)) { PendingUpload = upload; Client.Network.SendPacket(request); return(upload.ID); } else { throw new Exception("Timeout waiting for previous asset upload to begin"); } }
public void SaveToSLInventory(byte[] uploaddata, String nname, sbyte type, bool copy, bool mod, bool trans, bool pay, bool local, bool temp) { Console.WriteLine("Atempting to save to inv"); uploadID = UUID.Random(); AssetUploadRequestPacket asetUp = new AssetUploadRequestPacket(); asetUp.AssetBlock.StoreLocal = local; asetUp.AssetBlock.Tempfile = temp; asetUp.AssetBlock.TransactionID = uploadID; specialID = UUID.Combine(uploadID, frame.SessionID); asetUp.AssetBlock.Type = (sbyte)type; asetUp.AssetBlock.AssetData = new byte[] { }; proxy.InjectPacket(asetUp, Direction.Outgoing); this.curentUpload = new CurrentUploadType(); curentUpload.name = nname; curentUpload.data = uploaddata; curentUpload.temp = temp; curentUpload.type = (sbyte)type; curentUpload.local = local; curentUpload.paid = pay; grabbed = 0; if (pay) payMoney(10); uint newperms = 0; if (mod) newperms |= (uint)PermissionMask.Modify; if (copy) newperms |= (uint)PermissionMask.Copy; if (trans) newperms |= (uint)PermissionMask.Transfer; curentUpload.ownerMask = newperms; //generate owner mask }
/// <summary> /// /// </summary> /// <param name="transactionID">Usually a randomly generated UUID</param> /// <param name="type"></param> /// <param name="data"></param> /// <param name="tempFile"></param> /// <param name="storeLocal"></param> /// <param name="isPriority"></param> public void RequestUpload(LLUUID transactionID, AssetType type, byte[] data, bool tempFile, bool storeLocal, bool isPriority) { if (!Transfers.ContainsKey(transactionID)) { AssetUpload upload = new AssetUpload(); upload.AssetData = data; upload.ID = transactionID; upload.AssetID = ((transactionID == LLUUID.Zero) ? transactionID : transactionID.Combine(Client.Network.SecureSessionID)); upload.Size = data.Length; upload.XferID = 0; // Build and send the upload packet AssetUploadRequestPacket request = new AssetUploadRequestPacket(); request.AssetBlock.StoreLocal = storeLocal; request.AssetBlock.Tempfile = tempFile; request.AssetBlock.TransactionID = upload.ID; request.AssetBlock.Type = (sbyte)type; if (data.Length + 100 < Settings.MAX_PACKET_SIZE) { Client.Log( String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToStringHyphenated(), upload.AssetID.ToStringHyphenated(), upload.Size), Helpers.LogLevel.Info); // The whole asset will fit in this packet, makes things easy request.AssetBlock.AssetData = data; upload.Transferred = data.Length; } else { Client.Log( String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToStringHyphenated(), upload.AssetID.ToStringHyphenated(), upload.Size), Helpers.LogLevel.Info); // Asset is too big, send in multiple packets request.AssetBlock.AssetData = new byte[0]; } //Client.DebugLog(request.ToString()); // Add this upload to the Transfers dictionary using the assetID as the key. // Once the simulator assigns an actual identifier for this upload it will be // removed from Transfers and reinserted with the proper identifier lock (Transfers) Transfers[upload.AssetID] = upload; Client.Network.SendPacket(request); } else { Client.Log("RequestUpload() called for an asset we are already uploading, ignoring", Helpers.LogLevel.Info); } }
/// <summary> /// Initiate an asset upload /// </summary> /// <param name="assetID">The ID this asset will have if the /// upload succeeds</param> /// <param name="type">Asset type to upload this data as</param> /// <param name="data">Raw asset data to upload</param> /// <param name="tempFile">Whether this is a temporary file or not</param> /// <param name="storeLocal">Whether to store this asset on the local /// simulator or the grid-wide asset server</param> /// <param name="isPriority">Give this upload a higher priority</param> /// <returns>The transaction ID of this transfer</returns> public LLUUID RequestUpload(out LLUUID assetID, AssetType type, byte[] data, bool tempFile, bool storeLocal, bool isPriority) { AssetUpload upload = new AssetUpload(); upload.AssetData = data; upload.AssetType = type; upload.ID = LLUUID.Random(); assetID = LLUUID.Combine(upload.ID, Client.Self.SecureSessionID); upload.AssetID = assetID; upload.Size = data.Length; upload.XferID = 0; // Build and send the upload packet AssetUploadRequestPacket request = new AssetUploadRequestPacket(); request.AssetBlock.StoreLocal = storeLocal; request.AssetBlock.Tempfile = tempFile; request.AssetBlock.TransactionID = upload.ID; request.AssetBlock.Type = (sbyte)type; if (data.Length + 100 < Settings.MAX_PACKET_SIZE) { Client.Log( String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info); // The whole asset will fit in this packet, makes things easy request.AssetBlock.AssetData = data; upload.Transferred = data.Length; } else { Client.Log( String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info); // Asset is too big, send in multiple packets request.AssetBlock.AssetData = new byte[0]; } //Client.DebugLog(request.ToString()); /* // Add this upload to the Transfers dictionary using the assetID as the key. // Once the simulator assigns an actual identifier for this upload it will be // removed from Transfers and reinserted with the proper identifier lock (Transfers) Transfers[upload.AssetID] = upload; */ // Wait for the previous upload to receive a RequestXferPacket if (PendingUploadEvent.WaitOne(10000, false)) { PendingUpload = upload; Client.Network.SendPacket(request); return upload.ID; } else throw new Exception("Timeout waiting for previous asset upload to begin"); }
/// <summary> /// Initiate an asset upload /// </summary> /// <param name="assetID">The ID this asset will have if the /// upload succeeds</param> /// <param name="type">Asset type to upload this data as</param> /// <param name="data">Raw asset data to upload</param> /// <param name="storeLocal">Whether to store this asset on the local /// simulator or the grid-wide asset server</param> /// <param name="transactionID">The tranaction id for the upload <see cref="RequestCreateItem"/></param> /// <returns>The transaction ID of this transfer</returns> public UUID RequestUpload(out UUID assetID, AssetType type, byte[] data, bool storeLocal, UUID transactionID) { AssetUpload upload = new AssetUpload(); upload.AssetData = data; upload.AssetType = type; assetID = UUID.Combine(transactionID, Client.Self.SecureSessionID); upload.AssetID = assetID; upload.Size = data.Length; upload.XferID = 0; upload.ID = transactionID; // Build and send the upload packet AssetUploadRequestPacket request = new AssetUploadRequestPacket(); request.AssetBlock.StoreLocal = storeLocal; request.AssetBlock.Tempfile = false; // This field is deprecated request.AssetBlock.TransactionID = transactionID; request.AssetBlock.Type = (sbyte)type; bool isMultiPacketUpload; if (data.Length + 100 < Settings.MAX_PACKET_SIZE) { isMultiPacketUpload = false; Logger.Log( String.Format("Beginning asset upload [Single Packet], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info, Client); Transfers[upload.ID] = upload; // The whole asset will fit in this packet, makes things easy request.AssetBlock.AssetData = data; upload.Transferred = data.Length; } else { isMultiPacketUpload = true; Logger.Log( String.Format("Beginning asset upload [Multiple Packets], ID: {0}, AssetID: {1}, Size: {2}", upload.ID.ToString(), upload.AssetID.ToString(), upload.Size), Helpers.LogLevel.Info, Client); // Asset is too big, send in multiple packets request.AssetBlock.AssetData = Utils.EmptyBytes; } // Wait for the previous upload to receive a RequestXferPacket lock (PendingUploadLock) { const int UPLOAD_CONFIRM_TIMEOUT = 20 * 1000; const int SLEEP_INTERVAL = 50; int t = 0; while (WaitingForUploadConfirm && t < UPLOAD_CONFIRM_TIMEOUT) { System.Threading.Thread.Sleep(SLEEP_INTERVAL); t += SLEEP_INTERVAL; } if (t < UPLOAD_CONFIRM_TIMEOUT) { if (isMultiPacketUpload) { WaitingForUploadConfirm = true; } PendingUpload = upload; Client.Network.SendPacket(request); return upload.ID; } else { throw new Exception("Timeout waiting for previous asset upload to begin"); } } }
protected virtual void ProcessInPacket(Packet Pack) { ack_pack(Pack); if (debug) { if (Pack.Type != PacketType.AgentUpdate) { Console.WriteLine(Pack.Type.ToString()); } } if (this.ProcessPacketMethod(Pack)) { //there is a handler registered that handled this packet type return; } else { System.Text.Encoding _enc = System.Text.Encoding.ASCII; switch (Pack.Type) { case PacketType.CompleteAgentMovement: if (this.m_child) { this.UpgradeClient(); } ClientAvatar.CompleteMovement(m_world); ClientAvatar.SendInitialPosition(); break; case PacketType.RegionHandshakeReply: m_world.SendLayerData(this); break; case PacketType.AgentWearablesRequest: ClientAvatar.SendInitialAppearance(); foreach (SimClient client in m_clientThreads.Values) { if (client.AgentID != this.AgentID) { ObjectUpdatePacket objupdate = client.ClientAvatar.CreateUpdatePacket(); this.OutPacket(objupdate); client.ClientAvatar.SendAppearanceToOtherAgent(this); } } m_world.GetInitialPrims(this); break; case PacketType.AgentIsNowWearing: AgentIsNowWearingPacket wear = (AgentIsNowWearingPacket)Pack; //Console.WriteLine(Pack.ToString()); break; case PacketType.AgentSetAppearance: AgentSetAppearancePacket appear = (AgentSetAppearancePacket)Pack; // Console.WriteLine(appear.ToString()); this.ClientAvatar.SetAppearance(appear); break; case PacketType.ObjectAdd: m_world.AddNewPrim((ObjectAddPacket)Pack, this); break; case PacketType.ObjectLink: OpenSim.Framework.Console.MainConsole.Instance.WriteLine(Pack.ToString()); ObjectLinkPacket link = (ObjectLinkPacket)Pack; uint parentprimid = 0; OpenSim.world.Primitive parentprim = null; if (link.ObjectData.Length > 1) { parentprimid = link.ObjectData[0].ObjectLocalID; foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == parentprimid) { parentprim = (OpenSim.world.Primitive)ent; } } for (int i = 1; i < link.ObjectData.Length; i++) { foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == link.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).MakeParent(parentprim); } } } } break; case PacketType.ObjectScale: OpenSim.Framework.Console.MainConsole.Instance.WriteLine(Pack.ToString()); break; case PacketType.ObjectShape: ObjectShapePacket shape = (ObjectShapePacket)Pack; for (int i = 0; i < shape.ObjectData.Length; i++) { foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == shape.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).UpdateShape(shape.ObjectData[i]); } } } break; case PacketType.RequestImage: RequestImagePacket imageRequest = (RequestImagePacket)Pack; for (int i = 0; i < imageRequest.RequestImage.Length; i++) { m_assetCache.AddTextureRequest(this, imageRequest.RequestImage[i].Image); } break; case PacketType.TransferRequest: //Console.WriteLine("OpenSimClient.cs:ProcessInPacket() - Got transfer request"); TransferRequestPacket transfer = (TransferRequestPacket)Pack; m_assetCache.AddAssetRequest(this, transfer); break; case PacketType.AgentUpdate: ClientAvatar.HandleUpdate((AgentUpdatePacket)Pack); break; case PacketType.ObjectImage: ObjectImagePacket imagePack = (ObjectImagePacket)Pack; for (int i = 0; i < imagePack.ObjectData.Length; i++) { foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == imagePack.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).UpdateTexture(imagePack.ObjectData[i].TextureEntry); } } } break; case PacketType.ObjectFlagUpdate: ObjectFlagUpdatePacket flags = (ObjectFlagUpdatePacket)Pack; foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == flags.AgentData.ObjectLocalID) { ((OpenSim.world.Primitive)ent).UpdateObjectFlags(flags); } } break; case PacketType.AssetUploadRequest: AssetUploadRequestPacket request = (AssetUploadRequestPacket)Pack; this.UploadAssets.HandleUploadPacket(request, request.AssetBlock.TransactionID.Combine(this.SecureSessionID)); break; case PacketType.RequestXfer: //Console.WriteLine(Pack.ToString()); break; case PacketType.SendXferPacket: this.UploadAssets.HandleXferPacket((SendXferPacketPacket)Pack); break; case PacketType.CreateInventoryFolder: CreateInventoryFolderPacket invFolder = (CreateInventoryFolderPacket)Pack; m_inventoryCache.CreateNewInventoryFolder(this, invFolder.FolderData.FolderID, (ushort)invFolder.FolderData.Type, Util.FieldToString(invFolder.FolderData.Name), invFolder.FolderData.ParentID); //Console.WriteLine(Pack.ToString()); break; case PacketType.CreateInventoryItem: //Console.WriteLine(Pack.ToString()); CreateInventoryItemPacket createItem = (CreateInventoryItemPacket)Pack; if (createItem.InventoryBlock.TransactionID != LLUUID.Zero) { this.UploadAssets.CreateInventoryItem(createItem); } else { // Console.Write(Pack.ToString()); this.CreateInventoryItem(createItem); } break; case PacketType.FetchInventory: //Console.WriteLine("fetch item packet"); FetchInventoryPacket FetchInventory = (FetchInventoryPacket)Pack; m_inventoryCache.FetchInventory(this, FetchInventory); break; case PacketType.FetchInventoryDescendents: FetchInventoryDescendentsPacket Fetch = (FetchInventoryDescendentsPacket)Pack; m_inventoryCache.FetchInventoryDescendents(this, Fetch); break; case PacketType.UpdateInventoryItem: UpdateInventoryItemPacket update = (UpdateInventoryItemPacket)Pack; //Console.WriteLine(Pack.ToString()); for (int i = 0; i < update.InventoryData.Length; i++) { if (update.InventoryData[i].TransactionID != LLUUID.Zero) { AssetBase asset = m_assetCache.GetAsset(update.InventoryData[i].TransactionID.Combine(this.SecureSessionID)); if (asset != null) { // Console.WriteLine("updating inventory item, found asset" + asset.FullID.ToStringHyphenated() + " already in cache"); m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); } else { asset = this.UploadAssets.AddUploadToAssetCache(update.InventoryData[i].TransactionID); if (asset != null) { //Console.WriteLine("updating inventory item, adding asset" + asset.FullID.ToStringHyphenated() + " to cache"); m_inventoryCache.UpdateInventoryItemAsset(this, update.InventoryData[i].ItemID, asset); } else { //Console.WriteLine("trying to update inventory item, but asset is null"); } } } else { m_inventoryCache.UpdateInventoryItemDetails(this, update.InventoryData[i].ItemID, update.InventoryData[i]);; } } break; case PacketType.ViewerEffect: ViewerEffectPacket viewer = (ViewerEffectPacket)Pack; foreach (SimClient client in m_clientThreads.Values) { if (client.AgentID != this.AgentID) { viewer.AgentData.AgentID = client.AgentID; viewer.AgentData.SessionID = client.SessionID; client.OutPacket(viewer); } } break; case PacketType.RequestTaskInventory: // Console.WriteLine(Pack.ToString()); RequestTaskInventoryPacket requesttask = (RequestTaskInventoryPacket)Pack; ReplyTaskInventoryPacket replytask = new ReplyTaskInventoryPacket(); bool foundent = false; foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == requesttask.InventoryData.LocalID) { replytask.InventoryData.TaskID = ent.uuid; replytask.InventoryData.Serial = 0; replytask.InventoryData.Filename = new byte[0]; foundent = true; } } if (foundent) { this.OutPacket(replytask); } break; case PacketType.UpdateTaskInventory: // Console.WriteLine(Pack.ToString()); UpdateTaskInventoryPacket updatetask = (UpdateTaskInventoryPacket)Pack; AgentInventory myinventory = this.m_inventoryCache.GetAgentsInventory(this.AgentID); if (myinventory != null) { if (updatetask.UpdateData.Key == 0) { if (myinventory.InventoryItems[updatetask.InventoryData.ItemID] != null) { if (myinventory.InventoryItems[updatetask.InventoryData.ItemID].Type == 7) { LLUUID noteaid = myinventory.InventoryItems[updatetask.InventoryData.ItemID].AssetID; AssetBase assBase = this.m_assetCache.GetAsset(noteaid); if (assBase != null) { foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == updatetask.UpdateData.LocalID) { if (ent is OpenSim.world.Primitive) { this.m_world.AddScript(ent, Util.FieldToString(assBase.Data)); } } } } } } } } break; case PacketType.AgentAnimation: if (!m_child) { AgentAnimationPacket AgentAni = (AgentAnimationPacket)Pack; for (int i = 0; i < AgentAni.AnimationList.Length; i++) { if (AgentAni.AnimationList[i].StartAnim) { ClientAvatar.current_anim = AgentAni.AnimationList[i].AnimID; ClientAvatar.anim_seq = 1; ClientAvatar.SendAnimPack(); } } } break; case PacketType.ObjectSelect: ObjectSelectPacket incomingselect = (ObjectSelectPacket)Pack; for (int i = 0; i < incomingselect.ObjectData.Length; i++) { foreach (Entity ent in m_world.Entities.Values) { if (ent.localid == incomingselect.ObjectData[i].ObjectLocalID) { ((OpenSim.world.Primitive)ent).GetProperites(this); break; } } } break; } } }