diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | 813 |
1 files changed, 517 insertions, 296 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index ec39726..5811ed9 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | |||
@@ -46,9 +46,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
46 | { | 46 | { |
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
48 | 48 | ||
49 | private string m_inventoryFileName = String.Empty; | ||
50 | private byte[] m_inventoryFileData = new byte[0]; | 49 | private byte[] m_inventoryFileData = new byte[0]; |
51 | private uint m_inventoryFileNameSerial = 0; | 50 | private uint m_inventoryFileNameSerial = 0; |
51 | private bool m_inventoryPrivileged = false; | ||
52 | private object m_inventoryFileLock = new object(); | ||
53 | |||
54 | private Dictionary<UUID, ArrayList> m_scriptErrors = new Dictionary<UUID, ArrayList>(); | ||
52 | 55 | ||
53 | /// <value> | 56 | /// <value> |
54 | /// The part to which the inventory belongs. | 57 | /// The part to which the inventory belongs. |
@@ -85,7 +88,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
85 | /// </value> | 88 | /// </value> |
86 | protected internal TaskInventoryDictionary Items | 89 | protected internal TaskInventoryDictionary Items |
87 | { | 90 | { |
88 | get { return m_items; } | 91 | get { |
92 | return m_items; | ||
93 | } | ||
89 | set | 94 | set |
90 | { | 95 | { |
91 | m_items = value; | 96 | m_items = value; |
@@ -134,38 +139,45 @@ namespace OpenSim.Region.Framework.Scenes | |||
134 | public void ResetInventoryIDs() | 139 | public void ResetInventoryIDs() |
135 | { | 140 | { |
136 | if (null == m_part) | 141 | if (null == m_part) |
137 | return; | 142 | m_items.LockItemsForWrite(true); |
138 | 143 | ||
139 | lock (m_items) | 144 | if (Items.Count == 0) |
140 | { | 145 | { |
141 | if (0 == m_items.Count) | 146 | m_items.LockItemsForWrite(false); |
142 | return; | 147 | return; |
148 | } | ||
143 | 149 | ||
144 | IList<TaskInventoryItem> items = GetInventoryItems(); | 150 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
145 | m_items.Clear(); | 151 | Items.Clear(); |
146 | 152 | ||
147 | foreach (TaskInventoryItem item in items) | 153 | foreach (TaskInventoryItem item in items) |
148 | { | 154 | { |
149 | item.ResetIDs(m_part.UUID); | 155 | item.ResetIDs(m_part.UUID); |
150 | m_items.Add(item.ItemID, item); | 156 | Items.Add(item.ItemID, item); |
151 | } | ||
152 | } | 157 | } |
158 | m_items.LockItemsForWrite(false); | ||
153 | } | 159 | } |
154 | 160 | ||
155 | public void ResetObjectID() | 161 | public void ResetObjectID() |
156 | { | 162 | { |
157 | lock (Items) | 163 | m_items.LockItemsForWrite(true); |
164 | |||
165 | if (Items.Count == 0) | ||
158 | { | 166 | { |
159 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); | 167 | m_items.LockItemsForWrite(false); |
160 | Items.Clear(); | 168 | return; |
161 | |||
162 | foreach (TaskInventoryItem item in items) | ||
163 | { | ||
164 | item.ParentPartID = m_part.UUID; | ||
165 | item.ParentID = m_part.UUID; | ||
166 | Items.Add(item.ItemID, item); | ||
167 | } | ||
168 | } | 169 | } |
170 | |||
171 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); | ||
172 | Items.Clear(); | ||
173 | |||
174 | foreach (TaskInventoryItem item in items) | ||
175 | { | ||
176 | item.ParentPartID = m_part.UUID; | ||
177 | item.ParentID = m_part.UUID; | ||
178 | Items.Add(item.ItemID, item); | ||
179 | } | ||
180 | m_items.LockItemsForWrite(false); | ||
169 | } | 181 | } |
170 | 182 | ||
171 | /// <summary> | 183 | /// <summary> |
@@ -174,17 +186,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
174 | /// <param name="ownerId"></param> | 186 | /// <param name="ownerId"></param> |
175 | public void ChangeInventoryOwner(UUID ownerId) | 187 | public void ChangeInventoryOwner(UUID ownerId) |
176 | { | 188 | { |
177 | lock (Items) | 189 | List<TaskInventoryItem> items = GetInventoryItems(); |
178 | { | ||
179 | if (0 == Items.Count) | ||
180 | { | ||
181 | return; | ||
182 | } | ||
183 | } | ||
184 | 190 | ||
191 | if (items.Count == 0) | ||
192 | return; | ||
193 | |||
194 | m_items.LockItemsForWrite(true); | ||
185 | HasInventoryChanged = true; | 195 | HasInventoryChanged = true; |
186 | m_part.ParentGroup.HasGroupChanged = true; | 196 | m_part.ParentGroup.HasGroupChanged = true; |
187 | List<TaskInventoryItem> items = GetInventoryItems(); | ||
188 | foreach (TaskInventoryItem item in items) | 197 | foreach (TaskInventoryItem item in items) |
189 | { | 198 | { |
190 | if (ownerId != item.OwnerID) | 199 | if (ownerId != item.OwnerID) |
@@ -195,6 +204,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
195 | item.PermsGranter = UUID.Zero; | 204 | item.PermsGranter = UUID.Zero; |
196 | item.OwnerChanged = true; | 205 | item.OwnerChanged = true; |
197 | } | 206 | } |
207 | m_items.LockItemsForWrite(false); | ||
198 | } | 208 | } |
199 | 209 | ||
200 | /// <summary> | 210 | /// <summary> |
@@ -203,12 +213,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
203 | /// <param name="groupID"></param> | 213 | /// <param name="groupID"></param> |
204 | public void ChangeInventoryGroup(UUID groupID) | 214 | public void ChangeInventoryGroup(UUID groupID) |
205 | { | 215 | { |
206 | lock (Items) | 216 | m_items.LockItemsForWrite(true); |
217 | if (0 == Items.Count) | ||
207 | { | 218 | { |
208 | if (0 == Items.Count) | 219 | m_items.LockItemsForWrite(false); |
209 | { | 220 | return; |
210 | return; | ||
211 | } | ||
212 | } | 221 | } |
213 | 222 | ||
214 | // Don't let this set the HasGroupChanged flag for attachments | 223 | // Don't let this set the HasGroupChanged flag for attachments |
@@ -220,12 +229,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
220 | m_part.ParentGroup.HasGroupChanged = true; | 229 | m_part.ParentGroup.HasGroupChanged = true; |
221 | } | 230 | } |
222 | 231 | ||
223 | List<TaskInventoryItem> items = GetInventoryItems(); | 232 | IList<TaskInventoryItem> items = new List<TaskInventoryItem>(Items.Values); |
224 | foreach (TaskInventoryItem item in items) | 233 | foreach (TaskInventoryItem item in items) |
225 | { | 234 | { |
226 | if (groupID != item.GroupID) | 235 | if (groupID != item.GroupID) |
236 | { | ||
227 | item.GroupID = groupID; | 237 | item.GroupID = groupID; |
238 | } | ||
228 | } | 239 | } |
240 | m_items.LockItemsForWrite(false); | ||
229 | } | 241 | } |
230 | 242 | ||
231 | private void QueryScriptStates() | 243 | private void QueryScriptStates() |
@@ -233,15 +245,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
233 | if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null) | 245 | if (m_part == null || m_part.ParentGroup == null || m_part.ParentGroup.Scene == null) |
234 | return; | 246 | return; |
235 | 247 | ||
236 | lock (Items) | 248 | Items.LockItemsForRead(true); |
249 | foreach (TaskInventoryItem item in Items.Values) | ||
237 | { | 250 | { |
238 | foreach (TaskInventoryItem item in Items.Values) | 251 | if (item.InvType == (int)InventoryType.LSL) |
239 | { | 252 | { |
240 | bool running; | 253 | bool running; |
241 | if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running)) | 254 | if (TryGetScriptInstanceRunning(m_part.ParentGroup.Scene, item, out running)) |
242 | item.ScriptRunning = running; | 255 | item.ScriptRunning = running; |
243 | } | 256 | } |
244 | } | 257 | } |
258 | |||
259 | Items.LockItemsForRead(false); | ||
245 | } | 260 | } |
246 | 261 | ||
247 | public bool TryGetScriptInstanceRunning(UUID itemId, out bool running) | 262 | public bool TryGetScriptInstanceRunning(UUID itemId, out bool running) |
@@ -318,7 +333,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
318 | { | 333 | { |
319 | List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL); | 334 | List<TaskInventoryItem> scripts = GetInventoryItems(InventoryType.LSL); |
320 | foreach (TaskInventoryItem item in scripts) | 335 | foreach (TaskInventoryItem item in scripts) |
336 | { | ||
321 | RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); | 337 | RemoveScriptInstance(item.ItemID, sceneObjectBeingDeleted); |
338 | m_part.RemoveScriptEvents(item.ItemID); | ||
339 | } | ||
322 | } | 340 | } |
323 | 341 | ||
324 | /// <summary> | 342 | /// <summary> |
@@ -340,7 +358,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
340 | // item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 358 | // item.Name, item.ItemID, m_part.Name, m_part.UUID, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
341 | 359 | ||
342 | if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) | 360 | if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID)) |
361 | { | ||
362 | StoreScriptError(item.ItemID, "no permission"); | ||
343 | return false; | 363 | return false; |
364 | } | ||
344 | 365 | ||
345 | m_part.AddFlag(PrimFlags.Scripted); | 366 | m_part.AddFlag(PrimFlags.Scripted); |
346 | 367 | ||
@@ -350,14 +371,13 @@ namespace OpenSim.Region.Framework.Scenes | |||
350 | if (stateSource == 2 && // Prim crossing | 371 | if (stateSource == 2 && // Prim crossing |
351 | m_part.ParentGroup.Scene.m_trustBinaries) | 372 | m_part.ParentGroup.Scene.m_trustBinaries) |
352 | { | 373 | { |
353 | lock (m_items) | 374 | m_items.LockItemsForWrite(true); |
354 | { | 375 | m_items[item.ItemID].PermsMask = 0; |
355 | m_items[item.ItemID].PermsMask = 0; | 376 | m_items[item.ItemID].PermsGranter = UUID.Zero; |
356 | m_items[item.ItemID].PermsGranter = UUID.Zero; | 377 | m_items.LockItemsForWrite(false); |
357 | } | ||
358 | |||
359 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( | 378 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( |
360 | m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); | 379 | m_part.LocalId, item.ItemID, String.Empty, startParam, postOnRez, engine, stateSource); |
380 | StoreScriptErrors(item.ItemID, null); | ||
361 | m_part.ParentGroup.AddActiveScriptCount(1); | 381 | m_part.ParentGroup.AddActiveScriptCount(1); |
362 | m_part.ScheduleFullUpdate(); | 382 | m_part.ScheduleFullUpdate(); |
363 | return true; | 383 | return true; |
@@ -366,6 +386,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
366 | AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); | 386 | AssetBase asset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); |
367 | if (null == asset) | 387 | if (null == asset) |
368 | { | 388 | { |
389 | string msg = String.Format("asset ID {0} could not be found", item.AssetID); | ||
390 | StoreScriptError(item.ItemID, msg); | ||
369 | m_log.ErrorFormat( | 391 | m_log.ErrorFormat( |
370 | "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", | 392 | "[PRIM INVENTORY]: Couldn't start script {0}, {1} at {2} in {3} since asset ID {4} could not be found", |
371 | item.Name, item.ItemID, m_part.AbsolutePosition, | 393 | item.Name, item.ItemID, m_part.AbsolutePosition, |
@@ -378,16 +400,18 @@ namespace OpenSim.Region.Framework.Scenes | |||
378 | if (m_part.ParentGroup.m_savedScriptState != null) | 400 | if (m_part.ParentGroup.m_savedScriptState != null) |
379 | item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID); | 401 | item.OldItemID = RestoreSavedScriptState(item.LoadedItemID, item.OldItemID, item.ItemID); |
380 | 402 | ||
381 | lock (m_items) | 403 | m_items.LockItemsForWrite(true); |
382 | { | ||
383 | m_items[item.ItemID].OldItemID = item.OldItemID; | ||
384 | m_items[item.ItemID].PermsMask = 0; | ||
385 | m_items[item.ItemID].PermsGranter = UUID.Zero; | ||
386 | } | ||
387 | 404 | ||
405 | m_items[item.ItemID].OldItemID = item.OldItemID; | ||
406 | m_items[item.ItemID].PermsMask = 0; | ||
407 | m_items[item.ItemID].PermsGranter = UUID.Zero; | ||
408 | |||
409 | m_items.LockItemsForWrite(false); | ||
410 | |||
388 | string script = Utils.BytesToString(asset.Data); | 411 | string script = Utils.BytesToString(asset.Data); |
389 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( | 412 | m_part.ParentGroup.Scene.EventManager.TriggerRezScript( |
390 | m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); | 413 | m_part.LocalId, item.ItemID, script, startParam, postOnRez, engine, stateSource); |
414 | StoreScriptErrors(item.ItemID, null); | ||
391 | if (!item.ScriptRunning) | 415 | if (!item.ScriptRunning) |
392 | m_part.ParentGroup.Scene.EventManager.TriggerStopScript( | 416 | m_part.ParentGroup.Scene.EventManager.TriggerStopScript( |
393 | m_part.LocalId, item.ItemID); | 417 | m_part.LocalId, item.ItemID); |
@@ -466,22 +490,138 @@ namespace OpenSim.Region.Framework.Scenes | |||
466 | return stateID; | 490 | return stateID; |
467 | } | 491 | } |
468 | 492 | ||
493 | /// <summary> | ||
494 | /// Start a script which is in this prim's inventory. | ||
495 | /// Some processing may occur in the background, but this routine returns asap. | ||
496 | /// </summary> | ||
497 | /// <param name="itemId"> | ||
498 | /// A <see cref="UUID"/> | ||
499 | /// </param> | ||
469 | public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | 500 | public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) |
470 | { | 501 | { |
471 | TaskInventoryItem item = GetInventoryItem(itemId); | 502 | lock (m_scriptErrors) |
472 | if (item != null) | 503 | { |
504 | // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion | ||
505 | m_scriptErrors.Remove(itemId); | ||
506 | } | ||
507 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
508 | return true; | ||
509 | } | ||
510 | |||
511 | private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
512 | { | ||
513 | m_items.LockItemsForRead(true); | ||
514 | |||
515 | if (m_items.ContainsKey(itemId)) | ||
473 | { | 516 | { |
474 | return CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); | 517 | TaskInventoryItem it = m_items[itemId]; |
518 | m_items.LockItemsForRead(false); | ||
519 | |||
520 | CreateScriptInstance(it, startParam, postOnRez, engine, stateSource); | ||
475 | } | 521 | } |
476 | else | 522 | else |
477 | { | 523 | { |
478 | m_log.ErrorFormat( | 524 | m_items.LockItemsForRead(false); |
479 | "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", | 525 | string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID, |
480 | itemId, m_part.Name, m_part.UUID, | ||
481 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 526 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
527 | StoreScriptError(itemId, msg); | ||
528 | m_log.ErrorFormat( | ||
529 | "[PRIM INVENTORY]: " + | ||
530 | "Couldn't start script with ID {0} since it {1}", itemId, msg); | ||
531 | } | ||
532 | } | ||
482 | 533 | ||
483 | return false; | 534 | /// <summary> |
535 | /// Start a script which is in this prim's inventory and return any compilation error messages. | ||
536 | /// </summary> | ||
537 | /// <param name="itemId"> | ||
538 | /// A <see cref="UUID"/> | ||
539 | /// </param> | ||
540 | public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
541 | { | ||
542 | ArrayList errors; | ||
543 | |||
544 | // Indicate to CreateScriptInstanceInternal() we want it to | ||
545 | // post any compilation/loading error messages | ||
546 | lock (m_scriptErrors) | ||
547 | { | ||
548 | m_scriptErrors[itemId] = null; | ||
484 | } | 549 | } |
550 | |||
551 | // Perform compilation/loading | ||
552 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
553 | |||
554 | // Wait for and retrieve any errors | ||
555 | lock (m_scriptErrors) | ||
556 | { | ||
557 | while ((errors = m_scriptErrors[itemId]) == null) | ||
558 | { | ||
559 | if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000)) | ||
560 | { | ||
561 | m_log.ErrorFormat( | ||
562 | "[PRIM INVENTORY]: " + | ||
563 | "timedout waiting for script {0} errors", itemId); | ||
564 | errors = m_scriptErrors[itemId]; | ||
565 | if (errors == null) | ||
566 | { | ||
567 | errors = new ArrayList(1); | ||
568 | errors.Add("timedout waiting for errors"); | ||
569 | } | ||
570 | break; | ||
571 | } | ||
572 | } | ||
573 | m_scriptErrors.Remove(itemId); | ||
574 | } | ||
575 | return errors; | ||
576 | } | ||
577 | |||
578 | // Signal to CreateScriptInstanceEr() that compilation/loading is complete | ||
579 | private void StoreScriptErrors(UUID itemId, ArrayList errors) | ||
580 | { | ||
581 | lock (m_scriptErrors) | ||
582 | { | ||
583 | // If compilation/loading initiated via CreateScriptInstance(), | ||
584 | // it does not want the errors, so just get out | ||
585 | if (!m_scriptErrors.ContainsKey(itemId)) | ||
586 | { | ||
587 | return; | ||
588 | } | ||
589 | |||
590 | // Initiated via CreateScriptInstanceEr(), if we know what the | ||
591 | // errors are, save them and wake CreateScriptInstanceEr(). | ||
592 | if (errors != null) | ||
593 | { | ||
594 | m_scriptErrors[itemId] = errors; | ||
595 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
596 | return; | ||
597 | } | ||
598 | } | ||
599 | |||
600 | // Initiated via CreateScriptInstanceEr() but we don't know what | ||
601 | // the errors are yet, so retrieve them from the script engine. | ||
602 | // This may involve some waiting internal to GetScriptErrors(). | ||
603 | errors = GetScriptErrors(itemId); | ||
604 | |||
605 | // Get a default non-null value to indicate success. | ||
606 | if (errors == null) | ||
607 | { | ||
608 | errors = new ArrayList(); | ||
609 | } | ||
610 | |||
611 | // Post to CreateScriptInstanceEr() and wake it up | ||
612 | lock (m_scriptErrors) | ||
613 | { | ||
614 | m_scriptErrors[itemId] = errors; | ||
615 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
616 | } | ||
617 | } | ||
618 | |||
619 | // Like StoreScriptErrors(), but just posts a single string message | ||
620 | private void StoreScriptError(UUID itemId, string message) | ||
621 | { | ||
622 | ArrayList errors = new ArrayList(1); | ||
623 | errors.Add(message); | ||
624 | StoreScriptErrors(itemId, errors); | ||
485 | } | 625 | } |
486 | 626 | ||
487 | /// <summary> | 627 | /// <summary> |
@@ -494,15 +634,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
494 | /// </param> | 634 | /// </param> |
495 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) | 635 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) |
496 | { | 636 | { |
497 | bool scriptPresent = false; | 637 | if (m_items.ContainsKey(itemId)) |
498 | |||
499 | lock (m_items) | ||
500 | { | ||
501 | if (m_items.ContainsKey(itemId)) | ||
502 | scriptPresent = true; | ||
503 | } | ||
504 | |||
505 | if (scriptPresent) | ||
506 | { | 638 | { |
507 | if (!sceneObjectBeingDeleted) | 639 | if (!sceneObjectBeingDeleted) |
508 | m_part.RemoveScriptEvents(itemId); | 640 | m_part.RemoveScriptEvents(itemId); |
@@ -573,14 +705,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
573 | /// <returns></returns> | 705 | /// <returns></returns> |
574 | private bool InventoryContainsName(string name) | 706 | private bool InventoryContainsName(string name) |
575 | { | 707 | { |
576 | lock (m_items) | 708 | m_items.LockItemsForRead(true); |
709 | foreach (TaskInventoryItem item in m_items.Values) | ||
577 | { | 710 | { |
578 | foreach (TaskInventoryItem item in m_items.Values) | 711 | if (item.Name == name) |
579 | { | 712 | { |
580 | if (item.Name == name) | 713 | m_items.LockItemsForRead(false); |
581 | return true; | 714 | return true; |
582 | } | 715 | } |
583 | } | 716 | } |
717 | m_items.LockItemsForRead(false); | ||
584 | return false; | 718 | return false; |
585 | } | 719 | } |
586 | 720 | ||
@@ -622,8 +756,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
622 | /// <param name="item"></param> | 756 | /// <param name="item"></param> |
623 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) | 757 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) |
624 | { | 758 | { |
625 | List<TaskInventoryItem> il = GetInventoryItems(); | 759 | m_items.LockItemsForRead(true); |
626 | 760 | List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values); | |
761 | m_items.LockItemsForRead(false); | ||
627 | foreach (TaskInventoryItem i in il) | 762 | foreach (TaskInventoryItem i in il) |
628 | { | 763 | { |
629 | if (i.Name == item.Name) | 764 | if (i.Name == item.Name) |
@@ -661,14 +796,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
661 | item.Name = name; | 796 | item.Name = name; |
662 | item.GroupID = m_part.GroupID; | 797 | item.GroupID = m_part.GroupID; |
663 | 798 | ||
664 | lock (m_items) | 799 | m_items.LockItemsForWrite(true); |
665 | m_items.Add(item.ItemID, item); | 800 | m_items.Add(item.ItemID, item); |
666 | 801 | m_items.LockItemsForWrite(false); | |
667 | if (allowedDrop) | 802 | if (allowedDrop) |
668 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); | 803 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); |
669 | else | 804 | else |
670 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 805 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
671 | 806 | ||
672 | m_inventorySerial++; | 807 | m_inventorySerial++; |
673 | //m_inventorySerial += 2; | 808 | //m_inventorySerial += 2; |
674 | HasInventoryChanged = true; | 809 | HasInventoryChanged = true; |
@@ -684,15 +819,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
684 | /// <param name="items"></param> | 819 | /// <param name="items"></param> |
685 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) | 820 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) |
686 | { | 821 | { |
687 | lock (m_items) | 822 | m_items.LockItemsForWrite(true); |
823 | foreach (TaskInventoryItem item in items) | ||
688 | { | 824 | { |
689 | foreach (TaskInventoryItem item in items) | 825 | m_items.Add(item.ItemID, item); |
690 | { | 826 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
691 | m_items.Add(item.ItemID, item); | ||
692 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | ||
693 | } | ||
694 | m_inventorySerial++; | ||
695 | } | 827 | } |
828 | m_items.LockItemsForWrite(false); | ||
829 | |||
830 | m_inventorySerial++; | ||
696 | } | 831 | } |
697 | 832 | ||
698 | /// <summary> | 833 | /// <summary> |
@@ -703,23 +838,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
703 | public TaskInventoryItem GetInventoryItem(UUID itemId) | 838 | public TaskInventoryItem GetInventoryItem(UUID itemId) |
704 | { | 839 | { |
705 | TaskInventoryItem item; | 840 | TaskInventoryItem item; |
706 | 841 | m_items.LockItemsForRead(true); | |
707 | lock (m_items) | 842 | m_items.TryGetValue(itemId, out item); |
708 | m_items.TryGetValue(itemId, out item); | 843 | m_items.LockItemsForRead(false); |
709 | |||
710 | return item; | 844 | return item; |
711 | } | 845 | } |
712 | 846 | ||
713 | public TaskInventoryItem GetInventoryItem(string name) | 847 | public TaskInventoryItem GetInventoryItem(string name) |
714 | { | 848 | { |
715 | lock (m_items) | 849 | m_items.LockItemsForRead(true); |
850 | foreach (TaskInventoryItem item in m_items.Values) | ||
716 | { | 851 | { |
717 | foreach (TaskInventoryItem item in m_items.Values) | 852 | if (item.Name == name) |
718 | { | 853 | { |
719 | if (item.Name == name) | 854 | m_items.LockItemsForRead(false); |
720 | return item; | 855 | return item; |
721 | } | 856 | } |
722 | } | 857 | } |
858 | m_items.LockItemsForRead(false); | ||
723 | 859 | ||
724 | return null; | 860 | return null; |
725 | } | 861 | } |
@@ -728,19 +864,20 @@ namespace OpenSim.Region.Framework.Scenes | |||
728 | { | 864 | { |
729 | List<TaskInventoryItem> items = new List<TaskInventoryItem>(); | 865 | List<TaskInventoryItem> items = new List<TaskInventoryItem>(); |
730 | 866 | ||
731 | lock (m_items) | 867 | m_items.LockItemsForRead(true); |
868 | |||
869 | foreach (TaskInventoryItem item in m_items.Values) | ||
732 | { | 870 | { |
733 | foreach (TaskInventoryItem item in m_items.Values) | 871 | if (item.Name == name) |
734 | { | 872 | items.Add(item); |
735 | if (item.Name == name) | ||
736 | items.Add(item); | ||
737 | } | ||
738 | } | 873 | } |
739 | 874 | ||
875 | m_items.LockItemsForRead(false); | ||
876 | |||
740 | return items; | 877 | return items; |
741 | } | 878 | } |
742 | 879 | ||
743 | public bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist) | 880 | public bool GetRezReadySceneObjects(TaskInventoryItem item, out List<SceneObjectGroup> objlist, out List<Vector3> veclist, out Vector3 bbox, out float offsetHeight) |
744 | { | 881 | { |
745 | AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); | 882 | AssetBase rezAsset = m_part.ParentGroup.Scene.AssetService.Get(item.AssetID.ToString()); |
746 | 883 | ||
@@ -751,18 +888,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
751 | item.AssetID, item.Name, m_part.Name); | 888 | item.AssetID, item.Name, m_part.Name); |
752 | objlist = null; | 889 | objlist = null; |
753 | veclist = null; | 890 | veclist = null; |
891 | bbox = Vector3.Zero; | ||
892 | offsetHeight = 0; | ||
754 | return false; | 893 | return false; |
755 | } | 894 | } |
756 | 895 | ||
757 | Vector3 bbox; | 896 | bool single = m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); |
758 | float offsetHeight; | ||
759 | |||
760 | m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); | ||
761 | 897 | ||
762 | for (int i = 0; i < objlist.Count; i++) | 898 | for (int i = 0; i < objlist.Count; i++) |
763 | { | 899 | { |
764 | SceneObjectGroup group = objlist[i]; | 900 | SceneObjectGroup group = objlist[i]; |
765 | 901 | /* | |
902 | group.RootPart.AttachPoint = group.RootPart.Shape.State; | ||
903 | group.RootPart.AttachedPos = group.AbsolutePosition; | ||
904 | group.RootPart.AttachRotation = group.GroupRotation; | ||
905 | */ | ||
766 | group.ResetIDs(); | 906 | group.ResetIDs(); |
767 | 907 | ||
768 | SceneObjectPart rootPart = group.GetPart(group.UUID); | 908 | SceneObjectPart rootPart = group.GetPart(group.UUID); |
@@ -771,12 +911,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
771 | // in the serialization, transfer the correct name from the inventory to the | 911 | // in the serialization, transfer the correct name from the inventory to the |
772 | // object itself before we rez. | 912 | // object itself before we rez. |
773 | // Only do these for the first object if we are rezzing a coalescence. | 913 | // Only do these for the first object if we are rezzing a coalescence. |
774 | if (i == 0) | 914 | // nahh dont mess with coalescence objects, |
915 | // the name in inventory can be change for inventory purpuses only | ||
916 | if (objlist.Count == 1) | ||
775 | { | 917 | { |
776 | rootPart.Name = item.Name; | 918 | rootPart.Name = item.Name; |
777 | rootPart.Description = item.Description; | 919 | rootPart.Description = item.Description; |
778 | } | 920 | } |
779 | 921 | /* reverted to old code till part.ApplyPermissionsOnRez is better reviewed/fixed | |
780 | group.SetGroup(m_part.GroupID, null); | 922 | group.SetGroup(m_part.GroupID, null); |
781 | 923 | ||
782 | foreach (SceneObjectPart part in group.Parts) | 924 | foreach (SceneObjectPart part in group.Parts) |
@@ -792,7 +934,49 @@ namespace OpenSim.Region.Framework.Scenes | |||
792 | 934 | ||
793 | part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene); | 935 | part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene); |
794 | } | 936 | } |
937 | */ | ||
938 | // old code start | ||
939 | SceneObjectPart[] partList = group.Parts; | ||
940 | |||
941 | group.SetGroup(m_part.GroupID, null); | ||
942 | |||
943 | // TODO: Remove magic number badness | ||
944 | if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number | ||
945 | { | ||
946 | if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions()) | ||
947 | { | ||
948 | foreach (SceneObjectPart part in partList) | ||
949 | { | ||
950 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) | ||
951 | part.EveryoneMask = item.EveryonePermissions; | ||
952 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) | ||
953 | part.NextOwnerMask = item.NextPermissions; | ||
954 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) | ||
955 | part.GroupMask = item.GroupPermissions; | ||
956 | } | ||
957 | |||
958 | group.ApplyNextOwnerPermissions(); | ||
959 | } | ||
960 | } | ||
961 | |||
962 | foreach (SceneObjectPart part in partList) | ||
963 | { | ||
964 | // TODO: Remove magic number badness | ||
965 | if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number | ||
966 | { | ||
967 | part.LastOwnerID = part.OwnerID; | ||
968 | part.OwnerID = item.OwnerID; | ||
969 | part.Inventory.ChangeInventoryOwner(item.OwnerID); | ||
970 | } | ||
795 | 971 | ||
972 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) | ||
973 | part.EveryoneMask = item.EveryonePermissions; | ||
974 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) | ||
975 | part.NextOwnerMask = item.NextPermissions; | ||
976 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) | ||
977 | part.GroupMask = item.GroupPermissions; | ||
978 | } | ||
979 | // old code end | ||
796 | rootPart.TrimPermissions(); | 980 | rootPart.TrimPermissions(); |
797 | } | 981 | } |
798 | 982 | ||
@@ -817,8 +1001,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
817 | 1001 | ||
818 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) | 1002 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) |
819 | { | 1003 | { |
820 | TaskInventoryItem it = GetInventoryItem(item.ItemID); | 1004 | m_items.LockItemsForWrite(true); |
821 | if (it != null) | 1005 | |
1006 | if (m_items.ContainsKey(item.ItemID)) | ||
822 | { | 1007 | { |
823 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); | 1008 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); |
824 | 1009 | ||
@@ -831,14 +1016,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
831 | item.GroupID = m_part.GroupID; | 1016 | item.GroupID = m_part.GroupID; |
832 | 1017 | ||
833 | if (item.AssetID == UUID.Zero) | 1018 | if (item.AssetID == UUID.Zero) |
834 | item.AssetID = it.AssetID; | 1019 | item.AssetID = m_items[item.ItemID].AssetID; |
835 | 1020 | ||
836 | lock (m_items) | 1021 | m_items[item.ItemID] = item; |
837 | { | 1022 | m_inventorySerial++; |
838 | m_items[item.ItemID] = item; | ||
839 | m_inventorySerial++; | ||
840 | } | ||
841 | |||
842 | if (fireScriptEvents) | 1023 | if (fireScriptEvents) |
843 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 1024 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
844 | 1025 | ||
@@ -847,7 +1028,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
847 | HasInventoryChanged = true; | 1028 | HasInventoryChanged = true; |
848 | m_part.ParentGroup.HasGroupChanged = true; | 1029 | m_part.ParentGroup.HasGroupChanged = true; |
849 | } | 1030 | } |
850 | 1031 | m_items.LockItemsForWrite(false); | |
851 | return true; | 1032 | return true; |
852 | } | 1033 | } |
853 | else | 1034 | else |
@@ -858,8 +1039,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
858 | item.ItemID, m_part.Name, m_part.UUID, | 1039 | item.ItemID, m_part.Name, m_part.UUID, |
859 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 1040 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
860 | } | 1041 | } |
861 | return false; | 1042 | m_items.LockItemsForWrite(false); |
862 | 1043 | ||
1044 | return false; | ||
863 | } | 1045 | } |
864 | 1046 | ||
865 | /// <summary> | 1047 | /// <summary> |
@@ -870,160 +1052,182 @@ namespace OpenSim.Region.Framework.Scenes | |||
870 | /// in this prim's inventory.</returns> | 1052 | /// in this prim's inventory.</returns> |
871 | public int RemoveInventoryItem(UUID itemID) | 1053 | public int RemoveInventoryItem(UUID itemID) |
872 | { | 1054 | { |
873 | TaskInventoryItem item = GetInventoryItem(itemID); | 1055 | m_items.LockItemsForRead(true); |
874 | if (item != null) | 1056 | |
1057 | if (m_items.ContainsKey(itemID)) | ||
875 | { | 1058 | { |
876 | int type = m_items[itemID].InvType; | 1059 | int type = m_items[itemID].InvType; |
1060 | m_items.LockItemsForRead(false); | ||
877 | if (type == 10) // Script | 1061 | if (type == 10) // Script |
878 | { | 1062 | { |
879 | // route it through here, to handle script cleanup tasks | 1063 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); |
880 | RemoveScriptInstance(itemID, false); | ||
881 | } | 1064 | } |
1065 | m_items.LockItemsForWrite(true); | ||
882 | m_items.Remove(itemID); | 1066 | m_items.Remove(itemID); |
1067 | m_items.LockItemsForWrite(false); | ||
883 | m_inventorySerial++; | 1068 | m_inventorySerial++; |
884 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 1069 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
885 | 1070 | ||
886 | HasInventoryChanged = true; | 1071 | HasInventoryChanged = true; |
887 | m_part.ParentGroup.HasGroupChanged = true; | 1072 | m_part.ParentGroup.HasGroupChanged = true; |
888 | 1073 | ||
889 | if (!ContainsScripts()) | 1074 | int scriptcount = 0; |
1075 | m_items.LockItemsForRead(true); | ||
1076 | foreach (TaskInventoryItem item in m_items.Values) | ||
1077 | { | ||
1078 | if (item.Type == 10) | ||
1079 | { | ||
1080 | scriptcount++; | ||
1081 | } | ||
1082 | } | ||
1083 | m_items.LockItemsForRead(false); | ||
1084 | |||
1085 | |||
1086 | if (scriptcount <= 0) | ||
1087 | { | ||
890 | m_part.RemFlag(PrimFlags.Scripted); | 1088 | m_part.RemFlag(PrimFlags.Scripted); |
1089 | } | ||
891 | 1090 | ||
892 | m_part.ScheduleFullUpdate(); | 1091 | m_part.ScheduleFullUpdate(); |
893 | 1092 | ||
894 | return type; | 1093 | return type; |
895 | |||
896 | } | 1094 | } |
897 | else | 1095 | else |
898 | { | 1096 | { |
1097 | m_items.LockItemsForRead(false); | ||
899 | m_log.ErrorFormat( | 1098 | m_log.ErrorFormat( |
900 | "[PRIM INVENTORY]: " + | 1099 | "[PRIM INVENTORY]: " + |
901 | "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", | 1100 | "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory", |
902 | itemID, m_part.Name, m_part.UUID, | 1101 | itemID, m_part.Name, m_part.UUID); |
903 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
904 | } | 1102 | } |
905 | 1103 | ||
906 | return -1; | 1104 | return -1; |
907 | } | 1105 | } |
908 | 1106 | ||
909 | private bool CreateInventoryFile() | 1107 | |
1108 | /// <summary> | ||
1109 | /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client | ||
1110 | /// </summary> | ||
1111 | /// <param name="xferManager"></param> | ||
1112 | public void RequestInventoryFile(IClientAPI client, IXfer xferManager) | ||
910 | { | 1113 | { |
911 | // m_log.DebugFormat( | ||
912 | // "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", | ||
913 | // m_part.Name, m_part.UUID, m_part.LocalId, m_inventorySerial); | ||
914 | 1114 | ||
915 | if (m_inventoryFileName == String.Empty || | 1115 | lock (m_inventoryFileLock) |
916 | m_inventoryFileNameSerial < m_inventorySerial) | ||
917 | { | 1116 | { |
918 | // Something changed, we need to create a new file | 1117 | string filename = "inventory_" + UUID.Random().ToString() + ".tmp"; |
919 | m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; | ||
920 | m_inventoryFileNameSerial = m_inventorySerial; | ||
921 | |||
922 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); | ||
923 | 1118 | ||
924 | lock (m_items) | 1119 | bool changed = false; |
1120 | if (m_inventoryFileNameSerial < m_inventorySerial) | ||
925 | { | 1121 | { |
926 | foreach (TaskInventoryItem item in m_items.Values) | 1122 | m_inventoryFileNameSerial = m_inventorySerial; |
927 | { | 1123 | changed = true; |
928 | // m_log.DebugFormat( | 1124 | } |
929 | // "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}", | ||
930 | // item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId); | ||
931 | |||
932 | UUID ownerID = item.OwnerID; | ||
933 | uint everyoneMask = 0; | ||
934 | uint baseMask = item.BasePermissions; | ||
935 | uint ownerMask = item.CurrentPermissions; | ||
936 | uint groupMask = item.GroupPermissions; | ||
937 | 1125 | ||
938 | invString.AddItemStart(); | 1126 | if (m_inventoryFileData.Length < 2) |
939 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); | 1127 | changed = true; |
940 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
941 | 1128 | ||
942 | invString.AddPermissionsStart(); | 1129 | bool includeAssets = false; |
1130 | if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId)) | ||
1131 | includeAssets = true; | ||
943 | 1132 | ||
944 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | 1133 | if (m_inventoryPrivileged != includeAssets) |
945 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | 1134 | changed = true; |
946 | invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); | ||
947 | invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); | ||
948 | invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); | ||
949 | 1135 | ||
950 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
951 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
952 | 1136 | ||
953 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | 1137 | Items.LockItemsForRead(true); |
954 | 1138 | ||
955 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | 1139 | if (m_inventorySerial == 0) // No inventory |
956 | invString.AddSectionEnd(); | 1140 | { |
1141 | Items.LockItemsForRead(false); | ||
1142 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | ||
1143 | |||
1144 | return; | ||
1145 | } | ||
957 | 1146 | ||
958 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | 1147 | if (m_items.Count == 0) // No inventory |
959 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | 1148 | { |
960 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | 1149 | Items.LockItemsForRead(false); |
961 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | 1150 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); |
1151 | return; | ||
1152 | } | ||
962 | 1153 | ||
963 | invString.AddSaleStart(); | 1154 | if (!changed) |
964 | invString.AddNameValueLine("sale_type", "not"); | 1155 | { |
965 | invString.AddNameValueLine("sale_price", "0"); | 1156 | Items.LockItemsForRead(false); |
966 | invString.AddSectionEnd(); | ||
967 | 1157 | ||
968 | invString.AddNameValueLine("name", item.Name + "|"); | 1158 | xferManager.AddNewFile(filename, |
969 | invString.AddNameValueLine("desc", item.Description + "|"); | 1159 | m_inventoryFileData); |
1160 | client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial, | ||
1161 | Util.StringToBytes256(filename)); | ||
970 | 1162 | ||
971 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | 1163 | return; |
972 | invString.AddSectionEnd(); | ||
973 | } | ||
974 | } | 1164 | } |
975 | 1165 | ||
976 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); | 1166 | m_inventoryPrivileged = includeAssets; |
977 | 1167 | ||
978 | return true; | 1168 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); |
979 | } | ||
980 | |||
981 | // No need to recreate, the existing file is fine | ||
982 | return false; | ||
983 | } | ||
984 | 1169 | ||
985 | /// <summary> | 1170 | foreach (TaskInventoryItem item in m_items.Values) |
986 | /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client | ||
987 | /// </summary> | ||
988 | /// <param name="xferManager"></param> | ||
989 | public void RequestInventoryFile(IClientAPI client, IXfer xferManager) | ||
990 | { | ||
991 | lock (m_items) | ||
992 | { | ||
993 | // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing | ||
994 | // a new script if any previous deletion has left the prim inventory empty. | ||
995 | if (m_items.Count == 0) // No inventory | ||
996 | { | 1171 | { |
997 | // m_log.DebugFormat( | 1172 | UUID ownerID = item.OwnerID; |
998 | // "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items", | 1173 | uint everyoneMask = 0; |
999 | // m_part.Name, m_part.LocalId, m_part.UUID, client.Name); | 1174 | uint baseMask = item.BasePermissions; |
1175 | uint ownerMask = item.CurrentPermissions; | ||
1176 | uint groupMask = item.GroupPermissions; | ||
1000 | 1177 | ||
1001 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | 1178 | invString.AddItemStart(); |
1002 | return; | 1179 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); |
1180 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
1181 | |||
1182 | invString.AddPermissionsStart(); | ||
1183 | |||
1184 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | ||
1185 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | ||
1186 | invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); | ||
1187 | invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); | ||
1188 | invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); | ||
1189 | |||
1190 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
1191 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
1192 | |||
1193 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | ||
1194 | |||
1195 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | ||
1196 | invString.AddSectionEnd(); | ||
1197 | |||
1198 | if (includeAssets) | ||
1199 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | ||
1200 | else | ||
1201 | invString.AddNameValueLine("asset_id", UUID.Zero.ToString()); | ||
1202 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | ||
1203 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | ||
1204 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | ||
1205 | |||
1206 | invString.AddSaleStart(); | ||
1207 | invString.AddNameValueLine("sale_type", "not"); | ||
1208 | invString.AddNameValueLine("sale_price", "0"); | ||
1209 | invString.AddSectionEnd(); | ||
1210 | |||
1211 | invString.AddNameValueLine("name", item.Name + "|"); | ||
1212 | invString.AddNameValueLine("desc", item.Description + "|"); | ||
1213 | |||
1214 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | ||
1215 | invString.AddSectionEnd(); | ||
1003 | } | 1216 | } |
1004 | 1217 | ||
1005 | CreateInventoryFile(); | 1218 | Items.LockItemsForRead(false); |
1006 | 1219 | ||
1007 | // In principle, we should only do the rest if the inventory changed; | 1220 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); |
1008 | // by sending m_inventorySerial to the client, it ought to know | 1221 | |
1009 | // that nothing changed and that it doesn't need to request the file. | ||
1010 | // Unfortunately, it doesn't look like the client optimizes this; | ||
1011 | // the client seems to always come back and request the Xfer, | ||
1012 | // no matter what value m_inventorySerial has. | ||
1013 | // FIXME: Could probably be > 0 here rather than > 2 | ||
1014 | if (m_inventoryFileData.Length > 2) | 1222 | if (m_inventoryFileData.Length > 2) |
1015 | { | 1223 | { |
1016 | // Add the file for Xfer | 1224 | xferManager.AddNewFile(filename, m_inventoryFileData); |
1017 | // m_log.DebugFormat( | 1225 | client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial, |
1018 | // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}", | 1226 | Util.StringToBytes256(filename)); |
1019 | // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId); | 1227 | return; |
1020 | |||
1021 | xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData); | ||
1022 | } | 1228 | } |
1023 | 1229 | ||
1024 | // Tell the client we're ready to Xfer the file | 1230 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); |
1025 | client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, | ||
1026 | Util.StringToBytes256(m_inventoryFileName)); | ||
1027 | } | 1231 | } |
1028 | } | 1232 | } |
1029 | 1233 | ||
@@ -1033,13 +1237,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
1033 | /// <param name="datastore"></param> | 1237 | /// <param name="datastore"></param> |
1034 | public void ProcessInventoryBackup(ISimulationDataService datastore) | 1238 | public void ProcessInventoryBackup(ISimulationDataService datastore) |
1035 | { | 1239 | { |
1036 | if (HasInventoryChanged) | 1240 | // Removed this because linking will cause an immediate delete of the new |
1037 | { | 1241 | // child prim from the database and the subsequent storing of the prim sees |
1242 | // the inventory of it as unchanged and doesn't store it at all. The overhead | ||
1243 | // of storing prim inventory needlessly is much less than the aggravation | ||
1244 | // of prim inventory loss. | ||
1245 | // if (HasInventoryChanged) | ||
1246 | // { | ||
1247 | Items.LockItemsForRead(true); | ||
1248 | try | ||
1249 | { | ||
1250 | datastore.StorePrimInventory(m_part.UUID, Items.Values); | ||
1251 | } | ||
1252 | catch {} | ||
1253 | |||
1038 | HasInventoryChanged = false; | 1254 | HasInventoryChanged = false; |
1039 | List<TaskInventoryItem> items = GetInventoryItems(); | ||
1040 | datastore.StorePrimInventory(m_part.UUID, items); | ||
1041 | 1255 | ||
1042 | } | 1256 | Items.LockItemsForRead(false); |
1257 | |||
1258 | |||
1259 | // } | ||
1043 | } | 1260 | } |
1044 | 1261 | ||
1045 | public class InventoryStringBuilder | 1262 | public class InventoryStringBuilder |
@@ -1105,65 +1322,63 @@ namespace OpenSim.Region.Framework.Scenes | |||
1105 | { | 1322 | { |
1106 | uint mask=0x7fffffff; | 1323 | uint mask=0x7fffffff; |
1107 | 1324 | ||
1108 | lock (m_items) | 1325 | foreach (TaskInventoryItem item in m_items.Values) |
1109 | { | 1326 | { |
1110 | foreach (TaskInventoryItem item in m_items.Values) | 1327 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) |
1328 | mask &= ~((uint)PermissionMask.Copy >> 13); | ||
1329 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1330 | mask &= ~((uint)PermissionMask.Transfer >> 13); | ||
1331 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | ||
1332 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
1333 | |||
1334 | if (item.InvType == (int)InventoryType.Object) | ||
1111 | { | 1335 | { |
1112 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) | 1336 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
1113 | mask &= ~((uint)PermissionMask.Copy >> 13); | 1337 | mask &= ~((uint)PermissionMask.Copy >> 13); |
1114 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | 1338 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1115 | mask &= ~((uint)PermissionMask.Transfer >> 13); | 1339 | mask &= ~((uint)PermissionMask.Transfer >> 13); |
1116 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | 1340 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1117 | mask &= ~((uint)PermissionMask.Modify >> 13); | 1341 | mask &= ~((uint)PermissionMask.Modify >> 13); |
1118 | |||
1119 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1120 | mask &= ~(uint)PermissionMask.Copy; | ||
1121 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1122 | mask &= ~(uint)PermissionMask.Transfer; | ||
1123 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1124 | mask &= ~(uint)PermissionMask.Modify; | ||
1125 | } | 1342 | } |
1343 | |||
1344 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1345 | mask &= ~(uint)PermissionMask.Copy; | ||
1346 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1347 | mask &= ~(uint)PermissionMask.Transfer; | ||
1348 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1349 | mask &= ~(uint)PermissionMask.Modify; | ||
1126 | } | 1350 | } |
1127 | |||
1128 | return mask; | 1351 | return mask; |
1129 | } | 1352 | } |
1130 | 1353 | ||
1131 | public void ApplyNextOwnerPermissions() | 1354 | public void ApplyNextOwnerPermissions() |
1132 | { | 1355 | { |
1133 | lock (m_items) | 1356 | foreach (TaskInventoryItem item in m_items.Values) |
1134 | { | 1357 | { |
1135 | foreach (TaskInventoryItem item in m_items.Values) | 1358 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) |
1136 | { | 1359 | { |
1137 | // m_log.DebugFormat ( | 1360 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
1138 | // "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}", | 1361 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; |
1139 | // item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions); | 1362 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1140 | 1363 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; | |
1141 | if (item.InvType == (int)InventoryType.Object) | 1364 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1142 | { | 1365 | item.CurrentPermissions &= ~(uint)PermissionMask.Modify; |
1143 | uint perms = item.CurrentPermissions; | ||
1144 | PermissionsUtil.ApplyFoldedPermissions(perms, ref perms); | ||
1145 | item.CurrentPermissions = perms; | ||
1146 | } | ||
1147 | |||
1148 | item.CurrentPermissions &= item.NextPermissions; | ||
1149 | item.BasePermissions &= item.NextPermissions; | ||
1150 | item.EveryonePermissions &= item.NextPermissions; | ||
1151 | item.OwnerChanged = true; | ||
1152 | item.PermsMask = 0; | ||
1153 | item.PermsGranter = UUID.Zero; | ||
1154 | } | 1366 | } |
1367 | item.CurrentPermissions &= item.NextPermissions; | ||
1368 | item.BasePermissions &= item.NextPermissions; | ||
1369 | item.EveryonePermissions &= item.NextPermissions; | ||
1370 | item.OwnerChanged = true; | ||
1371 | item.PermsMask = 0; | ||
1372 | item.PermsGranter = UUID.Zero; | ||
1155 | } | 1373 | } |
1156 | } | 1374 | } |
1157 | 1375 | ||
1158 | public void ApplyGodPermissions(uint perms) | 1376 | public void ApplyGodPermissions(uint perms) |
1159 | { | 1377 | { |
1160 | lock (m_items) | 1378 | foreach (TaskInventoryItem item in m_items.Values) |
1161 | { | 1379 | { |
1162 | foreach (TaskInventoryItem item in m_items.Values) | 1380 | item.CurrentPermissions = perms; |
1163 | { | 1381 | item.BasePermissions = perms; |
1164 | item.CurrentPermissions = perms; | ||
1165 | item.BasePermissions = perms; | ||
1166 | } | ||
1167 | } | 1382 | } |
1168 | 1383 | ||
1169 | m_inventorySerial++; | 1384 | m_inventorySerial++; |
@@ -1176,14 +1391,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1176 | /// <returns></returns> | 1391 | /// <returns></returns> |
1177 | public bool ContainsScripts() | 1392 | public bool ContainsScripts() |
1178 | { | 1393 | { |
1179 | lock (m_items) | 1394 | foreach (TaskInventoryItem item in m_items.Values) |
1180 | { | 1395 | { |
1181 | foreach (TaskInventoryItem item in m_items.Values) | 1396 | if (item.InvType == (int)InventoryType.LSL) |
1182 | { | 1397 | { |
1183 | if (item.InvType == (int)InventoryType.LSL) | 1398 | return true; |
1184 | { | ||
1185 | return true; | ||
1186 | } | ||
1187 | } | 1399 | } |
1188 | } | 1400 | } |
1189 | 1401 | ||
@@ -1197,17 +1409,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
1197 | public int ScriptCount() | 1409 | public int ScriptCount() |
1198 | { | 1410 | { |
1199 | int count = 0; | 1411 | int count = 0; |
1200 | lock (m_items) | 1412 | Items.LockItemsForRead(true); |
1413 | foreach (TaskInventoryItem item in m_items.Values) | ||
1201 | { | 1414 | { |
1202 | foreach (TaskInventoryItem item in m_items.Values) | 1415 | if (item.InvType == (int)InventoryType.LSL) |
1203 | { | 1416 | { |
1204 | if (item.InvType == (int)InventoryType.LSL) | 1417 | count++; |
1205 | { | ||
1206 | count++; | ||
1207 | } | ||
1208 | } | 1418 | } |
1209 | } | 1419 | } |
1210 | 1420 | Items.LockItemsForRead(false); | |
1211 | return count; | 1421 | return count; |
1212 | } | 1422 | } |
1213 | /// <summary> | 1423 | /// <summary> |
@@ -1243,11 +1453,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1243 | { | 1453 | { |
1244 | List<UUID> ret = new List<UUID>(); | 1454 | List<UUID> ret = new List<UUID>(); |
1245 | 1455 | ||
1246 | lock (m_items) | 1456 | foreach (TaskInventoryItem item in m_items.Values) |
1247 | { | 1457 | ret.Add(item.ItemID); |
1248 | foreach (TaskInventoryItem item in m_items.Values) | ||
1249 | ret.Add(item.ItemID); | ||
1250 | } | ||
1251 | 1458 | ||
1252 | return ret; | 1459 | return ret; |
1253 | } | 1460 | } |
@@ -1256,8 +1463,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1256 | { | 1463 | { |
1257 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1464 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1258 | 1465 | ||
1259 | lock (m_items) | 1466 | Items.LockItemsForRead(true); |
1260 | ret = new List<TaskInventoryItem>(m_items.Values); | 1467 | ret = new List<TaskInventoryItem>(m_items.Values); |
1468 | Items.LockItemsForRead(false); | ||
1261 | 1469 | ||
1262 | return ret; | 1470 | return ret; |
1263 | } | 1471 | } |
@@ -1266,18 +1474,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
1266 | { | 1474 | { |
1267 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1475 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1268 | 1476 | ||
1269 | lock (m_items) | 1477 | Items.LockItemsForRead(true); |
1270 | { | 1478 | |
1271 | foreach (TaskInventoryItem item in m_items.Values) | 1479 | foreach (TaskInventoryItem item in m_items.Values) |
1272 | if (item.InvType == (int)type) | 1480 | if (item.InvType == (int)type) |
1273 | ret.Add(item); | 1481 | ret.Add(item); |
1274 | } | 1482 | |
1483 | Items.LockItemsForRead(false); | ||
1275 | 1484 | ||
1276 | return ret; | 1485 | return ret; |
1277 | } | 1486 | } |
1278 | 1487 | ||
1279 | public Dictionary<UUID, string> GetScriptStates() | 1488 | public Dictionary<UUID, string> GetScriptStates() |
1280 | { | 1489 | { |
1490 | return GetScriptStates(false); | ||
1491 | } | ||
1492 | |||
1493 | public Dictionary<UUID, string> GetScriptStates(bool oldIDs) | ||
1494 | { | ||
1281 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); | 1495 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); |
1282 | 1496 | ||
1283 | if (m_part.ParentGroup.Scene == null) // Group not in a scene | 1497 | if (m_part.ParentGroup.Scene == null) // Group not in a scene |
@@ -1303,14 +1517,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1303 | string n = e.GetXMLState(item.ItemID); | 1517 | string n = e.GetXMLState(item.ItemID); |
1304 | if (n != String.Empty) | 1518 | if (n != String.Empty) |
1305 | { | 1519 | { |
1306 | if (!ret.ContainsKey(item.ItemID)) | 1520 | if (oldIDs) |
1307 | ret[item.ItemID] = n; | 1521 | { |
1522 | if (!ret.ContainsKey(item.OldItemID)) | ||
1523 | ret[item.OldItemID] = n; | ||
1524 | } | ||
1525 | else | ||
1526 | { | ||
1527 | if (!ret.ContainsKey(item.ItemID)) | ||
1528 | ret[item.ItemID] = n; | ||
1529 | } | ||
1308 | break; | 1530 | break; |
1309 | } | 1531 | } |
1310 | } | 1532 | } |
1311 | } | 1533 | } |
1312 | } | 1534 | } |
1313 | |||
1314 | return ret; | 1535 | return ret; |
1315 | } | 1536 | } |
1316 | 1537 | ||