aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules
diff options
context:
space:
mode:
authorTeravus Ovares2008-04-23 22:44:59 +0000
committerTeravus Ovares2008-04-23 22:44:59 +0000
commit1909d74d5fa8e6cea151bb5ff6b8e40b197b9f90 (patch)
treee2f37410f60a2b038c7ced800008491c7d0f1d88 /OpenSim/Region/Environment/Modules
parent* Add NUnit to CONTRIBUTORS file (diff)
downloadopensim-SC_OLD-1909d74d5fa8e6cea151bb5ff6b8e40b197b9f90.zip
opensim-SC_OLD-1909d74d5fa8e6cea151bb5ff6b8e40b197b9f90.tar.gz
opensim-SC_OLD-1909d74d5fa8e6cea151bb5ff6b8e40b197b9f90.tar.bz2
opensim-SC_OLD-1909d74d5fa8e6cea151bb5ff6b8e40b197b9f90.tar.xz
* Patch from Melanie. Mantis 0001037: Add various internal plumbing to the example economy module, implements llSetPayPrice(), money() and llGiveMoney() in scripts. Thanks Melanie!
* Moves module loading before the script engine so the script engine can pick up events from modules registering interfaces with scene.
Diffstat (limited to 'OpenSim/Region/Environment/Modules')
-rw-r--r--OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs121
1 files changed, 119 insertions, 2 deletions
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
index d5b2ea2..8e14ec5 100644
--- a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
@@ -53,8 +53,22 @@ namespace OpenSim.Region.Environment.Modules
53 /// Centralized grid structure example using OpenSimWi Redux revision 9+ 53 /// Centralized grid structure example using OpenSimWi Redux revision 9+
54 /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux 54 /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux
55 /// </summary> 55 /// </summary>
56 public class BetaGridLikeMoneyModule: IRegionModule 56
57 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount);
58
59 public interface IMoneyModule : IRegionModule
60 {
61 bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount);
62
63 event ObjectPaid OnObjectPaid;
64 }
65
66 public class BetaGridLikeMoneyModule: IMoneyModule
57 { 67 {
68 public event ObjectPaid OnObjectPaid;
69
70 private ObjectPaid handerOnObjectPaid;
71
58 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
59 73
60 /// <summary> 74 /// <summary>
@@ -120,7 +134,7 @@ namespace OpenSim.Region.Environment.Modules
120 IConfig startupConfig = m_gConfig.Configs["Startup"]; 134 IConfig startupConfig = m_gConfig.Configs["Startup"];
121 IConfig economyConfig = m_gConfig.Configs["Economy"]; 135 IConfig economyConfig = m_gConfig.Configs["Economy"];
122 136
123 137 scene.RegisterModuleInterface<IMoneyModule>(this);
124 138
125 ReadConfigAndPopulate(scene, startupConfig, "Startup"); 139 ReadConfigAndPopulate(scene, startupConfig, "Startup");
126 ReadConfigAndPopulate(scene, economyConfig, "Economy"); 140 ReadConfigAndPopulate(scene, economyConfig, "Economy");
@@ -298,6 +312,7 @@ namespace OpenSim.Region.Environment.Modules
298 // Subscribe to Money messages 312 // Subscribe to Money messages
299 client.OnEconomyDataRequest += EconomyDataRequestHandler; 313 client.OnEconomyDataRequest += EconomyDataRequestHandler;
300 client.OnMoneyBalanceRequest += SendMoneyBalance; 314 client.OnMoneyBalanceRequest += SendMoneyBalance;
315 client.OnRequestPayPrice += requestPayPrice;
301 client.OnLogout += ClientClosed; 316 client.OnLogout += ClientClosed;
302 317
303 318
@@ -305,6 +320,21 @@ namespace OpenSim.Region.Environment.Modules
305 320
306 #region event Handlers 321 #region event Handlers
307 322
323 public void requestPayPrice(IClientAPI client, LLUUID objectID)
324 {
325 Scene scene=LocateSceneClientIn(client.AgentId);
326 if(scene == null)
327 return;
328
329 SceneObjectPart task=scene.GetSceneObjectPart(objectID);
330 if(task == null)
331 return;
332 SceneObjectGroup group=task.ParentGroup;
333 SceneObjectPart root=group.RootPart;
334
335 client.SendPayPrice(objectID, root.PayPrice);
336 }
337
308 /// <summary> 338 /// <summary>
309 /// When the client closes the connection we remove their accounting info from memory to free up resources. 339 /// When the client closes the connection we remove their accounting info from memory to free up resources.
310 /// </summary> 340 /// </summary>
@@ -400,6 +430,48 @@ namespace OpenSim.Region.Environment.Modules
400 IClientAPI sender = null; 430 IClientAPI sender = null;
401 IClientAPI receiver = null; 431 IClientAPI receiver = null;
402 432
433 if(m_MoneyAddress.Length > 0) // Handled on server
434 e.description=String.Empty;
435
436 if(e.transactiontype == 5008) // Object gets paid
437 {
438 sender = LocateClientObject(e.sender);
439 if (sender != null)
440 {
441 SceneObjectPart part=findPrim(e.receiver);
442 if(part == null)
443 return;
444
445 string name=resolveAgentName(part.OwnerID);
446 if(name == String.Empty)
447 name="(hippos)";
448
449 receiver = LocateClientObject(part.OwnerID);
450
451 string description=String.Format("Paid {0} via object {1}", name, e.description);
452 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
453
454 if(transactionresult)
455 {
456 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
457 if(handlerOnObjectPaid != null)
458 {
459 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
460 }
461 }
462
463 if (e.sender != e.receiver)
464 {
465 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
466 }
467 if(receiver != null)
468 {
469 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
470 }
471 }
472 return;
473 }
474
403 sender = LocateClientObject(e.sender); 475 sender = LocateClientObject(e.sender);
404 if (sender != null) 476 if (sender != null)
405 { 477 {
@@ -923,6 +995,51 @@ namespace OpenSim.Region.Environment.Modules
923 return MoneyRespData; 995 return MoneyRespData;
924 } 996 }
925 997
998 private SceneObjectPart findPrim(LLUUID objectID)
999 {
1000 lock (m_scenel)
1001 {
1002 foreach (Scene s in m_scenel.Values)
1003 {
1004 SceneObjectPart part=s.GetSceneObjectPart(objectID);
1005 if(part != null)
1006 {
1007 return part;
1008 }
1009 }
1010 }
1011 return null;
1012 }
1013
1014 private string resolveObjectName(LLUUID objectID)
1015 {
1016 SceneObjectPart part=findPrim(objectID);
1017 if(part != null)
1018 {
1019 return part.Name;
1020 }
1021 return String.Empty;
1022 }
1023
1024 private string resolveAgentName(LLUUID agentID)
1025 {
1026 // try avatar username surname
1027 Scene scene=GetRandomScene();
1028 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID);
1029 if (profile != null)
1030 {
1031 string avatarname = profile.FirstName + " " + profile.SurName;
1032 return avatarname;
1033 }
1034 return String.Empty;
1035 }
1036
1037 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
1038 {
1039 string description=String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
1040 return doMoneyTransfer(fromID, toID, amount, 2, description);
1041 }
1042
926 /// <summary> 1043 /// <summary>
927 /// Informs the Money Grid Server of a transfer. 1044 /// Informs the Money Grid Server of a transfer.
928 /// </summary> 1045 /// </summary>