diff options
author | Justin Clark-Casey (justincc) | 2011-04-18 21:59:01 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-04-18 21:59:01 +0100 |
commit | 61619ddefc96be2c1f802360cca48b1b36be8bb2 (patch) | |
tree | fa30854bfc53f3873ab9feb551534f8f36b5fa99 /OpenSim | |
parent | refactor: rename DeleteToInventory() to CopyToInventory() (diff) | |
download | opensim-SC_OLD-61619ddefc96be2c1f802360cca48b1b36be8bb2.zip opensim-SC_OLD-61619ddefc96be2c1f802360cca48b1b36be8bb2.tar.gz opensim-SC_OLD-61619ddefc96be2c1f802360cca48b1b36be8bb2.tar.bz2 opensim-SC_OLD-61619ddefc96be2c1f802360cca48b1b36be8bb2.tar.xz |
refactor: split out the code which actually copies a particular bundle to inventory
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | 221 |
1 files changed, 115 insertions, 106 deletions
diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 666f353..6b3df9d 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs | |||
@@ -213,19 +213,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
213 | 213 | ||
214 | return UUID.Zero; | 214 | return UUID.Zero; |
215 | } | 215 | } |
216 | 216 | ||
217 | /// <summary> | ||
218 | /// Delete a scene object from a scene and place in the given avatar's inventory. | ||
219 | /// Returns the UUID of the newly created asset. | ||
220 | /// </summary> | ||
221 | /// <param name="action"></param> | ||
222 | /// <param name="folderID"></param> | ||
223 | /// <param name="objectGroup"></param> | ||
224 | /// <param name="remoteClient"> </param> | ||
225 | public virtual UUID CopyToInventory(DeRezAction action, UUID folderID, | 217 | public virtual UUID CopyToInventory(DeRezAction action, UUID folderID, |
226 | List<SceneObjectGroup> objectGroups, IClientAPI remoteClient) | 218 | List<SceneObjectGroup> objectGroups, IClientAPI remoteClient) |
227 | { | 219 | { |
228 | Dictionary<UUID, List<SceneObjectGroup>> deletes = new Dictionary<UUID, List<SceneObjectGroup>>(); | 220 | Dictionary<UUID, List<SceneObjectGroup>> bundlesToCopy = new Dictionary<UUID, List<SceneObjectGroup>>(); |
229 | 221 | ||
230 | if (CoalesceMultipleObjectsToInventory) | 222 | if (CoalesceMultipleObjectsToInventory) |
231 | { | 223 | { |
@@ -234,10 +226,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
234 | // reasons. | 226 | // reasons. |
235 | foreach (SceneObjectGroup g in objectGroups) | 227 | foreach (SceneObjectGroup g in objectGroups) |
236 | { | 228 | { |
237 | if (!deletes.ContainsKey(g.OwnerID)) | 229 | if (!bundlesToCopy.ContainsKey(g.OwnerID)) |
238 | deletes[g.OwnerID] = new List<SceneObjectGroup>(); | 230 | bundlesToCopy[g.OwnerID] = new List<SceneObjectGroup>(); |
239 | 231 | ||
240 | deletes[g.OwnerID].Add(g); | 232 | bundlesToCopy[g.OwnerID].Add(g); |
241 | } | 233 | } |
242 | } | 234 | } |
243 | else | 235 | else |
@@ -247,7 +239,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
247 | { | 239 | { |
248 | List<SceneObjectGroup> bundle = new List<SceneObjectGroup>(); | 240 | List<SceneObjectGroup> bundle = new List<SceneObjectGroup>(); |
249 | bundle.Add(g); | 241 | bundle.Add(g); |
250 | deletes[g.UUID] = bundle; | 242 | bundlesToCopy[g.UUID] = bundle; |
251 | } | 243 | } |
252 | } | 244 | } |
253 | 245 | ||
@@ -257,112 +249,129 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess | |||
257 | 249 | ||
258 | // Each iteration is really a separate asset being created, | 250 | // Each iteration is really a separate asset being created, |
259 | // with distinct destinations as well. | 251 | // with distinct destinations as well. |
260 | foreach (List<SceneObjectGroup> objlist in deletes.Values) | 252 | foreach (List<SceneObjectGroup> bundle in bundlesToCopy.Values) |
253 | assetID = CopyBundleToInventory(action, folderID, bundle, remoteClient); | ||
254 | |||
255 | return assetID; | ||
256 | } | ||
257 | |||
258 | /// <summary> | ||
259 | /// Copy a bundle of objects to inventory. If there is only one object, then this will create an object | ||
260 | /// item. If there are multiple objects then these will be saved as a single coalesced item. | ||
261 | /// </summary> | ||
262 | /// <param name="action"></param> | ||
263 | /// <param name="folderID"></param> | ||
264 | /// <param name="objlist"></param> | ||
265 | /// <param name="remoteClient"></param> | ||
266 | /// <returns></returns> | ||
267 | protected UUID CopyBundleToInventory( | ||
268 | DeRezAction action, UUID folderID, List<SceneObjectGroup> objlist, IClientAPI remoteClient) | ||
269 | { | ||
270 | UUID assetID = UUID.Zero; | ||
271 | |||
272 | CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); | ||
273 | Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); | ||
274 | |||
275 | foreach (SceneObjectGroup objectGroup in objlist) | ||
261 | { | 276 | { |
262 | CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); | 277 | Vector3 inventoryStoredPosition = new Vector3 |
263 | Dictionary<UUID, Vector3> originalPositions = new Dictionary<UUID, Vector3>(); | 278 | (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize) |
279 | ? 250 | ||
280 | : objectGroup.AbsolutePosition.X) | ||
281 | , | ||
282 | (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize) | ||
283 | ? 250 | ||
284 | : objectGroup.AbsolutePosition.Y, | ||
285 | objectGroup.AbsolutePosition.Z); | ||
286 | |||
287 | originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; | ||
288 | |||
289 | objectGroup.AbsolutePosition = inventoryStoredPosition; | ||
290 | |||
291 | // Make sure all bits but the ones we want are clear | ||
292 | // on take. | ||
293 | // This will be applied to the current perms, so | ||
294 | // it will do what we want. | ||
295 | objectGroup.RootPart.NextOwnerMask &= | ||
296 | ((uint)PermissionMask.Copy | | ||
297 | (uint)PermissionMask.Transfer | | ||
298 | (uint)PermissionMask.Modify); | ||
299 | objectGroup.RootPart.NextOwnerMask |= | ||
300 | (uint)PermissionMask.Move; | ||
301 | |||
302 | coa.Add(objectGroup); | ||
303 | } | ||
264 | 304 | ||
265 | foreach (SceneObjectGroup objectGroup in objlist) | 305 | string itemXml; |
266 | { | ||
267 | Vector3 inventoryStoredPosition = new Vector3 | ||
268 | (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize) | ||
269 | ? 250 | ||
270 | : objectGroup.AbsolutePosition.X) | ||
271 | , | ||
272 | (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize) | ||
273 | ? 250 | ||
274 | : objectGroup.AbsolutePosition.Y, | ||
275 | objectGroup.AbsolutePosition.Z); | ||
276 | |||
277 | originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; | ||
278 | |||
279 | objectGroup.AbsolutePosition = inventoryStoredPosition; | ||
280 | |||
281 | // Make sure all bits but the ones we want are clear | ||
282 | // on take. | ||
283 | // This will be applied to the current perms, so | ||
284 | // it will do what we want. | ||
285 | objectGroup.RootPart.NextOwnerMask &= | ||
286 | ((uint)PermissionMask.Copy | | ||
287 | (uint)PermissionMask.Transfer | | ||
288 | (uint)PermissionMask.Modify); | ||
289 | objectGroup.RootPart.NextOwnerMask |= | ||
290 | (uint)PermissionMask.Move; | ||
291 | |||
292 | coa.Add(objectGroup); | ||
293 | } | ||
294 | 306 | ||
295 | string itemXml; | 307 | if (objlist.Count > 1) |
308 | itemXml = CoalescedSceneObjectsSerializer.ToXml(coa); | ||
309 | else | ||
310 | itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]); | ||
311 | |||
312 | // Restore the position of each group now that it has been stored to inventory. | ||
313 | foreach (SceneObjectGroup objectGroup in objlist) | ||
314 | objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; | ||
296 | 315 | ||
297 | if (objlist.Count > 1) | 316 | InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); |
298 | itemXml = CoalescedSceneObjectsSerializer.ToXml(coa); | 317 | if (item == null) |
299 | else | 318 | return UUID.Zero; |
300 | itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0]); | 319 | |
301 | 320 | // Can't know creator is the same, so null it in inventory | |
302 | // Restore the position of each group now that it has been stored to inventory. | 321 | if (objlist.Count > 1) |
303 | foreach (SceneObjectGroup objectGroup in objlist) | 322 | { |
304 | objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; | 323 | item.CreatorId = UUID.Zero.ToString(); |
324 | item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems; | ||
325 | } | ||
326 | else | ||
327 | { | ||
328 | item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); | ||
329 | item.SaleType = objlist[0].RootPart.ObjectSaleType; | ||
330 | item.SalePrice = objlist[0].RootPart.SalePrice; | ||
331 | } | ||
332 | |||
333 | AssetBase asset = CreateAsset( | ||
334 | objlist[0].GetPartName(objlist[0].RootPart.LocalId), | ||
335 | objlist[0].GetPartDescription(objlist[0].RootPart.LocalId), | ||
336 | (sbyte)AssetType.Object, | ||
337 | Utils.StringToBytes(itemXml), | ||
338 | objlist[0].OwnerID.ToString()); | ||
339 | m_Scene.AssetService.Store(asset); | ||
340 | |||
341 | item.AssetID = asset.FullID; | ||
342 | assetID = asset.FullID; | ||
305 | 343 | ||
306 | InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); | 344 | if (DeRezAction.SaveToExistingUserInventoryItem == action) |
307 | if (item == null) | 345 | { |
308 | return UUID.Zero; | 346 | m_Scene.InventoryService.UpdateItem(item); |
309 | 347 | } | |
310 | // Can't know creator is the same, so null it in inventory | 348 | else |
311 | if (objlist.Count > 1) | 349 | { |
312 | { | 350 | AddPermissions(item, objlist[0], objlist, remoteClient); |
313 | item.CreatorId = UUID.Zero.ToString(); | 351 | |
314 | item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems; | 352 | item.CreationDate = Util.UnixTimeSinceEpoch(); |
315 | } | 353 | item.Description = asset.Description; |
316 | else | 354 | item.Name = asset.Name; |
317 | { | 355 | item.AssetType = asset.Type; |
318 | item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); | ||
319 | item.SaleType = objlist[0].RootPart.ObjectSaleType; | ||
320 | item.SalePrice = objlist[0].RootPart.SalePrice; | ||
321 | } | ||
322 | |||
323 | AssetBase asset = CreateAsset( | ||
324 | objlist[0].GetPartName(objlist[0].RootPart.LocalId), | ||
325 | objlist[0].GetPartDescription(objlist[0].RootPart.LocalId), | ||
326 | (sbyte)AssetType.Object, | ||
327 | Utils.StringToBytes(itemXml), | ||
328 | objlist[0].OwnerID.ToString()); | ||
329 | m_Scene.AssetService.Store(asset); | ||
330 | |||
331 | item.AssetID = asset.FullID; | ||
332 | assetID = asset.FullID; | ||
333 | 356 | ||
334 | if (DeRezAction.SaveToExistingUserInventoryItem == action) | 357 | m_Scene.AddInventoryItem(item); |
358 | |||
359 | if (remoteClient != null && item.Owner == remoteClient.AgentId) | ||
335 | { | 360 | { |
336 | m_Scene.InventoryService.UpdateItem(item); | 361 | remoteClient.SendInventoryItemCreateUpdate(item, 0); |
337 | } | 362 | } |
338 | else | 363 | else |
339 | { | 364 | { |
340 | AddPermissions(item, objlist[0], objlist, remoteClient); | 365 | ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner); |
341 | 366 | if (notifyUser != null) | |
342 | item.CreationDate = Util.UnixTimeSinceEpoch(); | ||
343 | item.Description = asset.Description; | ||
344 | item.Name = asset.Name; | ||
345 | item.AssetType = asset.Type; | ||
346 | |||
347 | m_Scene.AddInventoryItem(item); | ||
348 | |||
349 | if (remoteClient != null && item.Owner == remoteClient.AgentId) | ||
350 | { | 367 | { |
351 | remoteClient.SendInventoryItemCreateUpdate(item, 0); | 368 | notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0); |
352 | } | ||
353 | else | ||
354 | { | ||
355 | ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner); | ||
356 | if (notifyUser != null) | ||
357 | { | ||
358 | notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0); | ||
359 | } | ||
360 | } | 369 | } |
361 | } | 370 | } |
362 | |||
363 | // This is a hook to do some per-asset post-processing for subclasses that need that | ||
364 | ExportAsset(remoteClient.AgentId, assetID); | ||
365 | } | 371 | } |
372 | |||
373 | // This is a hook to do some per-asset post-processing for subclasses that need that | ||
374 | ExportAsset(remoteClient.AgentId, assetID); | ||
366 | 375 | ||
367 | return assetID; | 376 | return assetID; |
368 | } | 377 | } |