clockwerk-opensim-stable – 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 (((group.AbsolutePosition.X > (int)Constants.RegionSize)
156 ? 250
157 : group.AbsolutePosition.X)
158 ,
159 (group.AbsolutePosition.X > (int)Constants.RegionSize)
160 ? 250
161 : group.AbsolutePosition.X,
162 group.AbsolutePosition.Z);
163  
164 Vector3 originalPosition = group.AbsolutePosition;
165  
166 group.AbsolutePosition = inventoryStoredPosition;
167  
168 string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(group);
169 group.AbsolutePosition = originalPosition;
170  
171 uint perms = group.GetEffectivePermissions();
172  
173 if ((perms & (uint)PermissionMask.Transfer) == 0)
174 {
175 if (m_dialogModule != null)
176 m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
177 return false;
178 }
179  
180 AssetBase asset = m_scene.CreateAsset(
181 group.GetPartName(localID),
182 group.GetPartDescription(localID),
183 (sbyte)AssetType.Object,
184 Utils.StringToBytes(sceneObjectXml),
185 group.OwnerID);
186 m_scene.AssetService.Store(asset);
187  
188 InventoryItemBase item = new InventoryItemBase();
189 item.CreatorId = part.CreatorID.ToString();
190 item.CreatorData = part.CreatorData;
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.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm;
217 item.CreationDate = Util.UnixTimeSinceEpoch();
218  
219 if (m_scene.AddInventoryItem(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;
261 }
262 }
263 }