OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AgentAssetsTransactions.cs
Go to the documentation of this file.
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 OpenSimulator 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 
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Services.Interfaces;
36 using OpenSim.Region.Framework.Interfaces;
37 
38 namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
39 {
44  {
45  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 
47  // Fields
48  private bool m_dumpAssetsToFile;
49  private Scene m_Scene;
50  private Dictionary<UUID, AssetXferUploader> XferUploaders = new Dictionary<UUID, AssetXferUploader>();
51 
52  // Methods
53  public AgentAssetTransactions(UUID agentID, Scene scene,
54  bool dumpAssetsToFile)
55  {
56  m_Scene = scene;
57  m_dumpAssetsToFile = dumpAssetsToFile;
58  }
59 
69  public AssetXferUploader RequestXferUploader(UUID transactionID)
70  {
71  AssetXferUploader uploader;
72 
73  lock (XferUploaders)
74  {
75  if (!XferUploaders.ContainsKey(transactionID))
76  {
77  uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);
78 
79 // m_log.DebugFormat(
80 // "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);
81 
82  XferUploaders.Add(transactionID, uploader);
83  }
84  else
85  {
86  uploader = XferUploaders[transactionID];
87  }
88  }
89 
90  return uploader;
91  }
92 
93  public void HandleXfer(ulong xferID, uint packetID, byte[] data)
94  {
95  AssetXferUploader foundUploader = null;
96 
97  lock (XferUploaders)
98  {
99  foreach (AssetXferUploader uploader in XferUploaders.Values)
100  {
101 // m_log.DebugFormat(
102 // "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
103 // uploader.XferID);
104 
105  if (uploader.XferID == xferID)
106  {
107  foundUploader = uploader;
108  break;
109  }
110  }
111  }
112 
113  if (foundUploader != null)
114  {
115 // m_log.DebugFormat(
116 // "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
117 // xferID, packetID, data.Length);
118 
119  foundUploader.HandleXferPacket(xferID, packetID, data);
120  }
121  else
122  {
123  // Check if the xfer is a terrain xfer
124  IEstateModule estateModule = m_Scene.RequestModuleInterface<IEstateModule>();
125  if (estateModule != null)
126  {
127  if (estateModule.IsTerrainXfer(xferID))
128  return;
129  }
130 
131  m_log.ErrorFormat(
132  "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
133  xferID, packetID, data.Length);
134  }
135  }
136 
137  public bool RemoveXferUploader(UUID transactionID)
138  {
139  lock (XferUploaders)
140  {
141  bool removed = XferUploaders.Remove(transactionID);
142 
143  if (!removed)
144  m_log.WarnFormat(
145  "[AGENT ASSET TRANSACTIONS]: Received request to remove xfer uploader with transaction ID {0} but none found",
146  transactionID);
147 // else
148 // m_log.DebugFormat(
149 // "[AGENT ASSET TRANSACTIONS]: Removed xfer uploader with transaction ID {0}", transactionID);
150 
151  return removed;
152  }
153  }
154 
155  public bool RequestCreateInventoryItem(IClientAPI remoteClient,
156  UUID transactionID, UUID folderID, uint callbackID,
157  string description, string name, sbyte invType,
158  sbyte type, byte wearableType, uint nextOwnerMask)
159  {
160  AssetXferUploader uploader = RequestXferUploader(transactionID);
161 
162  uploader.RequestCreateInventoryItem(
163  remoteClient, folderID, callbackID,
164  description, name, invType, type, wearableType, nextOwnerMask);
165 
166  return true;
167  }
168 
169  public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
170  SceneObjectPart part, UUID transactionID,
171  TaskInventoryItem item)
172  {
173  AssetXferUploader uploader = RequestXferUploader(transactionID);
174 
175  // Here we need to get the old asset to extract the
176  // texture UUIDs if it's a wearable.
177  if (item.Type == (int)AssetType.Bodypart ||
178  item.Type == (int)AssetType.Clothing ||
179  item.Type == (int)CustomAssetType.AnimationSet)
180  {
181  AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
182  if (oldAsset != null)
183  uploader.SetOldData(oldAsset.Data);
184  }
185 
186  uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
187  }
188 
189  public void RequestUpdateInventoryItem(IClientAPI remoteClient,
190  UUID transactionID, InventoryItemBase item)
191  {
192  AssetXferUploader uploader = RequestXferUploader(transactionID);
193 
194  // Here we need to get the old asset to extract the
195  // texture UUIDs if it's a wearable.
196  if (item.AssetType == (int)AssetType.Bodypart ||
197  item.AssetType == (int)AssetType.Clothing ||
198  item.AssetType == (int)CustomAssetType.AnimationSet)
199  {
200  AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
201  if (oldAsset != null)
202  uploader.SetOldData(oldAsset.Data);
203  }
204 
205  uploader.RequestUpdateInventoryItem(remoteClient, item);
206  }
207  }
208 }
void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
AssetXferUploader RequestXferUploader(UUID transactionID)
Return the xfer uploader for the given transaction.
Represents an item in a task inventory
AgentAssetTransactions(UUID agentID, Scene scene, bool dumpAssetsToFile)
void RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item)
Asset class. All Assets are reference by this class or a class derived from this class ...
Definition: AssetBase.cs:49
Inventory Item - contains all the properties associated with an individual inventory piece...
Interactive OpenSim region server
Definition: OpenSim.cs:55
bool IsTerrainXfer(ulong xferID)
Returns whether the transfer ID is being used for a terrain transfer.
bool RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID, uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask)