aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ReplaceableModules/MoneyModule
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ReplaceableModules/MoneyModule')
-rw-r--r--OpenSim/Region/ReplaceableModules/MoneyModule/SampleMoneyModule.cs866
1 files changed, 48 insertions, 818 deletions
diff --git a/OpenSim/Region/ReplaceableModules/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/ReplaceableModules/MoneyModule/SampleMoneyModule.cs
index 7d79102..0ea49e9 100644
--- a/OpenSim/Region/ReplaceableModules/MoneyModule/SampleMoneyModule.cs
+++ b/OpenSim/Region/ReplaceableModules/MoneyModule/SampleMoneyModule.cs
@@ -28,10 +28,7 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net;
32using System.Net.Sockets;
33using System.Reflection; 31using System.Reflection;
34using System.Xml;
35using log4net; 32using log4net;
36using Nini.Config; 33using Nini.Config;
37using Nwc.XmlRpc; 34using Nwc.XmlRpc;
@@ -45,15 +42,14 @@ using OpenSim.Region.Framework.Scenes;
45namespace OpenSim.Region.ReplaceableModules.MoneyModule 42namespace OpenSim.Region.ReplaceableModules.MoneyModule
46{ 43{
47 /// <summary> 44 /// <summary>
48 /// Demo Economy/Money Module. This is not a production quality money/economy module! 45 /// This is only the functionality required to make the functionality associated with money work
49 /// This is a demo for you to use when making one that works for you. 46 /// (such as land transfers). There is no money code here! Use FORGE as an example for money code.
50 /// // To use the following you need to add: 47 /// Demo Economy/Money Module. This is a purposely crippled module!
51 /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> 48 /// // To land transfer you need to add:
49 /// -helperuri <ADDRESS TO THIS SERVER>
52 /// to the command line parameters you use to start up your client 50 /// to the command line parameters you use to start up your client
53 /// This commonly looks like -helperuri http://127.0.0.1:9000/ 51 /// This commonly looks like -helperuri http://127.0.0.1:9000/
54 /// 52 ///
55 /// Centralized grid structure example using OpenSimWi Redux revision 9+
56 /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux
57 /// </summary> 53 /// </summary>
58 public class SampleMoneyModule : IMoneyModule, IRegionModule 54 public class SampleMoneyModule : IMoneyModule, IRegionModule
59 { 55 {
@@ -71,17 +67,11 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
71 67
72 private IConfigSource m_gConfig; 68 private IConfigSource m_gConfig;
73 69
74 private bool m_keepMoneyAcrossLogins = true;
75 private Dictionary<UUID, int> m_KnownClientFunds = new Dictionary<UUID, int>();
76 // private string m_LandAddress = String.Empty;
77 70
78 private int m_minFundsBeforeRefresh = 100;
79 private string m_MoneyAddress = String.Empty;
80 71
81 /// <summary> 72 /// <summary>
82 /// Region UUIDS indexed by AgentID 73 /// Region UUIDS indexed by AgentID
83 /// </summary> 74 /// </summary>
84 private Dictionary<UUID, UUID> m_rootAgents = new Dictionary<UUID, UUID>();
85 75
86 /// <summary> 76 /// <summary>
87 /// Scenes by Region Handle 77 /// Scenes by Region Handle
@@ -107,8 +97,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
107 private int TeleportMinPrice = 0; 97 private int TeleportMinPrice = 0;
108 98
109 private float TeleportPriceExponent = 0f; 99 private float TeleportPriceExponent = 0f;
110 // private int UserLevelPaysFees = 2; 100
111 // private Scene XMLRPCHandler;
112 101
113 #region IMoneyModule Members 102 #region IMoneyModule Members
114 103
@@ -146,21 +135,13 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
146 // to the command line parameters you use to start up your client 135 // to the command line parameters you use to start up your client
147 // This commonly looks like -helperuri http://127.0.0.1:9000/ 136 // This commonly looks like -helperuri http://127.0.0.1:9000/
148 137
149 if (m_MoneyAddress.Length > 0) 138
150 { 139 // Local Server.. enables functionality only.
151 // Centralized grid structure using OpenSimWi Redux revision 9+ 140 httpServer.AddXmlRPCHandler("getCurrencyQuote", quote_func);
152 // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux 141 httpServer.AddXmlRPCHandler("buyCurrency", buy_func);
153 httpServer.AddXmlRPCHandler("balanceUpdateRequest", GridMoneyUpdate); 142 httpServer.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
154 httpServer.AddXmlRPCHandler("userAlert", UserAlert); 143 httpServer.AddXmlRPCHandler("buyLandPrep", landBuy_func);
155 } 144
156 else
157 {
158 // Local Server.. enables functionality only.
159 httpServer.AddXmlRPCHandler("getCurrencyQuote", quote_func);
160 httpServer.AddXmlRPCHandler("buyCurrency", buy_func);
161 httpServer.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
162 httpServer.AddXmlRPCHandler("buyLandPrep", landBuy_func);
163 }
164 } 145 }
165 146
166 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) 147 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
@@ -205,8 +186,8 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
205 186
206 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description); 187 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
207 188
208 if (m_MoneyAddress.Length == 0) 189
209 BalanceUpdate(fromID, toID, give_result, description); 190 BalanceUpdate(fromID, toID, give_result, description);
210 191
211 return give_result; 192 return give_result;
212 } 193 }
@@ -268,9 +249,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
268 249
269 // UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); 250 // UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1);
270 m_stipend = startupConfig.GetInt("UserStipend", 1000); 251 m_stipend = startupConfig.GetInt("UserStipend", 1000);
271 m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10); 252
272 m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true);
273 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty);
274 // m_LandAddress = startupConfig.GetString("LandServer", String.Empty); 253 // m_LandAddress = startupConfig.GetString("LandServer", String.Empty);
275 } 254 }
276 255
@@ -307,65 +286,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
307 286
308 if (gridmode) 287 if (gridmode)
309 { 288 {
310 if (m_MoneyAddress.Length == 0) 289 CheckExistAndRefreshFunds(client.AgentId);
311 {
312 CheckExistAndRefreshFunds(client.AgentId);
313 }
314 else
315 {
316 bool childYN = true;
317 ScenePresence agent = null;
318 //client.SecureSessionId;
319 Scene s = LocateSceneClientIn(client.AgentId);
320 if (s != null)
321 {
322 agent = s.GetScenePresence(client.AgentId);
323 if (agent != null)
324 childYN = agent.IsChildAgent;
325 }
326 if (s != null && agent != null && childYN == false)
327 {
328 //s.RegionInfo.RegionHandle;
329 UUID agentID = UUID.Zero;
330 int funds = 0;
331
332 Hashtable hbinfo =
333 GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID,
334 s.RegionInfo.regionSecret);
335 if ((bool) hbinfo["success"] == true)
336 {
337 UUID.TryParse((string)hbinfo["agentId"], out agentID);
338 try
339 {
340 funds = (Int32) hbinfo["funds"];
341 }
342 catch (ArgumentException)
343 {
344 }
345 catch (FormatException)
346 {
347 }
348 catch (OverflowException)
349 {
350 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID);
351 client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
352 }
353 catch (InvalidCastException)
354 {
355 funds = 0;
356 }
357
358 m_KnownClientFunds[agentID] = funds;
359 }
360 else
361 {
362 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID,
363 (string) hbinfo["errorMessage"]);
364 client.SendAlertMessage((string) hbinfo["errorMessage"]);
365 }
366 SendMoneyBalance(client, agentID, client.SessionId, UUID.Zero);
367 }
368 }
369 } 290 }
370 else 291 else
371 { 292 {
@@ -399,53 +320,8 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
399 /// <returns></returns> 320 /// <returns></returns>
400 private bool doMoneyTransfer(UUID Sender, UUID Receiver, int amount, int transactiontype, string description) 321 private bool doMoneyTransfer(UUID Sender, UUID Receiver, int amount, int transactiontype, string description)
401 { 322 {
402 bool result = false; 323 bool result = true;
403 if (amount >= 0) 324
404 {
405 lock (m_KnownClientFunds)
406 {
407 // If we don't know about the sender, then the sender can't
408 // actually be here and therefore this is likely fraud or outdated.
409 if (m_MoneyAddress.Length == 0)
410 {
411 if (m_KnownClientFunds.ContainsKey(Sender))
412 {
413 // Does the sender have enough funds to give?
414 if (m_KnownClientFunds[Sender] >= amount)
415 {
416 // Subtract the funds from the senders account
417 m_KnownClientFunds[Sender] -= amount;
418
419 // do we know about the receiver?
420 if (!m_KnownClientFunds.ContainsKey(Receiver))
421 {
422 // Make a record for them so they get the updated balance when they login
423 CheckExistAndRefreshFunds(Receiver);
424 }
425 if (m_enabled)
426 {
427 //Add the amount to the Receiver's funds
428 m_KnownClientFunds[Receiver] += amount;
429 result = true;
430 }
431 }
432 else
433 {
434 // These below are redundant to make this clearer to read
435 result = false;
436 }
437 }
438 else
439 {
440 result = false;
441 }
442 }
443 else
444 {
445 result = TransferMoneyonMoneyServer(Sender, Receiver, amount, transactiontype, description);
446 }
447 }
448 }
449 return result; 325 return result;
450 } 326 }
451 327
@@ -480,126 +356,6 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
480 } 356 }
481 } 357 }
482 358
483 /// <summary>
484 /// Gets the current balance for the user from the Grid Money Server
485 /// </summary>
486 /// <param name="agentId"></param>
487 /// <param name="secureSessionID"></param>
488 /// <param name="regionId"></param>
489 /// <param name="regionSecret"></param>
490 /// <returns></returns>
491 public Hashtable GetBalanceForUserFromMoneyServer(UUID agentId, UUID secureSessionID, UUID regionId, string regionSecret)
492 {
493 Hashtable MoneyBalanceRequestParams = new Hashtable();
494 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
495 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
496 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
497 MoneyBalanceRequestParams["secret"] = regionSecret;
498 MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system
499
500 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorUserBalanceRequest");
501
502 return MoneyRespData;
503 }
504
505
506 /// <summary>
507 /// Generic XMLRPC client abstraction
508 /// </summary>
509 /// <param name="ReqParams">Hashtable containing parameters to the method</param>
510 /// <param name="method">Method to invoke</param>
511 /// <returns>Hashtable with success=>bool and other values</returns>
512 public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method)
513 {
514 ArrayList SendParams = new ArrayList();
515 SendParams.Add(ReqParams);
516 // Send Request
517 XmlRpcResponse MoneyResp;
518 try
519 {
520 XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams);
521 MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000);
522 }
523 catch (WebException ex)
524 {
525 m_log.ErrorFormat(
526 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
527 m_MoneyAddress, ex);
528
529 Hashtable ErrorHash = new Hashtable();
530 ErrorHash["success"] = false;
531 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
532 ErrorHash["errorURI"] = "";
533
534 return ErrorHash;
535 //throw (ex);
536 }
537 catch (SocketException ex)
538 {
539 m_log.ErrorFormat(
540 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
541 m_MoneyAddress, ex);
542
543 Hashtable ErrorHash = new Hashtable();
544 ErrorHash["success"] = false;
545 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
546 ErrorHash["errorURI"] = "";
547
548 return ErrorHash;
549 //throw (ex);
550 }
551 catch (XmlException ex)
552 {
553 m_log.ErrorFormat(
554 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
555 m_MoneyAddress, ex);
556
557 Hashtable ErrorHash = new Hashtable();
558 ErrorHash["success"] = false;
559 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
560 ErrorHash["errorURI"] = "";
561
562 return ErrorHash;
563 }
564 if (MoneyResp.IsFault)
565 {
566 Hashtable ErrorHash = new Hashtable();
567 ErrorHash["success"] = false;
568 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
569 ErrorHash["errorURI"] = "";
570
571 return ErrorHash;
572 }
573 Hashtable MoneyRespData = (Hashtable) MoneyResp.Value;
574
575 return MoneyRespData;
576 }
577
578 /// <summary>
579 /// This informs the Money Grid Server that the avatar is in this simulator
580 /// </summary>
581 /// <param name="agentId"></param>
582 /// <param name="secureSessionID"></param>
583 /// <param name="regionId"></param>
584 /// <param name="regionSecret"></param>
585 /// <returns></returns>
586 public Hashtable claim_user(UUID agentId, UUID secureSessionID, UUID regionId, string regionSecret)
587 {
588 Hashtable MoneyBalanceRequestParams = new Hashtable();
589 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
590 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
591 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
592 MoneyBalanceRequestParams["secret"] = regionSecret;
593
594 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulatorClaimUserRequest");
595 IClientAPI sendMoneyBal = LocateClientObject(agentId);
596 if (sendMoneyBal != null)
597 {
598 SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, UUID.Zero);
599 }
600 return MoneyRespData;
601 }
602
603 private SceneObjectPart findPrim(UUID objectID) 359 private SceneObjectPart findPrim(UUID objectID)
604 { 360 {
605 lock (m_scenel) 361 lock (m_scenel)
@@ -666,180 +422,6 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
666 } 422 }
667 423
668 /// <summary> 424 /// <summary>
669 /// Informs the Money Grid Server of a transfer.
670 /// </summary>
671 /// <param name="sourceId"></param>
672 /// <param name="destId"></param>
673 /// <param name="amount"></param>
674 /// <returns></returns>
675 public bool TransferMoneyonMoneyServer(UUID sourceId, UUID destId, int amount, int transactiontype, string description)
676 {
677 int aggregatePermInventory = 0;
678 int aggregatePermNextOwner = 0;
679 int flags = 0;
680 bool rvalue = false;
681
682 IClientAPI cli = LocateClientObject(sourceId);
683 if (cli != null)
684 {
685 Scene userScene = null;
686 lock (m_rootAgents)
687 {
688 userScene = GetSceneByUUID(m_rootAgents[sourceId]);
689 }
690 if (userScene != null)
691 {
692 Hashtable ht = new Hashtable();
693 ht["agentId"] = sourceId.ToString();
694 ht["secureSessionId"] = cli.SecureSessionId.ToString();
695 ht["regionId"] = userScene.RegionInfo.originRegionID.ToString();
696 ht["secret"] = userScene.RegionInfo.regionSecret;
697 ht["currencySecret"] = " ";
698 ht["destId"] = destId.ToString();
699 ht["cash"] = amount;
700 ht["aggregatePermInventory"] = aggregatePermInventory;
701 ht["aggregatePermNextOwner"] = aggregatePermNextOwner;
702 ht["flags"] = flags;
703 ht["transactionType"] = transactiontype;
704 ht["description"] = description;
705
706 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney");
707
708 if ((bool) hresult["success"] == true)
709 {
710 int funds1 = 0;
711 int funds2 = 0;
712 try
713 {
714 funds1 = (Int32) hresult["funds"];
715 }
716 catch (InvalidCastException)
717 {
718 funds1 = 0;
719 }
720 SetLocalFundsForAgentID(sourceId, funds1);
721 if (m_KnownClientFunds.ContainsKey(destId))
722 {
723 try
724 {
725 funds2 = (Int32) hresult["funds2"];
726 }
727 catch (InvalidCastException)
728 {
729 funds2 = 0;
730 }
731 SetLocalFundsForAgentID(destId, funds2);
732 }
733
734
735 rvalue = true;
736 }
737 else
738 {
739 cli.SendAgentAlertMessage((string) hresult["errorMessage"], true);
740 }
741 }
742 }
743 else
744 {
745 m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString());
746 }
747
748 return rvalue;
749 }
750
751 public int GetRemoteBalance(UUID agentId)
752 {
753 int funds = 0;
754
755 IClientAPI aClient = LocateClientObject(agentId);
756 if (aClient != null)
757 {
758 Scene s = LocateSceneClientIn(agentId);
759 if (s != null)
760 {
761 if (m_MoneyAddress.Length > 0)
762 {
763 Hashtable hbinfo =
764 GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID,
765 s.RegionInfo.regionSecret);
766 if ((bool) hbinfo["success"] == true)
767 {
768 try
769 {
770 funds = (Int32) hbinfo["funds"];
771 }
772 catch (ArgumentException)
773 {
774 }
775 catch (FormatException)
776 {
777 }
778 catch (OverflowException)
779 {
780 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId);
781 aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
782 }
783 catch (InvalidCastException)
784 {
785 funds = 0;
786 }
787 }
788 else
789 {
790 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId,
791 (string) hbinfo["errorMessage"]);
792 aClient.SendAlertMessage((string) hbinfo["errorMessage"]);
793 }
794 }
795
796 SetLocalFundsForAgentID(agentId, funds);
797 SendMoneyBalance(aClient, agentId, aClient.SessionId, UUID.Zero);
798 }
799 else
800 {
801 m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene.");
802 }
803 }
804 else
805 {
806 m_log.Debug("[MONEY]: Got balance request update for agent that isn't here.");
807 }
808 return funds;
809 }
810
811 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request)
812 {
813 m_log.Debug("[MONEY]: Dynamic balance update called.");
814 Hashtable requestData = (Hashtable) request.Params[0];
815
816 if (requestData.ContainsKey("agentId"))
817 {
818 UUID agentId = UUID.Zero;
819
820 UUID.TryParse((string) requestData["agentId"], out agentId);
821 if (agentId != UUID.Zero)
822 {
823 GetRemoteBalance(agentId);
824 }
825 else
826 {
827 m_log.Debug("[MONEY]: invalid agentId specified, dropping.");
828 }
829 }
830 else
831 {
832 m_log.Debug("[MONEY]: no agentId specified, dropping.");
833 }
834 XmlRpcResponse r = new XmlRpcResponse();
835 Hashtable rparms = new Hashtable();
836 rparms["success"] = true;
837
838 r.Value = rparms;
839 return r;
840 }
841
842 /// <summary>
843 /// XMLRPC handler to send alert message and sound to client 425 /// XMLRPC handler to send alert message and sound to client
844 /// </summary> 426 /// </summary>
845 public XmlRpcResponse UserAlert(XmlRpcRequest request) 427 public XmlRpcResponse UserAlert(XmlRpcRequest request)
@@ -900,34 +482,20 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
900 Hashtable quoteResponse = new Hashtable(); 482 Hashtable quoteResponse = new Hashtable();
901 XmlRpcResponse returnval = new XmlRpcResponse(); 483 XmlRpcResponse returnval = new XmlRpcResponse();
902 484
903 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 485
904 { 486 Hashtable currencyResponse = new Hashtable();
905 UUID.TryParse((string) requestData["agentId"], out agentId); 487 currencyResponse.Add("estimatedCost", 0);
906 try 488 currencyResponse.Add("currencyBuy", amount);
907 {
908 amount = (Int32) requestData["currencyBuy"];
909 }
910 catch (InvalidCastException)
911 {
912 }
913 Hashtable currencyResponse = new Hashtable();
914 currencyResponse.Add("estimatedCost", 0);
915 currencyResponse.Add("currencyBuy", amount);
916
917 quoteResponse.Add("success", true);
918 quoteResponse.Add("currency", currencyResponse);
919 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
920
921 returnval.Value = quoteResponse;
922 return returnval;
923 }
924 489
490 quoteResponse.Add("success", true);
491 quoteResponse.Add("currency", currencyResponse);
492 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
925 493
926 quoteResponse.Add("success", false);
927 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box");
928 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki");
929 returnval.Value = quoteResponse; 494 returnval.Value = quoteResponse;
930 return returnval; 495 return returnval;
496
497
498
931 } 499 }
932 500
933 public XmlRpcResponse buy_func(XmlRpcRequest request) 501 public XmlRpcResponse buy_func(XmlRpcRequest request)
@@ -935,36 +503,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
935 Hashtable requestData = (Hashtable) request.Params[0]; 503 Hashtable requestData = (Hashtable) request.Params[0];
936 UUID agentId = UUID.Zero; 504 UUID agentId = UUID.Zero;
937 int amount = 0; 505 int amount = 0;
938 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 506
939 {
940 UUID.TryParse((string) requestData["agentId"], out agentId);
941 try
942 {
943 amount = (Int32) requestData["currencyBuy"];
944 }
945 catch (InvalidCastException)
946 {
947 }
948 if (agentId != UUID.Zero)
949 {
950 lock (m_KnownClientFunds)
951 {
952 if (m_KnownClientFunds.ContainsKey(agentId))
953 {
954 m_KnownClientFunds[agentId] += amount;
955 }
956 else
957 {
958 m_KnownClientFunds.Add(agentId, amount);
959 }
960 }
961 IClientAPI client = LocateClientObject(agentId);
962 if (client != null)
963 {
964 SendMoneyBalance(client, agentId, client.SessionId, UUID.Zero);
965 }
966 }
967 }
968 XmlRpcResponse returnval = new XmlRpcResponse(); 507 XmlRpcResponse returnval = new XmlRpcResponse();
969 Hashtable returnresp = new Hashtable(); 508 Hashtable returnresp = new Hashtable();
970 returnresp.Add("success", true); 509 returnresp.Add("success", true);
@@ -1015,36 +554,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1015 554
1016 UUID agentId = UUID.Zero; 555 UUID agentId = UUID.Zero;
1017 int amount = 0; 556 int amount = 0;
1018 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 557
1019 {
1020 UUID.TryParse((string) requestData["agentId"], out agentId);
1021 try
1022 {
1023 amount = (Int32) requestData["currencyBuy"];
1024 }
1025 catch (InvalidCastException)
1026 {
1027 }
1028 if (agentId != UUID.Zero)
1029 {
1030 lock (m_KnownClientFunds)
1031 {
1032 if (m_KnownClientFunds.ContainsKey(agentId))
1033 {
1034 m_KnownClientFunds[agentId] += amount;
1035 }
1036 else
1037 {
1038 m_KnownClientFunds.Add(agentId, amount);
1039 }
1040 }
1041 IClientAPI client = LocateClientObject(agentId);
1042 if (client != null)
1043 {
1044 SendMoneyBalance(client, agentId, client.SessionId, UUID.Zero);
1045 }
1046 }
1047 }
1048 retparam.Add("success", true); 558 retparam.Add("success", true);
1049 ret.Value = retparam; 559 ret.Value = retparam;
1050 560
@@ -1061,20 +571,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1061 /// <param name="agentID"></param> 571 /// <param name="agentID"></param>
1062 private void CheckExistAndRefreshFunds(UUID agentID) 572 private void CheckExistAndRefreshFunds(UUID agentID)
1063 { 573 {
1064 lock (m_KnownClientFunds) 574
1065 {
1066 if (!m_KnownClientFunds.ContainsKey(agentID))
1067 {
1068 m_KnownClientFunds.Add(agentID, m_stipend);
1069 }
1070 else
1071 {
1072 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
1073 {
1074 m_KnownClientFunds[agentID] = m_stipend;
1075 }
1076 }
1077 }
1078 } 575 }
1079 576
1080 /// <summary> 577 /// <summary>
@@ -1085,33 +582,13 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1085 private int GetFundsForAgentID(UUID AgentID) 582 private int GetFundsForAgentID(UUID AgentID)
1086 { 583 {
1087 int returnfunds = 0; 584 int returnfunds = 0;
1088 lock (m_KnownClientFunds) 585
1089 {
1090 if (m_KnownClientFunds.ContainsKey(AgentID))
1091 {
1092 returnfunds = m_KnownClientFunds[AgentID];
1093 }
1094 else
1095 {
1096 //throw new Exception("Unable to get funds.");
1097 }
1098 }
1099 return returnfunds; 586 return returnfunds;
1100 } 587 }
1101 588
1102 private void SetLocalFundsForAgentID(UUID AgentID, int amount) 589 private void SetLocalFundsForAgentID(UUID AgentID, int amount)
1103 { 590 {
1104 lock (m_KnownClientFunds) 591
1105 {
1106 if (m_KnownClientFunds.ContainsKey(AgentID))
1107 {
1108 m_KnownClientFunds[AgentID] = amount;
1109 }
1110 else
1111 {
1112 m_KnownClientFunds.Add(AgentID, amount);
1113 }
1114 }
1115 } 592 }
1116 593
1117 #endregion 594 #endregion
@@ -1227,16 +704,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1227 /// <param name="AgentID"></param> 704 /// <param name="AgentID"></param>
1228 public void ClientClosed(UUID AgentID) 705 public void ClientClosed(UUID AgentID)
1229 { 706 {
1230 lock (m_KnownClientFunds) 707
1231 {
1232 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
1233 {
1234 }
1235 else
1236 {
1237 m_KnownClientFunds.Remove(AgentID);
1238 }
1239 }
1240 } 708 }
1241 709
1242 /// <summary> 710 /// <summary>
@@ -1258,52 +726,19 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1258 726
1259 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e) 727 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
1260 { 728 {
1261 if (m_MoneyAddress.Length == 0) 729
1262 { 730
1263 lock (m_KnownClientFunds) 731 lock (e)
1264 {
1265 if (m_KnownClientFunds.ContainsKey(e.agentId))
1266 {
1267 // Does the sender have enough funds to give?
1268 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
1269 {
1270 lock (e)
1271 {
1272 e.economyValidated = true;
1273 }
1274 }
1275 }
1276 }
1277 }
1278 else
1279 { 732 {
1280 if (GetRemoteBalance(e.agentId) >= e.parcelPrice) 733 e.economyValidated = true;
1281 {
1282 lock (e)
1283 {
1284 e.economyValidated = true;
1285 }
1286 }
1287 } 734 }
735
736
1288 } 737 }
1289 738
1290 private void processLandBuy(Object osender, EventManager.LandBuyArgs e) 739 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
1291 { 740 {
1292 lock (e) 741
1293 {
1294 if (e.economyValidated == true && e.transactionID == 0)
1295 {
1296 e.transactionID = Util.UnixTimeSinceEpoch();
1297
1298 if (doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
1299 {
1300 lock (e)
1301 {
1302 e.amountDebited = e.parcelPrice;
1303 }
1304 }
1305 }
1306 }
1307 } 742 }
1308 743
1309 /// <summary> 744 /// <summary>
@@ -1313,76 +748,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1313 /// <param name="e"></param> 748 /// <param name="e"></param>
1314 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e) 749 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
1315 { 750 {
1316 IClientAPI sender = null; 751
1317 IClientAPI receiver = null;
1318
1319 if (m_MoneyAddress.Length > 0) // Handled on server
1320 e.description = String.Empty;
1321
1322 if (e.transactiontype == 5008) // Object gets paid
1323 {
1324 sender = LocateClientObject(e.sender);
1325 if (sender != null)
1326 {
1327 SceneObjectPart part = findPrim(e.receiver);
1328 if (part == null)
1329 return;
1330
1331 string name = resolveAgentName(part.OwnerID);
1332 if (name == String.Empty)
1333 name = "(hippos)";
1334
1335 receiver = LocateClientObject(part.OwnerID);
1336
1337 string description = String.Format("Paid {0} via object {1}", name, e.description);
1338 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
1339
1340 if (transactionresult)
1341 {
1342 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
1343 if (handlerOnObjectPaid != null)
1344 {
1345 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
1346 }
1347 }
1348
1349 if (e.sender != e.receiver)
1350 {
1351 sender.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(e.description), GetFundsForAgentID(e.sender));
1352 }
1353 if (receiver != null)
1354 {
1355 receiver.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(e.description), GetFundsForAgentID(part.OwnerID));
1356 }
1357 }
1358 return;
1359 }
1360
1361 sender = LocateClientObject(e.sender);
1362 if (sender != null)
1363 {
1364 receiver = LocateClientObject(e.receiver);
1365
1366 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
1367
1368 if (e.sender != e.receiver)
1369 {
1370 if (sender != null)
1371 {
1372 sender.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(e.description), GetFundsForAgentID(e.sender));
1373 }
1374 }
1375
1376 if (receiver != null)
1377 {
1378 receiver.SendMoneyBalance(UUID.Random(), transactionresult, Utils.StringToBytes(e.description), GetFundsForAgentID(e.receiver));
1379 }
1380 }
1381 else
1382 {
1383 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" +
1384 e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString());
1385 }
1386 } 752 }
1387 753
1388 /// <summary> 754 /// <summary>
@@ -1391,17 +757,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1391 /// <param name="avatar"></param> 757 /// <param name="avatar"></param>
1392 private void MakeChildAgent(ScenePresence avatar) 758 private void MakeChildAgent(ScenePresence avatar)
1393 { 759 {
1394 lock (m_rootAgents) 760
1395 {
1396 if (m_rootAgents.ContainsKey(avatar.UUID))
1397 {
1398 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
1399 {
1400 m_rootAgents.Remove(avatar.UUID);
1401// m_log.Debug("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
1402 }
1403 }
1404 }
1405 } 761 }
1406 762
1407 /// <summary> 763 /// <summary>
@@ -1410,14 +766,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1410 /// <param name="AgentId"></param> 766 /// <param name="AgentId"></param>
1411 private void ClientLoggedOut(UUID AgentId) 767 private void ClientLoggedOut(UUID AgentId)
1412 { 768 {
1413 lock (m_rootAgents) 769
1414 {
1415 if (m_rootAgents.ContainsKey(AgentId))
1416 {
1417 m_rootAgents.Remove(AgentId);
1418 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
1419 }
1420 }
1421 } 770 }
1422 771
1423 /// <summary> 772 /// <summary>
@@ -1437,104 +786,13 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1437 /// <param name="regionID"></param> 786 /// <param name="regionID"></param>
1438 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID) 787 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
1439 { 788 {
1440 lock (m_rootAgents) 789
1441 {
1442 if (m_rootAgents.ContainsKey(avatar.UUID))
1443 {
1444 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
1445 {
1446 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
1447
1448
1449 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1450 // Claim User! my user! Mine mine mine!
1451 if (m_MoneyAddress.Length > 0)
1452 {
1453 Scene RegionItem = GetSceneByUUID(regionID);
1454 if (RegionItem != null)
1455 {
1456 Hashtable hresult =
1457 claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1458 if ((bool)hresult["success"] == true)
1459 {
1460 int funds = 0;
1461 try
1462 {
1463 funds = (Int32)hresult["funds"];
1464 }
1465 catch (InvalidCastException)
1466 {
1467 }
1468 SetLocalFundsForAgentID(avatar.UUID, funds);
1469 }
1470 else
1471 {
1472 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
1473 }
1474 }
1475 }
1476 }
1477 else
1478 {
1479 ILandObject obj = avatar.Scene.LandChannel.GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
1480 if ((obj.landData.Flags & (uint)Parcel.ParcelFlags.AllowDamage) != 0)
1481 {
1482 avatar.Invulnerable = false;
1483 }
1484 else
1485 {
1486 avatar.Invulnerable = true;
1487 }
1488 }
1489 }
1490 else
1491 {
1492 lock (m_rootAgents)
1493 {
1494 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
1495 }
1496 if (m_MoneyAddress.Length > 0)
1497 {
1498 Scene RegionItem = GetSceneByUUID(regionID);
1499 if (RegionItem != null)
1500 {
1501 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1502 if ((bool) hresult["success"] == true)
1503 {
1504 int funds = 0;
1505 try
1506 {
1507 funds = (Int32) hresult["funds"];
1508 }
1509 catch (InvalidCastException)
1510 {
1511 }
1512 SetLocalFundsForAgentID(avatar.UUID, funds);
1513 }
1514 else
1515 {
1516 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1517 }
1518 }
1519 }
1520
1521 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1522 }
1523 }
1524 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString()); 790 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
1525 } 791 }
1526 792
1527 public int GetBalance(IClientAPI client) 793 public int GetBalance(IClientAPI client)
1528 { 794 {
1529 GetClientFunds(client); 795 return 0;
1530
1531 lock (m_KnownClientFunds)
1532 {
1533 if (!m_KnownClientFunds.ContainsKey(client.AgentId))
1534 return 0;
1535
1536 return m_KnownClientFunds[client.AgentId];
1537 }
1538 } 796 }
1539 797
1540 // Please do not refactor these to be just one method 798 // Please do not refactor these to be just one method
@@ -1552,8 +810,6 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1552 810
1553 public bool AmountCovered(IClientAPI client, int amount) 811 public bool AmountCovered(IClientAPI client, int amount)
1554 { 812 {
1555 if (GetBalance(client) < amount)
1556 return false;
1557 return true; 813 return true;
1558 } 814 }
1559 815
@@ -1563,33 +819,7 @@ namespace OpenSim.Region.ReplaceableModules.MoneyModule
1563 UUID sessionID, UUID groupID, UUID categoryID, 819 UUID sessionID, UUID groupID, UUID categoryID,
1564 uint localID, byte saleType, int salePrice) 820 uint localID, byte saleType, int salePrice)
1565 { 821 {
1566 GetClientFunds(remoteClient); 822
1567
1568 if (!m_KnownClientFunds.ContainsKey(remoteClient.AgentId))
1569 {
1570 remoteClient.SendAgentAlertMessage("Unable to buy now. Your account balance was not found.", false);
1571 return;
1572 }
1573
1574 int funds = m_KnownClientFunds[remoteClient.AgentId];
1575
1576 if (salePrice != 0 && funds < salePrice)
1577 {
1578 remoteClient.SendAgentAlertMessage("Unable to buy now. You don't have sufficient funds.", false);
1579 return;
1580 }
1581
1582 Scene s = LocateSceneClientIn(remoteClient.AgentId);
1583
1584 SceneObjectPart part = s.GetSceneObjectPart(localID);
1585 if (part == null)
1586 {
1587 remoteClient.SendAgentAlertMessage("Unable to buy now. The object was not found.", false);
1588 return;
1589 }
1590
1591 if (s.PerformObjectBuy(remoteClient, categoryID, localID, saleType))
1592 doMoneyTransfer(remoteClient.AgentId, part.OwnerID, salePrice, 5000, "Object buy");
1593 } 823 }
1594 } 824 }
1595 825