aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/Modules/InstantMessageModule.cs8
-rw-r--r--OpenSim/Region/Environment/Modules/InventoryModule.cs158
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.Inventory.cs87
3 files changed, 246 insertions, 7 deletions
diff --git a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
index 53d9fd9..6f7235e 100644
--- a/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
+++ b/OpenSim/Region/Environment/Modules/InstantMessageModule.cs
@@ -70,13 +70,17 @@ namespace OpenSim.Region.Environment.Modules
70 uint ParentEstateID, LLVector3 Position, LLUUID RegionID, 70 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
71 byte[] binaryBucket) 71 byte[] binaryBucket)
72 { 72 {
73 bool FriendDialog = ((dialog == (byte)38) || (dialog == (byte)39) || (dialog == (byte)40)); 73 bool dialogHandledElsewhere
74 = ((dialog == (byte)38) || (dialog == (byte)39) || (dialog == (byte)40)
75 || dialog == (byte)InstantMessageDialog.InventoryOffered
76 || dialog == (byte)InstantMessageDialog.InventoryAccepted
77 || dialog == (byte)InstantMessageDialog.InventoryDeclined);
74 78
75 // IM dialogs need to be pre-processed and have their sessionID filled by the server 79 // IM dialogs need to be pre-processed and have their sessionID filled by the server
76 // so the sim can match the transaction on the return packet. 80 // so the sim can match the transaction on the return packet.
77 81
78 // Don't send a Friend Dialog IM with a LLUUID.Zero session. 82 // Don't send a Friend Dialog IM with a LLUUID.Zero session.
79 if (!(FriendDialog && imSessionID == LLUUID.Zero)) 83 if (!(dialogHandledElsewhere && imSessionID == LLUUID.Zero))
80 { 84 {
81 foreach (Scene scene in m_scenes) 85 foreach (Scene scene in m_scenes)
82 { 86 {
diff --git a/OpenSim/Region/Environment/Modules/InventoryModule.cs b/OpenSim/Region/Environment/Modules/InventoryModule.cs
index a0f3832..eadbb4f 100644
--- a/OpenSim/Region/Environment/Modules/InventoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/InventoryModule.cs
@@ -25,7 +25,13 @@
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
28using System;
29using System.Collections.Generic;
30
31using libsecondlife;
28using Nini.Config; 32using Nini.Config;
33
34using OpenSim.Framework;
29using OpenSim.Region.Environment.Interfaces; 35using OpenSim.Region.Environment.Interfaces;
30using OpenSim.Region.Environment.Scenes; 36using OpenSim.Region.Environment.Scenes;
31 37
@@ -33,11 +39,22 @@ namespace OpenSim.Region.Environment.Modules
33{ 39{
34 public class InventoryModule : IRegionModule 40 public class InventoryModule : IRegionModule
35 { 41 {
42 private static readonly log4net.ILog m_log
43 = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
44
36 private Scene m_scene; 45 private Scene m_scene;
46
47 /// <summary>
48 /// We need to keep track of the pending item offers between clients since the itemId offered only
49 /// occurs in the initial offer message, not the accept message. So this dictionary links
50 /// IM Session Ids to ItemIds
51 /// </summary>
52 private IDictionary<LLUUID, LLUUID> m_pendingOffers = new Dictionary<LLUUID, LLUUID>();
37 53
38 public void Initialise(Scene scene, IConfigSource config) 54 public void Initialise(Scene scene, IConfigSource config)
39 { 55 {
40 m_scene = scene; 56 m_scene = scene;
57 scene.EventManager.OnNewClient += OnNewClient;
41 } 58 }
42 59
43 public void PostInitialise() 60 public void PostInitialise()
@@ -57,5 +74,144 @@ namespace OpenSim.Region.Environment.Modules
57 { 74 {
58 get { return false; } 75 get { return false; }
59 } 76 }
77
78 private void OnNewClient(IClientAPI client)
79 {
80 // Inventory giving is conducted via instant message
81 client.OnInstantMessage += OnInstantMessage;
82 }
83
84 private void OnInstantMessage(IClientAPI client, LLUUID fromAgentID,
85 LLUUID fromAgentSession, LLUUID toAgentID,
86 LLUUID imSessionID, uint timestamp, string fromAgentName,
87 string message, byte dialog, bool fromGroup, byte offline,
88 uint ParentEstateID, LLVector3 Position, LLUUID RegionID,
89 byte[] binaryBucket)
90 {
91 if (dialog == (byte)InstantMessageDialog.InventoryOffered)
92 {
93 m_log.DebugFormat(
94 "[AGENT INVENTORY]: Routing inventory offering message from {0}, {1} to {2}",
95 client.AgentId, client.Name, toAgentID);
96
97 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
98 {
99 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID];
100
101 if (!user.IsChildAgent)
102 {
103 //byte[] rawId = new byte[16];
104
105 // First byte of the array is probably the item type
106 // Next 16 bytes are the UUID
107 //Array.Copy(binaryBucket, 1, rawId, 0, 16);
108
109 //LLUUID itemId = new LLUUID(new Guid(rawId));
110 LLUUID itemId = new LLUUID(binaryBucket, 1);
111
112 m_log.DebugFormat(
113 "[AGENT INVENTORY]: ItemId for giving is {0}", itemId);
114
115 m_pendingOffers[imSessionID] = itemId;
116
117 user.ControllingClient.SendInstantMessage(
118 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
119 dialog, timestamp, binaryBucket);
120
121 return;
122 }
123 else
124 {
125 m_log.WarnFormat(
126 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!",
127 toAgentID, client.AgentId, client.Name, message);
128 }
129 }
130 else
131 {
132 m_log.WarnFormat(
133 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}",
134 toAgentID, client.AgentId, client.Name, message);
135 }
136 }
137 else if (dialog == (byte)InstantMessageDialog.InventoryAccepted)
138 {
139 m_log.DebugFormat(
140 "[AGENT INVENTORY]: Routing inventory accepted message from {0}, {1} to {2}",
141 client.AgentId, client.Name, toAgentID);
142
143 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
144 {
145 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID];
146
147 if (!user.IsChildAgent)
148 {
149 user.ControllingClient.SendInstantMessage(
150 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
151 dialog, timestamp, binaryBucket);
152
153 if (m_pendingOffers.ContainsKey(imSessionID))
154 {
155 m_log.DebugFormat(
156 "[AGENT INVENTORY]: Accepted item id {0}", m_pendingOffers[imSessionID]);
157
158 // Since the message originates from the accepting client, the toAgentID is
159 // the agent giving the item.
160 m_scene.GiveInventoryItem(client, toAgentID, m_pendingOffers[imSessionID]);
161
162 m_pendingOffers.Remove(imSessionID);
163 }
164 else
165 {
166 m_log.ErrorFormat(
167 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to accept",
168 imSessionID);
169 }
170
171 return;
172 }
173 else
174 {
175 m_log.WarnFormat(
176 "[AGENT INVENTORY]: Agent {0} targeted for inventory give by {1}, {2} of {3} was a child agent!",
177 toAgentID, client.AgentId, client.Name, message);
178 }
179 }
180 else
181 {
182 m_log.WarnFormat(
183 "[AGENT INVENTORY]: Could not find agent {0} for user {1}, {2} to give {3}",
184 toAgentID, client.AgentId, client.Name, message);
185 }
186 }
187 else if (dialog == (byte)InstantMessageDialog.InventoryDeclined)
188 {
189 if (m_scene.Entities.ContainsKey(toAgentID) && m_scene.Entities[toAgentID] is ScenePresence)
190 {
191 ScenePresence user = (ScenePresence)m_scene.Entities[toAgentID];
192
193 if (!user.IsChildAgent)
194 {
195 user.ControllingClient.SendInstantMessage(
196 fromAgentID, fromAgentSession, message, toAgentID, imSessionID, fromAgentName,
197 dialog, timestamp, binaryBucket);
198
199 if (m_pendingOffers.ContainsKey(imSessionID))
200 {
201 m_log.DebugFormat(
202 "[AGENT INVENTORY]: Declined item id {0}", m_pendingOffers[imSessionID]);
203
204 m_pendingOffers.Remove(imSessionID);
205 }
206 else
207 {
208 m_log.ErrorFormat(
209 "[AGENT INVENTORY]: Could not find an item associated with session id {0} to decline",
210 imSessionID);
211 }
212 }
213 }
214 }
215 }
60 } 216 }
61} 217}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
index 2b8f344..f6f1367 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
@@ -286,10 +286,89 @@ namespace OpenSim.Region.Environment.Scenes
286 "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update."); 286 "[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " not found for an inventory item update.");
287 } 287 }
288 } 288 }
289
290 /// <summary>
291 /// Give an inventory item from one avatar to another
292 /// </summary>
293 /// <param name="recipientClient"></param>
294 /// <param name="sender"></param>
295 /// <param name="itemId"></param>
296 public void GiveInventoryItem(IClientAPI recipientClient, LLUUID senderId, LLUUID itemId)
297 {
298 // Retrieve the item from the sender
299 CachedUserInfo senderUserInfo = CommsManager.UserProfileCacheService.GetUserDetails(senderId);
300
301 if (senderUserInfo == null)
302 {
303 m_log.ErrorFormat(
304 "[AGENT INVENTORY]: Failed to find sending user {0} for item {1}", senderId, itemId);
305
306 return;
307 }
308
309 if (senderUserInfo.RootFolder != null)
310 {
311 InventoryItemBase item = senderUserInfo.RootFolder.HasItem(itemId);
312 if (item != null)
313 {
314 // TODO get recipient's root folder
315 CachedUserInfo recipientUserInfo
316 = CommsManager.UserProfileCacheService.GetUserDetails(recipientClient.AgentId);
317
318 if (recipientUserInfo != null)
319 {
320 // Insert a copy of the item into the recipient
321 InventoryItemBase itemCopy = new InventoryItemBase();
322 itemCopy.avatarID = recipientClient.AgentId;
323 itemCopy.creatorsID = recipientClient.AgentId;
324 itemCopy.inventoryID = LLUUID.Random();
325 itemCopy.assetID = item.assetID;
326 itemCopy.inventoryDescription = item.inventoryDescription;
327 itemCopy.inventoryName = item.inventoryName;
328 itemCopy.assetType = item.assetType;
329 itemCopy.invType = item.invType;
330 itemCopy.parentFolderID = recipientUserInfo.RootFolder.folderID;
331 itemCopy.inventoryCurrentPermissions = 2147483647;
332 itemCopy.inventoryNextPermissions = 2147483647;
333 itemCopy.inventoryEveryOnePermissions = item.inventoryEveryOnePermissions;
334 itemCopy.inventoryBasePermissions = item.inventoryBasePermissions;
335 itemCopy.inventoryCurrentPermissions = item.inventoryCurrentPermissions;
336
337 recipientUserInfo.AddItem(recipientClient.AgentId, itemCopy);
338
339 // Let the recipient client know about this new item
340 recipientClient.SendBulkUpdateInventory(itemCopy);
341 }
342 else
343 {
344 m_log.ErrorFormat(
345 "[AGENT INVENTORY]: Could not find userinfo for recipient user {0}, {1} of item {2}, {3} from {4}",
346 recipientClient.Name, recipientClient.AgentId, item.inventoryName,
347 item.inventoryID, senderId);
348 }
349 }
350 else
351 {
352 m_log.ErrorFormat(
353 "[AGENT INVENTORY]: Failed to find item {0} to give to {1}", itemId, senderId);
354
355 return;
356 }
357 }
358 else
359 {
360 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder");
361 return;
362 }
363 }
289 364
290 public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID, 365 public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, LLUUID oldAgentID, LLUUID oldItemID,
291 LLUUID newFolderID, string newName) 366 LLUUID newFolderID, string newName)
292 { 367 {
368 m_log.DebugFormat(
369 "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
370 remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
371
293 InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(oldItemID); 372 InventoryItemBase item = CommsManager.UserProfileCacheService.libraryRoot.HasItem(oldItemID);
294 if (item == null) 373 if (item == null)
295 { 374 {
@@ -349,9 +428,8 @@ namespace OpenSim.Region.Environment.Scenes
349 public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length, 428 public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
350 string newName) 429 string newName)
351 { 430 {
352 m_log.Info( 431 m_log.DebugFormat(
353 "[AGENT INVENTORY]: " + 432 "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
354 "Moving item for " + remoteClient.AgentId.ToString());
355 433
356 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 434 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
357 if (userInfo == null) 435 if (userInfo == null)
@@ -429,7 +507,8 @@ namespace OpenSim.Region.Environment.Scenes
429 } 507 }
430 508
431 /// <summary> 509 /// <summary>
432 /// Create a new inventory item. 510 /// Create a new inventory item. Called when the client creates a new item directly within their
511 /// inventory (e.g. by selecting a context inventory menu option).
433 /// </summary> 512 /// </summary>
434 /// <param name="remoteClient"></param> 513 /// <param name="remoteClient"></param>
435 /// <param name="transactionID"></param> 514 /// <param name="transactionID"></param>