clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 1 /*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27  
28 using System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using log4net;
32 using Mono.Addins;
33 using Nini.Config;
34 using OpenMetaverse;
35 using OpenMetaverse.Packets;
36 using OpenSim.Framework;
37 using OpenSim.Region.Framework;
38 using OpenSim.Region.Framework.Interfaces;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Region.Framework.Scenes.Serialization;
41 using PermissionMask = OpenSim.Framework.PermissionMask;
42  
43 namespace OpenSim.Region.CoreModules.World.Objects.BuySell
44 {
45 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BuySellModule")]
46 public class BuySellModule : IBuySellModule, INonSharedRegionModule
47 {
48 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
49  
50 protected Scene m_scene = null;
51 protected IDialogModule m_dialogModule;
52  
53 public string Name { get { return "Object BuySell Module"; } }
54 public Type ReplaceableInterface { get { return null; } }
55  
56 public void Initialise(IConfigSource source) {}
57  
58 public void AddRegion(Scene scene)
59 {
60 m_scene = scene;
61 m_scene.RegisterModuleInterface<IBuySellModule>(this);
62 m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
63 }
64  
65 public void RemoveRegion(Scene scene)
66 {
67 m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
68 }
69  
70 public void RegionLoaded(Scene scene)
71 {
72 m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
73 }
74  
75 public void Close()
76 {
77 RemoveRegion(m_scene);
78 }
79  
80 public void SubscribeToClientEvents(IClientAPI client)
81 {
82 client.OnObjectSaleInfo += ObjectSaleInfo;
83 }
84  
85 protected void ObjectSaleInfo(
86 IClientAPI client, UUID agentID, UUID sessionID, uint localID, byte saleType, int salePrice)
87 {
88 SceneObjectPart part = m_scene.GetSceneObjectPart(localID);
89 if (part == null)
90 return;
91  
92 if (part.ParentGroup.IsDeleted)
93 return;
94  
95 if (part.OwnerID != client.AgentId && (!m_scene.Permissions.IsGod(client.AgentId)))
96 return;
97  
98 part = part.ParentGroup.RootPart;
99  
100 part.ObjectSaleType = saleType;
101 part.SalePrice = salePrice;
102  
103 part.ParentGroup.HasGroupChanged = true;
104  
105 part.SendPropertiesToClient(client);
106 }
107  
108 public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice)
109 {
110 SceneObjectPart part = m_scene.GetSceneObjectPart(localID);
111  
112 if (part == null)
113 return false;
114  
115 SceneObjectGroup group = part.ParentGroup;
116  
117 switch (saleType)
118 {
119 case 1: // Sell as original (in-place sale)
120 uint effectivePerms = group.GetEffectivePermissions();
121  
122 if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
123 {
124 if (m_dialogModule != null)
125 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
126 return false;
127 }
128  
129 group.SetOwnerId(remoteClient.AgentId);
130 group.SetRootPartOwner(part, remoteClient.AgentId, remoteClient.ActiveGroupId);
131  
132 if (m_scene.Permissions.PropagatePermissions())
133 {
134 foreach (SceneObjectPart child in group.Parts)
135 {
136 child.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
137 child.TriggerScriptChangedEvent(Changed.OWNER);
138 child.ApplyNextOwnerPermissions();
139 }
140 }
141  
142 part.ObjectSaleType = 0;
143 part.SalePrice = 10;
144  
145 group.HasGroupChanged = true;
146 part.SendPropertiesToClient(remoteClient);
147 part.TriggerScriptChangedEvent(Changed.OWNER);
148 group.ResumeScripts();
149 part.ScheduleFullUpdate();
150  
151 break;
152  
153 case 2: // Sell a copy
154 Vector3 inventoryStoredPosition = new Vector3(
155 Math.Min(group.AbsolutePosition.X, m_scene.RegionInfo.RegionSizeX - 6),
156 Math.Min(group.AbsolutePosition.Y, m_scene.RegionInfo.RegionSizeY - 6),
157 group.AbsolutePosition.Z);
158  
159 Vector3 originalPosition = group.AbsolutePosition;
160  
161 group.AbsolutePosition = inventoryStoredPosition;
162  
163 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
164 group.AbsolutePosition = originalPosition;
165  
166 uint perms = group.GetEffectivePermissions();
167  
168 if ((perms & (uint)PermissionMask.Transfer) == 0)
169 {
170 if (m_dialogModule != null)
171 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
172 return false;
173 }
174  
175 AssetBase asset = m_scene.CreateAsset(
176 group.GetPartName(localID),
177 group.GetPartDescription(localID),
178 (sbyte)AssetType.Object,
179 Utils.StringToBytes(sceneObjectXml),
180 group.OwnerID);
181 m_scene.AssetService.Store(asset);
182  
183 InventoryItemBase item = new InventoryItemBase();
184 item.CreatorId = part.CreatorID.ToString();
185 item.CreatorData = part.CreatorData;
186  
187 item.ID = UUID.Random();
188 item.Owner = remoteClient.AgentId;
189 item.AssetID = asset.FullID;
190 item.Description = asset.Description;
191 item.Name = asset.Name;
192 item.AssetType = asset.Type;
193 item.InvType = (int)InventoryType.Object;
194 item.Folder = categoryID;
195  
196 PermissionsUtil.ApplyFoldedPermissions(perms, ref perms);
197  
198 item.BasePermissions = perms & part.NextOwnerMask;
199 item.CurrentPermissions = perms & part.NextOwnerMask;
200 item.NextPermissions = part.NextOwnerMask;
201 item.EveryOnePermissions = part.EveryoneMask &
202 part.NextOwnerMask;
203 item.GroupPermissions = part.GroupMask &
204 part.NextOwnerMask;
205 item.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
206 item.CreationDate = Util.UnixTimeSinceEpoch();
207  
208 if (m_scene.AddInventoryItem(item))
209 {
210 remoteClient.SendInventoryItemCreateUpdate(item, 0);
211 }
212 else
213 {
214 if (m_dialogModule != null)
215 m_dialogModule.SendAlertToUser(remoteClient, "Cannot buy now. Your inventory is unavailable");
216 return false;
217 }
218 break;
219  
220 case 3: // Sell contents
221 List<UUID> invList = part.Inventory.GetInventoryList();
222  
223 bool okToSell = true;
224  
225 foreach (UUID invID in invList)
226 {
227 TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invID);
228 if ((item1.CurrentPermissions &
229 (uint)PermissionMask.Transfer) == 0)
230 {
231 okToSell = false;
232 break;
233 }
234 }
235  
236 if (!okToSell)
237 {
238 if (m_dialogModule != null)
239 m_dialogModule.SendAlertToUser(
240 remoteClient, "This item's inventory doesn't appear to be for sale");
241 return false;
242 }
243  
244 if (invList.Count > 0)
245 m_scene.MoveTaskInventoryItems(remoteClient.AgentId, part.Name, part, invList);
246 break;
247 }
248  
249 return true;
250 }
251 }
252 }