aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorDahlia Trimble2009-01-10 09:15:23 +0000
committerDahlia Trimble2009-01-10 09:15:23 +0000
commit630ce5b26446883043aa5e6541a4550d0e918659 (patch)
tree5128485b0d8e94c96593b352a421623cbd053acb /OpenSim/Region
parentInclude the changes from StrawBerryFride's patch to (diff)
downloadopensim-SC-630ce5b26446883043aa5e6541a4550d0e918659.zip
opensim-SC-630ce5b26446883043aa5e6541a4550d0e918659.tar.gz
opensim-SC-630ce5b26446883043aa5e6541a4550d0e918659.tar.bz2
opensim-SC-630ce5b26446883043aa5e6541a4550d0e918659.tar.xz
Revert progressive texture patch from r8001 until issues can be addressed
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs62
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs21
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs31
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs2
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs307
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs73
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.Inventory.cs139
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs102
8 files changed, 310 insertions, 427 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
index 2f5ea23..6bb61e2 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureDownloadModule.cs
@@ -204,14 +204,14 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
204 /// <param name="e"></param> 204 /// <param name="e"></param>
205 public void TextureRequest(Object sender, TextureRequestArgs e) 205 public void TextureRequest(Object sender, TextureRequestArgs e)
206 { 206 {
207 IClientAPI client = (IClientAPI) sender; 207 IClientAPI client = (IClientAPI)sender;
208 208
209 if (e.Priority == 1016001f) // Preview 209 if (e.Priority == 1016001f) // Preview
210 { 210 {
211 if (client.Scene is Scene) 211 if (client.Scene is Scene)
212 { 212 {
213 Scene scene = (Scene)client.Scene; 213 Scene scene = (Scene)client.Scene;
214 214
215 CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId); 215 CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(client.AgentId);
216 if (profile == null) // Deny unknown user 216 if (profile == null) // Deny unknown user
217 return; 217 return;
@@ -241,52 +241,44 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
241 { 241 {
242 ITextureSender sender = null; 242 ITextureSender sender = null;
243 243
244// try 244 try
245// { 245 {
246 while (true) 246 while (true)
247 { 247 {
248 try 248 sender = m_queueSenders.Dequeue();
249
250 if (sender.Cancel)
249 { 251 {
250 sender = m_queueSenders.Dequeue(); 252 TextureSent(sender);
251 253
252 if (sender.Cancel) 254 sender.Cancel = false;
255 }
256 else
257 {
258 bool finished = sender.SendTexturePacket();
259 if (finished)
253 { 260 {
254 TextureSent(sender); 261 TextureSent(sender);
255
256 sender.Cancel = false;
257 } 262 }
258 else 263 else
259 { 264 {
260 bool finished = sender.SendTexturePacket(); 265 m_queueSenders.Enqueue(sender);
261 if (finished)
262 {
263 TextureSent(sender);
264 }
265 else
266 {
267 m_queueSenders.Enqueue(sender);
268 }
269 } 266 }
267 }
270 268
271 // Make sure that any sender we currently have can get garbage collected 269 // Make sure that any sender we currently have can get garbage collected
272 sender = null; 270 sender = null;
273 271
274 //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count()); 272 //m_log.InfoFormat("[TEXTURE] Texture sender queue size: {0}", m_queueSenders.Count());
275 }
276 catch(Exception e)
277 {
278 m_log.ErrorFormat(
279 "[TEXTURE]: Texture send thread caught exception. The texture send was aborted. Exception is {0}", e);
280 }
281 } 273 }
282// } 274 }
283// catch (Exception e) 275 catch (Exception e)
284// { 276 {
285// // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened 277 // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened
286// m_log.ErrorFormat( 278 m_log.ErrorFormat(
287// "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}", 279 "[TEXTURE]: Texture send thread terminating with exception. PLEASE REBOOT YOUR SIM - TEXTURES WILL NOT BE AVAILABLE UNTIL YOU DO. Exception is {0}",
288// e); 280 e);
289// } 281 }
290 } 282 }
291 283
292 /// <summary> 284 /// <summary>
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
index 044ee76..34ddee6 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/TextureNotFoundSender.cs
@@ -28,6 +28,7 @@
28using System.Reflection; 28using System.Reflection;
29using log4net; 29using log4net;
30using OpenMetaverse; 30using OpenMetaverse;
31using OpenMetaverse.Packets;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
33 34
@@ -38,11 +39,11 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
38 /// </summary> 39 /// </summary>
39 public class TextureNotFoundSender : ITextureSender 40 public class TextureNotFoundSender : ITextureSender
40 { 41 {
41// private static readonly log4net.ILog m_log 42 // private static readonly log4net.ILog m_log
42// = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 43 // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
43 44
44// private IClientAPI m_client; 45 // private IClientAPI m_client;
45// private UUID m_textureId; 46 // private UUID m_textureId;
46 47
47 public TextureNotFoundSender(IClientAPI client, UUID textureID) 48 public TextureNotFoundSender(IClientAPI client, UUID textureID)
48 { 49 {
@@ -55,13 +56,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
55 public bool Sending 56 public bool Sending
56 { 57 {
57 get { return false; } 58 get { return false; }
58 set {} 59 set { }
59 } 60 }
60 61
61 public bool Cancel 62 public bool Cancel
62 { 63 {
63 get { return false; } 64 get { return false; }
64 set {} 65 set { }
65 } 66 }
66 67
67 // See ITextureSender 68 // See ITextureSender
@@ -73,13 +74,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
73 // See ITextureSender 74 // See ITextureSender
74 public bool SendTexturePacket() 75 public bool SendTexturePacket()
75 { 76 {
76// m_log.DebugFormat( 77 // m_log.DebugFormat(
77// "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found", 78 // "[TEXTURE NOT FOUND SENDER]: Informing the client that texture {0} cannot be found",
78// m_textureId); 79 // m_textureId);
79 80
80 // XXX Temporarily disabling as this appears to be causing client crashes on at least 81 // XXX Temporarily disabling as this appears to be causing client crashes on at least
81 // 1.19.0(5) of the Linden Second Life client. 82 // 1.19.0(5) of the Linden Second Life client.
82// m_client.SendImageNotFound(m_textureId); 83 // m_client.SendImageNotFound(m_textureId);
83 84
84 return true; 85 return true;
85 } 86 }
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
index aab4ad0..e0790a2 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureDownload/UserTextureDownloadService.cs
@@ -56,10 +56,11 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
56 /// <summary> 56 /// <summary>
57 /// We will allow the client to request the same texture n times before dropping further requests 57 /// We will allow the client to request the same texture n times before dropping further requests
58 /// 58 ///
59 /// This number contains repeated requests for the same texture at different resolutions (which 59 /// This number includes repeated requests for the same texture at different resolutions (which we don't
60 /// are handled since r7368). However, this situation should be handled in a more sophisticated way. 60 /// currently handle properly as far as I know). However, this situation should be handled in a more
61 /// sophisticated way.
61 /// </summary> 62 /// </summary>
62 private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 15; 63 private static readonly int MAX_ALLOWED_TEXTURE_REQUESTS = 5;
63 64
64 /// <summary> 65 /// <summary>
65 /// XXX Also going to limit requests for found textures. 66 /// XXX Also going to limit requests for found textures.
@@ -119,13 +120,13 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
119 } 120 }
120 else 121 else
121 { 122 {
122// m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID); 123 // m_log.DebugFormat("[TEXTURE]: Received a request for texture {0}", e.RequestedAssetID);
123 124
124 if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID)) 125 if (!foundTextureLimitStrategy.AllowRequest(e.RequestedAssetID))
125 { 126 {
126// m_log.DebugFormat( 127 // m_log.DebugFormat(
127// "[TEXTURE]: Refusing request for {0} from client {1}", 128 // "[TEXTURE]: Refusing request for {0} from client {1}",
128// e.RequestedAssetID, m_client.AgentId); 129 // e.RequestedAssetID, m_client.AgentId);
129 130
130 return; 131 return;
131 } 132 }
@@ -138,9 +139,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
138 139
139 // Commenting out this message for now as it causes too much noise with other 140 // Commenting out this message for now as it causes too much noise with other
140 // debug messages. 141 // debug messages.
141// m_log.DebugFormat( 142 // m_log.DebugFormat(
142// "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests", 143 // "[TEXTURE]: Dropping requests for notified missing texture {0} for client {1} since we have received more than {2} requests",
143// e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS); 144 // e.RequestedAssetID, m_client.AgentId, MAX_ALLOWED_TEXTURE_REQUESTS);
144 } 145 }
145 146
146 return; 147 return;
@@ -148,7 +149,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
148 149
149 m_scene.AddPendingDownloads(1); 150 m_scene.AddPendingDownloads(1);
150 151
151 TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber, e.Priority); 152 TextureSender.TextureSender requestHandler = new TextureSender.TextureSender(m_client, e.DiscardLevel, e.PacketNumber);
152 m_textureSenders.Add(e.RequestedAssetID, requestHandler); 153 m_textureSenders.Add(e.RequestedAssetID, requestHandler);
153 154
154 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true); 155 m_scene.AssetCache.GetAsset(e.RequestedAssetID, TextureCallback, true);
@@ -195,9 +196,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureDownload
195 { 196 {
196 missingTextureLimitStrategy.MonitorRequests(textureID); 197 missingTextureLimitStrategy.MonitorRequests(textureID);
197 198
198// m_log.DebugFormat( 199 // m_log.DebugFormat(
199// "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}", 200 // "[TEXTURE]: Queueing first TextureNotFoundSender for {0}, client {1}",
200// textureID, m_client.AgentId); 201 // textureID, m_client.AgentId);
201 } 202 }
202 203
203 ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID); 204 ITextureSender textureNotFoundSender = new TextureNotFoundSender(m_client, textureID);
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
index cff215b..4049dfc 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
53 agent.startpos = Vector3.Zero; 53 agent.startpos = Vector3.Zero;
54 agent.CapsPath = "http://wibble.com"; 54 agent.CapsPath = "http://wibble.com";
55 55
56 new TextureSender(new TestClient(agent), 0, 0, 1.0f); 56 new TextureSender(new TestClient(agent), 0, 0);
57 } 57 }
58 } 58 }
59} \ No newline at end of file 59} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
index 0e34271..a6901b6 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs
@@ -27,188 +27,106 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using OpenMetaverse.Packets;
30using log4net; 31using log4net;
31using OpenSim.Framework; 32using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces; 33using OpenSim.Region.Environment.Interfaces;
33 34
34namespace OpenSim.Region.Environment.Modules.Agent.TextureSender 35namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
35{ 36{
36 public class ImageDownload 37 /// <summary>
38 /// A TextureSender handles the process of receiving a texture requested by the client from the
39 /// AssetCache, and then sending that texture back to the client.
40 /// </summary>
41 public class TextureSender : ITextureSender
37 { 42 {
38 public const int FIRST_IMAGE_PACKET_SIZE = 600; 43 private static readonly ILog m_log
39 public const int IMAGE_PACKET_SIZE = 1000; 44 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
40
41 public OpenMetaverse.AssetTexture Texture;
42 public int DiscardLevel;
43 public float Priority;
44 public int CurrentPacket;
45 public int StopPacket;
46
47 public ImageDownload(OpenMetaverse.AssetTexture texture, int discardLevel, float priority, int packet)
48 {
49 Texture = texture;
50 Update(discardLevel, priority, packet);
51 }
52
53 /// <summary>
54 /// Updates an image transfer with new information and recalculates
55 /// offsets
56 /// </summary>
57 /// <param name="discardLevel">New requested discard level</param>
58 /// <param name="priority">New requested priority</param>
59 /// <param name="packet">New requested packet offset</param>
60 public void Update(int discardLevel, float priority, int packet)
61 {
62 Priority = priority;
63 DiscardLevel = Clamp(discardLevel, 0, Texture.LayerInfo.Length - 1);
64 StopPacket = GetPacketForBytePosition(Texture.LayerInfo[(Texture.LayerInfo.Length - 1) - DiscardLevel].End);
65 CurrentPacket = Clamp(packet, 1, TexturePacketCount());
66 }
67 45
68 /// <summary> 46 /// <summary>
69 /// Returns the total number of packets needed to transfer this texture, 47 /// Records the number of times texture send has been called.
70 /// including the first packet of size FIRST_IMAGE_PACKET_SIZE
71 /// </summary> 48 /// </summary>
72 /// <returns>Total number of packets needed to transfer this texture</returns> 49 public int counter = 0;
73 public int TexturePacketCount()
74 {
75 return ((Texture.AssetData.Length - FIRST_IMAGE_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE) + 1;
76 }
77 50
78 /// <summary> 51 public bool ImageLoaded = false;
79 /// Returns the current byte offset for this transfer, calculated from
80 /// the CurrentPacket
81 /// </summary>
82 /// <returns>Current byte offset for this transfer</returns>
83 public int CurrentBytePosition()
84 {
85 return FIRST_IMAGE_PACKET_SIZE + (CurrentPacket - 1) * IMAGE_PACKET_SIZE;
86 }
87
88 /// <summary>
89 /// Returns the size, in bytes, of the last packet. This will be somewhere
90 /// between 1 and IMAGE_PACKET_SIZE bytes
91 /// </summary>
92 /// <returns>Size of the last packet in the transfer</returns>
93 public int LastPacketSize()
94 {
95 return Texture.AssetData.Length - (FIRST_IMAGE_PACKET_SIZE + ((TexturePacketCount() - 2) * IMAGE_PACKET_SIZE));
96 }
97 52
98 /// <summary> 53 /// <summary>
99 /// Find the packet number that contains a given byte position 54 /// Holds the texture asset to send.
100 /// </summary> 55 /// </summary>
101 /// <param name="bytePosition">Byte position</param> 56 private AssetBase m_asset;
102 /// <returns>Packet number that contains the given byte position</returns>
103 int GetPacketForBytePosition(int bytePosition)
104 {
105 return ((bytePosition - FIRST_IMAGE_PACKET_SIZE + IMAGE_PACKET_SIZE - 1) / IMAGE_PACKET_SIZE);
106 }
107 57
108 /// <summary> 58 //public UUID assetID { get { return m_asset.FullID; } }
109 /// Clamp a given value between a range
110 /// </summary>
111 /// <param name="value">Value to clamp</param>
112 /// <param name="min">Minimum allowable value</param>
113 /// <param name="max">Maximum allowable value</param>
114 /// <returns>A value inclusively between lower and upper</returns>
115 static int Clamp(int value, int min, int max)
116 {
117 // First we check to see if we're greater than the max
118 value = (value > max) ? max : value;
119 59
120 // Then we check to see if we're less than the min. 60 // private bool m_cancel = false;
121 value = (value < min) ? min : value;
122 61
123 // There's no check to see if min > max. 62 // See ITextureSender
124 return value;
125 }
126 }
127 63
128 /// <summary> 64 // private bool m_sending = false;
129 /// A TextureSender handles the process of receiving a texture requested by the client from the
130 /// AssetCache, and then sending that texture back to the client.
131 /// </summary>
132 public class TextureSender : ITextureSender
133 {
134 private static readonly ILog m_log
135 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
136 65
137 public bool ImageLoaded = false; 66 /// <summary>
67 /// This is actually the number of extra packets required to send the texture data! We always assume
68 /// at least one is required.
69 /// </summary>
70 private int NumPackets = 0;
138 71
139 /// <summary> 72 /// <summary>
140 /// Holds the texture asset to send. 73 /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts
74 /// at the 600th byte (0th indexed).
141 /// </summary> 75 /// </summary>
142 private AssetBase m_asset; 76 private int PacketCounter = 0;
143 private bool m_cancel = false;
144 private bool m_sending = false;
145 private bool sendFirstPacket = false;
146 private int initialDiscardLevel = 0;
147 private int initialPacketNum = 0;
148 private float initialPriority = 0.0f;
149 77
150 private ImageDownload download; 78 private int RequestedDiscardLevel = -1;
151 private IClientAPI RequestUser; 79 private IClientAPI RequestUser;
80 private uint StartPacketNumber = 0;
152 81
153 public TextureSender(IClientAPI client, int discardLevel, uint packetNumber, float priority) 82 public TextureSender(IClientAPI client, int discardLevel, uint packetNumber)
154 { 83 {
155 RequestUser = client; 84 RequestUser = client;
156 initialDiscardLevel = discardLevel; 85 RequestedDiscardLevel = discardLevel;
157 initialPacketNum = (int)packetNumber; 86 StartPacketNumber = packetNumber;
158 initialPriority = priority;
159 } 87 }
160 88
161 #region ITextureSender Members 89 #region ITextureSender Members
162 90
163 public bool Cancel 91 public bool Cancel
164 { 92 {
165 get { return m_cancel; } 93 get { return false; }
166 set { m_cancel = value; } 94 set
95 {
96 // m_cancel = value;
97 }
167 } 98 }
168 99
169 public bool Sending 100 public bool Sending
170 { 101 {
171 get { return m_sending; } 102 get { return false; }
172 set { m_sending = value; } 103 set
104 {
105 // m_sending = value;
106 }
173 } 107 }
174 108
175 // See ITextureSender 109 // See ITextureSender
176 public void UpdateRequest(int discardLevel, uint packetNumber) 110 public void UpdateRequest(int discardLevel, uint packetNumber)
177 { 111 {
178 if (download == null) 112 RequestedDiscardLevel = discardLevel;
179 return; 113 StartPacketNumber = packetNumber;
180 114 PacketCounter = (int)StartPacketNumber;
181 lock (download)
182 {
183 if (discardLevel < download.DiscardLevel)
184 m_log.DebugFormat("Image download {0} is changing from DiscardLevel {1} to {2}",
185 m_asset.FullID, download.DiscardLevel, discardLevel);
186
187 if (packetNumber != download.CurrentPacket)
188 m_log.DebugFormat("Image download {0} is changing from Packet {1} to {2}",
189 m_asset.FullID, download.CurrentPacket, packetNumber);
190
191 download.Update(discardLevel, download.Priority, (int)packetNumber);
192
193 sendFirstPacket = true;
194 }
195 } 115 }
196 116
197 // See ITextureSender 117 // See ITextureSender
198 public bool SendTexturePacket() 118 public bool SendTexturePacket()
199 { 119 {
200 if (download != null && !m_cancel && (sendFirstPacket || download.CurrentPacket <= download.StopPacket)) 120 //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID);
201 { 121
202 SendPacket(); 122 SendPacket();
203 return false; 123 counter++;
204 } 124 if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) ||
205 else 125 ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets / (RequestedDiscardLevel + 1)))))
206 { 126 {
207 m_sending = false;
208 m_cancel = true;
209 sendFirstPacket = false;
210 return true; 127 return true;
211 } 128 }
129 return false;
212 } 130 }
213 131
214 #endregion 132 #endregion
@@ -220,52 +138,9 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
220 public void TextureReceived(AssetBase asset) 138 public void TextureReceived(AssetBase asset)
221 { 139 {
222 m_asset = asset; 140 m_asset = asset;
223 141 NumPackets = CalculateNumPackets(asset.Data.Length);
224 try 142 PacketCounter = (int)StartPacketNumber;
225 { 143 ImageLoaded = true;
226 OpenMetaverse.AssetTexture texture = new OpenMetaverse.AssetTexture(m_asset.FullID, m_asset.Data);
227 if (texture.DecodeLayerBoundaries())
228 {
229 bool sane = true;
230
231 // Sanity check all of the layers
232 for (int i = 0; i < texture.LayerInfo.Length; i++)
233 {
234 if (texture.LayerInfo[i].End > texture.AssetData.Length)
235 {
236 sane = false;
237 break;
238 }
239 }
240
241 if (sane)
242 {
243 download = new ImageDownload(texture, initialDiscardLevel, initialPriority, initialPacketNum);
244 ImageLoaded = true;
245 m_sending = true;
246 m_cancel = false;
247 sendFirstPacket = true;
248 return;
249 }
250 else
251 {
252 m_log.Error("JPEG2000 texture decoding succeeded, but sanity check failed for " +
253 m_asset.FullID.ToString());
254 }
255 }
256 else
257 {
258 m_log.Error("JPEG2000 texture decoding failed for " + m_asset.FullID.ToString());
259 }
260 }
261 catch (Exception ex)
262 {
263 m_log.Error("JPEG2000 texture decoding threw an exception for " + m_asset.FullID.ToString(), ex);
264 }
265
266 ImageLoaded = false;
267 m_sending = false;
268 m_cancel = true;
269 } 144 }
270 145
271 /// <summary> 146 /// <summary>
@@ -273,48 +148,66 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
273 /// </summary> 148 /// </summary>
274 private void SendPacket() 149 private void SendPacket()
275 { 150 {
276 lock (download) 151 if (PacketCounter <= NumPackets)
277 { 152 {
278 if (sendFirstPacket) 153 if (PacketCounter == 0)
279 { 154 {
280 sendFirstPacket = false; 155 if (NumPackets == 0)
281
282 if (m_asset.Data.Length <= ImageDownload.FIRST_IMAGE_PACKET_SIZE)
283 { 156 {
284 RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2); 157 RequestUser.SendImageFirstPart(1, m_asset.FullID, (uint)m_asset.Data.Length, m_asset.Data, 2);
285 return; 158 PacketCounter++;
286 } 159 }
287 else 160 else
288 { 161 {
289 byte[] firstImageData = new byte[ImageDownload.FIRST_IMAGE_PACKET_SIZE]; 162 byte[] ImageData1 = new byte[600];
290 try { Buffer.BlockCopy(m_asset.Data, 0, firstImageData, 0, ImageDownload.FIRST_IMAGE_PACKET_SIZE); } 163 Array.Copy(m_asset.Data, 0, ImageData1, 0, 600);
291 catch (Exception) 164
292 { 165 RequestUser.SendImageFirstPart(
293 m_log.Error("Texture data copy failed on first packet for " + m_asset.FullID.ToString()); 166 (ushort)(NumPackets), m_asset.FullID, (uint)m_asset.Data.Length, ImageData1, 2);
294 m_cancel = true; 167 PacketCounter++;
295 m_sending = false;
296 return;
297 }
298 RequestUser.SendImageFirstPart((ushort)download.TexturePacketCount(), m_asset.FullID, (uint)m_asset.Data.Length, firstImageData, 2);
299 } 168 }
300 } 169 }
301 170 else
302 int imagePacketSize = (download.CurrentPacket == download.TexturePacketCount() - 1) ?
303 download.LastPacketSize() : ImageDownload.IMAGE_PACKET_SIZE;
304
305 byte[] imageData = new byte[imagePacketSize];
306 try { Buffer.BlockCopy(m_asset.Data, download.CurrentBytePosition(), imageData, 0, imagePacketSize); }
307 catch (Exception)
308 { 171 {
309 m_log.Error("Texture data copy failed for " + m_asset.FullID.ToString()); 172 int size = m_asset.Data.Length - 600 - (1000 * (PacketCounter - 1));
310 m_cancel = true; 173 if (size > 1000) size = 1000;
311 m_sending = false; 174 byte[] imageData = new byte[size];
312 return; 175 try
176 {
177 Array.Copy(m_asset.Data, 600 + (1000 * (PacketCounter - 1)), imageData, 0, size);
178 }
179 catch (ArgumentOutOfRangeException)
180 {
181 m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" +
182 m_asset.FullID.ToString());
183 return;
184 }
185
186 RequestUser.SendImageNextPart((ushort)PacketCounter, m_asset.FullID, imageData);
187 PacketCounter++;
313 } 188 }
189 }
190 }
314 191
315 RequestUser.SendImageNextPart((ushort)download.CurrentPacket, m_asset.FullID, imageData); 192 /// <summary>
316 ++download.CurrentPacket; 193 /// Calculate the number of packets that will be required to send the texture loaded into this sender
194 /// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
195 /// </summary>
196 /// <param name="length"></param>
197 /// <returns></returns>
198 private int CalculateNumPackets(int length)
199 {
200 int numPackets = 0;
201
202 if (length > 600)
203 {
204 //over 600 bytes so split up file
205 int restData = (length - 600);
206 int restPackets = ((restData + 999) / 1000);
207 numPackets = restPackets;
317 } 208 }
209
210 return numPackets;
318 } 211 }
319 } 212 }
320} 213}
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
index ed77b2e..4a03ecd 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Friends/FriendsModule.cs
@@ -30,6 +30,7 @@ using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Reflection; 31using System.Reflection;
32using OpenMetaverse; 32using OpenMetaverse;
33using OpenMetaverse.Packets;
33using log4net; 34using log4net;
34using Nini.Config; 35using Nini.Config;
35using Nwc.XmlRpc; 36using Nwc.XmlRpc;
@@ -101,10 +102,10 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
101 102
102 private Dictionary<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>(); 103 private Dictionary<UUID, ulong> m_rootAgents = new Dictionary<UUID, ulong>();
103 104
104 private Dictionary<UUID, UUID> m_pendingCallingcardRequests = new Dictionary<UUID,UUID>(); 105 private Dictionary<UUID, UUID> m_pendingCallingcardRequests = new Dictionary<UUID, UUID>();
105 106
106 private Scene m_initialScene; // saves a lookup if we don't have a specific scene 107 private Scene m_initialScene; // saves a lookup if we don't have a specific scene
107 private Dictionary<ulong, Scene> m_scenes = new Dictionary<ulong,Scene>(); 108 private Dictionary<ulong, Scene> m_scenes = new Dictionary<ulong, Scene>();
108 private IMessageTransferModule m_TransferModule = null; 109 private IMessageTransferModule m_TransferModule = null;
109 110
110 #region IRegionModule Members 111 #region IRegionModule Members
@@ -124,9 +125,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
124 if (!m_scenes.ContainsKey(scene.RegionInfo.RegionHandle)) 125 if (!m_scenes.ContainsKey(scene.RegionInfo.RegionHandle))
125 m_scenes[scene.RegionInfo.RegionHandle] = scene; 126 m_scenes[scene.RegionInfo.RegionHandle] = scene;
126 } 127 }
127 128
128 scene.RegisterModuleInterface<IFriendsModule>(this); 129 scene.RegisterModuleInterface<IFriendsModule>(this);
129 130
130 scene.EventManager.OnNewClient += OnNewClient; 131 scene.EventManager.OnNewClient += OnNewClient;
131 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage; 132 scene.EventManager.OnIncomingInstantMessage += OnGridInstantMessage;
132 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; 133 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
@@ -179,7 +180,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
179 lock (m_rootAgents) 180 lock (m_rootAgents)
180 { 181 {
181 List<ScenePresence> friendsHere = new List<ScenePresence>(); 182 List<ScenePresence> friendsHere = new List<ScenePresence>();
182 183
183 try 184 try
184 { 185 {
185 UUID agentID = new UUID((string)requestData["agentID"]); 186 UUID agentID = new UUID((string)requestData["agentID"]);
@@ -212,7 +213,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
212 } 213 }
213 } 214 }
214 } 215 }
215 catch(Exception e) 216 catch (Exception e)
216 { 217 {
217 m_log.Warn("[FRIENDS]: Got exception while parsing presence_update_bulk request:", e); 218 m_log.Warn("[FRIENDS]: Got exception while parsing presence_update_bulk request:", e);
218 } 219 }
@@ -374,24 +375,24 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
374 } 375 }
375 return returnAgent; 376 return returnAgent;
376 } 377 }
377 378
378 public void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage) 379 public void OfferFriendship(UUID fromUserId, IClientAPI toUserClient, string offerMessage)
379 { 380 {
380 CachedUserInfo userInfo = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(fromUserId); 381 CachedUserInfo userInfo = m_initialScene.CommsManager.UserProfileCacheService.GetUserDetails(fromUserId);
381 382
382 if (userInfo != null) 383 if (userInfo != null)
383 { 384 {
384 GridInstantMessage msg = new GridInstantMessage( 385 GridInstantMessage msg = new GridInstantMessage(
385 toUserClient.Scene, fromUserId, userInfo.UserProfile.Name, toUserClient.AgentId, 386 toUserClient.Scene, fromUserId, userInfo.UserProfile.Name, toUserClient.AgentId,
386 (byte)InstantMessageDialog.FriendshipOffered, offerMessage, false, Vector3.Zero); 387 (byte)InstantMessageDialog.FriendshipOffered, offerMessage, false, Vector3.Zero);
387 388
388 FriendshipOffered(msg); 389 FriendshipOffered(msg);
389 } 390 }
390 else 391 else
391 { 392 {
392 m_log.ErrorFormat("[FRIENDS]: No user found for id {0} in OfferFriendship()", fromUserId); 393 m_log.ErrorFormat("[FRIENDS]: No user found for id {0} in OfferFriendship()", fromUserId);
393 } 394 }
394 } 395 }
395 396
396 #region FriendRequestHandling 397 #region FriendRequestHandling
397 398
@@ -413,7 +414,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
413 FriendshipDeclined(client, im); 414 FriendshipDeclined(client, im);
414 } 415 }
415 } 416 }
416 417
417 /// <summary> 418 /// <summary>
418 /// Invoked when a user offers a friendship. 419 /// Invoked when a user offers a friendship.
419 /// </summary> 420 /// </summary>
@@ -448,14 +449,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
448 // If new friend is local, it will send an IM to the viewer. 449 // If new friend is local, it will send an IM to the viewer.
449 // If new friend is remote, it will cause a OnGridInstantMessage on the remote server 450 // If new friend is remote, it will cause a OnGridInstantMessage on the remote server
450 m_TransferModule.SendInstantMessage(im, 451 m_TransferModule.SendInstantMessage(im,
451 delegate(bool success) 452 delegate(bool success)
452 { 453 {
453 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); 454 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
454 } 455 }
455 ); 456 );
456 } 457 }
457 } 458 }
458 459
459 /// <summary> 460 /// <summary>
460 /// Invoked when a user accepts a friendship offer. 461 /// Invoked when a user accepts a friendship offer.
461 /// </summary> 462 /// </summary>
@@ -464,9 +465,9 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
464 private void FriendshipAccepted(IClientAPI client, GridInstantMessage im) 465 private void FriendshipAccepted(IClientAPI client, GridInstantMessage im)
465 { 466 {
466 m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})", 467 m_log.DebugFormat("[FRIEND]: 39 - from client {0}, agent {2} {3}, imsession {4} to {5}: {6} (dialog {7})",
467 client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog); 468 client.AgentId, im.fromAgentID, im.fromAgentName, im.imSessionID, im.toAgentID, im.message, im.dialog);
468 } 469 }
469 470
470 /// <summary> 471 /// <summary>
471 /// Invoked when a user declines a friendship offer. 472 /// Invoked when a user declines a friendship offer.
472 /// </summary> 473 /// </summary>
@@ -477,7 +478,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
477 { 478 {
478 UUID fromAgentID = new UUID(im.fromAgentID); 479 UUID fromAgentID = new UUID(im.fromAgentID);
479 UUID toAgentID = new UUID(im.toAgentID); 480 UUID toAgentID = new UUID(im.toAgentID);
480 481
481 // declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator 482 // declining the friendship offer causes a type 40 IM being sent to the (possibly remote) initiator
482 // toAgentID is initiator, fromAgentID declined friendship 483 // toAgentID is initiator, fromAgentID declined friendship
483 m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})", 484 m_log.DebugFormat("[FRIEND]: 40 - from client {0}, agent {1} {2}, imsession {3} to {4}: {5} (dialog {6})",
@@ -487,14 +488,15 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
487 // Send the decline to whoever is the destination. 488 // Send the decline to whoever is the destination.
488 GridInstantMessage msg = new GridInstantMessage(client.Scene, fromAgentID, client.Name, toAgentID, 489 GridInstantMessage msg = new GridInstantMessage(client.Scene, fromAgentID, client.Name, toAgentID,
489 im.dialog, im.message, im.offline != 0, im.Position); 490 im.dialog, im.message, im.offline != 0, im.Position);
490 491
491 // If new friend is local, it will send an IM to the viewer. 492 // If new friend is local, it will send an IM to the viewer.
492 // If new friend is remote, it will cause a OnGridInstantMessage on the remote server 493 // If new friend is remote, it will cause a OnGridInstantMessage on the remote server
493 m_TransferModule.SendInstantMessage(msg, 494 m_TransferModule.SendInstantMessage(msg,
494 delegate(bool success) { 495 delegate(bool success)
496 {
495 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); 497 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
496 } 498 }
497 ); 499 );
498 } 500 }
499 501
500 private void OnGridInstantMessage(GridInstantMessage msg) 502 private void OnGridInstantMessage(GridInstantMessage msg)
@@ -510,7 +512,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
510 { 512 {
511 // this should succeed as we *know* the root agent is here. 513 // this should succeed as we *know* the root agent is here.
512 m_TransferModule.SendInstantMessage(msg, 514 m_TransferModule.SendInstantMessage(msg,
513 delegate(bool success) { 515 delegate(bool success)
516 {
514 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); 517 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
515 } 518 }
516 ); 519 );
@@ -566,7 +569,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
566 client.Name, client.AgentId, agentID, friendID); 569 client.Name, client.AgentId, agentID, friendID);
567 570
568 // store the new friend persistently for both avatars 571 // store the new friend persistently for both avatars
569 m_initialScene.StoreAddFriendship(friendID, agentID, (uint) FriendRights.CanSeeOnline); 572 m_initialScene.StoreAddFriendship(friendID, agentID, (uint)FriendRights.CanSeeOnline);
570 573
571 // The cache entries aren't valid anymore either, as we just added a friend to both sides. 574 // The cache entries aren't valid anymore either, as we just added a friend to both sides.
572 lock (m_friendLists) 575 lock (m_friendLists)
@@ -609,7 +612,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
609 if (m_TransferModule != null) 612 if (m_TransferModule != null)
610 { 613 {
611 m_TransferModule.SendInstantMessage(msg, 614 m_TransferModule.SendInstantMessage(msg,
612 delegate(bool success) { 615 delegate(bool success)
616 {
613 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); 617 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
614 } 618 }
615 ); 619 );
@@ -633,7 +637,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
633 if (m_TransferModule != null) 637 if (m_TransferModule != null)
634 { 638 {
635 m_TransferModule.SendInstantMessage(msg, 639 m_TransferModule.SendInstantMessage(msg,
636 delegate(bool success) { 640 delegate(bool success)
641 {
637 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success); 642 m_log.DebugFormat("[FRIEND]: sending IM success = {0}", success);
638 } 643 }
639 ); 644 );
@@ -809,16 +814,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
809 // I can't believe that we have Dictionaries, but no Sets, considering Java introduced them years ago... 814 // I can't believe that we have Dictionaries, but no Sets, considering Java introduced them years ago...
810 List<UUID> friendIDsToSendTo = new List<UUID>(); 815 List<UUID> friendIDsToSendTo = new List<UUID>();
811 List<UUID> candidateFriendIDsToReceive = new List<UUID>(); 816 List<UUID> candidateFriendIDsToReceive = new List<UUID>();
812 817
813 foreach (FriendListItem item in friendList) 818 foreach (FriendListItem item in friendList)
814 { 819 {
815 if (((item.FriendListOwnerPerms | item.FriendPerms) & (uint)FriendRights.CanSeeOnline) != 0) 820 if (((item.FriendListOwnerPerms | item.FriendPerms) & (uint)FriendRights.CanSeeOnline) != 0)
816 { 821 {
817 // friend is allowed to see my presence => add 822 // friend is allowed to see my presence => add
818 if ((item.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0) 823 if ((item.FriendListOwnerPerms & (uint)FriendRights.CanSeeOnline) != 0)
819 friendIDsToSendTo.Add(item.Friend); 824 friendIDsToSendTo.Add(item.Friend);
820 825
821 if ((item.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0) 826 if ((item.FriendPerms & (uint)FriendRights.CanSeeOnline) != 0)
822 candidateFriendIDsToReceive.Add(item.Friend); 827 candidateFriendIDsToReceive.Add(item.Friend);
823 } 828 }
824 } 829 }
@@ -857,7 +862,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
857 if (iAmOnline) 862 if (iAmOnline)
858 { 863 {
859 List<UUID> friendIDsToReceive = new List<UUID>(); 864 List<UUID> friendIDsToReceive = new List<UUID>();
860 865
861 for (int i = candidateFriendIDsToReceive.Count - 1; i >= 0; --i) 866 for (int i = candidateFriendIDsToReceive.Count - 1; i >= 0; --i)
862 { 867 {
863 UUID uuid = candidateFriendIDsToReceive[i]; 868 UUID uuid = candidateFriendIDsToReceive[i];
@@ -867,11 +872,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
867 friendIDsToReceive.Add(uuid); 872 friendIDsToReceive.Add(uuid);
868 } 873 }
869 } 874 }
870 875
871 m_log.DebugFormat( 876 m_log.DebugFormat(
872 "[FRIEND]: Sending {0} online friends to {1}", friendIDsToReceive.Count, client.Name); 877 "[FRIEND]: Sending {0} online friends to {1}", friendIDsToReceive.Count, client.Name);
873 878
874 if (friendIDsToReceive.Count > 0) 879 if (friendIDsToReceive.Count > 0)
875 client.SendAgentOnline(friendIDsToReceive.ToArray()); 880 client.SendAgentOnline(friendIDsToReceive.ToArray());
876 881
877 // clear them for a possible second iteration; we don't have to repeat this 882 // clear them for a possible second iteration; we don't have to repeat this
@@ -914,7 +919,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
914 if (friendIDsToSendTo.Count > 0) 919 if (friendIDsToSendTo.Count > 0)
915 { 920 {
916 // sort them into regions 921 // sort them into regions
917 Dictionary<ulong, List<UUID>> friendsInRegion = new Dictionary<ulong,List<UUID>>(); 922 Dictionary<ulong, List<UUID>> friendsInRegion = new Dictionary<ulong, List<UUID>>();
918 foreach (UUID uuid in friendIDsToSendTo) 923 foreach (UUID uuid in friendIDsToSendTo)
919 { 924 {
920 ulong handle = friendRegions[uuid].regionHandle; // this can't fail as we filtered above already 925 ulong handle = friendRegions[uuid].regionHandle; // this can't fail as we filtered above already
@@ -993,5 +998,5 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Friends
993 } 998 }
994 } 999 }
995 1000
996 #endregion 1001 #endregion
997} 1002}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
index bcc0d19..a8387c4 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs
@@ -31,6 +31,7 @@ using System.Reflection;
31using System.Text; 31using System.Text;
32using System.Timers; 32using System.Timers;
33using OpenMetaverse; 33using OpenMetaverse;
34using OpenMetaverse.Packets;
34using log4net; 35using log4net;
35using OpenSim.Framework; 36using OpenSim.Framework;
36using OpenSim.Framework.Communications.Cache; 37using OpenSim.Framework.Communications.Cache;
@@ -42,12 +43,12 @@ namespace OpenSim.Region.Environment.Scenes
42 public partial class Scene 43 public partial class Scene
43 { 44 {
44 private static readonly ILog m_log 45 private static readonly ILog m_log
45 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 47
47 /// <summary> 48 /// <summary>
48 /// Allows asynchronous derezzing of objects from the scene into a client's inventory. 49 /// Allows asynchronous derezzing of objects from the scene into a client's inventory.
49 /// </summary> 50 /// </summary>
50 protected AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter; 51 protected AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter;
51 52
52 /// <summary> 53 /// <summary>
53 /// Start all the scripts in the scene which should be started. 54 /// Start all the scripts in the scene which should be started.
@@ -60,14 +61,14 @@ namespace OpenSim.Region.Environment.Scenes
60 { 61 {
61 if (group is SceneObjectGroup) 62 if (group is SceneObjectGroup)
62 { 63 {
63 ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0); 64 ((SceneObjectGroup)group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
64 } 65 }
65 } 66 }
66 } 67 }
67 68
68 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item) 69 public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item)
69 { 70 {
70 IMoneyModule money=RequestModuleInterface<IMoneyModule>(); 71 IMoneyModule money = RequestModuleInterface<IMoneyModule>();
71 if (money != null) 72 if (money != null)
72 { 73 {
73 money.ApplyUploadCharge(agentID); 74 money.ApplyUploadCharge(agentID);
@@ -145,9 +146,9 @@ namespace OpenSim.Region.Environment.Scenes
145 else 146 else
146 { 147 {
147 m_log.ErrorFormat( 148 m_log.ErrorFormat(
148 "[AGENT INVENTORY]: Could not resolve user {0} for adding an inventory item", 149 "[AGENT INVENTORY]: Could not resolve user {0} for adding an inventory item",
149 remoteClient.AgentId); 150 remoteClient.AgentId);
150 } 151 }
151 } 152 }
152 153
153 /// <summary> 154 /// <summary>
@@ -175,7 +176,7 @@ namespace OpenSim.Region.Environment.Scenes
175 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false); 176 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit notecard", false);
176 return UUID.Zero; 177 return UUID.Zero;
177 } 178 }
178 179
179 remoteClient.SendAgentAlertMessage("Notecard saved", false); 180 remoteClient.SendAgentAlertMessage("Notecard saved", false);
180 } 181 }
181 else if ((InventoryType)item.InvType == InventoryType.LSL) 182 else if ((InventoryType)item.InvType == InventoryType.LSL)
@@ -185,7 +186,7 @@ namespace OpenSim.Region.Environment.Scenes
185 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false); 186 remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
186 return UUID.Zero; 187 return UUID.Zero;
187 } 188 }
188 189
189 remoteClient.SendAgentAlertMessage("Script saved", false); 190 remoteClient.SendAgentAlertMessage("Script saved", false);
190 } 191 }
191 192
@@ -204,10 +205,10 @@ namespace OpenSim.Region.Environment.Scenes
204 else 205 else
205 { 206 {
206 m_log.ErrorFormat( 207 m_log.ErrorFormat(
207 "[AGENT INVENTORY]: Could not resolve user {0} for caps inventory update", 208 "[AGENT INVENTORY]: Could not resolve user {0} for caps inventory update",
208 remoteClient.AgentId); 209 remoteClient.AgentId);
209 } 210 }
210 211
211 return UUID.Zero; 212 return UUID.Zero;
212 } 213 }
213 214
@@ -283,7 +284,7 @@ namespace OpenSim.Region.Environment.Scenes
283 { 284 {
284 part.Inventory.RemoveScriptInstance(item.ItemID); 285 part.Inventory.RemoveScriptInstance(item.ItemID);
285 } 286 }
286 287
287 // Update item with new asset 288 // Update item with new asset
288 item.AssetID = asset.FullID; 289 item.AssetID = asset.FullID;
289 group.UpdateInventoryItem(item); 290 group.UpdateInventoryItem(item);
@@ -335,9 +336,9 @@ namespace OpenSim.Region.Environment.Scenes
335 /// <param name="name">The name of the updated item</param> 336 /// <param name="name">The name of the updated item</param>
336 /// <param name="description">The description of the updated item</param> 337 /// <param name="description">The description of the updated item</param>
337 /// <param name="nextOwnerMask">The permissions of the updated item</param> 338 /// <param name="nextOwnerMask">The permissions of the updated item</param>
338/* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID, 339 /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
339 UUID itemID, string name, string description, 340 UUID itemID, string name, string description,
340 uint nextOwnerMask)*/ 341 uint nextOwnerMask)*/
341 public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID, 342 public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID,
342 UUID itemID, InventoryItemBase itemUpd) 343 UUID itemID, InventoryItemBase itemUpd)
343 { 344 {
@@ -426,7 +427,7 @@ namespace OpenSim.Region.Environment.Scenes
426 { 427 {
427 return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero); 428 return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero);
428 } 429 }
429 430
430 /// <summary> 431 /// <summary>
431 /// Give an inventory item from one user to another 432 /// Give an inventory item from one user to another
432 /// </summary> 433 /// </summary>
@@ -485,7 +486,7 @@ namespace OpenSim.Region.Environment.Scenes
485 itemCopy.AssetType = item.AssetType; 486 itemCopy.AssetType = item.AssetType;
486 itemCopy.InvType = item.InvType; 487 itemCopy.InvType = item.InvType;
487 itemCopy.Folder = recipientFolderId; 488 itemCopy.Folder = recipientFolderId;
488 489
489 if (Permissions.PropagatePermissions()) 490 if (Permissions.PropagatePermissions())
490 { 491 {
491 if (item.InvType == 6) 492 if (item.InvType == 6)
@@ -502,7 +503,7 @@ namespace OpenSim.Region.Environment.Scenes
502 if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit 503 if ((item.CurrentPermissions & 8) != 0) // Propagate slam bit
503 { 504 {
504 itemCopy.CurrentPermissions = item.NextPermissions; 505 itemCopy.CurrentPermissions = item.NextPermissions;
505 itemCopy.BasePermissions=itemCopy.CurrentPermissions; 506 itemCopy.BasePermissions = itemCopy.CurrentPermissions;
506 itemCopy.CurrentPermissions |= 8; 507 itemCopy.CurrentPermissions |= 8;
507 } 508 }
508 509
@@ -557,10 +558,10 @@ namespace OpenSim.Region.Environment.Scenes
557 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder"); 558 m_log.Error("[AGENT INVENTORY]: Failed to find item " + itemId.ToString() + ", no root folder");
558 return null; 559 return null;
559 } 560 }
560 561
561 return null; 562 return null;
562 } 563 }
563 564
564 /// <summary> 565 /// <summary>
565 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent 566 /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
566 /// folders) is given. 567 /// folders) is given.
@@ -588,24 +589,24 @@ namespace OpenSim.Region.Environment.Scenes
588 589
589 return null; 590 return null;
590 } 591 }
591 592
592 if (!senderUserInfo.HasReceivedInventory) 593 if (!senderUserInfo.HasReceivedInventory)
593 { 594 {
594 m_log.DebugFormat( 595 m_log.DebugFormat(
595 "[AGENT INVENTORY]: Could not give inventory folder - have not yet received inventory for {0}", 596 "[AGENT INVENTORY]: Could not give inventory folder - have not yet received inventory for {0}",
596 senderId); 597 senderId);
597 598
598 return null; 599 return null;
599 } 600 }
600 601
601 InventoryFolderImpl folder = senderUserInfo.RootFolder.FindFolder(folderId); 602 InventoryFolderImpl folder = senderUserInfo.RootFolder.FindFolder(folderId);
602 603
603 if (null == folder) 604 if (null == folder)
604 { 605 {
605 m_log.ErrorFormat( 606 m_log.ErrorFormat(
606 "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId); 607 "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId);
607 608
608 return null; 609 return null;
609 } 610 }
610 611
611 CachedUserInfo recipientUserInfo 612 CachedUserInfo recipientUserInfo
@@ -618,30 +619,30 @@ namespace OpenSim.Region.Environment.Scenes
618 619
619 return null; 620 return null;
620 } 621 }
621 622
622 if (recipientParentFolderId == UUID.Zero) 623 if (recipientParentFolderId == UUID.Zero)
623 recipientParentFolderId = recipientUserInfo.RootFolder.ID; 624 recipientParentFolderId = recipientUserInfo.RootFolder.ID;
624 625
625 UUID newFolderId = UUID.Random(); 626 UUID newFolderId = UUID.Random();
626 recipientUserInfo.CreateFolder(folder.Name, newFolderId, (ushort)folder.Type, recipientParentFolderId); 627 recipientUserInfo.CreateFolder(folder.Name, newFolderId, (ushort)folder.Type, recipientParentFolderId);
627 628
628 // XXX: Messy - we should really get this back in the CreateFolder call 629 // XXX: Messy - we should really get this back in the CreateFolder call
629 InventoryFolderImpl copiedFolder = recipientUserInfo.RootFolder.FindFolder(newFolderId); 630 InventoryFolderImpl copiedFolder = recipientUserInfo.RootFolder.FindFolder(newFolderId);
630 631
631 // Give all the subfolders 632 // Give all the subfolders
632 List<InventoryFolderImpl> subFolders = folder.RequestListOfFolderImpls(); 633 List<InventoryFolderImpl> subFolders = folder.RequestListOfFolderImpls();
633 foreach (InventoryFolderImpl childFolder in subFolders) 634 foreach (InventoryFolderImpl childFolder in subFolders)
634 { 635 {
635 GiveInventoryFolder(recipientId, senderId, childFolder.ID, copiedFolder.ID); 636 GiveInventoryFolder(recipientId, senderId, childFolder.ID, copiedFolder.ID);
636 } 637 }
637 638
638 // Give all the items 639 // Give all the items
639 List<InventoryItemBase> items = folder.RequestListOfItems(); 640 List<InventoryItemBase> items = folder.RequestListOfItems();
640 foreach (InventoryItemBase item in items) 641 foreach (InventoryItemBase item in items)
641 { 642 {
642 GiveInventoryItem(recipientId, senderId, item.ID, copiedFolder.ID); 643 GiveInventoryItem(recipientId, senderId, item.ID, copiedFolder.ID);
643 } 644 }
644 645
645 return copiedFolder; 646 return copiedFolder;
646 } 647 }
647 648
@@ -879,7 +880,7 @@ namespace OpenSim.Region.Environment.Scenes
879 880
880 if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId)) 881 if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
881 return; 882 return;
882 883
883 if (transactionID == UUID.Zero) 884 if (transactionID == UUID.Zero)
884 { 885 {
885 CachedUserInfo userInfo 886 CachedUserInfo userInfo
@@ -890,7 +891,7 @@ namespace OpenSim.Region.Environment.Scenes
890 ScenePresence presence; 891 ScenePresence presence;
891 TryGetAvatar(remoteClient.AgentId, out presence); 892 TryGetAvatar(remoteClient.AgentId, out presence);
892 byte[] data = null; 893 byte[] data = null;
893 894
894 if (invType == 3 && presence != null) // OpenMetaverse.asset.assettype.landmark = 3 - needs to be turned into an enum 895 if (invType == 3 && presence != null) // OpenMetaverse.asset.assettype.landmark = 3 - needs to be turned into an enum
895 { 896 {
896 Vector3 pos = presence.AbsolutePosition; 897 Vector3 pos = presence.AbsolutePosition;
@@ -989,8 +990,8 @@ namespace OpenSim.Region.Environment.Scenes
989 { 990 {
990 if (ent is SceneObjectGroup) 991 if (ent is SceneObjectGroup)
991 { 992 {
992 if (((SceneObjectGroup) ent).HasChildPrim(localID)) 993 if (((SceneObjectGroup)ent).HasChildPrim(localID))
993 return (SceneObjectGroup) ent; 994 return (SceneObjectGroup)ent;
994 } 995 }
995 } 996 }
996 return null; 997 return null;
@@ -1425,7 +1426,7 @@ namespace OpenSim.Region.Environment.Scenes
1425 } 1426 }
1426 } 1427 }
1427 else // Updating existing item with new perms etc 1428 else // Updating existing item with new perms etc
1428 { 1429 {
1429 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); 1430 IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
1430 if (agentTransactions != null) 1431 if (agentTransactions != null)
1431 { 1432 {
@@ -1507,7 +1508,7 @@ namespace OpenSim.Region.Environment.Scenes
1507 } 1508 }
1508 } 1509 }
1509 else // script has been rezzed directly into a prim's inventory 1510 else // script has been rezzed directly into a prim's inventory
1510 { 1511 {
1511 SceneObjectPart part = GetSceneObjectPart(itemBase.Folder); 1512 SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
1512 if (part == null) 1513 if (part == null)
1513 return; 1514 return;
@@ -1517,10 +1518,10 @@ namespace OpenSim.Region.Environment.Scenes
1517 1518
1518 if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0) 1519 if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
1519 return; 1520 return;
1520 1521
1521 if (!Permissions.CanCreateObjectInventory( 1522 if (!Permissions.CanCreateObjectInventory(
1522 itemBase.InvType, part.UUID, remoteClient.AgentId)) 1523 itemBase.InvType, part.UUID, remoteClient.AgentId))
1523 return; 1524 return;
1524 1525
1525 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}")); 1526 AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType, Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"));
1526 AssetCache.AddAsset(asset); 1527 AssetCache.AddAsset(asset);
@@ -1733,7 +1734,7 @@ namespace OpenSim.Region.Environment.Scenes
1733 grp.UUID, 1734 grp.UUID,
1734 remoteClient.AgentId); 1735 remoteClient.AgentId);
1735 permissionToDelete = permissionToTake; 1736 permissionToDelete = permissionToTake;
1736 1737
1737 if (permissionToDelete) 1738 if (permissionToDelete)
1738 { 1739 {
1739 AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return"); 1740 AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
@@ -1803,7 +1804,7 @@ namespace OpenSim.Region.Environment.Scenes
1803 // 1804 //
1804 CachedUserInfo userInfo; 1805 CachedUserInfo userInfo;
1805 1806
1806 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy || 1807 if (action == DeRezAction.Take || action == DeRezAction.TakeCopy ||
1807 action == DeRezAction.SaveToExistingUserInventoryItem) 1808 action == DeRezAction.SaveToExistingUserInventoryItem)
1808 { 1809 {
1809 // Take or take copy require a taker 1810 // Take or take copy require a taker
@@ -1846,18 +1847,18 @@ namespace OpenSim.Region.Environment.Scenes
1846 // 1847 //
1847 1848
1848 InventoryFolderBase folder = null; 1849 InventoryFolderBase folder = null;
1849 InventoryItemBase item = null; 1850 InventoryItemBase item = null;
1850 1851
1851 if (DeRezAction.SaveToExistingUserInventoryItem == action) 1852 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1852 { 1853 {
1853 item = userInfo.RootFolder.FindItem( 1854 item = userInfo.RootFolder.FindItem(
1854 objectGroup.RootPart.FromUserInventoryItemID); 1855 objectGroup.RootPart.FromUserInventoryItemID);
1855 1856
1856 if (null == item) 1857 if (null == item)
1857 { 1858 {
1858 m_log.DebugFormat( 1859 m_log.DebugFormat(
1859 "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.", 1860 "[AGENT INVENTORY]: Object {0} {1} scheduled for save to inventory has already been deleted.",
1860 objectGroup.Name, objectGroup.UUID); 1861 objectGroup.Name, objectGroup.UUID);
1861 return UUID.Zero; 1862 return UUID.Zero;
1862 } 1863 }
1863 } 1864 }
@@ -1936,7 +1937,7 @@ namespace OpenSim.Region.Environment.Scenes
1936 item.InvType = (int)InventoryType.Object; 1937 item.InvType = (int)InventoryType.Object;
1937 item.Folder = folder.ID; 1938 item.Folder = folder.ID;
1938 item.Owner = userInfo.UserProfile.ID; 1939 item.Owner = userInfo.UserProfile.ID;
1939 1940
1940 } 1941 }
1941 1942
1942 AssetBase asset = CreateAsset( 1943 AssetBase asset = CreateAsset(
@@ -1946,10 +1947,10 @@ namespace OpenSim.Region.Environment.Scenes
1946 Utils.StringToBytes(sceneObjectXml)); 1947 Utils.StringToBytes(sceneObjectXml));
1947 AssetCache.AddAsset(asset); 1948 AssetCache.AddAsset(asset);
1948 assetID = asset.FullID; 1949 assetID = asset.FullID;
1949 1950
1950 if (DeRezAction.SaveToExistingUserInventoryItem == action) 1951 if (DeRezAction.SaveToExistingUserInventoryItem == action)
1951 { 1952 {
1952 item.AssetID = asset.FullID; 1953 item.AssetID = asset.FullID;
1953 userInfo.UpdateItem(item); 1954 userInfo.UpdateItem(item);
1954 } 1955 }
1955 else 1956 else
@@ -1958,8 +1959,8 @@ namespace OpenSim.Region.Environment.Scenes
1958 1959
1959 if (remoteClient != null && (remoteClient.AgentId != objectGroup.RootPart.OwnerID) && Permissions.PropagatePermissions()) 1960 if (remoteClient != null && (remoteClient.AgentId != objectGroup.RootPart.OwnerID) && Permissions.PropagatePermissions())
1960 { 1961 {
1961 uint perms=objectGroup.GetEffectivePermissions(); 1962 uint perms = objectGroup.GetEffectivePermissions();
1962 uint nextPerms=(perms & 7) << 13; 1963 uint nextPerms = (perms & 7) << 13;
1963 if ((nextPerms & (uint)PermissionMask.Copy) == 0) 1964 if ((nextPerms & (uint)PermissionMask.Copy) == 0)
1964 perms &= ~(uint)PermissionMask.Copy; 1965 perms &= ~(uint)PermissionMask.Copy;
1965 if ((nextPerms & (uint)PermissionMask.Transfer) == 0) 1966 if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
@@ -1990,7 +1991,7 @@ namespace OpenSim.Region.Environment.Scenes
1990 item.AssetType = asset.Type; 1991 item.AssetType = asset.Type;
1991 1992
1992 userInfo.AddItem(item); 1993 userInfo.AddItem(item);
1993 1994
1994 if (remoteClient != null && item.Owner == remoteClient.AgentId) 1995 if (remoteClient != null && item.Owner == remoteClient.AgentId)
1995 { 1996 {
1996 remoteClient.SendInventoryItemCreateUpdate(item); 1997 remoteClient.SendInventoryItemCreateUpdate(item);
@@ -2002,10 +2003,10 @@ namespace OpenSim.Region.Environment.Scenes
2002 { 2003 {
2003 notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item); 2004 notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item);
2004 } 2005 }
2005 } 2006 }
2006 } 2007 }
2007 } 2008 }
2008 2009
2009 return assetID; 2010 return assetID;
2010 } 2011 }
2011 2012
@@ -2019,11 +2020,11 @@ namespace OpenSim.Region.Environment.Scenes
2019 m_log.InfoFormat("[ATTACHMENT]: Save request for {0} which is unchanged", grp.UUID); 2020 m_log.InfoFormat("[ATTACHMENT]: Save request for {0} which is unchanged", grp.UUID);
2020 return; 2021 return;
2021 } 2022 }
2022 2023
2023 m_log.InfoFormat( 2024 m_log.InfoFormat(
2024 "[ATTACHMENT]: Updating asset for attachment {0}, attachpoint {1}", 2025 "[ATTACHMENT]: Updating asset for attachment {0}, attachpoint {1}",
2025 grp.UUID, grp.GetAttachmentPoint()); 2026 grp.UUID, grp.GetAttachmentPoint());
2026 2027
2027 string sceneObjectXml = objectGroup.ToXmlString(); 2028 string sceneObjectXml = objectGroup.ToXmlString();
2028 2029
2029 CachedUserInfo userInfo = 2030 CachedUserInfo userInfo =
@@ -2213,7 +2214,7 @@ namespace OpenSim.Region.Environment.Scenes
2213 2214
2214 Vector3 pos = GetNewRezLocation( 2215 Vector3 pos = GetNewRezLocation(
2215 RayStart, RayEnd, RayTargetID, Quaternion.Identity, 2216 RayStart, RayEnd, RayTargetID, Quaternion.Identity,
2216 BypassRayCast, bRayEndIsIntersection,true,scale, false); 2217 BypassRayCast, bRayEndIsIntersection, true, scale, false);
2217 2218
2218 // Rez object 2219 // Rez object
2219 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); 2220 CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
@@ -2235,20 +2236,20 @@ namespace OpenSim.Region.Environment.Scenes
2235 if (rezAsset != null) 2236 if (rezAsset != null)
2236 { 2237 {
2237 UUID itemId = UUID.Zero; 2238 UUID itemId = UUID.Zero;
2238 2239
2239 // If we have permission to copy then link the rezzed object back to the user inventory 2240 // If we have permission to copy then link the rezzed object back to the user inventory
2240 // item that it came from. This allows us to enable 'save object to inventory' 2241 // item that it came from. This allows us to enable 'save object to inventory'
2241 if (!Permissions.BypassPermissions()) 2242 if (!Permissions.BypassPermissions())
2242 { 2243 {
2243 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy) 2244 if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
2244 { 2245 {
2245 itemId = item.ID; 2246 itemId = item.ID;
2246 } 2247 }
2247 } 2248 }
2248 2249
2249 string xmlData = Utils.BytesToString(rezAsset.Data); 2250 string xmlData = Utils.BytesToString(rezAsset.Data);
2250 SceneObjectGroup group = new SceneObjectGroup(itemId, xmlData, true); 2251 SceneObjectGroup group = new SceneObjectGroup(itemId, xmlData, true);
2251 2252
2252 if (!Permissions.CanRezObject( 2253 if (!Permissions.CanRezObject(
2253 group.Children.Count, remoteClient.AgentId, pos) 2254 group.Children.Count, remoteClient.AgentId, pos)
2254 && !attachment) 2255 && !attachment)
@@ -2345,12 +2346,12 @@ namespace OpenSim.Region.Environment.Scenes
2345 group.ClearPartAttachmentData(); 2346 group.ClearPartAttachmentData();
2346 } 2347 }
2347 } 2348 }
2348 2349
2349 if (!attachment) 2350 if (!attachment)
2350 { 2351 {
2351 // Fire on_rez 2352 // Fire on_rez
2352 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0); 2353 group.CreateScriptInstances(0, true, DefaultScriptEngine, 0);
2353 2354
2354 rootPart.ScheduleFullUpdate(); 2355 rootPart.ScheduleFullUpdate();
2355 } 2356 }
2356 2357
@@ -2489,7 +2490,7 @@ namespace OpenSim.Region.Environment.Scenes
2489 DeRezObject(null, grp.RootPart.LocalId, 2490 DeRezObject(null, grp.RootPart.LocalId,
2490 grp.RootPart.GroupID, DeRezAction.Return, UUID.Zero); 2491 grp.RootPart.GroupID, DeRezAction.Return, UUID.Zero);
2491 } 2492 }
2492 2493
2493 return true; 2494 return true;
2494 } 2495 }
2495 2496
@@ -2621,7 +2622,7 @@ namespace OpenSim.Region.Environment.Scenes
2621 } 2622 }
2622 2623
2623 } 2624 }
2624 2625
2625 m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient); 2626 m_sceneGraph.DetachSingleAttachmentToInv(itemID, remoteClient);
2626 } 2627 }
2627 2628
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 3431309..61b16f4 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -63,7 +63,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
63 private IConfig m_ScriptConfig; 63 private IConfig m_ScriptConfig;
64 private ICompiler m_Compiler; 64 private ICompiler m_Compiler;
65 private int m_MinThreads; 65 private int m_MinThreads;
66 private int m_MaxThreads ; 66 private int m_MaxThreads;
67 private int m_IdleTimeout; 67 private int m_IdleTimeout;
68 private int m_StackSize; 68 private int m_StackSize;
69 private int m_SleepTime; 69 private int m_SleepTime;
@@ -72,8 +72,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
72 private bool m_Enabled = false; 72 private bool m_Enabled = false;
73 private bool m_InitialStartup = true; 73 private bool m_InitialStartup = true;
74 74
75// disable warning: need to keep a reference to XEngine.EventManager 75 // disable warning: need to keep a reference to XEngine.EventManager
76// alive to avoid it being garbage collected 76 // alive to avoid it being garbage collected
77#pragma warning disable 414 77#pragma warning disable 414
78 private EventManager m_EventManager; 78 private EventManager m_EventManager;
79#pragma warning restore 414 79#pragma warning restore 414
@@ -85,8 +85,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
85 85
86 // Maps the local id to the script inventory items in it 86 // Maps the local id to the script inventory items in it
87 87
88 private Dictionary<uint, List<UUID> > m_PrimObjects = 88 private Dictionary<uint, List<UUID>> m_PrimObjects =
89 new Dictionary<uint, List<UUID> >(); 89 new Dictionary<uint, List<UUID>>();
90 90
91 // Maps the UUID above to the script instance 91 // Maps the UUID above to the script instance
92 92
@@ -105,8 +105,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
105 105
106 // List the scripts running in each appdomain 106 // List the scripts running in each appdomain
107 107
108 private Dictionary<UUID, List<UUID> > m_DomainScripts = 108 private Dictionary<UUID, List<UUID>> m_DomainScripts =
109 new Dictionary<UUID, List<UUID> >(); 109 new Dictionary<UUID, List<UUID>>();
110 110
111 private Queue m_CompileQueue = new Queue(100); 111 private Queue m_CompileQueue = new Queue(100);
112 IWorkItemResult m_CurrentCompile = null; 112 IWorkItemResult m_CurrentCompile = null;
@@ -152,7 +152,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
152 152
153 if (m_ScriptConfig == null) 153 if (m_ScriptConfig == null)
154 { 154 {
155// m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled"); 155 // m_log.ErrorFormat("[XEngine] No script configuration found. Scripts disabled");
156 return; 156 return;
157 } 157 }
158 158
@@ -172,7 +172,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
172 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100); 172 m_MaxThreads = m_ScriptConfig.GetInt("MaxThreads", 100);
173 m_IdleTimeout = m_ScriptConfig.GetInt("IdleTimeout", 60); 173 m_IdleTimeout = m_ScriptConfig.GetInt("IdleTimeout", 60);
174 string priority = m_ScriptConfig.GetString("Priority", "BelowNormal"); 174 string priority = m_ScriptConfig.GetString("Priority", "BelowNormal");
175 m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300); 175 m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue", 300);
176 m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144); 176 m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144);
177 m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000; 177 m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000;
178 178
@@ -239,7 +239,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
239 if (m_SleepTime > 0) 239 if (m_SleepTime > 0)
240 { 240 {
241 m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), 241 m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance),
242 new Object[]{ m_SleepTime }); 242 new Object[] { m_SleepTime });
243 } 243 }
244 244
245 if (m_SaveTime > 0) 245 if (m_SaveTime > 0)
@@ -268,7 +268,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
268 if (saveTime > 0) 268 if (saveTime > 0)
269 System.Threading.Thread.Sleep(saveTime); 269 System.Threading.Thread.Sleep(saveTime);
270 270
271// m_log.Debug("[XEngine] Backing up script states"); 271 // m_log.Debug("[XEngine] Backing up script states");
272 272
273 List<IScriptInstance> instances = new List<IScriptInstance>(); 273 List<IScriptInstance> instances = new List<IScriptInstance>();
274 274
@@ -319,7 +319,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
319 System.Threading.Thread.Sleep(sleepTime); 319 System.Threading.Thread.Sleep(sleepTime);
320 320
321 m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance), 321 m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoMaintenance),
322 new Object[]{ sleepTime }); 322 new Object[] { sleepTime });
323 323
324 return 0; 324 return 0;
325 } 325 }
@@ -351,12 +351,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
351 int colon = firstline.IndexOf(':'); 351 int colon = firstline.IndexOf(':');
352 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1) 352 if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1)
353 { 353 {
354 string engineName = firstline.Substring(2, colon-2); 354 string engineName = firstline.Substring(2, colon - 2);
355 355
356 if (names.Contains(engineName)) 356 if (names.Contains(engineName))
357 { 357 {
358 engine = engineName; 358 engine = engineName;
359 script = "//" + script.Substring(script.IndexOf(':')+1); 359 script = "//" + script.Substring(script.IndexOf(':') + 1);
360 } 360 }
361 else 361 else
362 { 362 {
@@ -365,21 +365,21 @@ namespace OpenSim.Region.ScriptEngine.XEngine
365 SceneObjectPart part = 365 SceneObjectPart part =
366 m_Scene.GetSceneObjectPart( 366 m_Scene.GetSceneObjectPart(
367 localID); 367 localID);
368 368
369 TaskInventoryItem item = 369 TaskInventoryItem item =
370 part.Inventory.GetInventoryItem(itemID); 370 part.Inventory.GetInventoryItem(itemID);
371 371
372 ScenePresence presence = 372 ScenePresence presence =
373 m_Scene.GetScenePresence( 373 m_Scene.GetScenePresence(
374 item.OwnerID); 374 item.OwnerID);
375 375
376 if (presence != null) 376 if (presence != null)
377 { 377 {
378 presence.ControllingClient.SendAgentAlertMessage( 378 presence.ControllingClient.SendAgentAlertMessage(
379 "Selected engine unavailable. "+ 379 "Selected engine unavailable. " +
380 "Running script on "+ 380 "Running script on " +
381 ScriptEngineName, 381 ScriptEngineName,
382 false); 382 false);
383 } 383 }
384 } 384 }
385 } 385 }
@@ -389,7 +389,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
389 if (engine != ScriptEngineName) 389 if (engine != ScriptEngineName)
390 return; 390 return;
391 391
392 Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez, (StateSource)stateSource}; 392 Object[] parms = new Object[] { localID, itemID, script, startParam, postOnRez, (StateSource)stateSource };
393 393
394 if (stateSource == (int)StateSource.ScriptedRez) 394 if (stateSource == (int)StateSource.ScriptedRez)
395 { 395 {
@@ -453,7 +453,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
453 Object[] p = (Object[])parm; 453 Object[] p = (Object[])parm;
454 uint localID = (uint)p[0]; 454 uint localID = (uint)p[0];
455 UUID itemID = (UUID)p[1]; 455 UUID itemID = (UUID)p[1];
456 string script =(string)p[2]; 456 string script = (string)p[2];
457 int startParam = (int)p[3]; 457 int startParam = (int)p[3];
458 bool postOnRez = (bool)p[4]; 458 bool postOnRez = (bool)p[4];
459 StateSource stateSource = (StateSource)p[5]; 459 StateSource stateSource = (StateSource)p[5];
@@ -469,7 +469,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
469 { 469 {
470 Log.Error("[Script] SceneObjectPart unavailable. Script NOT started."); 470 Log.Error("[Script] SceneObjectPart unavailable. Script NOT started.");
471 return false; 471 return false;
472 } 472 }
473 473
474 TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID); 474 TaskInventoryItem item = part.Inventory.GetInventoryItem(itemID);
475 if (item == null) 475 if (item == null)
@@ -477,8 +477,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
477 477
478 UUID assetID = item.AssetID; 478 UUID assetID = item.AssetID;
479 479
480// m_log.DebugFormat("[XEngine] Compiling script {0} ({1})", 480 // m_log.DebugFormat("[XEngine] Compiling script {0} ({1})",
481// item.Name, itemID.ToString()); 481 // item.Name, itemID.ToString());
482 482
483 ScenePresence presence = m_Scene.GetScenePresence(item.OwnerID); 483 ScenePresence presence = m_Scene.GetScenePresence(item.OwnerID);
484 484
@@ -509,7 +509,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
509 } 509 }
510 catch (Exception e2) // LEGIT: User Scripting 510 catch (Exception e2) // LEGIT: User Scripting
511 { 511 {
512 m_log.Error("[XEngine]: "+ 512 m_log.Error("[XEngine]: " +
513 "Error displaying error in-world: " + 513 "Error displaying error in-world: " +
514 e2.ToString()); 514 e2.ToString());
515 m_log.Error("[XEngine]: " + 515 m_log.Error("[XEngine]: " +
@@ -537,27 +537,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
537 try 537 try
538 { 538 {
539 AppDomainSetup appSetup = new AppDomainSetup(); 539 AppDomainSetup appSetup = new AppDomainSetup();
540// appSetup.ApplicationBase = Path.Combine( 540 // appSetup.ApplicationBase = Path.Combine(
541// "ScriptEngines", 541 // "ScriptEngines",
542// m_Scene.RegionInfo.RegionID.ToString()); 542 // m_Scene.RegionInfo.RegionID.ToString());
543 543
544 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 544 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
545 Evidence evidence = new Evidence(baseEvidence); 545 Evidence evidence = new Evidence(baseEvidence);
546 546
547 AppDomain sandbox = 547 m_AppDomains[appDomain] =
548 AppDomain.CreateDomain( 548 AppDomain.CreateDomain(
549 m_Scene.RegionInfo.RegionID.ToString(), 549 m_Scene.RegionInfo.RegionID.ToString(),
550 evidence, appSetup); 550 evidence, appSetup);
551
552 PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
553 AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
554 PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
555 PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
556 CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
557 sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
558 sandbox.SetAppDomainPolicy(sandboxPolicy);
559
560 m_AppDomains[appDomain] = sandbox;
561 551
562 m_AppDomains[appDomain].AssemblyResolve += 552 m_AppDomains[appDomain].AssemblyResolve +=
563 new ResolveEventHandler( 553 new ResolveEventHandler(
@@ -613,7 +603,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
613 if (!m_Scripts.ContainsKey(itemID)) 603 if (!m_Scripts.ContainsKey(itemID))
614 return; 604 return;
615 605
616 IScriptInstance instance=m_Scripts[itemID]; 606 IScriptInstance instance = m_Scripts[itemID];
617 m_Scripts.Remove(itemID); 607 m_Scripts.Remove(itemID);
618 608
619 instance.ClearQueue(); 609 instance.ClearQueue();
@@ -685,17 +675,17 @@ namespace OpenSim.Region.ScriptEngine.XEngine
685 675
686 foreach (UUID assetID in assetIDList) 676 foreach (UUID assetID in assetIDList)
687 { 677 {
688// m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]); 678 // m_log.DebugFormat("[XEngine] Removing unreferenced assembly {0}", m_Assemblies[assetID]);
689 try 679 try
690 { 680 {
691 if (File.Exists(m_Assemblies[assetID])) 681 if (File.Exists(m_Assemblies[assetID]))
692 File.Delete(m_Assemblies[assetID]); 682 File.Delete(m_Assemblies[assetID]);
693 683
694 if (File.Exists(m_Assemblies[assetID]+".state")) 684 if (File.Exists(m_Assemblies[assetID] + ".state"))
695 File.Delete(m_Assemblies[assetID]+".state"); 685 File.Delete(m_Assemblies[assetID] + ".state");
696 686
697 if (File.Exists(m_Assemblies[assetID]+".mdb")) 687 if (File.Exists(m_Assemblies[assetID] + ".mdb"))
698 File.Delete(m_Assemblies[assetID]+".mdb"); 688 File.Delete(m_Assemblies[assetID] + ".mdb");
699 } 689 }
700 catch (Exception) 690 catch (Exception)
701 { 691 {
@@ -713,7 +703,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
713 703
714 AppDomain.Unload(domain); 704 AppDomain.Unload(domain);
715 domain = null; 705 domain = null;
716// m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString()); 706 // m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString());
717 } 707 }
718 } 708 }
719 709
@@ -745,8 +735,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
745 return new XWorkItem(m_ThreadPool.QueueWorkItem( 735 return new XWorkItem(m_ThreadPool.QueueWorkItem(
746 new WorkItemCallback(this.ProcessEventHandler), 736 new WorkItemCallback(this.ProcessEventHandler),
747 parms)); 737 parms));
748 } 738 }
749 739
750 /// <summary> 740 /// <summary>
751 /// Process a previously posted script event. 741 /// Process a previously posted script event.
752 /// </summary> 742 /// </summary>
@@ -757,8 +747,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
757 CultureInfo USCulture = new CultureInfo("en-US"); 747 CultureInfo USCulture = new CultureInfo("en-US");
758 Thread.CurrentThread.CurrentCulture = USCulture; 748 Thread.CurrentThread.CurrentCulture = USCulture;
759 749
760 IScriptInstance instance = (ScriptInstance) parms; 750 IScriptInstance instance = (ScriptInstance)parms;
761 751
762 //m_log.DebugFormat("[XENGINE]: Processing event for {0}", instance); 752 //m_log.DebugFormat("[XENGINE]: Processing event for {0}", instance);
763 753
764 return instance.EventProcessor(); 754 return instance.EventProcessor();
@@ -773,13 +763,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
773 public bool PostObjectEvent(uint localID, EventParams p) 763 public bool PostObjectEvent(uint localID, EventParams p)
774 { 764 {
775 bool result = false; 765 bool result = false;
776 766
777 lock (m_PrimObjects) 767 lock (m_PrimObjects)
778 { 768 {
779 if (!m_PrimObjects.ContainsKey(localID)) 769 if (!m_PrimObjects.ContainsKey(localID))
780 return false; 770 return false;
781 771
782 772
783 foreach (UUID itemID in m_PrimObjects[localID]) 773 foreach (UUID itemID in m_PrimObjects[localID])
784 { 774 {
785 if (m_Scripts.ContainsKey(itemID)) 775 if (m_Scripts.ContainsKey(itemID))
@@ -831,7 +821,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
831 foreach (string s in pathList) 821 foreach (string s in pathList)
832 { 822 {
833 string path = Path.Combine(Directory.GetCurrentDirectory(), 823 string path = Path.Combine(Directory.GetCurrentDirectory(),
834 Path.Combine(s, assemblyName))+".dll"; 824 Path.Combine(s, assemblyName)) + ".dll";
835 825
836 if (File.Exists(path)) 826 if (File.Exists(path))
837 return Assembly.LoadFrom(path); 827 return Assembly.LoadFrom(path);
@@ -969,7 +959,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
969 i.Running = prevRunning; 959 i.Running = prevRunning;
970 } 960 }
971 961
972 DoBackup(new Object[] {0}); 962 DoBackup(new Object[] { 0 });
973 } 963 }
974 964
975 public IScriptApi GetApi(UUID itemID, string name) 965 public IScriptApi GetApi(UUID itemID, string name)