aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/InventoryModule.cs
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-04-07 01:46:00 +0000
committerJustin Clarke Casey2008-04-07 01:46:00 +0000
commitdfe5e9d4ebb705d0c20d6260bae5d11659ac904d (patch)
tree013b251f500feebfdeae94681350d05c078533ee /OpenSim/Region/Environment/Modules/InventoryModule.cs
parentUpdate svn properties. (diff)
downloadopensim-SC-dfe5e9d4ebb705d0c20d6260bae5d11659ac904d.zip
opensim-SC-dfe5e9d4ebb705d0c20d6260bae5d11659ac904d.tar.gz
opensim-SC-dfe5e9d4ebb705d0c20d6260bae5d11659ac904d.tar.bz2
opensim-SC-dfe5e9d4ebb705d0c20d6260bae5d11659ac904d.tar.xz
* EXPERIMENTAL ROUGH DRAFT: First rough implementation of avatar to avatar item giving
* Now you can drag an object from your inventory and give it to another avatar * !!! Use at your own risk !!! Many things are unimplemented as of yet, including permissions (the person receiving your item can probably do absolutely everything with it) * Also, items for the receiving end up in their root folder rather than the objects folder
Diffstat (limited to 'OpenSim/Region/Environment/Modules/InventoryModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/InventoryModule.cs158
1 files changed, 157 insertions, 1 deletions
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}