aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-01-16 20:27:12 +0000
committerJustin Clarke Casey2008-01-16 20:27:12 +0000
commitb33da2538ed728bdc97cca20ada36913097160b0 (patch)
tree0464763a340891a49134d7bd66468302bc38dcad
parent* Fixed a packet counting issue that I introduced (diff)
downloadopensim-SC_OLD-b33da2538ed728bdc97cca20ada36913097160b0.zip
opensim-SC_OLD-b33da2538ed728bdc97cca20ada36913097160b0.tar.gz
opensim-SC_OLD-b33da2538ed728bdc97cca20ada36913097160b0.tar.bz2
opensim-SC_OLD-b33da2538ed728bdc97cca20ada36913097160b0.tar.xz
* Fix mantis 345 - it is now possible to duplicate prims directly in the region again without breakage
* This includes their inventories * Also, this revision properly synchronizes prim inventory crud.
-rw-r--r--OpenSim/Framework/TaskInventoryItem.cs61
-rw-r--r--OpenSim/Region/Environment/Scenes/InnerScene.cs7
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs6
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs209
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs8
5 files changed, 179 insertions, 112 deletions
diff --git a/OpenSim/Framework/TaskInventoryItem.cs b/OpenSim/Framework/TaskInventoryItem.cs
index 6e163a9..3009259 100644
--- a/OpenSim/Framework/TaskInventoryItem.cs
+++ b/OpenSim/Framework/TaskInventoryItem.cs
@@ -36,7 +36,13 @@ using System;
36 36
37namespace OpenSim.Framework 37namespace OpenSim.Framework
38{ 38{
39 public class TaskInventoryDictionary : Dictionary<LLUUID, TaskInventoryItem>, IXmlSerializable 39 /// <summary>
40 /// A dictionary for task inventory.
41 ///
42 /// This class is not thread safe. Callers must synchronize on Dictionary methods.
43 /// </summary>
44 public class TaskInventoryDictionary : Dictionary<LLUUID, TaskInventoryItem>,
45 ICloneable, IXmlSerializable
40 { 46 {
41 private static XmlSerializer tiiSerializer = new XmlSerializer(typeof(TaskInventoryItem)); 47 private static XmlSerializer tiiSerializer = new XmlSerializer(typeof(TaskInventoryItem));
42 48
@@ -86,19 +92,38 @@ namespace OpenSim.Framework
86 // see IXmlSerializable 92 // see IXmlSerializable
87 public void WriteXml(XmlWriter writer) 93 public void WriteXml(XmlWriter writer)
88 { 94 {
89 foreach (TaskInventoryItem item in Values) 95 lock (this)
90 { 96 {
91 tiiSerializer.Serialize(writer, item); 97 foreach (TaskInventoryItem item in Values)
98 {
99 tiiSerializer.Serialize(writer, item);
100 }
92 } 101 }
93 102
94 //tiiSerializer.Serialize(writer, Values); 103 //tiiSerializer.Serialize(writer, Values);
95 } 104 }
105
106 // see ICloneable
107 public Object Clone()
108 {
109 TaskInventoryDictionary clone = new TaskInventoryDictionary();
110
111 lock (this)
112 {
113 foreach (LLUUID uuid in Keys)
114 {
115 clone.Add(uuid, (TaskInventoryItem)this[uuid].Clone());
116 }
117 }
118
119 return clone;
120 }
96 } 121 }
97 122
98 /// <summary> 123 /// <summary>
99 /// Represents an item in a task inventory 124 /// Represents an item in a task inventory
100 /// </summary> 125 /// </summary>
101 public class TaskInventoryItem 126 public class TaskInventoryItem : ICloneable
102 { 127 {
103 /// <summary> 128 /// <summary>
104 /// XXX This should really be factored out into some constants class. 129 /// XXX This should really be factored out into some constants class.
@@ -141,17 +166,7 @@ namespace OpenSim.Framework
141 String.Empty, 166 String.Empty,
142 "lsltext", 167 "lsltext",
143 String.Empty 168 String.Empty
144 }; 169 };
145
146 /// <summary>
147 /// Reset the LLUUIDs for this item.
148 /// </summary>
149 /// <param name="partID">The new part ID to which this item belongs</param>
150 public void ResetIDs(LLUUID partID)
151 {
152 ItemID = LLUUID.Random();
153 ParentPartID = partID;
154 }
155 170
156 public LLUUID ItemID = LLUUID.Zero; 171 public LLUUID ItemID = LLUUID.Zero;
157 public LLUUID ParentID = LLUUID.Zero; //parent folder id 172 public LLUUID ParentID = LLUUID.Zero; //parent folder id
@@ -175,5 +190,21 @@ namespace OpenSim.Framework
175 public uint CreationDate = 0; 190 public uint CreationDate = 0;
176 191
177 public LLUUID ParentPartID = LLUUID.Zero; 192 public LLUUID ParentPartID = LLUUID.Zero;
193
194 /// <summary>
195 /// Reset the LLUUIDs for this item.
196 /// </summary>
197 /// <param name="partID">The new part ID to which this item belongs</param>
198 public void ResetIDs(LLUUID partID)
199 {
200 ItemID = LLUUID.Random();
201 ParentPartID = partID;
202 }
203
204 // See ICloneable
205 public Object Clone()
206 {
207 return MemberwiseClone();
208 }
178 } 209 }
179} 210}
diff --git a/OpenSim/Region/Environment/Scenes/InnerScene.cs b/OpenSim/Region/Environment/Scenes/InnerScene.cs
index 0116428..9aa3f20 100644
--- a/OpenSim/Region/Environment/Scenes/InnerScene.cs
+++ b/OpenSim/Region/Environment/Scenes/InnerScene.cs
@@ -928,17 +928,22 @@ namespace OpenSim.Region.Environment.Scenes
928 { 928 {
929 SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID); 929 SceneObjectGroup copy = originPrim.Copy(AgentID, GroupID);
930 copy.AbsolutePosition = copy.AbsolutePosition + offset; 930 copy.AbsolutePosition = copy.AbsolutePosition + offset;
931 copy.ResetIDs();
932
931 lock (Entities) 933 lock (Entities)
932 { 934 {
933 Entities.Add(copy.UUID, copy); 935 Entities.Add(copy.UUID, copy);
934 } 936 }
937
935 m_numPrim++; 938 m_numPrim++;
939
940 copy.StartScripts();
936 copy.ScheduleGroupForFullUpdate(); 941 copy.ScheduleGroupForFullUpdate();
937 } 942 }
938 } 943 }
939 else 944 else
940 { 945 {
941 MainLog.Instance.Warn("client", "Attempted to duplicate nonexistant prim"); 946 MainLog.Instance.Warn("SCENE", "Attempted to duplicate nonexistant prim id {0}", GroupID);
942 } 947 }
943 } 948 }
944 949
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
index 0b7f2a4..3327fea 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectGroup.cs
@@ -572,9 +572,8 @@ namespace OpenSim.Region.Environment.Scenes
572 /// <param name="part"></param> 572 /// <param name="part"></param>
573 public void CopyRootPart(SceneObjectPart part, LLUUID cAgentID, LLUUID cGroupID) 573 public void CopyRootPart(SceneObjectPart part, LLUUID cAgentID, LLUUID cGroupID)
574 { 574 {
575 SceneObjectPart newPart = part.Copy(m_scene.PrimIDAllocate(), OwnerID, GroupID); 575 SceneObjectPart newPart = part.Copy(m_scene.PrimIDAllocate(), OwnerID, GroupID, m_parts.Count);
576 newPart.SetParent(this); 576 newPart.SetParent(this);
577 newPart.LinkNum = m_parts.Count;
578 m_parts.Add(newPart.UUID, newPart); 577 m_parts.Add(newPart.UUID, newPart);
579 SetPartAsRoot(newPart); 578 SetPartAsRoot(newPart);
580 } 579 }
@@ -602,9 +601,8 @@ namespace OpenSim.Region.Environment.Scenes
602 /// <param name="part"></param> 601 /// <param name="part"></param>
603 public void CopyPart(SceneObjectPart part, LLUUID cAgentID, LLUUID cGroupID) 602 public void CopyPart(SceneObjectPart part, LLUUID cAgentID, LLUUID cGroupID)
604 { 603 {
605 SceneObjectPart newPart = part.Copy(m_scene.PrimIDAllocate(), OwnerID, GroupID); 604 SceneObjectPart newPart = part.Copy(m_scene.PrimIDAllocate(), OwnerID, GroupID, m_parts.Count);
606 newPart.SetParent(this); 605 newPart.SetParent(this);
607 newPart.LinkNum = m_parts.Count;
608 m_parts.Add(newPart.UUID, newPart); 606 m_parts.Add(newPart.UUID, newPart);
609 SetPartAsNonRoot(newPart); 607 SetPartAsNonRoot(newPart);
610 } 608 }
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
index 5132a6c..be2ddae 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.Inventory.cs
@@ -88,13 +88,16 @@ namespace OpenSim.Region.Environment.Scenes
88 /// <param name="linkNum'>Link number for the part</param> 88 /// <param name="linkNum'>Link number for the part</param>
89 public void ResetInventoryIDs() 89 public void ResetInventoryIDs()
90 { 90 {
91 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(TaskInventory.Values); 91 lock (TaskInventory)
92 TaskInventory.Clear(); 92 {
93 93 IList<TaskInventoryItem> items = new List<TaskInventoryItem>(TaskInventory.Values);
94 foreach (TaskInventoryItem item in items) 94 TaskInventory.Clear();
95 { 95
96 item.ResetIDs(UUID); 96 foreach (TaskInventoryItem item in items)
97 TaskInventory.Add(item.ItemID, item); 97 {
98 item.ResetIDs(UUID);
99 TaskInventory.Add(item.ItemID, item);
100 }
98 } 101 }
99 } 102 }
100 103
@@ -103,12 +106,15 @@ namespace OpenSim.Region.Environment.Scenes
103 /// </summary> 106 /// </summary>
104 public void StartScripts() 107 public void StartScripts()
105 { 108 {
106 foreach (TaskInventoryItem item in m_taskInventory.Values) 109 lock (m_taskInventory)
107 { 110 {
108 // XXX more hardcoding badness. Should be an enum in TaskInventoryItem 111 foreach (TaskInventoryItem item in m_taskInventory.Values)
109 if (10 == item.Type)
110 { 112 {
111 StartScript(item); 113 // XXX more hardcoding badness. Should be an enum in TaskInventoryItem
114 if (10 == item.Type)
115 {
116 StartScript(item);
117 }
112 } 118 }
113 } 119 }
114 } 120 }
@@ -149,18 +155,20 @@ namespace OpenSim.Region.Environment.Scenes
149 /// </param> 155 /// </param>
150 public void StartScript(LLUUID itemId) 156 public void StartScript(LLUUID itemId)
151 { 157 {
152 if (m_taskInventory.ContainsKey(itemId)) 158 lock (m_taskInventory)
153 { 159 {
154 StartScript(m_taskInventory[itemId]); 160 if (m_taskInventory.ContainsKey(itemId))
155 } 161 {
156 else 162 StartScript(m_taskInventory[itemId]);
157 { 163 }
158 MainLog.Instance.Error( 164 else
159 "PRIMINVENTORY", 165 {
160 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}", 166 MainLog.Instance.Error(
161 itemId, Name, UUID); 167 "PRIMINVENTORY",
162 } 168 "Couldn't start script with ID {0} since it couldn't be found for prim {1}, {2}",
163 169 itemId, Name, UUID);
170 }
171 }
164 } 172 }
165 173
166 /// <summary> 174 /// <summary>
@@ -191,7 +199,12 @@ namespace OpenSim.Region.Environment.Scenes
191 item.ParentID = m_folderID; 199 item.ParentID = m_folderID;
192 item.CreationDate = 1000; 200 item.CreationDate = 1000;
193 item.ParentPartID = UUID; 201 item.ParentPartID = UUID;
194 m_taskInventory.Add(item.ItemID, item); 202
203 lock (m_taskInventory)
204 {
205 m_taskInventory.Add(item.ItemID, item);
206 }
207
195 m_inventorySerial++; 208 m_inventorySerial++;
196 } 209 }
197 210
@@ -202,9 +215,12 @@ namespace OpenSim.Region.Environment.Scenes
202 /// <param name="items"></param> 215 /// <param name="items"></param>
203 public void AddInventoryItems(ICollection<TaskInventoryItem> items) 216 public void AddInventoryItems(ICollection<TaskInventoryItem> items)
204 { 217 {
205 foreach (TaskInventoryItem item in items) 218 lock (m_taskInventory)
206 { 219 {
207 m_taskInventory.Add(item.ItemID, item); 220 foreach (TaskInventoryItem item in items)
221 {
222 m_taskInventory.Add(item.ItemID, item);
223 }
208 } 224 }
209 225
210 m_inventorySerial++; 226 m_inventorySerial++;
@@ -217,16 +233,19 @@ namespace OpenSim.Region.Environment.Scenes
217 /// <returns>null if the item does not exist</returns> 233 /// <returns>null if the item does not exist</returns>
218 public TaskInventoryItem GetInventoryItem(LLUUID itemID) 234 public TaskInventoryItem GetInventoryItem(LLUUID itemID)
219 { 235 {
220 if (m_taskInventory.ContainsKey(itemID)) 236 lock (m_taskInventory)
221 { 237 {
222 return m_taskInventory[itemID]; 238 if (m_taskInventory.ContainsKey(itemID))
223 } 239 {
224 else 240 return m_taskInventory[itemID];
225 { 241 }
226 MainLog.Instance.Error( 242 else
227 "PRIMINVENTORY", 243 {
228 "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory", 244 MainLog.Instance.Error(
229 itemID, Name, UUID); 245 "PRIMINVENTORY",
246 "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
247 itemID, Name, UUID);
248 }
230 } 249 }
231 250
232 return null; 251 return null;
@@ -240,20 +259,23 @@ namespace OpenSim.Region.Environment.Scenes
240 /// <returns>false if the item did not exist, true if the update occurred succesfully</returns> 259 /// <returns>false if the item did not exist, true if the update occurred succesfully</returns>
241 public bool UpdateInventoryItem(TaskInventoryItem item) 260 public bool UpdateInventoryItem(TaskInventoryItem item)
242 { 261 {
243 if (m_taskInventory.ContainsKey(item.ItemID)) 262 lock (m_taskInventory)
244 { 263 {
245 m_taskInventory[item.ItemID] = item; 264 if (m_taskInventory.ContainsKey(item.ItemID))
246 m_inventorySerial++; 265 {
247 266 m_taskInventory[item.ItemID] = item;
248 return true; 267 m_inventorySerial++;
268
269 return true;
270 }
271 else
272 {
273 MainLog.Instance.Error(
274 "PRIMINVENTORY",
275 "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
276 item.ItemID, Name, UUID);
277 }
249 } 278 }
250 else
251 {
252 MainLog.Instance.Error(
253 "PRIMINVENTORY",
254 "Tried to retrieve item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
255 item.ItemID, Name, UUID);
256 }
257 279
258 return false; 280 return false;
259 } 281 }
@@ -266,21 +288,24 @@ namespace OpenSim.Region.Environment.Scenes
266 /// in this prim's inventory.</returns> 288 /// in this prim's inventory.</returns>
267 public int RemoveInventoryItem(LLUUID itemID) 289 public int RemoveInventoryItem(LLUUID itemID)
268 { 290 {
269 if (m_taskInventory.ContainsKey(itemID)) 291 lock (m_taskInventory)
270 { 292 {
271 int type = m_taskInventory[itemID].InvType; 293 if (m_taskInventory.ContainsKey(itemID))
272 m_taskInventory.Remove(itemID); 294 {
273 m_inventorySerial++; 295 int type = m_taskInventory[itemID].InvType;
274 296 m_taskInventory.Remove(itemID);
275 return type; 297 m_inventorySerial++;
298
299 return type;
300 }
301 else
302 {
303 MainLog.Instance.Error(
304 "PRIMINVENTORY",
305 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
306 itemID, Name, UUID);
307 }
276 } 308 }
277 else
278 {
279 MainLog.Instance.Error(
280 "PRIMINVENTORY",
281 "Tried to remove item ID {0} from prim {1}, {2} but the item does not exist in this inventory",
282 itemID, Name, UUID);
283 }
284 309
285 return -1; 310 return -1;
286 } 311 }
@@ -309,32 +334,36 @@ namespace OpenSim.Region.Environment.Scenes
309 { 334 {
310 byte[] fileData = new byte[0]; 335 byte[] fileData = new byte[0];
311 InventoryStringBuilder invString = new InventoryStringBuilder(m_folderID, UUID); 336 InventoryStringBuilder invString = new InventoryStringBuilder(m_folderID, UUID);
312 foreach (TaskInventoryItem item in m_taskInventory.Values) 337
313 { 338 lock (m_taskInventory)
314 invString.AddItemStart(); 339 {
315 invString.AddNameValueLine("item_id", item.ItemID.ToString()); 340 foreach (TaskInventoryItem item in m_taskInventory.Values)
316 invString.AddNameValueLine("parent_id", item.ParentID.ToString()); 341 {
317 342 invString.AddItemStart();
318 invString.AddPermissionsStart(); 343 invString.AddNameValueLine("item_id", item.ItemID.ToString());
319 invString.AddNameValueLine("base_mask", "0x7FFFFFFF"); 344 invString.AddNameValueLine("parent_id", item.ParentID.ToString());
320 invString.AddNameValueLine("owner_mask", "0x7FFFFFFF"); 345
321 invString.AddNameValueLine("group_mask", "0x7FFFFFFF"); 346 invString.AddPermissionsStart();
322 invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF"); 347 invString.AddNameValueLine("base_mask", "0x7FFFFFFF");
323 invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF"); 348 invString.AddNameValueLine("owner_mask", "0x7FFFFFFF");
324 invString.AddNameValueLine("creator_id", item.CreatorID.ToString()); 349 invString.AddNameValueLine("group_mask", "0x7FFFFFFF");
325 invString.AddNameValueLine("owner_id", item.OwnerID.ToString()); 350 invString.AddNameValueLine("everyone_mask", "0x7FFFFFFF");
326 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString()); 351 invString.AddNameValueLine("next_owner_mask", "0x7FFFFFFF");
327 invString.AddNameValueLine("group_id", item.GroupID.ToString()); 352 invString.AddNameValueLine("creator_id", item.CreatorID.ToString());
328 invString.AddSectionEnd(); 353 invString.AddNameValueLine("owner_id", item.OwnerID.ToString());
329 354 invString.AddNameValueLine("last_owner_id", item.LastOwnerID.ToString());
330 invString.AddNameValueLine("asset_id", item.AssetID.ToString()); 355 invString.AddNameValueLine("group_id", item.GroupID.ToString());
331 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]); 356 invString.AddSectionEnd();
332 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]); 357
333 invString.AddNameValueLine("flags", "0x00"); 358 invString.AddNameValueLine("asset_id", item.AssetID.ToString());
334 invString.AddNameValueLine("name", item.Name + "|"); 359 invString.AddNameValueLine("type", TaskInventoryItem.Types[item.Type]);
335 invString.AddNameValueLine("desc", item.Description + "|"); 360 invString.AddNameValueLine("inv_type", TaskInventoryItem.InvTypes[item.InvType]);
336 invString.AddNameValueLine("creation_date", item.CreationDate.ToString()); 361 invString.AddNameValueLine("flags", "0x00");
337 invString.AddSectionEnd(); 362 invString.AddNameValueLine("name", item.Name + "|");
363 invString.AddNameValueLine("desc", item.Description + "|");
364 invString.AddNameValueLine("creation_date", item.CreationDate.ToString());
365 invString.AddSectionEnd();
366 }
338 } 367 }
339 368
340 fileData = Helpers.StringToField(invString.BuildString); 369 fileData = Helpers.StringToField(invString.BuildString);
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index 93073c1..7866739 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -952,10 +952,10 @@ namespace OpenSim.Region.Environment.Scenes
952 #region Copying 952 #region Copying
953 953
954 /// <summary> 954 /// <summary>
955 /// 955 /// Duplicates this part.
956 /// </summary> 956 /// </summary>
957 /// <returns></returns> 957 /// <returns></returns>
958 public SceneObjectPart Copy(uint localID, LLUUID AgentID, LLUUID GroupID) 958 public SceneObjectPart Copy(uint localID, LLUUID AgentID, LLUUID GroupID, int linkNum)
959 { 959 {
960 SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone(); 960 SceneObjectPart dupe = (SceneObjectPart) MemberwiseClone();
961 dupe.m_shape = m_shape.Copy(); 961 dupe.m_shape = m_shape.Copy();
@@ -977,6 +977,10 @@ namespace OpenSim.Region.Environment.Scenes
977 dupe.ObjectSaleType = ObjectSaleType; 977 dupe.ObjectSaleType = ObjectSaleType;
978 dupe.SalePrice = SalePrice; 978 dupe.SalePrice = SalePrice;
979 dupe.Category = Category; 979 dupe.Category = Category;
980
981 dupe.TaskInventory = (TaskInventoryDictionary)dupe.TaskInventory.Clone();
982
983 dupe.ResetIDs(linkNum);
980 984
981 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. 985 // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated.
982 dupe.LastOwnerID = ObjectOwner; 986 dupe.LastOwnerID = ObjectOwner;