diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs index aabb2d1..d950af9 100644 --- a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs +++ b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs | |||
@@ -39,12 +39,20 @@ using OpenSim.Region.Environment.Scenes; | |||
39 | using Nwc.XmlRpc; | 39 | using Nwc.XmlRpc; |
40 | 40 | ||
41 | using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs; | 41 | using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs; |
42 | using LandBuyArgs = OpenSim.Region.Environment.Scenes.EventManager.LandBuyArgs; | ||
42 | 43 | ||
43 | namespace OpenSim.Region.Environment.Modules | 44 | namespace OpenSim.Region.Environment.Modules |
44 | { | 45 | { |
45 | /// <summary> | 46 | /// <summary> |
46 | /// Demo Economy/Money Module. This is not a production quality money/economy module! | 47 | /// Demo Economy/Money Module. This is not a production quality money/economy module! |
47 | /// This is a demo for you to use when making one that works for you. | 48 | /// This is a demo for you to use when making one that works for you. |
49 | /// // To use the following you need to add: | ||
50 | /// -helperuri <ADDRESS TO HERE OR grid MONEY SERVER> | ||
51 | /// to the command line parameters you use to start up your client | ||
52 | /// This commonly looks like -helperuri http://127.0.0.1:9000/ | ||
53 | /// | ||
54 | /// Centralized grid structure example using OpenSimWi Redux revision 9+ | ||
55 | /// svn co https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux | ||
48 | /// </summary> | 56 | /// </summary> |
49 | public class BetaGridLikeMoneyModule: IRegionModule | 57 | public class BetaGridLikeMoneyModule: IRegionModule |
50 | { | 58 | { |
@@ -134,6 +142,7 @@ namespace OpenSim.Region.Environment.Modules | |||
134 | if (m_MoneyAddress.Length > 0) | 142 | if (m_MoneyAddress.Length > 0) |
135 | { | 143 | { |
136 | // Centralized grid structure using OpenSimWi Redux revision 9+ | 144 | // Centralized grid structure using OpenSimWi Redux revision 9+ |
145 | // https://opensimwiredux.svn.sourceforge.net/svnroot/opensimwiredux | ||
137 | scene.AddXmlRPCHandler("dynamic_balance_update_request", GridMoneyUpdate); | 146 | scene.AddXmlRPCHandler("dynamic_balance_update_request", GridMoneyUpdate); |
138 | } | 147 | } |
139 | else | 148 | else |
@@ -165,6 +174,8 @@ namespace OpenSim.Region.Environment.Modules | |||
165 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; | 174 | scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel; |
166 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; | 175 | scene.EventManager.OnMakeChildAgent += MakeChildAgent; |
167 | scene.EventManager.OnClientClosed += ClientLoggedOut; | 176 | scene.EventManager.OnClientClosed += ClientLoggedOut; |
177 | scene.EventManager.OnLandBuy += ValidateLandBuy; | ||
178 | scene.EventManager.OnValidatedLandBuy += processLandBuy; | ||
168 | 179 | ||
169 | } | 180 | } |
170 | } | 181 | } |
@@ -329,6 +340,101 @@ namespace OpenSim.Region.Environment.Modules | |||
329 | } | 340 | } |
330 | } | 341 | } |
331 | 342 | ||
343 | private void ValidateLandBuy (Object osender, LandBuyArgs e) | ||
344 | { | ||
345 | LLUUID agentId = e.agentId; | ||
346 | int price = e.parcelPrice; | ||
347 | bool final = e.final; | ||
348 | |||
349 | int funds = 0; | ||
350 | |||
351 | if (m_MoneyAddress.Length > 0) | ||
352 | { | ||
353 | IClientAPI aClient = LocateClientObject(agentId); | ||
354 | if (aClient != null) | ||
355 | { | ||
356 | Scene s = LocateSceneClientIn(agentId); | ||
357 | if (s != null) | ||
358 | { | ||
359 | Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); | ||
360 | if ((bool)hbinfo["success"] == true) | ||
361 | { | ||
362 | |||
363 | Helpers.TryParse((string)hbinfo["agentId"], out agentId); | ||
364 | try | ||
365 | { | ||
366 | funds = (Int32)hbinfo["funds"]; | ||
367 | } | ||
368 | catch (ArgumentException) | ||
369 | { | ||
370 | } | ||
371 | catch (FormatException) | ||
372 | { | ||
373 | } | ||
374 | catch (OverflowException) | ||
375 | { | ||
376 | m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId); | ||
377 | aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable"); | ||
378 | } | ||
379 | catch (InvalidCastException) | ||
380 | { | ||
381 | funds = 0; | ||
382 | } | ||
383 | |||
384 | SetLocalFundsForAgentID(agentId, funds); | ||
385 | |||
386 | } | ||
387 | else | ||
388 | { | ||
389 | m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]); | ||
390 | aClient.SendAlertMessage((string)hbinfo["errorMessage"]); | ||
391 | } | ||
392 | } | ||
393 | } | ||
394 | } | ||
395 | else | ||
396 | { | ||
397 | funds = GetFundsForAgentID(agentId); | ||
398 | } | ||
399 | if (funds >= e.parcelPrice) | ||
400 | { | ||
401 | lock (e) | ||
402 | { | ||
403 | e.economyValidated = true; | ||
404 | } | ||
405 | XMLRPCHandler.EventManager.TriggerValidatedLandBuy(this, e); | ||
406 | } | ||
407 | } | ||
408 | |||
409 | private void processLandBuy(Object osender, LandBuyArgs e) | ||
410 | { | ||
411 | LLUUID agentId = e.agentId; | ||
412 | int price = e.parcelPrice; | ||
413 | bool final = e.final; | ||
414 | |||
415 | int funds = 0; | ||
416 | |||
417 | // Only do this if we have not already transacted against this. | ||
418 | if (e.transactionID == 0) | ||
419 | { | ||
420 | funds = GetFundsForAgentID(e.agentId); | ||
421 | if (e.landValidated) | ||
422 | { | ||
423 | if (e.parcelPrice >= 0) | ||
424 | { | ||
425 | doMoneyTranfer(agentId, e.parcelOwnerID, e.parcelPrice); | ||
426 | lock (e) | ||
427 | { | ||
428 | e.transactionID = Util.UnixTimeSinceEpoch(); | ||
429 | e.amountDebited = e.parcelPrice; | ||
430 | } | ||
431 | } | ||
432 | // This tells the land module that we've transacted. | ||
433 | XMLRPCHandler.EventManager.TriggerValidatedLandBuy(this, e); | ||
434 | } | ||
435 | } | ||
436 | |||
437 | } | ||
332 | /// <summary> | 438 | /// <summary> |
333 | /// THis method gets called when someone pays someone else as a gift. | 439 | /// THis method gets called when someone pays someone else as a gift. |
334 | /// </summary> | 440 | /// </summary> |