aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World
diff options
context:
space:
mode:
authorMelanie Thielker2009-07-10 20:46:16 +0000
committerMelanie Thielker2009-07-10 20:46:16 +0000
commitec1a5d89336570d1cbef64607160bd8ab1a55fb6 (patch)
treefb6995d36b431e7e65c8f46bb7f3c00fba12fd2b /OpenSim/Region/OptionalModules/World
parentCommitting the interface change and the addition to the modules to get (diff)
downloadopensim-SC_OLD-ec1a5d89336570d1cbef64607160bd8ab1a55fb6.zip
opensim-SC_OLD-ec1a5d89336570d1cbef64607160bd8ab1a55fb6.tar.gz
opensim-SC_OLD-ec1a5d89336570d1cbef64607160bd8ab1a55fb6.tar.bz2
opensim-SC_OLD-ec1a5d89336570d1cbef64607160bd8ab1a55fb6.tar.xz
Some module reshuffling, no user functionality yet
Diffstat (limited to 'OpenSim/Region/OptionalModules/World')
-rw-r--r--OpenSim/Region/OptionalModules/World/MoneyModule/Resources/MoneyModulePlugin.addin.xml8
-rw-r--r--OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs869
2 files changed, 877 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/Resources/MoneyModulePlugin.addin.xml b/OpenSim/Region/OptionalModules/World/MoneyModule/Resources/MoneyModulePlugin.addin.xml
new file mode 100644
index 0000000..a25f297
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/World/MoneyModule/Resources/MoneyModulePlugin.addin.xml
@@ -0,0 +1,8 @@
1<Addin id="OpenSim.Region.ReplaceableModules.MoneyModule" version="0.2">
2 <Runtime>
3 <Import assembly="OpenSim.Region.ReplaceableModules.MoneyModule.dll"/>
4 </Runtime>
5 <Dependencies>
6 <Addin id="OpenSim" version="0.5" />
7 </Dependencies>
8</Addin> \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs
new file mode 100644
index 0000000..5471f9e
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs
@@ -0,0 +1,869 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Reflection;
33using log4net;
34using Nini.Config;
35using Nwc.XmlRpc;
36using Mono.Addins;
37using OpenMetaverse;
38using OpenSim.Framework;
39using OpenSim.Framework.Communications.Cache;
40using OpenSim.Framework.Servers.HttpServer;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Region.Framework.Scenes;
43
44[assembly: Addin("SampleMoneyModule", "0.1")]
45[assembly: AddinDependency("OpenSim", "0.5")]
46
47namespace OpenSim.Region.OptionalModules.World.MoneyModule
48{
49 /// <summary>
50 /// This is only the functionality required to make the functionality associated with money work
51 /// (such as land transfers). There is no money code here! Use FORGE as an example for money code.
52 /// Demo Economy/Money Module. This is a purposely crippled module!
53 /// // To land transfer you need to add:
54 /// -helperuri <ADDRESS TO THIS SERVER>
55 /// to the command line parameters you use to start up your client
56 /// This commonly looks like -helperuri http://127.0.0.1:9000/
57 ///
58 /// </summary>
59
60 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
61 public class SampleMoneyModule : IMoneyModule, ISharedRegionModule
62 {
63 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
64
65 /// <summary>
66 /// Where Stipends come from and Fees go to.
67 /// </summary>
68 // private UUID EconomyBaseAccount = UUID.Zero;
69
70 private float EnergyEfficiency = 0f;
71 private bool gridmode = false;
72 // private ObjectPaid handerOnObjectPaid;
73 private bool m_enabled = true;
74 private bool m_sellEnabled = false;
75
76 private IConfigSource m_gConfig;
77
78
79
80 /// <summary>
81 /// Region UUIDS indexed by AgentID
82 /// </summary>
83
84 /// <summary>
85 /// Scenes by Region Handle
86 /// </summary>
87 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
88
89 // private int m_stipend = 1000;
90
91 private int ObjectCapacity = 45000;
92 private int ObjectCount = 0;
93 private int PriceEnergyUnit = 0;
94 private int PriceGroupCreate = 0;
95 private int PriceObjectClaim = 0;
96 private float PriceObjectRent = 0f;
97 private float PriceObjectScaleFactor = 0f;
98 private int PriceParcelClaim = 0;
99 private float PriceParcelClaimFactor = 0f;
100 private int PriceParcelRent = 0;
101 private int PricePublicObjectDecay = 0;
102 private int PricePublicObjectDelete = 0;
103 private int PriceRentLight = 0;
104 private int PriceUpload = 0;
105 private int TeleportMinPrice = 0;
106
107 private float TeleportPriceExponent = 0f;
108
109
110 #region IMoneyModule Members
111
112 public event ObjectPaid OnObjectPaid;
113
114 /// <summary>
115 /// Startup
116 /// </summary>
117 /// <param name="scene"></param>
118 /// <param name="config"></param>
119 public void Initialise(IConfigSource config)
120 {
121 m_gConfig = config;
122
123 IConfig startupConfig = m_gConfig.Configs["Startup"];
124 IConfig economyConfig = m_gConfig.Configs["Economy"];
125
126
127 ReadConfigAndPopulate(startupConfig, "Startup");
128 ReadConfigAndPopulate(economyConfig, "Economy");
129 }
130
131 public void AddRegion(Scene scene)
132 {
133 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
134 scene.SetObjectCapacity(ObjectCapacity);
135
136 if (m_enabled)
137 {
138 scene.RegisterModuleInterface<IMoneyModule>(this);
139 IHttpServer httpServer = MainServer.Instance;
140
141 lock (m_scenel)
142 {
143 if (m_scenel.Count == 0)
144 {
145 // XMLRPCHandler = scene;
146
147 // To use the following you need to add:
148 // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER>
149 // to the command line parameters you use to start up your client
150 // This commonly looks like -helperuri http://127.0.0.1:9000/
151
152
153 // Local Server.. enables functionality only.
154 httpServer.AddXmlRPCHandler("getCurrencyQuote", quote_func);
155 httpServer.AddXmlRPCHandler("buyCurrency", buy_func);
156 httpServer.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
157 httpServer.AddXmlRPCHandler("buyLandPrep", landBuy_func);
158
159 }
160
161 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
162 {
163 m_scenel[scene.RegionInfo.RegionHandle] = scene;
164 }
165 else
166 {
167 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
168 }
169 }
170
171 scene.EventManager.OnNewClient += OnNewClient;
172 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
173 scene.EventManager.OnClientClosed += ClientClosed;
174 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
175 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
176 scene.EventManager.OnClientClosed += ClientLoggedOut;
177 scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
178 scene.EventManager.OnLandBuy += processLandBuy;
179 }
180 }
181
182 public void RemoveRegion(Scene scene)
183 {
184 }
185
186 public void RegionLoaded(Scene scene)
187 {
188 }
189
190
191 // Please do not refactor these to be just one method
192 // Existing implementations need the distinction
193 //
194 public void ApplyUploadCharge(UUID agentID)
195 {
196 }
197
198 public void ApplyGroupCreationCharge(UUID agentID)
199 {
200 }
201
202 public void ApplyCharge(UUID agentID, int amount, string text)
203 {
204 }
205
206 public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount)
207 {
208 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
209
210 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
211
212
213 BalanceUpdate(fromID, toID, give_result, description);
214
215 return give_result;
216 }
217
218 public void PostInitialise()
219 {
220 }
221
222 public void Close()
223 {
224 }
225
226 public Type ReplacableInterface
227 {
228 get { return typeof(IMoneyModule); }
229 }
230
231 public string Name
232 {
233 get { return "BetaGridLikeMoneyModule"; }
234 }
235
236 #endregion
237
238 /// <summary>
239 /// Parse Configuration
240 /// </summary>
241 /// <param name="scene"></param>
242 /// <param name="startupConfig"></param>
243 /// <param name="config"></param>
244 private void ReadConfigAndPopulate(IConfig startupConfig, string config)
245 {
246 if (config == "Startup" && startupConfig != null)
247 {
248 gridmode = startupConfig.GetBoolean("gridmode", false);
249 m_enabled = (startupConfig.GetString("economymodule", "BetaGridLikeMoneyModule") == "BetaGridLikeMoneyModule");
250 }
251
252 if (config == "Economy" && startupConfig != null)
253 {
254 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000);
255 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
256 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
257 PricePublicObjectDecay = startupConfig.GetInt("PricePublicObjectDecay", 4);
258 PricePublicObjectDelete = startupConfig.GetInt("PricePublicObjectDelete", 4);
259 PriceParcelClaim = startupConfig.GetInt("PriceParcelClaim", 1);
260 PriceParcelClaimFactor = startupConfig.GetFloat("PriceParcelClaimFactor", 1f);
261 PriceUpload = startupConfig.GetInt("PriceUpload", 0);
262 PriceRentLight = startupConfig.GetInt("PriceRentLight", 5);
263 TeleportMinPrice = startupConfig.GetInt("TeleportMinPrice", 2);
264 TeleportPriceExponent = startupConfig.GetFloat("TeleportPriceExponent", 2f);
265 EnergyEfficiency = startupConfig.GetFloat("EnergyEfficiency", 1);
266 PriceObjectRent = startupConfig.GetFloat("PriceObjectRent", 1);
267 PriceObjectScaleFactor = startupConfig.GetFloat("PriceObjectScaleFactor", 10);
268 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
269 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
270 m_sellEnabled = startupConfig.GetBoolean("SellEnabled", false);
271 }
272
273 }
274
275 public EconomyData GetEconomyData()
276 {
277 EconomyData edata = new EconomyData();
278 edata.ObjectCapacity = ObjectCapacity;
279 edata.ObjectCount = ObjectCount;
280 edata.PriceEnergyUnit = PriceEnergyUnit;
281 edata.PriceGroupCreate = PriceGroupCreate;
282 edata.PriceObjectClaim = PriceObjectClaim;
283 edata.PriceObjectRent = PriceObjectRent;
284 edata.PriceObjectScaleFactor = PriceObjectScaleFactor;
285 edata.PriceParcelClaim = PriceParcelClaim;
286 edata.PriceParcelClaimFactor = PriceParcelClaimFactor;
287 edata.PriceParcelRent = PriceParcelRent;
288 edata.PricePublicObjectDecay = PricePublicObjectDecay;
289 edata.PricePublicObjectDelete = PricePublicObjectDelete;
290 edata.PriceRentLight = PriceRentLight;
291 edata.PriceUpload = PriceUpload;
292 edata.TeleportMinPrice = TeleportMinPrice;
293 return edata;
294 }
295
296 private void GetClientFunds(IClientAPI client)
297 {
298 // Here we check if we're in grid mode
299 // I imagine that the 'check balance'
300 // function for the client should be here or shortly after
301
302 if (gridmode)
303 {
304 CheckExistAndRefreshFunds(client.AgentId);
305 }
306 else
307 {
308 CheckExistAndRefreshFunds(client.AgentId);
309 }
310
311 }
312
313 /// <summary>
314 /// New Client Event Handler
315 /// </summary>
316 /// <param name="client"></param>
317 private void OnNewClient(IClientAPI client)
318 {
319 GetClientFunds(client);
320
321 // Subscribe to Money messages
322 client.OnEconomyDataRequest += EconomyDataRequestHandler;
323 client.OnMoneyBalanceRequest += SendMoneyBalance;
324 client.OnRequestPayPrice += requestPayPrice;
325 client.OnObjectBuy += ObjectBuy;
326 client.OnLogout += ClientClosed;
327 }
328
329 /// <summary>
330 /// Transfer money
331 /// </summary>
332 /// <param name="Sender"></param>
333 /// <param name="Receiver"></param>
334 /// <param name="amount"></param>
335 /// <returns></returns>
336 private bool doMoneyTransfer(UUID Sender, UUID Receiver, int amount, int transactiontype, string description)
337 {
338 bool result = true;
339
340 return result;
341 }
342
343
344 /// <summary>
345 /// Sends the the stored money balance to the client
346 /// </summary>
347 /// <param name="client"></param>
348 /// <param name="agentID"></param>
349 /// <param name="SessionID"></param>
350 /// <param name="TransactionID"></param>
351 public void SendMoneyBalance(IClientAPI client, UUID agentID, UUID SessionID, UUID TransactionID)
352 {
353 if (client.AgentId == agentID && client.SessionId == SessionID)
354 {
355 int returnfunds = 0;
356
357 try
358 {
359 returnfunds = GetFundsForAgentID(agentID);
360 }
361 catch (Exception e)
362 {
363 client.SendAlertMessage(e.Message + " ");
364 }
365
366 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
367 }
368 else
369 {
370 client.SendAlertMessage("Unable to send your money balance to you!");
371 }
372 }
373
374 private SceneObjectPart findPrim(UUID objectID)
375 {
376 lock (m_scenel)
377 {
378 foreach (Scene s in m_scenel.Values)
379 {
380 SceneObjectPart part = s.GetSceneObjectPart(objectID);
381 if (part != null)
382 {
383 return part;
384 }
385 }
386 }
387 return null;
388 }
389
390 private string resolveObjectName(UUID objectID)
391 {
392 SceneObjectPart part = findPrim(objectID);
393 if (part != null)
394 {
395 return part.Name;
396 }
397 return String.Empty;
398 }
399
400 private string resolveAgentName(UUID agentID)
401 {
402 // try avatar username surname
403 Scene scene = GetRandomScene();
404 CachedUserInfo profile = scene.CommsManager.UserProfileCacheService.GetUserDetails(agentID);
405 if (profile != null && profile.UserProfile != null)
406 {
407 string avatarname = profile.UserProfile.FirstName + " " + profile.UserProfile.SurName;
408 return avatarname;
409 }
410 else
411 {
412 m_log.ErrorFormat(
413 "[MONEY]: Could not resolve user {0}",
414 agentID);
415 }
416
417 return String.Empty;
418 }
419
420 private void BalanceUpdate(UUID senderID, UUID receiverID, bool transactionresult, string description)
421 {
422 IClientAPI sender = LocateClientObject(senderID);
423 IClientAPI receiver = LocateClientObject(receiverID);
424
425 if (senderID != receiverID)
426 {
427 if (sender != null)
428 {
429 sender.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(senderID));
430 }
431
432 if (receiver != null)
433 {
434 receiver.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(description), GetFundsForAgentID(receiverID));
435 }
436 }
437 }
438
439 /// <summary>
440 /// XMLRPC handler to send alert message and sound to client
441 /// </summary>
442 public XmlRpcResponse UserAlert(XmlRpcRequest request, IPEndPoint remoteClient)
443 {
444 XmlRpcResponse ret = new XmlRpcResponse();
445 Hashtable retparam = new Hashtable();
446 Hashtable requestData = (Hashtable) request.Params[0];
447
448 UUID agentId;
449 UUID soundId;
450 UUID regionId;
451
452 UUID.TryParse((string) requestData["agentId"], out agentId);
453 UUID.TryParse((string) requestData["soundId"], out soundId);
454 UUID.TryParse((string) requestData["regionId"], out regionId);
455 string text = (string) requestData["text"];
456 string secret = (string) requestData["secret"];
457
458 Scene userScene = GetSceneByUUID(regionId);
459 if (userScene != null)
460 {
461 if (userScene.RegionInfo.regionSecret == secret)
462 {
463
464 IClientAPI client = LocateClientObject(agentId);
465 if (client != null)
466 {
467
468 if (soundId != UUID.Zero)
469 client.SendPlayAttachedSound(soundId, UUID.Zero, UUID.Zero, 1.0f, 0);
470
471 client.SendBlueBoxMessage(UUID.Zero, "", text);
472
473 retparam.Add("success", true);
474 }
475 else
476 {
477 retparam.Add("success", false);
478 }
479 }
480 else
481 {
482 retparam.Add("success", false);
483 }
484 }
485
486 ret.Value = retparam;
487 return ret;
488 }
489
490 # region Standalone box enablers only
491
492 public XmlRpcResponse quote_func(XmlRpcRequest request, IPEndPoint remoteClient)
493 {
494 // Hashtable requestData = (Hashtable) request.Params[0];
495 // UUID agentId = UUID.Zero;
496 int amount = 0;
497 Hashtable quoteResponse = new Hashtable();
498 XmlRpcResponse returnval = new XmlRpcResponse();
499
500
501 Hashtable currencyResponse = new Hashtable();
502 currencyResponse.Add("estimatedCost", 0);
503 currencyResponse.Add("currencyBuy", amount);
504
505 quoteResponse.Add("success", true);
506 quoteResponse.Add("currency", currencyResponse);
507 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
508
509 returnval.Value = quoteResponse;
510 return returnval;
511
512
513
514 }
515
516 public XmlRpcResponse buy_func(XmlRpcRequest request, IPEndPoint remoteClient)
517 {
518 // Hashtable requestData = (Hashtable) request.Params[0];
519 // UUID agentId = UUID.Zero;
520 // int amount = 0;
521
522 XmlRpcResponse returnval = new XmlRpcResponse();
523 Hashtable returnresp = new Hashtable();
524 returnresp.Add("success", true);
525 returnval.Value = returnresp;
526 return returnval;
527 }
528
529 public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request, IPEndPoint remoteClient)
530 {
531 XmlRpcResponse ret = new XmlRpcResponse();
532 Hashtable retparam = new Hashtable();
533 Hashtable membershiplevels = new Hashtable();
534 ArrayList levels = new ArrayList();
535 Hashtable level = new Hashtable();
536 level.Add("id", "00000000-0000-0000-0000-000000000000");
537 level.Add("description", "some level");
538 levels.Add(level);
539 //membershiplevels.Add("levels",levels);
540
541 Hashtable landuse = new Hashtable();
542 landuse.Add("upgrade", false);
543 landuse.Add("action", "http://invaliddomaininvalid.com/");
544
545 Hashtable currency = new Hashtable();
546 currency.Add("estimatedCost", 0);
547
548 Hashtable membership = new Hashtable();
549 membershiplevels.Add("upgrade", false);
550 membershiplevels.Add("action", "http://invaliddomaininvalid.com/");
551 membershiplevels.Add("levels", membershiplevels);
552
553 retparam.Add("success", true);
554 retparam.Add("currency", currency);
555 retparam.Add("membership", membership);
556 retparam.Add("landuse", landuse);
557 retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf");
558
559 ret.Value = retparam;
560
561 return ret;
562 }
563
564 public XmlRpcResponse landBuy_func(XmlRpcRequest request, IPEndPoint remoteClient)
565 {
566 XmlRpcResponse ret = new XmlRpcResponse();
567 Hashtable retparam = new Hashtable();
568 // Hashtable requestData = (Hashtable) request.Params[0];
569
570 // UUID agentId = UUID.Zero;
571 // int amount = 0;
572
573 retparam.Add("success", true);
574 ret.Value = retparam;
575
576 return ret;
577 }
578
579 #endregion
580
581 #region local Fund Management
582
583 /// <summary>
584 /// Ensures that the agent accounting data is set up in this instance.
585 /// </summary>
586 /// <param name="agentID"></param>
587 private void CheckExistAndRefreshFunds(UUID agentID)
588 {
589
590 }
591
592 /// <summary>
593 /// Gets the amount of Funds for an agent
594 /// </summary>
595 /// <param name="AgentID"></param>
596 /// <returns></returns>
597 private int GetFundsForAgentID(UUID AgentID)
598 {
599 int returnfunds = 0;
600
601 return returnfunds;
602 }
603
604 // private void SetLocalFundsForAgentID(UUID AgentID, int amount)
605 // {
606
607 // }
608
609 #endregion
610
611 #region Utility Helpers
612
613 /// <summary>
614 /// Locates a IClientAPI for the client specified
615 /// </summary>
616 /// <param name="AgentID"></param>
617 /// <returns></returns>
618 private IClientAPI LocateClientObject(UUID AgentID)
619 {
620 ScenePresence tPresence = null;
621 IClientAPI rclient = null;
622
623 lock (m_scenel)
624 {
625 foreach (Scene _scene in m_scenel.Values)
626 {
627 tPresence = _scene.GetScenePresence(AgentID);
628 if (tPresence != null)
629 {
630 if (!tPresence.IsChildAgent)
631 {
632 rclient = tPresence.ControllingClient;
633 }
634 }
635 if (rclient != null)
636 {
637 return rclient;
638 }
639 }
640 }
641 return null;
642 }
643
644 private Scene LocateSceneClientIn(UUID AgentId)
645 {
646 lock (m_scenel)
647 {
648 foreach (Scene _scene in m_scenel.Values)
649 {
650 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
651 if (tPresence != null)
652 {
653 if (!tPresence.IsChildAgent)
654 {
655 return _scene;
656 }
657 }
658 }
659 }
660 return null;
661 }
662
663 /// <summary>
664 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
665 /// </summary>
666 /// <returns></returns>
667 public Scene GetRandomScene()
668 {
669 lock (m_scenel)
670 {
671 foreach (Scene rs in m_scenel.Values)
672 return rs;
673 }
674 return null;
675 }
676
677 /// <summary>
678 /// Utility function to get a Scene by RegionID in a module
679 /// </summary>
680 /// <param name="RegionID"></param>
681 /// <returns></returns>
682 public Scene GetSceneByUUID(UUID RegionID)
683 {
684 lock (m_scenel)
685 {
686 foreach (Scene rs in m_scenel.Values)
687 {
688 if (rs.RegionInfo.originRegionID == RegionID)
689 {
690 return rs;
691 }
692 }
693 }
694 return null;
695 }
696
697 #endregion
698
699 #region event Handlers
700
701 public void requestPayPrice(IClientAPI client, UUID objectID)
702 {
703 Scene scene = LocateSceneClientIn(client.AgentId);
704 if (scene == null)
705 return;
706
707 SceneObjectPart task = scene.GetSceneObjectPart(objectID);
708 if (task == null)
709 return;
710 SceneObjectGroup group = task.ParentGroup;
711 SceneObjectPart root = group.RootPart;
712
713 client.SendPayPrice(objectID, root.PayPrice);
714 }
715
716 /// <summary>
717 /// When the client closes the connection we remove their accounting info from memory to free up resources.
718 /// </summary>
719 /// <param name="AgentID"></param>
720 public void ClientClosed(UUID AgentID, Scene scene)
721 {
722
723 }
724
725 /// <summary>
726 /// Event called Economy Data Request handler.
727 /// </summary>
728 /// <param name="agentId"></param>
729 public void EconomyDataRequestHandler(UUID agentId)
730 {
731 IClientAPI user = LocateClientObject(agentId);
732
733 if (user != null)
734 {
735 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
736 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
737 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
738 TeleportMinPrice, TeleportPriceExponent);
739 }
740 }
741
742 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
743 {
744
745
746 lock (e)
747 {
748 e.economyValidated = true;
749 }
750
751
752 }
753
754 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
755 {
756
757 }
758
759 /// <summary>
760 /// THis method gets called when someone pays someone else as a gift.
761 /// </summary>
762 /// <param name="osender"></param>
763 /// <param name="e"></param>
764 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
765 {
766
767 }
768
769 /// <summary>
770 /// Event Handler for when a root agent becomes a child agent
771 /// </summary>
772 /// <param name="avatar"></param>
773 private void MakeChildAgent(ScenePresence avatar)
774 {
775
776 }
777
778 /// <summary>
779 /// Event Handler for when the client logs out.
780 /// </summary>
781 /// <param name="AgentId"></param>
782 private void ClientLoggedOut(UUID AgentId, Scene scene)
783 {
784
785 }
786
787 /// <summary>
788 /// Call this when the client disconnects.
789 /// </summary>
790 /// <param name="client"></param>
791 public void ClientClosed(IClientAPI client)
792 {
793 ClientClosed(client.AgentId, null);
794 }
795
796 /// <summary>
797 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
798 /// </summary>
799 /// <param name="avatar"></param>
800 /// <param name="localLandID"></param>
801 /// <param name="regionID"></param>
802 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
803 {
804
805 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
806 }
807
808 public int GetBalance(IClientAPI client)
809 {
810 return 0;
811 }
812
813 // Please do not refactor these to be just one method
814 // Existing implementations need the distinction
815 //
816 public bool UploadCovered(IClientAPI client)
817 {
818 return AmountCovered(client, PriceUpload);
819 }
820
821 public bool GroupCreationCovered(IClientAPI client)
822 {
823 return AmountCovered(client, PriceGroupCreate);
824 }
825
826 public bool AmountCovered(IClientAPI client, int amount)
827 {
828 return true;
829 }
830
831 #endregion
832
833 public void ObjectBuy(IClientAPI remoteClient, UUID agentID,
834 UUID sessionID, UUID groupID, UUID categoryID,
835 uint localID, byte saleType, int salePrice)
836 {
837 if (!m_sellEnabled)
838 {
839 remoteClient.SendBlueBoxMessage(UUID.Zero, "", "Buying is not implemented in this version");
840 return;
841 }
842
843 if (salePrice != 0)
844 {
845 remoteClient.SendBlueBoxMessage(UUID.Zero, "", "Buying anything for a price other than zero is not implemented");
846 return;
847 }
848
849 Scene s = LocateSceneClientIn(remoteClient.AgentId);
850 SceneObjectPart part = s.GetSceneObjectPart(localID);
851 if (part == null)
852 {
853 remoteClient.SendAgentAlertMessage("Unable to buy now. The object was not found.", false);
854 return;
855 }
856 s.PerformObjectBuy(remoteClient, categoryID, localID, saleType);
857 }
858 }
859
860 public enum TransactionType : int
861 {
862 SystemGenerated = 0,
863 RegionMoneyRequest = 1,
864 Gift = 2,
865 Purchase = 3
866 }
867
868
869}