aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMelanie2012-03-28 23:51:44 +0200
committerMelanie2012-03-29 00:47:09 +0100
commitc52ff5cf7b4ff71fa14b39ea2e104c7c3d5a1ba8 (patch)
treea3d4bb1e9fbf079e95182c18296e4b34701af49c /OpenSim/Region
parentAdding the Avination calling card interface (diff)
downloadopensim-SC_OLD-c52ff5cf7b4ff71fa14b39ea2e104c7c3d5a1ba8.zip
opensim-SC_OLD-c52ff5cf7b4ff71fa14b39ea2e104c7c3d5a1ba8.tar.gz
opensim-SC_OLD-c52ff5cf7b4ff71fa14b39ea2e104c7c3d5a1ba8.tar.bz2
opensim-SC_OLD-c52ff5cf7b4ff71fa14b39ea2e104c7c3d5a1ba8.tar.xz
Committing the Avination calling card module
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs286
1 files changed, 286 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs
new file mode 100644
index 0000000..5e2a651
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Friends/CallingCardModule.cs
@@ -0,0 +1,286 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using log4net;
5using Nini.Config;
6using OpenMetaverse;
7using OpenSim.Framework;
8using OpenSim.Region.Framework.Interfaces;
9using OpenSim.Region.Framework.Scenes;
10using OpenSim.Services.Interfaces;
11using Mono.Addins;
12
13namespace Careminster.XCallingCard.Modules
14{
15 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "XCallingCard")]
16 public class CallingCardModule : ISharedRegionModule, ICallingCardModule
17 {
18 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
19 protected List<Scene> m_Scenes = new List<Scene>();
20 protected bool m_Enabled = true;
21
22 public void Initialise(IConfigSource source)
23 {
24 IConfig ccConfig = source.Configs["XCallingCard"];
25 if (ccConfig != null)
26 m_Enabled = ccConfig.GetBoolean("Enabled", true);
27 }
28
29 public void AddRegion(Scene scene)
30 {
31 if (!m_Enabled)
32 return;
33
34 m_Scenes.Add(scene);
35
36 scene.RegisterModuleInterface<ICallingCardModule>(this);
37 }
38
39 public void RemoveRegion(Scene scene)
40 {
41 if (!m_Enabled)
42 return;
43
44 m_Scenes.Remove(scene);
45
46 scene.EventManager.OnNewClient -= OnNewClient;
47 scene.EventManager.OnIncomingInstantMessage +=
48 OnIncomingInstantMessage;
49
50 scene.UnregisterModuleInterface<ICallingCardModule>(this);
51 }
52
53 public void RegionLoaded(Scene scene)
54 {
55 if (!m_Enabled)
56 return;
57 scene.EventManager.OnNewClient += OnNewClient;
58 }
59
60 public void PostInitialise()
61 {
62 }
63
64 public void Close()
65 {
66 }
67
68 public Type ReplaceableInterface
69 {
70 get { return null; }
71 }
72
73 public string Name
74 {
75 get { return "XCallingCardModule"; }
76 }
77
78 private void OnNewClient(IClientAPI client)
79 {
80 client.OnOfferCallingCard += OnOfferCallingCard;
81 client.OnAcceptCallingCard += OnAcceptCallingCard;
82 client.OnDeclineCallingCard += OnDeclineCallingCard;
83 }
84
85 private void OnOfferCallingCard(IClientAPI client, UUID destID, UUID transactionID)
86 {
87 ScenePresence sp = GetClientPresence(client.AgentId);
88 if (sp != null)
89 {
90 // If we're in god mode, we reverse the meaning. Offer
91 // calling card becomes "Take a calling card" for that
92 // person, no matter if they agree or not.
93 if (sp.GodLevel >= 200)
94 {
95 CreateCallingCard(client.AgentId, destID, UUID.Zero, true);
96 return;
97 }
98 }
99
100 IClientAPI dest = FindClientObject(destID);
101 if (dest != null)
102 {
103 DoCallingCardOffer(dest, client.AgentId);
104 return;
105 }
106
107 IMessageTransferModule transferModule =
108 m_Scenes[0].RequestModuleInterface<IMessageTransferModule>();
109
110 if (transferModule != null)
111 {
112 transferModule.SendInstantMessage(new GridInstantMessage(
113 client.Scene, client.AgentId,
114 client.FirstName+" "+client.LastName,
115 destID, (byte)211, false,
116 String.Empty,
117 transactionID, false, new Vector3(), new byte[0]),
118 delegate(bool success) {} );
119 }
120 }
121
122 private void DoCallingCardOffer(IClientAPI dest, UUID from)
123 {
124 UUID itemID = CreateCallingCard(dest.AgentId, from, UUID.Zero, false);
125
126 dest.SendOfferCallingCard(from, itemID);
127 }
128
129 // Create a calling card in the user's inventory. This is called
130 // from direct calling card creation, when the offer is forwarded,
131 // and from the friends module when the friend is confirmed.
132 // Because of the latter, it will send a bulk inventory update
133 // if the receiving user is in the same simulator.
134 public UUID CreateCallingCard(UUID userID, UUID creatorID, UUID folderID)
135 {
136 return CreateCallingCard(userID, creatorID, folderID, false);
137 }
138
139 private UUID CreateCallingCard(UUID userID, UUID creatorID, UUID folderID, bool isGod)
140 {
141 IUserAccountService userv = m_Scenes[0].UserAccountService;
142 if (userv == null)
143 return UUID.Zero;
144
145 UserAccount info = userv.GetUserAccount(UUID.Zero, creatorID);
146 if (info == null)
147 return UUID.Zero;
148
149 IInventoryService inv = m_Scenes[0].InventoryService;
150 if (inv == null)
151 return UUID.Zero;
152
153 if (folderID == UUID.Zero)
154 {
155 InventoryFolderBase folder = inv.GetFolderForType(userID,
156 AssetType.CallingCard);
157
158 if (folder == null) // Nowhere to put it
159 return UUID.Zero;
160
161 folderID = folder.ID;
162 }
163
164 m_log.DebugFormat("[XCALLINGCARD]: Creating calling card for {0} in inventory of {1}", info.Name, userID);
165
166 InventoryItemBase item = new InventoryItemBase();
167 item.AssetID = UUID.Zero;
168 item.AssetType = (int)AssetType.CallingCard;
169 item.BasePermissions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
170 if (isGod)
171 item.BasePermissions = (uint)(PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer | PermissionMask.Move);
172
173 item.EveryOnePermissions = (uint)PermissionMask.None;
174 item.CurrentPermissions = item.BasePermissions;
175 item.NextPermissions = (uint)(PermissionMask.Copy | PermissionMask.Modify);
176
177 item.ID = UUID.Random();
178 item.CreatorId = creatorID.ToString();
179 item.Owner = userID;
180 item.GroupID = UUID.Zero;
181 item.GroupOwned = false;
182 item.Folder = folderID;
183
184 item.CreationDate = Util.UnixTimeSinceEpoch();
185 item.InvType = (int)InventoryType.CallingCard;
186 item.Flags = 0;
187
188 item.Name = info.Name;
189 item.Description = "";
190
191 item.SalePrice = 10;
192 item.SaleType = (byte)SaleType.Not;
193
194 inv.AddItem(item);
195
196 IClientAPI client = FindClientObject(userID);
197 if (client != null)
198 client.SendBulkUpdateInventory(item);
199
200 return item.ID;
201 }
202
203 private void OnAcceptCallingCard(IClientAPI client, UUID transactionID, UUID folderID)
204 {
205 }
206
207 private void OnDeclineCallingCard(IClientAPI client, UUID transactionID)
208 {
209 IInventoryService invService = m_Scenes[0].InventoryService;
210
211 InventoryFolderBase trashFolder =
212 invService.GetFolderForType(client.AgentId, AssetType.TrashFolder);
213
214 InventoryItemBase item = new InventoryItemBase(transactionID, client.AgentId);
215 item = invService.GetItem(item);
216
217 if (item != null && trashFolder != null)
218 {
219 item.Folder = trashFolder.ID;
220 List<UUID> uuids = new List<UUID>();
221 uuids.Add(item.ID);
222 invService.DeleteItems(item.Owner, uuids);
223 m_Scenes[0].AddInventoryItem(client, item);
224 }
225 }
226
227 public IClientAPI FindClientObject(UUID agentID)
228 {
229 Scene scene = GetClientScene(agentID);
230 if (scene == null)
231 return null;
232
233 ScenePresence presence = scene.GetScenePresence(agentID);
234 if (presence == null)
235 return null;
236
237 return presence.ControllingClient;
238 }
239
240 private Scene GetClientScene(UUID agentId)
241 {
242 lock (m_Scenes)
243 {
244 foreach (Scene scene in m_Scenes)
245 {
246 ScenePresence presence = scene.GetScenePresence(agentId);
247 if (presence != null)
248 {
249 if (!presence.IsChildAgent)
250 return scene;
251 }
252 }
253 }
254 return null;
255 }
256
257 private ScenePresence GetClientPresence(UUID agentId)
258 {
259 lock (m_Scenes)
260 {
261 foreach (Scene scene in m_Scenes)
262 {
263 ScenePresence presence = scene.GetScenePresence(agentId);
264 if (presence != null)
265 {
266 if (!presence.IsChildAgent)
267 return presence;
268 }
269 }
270 }
271 return null;
272 }
273
274 private void OnIncomingInstantMessage(GridInstantMessage msg)
275 {
276 if (msg.dialog == (uint)211)
277 {
278 IClientAPI client = FindClientObject(new UUID(msg.toAgentID));
279 if (client == null)
280 return;
281
282 DoCallingCardOffer(client, new UUID(msg.fromAgentID));
283 }
284 }
285 }
286}