diff options
author | Adam Frisby | 2008-04-30 21:16:36 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:16:36 +0000 |
commit | f5c312bc3c2567449c7268a54a08a54119f58d53 (patch) | |
tree | 424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz |
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.)
* This should be moved into a seperate project file.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs (renamed from OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs) | 815 |
1 files changed, 407 insertions, 408 deletions
diff --git a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs index 9fa173d..74bb247 100644 --- a/OpenSim/Region/Environment/Modules/AgentAssetsTransactions.cs +++ b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs | |||
@@ -1,408 +1,407 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using libsecondlife; | 31 | using libsecondlife; |
32 | using libsecondlife.Packets; | 32 | using libsecondlife.Packets; |
33 | using OpenSim.Framework; | 33 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications.Cache; | 34 | using OpenSim.Framework.Communications.Cache; |
35 | 35 | ||
36 | namespace OpenSim.Region.Environment.Modules | 36 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction |
37 | { | 37 | { |
38 | 38 | /// <summary> | |
39 | /// <summary> | 39 | /// Manage asset transactions for a single agent. |
40 | /// Manage asset transactions for a single agent. | 40 | /// </summary> |
41 | /// </summary> | 41 | public class AgentAssetTransactions |
42 | public class AgentAssetTransactions | 42 | { |
43 | { | 43 | //private static readonly log4net.ILog m_log |
44 | //private static readonly log4net.ILog m_log | 44 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
45 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | 45 | |
46 | 46 | // Fields | |
47 | // Fields | 47 | public LLUUID UserID; |
48 | public LLUUID UserID; | 48 | public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>(); |
49 | public Dictionary<LLUUID, AssetXferUploader> XferUploaders = new Dictionary<LLUUID, AssetXferUploader>(); | 49 | public AgentAssetTransactionsManager Manager; |
50 | public AgentAssetTransactionsManager Manager; | 50 | private bool m_dumpAssetsToFile; |
51 | private bool m_dumpAssetsToFile; | 51 | |
52 | 52 | // Methods | |
53 | // Methods | 53 | public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile) |
54 | public AgentAssetTransactions(LLUUID agentID, AgentAssetTransactionsManager manager, bool dumpAssetsToFile) | 54 | { |
55 | { | 55 | UserID = agentID; |
56 | UserID = agentID; | 56 | Manager = manager; |
57 | Manager = manager; | 57 | m_dumpAssetsToFile = dumpAssetsToFile; |
58 | m_dumpAssetsToFile = dumpAssetsToFile; | 58 | } |
59 | } | 59 | |
60 | 60 | public AssetXferUploader RequestXferUploader(LLUUID transactionID) | |
61 | public AssetXferUploader RequestXferUploader(LLUUID transactionID) | 61 | { |
62 | { | 62 | if (!XferUploaders.ContainsKey(transactionID)) |
63 | if (!XferUploaders.ContainsKey(transactionID)) | 63 | { |
64 | { | 64 | AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile); |
65 | AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile); | 65 | |
66 | 66 | lock (XferUploaders) | |
67 | lock (XferUploaders) | 67 | { |
68 | { | 68 | XferUploaders.Add(transactionID, uploader); |
69 | XferUploaders.Add(transactionID, uploader); | 69 | } |
70 | } | 70 | |
71 | 71 | return uploader; | |
72 | return uploader; | 72 | } |
73 | } | 73 | return null; |
74 | return null; | 74 | } |
75 | } | 75 | |
76 | 76 | public void HandleXfer(ulong xferID, uint packetID, byte[] data) | |
77 | public void HandleXfer(ulong xferID, uint packetID, byte[] data) | 77 | { |
78 | { | 78 | // AssetXferUploader uploaderFound = null; |
79 | // AssetXferUploader uploaderFound = null; | 79 | |
80 | 80 | lock (XferUploaders) | |
81 | lock (XferUploaders) | 81 | { |
82 | { | 82 | foreach (AssetXferUploader uploader in XferUploaders.Values) |
83 | foreach (AssetXferUploader uploader in XferUploaders.Values) | 83 | { |
84 | { | 84 | if (uploader.XferID == xferID) |
85 | if (uploader.XferID == xferID) | 85 | { |
86 | { | 86 | uploader.HandleXferPacket(xferID, packetID, data); |
87 | uploader.HandleXferPacket(xferID, packetID, data); | 87 | break; |
88 | break; | 88 | } |
89 | } | 89 | } |
90 | } | 90 | } |
91 | } | 91 | } |
92 | } | 92 | |
93 | 93 | public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | |
94 | public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | 94 | uint callbackID, string description, string name, sbyte invType, |
95 | uint callbackID, string description, string name, sbyte invType, | 95 | sbyte type, byte wearableType, uint nextOwnerMask) |
96 | sbyte type, byte wearableType, uint nextOwnerMask) | 96 | { |
97 | { | 97 | if (XferUploaders.ContainsKey(transactionID)) |
98 | if (XferUploaders.ContainsKey(transactionID)) | 98 | { |
99 | { | 99 | XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID, |
100 | XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID, | 100 | callbackID, description, name, invType, type, |
101 | callbackID, description, name, invType, type, | 101 | wearableType, nextOwnerMask); |
102 | wearableType, nextOwnerMask); | 102 | } |
103 | } | 103 | } |
104 | } | 104 | |
105 | 105 | public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, | |
106 | public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, | 106 | InventoryItemBase item) |
107 | InventoryItemBase item) | 107 | { |
108 | { | 108 | if (XferUploaders.ContainsKey(transactionID)) |
109 | if (XferUploaders.ContainsKey(transactionID)) | 109 | { |
110 | { | 110 | XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item); |
111 | XferUploaders[transactionID].RequestUpdateInventoryItem(remoteClient, transactionID, item); | 111 | } |
112 | } | 112 | } |
113 | } | 113 | |
114 | 114 | /// <summary> | |
115 | /// <summary> | 115 | /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed. |
116 | /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed. | 116 | /// </summary> |
117 | /// </summary> | 117 | /// <param name="transactionID"></param> |
118 | /// <param name="transactionID"></param> | 118 | /// <returns>The asset if the upload has completed, null if it has not.</returns> |
119 | /// <returns>The asset if the upload has completed, null if it has not.</returns> | 119 | public AssetBase GetTransactionAsset(LLUUID transactionID) |
120 | public AssetBase GetTransactionAsset(LLUUID transactionID) | 120 | { |
121 | { | 121 | if (XferUploaders.ContainsKey(transactionID)) |
122 | if (XferUploaders.ContainsKey(transactionID)) | 122 | { |
123 | { | 123 | AssetXferUploader uploader = XferUploaders[transactionID]; |
124 | AssetXferUploader uploader = XferUploaders[transactionID]; | 124 | AssetBase asset = uploader.GetAssetData(); |
125 | AssetBase asset = uploader.GetAssetData(); | 125 | |
126 | 126 | lock (XferUploaders) | |
127 | lock (XferUploaders) | 127 | { |
128 | { | 128 | XferUploaders.Remove(transactionID); |
129 | XferUploaders.Remove(transactionID); | 129 | } |
130 | } | 130 | |
131 | 131 | return asset; | |
132 | return asset; | 132 | } |
133 | } | 133 | |
134 | 134 | return null; | |
135 | return null; | 135 | } |
136 | } | 136 | |
137 | 137 | // Nested Types | |
138 | // Nested Types | 138 | public class AssetXferUploader |
139 | public class AssetXferUploader | 139 | { |
140 | { | 140 | // Fields |
141 | // Fields | 141 | public bool AddToInventory; |
142 | public bool AddToInventory; | 142 | public AssetBase Asset; |
143 | public AssetBase Asset; | 143 | public LLUUID InventFolder = LLUUID.Zero; |
144 | public LLUUID InventFolder = LLUUID.Zero; | 144 | private IClientAPI ourClient; |
145 | private IClientAPI ourClient; | 145 | public LLUUID TransactionID = LLUUID.Zero; |
146 | public LLUUID TransactionID = LLUUID.Zero; | 146 | public bool UploadComplete; |
147 | public bool UploadComplete; | 147 | public ulong XferID; |
148 | public ulong XferID; | 148 | private string m_name = String.Empty; |
149 | private string m_name = String.Empty; | 149 | private string m_description = String.Empty; |
150 | private string m_description = String.Empty; | 150 | private sbyte type = 0; |
151 | private sbyte type = 0; | 151 | private sbyte invType = 0; |
152 | private sbyte invType = 0; | 152 | private byte wearableType = 0; |
153 | private byte wearableType = 0; | 153 | private uint nextPerm = 0; |
154 | private uint nextPerm = 0; | 154 | private bool m_finished = false; |
155 | private bool m_finished = false; | 155 | private bool m_createItem = false; |
156 | private bool m_createItem = false; | 156 | private AgentAssetTransactions m_userTransactions; |
157 | private AgentAssetTransactions m_userTransactions; | 157 | private bool m_storeLocal; |
158 | private bool m_storeLocal; | 158 | private bool m_dumpAssetToFile; |
159 | private bool m_dumpAssetToFile; | 159 | |
160 | 160 | public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile) | |
161 | public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile) | 161 | { |
162 | { | 162 | m_userTransactions = transactions; |
163 | m_userTransactions = transactions; | 163 | m_dumpAssetToFile = dumpAssetToFile; |
164 | m_dumpAssetToFile = dumpAssetToFile; | 164 | } |
165 | } | 165 | |
166 | 166 | /// <summary> | |
167 | /// <summary> | 167 | /// Process transfer data received from the client. |
168 | /// Process transfer data received from the client. | 168 | /// </summary> |
169 | /// </summary> | 169 | /// <param name="xferID"></param> |
170 | /// <param name="xferID"></param> | 170 | /// <param name="packetID"></param> |
171 | /// <param name="packetID"></param> | 171 | /// <param name="data"></param> |
172 | /// <param name="data"></param> | 172 | /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> |
173 | /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> | 173 | public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) |
174 | public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) | 174 | { |
175 | { | 175 | if (XferID == xferID) |
176 | if (XferID == xferID) | 176 | { |
177 | { | 177 | if (Asset.Data.Length > 1) |
178 | if (Asset.Data.Length > 1) | 178 | { |
179 | { | 179 | byte[] destinationArray = new byte[Asset.Data.Length + data.Length]; |
180 | byte[] destinationArray = new byte[Asset.Data.Length + data.Length]; | 180 | Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length); |
181 | Array.Copy(Asset.Data, 0, destinationArray, 0, Asset.Data.Length); | 181 | Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length); |
182 | Array.Copy(data, 0, destinationArray, Asset.Data.Length, data.Length); | 182 | Asset.Data = destinationArray; |
183 | Asset.Data = destinationArray; | 183 | } |
184 | } | 184 | else |
185 | else | 185 | { |
186 | { | 186 | byte[] buffer2 = new byte[data.Length - 4]; |
187 | byte[] buffer2 = new byte[data.Length - 4]; | 187 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); |
188 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); | 188 | Asset.Data = buffer2; |
189 | Asset.Data = buffer2; | 189 | } |
190 | } | 190 | ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket(); |
191 | ConfirmXferPacketPacket newPack = new ConfirmXferPacketPacket(); | 191 | newPack.XferID.ID = xferID; |
192 | newPack.XferID.ID = xferID; | 192 | newPack.XferID.Packet = packetID; |
193 | newPack.XferID.Packet = packetID; | 193 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); |
194 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | 194 | if ((packetID & 0x80000000) != 0) |
195 | if ((packetID & 0x80000000) != 0) | 195 | { |
196 | { | 196 | SendCompleteMessage(); |
197 | SendCompleteMessage(); | 197 | return true; |
198 | return true; | 198 | } |
199 | } | 199 | } |
200 | } | 200 | |
201 | 201 | return false; | |
202 | return false; | 202 | } |
203 | } | 203 | |
204 | 204 | /// <summary> | |
205 | /// <summary> | 205 | /// Initialise asset transfer from the client |
206 | /// Initialise asset transfer from the client | 206 | /// </summary> |
207 | /// </summary> | 207 | /// <param name="xferID"></param> |
208 | /// <param name="xferID"></param> | 208 | /// <param name="packetID"></param> |
209 | /// <param name="packetID"></param> | 209 | /// <param name="data"></param> |
210 | /// <param name="data"></param> | 210 | /// <returns>True if the transfer is complete, false otherwise</returns> |
211 | /// <returns>True if the transfer is complete, false otherwise</returns> | 211 | public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, |
212 | public bool Initialise(IClientAPI remoteClient, LLUUID assetID, LLUUID transaction, sbyte type, byte[] data, | 212 | bool storeLocal, bool tempFile) |
213 | bool storeLocal, bool tempFile) | 213 | { |
214 | { | 214 | ourClient = remoteClient; |
215 | ourClient = remoteClient; | 215 | Asset = new AssetBase(); |
216 | Asset = new AssetBase(); | 216 | Asset.FullID = assetID; |
217 | Asset.FullID = assetID; | 217 | Asset.InvType = type; |
218 | Asset.InvType = type; | 218 | Asset.Type = type; |
219 | Asset.Type = type; | 219 | Asset.Data = data; |
220 | Asset.Data = data; | 220 | Asset.Name = "blank"; |
221 | Asset.Name = "blank"; | 221 | Asset.Description = "empty"; |
222 | Asset.Description = "empty"; | 222 | Asset.Local = storeLocal; |
223 | Asset.Local = storeLocal; | 223 | Asset.Temporary = tempFile; |
224 | Asset.Temporary = tempFile; | 224 | |
225 | 225 | TransactionID = transaction; | |
226 | TransactionID = transaction; | 226 | m_storeLocal = storeLocal; |
227 | m_storeLocal = storeLocal; | 227 | if (Asset.Data.Length > 2) |
228 | if (Asset.Data.Length > 2) | 228 | { |
229 | { | 229 | SendCompleteMessage(); |
230 | SendCompleteMessage(); | 230 | return true; |
231 | return true; | 231 | } |
232 | } | 232 | else |
233 | else | 233 | { |
234 | { | 234 | RequestStartXfer(); |
235 | RequestStartXfer(); | 235 | } |
236 | } | 236 | |
237 | 237 | return false; | |
238 | return false; | 238 | } |
239 | } | 239 | |
240 | 240 | protected void RequestStartXfer() | |
241 | protected void RequestStartXfer() | 241 | { |
242 | { | 242 | UploadComplete = false; |
243 | UploadComplete = false; | 243 | XferID = Util.GetNextXferID(); |
244 | XferID = Util.GetNextXferID(); | 244 | RequestXferPacket newPack = new RequestXferPacket(); |
245 | RequestXferPacket newPack = new RequestXferPacket(); | 245 | newPack.XferID.ID = XferID; |
246 | newPack.XferID.ID = XferID; | 246 | newPack.XferID.VFileType = Asset.Type; |
247 | newPack.XferID.VFileType = Asset.Type; | 247 | newPack.XferID.VFileID = Asset.FullID; |
248 | newPack.XferID.VFileID = Asset.FullID; | 248 | newPack.XferID.FilePath = 0; |
249 | newPack.XferID.FilePath = 0; | 249 | newPack.XferID.Filename = new byte[0]; |
250 | newPack.XferID.Filename = new byte[0]; | 250 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); |
251 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | 251 | } |
252 | } | 252 | |
253 | 253 | protected void SendCompleteMessage() | |
254 | protected void SendCompleteMessage() | 254 | { |
255 | { | 255 | UploadComplete = true; |
256 | UploadComplete = true; | 256 | AssetUploadCompletePacket newPack = new AssetUploadCompletePacket(); |
257 | AssetUploadCompletePacket newPack = new AssetUploadCompletePacket(); | 257 | newPack.AssetBlock.Type = Asset.Type; |
258 | newPack.AssetBlock.Type = Asset.Type; | 258 | newPack.AssetBlock.Success = true; |
259 | newPack.AssetBlock.Success = true; | 259 | newPack.AssetBlock.UUID = Asset.FullID; |
260 | newPack.AssetBlock.UUID = Asset.FullID; | 260 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); |
261 | ourClient.OutPacket(newPack, ThrottleOutPacketType.Asset); | 261 | m_finished = true; |
262 | m_finished = true; | 262 | if (m_createItem) |
263 | if (m_createItem) | 263 | { |
264 | { | 264 | DoCreateItem(); |
265 | DoCreateItem(); | 265 | } |
266 | } | 266 | else if (m_storeLocal) |
267 | else if (m_storeLocal) | 267 | { |
268 | { | 268 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); |
269 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); | 269 | } |
270 | } | 270 | |
271 | 271 | // Console.WriteLine("upload complete "+ this.TransactionID); | |
272 | // Console.WriteLine("upload complete "+ this.TransactionID); | 272 | |
273 | 273 | if (m_dumpAssetToFile) | |
274 | if (m_dumpAssetToFile) | 274 | { |
275 | { | 275 | DateTime now = DateTime.Now; |
276 | DateTime now = DateTime.Now; | 276 | string filename = |
277 | string filename = | 277 | String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, |
278 | String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, | 278 | now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type); |
279 | now.Hour, now.Minute, now.Second, Asset.Name, Asset.Type); | 279 | SaveAssetToFile(filename, Asset.Data); |
280 | SaveAssetToFile(filename, Asset.Data); | 280 | } |
281 | } | 281 | } |
282 | } | 282 | |
283 | 283 | ///Left this in and commented in case there are unforseen issues | |
284 | ///Left this in and commented in case there are unforseen issues | 284 | //private void SaveAssetToFile(string filename, byte[] data) |
285 | //private void SaveAssetToFile(string filename, byte[] data) | 285 | //{ |
286 | //{ | 286 | // FileStream fs = File.Create(filename); |
287 | // FileStream fs = File.Create(filename); | 287 | // BinaryWriter bw = new BinaryWriter(fs); |
288 | // BinaryWriter bw = new BinaryWriter(fs); | 288 | // bw.Write(data); |
289 | // bw.Write(data); | 289 | // bw.Close(); |
290 | // bw.Close(); | 290 | // fs.Close(); |
291 | // fs.Close(); | 291 | //} |
292 | //} | 292 | private void SaveAssetToFile(string filename, byte[] data) |
293 | private void SaveAssetToFile(string filename, byte[] data) | 293 | { |
294 | { | 294 | string assetPath = "UserAssets"; |
295 | string assetPath = "UserAssets"; | 295 | if (!Directory.Exists(assetPath)) |
296 | if (!Directory.Exists(assetPath)) | 296 | { |
297 | { | 297 | Directory.CreateDirectory(assetPath); |
298 | Directory.CreateDirectory(assetPath); | 298 | } |
299 | } | 299 | FileStream fs = File.Create(Path.Combine(assetPath, filename)); |
300 | FileStream fs = File.Create(Path.Combine(assetPath, filename)); | 300 | BinaryWriter bw = new BinaryWriter(fs); |
301 | BinaryWriter bw = new BinaryWriter(fs); | 301 | bw.Write(data); |
302 | bw.Write(data); | 302 | bw.Close(); |
303 | bw.Close(); | 303 | fs.Close(); |
304 | fs.Close(); | 304 | } |
305 | } | 305 | |
306 | 306 | public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | |
307 | public void RequestCreateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, LLUUID folderID, | 307 | uint callbackID, string description, string name, sbyte invType, |
308 | uint callbackID, string description, string name, sbyte invType, | 308 | sbyte type, byte wearableType, uint nextOwnerMask) |
309 | sbyte type, byte wearableType, uint nextOwnerMask) | 309 | { |
310 | { | 310 | if (TransactionID == transactionID) |
311 | if (TransactionID == transactionID) | 311 | { |
312 | { | 312 | InventFolder = folderID; |
313 | InventFolder = folderID; | 313 | m_name = name; |
314 | m_name = name; | 314 | m_description = description; |
315 | m_description = description; | 315 | this.type = type; |
316 | this.type = type; | 316 | this.invType = invType; |
317 | this.invType = invType; | 317 | this.wearableType = wearableType; |
318 | this.wearableType = wearableType; | 318 | nextPerm = nextOwnerMask; |
319 | nextPerm = nextOwnerMask; | 319 | Asset.Name = name; |
320 | Asset.Name = name; | 320 | Asset.Description = description; |
321 | Asset.Description = description; | 321 | Asset.Type = type; |
322 | Asset.Type = type; | 322 | Asset.InvType = invType; |
323 | Asset.InvType = invType; | 323 | m_createItem = true; |
324 | m_createItem = true; | 324 | if (m_finished) |
325 | if (m_finished) | 325 | { |
326 | { | 326 | DoCreateItem(); |
327 | DoCreateItem(); | 327 | } |
328 | } | 328 | } |
329 | } | 329 | } |
330 | } | 330 | |
331 | 331 | public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, | |
332 | public void RequestUpdateInventoryItem(IClientAPI remoteClient, LLUUID transactionID, | 332 | InventoryItemBase item) |
333 | InventoryItemBase item) | 333 | { |
334 | { | 334 | if (TransactionID == transactionID) |
335 | if (TransactionID == transactionID) | 335 | { |
336 | { | 336 | CachedUserInfo userInfo = |
337 | CachedUserInfo userInfo = | 337 | m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( |
338 | m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( | 338 | remoteClient.AgentId); |
339 | remoteClient.AgentId); | 339 | |
340 | 340 | if (userInfo != null) | |
341 | if (userInfo != null) | 341 | { |
342 | { | 342 | LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId); |
343 | LLUUID assetID = LLUUID.Combine(transactionID, remoteClient.SecureSessionId); | 343 | |
344 | 344 | AssetBase asset | |
345 | AssetBase asset | 345 | = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset( |
346 | = m_userTransactions.Manager.MyScene.CommsManager.AssetCache.GetAsset( | 346 | assetID, (item.AssetType == (int) AssetType.Texture ? true : false)); |
347 | assetID, (item.AssetType == (int) AssetType.Texture ? true : false)); | 347 | |
348 | 348 | if (asset == null) | |
349 | if (asset == null) | 349 | { |
350 | { | 350 | asset = m_userTransactions.GetTransactionAsset(transactionID); |
351 | asset = m_userTransactions.GetTransactionAsset(transactionID); | 351 | } |
352 | } | 352 | |
353 | 353 | if (asset != null && asset.FullID == assetID) | |
354 | if (asset != null && asset.FullID == assetID) | 354 | { |
355 | { | 355 | asset.Name = item.Name; |
356 | asset.Name = item.Name; | 356 | asset.Description = item.Description; |
357 | asset.Description = item.Description; | 357 | asset.InvType = (sbyte) item.InvType; |
358 | asset.InvType = (sbyte) item.InvType; | 358 | asset.Type = (sbyte) item.AssetType; |
359 | asset.Type = (sbyte) item.AssetType; | 359 | item.AssetID = asset.FullID; |
360 | item.AssetID = asset.FullID; | 360 | |
361 | 361 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); | |
362 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); | 362 | } |
363 | } | 363 | |
364 | 364 | userInfo.UpdateItem(remoteClient.AgentId, item); | |
365 | userInfo.UpdateItem(remoteClient.AgentId, item); | 365 | } |
366 | } | 366 | } |
367 | } | 367 | } |
368 | } | 368 | |
369 | 369 | private void DoCreateItem() | |
370 | private void DoCreateItem() | 370 | { |
371 | { | 371 | //really need to fix this call, if lbsa71 saw this he would die. |
372 | //really need to fix this call, if lbsa71 saw this he would die. | 372 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); |
373 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(Asset); | 373 | CachedUserInfo userInfo = |
374 | CachedUserInfo userInfo = | 374 | m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId); |
375 | m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails(ourClient.AgentId); | 375 | if (userInfo != null) |
376 | if (userInfo != null) | 376 | { |
377 | { | 377 | InventoryItemBase item = new InventoryItemBase(); |
378 | InventoryItemBase item = new InventoryItemBase(); | 378 | item.Owner = ourClient.AgentId; |
379 | item.Owner = ourClient.AgentId; | 379 | item.Creator = ourClient.AgentId; |
380 | item.Creator = ourClient.AgentId; | 380 | item.ID = LLUUID.Random(); |
381 | item.ID = LLUUID.Random(); | 381 | item.AssetID = Asset.FullID; |
382 | item.AssetID = Asset.FullID; | 382 | item.Description = m_description; |
383 | item.Description = m_description; | 383 | item.Name = m_name; |
384 | item.Name = m_name; | 384 | item.AssetType = type; |
385 | item.AssetType = type; | 385 | item.InvType = invType; |
386 | item.InvType = invType; | 386 | item.Folder = InventFolder; |
387 | item.Folder = InventFolder; | 387 | item.BasePermissions = 2147483647; |
388 | item.BasePermissions = 2147483647; | 388 | item.CurrentPermissions = 2147483647; |
389 | item.CurrentPermissions = 2147483647; | 389 | item.NextPermissions = nextPerm; |
390 | item.NextPermissions = nextPerm; | 390 | item.Flags = (uint)wearableType; |
391 | item.Flags = (uint)wearableType; | 391 | |
392 | 392 | userInfo.AddItem(ourClient.AgentId, item); | |
393 | userInfo.AddItem(ourClient.AgentId, item); | 393 | ourClient.SendInventoryItemCreateUpdate(item); |
394 | ourClient.SendInventoryItemCreateUpdate(item); | 394 | } |
395 | } | 395 | } |
396 | } | 396 | |
397 | 397 | public AssetBase GetAssetData() | |
398 | public AssetBase GetAssetData() | 398 | { |
399 | { | 399 | if (m_finished) |
400 | if (m_finished) | 400 | { |
401 | { | 401 | return Asset; |
402 | return Asset; | 402 | } |
403 | } | 403 | return null; |
404 | return null; | 404 | } |
405 | } | 405 | } |
406 | } | 406 | } |
407 | } | 407 | } \ No newline at end of file |
408 | } | ||