aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2010-08-13 22:29:42 +0100
committerJustin Clark-Casey (justincc)2010-08-13 22:29:42 +0100
commite89f0b3f71dc8bd439fcfc23d12b305369eac36b (patch)
treee14eda03955229bdc32ebe51d735157dc09f4c90 /OpenSim/Region/CoreModules
parentminor: remove mono compiler warning (diff)
downloadopensim-SC_OLD-e89f0b3f71dc8bd439fcfc23d12b305369eac36b.zip
opensim-SC_OLD-e89f0b3f71dc8bd439fcfc23d12b305369eac36b.tar.gz
opensim-SC_OLD-e89f0b3f71dc8bd439fcfc23d12b305369eac36b.tar.bz2
opensim-SC_OLD-e89f0b3f71dc8bd439fcfc23d12b305369eac36b.tar.xz
refactor: move Scene.PerformObjectBuy into BuySellModule
Diffstat (limited to 'OpenSim/Region/CoreModules')
-rw-r--r--OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs169
1 files changed, 167 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
index 326eea9..b0ddd8f 100644
--- a/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
+++ b/OpenSim/Region/CoreModules/World/Objects/BuySell/BuySellModule.cs
@@ -37,15 +37,17 @@ using OpenSim.Framework;
37using OpenSim.Region.Framework; 37using OpenSim.Region.Framework;
38using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
40using OpenSim.Region.Framework.Scenes.Serialization;
40 41
41namespace OpenSim.Region.CoreModules.World.Objects.BuySell 42namespace OpenSim.Region.CoreModules.World.Objects.BuySell
42{ 43{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BuySellModule")] 44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BuySellModule")]
44 public class BuySellModule : INonSharedRegionModule 45 public class BuySellModule : IBuySellModule, INonSharedRegionModule
45 { 46 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 48
48 protected Scene m_scene = null; 49 protected Scene m_scene = null;
50 protected IDialogModule m_dialogModule;
49 51
50 public string Name { get { return "Object BuySell Module"; } } 52 public string Name { get { return "Object BuySell Module"; } }
51 public Type ReplaceableInterface { get { return null; } } 53 public Type ReplaceableInterface { get { return null; } }
@@ -55,6 +57,7 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
55 public void AddRegion(Scene scene) 57 public void AddRegion(Scene scene)
56 { 58 {
57 m_scene = scene; 59 m_scene = scene;
60 m_scene.RegisterModuleInterface<IBuySellModule>(this);
58 m_scene.EventManager.OnNewClient += SubscribeToClientEvents; 61 m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
59 } 62 }
60 63
@@ -63,7 +66,10 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
63 m_scene.EventManager.OnNewClient -= SubscribeToClientEvents; 66 m_scene.EventManager.OnNewClient -= SubscribeToClientEvents;
64 } 67 }
65 68
66 public void RegionLoaded(Scene scene) {} 69 public void RegionLoaded(Scene scene)
70 {
71 m_dialogModule = scene.RequestModuleInterface<IDialogModule>();
72 }
67 73
68 public void Close() 74 public void Close()
69 { 75 {
@@ -93,6 +99,165 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
93 part.ParentGroup.HasGroupChanged = true; 99 part.ParentGroup.HasGroupChanged = true;
94 100
95 part.GetProperties(client); 101 part.GetProperties(client);
102 }
103
104 public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType)
105 {
106 SceneObjectPart part = m_scene.GetSceneObjectPart(localID);
107
108 if (part == null)
109 return false;
110
111 if (part.ParentGroup == null)
112 return false;
113
114 SceneObjectGroup group = part.ParentGroup;
115
116 switch (saleType)
117 {
118 case 1: // Sell as original (in-place sale)
119 uint effectivePerms = group.GetEffectivePermissions();
120
121 if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
122 {
123 if (m_dialogModule != null)
124 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
125 return false;
126 }
127
128 group.SetOwnerId(remoteClient.AgentId);
129 group.SetRootPartOwner(part, remoteClient.AgentId, remoteClient.ActiveGroupId);
130
131 List<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
132
133 if (m_scene.Permissions.PropagatePermissions())
134 {
135 foreach (SceneObjectPart child in partList)
136 {
137 child.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
138 child.TriggerScriptChangedEvent(Changed.OWNER);
139 child.ApplyNextOwnerPermissions();
140 }
141 }
142
143 part.ObjectSaleType = 0;
144 part.SalePrice = 10;
145
146 group.HasGroupChanged = true;
147 part.GetProperties(remoteClient);
148 part.TriggerScriptChangedEvent(Changed.OWNER);
149 group.ResumeScripts();
150 part.ScheduleFullUpdate();
151
152 break;
153
154 case 2: // Sell a copy
155 Vector3 inventoryStoredPosition = new Vector3
156 (((group.AbsolutePosition.X > (int)Constants.RegionSize)
157 ? 250
158 : group.AbsolutePosition.X)
159 ,
160 (group.AbsolutePosition.X > (int)Constants.RegionSize)
161 ? 250
162 : group.AbsolutePosition.X,
163 group.AbsolutePosition.Z);
164
165 Vector3 originalPosition = group.AbsolutePosition;
166
167 group.AbsolutePosition = inventoryStoredPosition;
168
169 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
170 group.AbsolutePosition = originalPosition;
171
172 uint perms = group.GetEffectivePermissions();
173
174 if ((perms & (uint)PermissionMask.Transfer) == 0)
175 {
176 if (m_dialogModule != null)
177 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
178 return false;
179 }
180
181 AssetBase asset = m_scene.CreateAsset(
182 group.GetPartName(localID),
183 group.GetPartDescription(localID),
184 (sbyte)AssetType.Object,
185 Utils.StringToBytes(sceneObjectXml),
186 group.OwnerID);
187 m_scene.AssetService.Store(asset);
188
189 InventoryItemBase item = new InventoryItemBase();
190 item.CreatorId = part.CreatorID.ToString();
191
192 item.ID = UUID.Random();
193 item.Owner = remoteClient.AgentId;
194 item.AssetID = asset.FullID;
195 item.Description = asset.Description;
196 item.Name = asset.Name;
197 item.AssetType = asset.Type;
198 item.InvType = (int)InventoryType.Object;
199 item.Folder = categoryID;
200
201 uint nextPerms=(perms & 7) << 13;
202 if ((nextPerms & (uint)PermissionMask.Copy) == 0)
203 perms &= ~(uint)PermissionMask.Copy;
204 if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
205 perms &= ~(uint)PermissionMask.Transfer;
206 if ((nextPerms & (uint)PermissionMask.Modify) == 0)
207 perms &= ~(uint)PermissionMask.Modify;
208
209 item.BasePermissions = perms & part.NextOwnerMask;
210 item.CurrentPermissions = perms & part.NextOwnerMask;
211 item.NextPermissions = part.NextOwnerMask;
212 item.EveryOnePermissions = part.EveryoneMask &
213 part.NextOwnerMask;
214 item.GroupPermissions = part.GroupMask &
215 part.NextOwnerMask;
216 item.CurrentPermissions |= 16; // Slam!
217 item.CreationDate = Util.UnixTimeSinceEpoch();
218
219 if (m_scene.InventoryService.AddItem(item))
220 {
221 remoteClient.SendInventoryItemCreateUpdate(item, 0);
222 }
223 else
224 {
225 if (m_dialogModule != null)
226 m_dialogModule.SendAlertToUser(remoteClient, "Cannot buy now. Your inventory is unavailable");
227 return false;
228 }
229 break;
230
231 case 3: // Sell contents
232 List<UUID> invList = part.Inventory.GetInventoryList();
233
234 bool okToSell = true;
235
236 foreach (UUID invID in invList)
237 {
238 TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invID);
239 if ((item1.CurrentPermissions &
240 (uint)PermissionMask.Transfer) == 0)
241 {
242 okToSell = false;
243 break;
244 }
245 }
246
247 if (!okToSell)
248 {
249 if (m_dialogModule != null)
250 m_dialogModule.SendAlertToUser(
251 remoteClient, "This item's inventory doesn't appear to be for sale");
252 return false;
253 }
254
255 if (invList.Count > 0)
256 m_scene.MoveTaskInventoryItems(remoteClient.AgentId, part.Name, part, invList);
257 break;
258 }
259
260 return true;
96 } 261 }
97 } 262 }
98} \ No newline at end of file 263} \ No newline at end of file