diff options
author | MW | 2007-03-25 17:34:58 +0000 |
---|---|---|
committer | MW | 2007-03-25 17:34:58 +0000 |
commit | 40af8c256165eb6fb56f58e3c13ee9293e052f66 (patch) | |
tree | add744edd5c35ddc6de735cfab4ae39e944755d1 /OpenSim.RegionServer/AgentAssetUpload.cs | |
parent | Adding the only stuff that makes sense (diff) | |
download | opensim-SC-40af8c256165eb6fb56f58e3c13ee9293e052f66.zip opensim-SC-40af8c256165eb6fb56f58e3c13ee9293e052f66.tar.gz opensim-SC-40af8c256165eb6fb56f58e3c13ee9293e052f66.tar.bz2 opensim-SC-40af8c256165eb6fb56f58e3c13ee9293e052f66.tar.xz |
You want large textures, you shall have! - Xfer system now working for large asset uploads
Fixed the VS solution file.
Now forwars ViewerEffect messages onto the other clients
Renamed OpenSim.Framework/Inventory.cs to OpenSim.Framework/AgentInventory.cs
Diffstat (limited to 'OpenSim.RegionServer/AgentAssetUpload.cs')
-rw-r--r-- | OpenSim.RegionServer/AgentAssetUpload.cs | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/OpenSim.RegionServer/AgentAssetUpload.cs b/OpenSim.RegionServer/AgentAssetUpload.cs new file mode 100644 index 0000000..2b4d78f --- /dev/null +++ b/OpenSim.RegionServer/AgentAssetUpload.cs | |||
@@ -0,0 +1,212 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Framework.Assets; | ||
5 | using OpenSim.Framework.Utilities; | ||
6 | using libsecondlife; | ||
7 | using libsecondlife.Packets; | ||
8 | |||
9 | namespace OpenSim | ||
10 | { | ||
11 | public class AgentAssetUpload | ||
12 | { | ||
13 | private Dictionary<LLUUID, AssetTransaction> transactions = new Dictionary<LLUUID, AssetTransaction>(); | ||
14 | private SimClient ourClient; | ||
15 | |||
16 | public AgentAssetUpload(SimClient client) | ||
17 | { | ||
18 | this.ourClient = client; | ||
19 | } | ||
20 | |||
21 | public void AddUpload(LLUUID transactionID, AssetBase asset) | ||
22 | { | ||
23 | Console.WriteLine("adding upload asset"); | ||
24 | AssetTransaction upload = new AssetTransaction(); | ||
25 | lock (this.transactions) | ||
26 | { | ||
27 | upload.Asset = asset; | ||
28 | upload.TransactionID = transactionID; | ||
29 | this.transactions.Add(transactionID, upload); | ||
30 | } | ||
31 | if (upload.Asset.Data.Length > 2) | ||
32 | { | ||
33 | //is complete | ||
34 | upload.UploadComplete = true; | ||
35 | AssetUploadCompletePacket response = new AssetUploadCompletePacket(); | ||
36 | response.AssetBlock.Type = asset.Type; | ||
37 | response.AssetBlock.Success = true; | ||
38 | response.AssetBlock.UUID = transactionID.Combine(this.ourClient.SecureSessionID); | ||
39 | this.ourClient.OutPacket(response); | ||
40 | } | ||
41 | else | ||
42 | { | ||
43 | Console.WriteLine(" no data in upload request so use xfer system"); | ||
44 | upload.UploadComplete = false; | ||
45 | upload.XferID = Util.GetNextXferID(); | ||
46 | RequestXferPacket xfer = new RequestXferPacket(); | ||
47 | xfer.XferID.ID = upload.XferID; | ||
48 | xfer.XferID.VFileType = upload.Asset.Type; | ||
49 | xfer.XferID.VFileID = transactionID.Combine(this.ourClient.SecureSessionID); | ||
50 | xfer.XferID.FilePath = 0; | ||
51 | xfer.XferID.Filename = new byte[0]; | ||
52 | this.ourClient.OutPacket(xfer); | ||
53 | } | ||
54 | |||
55 | } | ||
56 | |||
57 | public AssetBase GetUpload(LLUUID transactionID) | ||
58 | { | ||
59 | if (this.transactions.ContainsKey(transactionID)) | ||
60 | { | ||
61 | return this.transactions[transactionID].Asset; | ||
62 | } | ||
63 | |||
64 | return null; | ||
65 | } | ||
66 | |||
67 | public void HandleUploadPacket(AssetUploadRequestPacket pack, LLUUID assetID) | ||
68 | { | ||
69 | |||
70 | AssetBase asset = null; | ||
71 | if (pack.AssetBlock.Type == 0) | ||
72 | { | ||
73 | |||
74 | //first packet for transaction | ||
75 | asset = new AssetBase(); | ||
76 | asset.FullID = assetID; | ||
77 | asset.Type = pack.AssetBlock.Type; | ||
78 | asset.InvType = asset.Type; | ||
79 | asset.Name = "UploadedTexture" + Util.RandomClass.Next(1, 1000).ToString("000"); | ||
80 | asset.Data = pack.AssetBlock.AssetData; | ||
81 | |||
82 | |||
83 | } | ||
84 | /* for now we will only support uploading of textures | ||
85 | else if (pack.AssetBlock.Type == 13 | pack.AssetBlock.Type == 5) | ||
86 | { | ||
87 | |||
88 | asset = new AssetBase(); | ||
89 | asset.FullID = assetID; | ||
90 | Console.WriteLine("skin asset id is " + assetID.ToStringHyphenated()); | ||
91 | asset.Type = pack.AssetBlock.Type; | ||
92 | asset.InvType = asset.Type; | ||
93 | asset.Name = "NewClothing" + Util.RandomClass.Next(1, 1000).ToString("000"); | ||
94 | asset.Data = pack.AssetBlock.AssetData; | ||
95 | |||
96 | |||
97 | }*/ | ||
98 | |||
99 | if (asset != null) | ||
100 | { | ||
101 | this.AddUpload(pack.AssetBlock.TransactionID, asset); | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | |||
106 | //currently we don't support this asset type | ||
107 | //so lets just tell the client that the upload is complete | ||
108 | AssetUploadCompletePacket response = new AssetUploadCompletePacket(); | ||
109 | response.AssetBlock.Type = pack.AssetBlock.Type; | ||
110 | response.AssetBlock.Success = true; | ||
111 | response.AssetBlock.UUID = pack.AssetBlock.TransactionID.Combine(this.ourClient.SecureSessionID); | ||
112 | this.ourClient.OutPacket(response); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | |||
117 | #region Xfer packet system for larger uploads | ||
118 | |||
119 | public void HandleXferPacket(SendXferPacketPacket xferPacket) | ||
120 | { | ||
121 | lock (this.transactions) | ||
122 | { | ||
123 | foreach (AssetTransaction trans in this.transactions.Values) | ||
124 | { | ||
125 | if (trans.XferID == xferPacket.XferID.ID) | ||
126 | { | ||
127 | if (trans.Asset.Data.Length > 1) | ||
128 | { | ||
129 | byte[] newArray = new byte[trans.Asset.Data.Length + xferPacket.DataPacket.Data.Length]; | ||
130 | Array.Copy(trans.Asset.Data, 0, newArray, 0, trans.Asset.Data.Length); | ||
131 | Array.Copy(xferPacket.DataPacket.Data, 0, newArray, trans.Asset.Data.Length, xferPacket.DataPacket.Data.Length); | ||
132 | trans.Asset.Data = newArray; | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | byte[] newArray = new byte[xferPacket.DataPacket.Data.Length-4]; | ||
137 | Array.Copy(xferPacket.DataPacket.Data, 4, newArray, 0, xferPacket.DataPacket.Data.Length-4); | ||
138 | trans.Asset.Data = newArray; | ||
139 | } | ||
140 | |||
141 | if ((xferPacket.XferID.Packet & 2147483648) != 0) | ||
142 | { | ||
143 | //end of transfer | ||
144 | trans.UploadComplete = true; | ||
145 | AssetUploadCompletePacket response = new AssetUploadCompletePacket(); | ||
146 | response.AssetBlock.Type = trans.Asset.Type; | ||
147 | response.AssetBlock.Success = true; | ||
148 | response.AssetBlock.UUID = trans.TransactionID.Combine(this.ourClient.SecureSessionID); | ||
149 | this.ourClient.OutPacket(response); | ||
150 | |||
151 | //check if we should add it to inventory | ||
152 | if (trans.AddToInventory) | ||
153 | { | ||
154 | OpenSimRoot.Instance.AssetCache.AddAsset(trans.Asset); | ||
155 | OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this.ourClient, trans.InventFolder, trans.Asset); | ||
156 | } | ||
157 | |||
158 | Console.WriteLine(Helpers.FieldToString(trans.Asset.Data)); | ||
159 | } | ||
160 | break; | ||
161 | } | ||
162 | |||
163 | } | ||
164 | } | ||
165 | |||
166 | ConfirmXferPacketPacket confirmXfer = new ConfirmXferPacketPacket(); | ||
167 | confirmXfer.XferID.ID = xferPacket.XferID.ID; | ||
168 | confirmXfer.XferID.Packet = xferPacket.XferID.Packet; | ||
169 | this.ourClient.OutPacket(confirmXfer); | ||
170 | } | ||
171 | |||
172 | #endregion | ||
173 | |||
174 | public void CreateInventoryItem(CreateInventoryItemPacket packet) | ||
175 | { | ||
176 | if(this.transactions.ContainsKey(packet.InventoryBlock.TransactionID)) | ||
177 | { | ||
178 | AssetTransaction trans = this.transactions[packet.InventoryBlock.TransactionID]; | ||
179 | trans.Asset.Description = Helpers.FieldToString(packet.InventoryBlock.Description); | ||
180 | trans.Asset.Name = Helpers.FieldToString(packet.InventoryBlock.Name); | ||
181 | trans.Asset.Type = packet.InventoryBlock.Type; | ||
182 | if (trans.UploadComplete) | ||
183 | { | ||
184 | //already complete so we can add it to the inventory | ||
185 | OpenSimRoot.Instance.AssetCache.AddAsset(trans.Asset); | ||
186 | OpenSimRoot.Instance.InventoryCache.AddNewInventoryItem(this.ourClient, packet.InventoryBlock.FolderID, trans.Asset); | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | trans.AddToInventory = true; | ||
191 | trans.InventFolder = packet.InventoryBlock.FolderID; | ||
192 | } | ||
193 | } | ||
194 | } | ||
195 | |||
196 | } | ||
197 | |||
198 | public class AssetTransaction | ||
199 | { | ||
200 | public uint XferID; | ||
201 | public AssetBase Asset; | ||
202 | public bool AddToInventory; | ||
203 | public LLUUID InventFolder = LLUUID.Zero; | ||
204 | public bool UploadComplete = false; | ||
205 | public LLUUID TransactionID = LLUUID.Zero; | ||
206 | |||
207 | public AssetTransaction() | ||
208 | { | ||
209 | |||
210 | } | ||
211 | } | ||
212 | } | ||