diff options
author | Dr Scofield | 2009-02-09 09:16:15 +0000 |
---|---|---|
committer | Dr Scofield | 2009-02-09 09:16:15 +0000 |
commit | a89d097355526d4dc52a75a9734c6a02c3008ef4 (patch) | |
tree | f12e2cf5807762e0fbaf2f304e75b618f62b4cf6 /OpenSim/Region/Environment/Modules/Agent/AssetTransaction | |
parent | adding bin/ScriptEngines/*/*.{dll,state}, bin/j2kDecodeCache, (diff) | |
download | opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.zip opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.gz opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.bz2 opensim-SC_OLD-a89d097355526d4dc52a75a9734c6a02c3008ef4.tar.xz |
starting phase 2 of the OpenSim.Region.Environment commit: relocating
OpenSim.Region.Environment.Modules.Agent en bloc to OpenSim.Region.CoreModules
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Agent/AssetTransaction')
4 files changed, 0 insertions, 1018 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs deleted file mode 100644 index 82325b7..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetTransactionsManager.cs +++ /dev/null | |||
@@ -1,231 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections.Generic; | ||
29 | //using System.Reflection; | ||
30 | //using log4net; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction | ||
37 | { | ||
38 | /* | ||
39 | public class AgentAssetTransactionsManager | ||
40 | { | ||
41 | //private static readonly ILog m_log | ||
42 | // = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | /// <summary> | ||
45 | /// Each agent has its own singleton collection of transactions | ||
46 | /// </summary> | ||
47 | private Dictionary<UUID, AgentAssetTransactions> AgentTransactions = | ||
48 | new Dictionary<UUID, AgentAssetTransactions>(); | ||
49 | |||
50 | /// <summary> | ||
51 | /// Should we dump uploaded assets to the filesystem? | ||
52 | /// </summary> | ||
53 | private bool m_dumpAssetsToFile; | ||
54 | |||
55 | public Scene MyScene; | ||
56 | |||
57 | public AgentAssetTransactionsManager(Scene scene, bool dumpAssetsToFile) | ||
58 | { | ||
59 | MyScene = scene; | ||
60 | m_dumpAssetsToFile = dumpAssetsToFile; | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Get the collection of asset transactions for the given user. If one does not already exist, it | ||
65 | /// is created. | ||
66 | /// </summary> | ||
67 | /// <param name="userID"></param> | ||
68 | /// <returns></returns> | ||
69 | private AgentAssetTransactions GetUserTransactions(UUID userID) | ||
70 | { | ||
71 | lock (AgentTransactions) | ||
72 | { | ||
73 | if (!AgentTransactions.ContainsKey(userID)) | ||
74 | { | ||
75 | AgentAssetTransactions transactions = null; | ||
76 | //= new AgentAssetTransactions(userID, this, m_dumpAssetsToFile); | ||
77 | AgentTransactions.Add(userID, transactions); | ||
78 | } | ||
79 | |||
80 | return AgentTransactions[userID]; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | /// <summary> | ||
85 | /// Remove the given agent asset transactions. This should be called when a client is departing | ||
86 | /// from a scene (and hence won't be making any more transactions here). | ||
87 | /// </summary> | ||
88 | /// <param name="userID"></param> | ||
89 | public void RemoveAgentAssetTransactions(UUID userID) | ||
90 | { | ||
91 | // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID); | ||
92 | |||
93 | lock (AgentTransactions) | ||
94 | { | ||
95 | AgentTransactions.Remove(userID); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | /// <summary> | ||
100 | /// Create an inventory item from data that has been received through a transaction. | ||
101 | /// | ||
102 | /// This is called when new clothing or body parts are created. It may also be called in other | ||
103 | /// situations. | ||
104 | /// </summary> | ||
105 | /// <param name="remoteClient"></param> | ||
106 | /// <param name="transactionID"></param> | ||
107 | /// <param name="folderID"></param> | ||
108 | /// <param name="callbackID"></param> | ||
109 | /// <param name="description"></param> | ||
110 | /// <param name="name"></param> | ||
111 | /// <param name="invType"></param> | ||
112 | /// <param name="type"></param> | ||
113 | /// <param name="wearableType"></param> | ||
114 | /// <param name="nextOwnerMask"></param> | ||
115 | public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, | ||
116 | uint callbackID, string description, string name, sbyte invType, | ||
117 | sbyte type, byte wearableType, uint nextOwnerMask) | ||
118 | { | ||
119 | // m_log.DebugFormat( | ||
120 | // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); | ||
121 | |||
122 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
123 | |||
124 | transactions.RequestCreateInventoryItem( | ||
125 | remoteClient, transactionID, folderID, callbackID, description, | ||
126 | name, invType, type, wearableType, nextOwnerMask); | ||
127 | } | ||
128 | |||
129 | /// <summary> | ||
130 | /// Update an inventory item with data that has been received through a transaction. | ||
131 | /// | ||
132 | /// This is called when clothing or body parts are updated (for instance, with new textures or | ||
133 | /// colours). It may also be called in other situations. | ||
134 | /// </summary> | ||
135 | /// <param name="remoteClient"></param> | ||
136 | /// <param name="transactionID"></param> | ||
137 | /// <param name="item"></param> | ||
138 | public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, | ||
139 | InventoryItemBase item) | ||
140 | { | ||
141 | // m_log.DebugFormat( | ||
142 | // "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", | ||
143 | // item.Name); | ||
144 | |||
145 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
146 | |||
147 | transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); | ||
148 | } | ||
149 | |||
150 | /// <summary> | ||
151 | /// Update a task inventory item with data that has been received through a transaction. | ||
152 | /// | ||
153 | /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent | ||
154 | /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction | ||
155 | /// and comes through this method. | ||
156 | /// </summary> | ||
157 | /// <param name="remoteClient"></param> | ||
158 | /// <param name="transactionID"></param> | ||
159 | /// <param name="item"></param> | ||
160 | public void HandleTaskItemUpdateFromTransaction( | ||
161 | IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) | ||
162 | { | ||
163 | // m_log.DebugFormat( | ||
164 | // "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", | ||
165 | // item.Name); | ||
166 | |||
167 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
168 | |||
169 | transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item); | ||
170 | } | ||
171 | |||
172 | /// <summary> | ||
173 | /// Request that a client (agent) begin an asset transfer. | ||
174 | /// </summary> | ||
175 | /// <param name="remoteClient"></param> | ||
176 | /// <param name="assetID"></param> | ||
177 | /// <param name="transaction"></param> | ||
178 | /// <param name="type"></param> | ||
179 | /// <param name="data"></param></param> | ||
180 | /// <param name="tempFile"></param> | ||
181 | public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, | ||
182 | byte[] data, bool storeLocal, bool tempFile) | ||
183 | { | ||
184 | //System.Console.WriteLine("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile); | ||
185 | if (((AssetType)type == AssetType.Texture || | ||
186 | (AssetType)type == AssetType.Sound || | ||
187 | (AssetType)type == AssetType.TextureTGA || | ||
188 | (AssetType)type == AssetType.Animation) && | ||
189 | tempFile == false) | ||
190 | { | ||
191 | Scene scene = (Scene)remoteClient.Scene; | ||
192 | IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>(); | ||
193 | |||
194 | if (mm != null) | ||
195 | { | ||
196 | if (!mm.UploadCovered(remoteClient)) | ||
197 | { | ||
198 | remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
199 | return; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | //Console.WriteLine("asset upload of " + assetID); | ||
205 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
206 | |||
207 | AssetXferUploader uploader = transactions.RequestXferUploader(transaction); | ||
208 | if (uploader != null) | ||
209 | { | ||
210 | uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | /// <summary> | ||
215 | /// Handle asset transfer data packets received in response to the asset upload request in | ||
216 | /// HandleUDPUploadRequest() | ||
217 | /// </summary> | ||
218 | /// <param name="remoteClient"></param> | ||
219 | /// <param name="xferID"></param> | ||
220 | /// <param name="packetID"></param> | ||
221 | /// <param name="data"></param> | ||
222 | public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | ||
223 | { | ||
224 | //System.Console.WriteLine("xferID: " + xferID + " packetID: " + packetID + " data!"); | ||
225 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
226 | |||
227 | transactions.HandleXfer(xferID, packetID, data); | ||
228 | } | ||
229 | } | ||
230 | */ | ||
231 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs deleted file mode 100644 index adfbbad..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AgentAssetsTransactions.cs +++ /dev/null | |||
@@ -1,232 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Framework.Communications.Cache; | ||
34 | |||
35 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// Manage asset transactions for a single agent. | ||
39 | /// </summary> | ||
40 | public class AgentAssetTransactions | ||
41 | { | ||
42 | private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | // Fields | ||
45 | private bool m_dumpAssetsToFile; | ||
46 | public AssetTransactionModule Manager; | ||
47 | public UUID UserID; | ||
48 | public Dictionary<UUID, AssetXferUploader> XferUploaders = new Dictionary<UUID, AssetXferUploader>(); | ||
49 | |||
50 | // Methods | ||
51 | public AgentAssetTransactions(UUID agentID, AssetTransactionModule manager, bool dumpAssetsToFile) | ||
52 | { | ||
53 | UserID = agentID; | ||
54 | Manager = manager; | ||
55 | m_dumpAssetsToFile = dumpAssetsToFile; | ||
56 | } | ||
57 | |||
58 | public AssetXferUploader RequestXferUploader(UUID transactionID) | ||
59 | { | ||
60 | if (!XferUploaders.ContainsKey(transactionID)) | ||
61 | { | ||
62 | AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile); | ||
63 | |||
64 | lock (XferUploaders) | ||
65 | { | ||
66 | XferUploaders.Add(transactionID, uploader); | ||
67 | } | ||
68 | |||
69 | return uploader; | ||
70 | } | ||
71 | return null; | ||
72 | } | ||
73 | |||
74 | public void HandleXfer(ulong xferID, uint packetID, byte[] data) | ||
75 | { | ||
76 | lock (XferUploaders) | ||
77 | { | ||
78 | foreach (AssetXferUploader uploader in XferUploaders.Values) | ||
79 | { | ||
80 | if (uploader.XferID == xferID) | ||
81 | { | ||
82 | uploader.HandleXferPacket(xferID, packetID, data); | ||
83 | break; | ||
84 | } | ||
85 | } | ||
86 | } | ||
87 | } | ||
88 | |||
89 | public void RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID, | ||
90 | uint callbackID, string description, string name, sbyte invType, | ||
91 | sbyte type, byte wearableType, uint nextOwnerMask) | ||
92 | { | ||
93 | if (XferUploaders.ContainsKey(transactionID)) | ||
94 | { | ||
95 | XferUploaders[transactionID].RequestCreateInventoryItem(remoteClient, transactionID, folderID, | ||
96 | callbackID, description, name, invType, type, | ||
97 | wearableType, nextOwnerMask); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | |||
102 | |||
103 | /// <summary> | ||
104 | /// Get an uploaded asset. If the data is successfully retrieved, the transaction will be removed. | ||
105 | /// </summary> | ||
106 | /// <param name="transactionID"></param> | ||
107 | /// <returns>The asset if the upload has completed, null if it has not.</returns> | ||
108 | public AssetBase GetTransactionAsset(UUID transactionID) | ||
109 | { | ||
110 | if (XferUploaders.ContainsKey(transactionID)) | ||
111 | { | ||
112 | AssetXferUploader uploader = XferUploaders[transactionID]; | ||
113 | AssetBase asset = uploader.GetAssetData(); | ||
114 | |||
115 | lock (XferUploaders) | ||
116 | { | ||
117 | XferUploaders.Remove(transactionID); | ||
118 | } | ||
119 | |||
120 | return asset; | ||
121 | } | ||
122 | |||
123 | return null; | ||
124 | } | ||
125 | |||
126 | //private void CreateItemFromUpload(AssetBase asset, IClientAPI ourClient, UUID inventoryFolderID, uint nextPerms, uint wearableType) | ||
127 | //{ | ||
128 | // Manager.MyScene.CommsManager.AssetCache.AddAsset(asset); | ||
129 | // CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( | ||
130 | // ourClient.AgentId); | ||
131 | |||
132 | // if (userInfo != null) | ||
133 | // { | ||
134 | // InventoryItemBase item = new InventoryItemBase(); | ||
135 | // item.Owner = ourClient.AgentId; | ||
136 | // item.Creator = ourClient.AgentId; | ||
137 | // item.ID = UUID.Random(); | ||
138 | // item.AssetID = asset.FullID; | ||
139 | // item.Description = asset.Description; | ||
140 | // item.Name = asset.Name; | ||
141 | // item.AssetType = asset.Type; | ||
142 | // item.InvType = asset.Type; | ||
143 | // item.Folder = inventoryFolderID; | ||
144 | // item.BasePermissions = 0x7fffffff; | ||
145 | // item.CurrentPermissions = 0x7fffffff; | ||
146 | // item.EveryOnePermissions = 0; | ||
147 | // item.NextPermissions = nextPerms; | ||
148 | // item.Flags = wearableType; | ||
149 | // item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
150 | |||
151 | // userInfo.AddItem(item); | ||
152 | // ourClient.SendInventoryItemCreateUpdate(item); | ||
153 | // } | ||
154 | // else | ||
155 | // { | ||
156 | // m_log.ErrorFormat( | ||
157 | // "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation", | ||
158 | // ourClient.AgentId); | ||
159 | // } | ||
160 | //} | ||
161 | |||
162 | public void RequestUpdateTaskInventoryItem( | ||
163 | IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) | ||
164 | { | ||
165 | if (XferUploaders.ContainsKey(transactionID)) | ||
166 | { | ||
167 | AssetBase asset = XferUploaders[transactionID].GetAssetData(); | ||
168 | if (asset != null) | ||
169 | { | ||
170 | m_log.DebugFormat( | ||
171 | "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}", | ||
172 | item.Name, part.Name, transactionID); | ||
173 | |||
174 | asset.Metadata.Name = item.Name; | ||
175 | asset.Metadata.Description = item.Description; | ||
176 | asset.Metadata.Type = (sbyte)item.Type; | ||
177 | item.AssetID = asset.Metadata.FullID; | ||
178 | |||
179 | Manager.MyScene.CommsManager.AssetCache.AddAsset(asset); | ||
180 | |||
181 | if (part.Inventory.UpdateInventoryItem(item)) | ||
182 | part.GetProperties(remoteClient); | ||
183 | } | ||
184 | } | ||
185 | } | ||
186 | |||
187 | |||
188 | public void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, | ||
189 | InventoryItemBase item) | ||
190 | { | ||
191 | if (XferUploaders.ContainsKey(transactionID)) | ||
192 | { | ||
193 | CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( | ||
194 | remoteClient.AgentId); | ||
195 | |||
196 | if (userInfo != null) | ||
197 | { | ||
198 | UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId); | ||
199 | |||
200 | AssetBase asset | ||
201 | = Manager.MyScene.CommsManager.AssetCache.GetAsset( | ||
202 | assetID, (item.AssetType == (int)AssetType.Texture ? true : false)); | ||
203 | |||
204 | if (asset == null) | ||
205 | { | ||
206 | asset = GetTransactionAsset(transactionID); | ||
207 | } | ||
208 | |||
209 | if (asset != null && asset.Metadata.FullID == assetID) | ||
210 | { | ||
211 | // Assets never get updated, new ones get created | ||
212 | asset.Metadata.FullID = UUID.Random(); | ||
213 | asset.Metadata.Name = item.Name; | ||
214 | asset.Metadata.Description = item.Description; | ||
215 | asset.Metadata.Type = (sbyte)item.AssetType; | ||
216 | item.AssetID = asset.Metadata.FullID; | ||
217 | |||
218 | Manager.MyScene.CommsManager.AssetCache.AddAsset(asset); | ||
219 | } | ||
220 | |||
221 | userInfo.UpdateItem(item); | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | m_log.ErrorFormat( | ||
226 | "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item update", | ||
227 | remoteClient.AgentId); | ||
228 | } | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs deleted file mode 100644 index 1eb6795..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetTransactionModule.cs +++ /dev/null | |||
@@ -1,288 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Interfaces; | ||
34 | using OpenSim.Region.Framework.Scenes; | ||
35 | |||
36 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction | ||
37 | { | ||
38 | public class AssetTransactionModule : IRegionModule, IAgentAssetTransactions | ||
39 | { | ||
40 | private readonly Dictionary<UUID, Scene> RegisteredScenes = new Dictionary<UUID, Scene>(); | ||
41 | private bool m_dumpAssetsToFile = false; | ||
42 | private Scene m_scene = null; | ||
43 | |||
44 | public Scene MyScene | ||
45 | { | ||
46 | get{ return m_scene;} | ||
47 | } | ||
48 | |||
49 | /// <summary> | ||
50 | /// Each agent has its own singleton collection of transactions | ||
51 | /// </summary> | ||
52 | private Dictionary<UUID, AgentAssetTransactions> AgentTransactions = | ||
53 | new Dictionary<UUID, AgentAssetTransactions>(); | ||
54 | |||
55 | |||
56 | public AssetTransactionModule() | ||
57 | { | ||
58 | // System.Console.WriteLine("creating AgentAssetTransactionModule"); | ||
59 | } | ||
60 | |||
61 | #region IRegionModule Members | ||
62 | |||
63 | public void Initialise(Scene scene, IConfigSource config) | ||
64 | { | ||
65 | if (!RegisteredScenes.ContainsKey(scene.RegionInfo.RegionID)) | ||
66 | { | ||
67 | // System.Console.WriteLine("initialising AgentAssetTransactionModule"); | ||
68 | RegisteredScenes.Add(scene.RegionInfo.RegionID, scene); | ||
69 | scene.RegisterModuleInterface<IAgentAssetTransactions>(this); | ||
70 | |||
71 | scene.EventManager.OnNewClient += NewClient; | ||
72 | } | ||
73 | |||
74 | if (m_scene == null) | ||
75 | { | ||
76 | m_scene = scene; | ||
77 | if (config.Configs["StandAlone"] != null) | ||
78 | { | ||
79 | try | ||
80 | { | ||
81 | m_dumpAssetsToFile = config.Configs["StandAlone"].GetBoolean("dump_assets_to_file", false); | ||
82 | } | ||
83 | catch (Exception) | ||
84 | { | ||
85 | } | ||
86 | } | ||
87 | else | ||
88 | { | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | public void PostInitialise() | ||
94 | { | ||
95 | } | ||
96 | |||
97 | public void Close() | ||
98 | { | ||
99 | } | ||
100 | |||
101 | public string Name | ||
102 | { | ||
103 | get { return "AgentTransactionModule"; } | ||
104 | } | ||
105 | |||
106 | public bool IsSharedModule | ||
107 | { | ||
108 | get { return true; } | ||
109 | } | ||
110 | |||
111 | #endregion | ||
112 | |||
113 | public void NewClient(IClientAPI client) | ||
114 | { | ||
115 | client.OnAssetUploadRequest += HandleUDPUploadRequest; | ||
116 | client.OnXferReceive += HandleXfer; | ||
117 | } | ||
118 | |||
119 | #region AgentAssetTransactions | ||
120 | /// <summary> | ||
121 | /// Get the collection of asset transactions for the given user. If one does not already exist, it | ||
122 | /// is created. | ||
123 | /// </summary> | ||
124 | /// <param name="userID"></param> | ||
125 | /// <returns></returns> | ||
126 | private AgentAssetTransactions GetUserTransactions(UUID userID) | ||
127 | { | ||
128 | lock (AgentTransactions) | ||
129 | { | ||
130 | if (!AgentTransactions.ContainsKey(userID)) | ||
131 | { | ||
132 | AgentAssetTransactions transactions = new AgentAssetTransactions(userID, this, m_dumpAssetsToFile); | ||
133 | AgentTransactions.Add(userID, transactions); | ||
134 | } | ||
135 | |||
136 | return AgentTransactions[userID]; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | /// <summary> | ||
141 | /// Remove the given agent asset transactions. This should be called when a client is departing | ||
142 | /// from a scene (and hence won't be making any more transactions here). | ||
143 | /// </summary> | ||
144 | /// <param name="userID"></param> | ||
145 | public void RemoveAgentAssetTransactions(UUID userID) | ||
146 | { | ||
147 | // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID); | ||
148 | |||
149 | lock (AgentTransactions) | ||
150 | { | ||
151 | AgentTransactions.Remove(userID); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | /// <summary> | ||
156 | /// Create an inventory item from data that has been received through a transaction. | ||
157 | /// | ||
158 | /// This is called when new clothing or body parts are created. It may also be called in other | ||
159 | /// situations. | ||
160 | /// </summary> | ||
161 | /// <param name="remoteClient"></param> | ||
162 | /// <param name="transactionID"></param> | ||
163 | /// <param name="folderID"></param> | ||
164 | /// <param name="callbackID"></param> | ||
165 | /// <param name="description"></param> | ||
166 | /// <param name="name"></param> | ||
167 | /// <param name="invType"></param> | ||
168 | /// <param name="type"></param> | ||
169 | /// <param name="wearableType"></param> | ||
170 | /// <param name="nextOwnerMask"></param> | ||
171 | public void HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, | ||
172 | uint callbackID, string description, string name, sbyte invType, | ||
173 | sbyte type, byte wearableType, uint nextOwnerMask) | ||
174 | { | ||
175 | // m_log.DebugFormat( | ||
176 | // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name); | ||
177 | |||
178 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
179 | |||
180 | transactions.RequestCreateInventoryItem( | ||
181 | remoteClient, transactionID, folderID, callbackID, description, | ||
182 | name, invType, type, wearableType, nextOwnerMask); | ||
183 | } | ||
184 | |||
185 | /// <summary> | ||
186 | /// Update an inventory item with data that has been received through a transaction. | ||
187 | /// | ||
188 | /// This is called when clothing or body parts are updated (for instance, with new textures or | ||
189 | /// colours). It may also be called in other situations. | ||
190 | /// </summary> | ||
191 | /// <param name="remoteClient"></param> | ||
192 | /// <param name="transactionID"></param> | ||
193 | /// <param name="item"></param> | ||
194 | public void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, | ||
195 | InventoryItemBase item) | ||
196 | { | ||
197 | // m_log.DebugFormat( | ||
198 | // "[TRANSACTIONS MANAGER] Called HandleItemUpdateFromTransaction with item {0}", | ||
199 | // item.Name); | ||
200 | |||
201 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
202 | |||
203 | transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item); | ||
204 | } | ||
205 | |||
206 | /// <summary> | ||
207 | /// Update a task inventory item with data that has been received through a transaction. | ||
208 | /// | ||
209 | /// This is currently called when, for instance, a notecard in a prim is saved. The data is sent | ||
210 | /// up through a single AssetUploadRequest. A subsequent UpdateTaskInventory then references the transaction | ||
211 | /// and comes through this method. | ||
212 | /// </summary> | ||
213 | /// <param name="remoteClient"></param> | ||
214 | /// <param name="transactionID"></param> | ||
215 | /// <param name="item"></param> | ||
216 | public void HandleTaskItemUpdateFromTransaction( | ||
217 | IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item) | ||
218 | { | ||
219 | // m_log.DebugFormat( | ||
220 | // "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}", | ||
221 | // item.Name); | ||
222 | |||
223 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
224 | |||
225 | transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item); | ||
226 | } | ||
227 | |||
228 | /// <summary> | ||
229 | /// Request that a client (agent) begin an asset transfer. | ||
230 | /// </summary> | ||
231 | /// <param name="remoteClient"></param> | ||
232 | /// <param name="assetID"></param> | ||
233 | /// <param name="transaction"></param> | ||
234 | /// <param name="type"></param> | ||
235 | /// <param name="data"></param></param> | ||
236 | /// <param name="tempFile"></param> | ||
237 | public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, | ||
238 | byte[] data, bool storeLocal, bool tempFile) | ||
239 | { | ||
240 | //System.Console.WriteLine("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile); | ||
241 | if (((AssetType)type == AssetType.Texture || | ||
242 | (AssetType)type == AssetType.Sound || | ||
243 | (AssetType)type == AssetType.TextureTGA || | ||
244 | (AssetType)type == AssetType.Animation) && | ||
245 | tempFile == false) | ||
246 | { | ||
247 | Scene scene = (Scene)remoteClient.Scene; | ||
248 | IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>(); | ||
249 | |||
250 | if (mm != null) | ||
251 | { | ||
252 | if (!mm.UploadCovered(remoteClient)) | ||
253 | { | ||
254 | remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false); | ||
255 | return; | ||
256 | } | ||
257 | } | ||
258 | } | ||
259 | |||
260 | //Console.WriteLine("asset upload of " + assetID); | ||
261 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
262 | |||
263 | AssetXferUploader uploader = transactions.RequestXferUploader(transaction); | ||
264 | if (uploader != null) | ||
265 | { | ||
266 | uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile); | ||
267 | } | ||
268 | } | ||
269 | |||
270 | /// <summary> | ||
271 | /// Handle asset transfer data packets received in response to the asset upload request in | ||
272 | /// HandleUDPUploadRequest() | ||
273 | /// </summary> | ||
274 | /// <param name="remoteClient"></param> | ||
275 | /// <param name="xferID"></param> | ||
276 | /// <param name="packetID"></param> | ||
277 | /// <param name="data"></param> | ||
278 | public void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | ||
279 | { | ||
280 | //System.Console.WriteLine("xferID: " + xferID + " packetID: " + packetID + " data!"); | ||
281 | AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId); | ||
282 | |||
283 | transactions.HandleXfer(xferID, packetID, data); | ||
284 | } | ||
285 | |||
286 | #endregion | ||
287 | } | ||
288 | } | ||
diff --git a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs b/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs deleted file mode 100644 index e1e1065..0000000 --- a/OpenSim/Region/Environment/Modules/Agent/AssetTransaction/AssetXferUploader.cs +++ /dev/null | |||
@@ -1,267 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.IO; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenMetaverse.Packets; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Communications.Cache; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | |||
38 | namespace OpenSim.Region.Environment.Modules.Agent.AssetTransaction | ||
39 | { | ||
40 | public class AssetXferUploader | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | private AssetBase m_asset; | ||
45 | private UUID InventFolder = UUID.Zero; | ||
46 | private sbyte invType = 0; | ||
47 | private bool m_createItem = false; | ||
48 | private string m_description = String.Empty; | ||
49 | private bool m_dumpAssetToFile; | ||
50 | private bool m_finished = false; | ||
51 | private string m_name = String.Empty; | ||
52 | private bool m_storeLocal; | ||
53 | private AgentAssetTransactions m_userTransactions; | ||
54 | private uint nextPerm = 0; | ||
55 | private IClientAPI ourClient; | ||
56 | private UUID TransactionID = UUID.Zero; | ||
57 | private sbyte type = 0; | ||
58 | private byte wearableType = 0; | ||
59 | public ulong XferID; | ||
60 | |||
61 | public AssetXferUploader(AgentAssetTransactions transactions, bool dumpAssetToFile) | ||
62 | { | ||
63 | m_userTransactions = transactions; | ||
64 | m_dumpAssetToFile = dumpAssetToFile; | ||
65 | } | ||
66 | |||
67 | /// <summary> | ||
68 | /// Process transfer data received from the client. | ||
69 | /// </summary> | ||
70 | /// <param name="xferID"></param> | ||
71 | /// <param name="packetID"></param> | ||
72 | /// <param name="data"></param> | ||
73 | /// <returns>True if the transfer is complete, false otherwise or if the xferID was not valid</returns> | ||
74 | public bool HandleXferPacket(ulong xferID, uint packetID, byte[] data) | ||
75 | { | ||
76 | if (XferID == xferID) | ||
77 | { | ||
78 | if (m_asset.Data.Length > 1) | ||
79 | { | ||
80 | byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; | ||
81 | Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); | ||
82 | Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); | ||
83 | m_asset.Data = destinationArray; | ||
84 | } | ||
85 | else | ||
86 | { | ||
87 | byte[] buffer2 = new byte[data.Length - 4]; | ||
88 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); | ||
89 | m_asset.Data = buffer2; | ||
90 | } | ||
91 | |||
92 | ourClient.SendConfirmXfer(xferID, packetID); | ||
93 | |||
94 | if ((packetID & 0x80000000) != 0) | ||
95 | { | ||
96 | SendCompleteMessage(); | ||
97 | return true; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | return false; | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// Initialise asset transfer from the client | ||
106 | /// </summary> | ||
107 | /// <param name="xferID"></param> | ||
108 | /// <param name="packetID"></param> | ||
109 | /// <param name="data"></param> | ||
110 | /// <returns>True if the transfer is complete, false otherwise</returns> | ||
111 | public bool Initialise(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type, byte[] data, | ||
112 | bool storeLocal, bool tempFile) | ||
113 | { | ||
114 | ourClient = remoteClient; | ||
115 | m_asset = new AssetBase(); | ||
116 | m_asset.Metadata.FullID = assetID; | ||
117 | m_asset.Metadata.Type = type; | ||
118 | m_asset.Data = data; | ||
119 | m_asset.Metadata.Name = "blank"; | ||
120 | m_asset.Metadata.Description = "empty"; | ||
121 | m_asset.Metadata.Local = storeLocal; | ||
122 | m_asset.Metadata.Temporary = tempFile; | ||
123 | |||
124 | TransactionID = transaction; | ||
125 | m_storeLocal = storeLocal; | ||
126 | |||
127 | if (m_asset.Data.Length > 2) | ||
128 | { | ||
129 | SendCompleteMessage(); | ||
130 | return true; | ||
131 | } | ||
132 | else | ||
133 | { | ||
134 | RequestStartXfer(); | ||
135 | } | ||
136 | |||
137 | return false; | ||
138 | } | ||
139 | |||
140 | protected void RequestStartXfer() | ||
141 | { | ||
142 | XferID = Util.GetNextXferID(); | ||
143 | ourClient.SendXferRequest(XferID, m_asset.Metadata.Type, m_asset.Metadata.FullID, 0, new byte[0]); | ||
144 | } | ||
145 | |||
146 | protected void SendCompleteMessage() | ||
147 | { | ||
148 | ourClient.SendAssetUploadCompleteMessage(m_asset.Metadata.Type, true, m_asset.Metadata.FullID); | ||
149 | |||
150 | m_finished = true; | ||
151 | if (m_createItem) | ||
152 | { | ||
153 | DoCreateItem(); | ||
154 | } | ||
155 | else if (m_storeLocal) | ||
156 | { | ||
157 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset); | ||
158 | } | ||
159 | |||
160 | m_log.DebugFormat("[ASSET TRANSACTIONS]: Uploaded asset data for transaction {0}", TransactionID); | ||
161 | |||
162 | if (m_dumpAssetToFile) | ||
163 | { | ||
164 | DateTime now = DateTime.Now; | ||
165 | string filename = | ||
166 | String.Format("{6}_{7}_{0:d2}{1:d2}{2:d2}_{3:d2}{4:d2}{5:d2}.dat", now.Year, now.Month, now.Day, | ||
167 | now.Hour, now.Minute, now.Second, m_asset.Metadata.Name, m_asset.Metadata.Type); | ||
168 | SaveAssetToFile(filename, m_asset.Data); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | private void SaveAssetToFile(string filename, byte[] data) | ||
173 | { | ||
174 | string assetPath = "UserAssets"; | ||
175 | if (!Directory.Exists(assetPath)) | ||
176 | { | ||
177 | Directory.CreateDirectory(assetPath); | ||
178 | } | ||
179 | FileStream fs = File.Create(Path.Combine(assetPath, filename)); | ||
180 | BinaryWriter bw = new BinaryWriter(fs); | ||
181 | bw.Write(data); | ||
182 | bw.Close(); | ||
183 | fs.Close(); | ||
184 | } | ||
185 | |||
186 | public void RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID, | ||
187 | uint callbackID, string description, string name, sbyte invType, | ||
188 | sbyte type, byte wearableType, uint nextOwnerMask) | ||
189 | { | ||
190 | if (TransactionID == transactionID) | ||
191 | { | ||
192 | InventFolder = folderID; | ||
193 | m_name = name; | ||
194 | m_description = description; | ||
195 | this.type = type; | ||
196 | this.invType = invType; | ||
197 | this.wearableType = wearableType; | ||
198 | nextPerm = nextOwnerMask; | ||
199 | m_asset.Metadata.Name = name; | ||
200 | m_asset.Metadata.Description = description; | ||
201 | m_asset.Metadata.Type = type; | ||
202 | |||
203 | if (m_finished) | ||
204 | { | ||
205 | DoCreateItem(); | ||
206 | } | ||
207 | else | ||
208 | { | ||
209 | m_createItem = true; //set flag so the inventory item is created when upload is complete | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | |||
215 | private void DoCreateItem() | ||
216 | { | ||
217 | m_userTransactions.Manager.MyScene.CommsManager.AssetCache.AddAsset(m_asset); | ||
218 | CachedUserInfo userInfo = | ||
219 | m_userTransactions.Manager.MyScene.CommsManager.UserProfileCacheService.GetUserDetails( | ||
220 | ourClient.AgentId); | ||
221 | |||
222 | if (userInfo != null) | ||
223 | { | ||
224 | InventoryItemBase item = new InventoryItemBase(); | ||
225 | item.Owner = ourClient.AgentId; | ||
226 | item.Creator = ourClient.AgentId; | ||
227 | item.ID = UUID.Random(); | ||
228 | item.AssetID = m_asset.Metadata.FullID; | ||
229 | item.Description = m_description; | ||
230 | item.Name = m_name; | ||
231 | item.AssetType = type; | ||
232 | item.InvType = invType; | ||
233 | item.Folder = InventFolder; | ||
234 | item.BasePermissions = 0x7fffffff; | ||
235 | item.CurrentPermissions = 0x7fffffff; | ||
236 | item.GroupPermissions=0; | ||
237 | item.EveryOnePermissions=0; | ||
238 | item.NextPermissions = nextPerm; | ||
239 | item.Flags = (uint) wearableType; | ||
240 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
241 | |||
242 | userInfo.AddItem(item); | ||
243 | ourClient.SendInventoryItemCreateUpdate(item); | ||
244 | } | ||
245 | else | ||
246 | { | ||
247 | m_log.ErrorFormat( | ||
248 | "[ASSET TRANSACTIONS]: Could not find user {0} for inventory item creation", | ||
249 | ourClient.AgentId); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /// <summary> | ||
254 | /// Get the asset data uploaded in this transfer. | ||
255 | /// </summary> | ||
256 | /// <returns>null if the asset has not finished uploading</returns> | ||
257 | public AssetBase GetAssetData() | ||
258 | { | ||
259 | if (m_finished) | ||
260 | { | ||
261 | return m_asset; | ||
262 | } | ||
263 | |||
264 | return null; | ||
265 | } | ||
266 | } | ||
267 | } | ||