diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs | 812 |
1 files changed, 523 insertions, 289 deletions
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index ec39726..7af0b20 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,29 @@ 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 | } |
895 | <<<<<<< HEAD | ||
756 | 896 | ||
757 | Vector3 bbox; | 897 | Vector3 bbox; |
758 | float offsetHeight; | 898 | float offsetHeight; |
759 | 899 | ||
760 | m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); | 900 | m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); |
901 | ======= | ||
902 | |||
903 | bool single = m_part.ParentGroup.Scene.GetObjectsToRez(rezAsset.Data, false, out objlist, out veclist, out bbox, out offsetHeight); | ||
904 | >>>>>>> avn/ubitvar | ||
761 | 905 | ||
762 | for (int i = 0; i < objlist.Count; i++) | 906 | for (int i = 0; i < objlist.Count; i++) |
763 | { | 907 | { |
764 | SceneObjectGroup group = objlist[i]; | 908 | SceneObjectGroup group = objlist[i]; |
765 | 909 | /* | |
910 | group.RootPart.AttachPoint = group.RootPart.Shape.State; | ||
911 | group.RootPart.AttachedPos = group.AbsolutePosition; | ||
912 | group.RootPart.AttachRotation = group.GroupRotation; | ||
913 | */ | ||
766 | group.ResetIDs(); | 914 | group.ResetIDs(); |
767 | 915 | ||
768 | SceneObjectPart rootPart = group.GetPart(group.UUID); | 916 | SceneObjectPart rootPart = group.GetPart(group.UUID); |
@@ -771,12 +919,14 @@ namespace OpenSim.Region.Framework.Scenes | |||
771 | // in the serialization, transfer the correct name from the inventory to the | 919 | // in the serialization, transfer the correct name from the inventory to the |
772 | // object itself before we rez. | 920 | // object itself before we rez. |
773 | // Only do these for the first object if we are rezzing a coalescence. | 921 | // Only do these for the first object if we are rezzing a coalescence. |
774 | if (i == 0) | 922 | // nahh dont mess with coalescence objects, |
923 | // the name in inventory can be change for inventory purpuses only | ||
924 | if (objlist.Count == 1) | ||
775 | { | 925 | { |
776 | rootPart.Name = item.Name; | 926 | rootPart.Name = item.Name; |
777 | rootPart.Description = item.Description; | 927 | rootPart.Description = item.Description; |
778 | } | 928 | } |
779 | 929 | /* reverted to old code till part.ApplyPermissionsOnRez is better reviewed/fixed | |
780 | group.SetGroup(m_part.GroupID, null); | 930 | group.SetGroup(m_part.GroupID, null); |
781 | 931 | ||
782 | foreach (SceneObjectPart part in group.Parts) | 932 | foreach (SceneObjectPart part in group.Parts) |
@@ -792,7 +942,49 @@ namespace OpenSim.Region.Framework.Scenes | |||
792 | 942 | ||
793 | part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene); | 943 | part.ApplyPermissionsOnRez(dest, false, m_part.ParentGroup.Scene); |
794 | } | 944 | } |
945 | */ | ||
946 | // old code start | ||
947 | SceneObjectPart[] partList = group.Parts; | ||
948 | |||
949 | group.SetGroup(m_part.GroupID, null); | ||
795 | 950 | ||
951 | // TODO: Remove magic number badness | ||
952 | if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number | ||
953 | { | ||
954 | if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions()) | ||
955 | { | ||
956 | foreach (SceneObjectPart part in partList) | ||
957 | { | ||
958 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) | ||
959 | part.EveryoneMask = item.EveryonePermissions; | ||
960 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) | ||
961 | part.NextOwnerMask = item.NextPermissions; | ||
962 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) | ||
963 | part.GroupMask = item.GroupPermissions; | ||
964 | } | ||
965 | |||
966 | group.ApplyNextOwnerPermissions(); | ||
967 | } | ||
968 | } | ||
969 | |||
970 | foreach (SceneObjectPart part in partList) | ||
971 | { | ||
972 | // TODO: Remove magic number badness | ||
973 | if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) // Magic number | ||
974 | { | ||
975 | part.LastOwnerID = part.OwnerID; | ||
976 | part.OwnerID = item.OwnerID; | ||
977 | part.Inventory.ChangeInventoryOwner(item.OwnerID); | ||
978 | } | ||
979 | |||
980 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteEveryone) != 0) | ||
981 | part.EveryoneMask = item.EveryonePermissions; | ||
982 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteNextOwner) != 0) | ||
983 | part.NextOwnerMask = item.NextPermissions; | ||
984 | if ((item.Flags & (uint)InventoryItemFlags.ObjectOverwriteGroup) != 0) | ||
985 | part.GroupMask = item.GroupPermissions; | ||
986 | } | ||
987 | // old code end | ||
796 | rootPart.TrimPermissions(); | 988 | rootPart.TrimPermissions(); |
797 | } | 989 | } |
798 | 990 | ||
@@ -817,8 +1009,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
817 | 1009 | ||
818 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) | 1010 | public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents, bool considerChanged) |
819 | { | 1011 | { |
820 | TaskInventoryItem it = GetInventoryItem(item.ItemID); | 1012 | m_items.LockItemsForWrite(true); |
821 | if (it != null) | 1013 | |
1014 | if (m_items.ContainsKey(item.ItemID)) | ||
822 | { | 1015 | { |
823 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); | 1016 | // m_log.DebugFormat("[PRIM INVENTORY]: Updating item {0} in {1}", item.Name, m_part.Name); |
824 | 1017 | ||
@@ -831,14 +1024,10 @@ namespace OpenSim.Region.Framework.Scenes | |||
831 | item.GroupID = m_part.GroupID; | 1024 | item.GroupID = m_part.GroupID; |
832 | 1025 | ||
833 | if (item.AssetID == UUID.Zero) | 1026 | if (item.AssetID == UUID.Zero) |
834 | item.AssetID = it.AssetID; | 1027 | item.AssetID = m_items[item.ItemID].AssetID; |
835 | 1028 | ||
836 | lock (m_items) | 1029 | m_items[item.ItemID] = item; |
837 | { | 1030 | m_inventorySerial++; |
838 | m_items[item.ItemID] = item; | ||
839 | m_inventorySerial++; | ||
840 | } | ||
841 | |||
842 | if (fireScriptEvents) | 1031 | if (fireScriptEvents) |
843 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 1032 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
844 | 1033 | ||
@@ -847,7 +1036,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
847 | HasInventoryChanged = true; | 1036 | HasInventoryChanged = true; |
848 | m_part.ParentGroup.HasGroupChanged = true; | 1037 | m_part.ParentGroup.HasGroupChanged = true; |
849 | } | 1038 | } |
850 | 1039 | m_items.LockItemsForWrite(false); | |
851 | return true; | 1040 | return true; |
852 | } | 1041 | } |
853 | else | 1042 | else |
@@ -858,8 +1047,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
858 | item.ItemID, m_part.Name, m_part.UUID, | 1047 | item.ItemID, m_part.Name, m_part.UUID, |
859 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | 1048 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); |
860 | } | 1049 | } |
861 | return false; | 1050 | m_items.LockItemsForWrite(false); |
862 | 1051 | ||
1052 | return false; | ||
863 | } | 1053 | } |
864 | 1054 | ||
865 | /// <summary> | 1055 | /// <summary> |
@@ -870,160 +1060,187 @@ namespace OpenSim.Region.Framework.Scenes | |||
870 | /// in this prim's inventory.</returns> | 1060 | /// in this prim's inventory.</returns> |
871 | public int RemoveInventoryItem(UUID itemID) | 1061 | public int RemoveInventoryItem(UUID itemID) |
872 | { | 1062 | { |
873 | TaskInventoryItem item = GetInventoryItem(itemID); | 1063 | m_items.LockItemsForRead(true); |
874 | if (item != null) | 1064 | |
1065 | if (m_items.ContainsKey(itemID)) | ||
875 | { | 1066 | { |
876 | int type = m_items[itemID].InvType; | 1067 | int type = m_items[itemID].InvType; |
1068 | m_items.LockItemsForRead(false); | ||
877 | if (type == 10) // Script | 1069 | if (type == 10) // Script |
878 | { | 1070 | { |
1071 | <<<<<<< HEAD | ||
879 | // route it through here, to handle script cleanup tasks | 1072 | // route it through here, to handle script cleanup tasks |
880 | RemoveScriptInstance(itemID, false); | 1073 | RemoveScriptInstance(itemID, false); |
1074 | ======= | ||
1075 | m_part.ParentGroup.Scene.EventManager.TriggerRemoveScript(m_part.LocalId, itemID); | ||
1076 | >>>>>>> avn/ubitvar | ||
881 | } | 1077 | } |
1078 | m_items.LockItemsForWrite(true); | ||
882 | m_items.Remove(itemID); | 1079 | m_items.Remove(itemID); |
1080 | m_items.LockItemsForWrite(false); | ||
883 | m_inventorySerial++; | 1081 | m_inventorySerial++; |
884 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); | 1082 | m_part.TriggerScriptChangedEvent(Changed.INVENTORY); |
885 | 1083 | ||
886 | HasInventoryChanged = true; | 1084 | HasInventoryChanged = true; |
887 | m_part.ParentGroup.HasGroupChanged = true; | 1085 | m_part.ParentGroup.HasGroupChanged = true; |
888 | 1086 | ||
889 | if (!ContainsScripts()) | 1087 | int scriptcount = 0; |
1088 | m_items.LockItemsForRead(true); | ||
1089 | foreach (TaskInventoryItem item in m_items.Values) | ||
1090 | { | ||
1091 | if (item.Type == 10) | ||
1092 | { | ||
1093 | scriptcount++; | ||
1094 | } | ||
1095 | } | ||
1096 | m_items.LockItemsForRead(false); | ||
1097 | |||
1098 | |||
1099 | if (scriptcount <= 0) | ||
1100 | { | ||
890 | m_part.RemFlag(PrimFlags.Scripted); | 1101 | m_part.RemFlag(PrimFlags.Scripted); |
1102 | } | ||
891 | 1103 | ||
892 | m_part.ScheduleFullUpdate(); | 1104 | m_part.ScheduleFullUpdate(); |
893 | 1105 | ||
894 | return type; | 1106 | return type; |
895 | |||
896 | } | 1107 | } |
897 | else | 1108 | else |
898 | { | 1109 | { |
1110 | m_items.LockItemsForRead(false); | ||
899 | m_log.ErrorFormat( | 1111 | m_log.ErrorFormat( |
900 | "[PRIM INVENTORY]: " + | 1112 | "[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", | 1113 | "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, | 1114 | itemID, m_part.Name, m_part.UUID); |
903 | m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName); | ||
904 | } | 1115 | } |
905 | 1116 | ||
906 | return -1; | 1117 | return -1; |
907 | } | 1118 | } |
908 | 1119 | ||
909 | private bool CreateInventoryFile() | 1120 | |
1121 | /// <summary> | ||
1122 | /// Serialize all the metadata for the items in this prim's inventory ready for sending to the client | ||
1123 | /// </summary> | ||
1124 | /// <param name="xferManager"></param> | ||
1125 | public void RequestInventoryFile(IClientAPI client, IXfer xferManager) | ||
910 | { | 1126 | { |
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 | 1127 | ||
915 | if (m_inventoryFileName == String.Empty || | 1128 | lock (m_inventoryFileLock) |
916 | m_inventoryFileNameSerial < m_inventorySerial) | ||
917 | { | 1129 | { |
918 | // Something changed, we need to create a new file | 1130 | string filename = "inventory_" + UUID.Random().ToString() + ".tmp"; |
919 | m_inventoryFileName = "inventory_" + UUID.Random().ToString() + ".tmp"; | ||
920 | m_inventoryFileNameSerial = m_inventorySerial; | ||
921 | 1131 | ||
922 | InventoryStringBuilder invString = new InventoryStringBuilder(m_part.UUID, UUID.Zero); | 1132 | bool changed = false; |
923 | 1133 | if (m_inventoryFileNameSerial < m_inventorySerial) | |
924 | lock (m_items) | ||
925 | { | 1134 | { |
926 | foreach (TaskInventoryItem item in m_items.Values) | 1135 | m_inventoryFileNameSerial = m_inventorySerial; |
927 | { | 1136 | changed = true; |
928 | // m_log.DebugFormat( | 1137 | } |
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 | 1138 | ||
938 | invString.AddItemStart(); | 1139 | if (m_inventoryFileData.Length < 2) |
939 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); | 1140 | changed = true; |
940 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
941 | 1141 | ||
942 | invString.AddPermissionsStart(); | 1142 | bool includeAssets = false; |
1143 | if (m_part.ParentGroup.Scene.Permissions.CanEditObjectInventory(m_part.UUID, client.AgentId)) | ||
1144 | includeAssets = true; | ||
943 | 1145 | ||
944 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | 1146 | if (m_inventoryPrivileged != includeAssets) |
945 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | 1147 | 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 | 1148 | ||
950 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
951 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
952 | 1149 | ||
953 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | 1150 | Items.LockItemsForRead(true); |
954 | 1151 | ||
955 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | 1152 | if (m_inventorySerial == 0) // No inventory |
956 | invString.AddSectionEnd(); | 1153 | { |
1154 | Items.LockItemsForRead(false); | ||
1155 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | ||
1156 | |||
1157 | return; | ||
1158 | } | ||
957 | 1159 | ||
958 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | 1160 | if (m_items.Count == 0) // No inventory |
959 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | 1161 | { |
960 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | 1162 | Items.LockItemsForRead(false); |
961 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | 1163 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); |
1164 | return; | ||
1165 | } | ||
962 | 1166 | ||
963 | invString.AddSaleStart(); | 1167 | if (!changed) |
964 | invString.AddNameValueLine("sale_type", "not"); | 1168 | { |
965 | invString.AddNameValueLine("sale_price", "0"); | 1169 | Items.LockItemsForRead(false); |
966 | invString.AddSectionEnd(); | ||
967 | 1170 | ||
968 | invString.AddNameValueLine("name", item.Name + "|"); | 1171 | xferManager.AddNewFile(filename, |
969 | invString.AddNameValueLine("desc", item.Description + "|"); | 1172 | m_inventoryFileData); |
1173 | client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial, | ||
1174 | Util.StringToBytes256(filename)); | ||
970 | 1175 | ||
971 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | 1176 | return; |
972 | invString.AddSectionEnd(); | ||
973 | } | ||
974 | } | 1177 | } |
975 | 1178 | ||
976 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); | 1179 | m_inventoryPrivileged = includeAssets; |
977 | 1180 | ||
978 | return true; | 1181 | 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 | 1182 | ||
985 | /// <summary> | 1183 | 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 | { | 1184 | { |
997 | // m_log.DebugFormat( | 1185 | UUID ownerID = item.OwnerID; |
998 | // "[PRIM INVENTORY]: Not sending inventory data for part {0} {1} {2} for {3} since no items", | 1186 | uint everyoneMask = 0; |
999 | // m_part.Name, m_part.LocalId, m_part.UUID, client.Name); | 1187 | uint baseMask = item.BasePermissions; |
1188 | uint ownerMask = item.CurrentPermissions; | ||
1189 | uint groupMask = item.GroupPermissions; | ||
1000 | 1190 | ||
1001 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); | 1191 | invString.AddItemStart(); |
1002 | return; | 1192 | invString.AddNameValueLine("item_id", item.ItemID.ToString()); |
1193 | invString.AddNameValueLine("parent_id", m_part.UUID.ToString()); | ||
1194 | |||
1195 | invString.AddPermissionsStart(); | ||
1196 | |||
1197 | invString.AddNameValueLine("base_mask", Utils.UIntToHexString(baseMask)); | ||
1198 | invString.AddNameValueLine("owner_mask", Utils.UIntToHexString(ownerMask)); | ||
1199 | invString.AddNameValueLine("group_mask", Utils.UIntToHexString(groupMask)); | ||
1200 | invString.AddNameValueLine("everyone_mask", Utils.UIntToHexString(everyoneMask)); | ||
1201 | invString.AddNameValueLine("next_owner_mask", Utils.UIntToHexString(item.NextPermissions)); | ||
1202 | |||
1203 | invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); | ||
1204 | invString.AddNameValueLine("owner_id", ownerID.ToString()); | ||
1205 | |||
1206 | invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); | ||
1207 | |||
1208 | invString.AddNameValueLine("group_id", item.GroupID.ToString()); | ||
1209 | invString.AddSectionEnd(); | ||
1210 | |||
1211 | if (includeAssets) | ||
1212 | invString.AddNameValueLine("asset_id", item.AssetID.ToString()); | ||
1213 | else | ||
1214 | invString.AddNameValueLine("asset_id", UUID.Zero.ToString()); | ||
1215 | invString.AddNameValueLine("type", Utils.AssetTypeToString((AssetType)item.Type)); | ||
1216 | invString.AddNameValueLine("inv_type", Utils.InventoryTypeToString((InventoryType)item.InvType)); | ||
1217 | invString.AddNameValueLine("flags", Utils.UIntToHexString(item.Flags)); | ||
1218 | |||
1219 | invString.AddSaleStart(); | ||
1220 | invString.AddNameValueLine("sale_type", "not"); | ||
1221 | invString.AddNameValueLine("sale_price", "0"); | ||
1222 | invString.AddSectionEnd(); | ||
1223 | |||
1224 | invString.AddNameValueLine("name", item.Name + "|"); | ||
1225 | invString.AddNameValueLine("desc", item.Description + "|"); | ||
1226 | |||
1227 | invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); | ||
1228 | invString.AddSectionEnd(); | ||
1003 | } | 1229 | } |
1004 | 1230 | ||
1005 | CreateInventoryFile(); | 1231 | Items.LockItemsForRead(false); |
1006 | 1232 | ||
1007 | // In principle, we should only do the rest if the inventory changed; | 1233 | m_inventoryFileData = Utils.StringToBytes(invString.BuildString); |
1008 | // by sending m_inventorySerial to the client, it ought to know | 1234 | |
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) | 1235 | if (m_inventoryFileData.Length > 2) |
1015 | { | 1236 | { |
1016 | // Add the file for Xfer | 1237 | xferManager.AddNewFile(filename, m_inventoryFileData); |
1017 | // m_log.DebugFormat( | 1238 | client.SendTaskInventory(m_part.UUID, (short)m_inventoryFileNameSerial, |
1018 | // "[PRIM INVENTORY]: Adding inventory file {0} (length {1}) for transfer on {2} {3} {4}", | 1239 | Util.StringToBytes256(filename)); |
1019 | // m_inventoryFileName, m_inventoryFileData.Length, m_part.Name, m_part.UUID, m_part.LocalId); | 1240 | return; |
1020 | |||
1021 | xferManager.AddNewFile(m_inventoryFileName, m_inventoryFileData); | ||
1022 | } | 1241 | } |
1023 | 1242 | ||
1024 | // Tell the client we're ready to Xfer the file | 1243 | client.SendTaskInventory(m_part.UUID, 0, new byte[0]); |
1025 | client.SendTaskInventory(m_part.UUID, (short)m_inventorySerial, | ||
1026 | Util.StringToBytes256(m_inventoryFileName)); | ||
1027 | } | 1244 | } |
1028 | } | 1245 | } |
1029 | 1246 | ||
@@ -1033,13 +1250,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
1033 | /// <param name="datastore"></param> | 1250 | /// <param name="datastore"></param> |
1034 | public void ProcessInventoryBackup(ISimulationDataService datastore) | 1251 | public void ProcessInventoryBackup(ISimulationDataService datastore) |
1035 | { | 1252 | { |
1036 | if (HasInventoryChanged) | 1253 | // Removed this because linking will cause an immediate delete of the new |
1037 | { | 1254 | // child prim from the database and the subsequent storing of the prim sees |
1255 | // the inventory of it as unchanged and doesn't store it at all. The overhead | ||
1256 | // of storing prim inventory needlessly is much less than the aggravation | ||
1257 | // of prim inventory loss. | ||
1258 | // if (HasInventoryChanged) | ||
1259 | // { | ||
1260 | Items.LockItemsForRead(true); | ||
1261 | try | ||
1262 | { | ||
1263 | datastore.StorePrimInventory(m_part.UUID, Items.Values); | ||
1264 | } | ||
1265 | catch {} | ||
1266 | |||
1038 | HasInventoryChanged = false; | 1267 | HasInventoryChanged = false; |
1039 | List<TaskInventoryItem> items = GetInventoryItems(); | ||
1040 | datastore.StorePrimInventory(m_part.UUID, items); | ||
1041 | 1268 | ||
1042 | } | 1269 | Items.LockItemsForRead(false); |
1270 | |||
1271 | |||
1272 | // } | ||
1043 | } | 1273 | } |
1044 | 1274 | ||
1045 | public class InventoryStringBuilder | 1275 | public class InventoryStringBuilder |
@@ -1105,65 +1335,63 @@ namespace OpenSim.Region.Framework.Scenes | |||
1105 | { | 1335 | { |
1106 | uint mask=0x7fffffff; | 1336 | uint mask=0x7fffffff; |
1107 | 1337 | ||
1108 | lock (m_items) | 1338 | foreach (TaskInventoryItem item in m_items.Values) |
1109 | { | 1339 | { |
1110 | foreach (TaskInventoryItem item in m_items.Values) | 1340 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) |
1341 | mask &= ~((uint)PermissionMask.Copy >> 13); | ||
1342 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1343 | mask &= ~((uint)PermissionMask.Transfer >> 13); | ||
1344 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | ||
1345 | mask &= ~((uint)PermissionMask.Modify >> 13); | ||
1346 | |||
1347 | if (item.InvType == (int)InventoryType.Object) | ||
1111 | { | 1348 | { |
1112 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Copy) == 0) | 1349 | if ((item.CurrentPermissions & ((uint)PermissionMask.Copy >> 13)) == 0) |
1113 | mask &= ~((uint)PermissionMask.Copy >> 13); | 1350 | mask &= ~((uint)PermissionMask.Copy >> 13); |
1114 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Transfer) == 0) | 1351 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1115 | mask &= ~((uint)PermissionMask.Transfer >> 13); | 1352 | mask &= ~((uint)PermissionMask.Transfer >> 13); |
1116 | if ((item.CurrentPermissions & item.NextPermissions & (uint)PermissionMask.Modify) == 0) | 1353 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1117 | mask &= ~((uint)PermissionMask.Modify >> 13); | 1354 | 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 | } | 1355 | } |
1356 | |||
1357 | if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) | ||
1358 | mask &= ~(uint)PermissionMask.Copy; | ||
1359 | if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0) | ||
1360 | mask &= ~(uint)PermissionMask.Transfer; | ||
1361 | if ((item.CurrentPermissions & (uint)PermissionMask.Modify) == 0) | ||
1362 | mask &= ~(uint)PermissionMask.Modify; | ||
1126 | } | 1363 | } |
1127 | |||
1128 | return mask; | 1364 | return mask; |
1129 | } | 1365 | } |
1130 | 1366 | ||
1131 | public void ApplyNextOwnerPermissions() | 1367 | public void ApplyNextOwnerPermissions() |
1132 | { | 1368 | { |
1133 | lock (m_items) | 1369 | foreach (TaskInventoryItem item in m_items.Values) |
1134 | { | 1370 | { |
1135 | foreach (TaskInventoryItem item in m_items.Values) | 1371 | if (item.InvType == (int)InventoryType.Object && (item.CurrentPermissions & 7) != 0) |
1136 | { | 1372 | { |
1137 | // m_log.DebugFormat ( | 1373 | 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}", | 1374 | item.CurrentPermissions &= ~(uint)PermissionMask.Copy; |
1139 | // item.NextPermissions, item.Name, m_part.Name, item.CurrentPermissions, item.BasePermissions, item.EveryonePermissions); | 1375 | if ((item.CurrentPermissions & ((uint)PermissionMask.Transfer >> 13)) == 0) |
1140 | 1376 | item.CurrentPermissions &= ~(uint)PermissionMask.Transfer; | |
1141 | if (item.InvType == (int)InventoryType.Object) | 1377 | if ((item.CurrentPermissions & ((uint)PermissionMask.Modify >> 13)) == 0) |
1142 | { | 1378 | 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 | } | 1379 | } |
1380 | item.CurrentPermissions &= item.NextPermissions; | ||
1381 | item.BasePermissions &= item.NextPermissions; | ||
1382 | item.EveryonePermissions &= item.NextPermissions; | ||
1383 | item.OwnerChanged = true; | ||
1384 | item.PermsMask = 0; | ||
1385 | item.PermsGranter = UUID.Zero; | ||
1155 | } | 1386 | } |
1156 | } | 1387 | } |
1157 | 1388 | ||
1158 | public void ApplyGodPermissions(uint perms) | 1389 | public void ApplyGodPermissions(uint perms) |
1159 | { | 1390 | { |
1160 | lock (m_items) | 1391 | foreach (TaskInventoryItem item in m_items.Values) |
1161 | { | 1392 | { |
1162 | foreach (TaskInventoryItem item in m_items.Values) | 1393 | item.CurrentPermissions = perms; |
1163 | { | 1394 | item.BasePermissions = perms; |
1164 | item.CurrentPermissions = perms; | ||
1165 | item.BasePermissions = perms; | ||
1166 | } | ||
1167 | } | 1395 | } |
1168 | 1396 | ||
1169 | m_inventorySerial++; | 1397 | m_inventorySerial++; |
@@ -1176,14 +1404,11 @@ namespace OpenSim.Region.Framework.Scenes | |||
1176 | /// <returns></returns> | 1404 | /// <returns></returns> |
1177 | public bool ContainsScripts() | 1405 | public bool ContainsScripts() |
1178 | { | 1406 | { |
1179 | lock (m_items) | 1407 | foreach (TaskInventoryItem item in m_items.Values) |
1180 | { | 1408 | { |
1181 | foreach (TaskInventoryItem item in m_items.Values) | 1409 | if (item.InvType == (int)InventoryType.LSL) |
1182 | { | 1410 | { |
1183 | if (item.InvType == (int)InventoryType.LSL) | 1411 | return true; |
1184 | { | ||
1185 | return true; | ||
1186 | } | ||
1187 | } | 1412 | } |
1188 | } | 1413 | } |
1189 | 1414 | ||
@@ -1197,17 +1422,15 @@ namespace OpenSim.Region.Framework.Scenes | |||
1197 | public int ScriptCount() | 1422 | public int ScriptCount() |
1198 | { | 1423 | { |
1199 | int count = 0; | 1424 | int count = 0; |
1200 | lock (m_items) | 1425 | Items.LockItemsForRead(true); |
1426 | foreach (TaskInventoryItem item in m_items.Values) | ||
1201 | { | 1427 | { |
1202 | foreach (TaskInventoryItem item in m_items.Values) | 1428 | if (item.InvType == (int)InventoryType.LSL) |
1203 | { | 1429 | { |
1204 | if (item.InvType == (int)InventoryType.LSL) | 1430 | count++; |
1205 | { | ||
1206 | count++; | ||
1207 | } | ||
1208 | } | 1431 | } |
1209 | } | 1432 | } |
1210 | 1433 | Items.LockItemsForRead(false); | |
1211 | return count; | 1434 | return count; |
1212 | } | 1435 | } |
1213 | /// <summary> | 1436 | /// <summary> |
@@ -1243,11 +1466,8 @@ namespace OpenSim.Region.Framework.Scenes | |||
1243 | { | 1466 | { |
1244 | List<UUID> ret = new List<UUID>(); | 1467 | List<UUID> ret = new List<UUID>(); |
1245 | 1468 | ||
1246 | lock (m_items) | 1469 | foreach (TaskInventoryItem item in m_items.Values) |
1247 | { | 1470 | ret.Add(item.ItemID); |
1248 | foreach (TaskInventoryItem item in m_items.Values) | ||
1249 | ret.Add(item.ItemID); | ||
1250 | } | ||
1251 | 1471 | ||
1252 | return ret; | 1472 | return ret; |
1253 | } | 1473 | } |
@@ -1256,8 +1476,9 @@ namespace OpenSim.Region.Framework.Scenes | |||
1256 | { | 1476 | { |
1257 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1477 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1258 | 1478 | ||
1259 | lock (m_items) | 1479 | Items.LockItemsForRead(true); |
1260 | ret = new List<TaskInventoryItem>(m_items.Values); | 1480 | ret = new List<TaskInventoryItem>(m_items.Values); |
1481 | Items.LockItemsForRead(false); | ||
1261 | 1482 | ||
1262 | return ret; | 1483 | return ret; |
1263 | } | 1484 | } |
@@ -1266,18 +1487,24 @@ namespace OpenSim.Region.Framework.Scenes | |||
1266 | { | 1487 | { |
1267 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); | 1488 | List<TaskInventoryItem> ret = new List<TaskInventoryItem>(); |
1268 | 1489 | ||
1269 | lock (m_items) | 1490 | Items.LockItemsForRead(true); |
1270 | { | 1491 | |
1271 | foreach (TaskInventoryItem item in m_items.Values) | 1492 | foreach (TaskInventoryItem item in m_items.Values) |
1272 | if (item.InvType == (int)type) | 1493 | if (item.InvType == (int)type) |
1273 | ret.Add(item); | 1494 | ret.Add(item); |
1274 | } | 1495 | |
1496 | Items.LockItemsForRead(false); | ||
1275 | 1497 | ||
1276 | return ret; | 1498 | return ret; |
1277 | } | 1499 | } |
1278 | 1500 | ||
1279 | public Dictionary<UUID, string> GetScriptStates() | 1501 | public Dictionary<UUID, string> GetScriptStates() |
1280 | { | 1502 | { |
1503 | return GetScriptStates(false); | ||
1504 | } | ||
1505 | |||
1506 | public Dictionary<UUID, string> GetScriptStates(bool oldIDs) | ||
1507 | { | ||
1281 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); | 1508 | Dictionary<UUID, string> ret = new Dictionary<UUID, string>(); |
1282 | 1509 | ||
1283 | if (m_part.ParentGroup.Scene == null) // Group not in a scene | 1510 | if (m_part.ParentGroup.Scene == null) // Group not in a scene |
@@ -1303,14 +1530,21 @@ namespace OpenSim.Region.Framework.Scenes | |||
1303 | string n = e.GetXMLState(item.ItemID); | 1530 | string n = e.GetXMLState(item.ItemID); |
1304 | if (n != String.Empty) | 1531 | if (n != String.Empty) |
1305 | { | 1532 | { |
1306 | if (!ret.ContainsKey(item.ItemID)) | 1533 | if (oldIDs) |
1307 | ret[item.ItemID] = n; | 1534 | { |
1535 | if (!ret.ContainsKey(item.OldItemID)) | ||
1536 | ret[item.OldItemID] = n; | ||
1537 | } | ||
1538 | else | ||
1539 | { | ||
1540 | if (!ret.ContainsKey(item.ItemID)) | ||
1541 | ret[item.ItemID] = n; | ||
1542 | } | ||
1308 | break; | 1543 | break; |
1309 | } | 1544 | } |
1310 | } | 1545 | } |
1311 | } | 1546 | } |
1312 | } | 1547 | } |
1313 | |||
1314 | return ret; | 1548 | return ret; |
1315 | } | 1549 | } |
1316 | 1550 | ||