public void HandleObjectBuyWorkItem(object o) { var req = (ObjectBuy)o; IAgent agent; if (!Agents.TryGetValue(req.AgentID, out agent)) { return; } foreach (ObjectBuy.Data data in req.ObjectData) { ObjectPart part; if (!Primitives.TryGetValue(data.ObjectLocalID, out part)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyDueNotFoundObject", "Unable to buy. The object was not found."), ID); } else { Object.ObjectGroup grp = part.ObjectGroup; if (grp.SalePrice != data.SalePrice || grp.SaleType != data.SaleType) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "BuyingCurrentlyNotPossibleDueInvalidRequest", "Buying currently not possible since the viewer request is invalid. You might have to relog."), ID); } else if (grp.SalePrice != 0 && agent.EconomyService == null) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "BuyingForAnyOtherPriceThanZeroIsNotPossible", "Buying for any other price than zero is not possible without economy system."), ID); } else { var assetids = new List <UUID>(); var items = new List <InventoryItem>(); bool foundNoTransfer = false; AssetData newAsset; switch (grp.SaleType) { case InventoryItem.SaleInfoData.SaleType.NoSale: default: continue; case InventoryItem.SaleInfoData.SaleType.Original: case InventoryItem.SaleInfoData.SaleType.Copy: UUID assetID; if (grp.Owner == agent.Owner) { assetID = grp.OriginalAssetID; if (assetID == UUID.Zero) { newAsset = grp.Asset(XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.WriteOwnerInfo); assetID = UUID.Random; newAsset.ID = assetID; AssetService.Store(newAsset); assetID = newAsset.ID; grp.OriginalAssetID = assetID; } } else { assetID = grp.NextOwnerAssetID; if (assetID == UUID.Zero) { newAsset = grp.Asset(UGUI.Unknown, XmlSerializationOptions.WriteXml2 | XmlSerializationOptions.AdjustForNextOwner); assetID = UUID.Random; newAsset.ID = assetID; AssetService.Store(newAsset); assetID = newAsset.ID; grp.NextOwnerAssetID = assetID; } } assetids.Add(assetID); if (grp.SaleType == InventoryItem.SaleInfoData.SaleType.Original) { Remove(grp); } bool foundNoCopy = false; foreach (ObjectPart checkpart in grp.Values) { if (!checkpart.CheckPermissions(checkpart.Owner, checkpart.Group, InventoryPermissionsMask.Transfer)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID); foundNoTransfer = true; break; } if (grp.SaleType == InventoryItem.SaleInfoData.SaleType.Copy && !checkpart.CheckPermissions(checkpart.Owner, checkpart.Group, InventoryPermissionsMask.Copy)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoCopyItemAsACopy", "Unable to sell no copy item as a copy."), ID); foundNoCopy = true; break; } foreach (ObjectPartInventoryItem item in checkpart.Inventory.Values) { if (item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Transfer)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID); foundNoTransfer = true; break; } } } if (foundNoTransfer || foundNoCopy) { continue; } var objectItem = new InventoryItem { Name = grp.Name, Description = grp.Description, LastOwner = grp.Owner, Owner = agent.Owner, AssetID = assetID, AssetType = AssetType.Object, InventoryType = InventoryType.Object }; objectItem.Permissions.Base = grp.RootPart.BaseMask; objectItem.Permissions.EveryOne = grp.RootPart.EveryoneMask; objectItem.Permissions.Group = InventoryPermissionsMask.None; objectItem.Permissions.NextOwner = grp.RootPart.NextOwnerMask; objectItem.Permissions.Current = objectItem.Permissions.Base; if (!agent.Owner.EqualsGrid(grp.Owner)) { objectItem.AdjustToNextOwner(); } items.Add(objectItem); break; case InventoryItem.SaleInfoData.SaleType.Content: foreach (ObjectPartInventoryItem item in part.Inventory.Values) { if (!item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Transfer)) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToSellNoTransferItem", "Unable to sell no transfer item."), ID); foundNoTransfer = true; break; } } if (foundNoTransfer) { continue; } foreach (ObjectPartInventoryItem item in part.Inventory.Values) { assetID = item.NextOwnerAssetID; if (assetID == UUID.Zero && !item.Owner.EqualsGrid(agent.Owner)) { /* create next owner asset id */ item.NextOwnerAssetID = AssetService.GenerateNextOwnerAsset(assetID); } var newItem = new InventoryItem(item); if (!item.Owner.EqualsGrid(agent.Owner)) { newItem.AssetID = item.NextOwnerAssetID; newItem.AdjustToNextOwner(); } assetids.Add(newItem.AssetID); items.Add(newItem); if (!item.CheckPermissions(item.Owner, item.Group, InventoryPermissionsMask.Copy)) { part.Inventory.Remove(item.ID); } } break; } if (grp.SalePrice == 0) { new ObjectBuyTransferItem( agent, this, assetids, items, grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ? part.Name : string.Empty, part.ID).QueueWorkItem(); } else if (agent.EconomyService != null) { IActiveTransaction transaction; try { transaction = agent.EconomyService.BeginTransferTransaction(agent.Owner, part.Owner, grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ? (BaseTransaction) new ObjectInventorySaleTransaction( GridPosition, ID, Name) { ObjectID = grp.ID, ObjectName = grp.Name } : new ObjectSaleTransaction( GridPosition, ID, Name) { ObjectID = grp.ID, ObjectName = grp.Name }, grp.SalePrice); } catch (InsufficientFundsException) { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyInsufficientFunds", "Unable to buy. Insufficient funds."), ID); continue; } catch (Exception e) { m_Log.Error("Exception at object selling", e); agent.SendAlertMessage(e.Message, ID); continue; } new ObjectBuyTransferItem( agent, this, assetids, items, grp.SaleType == InventoryItem.SaleInfoData.SaleType.Content ? part.Name : string.Empty, part.ID, transaction).QueueWorkItem(); } else { agent.SendAlertMessage(this.GetLanguageString(agent.CurrentCulture, "UnableToBuyNoEconomyConfigured", "Unable to buy. No economy configured."), ID); } } } } }