aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
authorTeravus Ovares2008-02-05 05:26:18 +0000
committerTeravus Ovares2008-02-05 05:26:18 +0000
commitca5aadfbff63e03b7ca081e753204d8da040c9bb (patch)
treee2d19e01678c27cff57bc26257cec7385c3df274 /OpenSim/Region/Environment
parentAdded copyright statements. (diff)
downloadopensim-SC_OLD-ca5aadfbff63e03b7ca081e753204d8da040c9bb.zip
opensim-SC_OLD-ca5aadfbff63e03b7ca081e753204d8da040c9bb.tar.gz
opensim-SC_OLD-ca5aadfbff63e03b7ca081e753204d8da040c9bb.tar.bz2
opensim-SC_OLD-ca5aadfbff63e03b7ca081e753204d8da040c9bb.tar.xz
* Refactored the sound calls to SceneObjectPart
* Fixed a few bugs * Wrote an example module to make certain event systems more mature.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs324
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs2
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneEvents.cs12
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneObjectPart.cs78
4 files changed, 416 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
new file mode 100644
index 0000000..81478a1
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
@@ -0,0 +1,324 @@
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 OpenSim 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
29using Nini.Config;
30using System;
31using System.Collections;
32using System.Collections.Generic;
33using OpenSim.Framework;
34using OpenSim.Framework.Console;
35using OpenSim.Region.Environment.Interfaces;
36using OpenSim.Region.Environment.Scenes;
37using libsecondlife;
38using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs;
39
40namespace OpenSim.Region.Environment.Modules
41{
42 public class BetaGridLikeMoneyModule: IRegionModule
43 {
44
45 private LogBase m_log;
46
47 private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>();
48
49 private IConfigSource m_gConfig;
50
51 private bool m_keepMoneyAcrossLogins = true;
52
53 private int m_minFundsBeforeRefresh = 100;
54
55 private int m_stipend = 1000;
56
57 private bool m_enabled = true;
58
59
60
61 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
62
63
64
65 private bool gridmode = false;
66
67 public void Initialise(Scene scene, IConfigSource config)
68 {
69 m_log = MainLog.Instance;
70
71 m_gConfig = config;
72 ReadConfigAndPopulate();
73
74 if (m_enabled)
75 {
76 lock (m_scenel)
77 {
78
79 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
80 {
81 m_scenel[scene.RegionInfo.RegionHandle] = scene;
82 }
83 else
84 {
85 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
86 }
87 }
88
89 scene.EventManager.OnNewClient += OnNewClient;
90 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
91 scene.EventManager.OnClientClosed += ClientClosed;
92 }
93 }
94 private void ReadConfigAndPopulate()
95 {
96 IConfig startupConfig = m_gConfig.Configs["Startup"];
97 gridmode = startupConfig.GetBoolean("gridmode", false);
98 m_enabled = (startupConfig.GetString("moneymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
99
100 }
101
102 private void OnNewClient(IClientAPI client)
103 {
104 // Here we check if we're in grid mode
105 // I imagine that the 'check balance'
106 // function for the client should be here or shortly after
107
108 if (gridmode)
109 {
110 CheckExistAndRefreshFunds(client.AgentId);
111 }
112 else
113 {
114 CheckExistAndRefreshFunds(client.AgentId);
115 }
116
117 // Subscribe to Money messages
118 client.OnMoneyBalanceRequest += SendMoneyBalance;
119 client.OnLogout += ClientClosed;
120
121 }
122
123 public void ClientClosed(LLUUID AgentID)
124 {
125 lock (m_KnownClientFunds)
126 {
127 if (!m_keepMoneyAcrossLogins)
128 m_KnownClientFunds.Remove(AgentID);
129 }
130
131 }
132
133 private void MoneyTransferAction (Object osender, MoneyTransferArgs e)
134 {
135 IClientAPI sender = null;
136 IClientAPI receiver = null;
137
138 sender = LocateClientObject(e.sender);
139 if (sender != null)
140 {
141
142
143 receiver = LocateClientObject(e.reciever);
144 bool transactionresult = doMoneyTranfer(e.sender, e.reciever, e.amount);
145
146 if (e.sender != e.reciever)
147 {
148 if (sender != null)
149 {
150 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
151 }
152 }
153
154 if (receiver != null)
155 {
156 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.reciever));
157 }
158
159
160 }
161 else
162 {
163 MainLog.Instance.Warn("MONEY", "Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Reciver: " + e.reciever.ToString() + " Amount: " + e.amount.ToString());
164 }
165
166
167
168 }
169
170 private bool doMoneyTranfer(LLUUID Sender, LLUUID Receiver, int amount)
171 {
172 bool result = false;
173 if (amount >= 0)
174 {
175 lock (m_KnownClientFunds)
176 {
177 // If we don't know about the sender, then the sender can't
178 // actually be here and therefore this is likely fraud or outdated.
179 if (m_KnownClientFunds.ContainsKey(Sender))
180 {
181 // Does the sender have enough funds to give?
182 if (m_KnownClientFunds[Sender] >= amount)
183 {
184 // Subtract the funds from the senders account
185 m_KnownClientFunds[Sender] -= amount;
186
187 // do we know about the receiver?
188 if (!m_KnownClientFunds.ContainsKey(Receiver))
189 {
190 // Make a record for them so they get the updated balance when they login
191 CheckExistAndRefreshFunds(Receiver);
192 }
193
194 //Add the amount to the Receiver's funds
195 m_KnownClientFunds[Receiver] += amount;
196 result = true;
197 }
198 else
199 {
200 // These below are redundant to make this clearer to read
201 result = false;
202 }
203 }
204 else
205 {
206 result = false;
207 }
208 }
209 }
210 return result;
211 }
212
213 private IClientAPI LocateClientObject(LLUUID AgentID)
214 {
215 ScenePresence tPresence = null;
216 IClientAPI rclient = null;
217
218 lock (m_scenel)
219 {
220 foreach (Scene _scene in m_scenel.Values)
221 {
222 tPresence = _scene.GetScenePresence(AgentID);
223 if (tPresence != null)
224 {
225 if (!tPresence.IsChildAgent)
226 {
227 rclient = tPresence.ControllingClient;
228 }
229 }
230 if (rclient != null)
231 {
232 return rclient;
233 }
234 }
235
236 }
237 return null;
238 }
239
240 public void ClientClosed(IClientAPI client)
241 {
242 ClientClosed(client.AgentId);
243 }
244
245 public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID)
246 {
247 if (client.AgentId == agentID && client.SessionId == SessionID)
248 {
249
250 int returnfunds = 0;
251
252 try
253 {
254 returnfunds = GetFundsForAgentID(agentID);
255 }
256 catch (System.Exception e)
257 {
258 client.SendAlertMessage(e.Message + " ");
259 }
260
261 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
262 }
263 else
264 {
265 client.SendAlertMessage("Unable to send your money balance to you!");
266 }
267 }
268
269 private void CheckExistAndRefreshFunds(LLUUID agentID)
270 {
271 lock (m_KnownClientFunds)
272 {
273 if (!m_KnownClientFunds.ContainsKey(agentID))
274 {
275 m_KnownClientFunds.Add(agentID, m_stipend);
276 }
277 else
278 {
279 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
280 {
281 m_KnownClientFunds[agentID] = m_stipend;
282 }
283 }
284 }
285 }
286 private int GetFundsForAgentID(LLUUID AgentID)
287 {
288 int returnfunds = 0;
289 lock (m_KnownClientFunds)
290 {
291 if (m_KnownClientFunds.ContainsKey(AgentID))
292 {
293 returnfunds = m_KnownClientFunds[AgentID];
294 }
295 else
296 {
297 throw new Exception("Unable to get funds.");
298 }
299 }
300 return returnfunds;
301 }
302
303 public void PostInitialise()
304 {
305 }
306
307
308
309 public void Close()
310 {
311 }
312
313 public string Name
314 {
315 get { return "BetaGridLikeMoneyModule"; }
316 }
317
318 public bool IsSharedModule
319 {
320 get { return true; }
321 }
322 }
323
324}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 89fd5ea..a80426b 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1315,6 +1315,8 @@ namespace OpenSim.Region.Environment.Scenes
1315 avatar.AbsolutePosition.Z); 1315 avatar.AbsolutePosition.Z);
1316 m_sceneGridService.SendCloseChildAgentConnections(avatar); 1316 m_sceneGridService.SendCloseChildAgentConnections(avatar);
1317 } 1317 }
1318
1319 m_eventManager.TriggerClientClosed(agentID);
1318 } 1320 }
1319 catch (NullReferenceException) 1321 catch (NullReferenceException)
1320 { 1322 {
diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
index 51d1b32..cada991 100644
--- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
@@ -125,6 +125,10 @@ namespace OpenSim.Region.Environment.Scenes
125 125
126 public event NewGridInstantMessage OnGridInstantMessageToGroupsModule; 126 public event NewGridInstantMessage OnGridInstantMessageToGroupsModule;
127 127
128 public delegate void ClientClosed(LLUUID clientID);
129
130 public event ClientClosed OnClientClosed;
131
128 public delegate void ScriptChangedEvent(uint localID, uint change); 132 public delegate void ScriptChangedEvent(uint localID, uint change);
129 133
130 public event ScriptChangedEvent OnScriptChangedEvent; 134 public event ScriptChangedEvent OnScriptChangedEvent;
@@ -338,6 +342,14 @@ namespace OpenSim.Region.Environment.Scenes
338 342
339 } 343 }
340 } 344 }
345
346 public void TriggerClientClosed(LLUUID ClientID)
347 {
348 if (OnClientClosed != null)
349 {
350 OnClientClosed(ClientID);
351 }
352 }
341 353
342 } 354 }
343} \ No newline at end of file 355} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
index 159eaf1..0ba64f2 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs
@@ -1457,6 +1457,84 @@ namespace OpenSim.Region.Environment.Scenes
1457 1457
1458 #endregion 1458 #endregion
1459 1459
1460 #region Sound
1461 public void PreloadSound(string sound)
1462 {
1463 LLUUID ownerID = OwnerID;
1464 LLUUID objectID = UUID;
1465 LLUUID soundID = LLUUID.Zero;
1466
1467 if (!LLUUID.TryParse(sound, out soundID))
1468 {
1469 //Trys to fetch sound id from prim's inventory.
1470 //Prim's inventory doesn't support non script items yet
1471 SceneObjectPart op = this;
1472 foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
1473 {
1474 if (item.Value.Name == sound)
1475 {
1476 soundID = item.Value.ItemID;
1477 break;
1478 }
1479 }
1480 }
1481
1482 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
1483 foreach (ScenePresence p in avatarts)
1484 {
1485 // TODO: some filtering by distance of avatar
1486
1487 p.ControllingClient.SendPreLoadSound(objectID, objectID, soundID);
1488 }
1489 }
1490
1491 public void SendSound(string sound, double volume, bool triggered)
1492 {
1493 if (volume > 1)
1494 volume = 1;
1495 if (volume < 0)
1496 volume = 0;
1497
1498 LLUUID ownerID = OwnerID;
1499 LLUUID objectID = UUID;
1500 LLUUID parentID = GetRootPartUUID();
1501 LLUUID soundID = LLUUID.Zero;
1502 LLVector3 position = AbsolutePosition; // region local
1503 ulong regionHandle = m_parentGroup.Scene.RegionInfo.RegionHandle;
1504
1505 byte flags = 0;
1506
1507 if (!LLUUID.TryParse(sound, out soundID))
1508 {
1509 // search sound file from inventory
1510 SceneObjectPart op = this;
1511 foreach (KeyValuePair<LLUUID, TaskInventoryItem> item in op.TaskInventory)
1512 {
1513 if (item.Value.Name == sound)
1514 {
1515 soundID = item.Value.ItemID;
1516 break;
1517 }
1518 }
1519 }
1520
1521 List<ScenePresence> avatarts = m_parentGroup.Scene.GetAvatars();
1522 foreach (ScenePresence p in avatarts)
1523 {
1524 // TODO: some filtering by distance of avatar
1525 if (triggered)
1526 {
1527 p.ControllingClient.SendTriggeredSound(soundID, ownerID, objectID, parentID, regionHandle, position, (float)volume);
1528 }
1529 else
1530 {
1531 p.ControllingClient.SendPlayAttachedSound(soundID, objectID, ownerID, (float)volume, flags);
1532 }
1533 }
1534 }
1535
1536 #endregion
1537
1460 #region Resizing/Scale 1538 #region Resizing/Scale
1461 1539
1462 /// <summary> 1540 /// <summary>