diff options
Diffstat (limited to 'OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | 745 |
1 files changed, 465 insertions, 280 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index fb8ecd5..8893cc0 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | |||
@@ -49,6 +49,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
49 | private string m_inventoryFileName = String.Empty; | 49 | private string m_inventoryFileName = String.Empty; |
50 | private byte[] m_inventoryFileData = new byte[0]; | 50 | private byte[] m_inventoryFileData = new byte[0]; |
51 | private uint m_inventoryFileNameSerial = 0; | 51 | private uint m_inventoryFileNameSerial = 0; |
52 | private bool m_inventoryPrivileged = false; | ||
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 | { | 190 | |
179 | if (0 == Items.Count) | 191 | if (items.Count == 0) |
180 | { | 192 | return; |
181 | return; | ||
182 | } | ||
183 | } | ||
184 | 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); |
@@ -460,22 +484,149 @@ namespace OpenSim.Region.Framework.Scenes | |||
460 | return stateID; | 484 | return stateID; |
461 | } | 485 | } |
462 | 486 | ||
487 | /// <summary> | ||
488 | /// Start a script which is in this prim's inventory. | ||
489 | /// Some processing may occur in the background, but this routine returns asap. | ||
490 | /// </summary> | ||
491 | /// <param name="itemId"> | ||
492 | /// A <see cref="UUID"/> | ||
493 | /// </param> | ||
463 | public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | 494 | public bool CreateScriptInstance(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) |
464 | { | 495 | { |
465 | TaskInventoryItem item = GetInventoryItem(itemId); | 496 | lock (m_scriptErrors) |
466 | if (item != null) | ||
467 | { | 497 | { |
468 | return CreateScriptInstance(item, startParam, postOnRez, engine, stateSource); | 498 | // Indicate to CreateScriptInstanceInternal() we don't want it to wait for completion |
499 | m_scriptErrors.Remove(itemId); | ||
500 | } | ||
501 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
502 | return true; | ||
503 | } | ||
504 | |||
505 | private void CreateScriptInstanceInternal(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
506 | { | ||
507 | m_items.LockItemsForRead(true); | ||
508 | if (m_items.ContainsKey(itemId)) | ||
509 | { | ||
510 | if (m_items.ContainsKey(itemId)) | ||
511 | { | ||
512 | m_items.LockItemsForRead(false); | ||
513 | CreateScriptInstance(m_items[itemId], startParam, postOnRez, engine, stateSource); | ||
514 | } | ||
515 | else | ||
516 | { | ||
517 | m_items.LockItemsForRead(false); | ||
518 | string msg = String.Format("couldn't be found for prim {0}, {1} at {2} in {3}", m_part.Name, m_part.UUID, | ||
519 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
520 | StoreScriptError(itemId, msg); | ||
521 | m_log.ErrorFormat( | ||
522 | "[PRIM INVENTORY]: " + | ||
523 | "Couldn't start script with ID {0} since it {1}", itemId, msg); | ||
524 | } | ||
469 | } | 525 | } |
470 | else | 526 | else |
471 | { | 527 | { |
528 | m_items.LockItemsForRead(false); | ||
529 | string msg = String.Format("couldn't be found for prim {0}, {1}", m_part.Name, m_part.UUID); | ||
530 | StoreScriptError(itemId, msg); | ||
472 | m_log.ErrorFormat( | 531 | m_log.ErrorFormat( |
473 | "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", | 532 | "[PRIM INVENTORY]: Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2} at {3} in {4}", |
474 | itemId, m_part.Name, m_part.UUID, | 533 | itemId, m_part.Name, m_part.UUID, |
475 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 534 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
535 | } | ||
536 | |||
537 | } | ||
476 | 538 | ||
477 | return false; | 539 | /// <summary> |
540 | /// Start a script which is in this prim's inventory and return any compilation error messages. | ||
541 | /// </summary> | ||
542 | /// <param name="itemId"> | ||
543 | /// A <see cref="UUID"/> | ||
544 | /// </param> | ||
545 | public ArrayList CreateScriptInstanceEr(UUID itemId, int startParam, bool postOnRez, string engine, int stateSource) | ||
546 | { | ||
547 | ArrayList errors; | ||
548 | |||
549 | // Indicate to CreateScriptInstanceInternal() we want it to | ||
550 | // post any compilation/loading error messages | ||
551 | lock (m_scriptErrors) | ||
552 | { | ||
553 | m_scriptErrors[itemId] = null; | ||
554 | } | ||
555 | |||
556 | // Perform compilation/loading | ||
557 | CreateScriptInstanceInternal(itemId, startParam, postOnRez, engine, stateSource); | ||
558 | |||
559 | // Wait for and retrieve any errors | ||
560 | lock (m_scriptErrors) | ||
561 | { | ||
562 | while ((errors = m_scriptErrors[itemId]) == null) | ||
563 | { | ||
564 | if (!System.Threading.Monitor.Wait(m_scriptErrors, 15000)) | ||
565 | { | ||
566 | m_log.ErrorFormat( | ||
567 | "[PRIM INVENTORY]: " + | ||
568 | "timedout waiting for script {0} errors", itemId); | ||
569 | errors = m_scriptErrors[itemId]; | ||
570 | if (errors == null) | ||
571 | { | ||
572 | errors = new ArrayList(1); | ||
573 | errors.Add("timedout waiting for errors"); | ||
574 | } | ||
575 | break; | ||
576 | } | ||
577 | } | ||
578 | m_scriptErrors.Remove(itemId); | ||
579 | } | ||
580 | return errors; | ||
581 | } | ||
582 | |||
583 | // Signal to CreateScriptInstanceEr() that compilation/loading is complete | ||
584 | private void StoreScriptErrors(UUID itemId, ArrayList errors) | ||
585 | { | ||
586 | lock (m_scriptErrors) | ||
587 | { | ||
588 | // If compilation/loading initiated via CreateScriptInstance(), | ||
589 | // it does not want the errors, so just get out | ||
590 | if (!m_scriptErrors.ContainsKey(itemId)) | ||
591 | { | ||
592 | return; | ||
593 | } | ||
594 | |||
595 | // Initiated via CreateScriptInstanceEr(), if we know what the | ||
596 | // errors are, save them and wake CreateScriptInstanceEr(). | ||
597 | if (errors != null) | ||
598 | { | ||
599 | m_scriptErrors[itemId] = errors; | ||
600 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
601 | return; | ||
602 | } | ||
478 | } | 603 | } |
604 | |||
605 | // Initiated via CreateScriptInstanceEr() but we don't know what | ||
606 | // the errors are yet, so retrieve them from the script engine. | ||
607 | // This may involve some waiting internal to GetScriptErrors(). | ||
608 | errors = GetScriptErrors(itemId); | ||
609 | |||
610 | // Get a default non-null value to indicate success. | ||
611 | if (errors == null) | ||
612 | { | ||
613 | errors = new ArrayList(); | ||
614 | } | ||
615 | |||
616 | // Post to CreateScriptInstanceEr() and wake it up | ||
617 | lock (m_scriptErrors) | ||
618 | { | ||
619 | m_scriptErrors[itemId] = errors; | ||
620 | System.Threading.Monitor.PulseAll(m_scriptErrors); | ||
621 | } | ||
622 | } | ||
623 | |||
624 | // Like StoreScriptErrors(), but just posts a single string message | ||
625 | private void StoreScriptError(UUID itemId, string message) | ||
626 | { | ||
627 | ArrayList errors = new ArrayList(1); | ||
628 | errors.Add(message); | ||
629 | StoreScriptErrors(itemId, errors); | ||
479 | } | 630 | } |
480 | 631 | ||
481 | /// <summary> | 632 | /// <summary> |
@@ -488,15 +639,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
488 | /// </param> | 639 | /// </param> |
489 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) | 640 | public void RemoveScriptInstance(UUID itemId, bool sceneObjectBeingDeleted) |
490 | { | 641 | { |
491 | bool scriptPresent = false; | 642 | if (m_items.ContainsKey(itemId)) |
492 | |||
493 | lock (m_items) | ||
494 | { | ||
495 | if (m_items.ContainsKey(itemId)) | ||
496 | scriptPresent = true; | ||
497 | } | ||
498 | |||
499 | if (scriptPresent) | ||
500 | { | 643 | { |
501 | if (!sceneObjectBeingDeleted) | 644 | if (!sceneObjectBeingDeleted) |
502 | m_part.RemoveScriptEvents(itemId); | 645 | m_part.RemoveScriptEvents(itemId); |
@@ -567,14 +710,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
567 | /// <returns></returns> | 710 | /// <returns></returns> |
568 | private bool InventoryContainsName(string name) | 711 | private bool InventoryContainsName(string name) |
569 | { | 712 | { |
570 | lock (m_items) | 713 | m_items.LockItemsForRead(true); |
714 | foreach (TaskInventoryItem item in m_items.Values) | ||
571 | { | 715 | { |
572 | foreach (TaskInventoryItem item in m_items.Values) | 716 | if (item.Name == name) |
573 | { | 717 | { |
574 | if (item.Name == name) | 718 | m_items.LockItemsForRead(false); |
575 | return true; | 719 | return true; |
576 | } | 720 | } |
577 | } | 721 | } |
722 | m_items.LockItemsForRead(false); | ||
578 | return false; | 723 | return false; |
579 | } | 724 | } |
580 | 725 | ||
@@ -616,8 +761,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
616 | /// <param name="item"></param> | 761 | /// <param name="item"></param> |
617 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) | 762 | public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop) |
618 | { | 763 | { |
619 | List<TaskInventoryItem> il = GetInventoryItems(); | 764 | m_items.LockItemsForRead(true); |
620 | 765 | List<TaskInventoryItem> il = new List<TaskInventoryItem>(m_items.Values); | |
766 | m_items.LockItemsForRead(false); | ||
621 | foreach (TaskInventoryItem i in il) | 767 | foreach (TaskInventoryItem i in il) |
622 | { | 768 | { |
623 | if (i.Name == item.Name) | 769 | if (i.Name == item.Name) |
@@ -655,14 +801,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
655 | item.Name = name; | 801 | item.Name = name; |
656 | item.GroupID = m_part.GroupID; | 802 | item.GroupID = m_part.GroupID; |
657 | 803 | ||
658 | lock (m_items) | 804 | m_items.LockItemsForWrite(true); |
659 | m_items.Add(item.ItemID, item); | 805 | m_items.Add(item.ItemID, item); |
660 | 806 | m_items.LockItemsForWrite(false); | |
661 | if (allowedDrop) | 807 | if (allowedDrop) |
662 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); | 808 | m_part.TriggerScriptChangedEvent(Changed.ALLOWED_DROP); |
663 | else | 809 | else |
664 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 810 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
665 | 811 | ||
666 | m_inventorySerial++; | 812 | m_inventorySerial++; |
667 | //m_inventorySerial += 2; | 813 | //m_inventorySerial += 2; |
668 | HasInventoryChanged = true; | 814 | HasInventoryChanged = true; |
@@ -678,15 +824,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
678 | /// <param name="items"></param> | 824 | /// <param name="items"></param> |
679 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) | 825 | public void RestoreInventoryItems(ICollection<TaskInventoryItem> items) |
680 | { | 826 | { |
681 | lock (m_items) | 827 | m_items.LockItemsForWrite(true); |
828 | foreach (TaskInventoryItem item in items) | ||
682 | { | 829 | { |
683 | foreach (TaskInventoryItem item in items) | 830 | m_items.Add(item.ItemID, item); |
684 | { | 831 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
685 | m_items.Add(item.ItemID, item); | ||
686 | // m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | ||
687 | } | ||
688 | m_inventorySerial++; | ||
689 | } | 832 | } |
833 | m_items.LockItemsForWrite(false); | ||
834 | |||
835 | m_inventorySerial++; | ||
690 | } | 836 | } |
691 | 837 | ||
692 | /// <summary> | 838 | /// <summary> |
@@ -697,23 +843,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
697 | public TaskInventoryItem GetInventoryItem(UUID itemId) | 843 | public TaskInventoryItem GetInventoryItem(UUID itemId) |
698 | { | 844 | { |
699 | TaskInventoryItem item; | 845 | TaskInventoryItem item; |
700 | 846 | m_items.LockItemsForRead(true); | |
701 | lock (m_items) | 847 | m_items.TryGetValue(itemId, out item); |
702 | m_items.TryGetValue(itemId, out item); | 848 | m_items.LockItemsForRead(false); |
703 | |||
704 | return item; | 849 | return item; |
705 | } | 850 | } |
706 | 851 | ||
707 | public TaskInventoryItem GetInventoryItem(string name) | 852 | public TaskInventoryItem GetInventoryItem(string name) |
708 | { | 853 | { |
709 | lock (m_items) | 854 | m_items.LockItemsForRead(true); |
855 | foreach (TaskInventoryItem item in m_items.Values) | ||
710 | { | 856 | { |
711 | foreach (TaskInventoryItem item in m_items.Values) | 857 | if (item.Name == name) |
712 | { | 858 | { |
713 | if (item.Name == name) | 859 | m_items.LockItemsForRead(false); |
714 | return item; | 860 | return item; |
715 | } | 861 | } |
716 | } | 862 | } |
863 | m_items.LockItemsForRead(false); | ||
717 | 864 | ||
718 | return null; | 865 | return null; |
719 | } | 866 | } |
@@ -722,15 +869,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
722 | { | 869 | { |
723 | List<TaskInventoryItem> items = new List<TaskInventoryItem>(); | 870 | List<TaskInventoryItem> items = new List<TaskInventoryItem>(); |
724 | 871 | ||
725 | lock (m_items) | 872 | m_items.LockItemsForRead(true); |
873 | |||
874 | foreach (TaskInventoryItem item in m_items.Values) | ||
726 | { | 875 | { |
727 | foreach (TaskInventoryItem item in m_items.Values) | 876 | if (item.Name == name) |
728 | { | 877 | items.Add(item); |
729 | if (item.Name == name) | ||
730 | items.Add(item); | ||
731 | } | ||
732 | } | 878 | } |
733 | 879 | ||
880 | m_items.LockItemsForRead(false); | ||
881 | |||
734 | return items; | 882 | return items; |
735 | } | 883 | } |
736 | 884 | ||
@@ -757,6 +905,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
757 | { | 905 | { |
758 | SceneObjectGroup group = objlist[i]; | 906 | SceneObjectGroup group = objlist[i]; |
759 | 907 | ||
908 | group.RootPart.AttachPoint = group.RootPart.Shape.State; | ||
909 | group.RootPart.AttachOffset = group.AbsolutePosition; | ||
910 | group.RootPart.AttachRotation = group.GroupRotation; | ||
911 | |||
760 | group.ResetIDs(); | 912 | group.ResetIDs(); |
761 | 913 | ||
762 | SceneObjectPart rootPart = group.GetPart(group.UUID); | 914 | SceneObjectPart rootPart = group.GetPart(group.UUID); |
@@ -811,8 +963,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
811 | 963 | ||
812 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) | 964 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) |
813 | { | 965 | { |
814 | TaskInventoryItem it = GetInventoryItem(item.ItemID); | 966 | m_items.LockItemsForWrite(true); |
815 | if (it != null) | 967 | |
968 | if (m_items.ContainsKey(item.ItemID)) | ||
816 | { | 969 | { |
817 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); | 970 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); |
818 | 971 | ||
@@ -825,14 +978,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
825 | item.GroupID = m_part.GroupID; | 978 | item.GroupID = m_part.GroupID; |
826 | 979 | ||
827 | if (item.AssetID == UUID.Zero) | 980 | if (item.AssetID == UUID.Zero) |
828 | item.AssetID = it.AssetID; | 981 | item.AssetID = m_items[item.ItemID].AssetID; |
829 | 982 | ||
830 | lock (m_items) | 983 | m_items[item.ItemID] = item; |
831 | { | 984 | m_inventorySerial++; |
832 | m_items[item.ItemID] = item; | ||
833 | m_inventorySerial++; | ||
834 | } | ||
835 | |||
836 | if (fireScriptEvents) | 985 | if (fireScriptEvents) |
837 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 986 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
838 | 987 | ||
@@ -841,7 +990,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
841 | HasInventoryChanged = true; | 990 | HasInventoryChanged = true; |
842 | m_part.ParentGroup.HasGroupChanged = true; | 991 | m_part.ParentGroup.HasGroupChanged = true; |
843 | } | 992 | } |
844 | 993 | m_items.LockItemsForWrite(false); | |
845 | return true; | 994 | return true; |
846 | } | 995 | } |
847 | else | 996 | else |
@@ -852,8 +1001,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
852 | item.ItemID, m_part.Name, m_part.UUID, | 1001 | item.ItemID, m_part.Name, m_part.UUID, |
853 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 1002 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
854 | } | 1003 | } |
855 | return false; | 1004 | m_items.LockItemsForWrite(false); |
856 | 1005 | ||
1006 | return false; | ||
857 | } | 1007 | } |
858 | 1008 | ||
859 | /// <summary> | 1009 | /// <summary> |
@@ -864,43 +1014,59 @@ namespace OpenSim.Region.Framework.Scenes | |||
864 | /// in this prim's inventory.</returns> | 1014 | /// in this prim's inventory.</returns> |
865 | public int RemoveInventoryItem(UUID itemID) | 1015 | public int RemoveInventoryItem(UUID itemID) |
866 | { | 1016 | { |
867 | TaskInventoryItem item = GetInventoryItem(itemID); | 1017 | m_items.LockItemsForRead(true); |
868 | if (item != null) | 1018 | |
1019 | if (m_items.ContainsKey(itemID)) | ||
869 | { | 1020 | { |
870 | int type = m_items[itemID].InvType; | 1021 | int type = m_items[itemID].InvType; |
1022 | m_items.LockItemsForRead(false); | ||
871 | if (type == 10) // Script | 1023 | if (type == 10) // Script |
872 | { | 1024 | { |
873 | m_part.RemoveScriptEvents(itemID); | ||
874 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); | 1025 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); |
875 | } | 1026 | } |
1027 | m_items.LockItemsForWrite(true); | ||
876 | m_items.Remove(itemID); | 1028 | m_items.Remove(itemID); |
1029 | m_items.LockItemsForWrite(false); | ||
877 | m_inventorySerial++; | 1030 | m_inventorySerial++; |
878 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 1031 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
879 | 1032 | ||
880 | HasInventoryChanged = true; | 1033 | HasInventoryChanged = true; |
881 | m_part.ParentGroup.HasGroupChanged = true; | 1034 | m_part.ParentGroup.HasGroupChanged = true; |
882 | 1035 | ||
883 | if (!ContainsScripts()) | 1036 | int scriptcount = 0; |
1037 | m_items.LockItemsForRead(true); | ||
1038 | foreach (TaskInventoryItem item in m_items.Values) | ||
1039 | { | ||
1040 | if (item.Type == 10) | ||
1041 | { | ||
1042 | scriptcount++; | ||
1043 | } | ||
1044 | } | ||
1045 | m_items.LockItemsForRead(false); | ||
1046 | |||
1047 | |||
1048 | if (scriptcount <= 0) | ||
1049 | { | ||
884 | m_part.RemFlag(PrimFlags.Scripted); | 1050 | m_part.RemFlag(PrimFlags.Scripted); |
1051 | } | ||
885 | 1052 | ||
886 | m_part.ScheduleFullUpdate(); | 1053 | m_part.ScheduleFullUpdate(); |
887 | 1054 | ||
888 | return type; | 1055 | return type; |
889 | |||
890 | } | 1056 | } |
891 | else | 1057 | else |
892 | { | 1058 | { |
1059 | m_items.LockItemsForRead(false); | ||
893 | m_log.ErrorFormat( | 1060 | m_log.ErrorFormat( |
894 | "[PRIM INVENTORY]: " + | 1061 | "[PRIM INVENTORY]: " + |
895 | "Tried to remove item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory", | 1062 | "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory", |
896 | itemID, m_part.Name, m_part.UUID, | 1063 | itemID, m_part.Name, m_part.UUID); |
897 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
898 | } | 1064 | } |
899 | 1065 | ||
900 | return -1; | 1066 | return -1; |
901 | } | 1067 | } |
902 | 1068 | ||
903 | private bool CreateInventoryFile() | 1069 | private bool CreateInventoryFileName() |
904 | { | 1070 | { |
905 | // m_log.DebugFormat( | 1071 | // m_log.DebugFormat( |
906 | // "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", | 1072 | // "[PRIM INVENTORY]: Creating inventory file for {0} {1} {2}, serial {3}", |
@@ -909,70 +1075,12 @@ namespace OpenSim.Region.Framework.Scenes | |||
909 | if (m_inventoryFileName == String.Empty || | 1075 | if (m_inventoryFileName == String.Empty || |
910 | m_inventoryFileNameSerial < m_inventorySerial) | 1076 | m_inventoryFileNameSerial < m_inventorySerial) |
911 | { | 1077 | { |
912 | // Something changed, we need to create a new file | ||
913 | m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; | 1078 | m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; |
914 | m_inventoryFileNameSerial = m_inventorySerial; | 1079 | m_inventoryFileNameSerial = m_inventorySerial; |
915 | 1080 | ||
916 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); | ||
917 | |||
918 | lock (m_items) | ||
919 | { | ||
920 | foreach (TaskInventoryItem item in m_items.Values) | ||
921 | { | ||
922 | // m_log.DebugFormat( | ||
923 | // "[PRIM INVENTORY]: Adding item {0} {1} for serial {2} on prim {3} {4} {5}", | ||
924 | // item.Name, item.ItemID, m_inventorySerial, m_part.Name, m_part.UUID, m_part.LocalId); | ||
925 | |||
926 | UUID ownerID = item.OwnerID; | ||
927 | uint everyoneMask = 0; | ||
928 | uint baseMask = item.BasePermissions; | ||
929 | uint ownerMask = item.CurrentPermissions; | ||
930 | uint groupMask = item.GroupPermissions; | ||
931 | |||
932 | invString.AddItemStart(); | ||
933 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); | ||
934 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
935 | |||
936 | invString.AddPermissionsStart(); | ||
937 | |||
938 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | ||
939 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | ||
940 | invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); | ||
941 | invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); | ||
942 | invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); | ||
943 | |||
944 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
945 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
946 | |||
947 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | ||
948 | |||
949 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | ||
950 | invString.AddSectionEnd(); | ||
951 | |||
952 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | ||
953 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | ||
954 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | ||
955 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | ||
956 | |||
957 | invString.AddSaleStart(); | ||
958 | invString.AddNameValueLine("sale_type", "not"); | ||
959 | invString.AddNameValueLine("sale_price", "0"); | ||
960 | invString.AddSectionEnd(); | ||
961 | |||
962 | invString.AddNameValueLine("name", item.Name + "|"); | ||
963 | invString.AddNameValueLine("desc", item.Description + "|"); | ||
964 | |||
965 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | ||
966 | invString.AddSectionEnd(); | ||
967 | } | ||
968 | } | ||
969 | |||
970 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); | ||
971 | |||
972 | return true; | 1081 | return true; |
973 | } | 1082 | } |
974 | 1083 | ||
975 | // No need to recreate, the existing file is fine | ||
976 | return false; | 1084 | return false; |
977 | } | 1085 | } |
978 | 1086 | ||
@@ -982,43 +1090,110 @@ namespace OpenSim.Region.Framework.Scenes | |||
982 | /// <param name="xferManager"></param> | 1090 | /// <param name="xferManager"></param> |
983 | public void RequestInventoryFile(IClientAPI client, IXfer xferManager) | 1091 | public void RequestInventoryFile(IClientAPI client, IXfer xferManager) |
984 | { | 1092 | { |
985 | lock (m_items) | 1093 | bool changed = CreateInventoryFileName(); |
986 | { | ||
987 | // Don't send a inventory xfer name if there are no items. Doing so causes viewer 3 to crash when rezzing | ||
988 | // a new script if any previous deletion has left the prim inventory empty. | ||
989 | if (m_items.Count == 0) // No inventory | ||
990 | { | ||
991 | // m_log.DebugFormat( | ||
992 | // "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items", | ||
993 | // m_part.Name, m_part.LocalId, m_part.UUID, client.Name); | ||
994 | 1094 | ||
995 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | 1095 | bool includeAssets = false; |
996 | return; | 1096 | if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId)) |
997 | } | 1097 | includeAssets = true; |
1098 | |||
1099 | if (m_inventoryPrivileged != includeAssets) | ||
1100 | changed = true; | ||
1101 | |||
1102 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); | ||
998 | 1103 | ||
999 | CreateInventoryFile(); | 1104 | Items.LockItemsForRead(true); |
1105 | |||
1106 | if (m_inventorySerial == 0) // No inventory | ||
1107 | { | ||
1108 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | ||
1109 | Items.LockItemsForRead(false); | ||
1110 | return; | ||
1111 | } | ||
1112 | |||
1113 | if (m_items.Count == 0) // No inventory | ||
1114 | { | ||
1115 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | ||
1116 | Items.LockItemsForRead(false); | ||
1117 | return; | ||
1118 | } | ||
1000 | 1119 | ||
1001 | // In principle, we should only do the rest if the inventory changed; | 1120 | if (!changed) |
1002 | // by sending m_inventorySerial to the client, it ought to know | 1121 | { |
1003 | // that nothing changed and that it doesn't need to request the file. | ||
1004 | // Unfortunately, it doesn't look like the client optimizes this; | ||
1005 | // the client seems to always come back and request the Xfer, | ||
1006 | // no matter what value m_inventorySerial has. | ||
1007 | // FIXME: Could probably be > 0 here rather than > 2 | ||
1008 | if (m_inventoryFileData.Length > 2) | 1122 | if (m_inventoryFileData.Length > 2) |
1009 | { | 1123 | { |
1010 | // Add the file for Xfer | 1124 | xferManager.AddNewFile(m_inventoryFileName, |
1011 | // m_log.DebugFormat( | 1125 | m_inventoryFileData); |
1012 | // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}", | 1126 | client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, |
1013 | // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId); | 1127 | Util.StringToBytes256(m_inventoryFileName)); |
1014 | 1128 | ||
1015 | xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData); | 1129 | Items.LockItemsForRead(false); |
1130 | return; | ||
1016 | } | 1131 | } |
1017 | |||
1018 | // Tell the client we're ready to Xfer the file | ||
1019 | client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, | ||
1020 | Util.StringToBytes256(m_inventoryFileName)); | ||
1021 | } | 1132 | } |
1133 | |||
1134 | m_inventoryPrivileged = includeAssets; | ||
1135 | |||
1136 | foreach (TaskInventoryItem item in m_items.Values) | ||
1137 | { | ||
1138 | UUID ownerID = item.OwnerID; | ||
1139 | uint everyoneMask = 0; | ||
1140 | uint baseMask = item.BasePermissions; | ||
1141 | uint ownerMask = item.CurrentPermissions; | ||
1142 | uint groupMask = item.GroupPermissions; | ||
1143 | |||
1144 | invString.AddItemStart(); | ||
1145 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); | ||
1146 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
1147 | |||
1148 | invString.AddPermissionsStart(); | ||
1149 | |||
1150 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | ||
1151 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | ||
1152 | invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); | ||
1153 | invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); | ||
1154 | invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); | ||
1155 | |||
1156 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
1157 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
1158 | |||
1159 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | ||
1160 | |||
1161 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | ||
1162 | invString.AddSectionEnd(); | ||
1163 | |||
1164 | if (includeAssets) | ||
1165 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | ||
1166 | else | ||
1167 | invString.AddNameValueLine("asset_id", UUID.Zero.ToString()); | ||
1168 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | ||
1169 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | ||
1170 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | ||
1171 | |||
1172 | invString.AddSaleStart(); | ||
1173 | invString.AddNameValueLine("sale_type", "not"); | ||
1174 | invString.AddNameValueLine("sale_price", "0"); | ||
1175 | invString.AddSectionEnd(); | ||
1176 | |||
1177 | invString.AddNameValueLine("name", item.Name + "|"); | ||
1178 | invString.AddNameValueLine("desc", item.Description + "|"); | ||
1179 | |||
1180 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | ||
1181 | invString.AddSectionEnd(); | ||
1182 | } | ||
1183 | |||
1184 | Items.LockItemsForRead(false); | ||
1185 | |||
1186 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); | ||
1187 | |||
1188 | if (m_inventoryFileData.Length > 2) | ||
1189 | { | ||
1190 | xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData); | ||
1191 | client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, | ||
1192 | Util.StringToBytes256(m_inventoryFileName)); | ||
1193 | return; | ||
1194 | } | ||
1195 | |||
1196 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | ||
1022 | } | 1197 | } |
1023 | 1198 | ||
1024 | /// <summary> | 1199 | /// <summary> |
@@ -1027,13 +1202,19 @@ namespace OpenSim.Region.Framework.Scenes | |||
1027 | /// <param name="datastore"></param> | 1202 | /// <param name="datastore"></param> |
1028 | public void ProcessInventoryBackup(ISimulationDataService datastore) | 1203 | public void ProcessInventoryBackup(ISimulationDataService datastore) |
1029 | { | 1204 | { |
1030 | if (HasInventoryChanged) | 1205 | // Removed this because linking will cause an immediate delete of the new |
1031 | { | 1206 | // child prim from the database and the subsequent storing of the prim sees |
1032 | HasInventoryChanged = false; | 1207 | // the inventory of it as unchanged and doesn't store it at all. The overhead |
1033 | List<TaskInventoryItem> items = GetInventoryItems(); | 1208 | // of storing prim inventory needlessly is much less than the aggravation |
1034 | datastore.StorePrimInventory(m_part.UUID, items); | 1209 | // of prim inventory loss. |
1210 | // if (HasInventoryChanged) | ||
1211 | // { | ||
1212 | Items.LockItemsForRead(true); | ||
1213 | datastore.StorePrimInventory(m_part.UUID, Items.Values); | ||
1214 | Items.LockItemsForRead(false); | ||
1035 | 1215 | ||
1036 | } | 1216 | HasInventoryChanged = false; |
1217 | // } | ||
1037 | } | 1218 | } |
1038 | 1219 | ||
1039 | public class InventoryStringBuilder | 1220 | public class InventoryStringBuilder |
@@ -1099,65 +1280,63 @@ namespace OpenSim.Region.Framework.Scenes | |||
1099 | { | 1280 | { |
1100 | uint mask=0x7fffffff; | 1281 | uint mask=0x7fffffff; |
1101 | 1282 | ||
1102 | lock (m_items) | 1283 | foreach (TaskInventoryItem item in m_items.Values) |
1103 | { | 1284 | { |
1104 | foreach (TaskInventoryItem item in m_items.Values) | 1285 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) |
1286 | mask &= ~((uint)PermissionMask.Copy >> 13); | ||
1287 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1288 | mask &= ~((uint)PermissionMask.Transfer >> 13); | ||
1289 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | ||
1290 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
1291 | |||
1292 | if (item.InvType == (int)InventoryType.Object) | ||
1105 | { | 1293 | { |
1106 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) | 1294 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
1107 | mask &= ~((uint)PermissionMask.Copy >> 13); | 1295 | mask &= ~((uint)PermissionMask.Copy >> 13); |
1108 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | 1296 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1109 | mask &= ~((uint)PermissionMask.Transfer >> 13); | 1297 | mask &= ~((uint)PermissionMask.Transfer >> 13); |
1110 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | 1298 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1111 | mask &= ~((uint)PermissionMask.Modify >> 13); | 1299 | mask &= ~((uint)PermissionMask.Modify >> 13); |
1112 | |||
1113 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1114 | mask &= ~(uint)PermissionMask.Copy; | ||
1115 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1116 | mask &= ~(uint)PermissionMask.Transfer; | ||
1117 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1118 | mask &= ~(uint)PermissionMask.Modify; | ||
1119 | } | 1300 | } |
1301 | |||
1302 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1303 | mask &= ~(uint)PermissionMask.Copy; | ||
1304 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1305 | mask &= ~(uint)PermissionMask.Transfer; | ||
1306 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1307 | mask &= ~(uint)PermissionMask.Modify; | ||
1120 | } | 1308 | } |
1121 | |||
1122 | return mask; | 1309 | return mask; |
1123 | } | 1310 | } |
1124 | 1311 | ||
1125 | public void ApplyNextOwnerPermissions() | 1312 | public void ApplyNextOwnerPermissions() |
1126 | { | 1313 | { |
1127 | lock (m_items) | 1314 | foreach (TaskInventoryItem item in m_items.Values) |
1128 | { | 1315 | { |
1129 | foreach (TaskInventoryItem item in m_items.Values) | 1316 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) |
1130 | { | 1317 | { |
1131 | // m_log.DebugFormat ( | 1318 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
1132 | // "[SCENE OBJECT PART INVENTORY]: Applying next permissions {0} to {1} in {2} with current {3}, base {4}, everyone {5}", | 1319 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; |
1133 | // item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions); | 1320 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1134 | 1321 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; | |
1135 | if (item.InvType == (int)InventoryType.Object) | 1322 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1136 | { | 1323 | item.CurrentPermissions &= ~(uint)PermissionMask.Modify; |
1137 | uint perms = item.CurrentPermissions; | ||
1138 | PermissionsUtil.ApplyFoldedPermissions(perms, ref perms); | ||
1139 | item.CurrentPermissions = perms; | ||
1140 | } | ||
1141 | |||
1142 | item.CurrentPermissions &= item.NextPermissions; | ||
1143 | item.BasePermissions &= item.NextPermissions; | ||
1144 | item.EveryonePermissions &= item.NextPermissions; | ||
1145 | item.OwnerChanged = true; | ||
1146 | item.PermsMask = 0; | ||
1147 | item.PermsGranter = UUID.Zero; | ||
1148 | } | 1324 | } |
1325 | item.CurrentPermissions &= item.NextPermissions; | ||
1326 | item.BasePermissions &= item.NextPermissions; | ||
1327 | item.EveryonePermissions &= item.NextPermissions; | ||
1328 | item.OwnerChanged = true; | ||
1329 | item.PermsMask = 0; | ||
1330 | item.PermsGranter = UUID.Zero; | ||
1149 | } | 1331 | } |
1150 | } | 1332 | } |
1151 | 1333 | ||
1152 | public void ApplyGodPermissions(uint perms) | 1334 | public void ApplyGodPermissions(uint perms) |
1153 | { | 1335 | { |
1154 | lock (m_items) | 1336 | foreach (TaskInventoryItem item in m_items.Values) |
1155 | { | 1337 | { |
1156 | foreach (TaskInventoryItem item in m_items.Values) | 1338 | item.CurrentPermissions = perms; |
1157 | { | 1339 | item.BasePermissions = perms; |
1158 | item.CurrentPermissions = perms; | ||
1159 | item.BasePermissions = perms; | ||
1160 | } | ||
1161 | } | 1340 | } |
1162 | 1341 | ||
1163 | m_inventorySerial++; | 1342 | m_inventorySerial++; |
@@ -1170,14 +1349,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1170 | /// <returns></returns> | 1349 | /// <returns></returns> |
1171 | public bool ContainsScripts() | 1350 | public bool ContainsScripts() |
1172 | { | 1351 | { |
1173 | lock (m_items) | 1352 | foreach (TaskInventoryItem item in m_items.Values) |
1174 | { | 1353 | { |
1175 | foreach (TaskInventoryItem item in m_items.Values) | 1354 | if (item.InvType == (int)InventoryType.LSL) |
1176 | { | 1355 | { |
1177 | if (item.InvType == (int)InventoryType.LSL) | 1356 | return true; |
1178 | { | ||
1179 | return true; | ||
1180 | } | ||
1181 | } | 1357 | } |
1182 | } | 1358 | } |
1183 | 1359 | ||
@@ -1191,17 +1367,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
1191 | public int ScriptCount() | 1367 | public int ScriptCount() |
1192 | { | 1368 | { |
1193 | int count = 0; | 1369 | int count = 0; |
1194 | lock (m_items) | 1370 | Items.LockItemsForRead(true); |
1371 | foreach (TaskInventoryItem item in m_items.Values) | ||
1195 | { | 1372 | { |
1196 | foreach (TaskInventoryItem item in m_items.Values) | 1373 | if (item.InvType == (int)InventoryType.LSL) |
1197 | { | 1374 | { |
1198 | if (item.InvType == (int)InventoryType.LSL) | 1375 | count++; |
1199 | { | ||
1200 | count++; | ||
1201 | } | ||
1202 | } | 1376 | } |
1203 | } | 1377 | } |
1204 | 1378 | Items.LockItemsForRead(false); | |
1205 | return count; | 1379 | return count; |
1206 | } | 1380 | } |
1207 | /// <summary> | 1381 | /// <summary> |
@@ -1237,11 +1411,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1237 | { | 1411 | { |
1238 | List<UUID> ret = new List<UUID>(); | 1412 | List<UUID> ret = new List<UUID>(); |
1239 | 1413 | ||
1240 | lock (m_items) | 1414 | foreach (TaskInventoryItem item in m_items.Values) |
1241 | { | 1415 | ret.Add(item.ItemID); |
1242 | foreach (TaskInventoryItem item in m_items.Values) | ||
1243 | ret.Add(item.ItemID); | ||
1244 | } | ||
1245 | 1416 | ||
1246 | return ret; | 1417 | return ret; |
1247 | } | 1418 | } |
@@ -1250,8 +1421,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1250 | { | 1421 | { |
1251 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1422 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1252 | 1423 | ||
1253 | lock (m_items) | 1424 | Items.LockItemsForRead(true); |
1254 | ret = new List<TaskInventoryItem>(m_items.Values); | 1425 | ret = new List<TaskInventoryItem>(m_items.Values); |
1426 | Items.LockItemsForRead(false); | ||
1255 | 1427 | ||
1256 | return ret; | 1428 | return ret; |
1257 | } | 1429 | } |
@@ -1260,18 +1432,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
1260 | { | 1432 | { |
1261 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1433 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1262 | 1434 | ||
1263 | lock (m_items) | 1435 | Items.LockItemsForRead(true); |
1264 | { | 1436 | |
1265 | foreach (TaskInventoryItem item in m_items.Values) | 1437 | foreach (TaskInventoryItem item in m_items.Values) |
1266 | if (item.InvType == (int)type) | 1438 | if (item.InvType == (int)type) |
1267 | ret.Add(item); | 1439 | ret.Add(item); |
1268 | } | 1440 | |
1441 | Items.LockItemsForRead(false); | ||
1269 | 1442 | ||
1270 | return ret; | 1443 | return ret; |
1271 | } | 1444 | } |
1272 | 1445 | ||
1273 | public Dictionary<UUID, string> GetScriptStates() | 1446 | public Dictionary<UUID, string> GetScriptStates() |
1274 | { | 1447 | { |
1448 | return GetScriptStates(false); | ||
1449 | } | ||
1450 | |||
1451 | public Dictionary<UUID, string> GetScriptStates(bool oldIDs) | ||
1452 | { | ||
1275 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); | 1453 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); |
1276 | 1454 | ||
1277 | if (m_part.ParentGroup.Scene == null) // Group not in a scene | 1455 | if (m_part.ParentGroup.Scene == null) // Group not in a scene |
@@ -1297,14 +1475,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1297 | string n = e.GetXMLState(item.ItemID); | 1475 | string n = e.GetXMLState(item.ItemID); |
1298 | if (n != String.Empty) | 1476 | if (n != String.Empty) |
1299 | { | 1477 | { |
1300 | if (!ret.ContainsKey(item.ItemID)) | 1478 | if (oldIDs) |
1301 | ret[item.ItemID] = n; | 1479 | { |
1480 | if (!ret.ContainsKey(item.OldItemID)) | ||
1481 | ret[item.OldItemID] = n; | ||
1482 | } | ||
1483 | else | ||
1484 | { | ||
1485 | if (!ret.ContainsKey(item.ItemID)) | ||
1486 | ret[item.ItemID] = n; | ||
1487 | } | ||
1302 | break; | 1488 | break; |
1303 | } | 1489 | } |
1304 | } | 1490 | } |
1305 | } | 1491 | } |
1306 | } | 1492 | } |
1307 | |||
1308 | return ret; | 1493 | return ret; |
1309 | } | 1494 | } |
1310 | 1495 | ||