OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
AssetTransactionModule.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;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Nini.Config;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
37 using Mono.Addins;
38 
39 namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
40 {
41  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AssetTransactionModule")]
44  {
45 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 
47  protected Scene m_Scene;
48  private bool m_dumpAssetsToFile = false;
49  private int m_levelUpload = 0;
50 
54  private Dictionary<UUID, AgentAssetTransactions> AgentTransactions =
55  new Dictionary<UUID, AgentAssetTransactions>();
56 
57  #region Region Module interface
58 
59  public void Initialise(IConfigSource source)
60  {
61  IConfig sconfig = source.Configs["Startup"];
62  if (sconfig != null)
63  {
64  m_levelUpload = sconfig.GetInt("LevelUpload", 0);
65  }
66  }
67 
68  public void AddRegion(Scene scene)
69  {
70  m_Scene = scene;
71  scene.RegisterModuleInterface<IAgentAssetTransactions>(this);
72  scene.EventManager.OnNewClient += NewClient;
73  }
74 
75  public void RegionLoaded(Scene scene)
76  {
77  }
78 
79  public void RemoveRegion(Scene scene)
80  {
81  }
82 
83  public void Close()
84  {
85  }
86 
87  public string Name
88  {
89  get { return "AgentTransactionModule"; }
90  }
91 
92  public Type ReplaceableInterface
93  {
94  get { return typeof(IAgentAssetTransactions); }
95  }
96 
97  #endregion
98 
99  public void NewClient(IClientAPI client)
100  {
101  client.OnAssetUploadRequest += HandleUDPUploadRequest;
102  client.OnXferReceive += HandleXfer;
103  }
104 
105  #region AgentAssetTransactions
106  private AgentAssetTransactions GetUserTransactions(UUID userID)
113  {
114  lock (AgentTransactions)
115  {
116  if (!AgentTransactions.ContainsKey(userID))
117  {
118  AgentAssetTransactions transactions =
119  new AgentAssetTransactions(userID, m_Scene,
120  m_dumpAssetsToFile);
121 
122  AgentTransactions.Add(userID, transactions);
123  }
124 
125  return AgentTransactions[userID];
126  }
127  }
128 
135  public void RemoveAgentAssetTransactions(UUID userID)
136  {
137  // m_log.DebugFormat("Removing agent asset transactions structure for agent {0}", userID);
138 
139  lock (AgentTransactions)
140  {
141  AgentTransactions.Remove(userID);
142  }
143  }
144 
162  UUID transactionID, UUID folderID, uint callbackID,
163  string description, string name, sbyte invType,
164  sbyte type, byte wearableType, uint nextOwnerMask)
165  {
166 // m_log.DebugFormat(
167 // "[TRANSACTIONS MANAGER] Called HandleItemCreationFromTransaction with item {0}", name);
168 
169  AgentAssetTransactions transactions =
170  GetUserTransactions(remoteClient.AgentId);
171 
172  return transactions.RequestCreateInventoryItem(remoteClient, transactionID,
173  folderID, callbackID, description, name, invType, type,
174  wearableType, nextOwnerMask);
175  }
176 
189  public void HandleItemUpdateFromTransaction(IClientAPI remoteClient,
190  UUID transactionID, InventoryItemBase item)
191  {
192 // m_log.DebugFormat(
193 // "[ASSET TRANSACTION MODULE]: Called HandleItemUpdateFromTransaction with item {0}",
194 // item.Name);
195 
196  AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
197 
198  transactions.RequestUpdateInventoryItem(remoteClient, transactionID, item);
199  }
200 
215  IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
216  {
217 // m_log.DebugFormat(
218 // "[ASSET TRANSACTION MODULE]: Called HandleTaskItemUpdateFromTransaction with item {0} in {1} for {2} in {3}",
219 // item.Name, part.Name, remoteClient.Name, m_Scene.RegionInfo.RegionName);
220 
221  AgentAssetTransactions transactions =
222  GetUserTransactions(remoteClient.AgentId);
223 
224  transactions.RequestUpdateTaskInventoryItem(remoteClient, part,
225  transactionID, item);
226  }
227 
237  public void HandleUDPUploadRequest(IClientAPI remoteClient,
238  UUID assetID, UUID transactionID, sbyte type, byte[] data,
239  bool storeLocal, bool tempFile)
240  {
241 // m_log.DebugFormat(
242 // "[ASSET TRANSACTION MODULE]: HandleUDPUploadRequest - assetID: {0}, transaction {1}, type {2}, storeLocal {3}, tempFile {4}, data.Length {5}",
243 // assetID, transactionID, type, storeLocal, tempFile, data.Length);
244 
245  if (((AssetType)type == AssetType.Texture ||
246  (AssetType)type == AssetType.Sound ||
247  (AssetType)type == AssetType.TextureTGA ||
248  (AssetType)type == AssetType.Animation) &&
249  tempFile == false)
250  {
251  ScenePresence avatar = null;
252  Scene scene = (Scene)remoteClient.Scene;
253  scene.TryGetScenePresence(remoteClient.AgentId, out avatar);
254 
255  // check user level
256  if (avatar != null)
257  {
258  if (avatar.UserLevel < m_levelUpload)
259  {
260  remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
261  return;
262  }
263  }
264 
265  // check funds
266  IMoneyModule mm = scene.RequestModuleInterface<IMoneyModule>();
267 
268  if (mm != null)
269  {
270  if (!mm.UploadCovered(remoteClient.AgentId, mm.UploadCharge))
271  {
272  remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
273  return;
274  }
275  }
276  }
277 
278  AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
279  AssetXferUploader uploader = transactions.RequestXferUploader(transactionID);
280  uploader.StartUpload(remoteClient, assetID, transactionID, type, data, storeLocal, tempFile);
281  }
282 
291  public void HandleXfer(IClientAPI remoteClient, ulong xferID,
292  uint packetID, byte[] data)
293  {
294 // m_log.Debug("xferID: " + xferID + " packetID: " + packetID + " data length " + data.Length);
295  AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
296 
297  transactions.HandleXfer(xferID, packetID, data);
298  }
299 
300  #endregion
301  }
302 }
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
bool HandleItemCreationFromTransaction(IClientAPI remoteClient, UUID transactionID, UUID folderID, uint callbackID, string description, string name, sbyte invType, sbyte type, byte wearableType, uint nextOwnerMask)
Create an inventory item from data that has been received through a transaction. This is called when ...
void HandleItemUpdateFromTransaction(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item)
Update an inventory item with data that has been received through a transaction.
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
bool UploadCovered(UUID agentID, int amount)
Represents an item in a task inventory
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void HandleTaskItemUpdateFromTransaction(IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
Update a task inventory item with data that has been received through a transaction.
void HandleXfer(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data)
Handle asset transfer data packets received in response to the asset upload request in HandleUDPUploa...
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Inventory Item - contains all the properties associated with an individual inventory piece...
override bool TryGetScenePresence(UUID agentID, out ScenePresence sp)
Try to get a scene presence from the scene
Definition: Scene.cs:5401
void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transactionID, sbyte type, byte[] data, bool storeLocal, bool tempFile)
Request that a client (agent) begin an asset transfer.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void RemoveAgentAssetTransactions(UUID userID)
Remove the given agent asset transactions. This should be called when a client is departing from a sc...