aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Avatar/Currency
diff options
context:
space:
mode:
authorAdam Frisby2008-04-30 21:43:47 +0000
committerAdam Frisby2008-04-30 21:43:47 +0000
commitbe20f41637b6c06ce3ab16bc25851b6e43468e12 (patch)
treec41081329891f4c24de704fc760fb9012954ac9d /OpenSim/Region/Environment/Modules/Avatar/Currency
parent* Sometimes you know, you do something really stupid. (diff)
downloadopensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.zip
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.gz
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.bz2
opensim-SC_OLD-be20f41637b6c06ce3ab16bc25851b6e43468e12.tar.xz
* Cruft removal step #1. Cleaning Modules directory.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/Avatar/Currency')
-rw-r--r--OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs1171
1 files changed, 575 insertions, 596 deletions
diff --git a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
index 0e058ec..181984e 100644
--- a/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/Avatar/Currency/SampleMoney/SampleMoneyModule.cs
@@ -53,7 +53,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
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
57 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount); 56 public delegate void ObjectPaid(LLUUID objectID, LLUUID agentID, int amount);
58 57
59 public interface IMoneyModule : IRegionModule 58 public interface IMoneyModule : IRegionModule
@@ -65,37 +64,39 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
65 64
66 public class SampleMoneyModule : IMoneyModule 65 public class SampleMoneyModule : IMoneyModule
67 { 66 {
68 public event ObjectPaid OnObjectPaid;
69
70 private ObjectPaid handerOnObjectPaid;
71
72 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 67 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
73 68
74 /// <summary>
75 /// Region UUIDS indexed by AgentID
76 /// </summary>
77 Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
78
79 /// <summary> 69 /// <summary>
80 /// Scenes by Region Handle 70 /// Where Stipends come from and Fees go to.
81 /// </summary> 71 /// </summary>
82 private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>(); 72 private LLUUID EconomyBaseAccount = LLUUID.Zero;
73
74 private float EnergyEfficiency = 0f;
75 private bool gridmode = false;
76 private ObjectPaid handerOnObjectPaid;
77 private bool m_enabled = true;
83 78
84 private IConfigSource m_gConfig; 79 private IConfigSource m_gConfig;
85 80
86 private bool m_keepMoneyAcrossLogins = true; 81 private bool m_keepMoneyAcrossLogins = true;
82 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
83 private string m_LandAddress = String.Empty;
87 84
88 private int m_minFundsBeforeRefresh = 100; 85 private int m_minFundsBeforeRefresh = 100;
86 private string m_MoneyAddress = String.Empty;
89 87
90 private int m_stipend = 1000; 88 /// <summary>
89 /// Region UUIDS indexed by AgentID
90 /// </summary>
91 private Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
91 92
92 private bool m_enabled = true; 93 /// <summary>
94 /// Scenes by Region Handle
95 /// </summary>
96 private Dictionary<ulong, Scene> m_scenel = new Dictionary<ulong, Scene>();
93 97
94 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); 98 private int m_stipend = 1000;
95 99
96 private bool gridmode = false;
97 private Scene XMLRPCHandler;
98 private float EnergyEfficiency = 0f;
99 private int ObjectCapacity = 45000; 100 private int ObjectCapacity = 45000;
100 private int ObjectCount = 0; 101 private int ObjectCount = 0;
101 private int PriceEnergyUnit = 0; 102 private int PriceEnergyUnit = 0;
@@ -111,16 +112,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
111 private int PriceRentLight = 0; 112 private int PriceRentLight = 0;
112 private int PriceUpload = 0; 113 private int PriceUpload = 0;
113 private int TeleportMinPrice = 0; 114 private int TeleportMinPrice = 0;
115
116 private float TeleportPriceExponent = 0f;
114 private int UserLevelPaysFees = 2; 117 private int UserLevelPaysFees = 2;
115 private string m_MoneyAddress = String.Empty; 118 private Scene XMLRPCHandler;
116 private string m_LandAddress = String.Empty;
117 119
118 float TeleportPriceExponent = 0f; 120 #region IMoneyModule Members
119 121
120 /// <summary> 122 public event ObjectPaid OnObjectPaid;
121 /// Where Stipends come from and Fees go to.
122 /// </summary>
123 LLUUID EconomyBaseAccount = LLUUID.Zero;
124 123
125 /// <summary> 124 /// <summary>
126 /// Startup 125 /// Startup
@@ -130,12 +129,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
130 public void Initialise(Scene scene, IConfigSource config) 129 public void Initialise(Scene scene, IConfigSource config)
131 { 130 {
132 m_gConfig = config; 131 m_gConfig = config;
133 132
134 IConfig startupConfig = m_gConfig.Configs["Startup"]; 133 IConfig startupConfig = m_gConfig.Configs["Startup"];
135 IConfig economyConfig = m_gConfig.Configs["Economy"]; 134 IConfig economyConfig = m_gConfig.Configs["Economy"];
136 135
137 scene.RegisterModuleInterface<IMoneyModule>(this); 136 scene.RegisterModuleInterface<IMoneyModule>(this);
138 137
139 ReadConfigAndPopulate(scene, startupConfig, "Startup"); 138 ReadConfigAndPopulate(scene, startupConfig, "Startup");
140 ReadConfigAndPopulate(scene, economyConfig, "Economy"); 139 ReadConfigAndPopulate(scene, economyConfig, "Economy");
141 140
@@ -167,8 +166,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
167 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func); 166 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
168 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func); 167 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func);
169 } 168 }
170
171
172 } 169 }
173 170
174 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) 171 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
@@ -180,7 +177,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
180 m_scenel.Add(scene.RegionInfo.RegionHandle, scene); 177 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
181 } 178 }
182 } 179 }
183 180
184 scene.EventManager.OnNewClient += OnNewClient; 181 scene.EventManager.OnNewClient += OnNewClient;
185 scene.EventManager.OnMoneyTransfer += MoneyTransferAction; 182 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
186 scene.EventManager.OnClientClosed += ClientClosed; 183 scene.EventManager.OnClientClosed += ClientClosed;
@@ -189,9 +186,41 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
189 scene.EventManager.OnClientClosed += ClientLoggedOut; 186 scene.EventManager.OnClientClosed += ClientLoggedOut;
190 scene.EventManager.OnValidateLandBuy += ValidateLandBuy; 187 scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
191 scene.EventManager.OnLandBuy += processLandBuy; 188 scene.EventManager.OnLandBuy += processLandBuy;
192
193 } 189 }
194 } 190 }
191
192 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
193 {
194 string description = String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
195
196 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
197
198 if (m_MoneyAddress.Length == 0)
199 BalanceUpdate(fromID, toID, give_result, description);
200
201 return give_result;
202 }
203
204 public void PostInitialise()
205 {
206 }
207
208 public void Close()
209 {
210 }
211
212 public string Name
213 {
214 get { return "BetaGridLikeMoneyModule"; }
215 }
216
217 public bool IsSharedModule
218 {
219 get { return true; }
220 }
221
222 #endregion
223
195 /// <summary> 224 /// <summary>
196 /// Parse Configuration 225 /// Parse Configuration
197 /// </summary> 226 /// </summary>
@@ -207,7 +236,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
207 } 236 }
208 237
209 if (config == "Economy" && startupConfig != null) 238 if (config == "Economy" && startupConfig != null)
210 { 239 {
211 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000); 240 ObjectCapacity = startupConfig.GetInt("ObjectCapacity", 45000);
212 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100); 241 PriceEnergyUnit = startupConfig.GetInt("PriceEnergyUnit", 100);
213 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10); 242 PriceObjectClaim = startupConfig.GetInt("PriceObjectClaim", 10);
@@ -225,7 +254,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
225 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1); 254 PriceParcelRent = startupConfig.GetInt("PriceParcelRent", 1);
226 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1); 255 PriceGroupCreate = startupConfig.GetInt("PriceGroupCreate", -1);
227 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString()); 256 string EBA = startupConfig.GetString("EconomyBaseAccount", LLUUID.Zero.ToString());
228 Helpers.TryParse(EBA,out EconomyBaseAccount); 257 Helpers.TryParse(EBA, out EconomyBaseAccount);
229 258
230 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1); 259 UserLevelPaysFees = startupConfig.GetInt("UserLevelPaysFees", -1);
231 m_stipend = startupConfig.GetInt("UserStipend", 500); 260 m_stipend = startupConfig.GetInt("UserStipend", 500);
@@ -234,7 +263,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
234 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty); 263 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty);
235 m_LandAddress = startupConfig.GetString("LandServer", String.Empty); 264 m_LandAddress = startupConfig.GetString("LandServer", String.Empty);
236 } 265 }
237 266
238 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. 267 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
239 scene.SetObjectCapacity(ObjectCapacity); 268 scene.SetObjectCapacity(ObjectCapacity);
240 } 269 }
@@ -253,7 +282,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
253 { 282 {
254 if (m_MoneyAddress.Length == 0) 283 if (m_MoneyAddress.Length == 0)
255 { 284 {
256
257 CheckExistAndRefreshFunds(client.AgentId); 285 CheckExistAndRefreshFunds(client.AgentId);
258 } 286 }
259 else 287 else
@@ -273,15 +301,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
273 //s.RegionInfo.RegionHandle; 301 //s.RegionInfo.RegionHandle;
274 LLUUID agentID = LLUUID.Zero; 302 LLUUID agentID = LLUUID.Zero;
275 int funds = 0; 303 int funds = 0;
276
277 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret);
278 if ((bool)hbinfo["success"] == true)
279 {
280 304
281 Helpers.TryParse((string)hbinfo["agentId"], out agentID); 305 Hashtable hbinfo =
306 GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
307 s.RegionInfo.regionSecret);
308 if ((bool) hbinfo["success"] == true)
309 {
310 Helpers.TryParse((string) hbinfo["agentId"], out agentID);
282 try 311 try
283 { 312 {
284 funds = (Int32)hbinfo["funds"]; 313 funds = (Int32) hbinfo["funds"];
285 } 314 }
286 catch (ArgumentException) 315 catch (ArgumentException)
287 { 316 {
@@ -303,340 +332,27 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
303 } 332 }
304 else 333 else
305 { 334 {
306 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, (string)hbinfo["errorMessage"]); 335 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID,
307 client.SendAlertMessage((string)hbinfo["errorMessage"]); 336 (string) hbinfo["errorMessage"]);
337 client.SendAlertMessage((string) hbinfo["errorMessage"]);
308 } 338 }
309 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero); 339 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero);
310
311 } 340 }
312 } 341 }
313
314 } 342 }
315 else 343 else
316 { 344 {
317 CheckExistAndRefreshFunds(client.AgentId); 345 CheckExistAndRefreshFunds(client.AgentId);
318 } 346 }
319 347
320 // Subscribe to Money messages 348 // Subscribe to Money messages
321 client.OnEconomyDataRequest += EconomyDataRequestHandler; 349 client.OnEconomyDataRequest += EconomyDataRequestHandler;
322 client.OnMoneyBalanceRequest += SendMoneyBalance; 350 client.OnMoneyBalanceRequest += SendMoneyBalance;
323 client.OnRequestPayPrice += requestPayPrice; 351 client.OnRequestPayPrice += requestPayPrice;
324 client.OnLogout += ClientClosed; 352 client.OnLogout += ClientClosed;
325
326
327 }
328
329 #region event Handlers
330
331 public void requestPayPrice(IClientAPI client, LLUUID objectID)
332 {
333 Scene scene=LocateSceneClientIn(client.AgentId);
334 if(scene == null)
335 return;
336
337 SceneObjectPart task=scene.GetSceneObjectPart(objectID);
338 if(task == null)
339 return;
340 SceneObjectGroup group=task.ParentGroup;
341 SceneObjectPart root=group.RootPart;
342
343 client.SendPayPrice(objectID, root.PayPrice);
344 }
345
346 /// <summary>
347 /// When the client closes the connection we remove their accounting info from memory to free up resources.
348 /// </summary>
349 /// <param name="AgentID"></param>
350 public void ClientClosed(LLUUID AgentID)
351 {
352 lock (m_KnownClientFunds)
353 {
354 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
355 {
356 }
357 else
358 {
359 m_KnownClientFunds.Remove(AgentID);
360 }
361 }
362 }
363
364 /// <summary>
365 /// Event called Economy Data Request handler.
366 /// </summary>
367 /// <param name="agentId"></param>
368 public void EconomyDataRequestHandler(LLUUID agentId)
369 {
370 IClientAPI user = LocateClientObject(agentId);
371
372 if (user != null)
373 {
374 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
375 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
376 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
377 TeleportMinPrice, TeleportPriceExponent);
378 }
379 }
380
381 private void ValidateLandBuy (Object osender, EventManager.LandBuyArgs e)
382 {
383 if (m_MoneyAddress.Length == 0)
384 {
385 lock (m_KnownClientFunds)
386 {
387 if (m_KnownClientFunds.ContainsKey(e.agentId))
388 {
389 // Does the sender have enough funds to give?
390 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
391 {
392 lock(e)
393 {
394 e.economyValidated=true;
395 }
396 }
397 }
398 }
399 }
400 else
401 {
402 if(GetRemoteBalance(e.agentId) >= e.parcelPrice)
403 {
404 lock(e)
405 {
406 e.economyValidated=true;
407 }
408 }
409 }
410 }
411
412 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
413 {
414 lock(e)
415 {
416 if(e.economyValidated == true && e.transactionID == 0)
417 {
418 e.transactionID=Util.UnixTimeSinceEpoch();
419
420 if(doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
421 {
422 lock (e)
423 {
424 e.amountDebited = e.parcelPrice;
425 }
426 }
427 }
428 }
429 } 353 }
430 354
431 /// <summary> 355 /// <summary>
432 /// THis method gets called when someone pays someone else as a gift.
433 /// </summary>
434 /// <param name="osender"></param>
435 /// <param name="e"></param>
436 private void MoneyTransferAction (Object osender, EventManager.MoneyTransferArgs e)
437 {
438 IClientAPI sender = null;
439 IClientAPI receiver = null;
440
441 if(m_MoneyAddress.Length > 0) // Handled on server
442 e.description=String.Empty;
443
444 if(e.transactiontype == 5008) // Object gets paid
445 {
446 sender = LocateClientObject(e.sender);
447 if (sender != null)
448 {
449 SceneObjectPart part=findPrim(e.receiver);
450 if(part == null)
451 return;
452
453 string name=resolveAgentName(part.OwnerID);
454 if(name == String.Empty)
455 name="(hippos)";
456
457 receiver = LocateClientObject(part.OwnerID);
458
459 string description=String.Format("Paid {0} via object {1}", name, e.description);
460 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
461
462 if(transactionresult)
463 {
464 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
465 if(handlerOnObjectPaid != null)
466 {
467 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
468 }
469 }
470
471 if (e.sender != e.receiver)
472 {
473 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
474 }
475 if(receiver != null)
476 {
477 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
478 }
479 }
480 return;
481 }
482
483 sender = LocateClientObject(e.sender);
484 if (sender != null)
485 {
486 receiver = LocateClientObject(e.receiver);
487
488 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
489
490 if (e.sender != e.receiver)
491 {
492 if (sender != null)
493 {
494 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
495 }
496 }
497
498 if (receiver != null)
499 {
500 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver));
501 }
502 }
503 else
504 {
505 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" + e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString());
506 }
507 }
508
509 /// <summary>
510 /// Event Handler for when a root agent becomes a child agent
511 /// </summary>
512 /// <param name="avatar"></param>
513 private void MakeChildAgent(ScenePresence avatar)
514 {
515 lock (m_rootAgents)
516 {
517 if (m_rootAgents.ContainsKey(avatar.UUID))
518 {
519 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
520 {
521 m_rootAgents.Remove(avatar.UUID);
522 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
523 }
524
525 }
526 }
527
528 }
529
530 /// <summary>
531 /// Event Handler for when the client logs out.
532 /// </summary>
533 /// <param name="AgentId"></param>
534 private void ClientLoggedOut(LLUUID AgentId)
535 {
536 lock (m_rootAgents)
537 {
538 if (m_rootAgents.ContainsKey(AgentId))
539 {
540 m_rootAgents.Remove(AgentId);
541 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
542 }
543 }
544 }
545
546 /// <summary>
547 /// Call this when the client disconnects.
548 /// </summary>
549 /// <param name="client"></param>
550 public void ClientClosed(IClientAPI client)
551 {
552 ClientClosed(client.AgentId);
553 }
554
555 /// <summary>
556 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
557 /// </summary>
558 /// <param name="avatar"></param>
559 /// <param name="localLandID"></param>
560 /// <param name="regionID"></param>
561 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
562 {
563 lock (m_rootAgents)
564 {
565 if (m_rootAgents.ContainsKey(avatar.UUID))
566 {
567 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
568 {
569 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
570 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
571 // Claim User! my user! Mine mine mine!
572 if (m_MoneyAddress.Length > 0)
573 {
574 Scene RegionItem = GetSceneByUUID(regionID);
575 if (RegionItem != null)
576 {
577 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
578 if ((bool)hresult["success"] == true)
579 {
580 int funds = 0;
581 try
582 {
583 funds = (Int32)hresult["funds"];
584 }
585 catch (InvalidCastException)
586 {
587
588 }
589 SetLocalFundsForAgentID(avatar.UUID, funds);
590 }
591 else
592 {
593 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
594 }
595 }
596 }
597 }
598 }
599 else
600 {
601 lock (m_rootAgents)
602 {
603 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
604 }
605 if (m_MoneyAddress.Length > 0)
606 {
607 Scene RegionItem = GetSceneByUUID(regionID);
608 if (RegionItem != null)
609 {
610 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
611 if ((bool)hresult["success"] == true)
612 {
613 int funds = 0;
614 try
615 {
616 funds = (Int32)hresult["funds"];
617 }
618 catch (InvalidCastException)
619 {
620
621 }
622 SetLocalFundsForAgentID(avatar.UUID, funds);
623 }
624 else
625 {
626 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
627 }
628 }
629 }
630
631 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
632 }
633 }
634 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
635 }
636
637 #endregion
638
639 /// <summary>
640 /// Transfer money 356 /// Transfer money
641 /// </summary> 357 /// </summary>
642 /// <param name="Sender"></param> 358 /// <param name="Sender"></param>
@@ -695,96 +411,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
695 return result; 411 return result;
696 } 412 }
697 413
698 #region Utility Helpers
699 /// <summary>
700 /// Locates a IClientAPI for the client specified
701 /// </summary>
702 /// <param name="AgentID"></param>
703 /// <returns></returns>
704 private IClientAPI LocateClientObject(LLUUID AgentID)
705 {
706 ScenePresence tPresence = null;
707 IClientAPI rclient = null;
708
709 lock (m_scenel)
710 {
711 foreach (Scene _scene in m_scenel.Values)
712 {
713 tPresence = _scene.GetScenePresence(AgentID);
714 if (tPresence != null)
715 {
716 if (!tPresence.IsChildAgent)
717 {
718 rclient = tPresence.ControllingClient;
719 }
720 }
721 if (rclient != null)
722 {
723 return rclient;
724 }
725 }
726
727 }
728 return null;
729 }
730
731 private Scene LocateSceneClientIn(LLUUID AgentId)
732 {
733 lock (m_scenel)
734 {
735 foreach (Scene _scene in m_scenel.Values)
736 {
737 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
738 if (tPresence != null)
739 {
740 if (!tPresence.IsChildAgent)
741 {
742 return _scene;
743 }
744 }
745
746 }
747
748 }
749 return null;
750 }
751
752 /// <summary>
753 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
754 /// </summary>
755 /// <returns></returns>
756 public Scene GetRandomScene()
757 {
758 lock (m_scenel)
759 {
760 foreach (Scene rs in m_scenel.Values)
761 return rs;
762 }
763 return null;
764
765 }
766 /// <summary>
767 /// Utility function to get a Scene by RegionID in a module
768 /// </summary>
769 /// <param name="RegionID"></param>
770 /// <returns></returns>
771 public Scene GetSceneByUUID(LLUUID RegionID)
772 {
773 lock (m_scenel)
774 {
775 foreach (Scene rs in m_scenel.Values)
776 {
777 if (rs.RegionInfo.originRegionID == RegionID)
778 {
779 return rs;
780 }
781 }
782 }
783 return null;
784 }
785 #endregion
786
787
788 414
789 /// <summary> 415 /// <summary>
790 /// Sends the the stored money balance to the client 416 /// Sends the the stored money balance to the client
@@ -798,7 +424,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
798 if (client.AgentId == agentID && client.SessionId == SessionID) 424 if (client.AgentId == agentID && client.SessionId == SessionID)
799 { 425 {
800 int returnfunds = 0; 426 int returnfunds = 0;
801 427
802 try 428 try
803 { 429 {
804 returnfunds = GetFundsForAgentID(agentID); 430 returnfunds = GetFundsForAgentID(agentID);
@@ -807,7 +433,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
807 { 433 {
808 client.SendAlertMessage(e.Message + " "); 434 client.SendAlertMessage(e.Message + " ");
809 } 435 }
810 436
811 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds); 437 client.SendMoneyBalance(TransactionID, true, new byte[0], returnfunds);
812 } 438 }
813 else 439 else
@@ -816,67 +442,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
816 } 442 }
817 } 443 }
818 444
819 #region local Fund Management
820 /// <summary>
821 /// Ensures that the agent accounting data is set up in this instance.
822 /// </summary>
823 /// <param name="agentID"></param>
824 private void CheckExistAndRefreshFunds(LLUUID agentID)
825 {
826 lock (m_KnownClientFunds)
827 {
828 if (!m_KnownClientFunds.ContainsKey(agentID))
829 {
830 m_KnownClientFunds.Add(agentID, m_stipend);
831 }
832 else
833 {
834 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
835 {
836 m_KnownClientFunds[agentID] = m_stipend;
837 }
838 }
839 }
840 }
841 /// <summary>
842 /// Gets the amount of Funds for an agent
843 /// </summary>
844 /// <param name="AgentID"></param>
845 /// <returns></returns>
846 private int GetFundsForAgentID(LLUUID AgentID)
847 {
848 int returnfunds = 0;
849 lock (m_KnownClientFunds)
850 {
851 if (m_KnownClientFunds.ContainsKey(AgentID))
852 {
853 returnfunds = m_KnownClientFunds[AgentID];
854 }
855 else
856 {
857 //throw new Exception("Unable to get funds.");
858 }
859 }
860 return returnfunds;
861 }
862 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
863 {
864 lock (m_KnownClientFunds)
865 {
866 if (m_KnownClientFunds.ContainsKey(AgentID))
867 {
868 m_KnownClientFunds[AgentID] = amount;
869 }
870 else
871 {
872 m_KnownClientFunds.Add(AgentID, amount);
873 }
874 }
875
876 }
877
878 #endregion
879
880 /// <summary> 445 /// <summary>
881 /// Gets the current balance for the user from the Grid Money Server 446 /// Gets the current balance for the user from the Grid Money Server
882 /// </summary> 447 /// </summary>
@@ -887,7 +452,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
887 /// <returns></returns> 452 /// <returns></returns>
888 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) 453 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
889 { 454 {
890
891 Hashtable MoneyBalanceRequestParams = new Hashtable(); 455 Hashtable MoneyBalanceRequestParams = new Hashtable();
892 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 456 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
893 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 457 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
@@ -899,8 +463,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
899 463
900 return MoneyRespData; 464 return MoneyRespData;
901 } 465 }
902 466
903
904 467
905 /// <summary> 468 /// <summary>
906 /// Generic XMLRPC client abstraction 469 /// Generic XMLRPC client abstraction
@@ -921,7 +484,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
921 } 484 }
922 catch (WebException ex) 485 catch (WebException ex)
923 { 486 {
924
925 m_log.ErrorFormat( 487 m_log.ErrorFormat(
926 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 488 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
927 m_MoneyAddress, ex); 489 m_MoneyAddress, ex);
@@ -936,7 +498,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
936 } 498 }
937 catch (SocketException ex) 499 catch (SocketException ex)
938 { 500 {
939
940 m_log.ErrorFormat( 501 m_log.ErrorFormat(
941 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}", 502 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
942 m_MoneyAddress, ex); 503 m_MoneyAddress, ex);
@@ -961,7 +522,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
961 ErrorHash["errorURI"] = ""; 522 ErrorHash["errorURI"] = "";
962 523
963 return ErrorHash; 524 return ErrorHash;
964
965 } 525 }
966 if (MoneyResp.IsFault) 526 if (MoneyResp.IsFault)
967 { 527 {
@@ -971,12 +531,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
971 ErrorHash["errorURI"] = ""; 531 ErrorHash["errorURI"] = "";
972 532
973 return ErrorHash; 533 return ErrorHash;
974
975 } 534 }
976 Hashtable MoneyRespData = (Hashtable)MoneyResp.Value; 535 Hashtable MoneyRespData = (Hashtable) MoneyResp.Value;
977 536
978 return MoneyRespData; 537 return MoneyRespData;
979 } 538 }
539
980 /// <summary> 540 /// <summary>
981 /// This informs the Money Grid Server that the avatar is in this simulator 541 /// This informs the Money Grid Server that the avatar is in this simulator
982 /// </summary> 542 /// </summary>
@@ -987,7 +547,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
987 /// <returns></returns> 547 /// <returns></returns>
988 public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret) 548 public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
989 { 549 {
990
991 Hashtable MoneyBalanceRequestParams = new Hashtable(); 550 Hashtable MoneyBalanceRequestParams = new Hashtable();
992 MoneyBalanceRequestParams["agentId"] = agentId.ToString(); 551 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
993 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString(); 552 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
@@ -1009,8 +568,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1009 { 568 {
1010 foreach (Scene s in m_scenel.Values) 569 foreach (Scene s in m_scenel.Values)
1011 { 570 {
1012 SceneObjectPart part=s.GetSceneObjectPart(objectID); 571 SceneObjectPart part = s.GetSceneObjectPart(objectID);
1013 if(part != null) 572 if (part != null)
1014 { 573 {
1015 return part; 574 return part;
1016 } 575 }
@@ -1021,8 +580,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1021 580
1022 private string resolveObjectName(LLUUID objectID) 581 private string resolveObjectName(LLUUID objectID)
1023 { 582 {
1024 SceneObjectPart part=findPrim(objectID); 583 SceneObjectPart part = findPrim(objectID);
1025 if(part != null) 584 if (part != null)
1026 { 585 {
1027 return part.Name; 586 return part.Name;
1028 } 587 }
@@ -1032,7 +591,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1032 private string resolveAgentName(LLUUID agentID) 591 private string resolveAgentName(LLUUID agentID)
1033 { 592 {
1034 // try avatar username surname 593 // try avatar username surname
1035 Scene scene=GetRandomScene(); 594 Scene scene = GetRandomScene();
1036 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID); 595 UserProfileData profile = scene.CommsManager.UserService.GetUserProfile(agentID);
1037 if (profile != null) 596 if (profile != null)
1038 { 597 {
@@ -1042,19 +601,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1042 return String.Empty; 601 return String.Empty;
1043 } 602 }
1044 603
1045 public bool ObjectGiveMoney(LLUUID objectID, LLUUID fromID, LLUUID toID, int amount)
1046 {
1047 string description=String.Format("Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
1048
1049 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
1050
1051 if (m_MoneyAddress.Length == 0)
1052 BalanceUpdate(fromID, toID, give_result, description);
1053
1054 return give_result;
1055
1056
1057 }
1058 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description) 604 private void BalanceUpdate(LLUUID senderID, LLUUID receiverID, bool transactionresult, string description)
1059 { 605 {
1060 IClientAPI sender = LocateClientObject(senderID); 606 IClientAPI sender = LocateClientObject(senderID);
@@ -1091,7 +637,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1091 IClientAPI cli = LocateClientObject(sourceId); 637 IClientAPI cli = LocateClientObject(sourceId);
1092 if (cli != null) 638 if (cli != null)
1093 { 639 {
1094
1095 Scene userScene = null; 640 Scene userScene = null;
1096 lock (m_rootAgents) 641 lock (m_rootAgents)
1097 { 642 {
@@ -1112,18 +657,18 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1112 ht["flags"] = flags; 657 ht["flags"] = flags;
1113 ht["transactionType"] = transactiontype; 658 ht["transactionType"] = transactiontype;
1114 ht["description"] = description; 659 ht["description"] = description;
1115 660
1116 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney"); 661 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "regionMoveMoney");
1117 662
1118 if ((bool)hresult["success"] == true) 663 if ((bool) hresult["success"] == true)
1119 { 664 {
1120 int funds1 = 0; 665 int funds1 = 0;
1121 int funds2 = 0; 666 int funds2 = 0;
1122 try 667 try
1123 { 668 {
1124 funds1 = (Int32)hresult["funds"]; 669 funds1 = (Int32) hresult["funds"];
1125 } 670 }
1126 catch(InvalidCastException) 671 catch (InvalidCastException)
1127 { 672 {
1128 funds1 = 0; 673 funds1 = 0;
1129 } 674 }
@@ -1132,7 +677,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1132 { 677 {
1133 try 678 try
1134 { 679 {
1135 funds2 = (Int32)hresult["funds2"]; 680 funds2 = (Int32) hresult["funds2"];
1136 } 681 }
1137 catch (InvalidCastException) 682 catch (InvalidCastException)
1138 { 683 {
@@ -1146,9 +691,8 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1146 } 691 }
1147 else 692 else
1148 { 693 {
1149 cli.SendAgentAlertMessage((string)hresult["errorMessage"], true); 694 cli.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1150 } 695 }
1151
1152 } 696 }
1153 } 697 }
1154 else 698 else
@@ -1157,7 +701,6 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1157 } 701 }
1158 702
1159 return rvalue; 703 return rvalue;
1160
1161 } 704 }
1162 705
1163 public int GetRemoteBalance(LLUUID agentId) 706 public int GetRemoteBalance(LLUUID agentId)
@@ -1172,12 +715,14 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1172 { 715 {
1173 if (m_MoneyAddress.Length > 0) 716 if (m_MoneyAddress.Length > 0)
1174 { 717 {
1175 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret); 718 Hashtable hbinfo =
1176 if ((bool)hbinfo["success"] == true) 719 GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(),
720 s.RegionInfo.regionSecret);
721 if ((bool) hbinfo["success"] == true)
1177 { 722 {
1178 try 723 try
1179 { 724 {
1180 funds = (Int32)hbinfo["funds"]; 725 funds = (Int32) hbinfo["funds"];
1181 } 726 }
1182 catch (ArgumentException) 727 catch (ArgumentException)
1183 { 728 {
@@ -1194,12 +739,12 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1194 { 739 {
1195 funds = 0; 740 funds = 0;
1196 } 741 }
1197
1198 } 742 }
1199 else 743 else
1200 { 744 {
1201 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]); 745 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId,
1202 aClient.SendAlertMessage((string)hbinfo["errorMessage"]); 746 (string) hbinfo["errorMessage"]);
747 aClient.SendAlertMessage((string) hbinfo["errorMessage"]);
1203 } 748 }
1204 } 749 }
1205 750
@@ -1221,17 +766,16 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1221 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request) 766 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request)
1222 { 767 {
1223 m_log.Debug("[MONEY]: Dynamic balance update called."); 768 m_log.Debug("[MONEY]: Dynamic balance update called.");
1224 Hashtable requestData = (Hashtable)request.Params[0]; 769 Hashtable requestData = (Hashtable) request.Params[0];
1225 770
1226 if (requestData.ContainsKey("agentId")) 771 if (requestData.ContainsKey("agentId"))
1227 { 772 {
1228 LLUUID agentId = LLUUID.Zero; 773 LLUUID agentId = LLUUID.Zero;
1229 774
1230 Helpers.TryParse((string)requestData["agentId"], out agentId); 775 Helpers.TryParse((string) requestData["agentId"], out agentId);
1231 if (agentId != LLUUID.Zero) 776 if (agentId != LLUUID.Zero)
1232 { 777 {
1233 GetRemoteBalance(agentId); 778 GetRemoteBalance(agentId);
1234
1235 } 779 }
1236 else 780 else
1237 { 781 {
@@ -1245,7 +789,7 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1245 XmlRpcResponse r = new XmlRpcResponse(); 789 XmlRpcResponse r = new XmlRpcResponse();
1246 Hashtable rparms = new Hashtable(); 790 Hashtable rparms = new Hashtable();
1247 rparms["success"] = true; 791 rparms["success"] = true;
1248 792
1249 r.Value = rparms; 793 r.Value = rparms;
1250 return r; 794 return r;
1251 } 795 }
@@ -1257,24 +801,24 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1257 { 801 {
1258 XmlRpcResponse ret = new XmlRpcResponse(); 802 XmlRpcResponse ret = new XmlRpcResponse();
1259 Hashtable retparam = new Hashtable(); 803 Hashtable retparam = new Hashtable();
1260 Hashtable requestData = (Hashtable)request.Params[0]; 804 Hashtable requestData = (Hashtable) request.Params[0];
1261 805
1262 LLUUID agentId = LLUUID.Zero; 806 LLUUID agentId = LLUUID.Zero;
1263 LLUUID soundId = LLUUID.Zero; 807 LLUUID soundId = LLUUID.Zero;
1264 808
1265 Helpers.TryParse((string)requestData["agentId"], out agentId); 809 Helpers.TryParse((string) requestData["agentId"], out agentId);
1266 Helpers.TryParse((string)requestData["soundId"], out soundId); 810 Helpers.TryParse((string) requestData["soundId"], out soundId);
1267 string text=(string)requestData["text"]; 811 string text = (string) requestData["text"];
1268 string secret=(string)requestData["secret"]; 812 string secret = (string) requestData["secret"];
1269 813
1270 Scene userScene = GetRandomScene(); 814 Scene userScene = GetRandomScene();
1271 if(userScene.RegionInfo.regionSecret.ToString() == secret) 815 if (userScene.RegionInfo.regionSecret.ToString() == secret)
1272 { 816 {
1273 IClientAPI client = LocateClientObject(agentId); 817 IClientAPI client = LocateClientObject(agentId);
1274 818
1275 if (client != null) 819 if (client != null)
1276 { 820 {
1277 if(soundId != LLUUID.Zero) 821 if (soundId != LLUUID.Zero)
1278 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0); 822 client.SendPlayAttachedSound(soundId, LLUUID.Zero, LLUUID.Zero, 1.0f, 0);
1279 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text); 823 client.SendBlueBoxMessage(LLUUID.Zero, LLUUID.Zero, "", text);
1280 retparam.Add("success", true); 824 retparam.Add("success", true);
@@ -1293,12 +837,11 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1293 return ret; 837 return ret;
1294 } 838 }
1295 839
1296
1297 # region Standalone box enablers only 840 # region Standalone box enablers only
1298 841
1299 public XmlRpcResponse quote_func(XmlRpcRequest request) 842 public XmlRpcResponse quote_func(XmlRpcRequest request)
1300 { 843 {
1301 Hashtable requestData = (Hashtable)request.Params[0]; 844 Hashtable requestData = (Hashtable) request.Params[0];
1302 LLUUID agentId = LLUUID.Zero; 845 LLUUID agentId = LLUUID.Zero;
1303 int amount = 0; 846 int amount = 0;
1304 Hashtable quoteResponse = new Hashtable(); 847 Hashtable quoteResponse = new Hashtable();
@@ -1306,51 +849,48 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1306 849
1307 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 850 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1308 { 851 {
1309 Helpers.TryParse((string)requestData["agentId"], out agentId); 852 Helpers.TryParse((string) requestData["agentId"], out agentId);
1310 try 853 try
1311 { 854 {
1312 amount = (Int32)requestData["currencyBuy"]; 855 amount = (Int32) requestData["currencyBuy"];
1313 } 856 }
1314 catch (InvalidCastException) 857 catch (InvalidCastException)
1315 { 858 {
1316
1317 } 859 }
1318 Hashtable currencyResponse = new Hashtable(); 860 Hashtable currencyResponse = new Hashtable();
1319 currencyResponse.Add("estimatedCost", 0); 861 currencyResponse.Add("estimatedCost", 0);
1320 currencyResponse.Add("currencyBuy", amount); 862 currencyResponse.Add("currencyBuy", amount);
1321 863
1322 quoteResponse.Add("success", true); 864 quoteResponse.Add("success", true);
1323 quoteResponse.Add("currency", currencyResponse); 865 quoteResponse.Add("currency", currencyResponse);
1324 quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); 866 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
1325 867
1326 returnval.Value = quoteResponse; 868 returnval.Value = quoteResponse;
1327 return returnval; 869 return returnval;
1328 } 870 }
1329 871
1330 872
1331
1332 quoteResponse.Add("success", false); 873 quoteResponse.Add("success", false);
1333 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box"); 874 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box");
1334 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki"); 875 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki");
1335 returnval.Value = quoteResponse; 876 returnval.Value = quoteResponse;
1336 return returnval; 877 return returnval;
1337 } 878 }
879
1338 public XmlRpcResponse buy_func(XmlRpcRequest request) 880 public XmlRpcResponse buy_func(XmlRpcRequest request)
1339 { 881 {
1340 882 Hashtable requestData = (Hashtable) request.Params[0];
1341 Hashtable requestData = (Hashtable)request.Params[0];
1342 LLUUID agentId = LLUUID.Zero; 883 LLUUID agentId = LLUUID.Zero;
1343 int amount = 0; 884 int amount = 0;
1344 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 885 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1345 { 886 {
1346 Helpers.TryParse((string)requestData["agentId"], out agentId); 887 Helpers.TryParse((string) requestData["agentId"], out agentId);
1347 try 888 try
1348 { 889 {
1349 amount = (Int32)requestData["currencyBuy"]; 890 amount = (Int32) requestData["currencyBuy"];
1350 } 891 }
1351 catch (InvalidCastException) 892 catch (InvalidCastException)
1352 { 893 {
1353
1354 } 894 }
1355 if (agentId != LLUUID.Zero) 895 if (agentId != LLUUID.Zero)
1356 { 896 {
@@ -1412,26 +952,25 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1412 ret.Value = retparam; 952 ret.Value = retparam;
1413 953
1414 return ret; 954 return ret;
1415
1416 } 955 }
956
1417 public XmlRpcResponse landBuy_func(XmlRpcRequest request) 957 public XmlRpcResponse landBuy_func(XmlRpcRequest request)
1418 { 958 {
1419 XmlRpcResponse ret = new XmlRpcResponse(); 959 XmlRpcResponse ret = new XmlRpcResponse();
1420 Hashtable retparam = new Hashtable(); 960 Hashtable retparam = new Hashtable();
1421 Hashtable requestData = (Hashtable)request.Params[0]; 961 Hashtable requestData = (Hashtable) request.Params[0];
1422 962
1423 LLUUID agentId = LLUUID.Zero; 963 LLUUID agentId = LLUUID.Zero;
1424 int amount = 0; 964 int amount = 0;
1425 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy")) 965 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1426 { 966 {
1427 Helpers.TryParse((string)requestData["agentId"], out agentId); 967 Helpers.TryParse((string) requestData["agentId"], out agentId);
1428 try 968 try
1429 { 969 {
1430 amount = (Int32)requestData["currencyBuy"]; 970 amount = (Int32) requestData["currencyBuy"];
1431 } 971 }
1432 catch (InvalidCastException) 972 catch (InvalidCastException)
1433 { 973 {
1434
1435 } 974 }
1436 if (agentId != LLUUID.Zero) 975 if (agentId != LLUUID.Zero)
1437 { 976 {
@@ -1457,35 +996,475 @@ namespace OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney
1457 ret.Value = retparam; 996 ret.Value = retparam;
1458 997
1459 return ret; 998 return ret;
999 }
1000
1001 #endregion
1002
1003 #region local Fund Management
1004
1005 /// <summary>
1006 /// Ensures that the agent accounting data is set up in this instance.
1007 /// </summary>
1008 /// <param name="agentID"></param>
1009 private void CheckExistAndRefreshFunds(LLUUID agentID)
1010 {
1011 lock (m_KnownClientFunds)
1012 {
1013 if (!m_KnownClientFunds.ContainsKey(agentID))
1014 {
1015 m_KnownClientFunds.Add(agentID, m_stipend);
1016 }
1017 else
1018 {
1019 if (m_KnownClientFunds[agentID] <= m_minFundsBeforeRefresh)
1020 {
1021 m_KnownClientFunds[agentID] = m_stipend;
1022 }
1023 }
1024 }
1025 }
1460 1026
1027 /// <summary>
1028 /// Gets the amount of Funds for an agent
1029 /// </summary>
1030 /// <param name="AgentID"></param>
1031 /// <returns></returns>
1032 private int GetFundsForAgentID(LLUUID AgentID)
1033 {
1034 int returnfunds = 0;
1035 lock (m_KnownClientFunds)
1036 {
1037 if (m_KnownClientFunds.ContainsKey(AgentID))
1038 {
1039 returnfunds = m_KnownClientFunds[AgentID];
1040 }
1041 else
1042 {
1043 //throw new Exception("Unable to get funds.");
1044 }
1045 }
1046 return returnfunds;
1461 } 1047 }
1048
1049 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
1050 {
1051 lock (m_KnownClientFunds)
1052 {
1053 if (m_KnownClientFunds.ContainsKey(AgentID))
1054 {
1055 m_KnownClientFunds[AgentID] = amount;
1056 }
1057 else
1058 {
1059 m_KnownClientFunds.Add(AgentID, amount);
1060 }
1061 }
1062 }
1063
1462 #endregion 1064 #endregion
1463 1065
1464 public void PostInitialise() 1066 #region Utility Helpers
1067
1068 /// <summary>
1069 /// Locates a IClientAPI for the client specified
1070 /// </summary>
1071 /// <param name="AgentID"></param>
1072 /// <returns></returns>
1073 private IClientAPI LocateClientObject(LLUUID AgentID)
1465 { 1074 {
1075 ScenePresence tPresence = null;
1076 IClientAPI rclient = null;
1077
1078 lock (m_scenel)
1079 {
1080 foreach (Scene _scene in m_scenel.Values)
1081 {
1082 tPresence = _scene.GetScenePresence(AgentID);
1083 if (tPresence != null)
1084 {
1085 if (!tPresence.IsChildAgent)
1086 {
1087 rclient = tPresence.ControllingClient;
1088 }
1089 }
1090 if (rclient != null)
1091 {
1092 return rclient;
1093 }
1094 }
1095 }
1096 return null;
1466 } 1097 }
1467 1098
1468 public void Close() 1099 private Scene LocateSceneClientIn(LLUUID AgentId)
1469 { 1100 {
1101 lock (m_scenel)
1102 {
1103 foreach (Scene _scene in m_scenel.Values)
1104 {
1105 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
1106 if (tPresence != null)
1107 {
1108 if (!tPresence.IsChildAgent)
1109 {
1110 return _scene;
1111 }
1112 }
1113 }
1114 }
1115 return null;
1470 } 1116 }
1471 1117
1472 public string Name 1118 /// <summary>
1119 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
1120 /// </summary>
1121 /// <returns></returns>
1122 public Scene GetRandomScene()
1473 { 1123 {
1474 get { return "BetaGridLikeMoneyModule"; } 1124 lock (m_scenel)
1125 {
1126 foreach (Scene rs in m_scenel.Values)
1127 return rs;
1128 }
1129 return null;
1475 } 1130 }
1476 1131
1477 public bool IsSharedModule 1132 /// <summary>
1133 /// Utility function to get a Scene by RegionID in a module
1134 /// </summary>
1135 /// <param name="RegionID"></param>
1136 /// <returns></returns>
1137 public Scene GetSceneByUUID(LLUUID RegionID)
1478 { 1138 {
1479 get { return true; } 1139 lock (m_scenel)
1140 {
1141 foreach (Scene rs in m_scenel.Values)
1142 {
1143 if (rs.RegionInfo.originRegionID == RegionID)
1144 {
1145 return rs;
1146 }
1147 }
1148 }
1149 return null;
1150 }
1151
1152 #endregion
1153
1154 #region event Handlers
1155
1156 public void requestPayPrice(IClientAPI client, LLUUID objectID)
1157 {
1158 Scene scene = LocateSceneClientIn(client.AgentId);
1159 if (scene == null)
1160 return;
1161
1162 SceneObjectPart task = scene.GetSceneObjectPart(objectID);
1163 if (task == null)
1164 return;
1165 SceneObjectGroup group = task.ParentGroup;
1166 SceneObjectPart root = group.RootPart;
1167
1168 client.SendPayPrice(objectID, root.PayPrice);
1169 }
1170
1171 /// <summary>
1172 /// When the client closes the connection we remove their accounting info from memory to free up resources.
1173 /// </summary>
1174 /// <param name="AgentID"></param>
1175 public void ClientClosed(LLUUID AgentID)
1176 {
1177 lock (m_KnownClientFunds)
1178 {
1179 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
1180 {
1181 }
1182 else
1183 {
1184 m_KnownClientFunds.Remove(AgentID);
1185 }
1186 }
1480 } 1187 }
1188
1189 /// <summary>
1190 /// Event called Economy Data Request handler.
1191 /// </summary>
1192 /// <param name="agentId"></param>
1193 public void EconomyDataRequestHandler(LLUUID agentId)
1194 {
1195 IClientAPI user = LocateClientObject(agentId);
1196
1197 if (user != null)
1198 {
1199 user.SendEconomyData(EnergyEfficiency, ObjectCapacity, ObjectCount, PriceEnergyUnit, PriceGroupCreate,
1200 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
1201 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
1202 TeleportMinPrice, TeleportPriceExponent);
1203 }
1204 }
1205
1206 private void ValidateLandBuy(Object osender, EventManager.LandBuyArgs e)
1207 {
1208 if (m_MoneyAddress.Length == 0)
1209 {
1210 lock (m_KnownClientFunds)
1211 {
1212 if (m_KnownClientFunds.ContainsKey(e.agentId))
1213 {
1214 // Does the sender have enough funds to give?
1215 if (m_KnownClientFunds[e.agentId] >= e.parcelPrice)
1216 {
1217 lock (e)
1218 {
1219 e.economyValidated = true;
1220 }
1221 }
1222 }
1223 }
1224 }
1225 else
1226 {
1227 if (GetRemoteBalance(e.agentId) >= e.parcelPrice)
1228 {
1229 lock (e)
1230 {
1231 e.economyValidated = true;
1232 }
1233 }
1234 }
1235 }
1236
1237 private void processLandBuy(Object osender, EventManager.LandBuyArgs e)
1238 {
1239 lock (e)
1240 {
1241 if (e.economyValidated == true && e.transactionID == 0)
1242 {
1243 e.transactionID = Util.UnixTimeSinceEpoch();
1244
1245 if (doMoneyTransfer(e.agentId, e.parcelOwnerID, e.parcelPrice, 0, "Land purchase"))
1246 {
1247 lock (e)
1248 {
1249 e.amountDebited = e.parcelPrice;
1250 }
1251 }
1252 }
1253 }
1254 }
1255
1256 /// <summary>
1257 /// THis method gets called when someone pays someone else as a gift.
1258 /// </summary>
1259 /// <param name="osender"></param>
1260 /// <param name="e"></param>
1261 private void MoneyTransferAction(Object osender, EventManager.MoneyTransferArgs e)
1262 {
1263 IClientAPI sender = null;
1264 IClientAPI receiver = null;
1265
1266 if (m_MoneyAddress.Length > 0) // Handled on server
1267 e.description = String.Empty;
1268
1269 if (e.transactiontype == 5008) // Object gets paid
1270 {
1271 sender = LocateClientObject(e.sender);
1272 if (sender != null)
1273 {
1274 SceneObjectPart part = findPrim(e.receiver);
1275 if (part == null)
1276 return;
1277
1278 string name = resolveAgentName(part.OwnerID);
1279 if (name == String.Empty)
1280 name = "(hippos)";
1281
1282 receiver = LocateClientObject(part.OwnerID);
1283
1284 string description = String.Format("Paid {0} via object {1}", name, e.description);
1285 bool transactionresult = doMoneyTransfer(e.sender, part.OwnerID, e.amount, e.transactiontype, description);
1286
1287 if (transactionresult)
1288 {
1289 ObjectPaid handlerOnObjectPaid = OnObjectPaid;
1290 if (handlerOnObjectPaid != null)
1291 {
1292 handlerOnObjectPaid(e.receiver, e.sender, e.amount);
1293 }
1294 }
1295
1296 if (e.sender != e.receiver)
1297 {
1298 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1299 }
1300 if (receiver != null)
1301 {
1302 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(part.OwnerID));
1303 }
1304 }
1305 return;
1306 }
1307
1308 sender = LocateClientObject(e.sender);
1309 if (sender != null)
1310 {
1311 receiver = LocateClientObject(e.receiver);
1312
1313 bool transactionresult = doMoneyTransfer(e.sender, e.receiver, e.amount, e.transactiontype, e.description);
1314
1315 if (e.sender != e.receiver)
1316 {
1317 if (sender != null)
1318 {
1319 sender.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.sender));
1320 }
1321 }
1322
1323 if (receiver != null)
1324 {
1325 receiver.SendMoneyBalance(LLUUID.Random(), transactionresult, Helpers.StringToField(e.description), GetFundsForAgentID(e.receiver));
1326 }
1327 }
1328 else
1329 {
1330 m_log.Warn("[MONEY]: Potential Fraud Warning, got money transfer request for avatar that isn't in this simulator - Details; Sender:" +
1331 e.sender.ToString() + " Receiver: " + e.receiver.ToString() + " Amount: " + e.amount.ToString());
1332 }
1333 }
1334
1335 /// <summary>
1336 /// Event Handler for when a root agent becomes a child agent
1337 /// </summary>
1338 /// <param name="avatar"></param>
1339 private void MakeChildAgent(ScenePresence avatar)
1340 {
1341 lock (m_rootAgents)
1342 {
1343 if (m_rootAgents.ContainsKey(avatar.UUID))
1344 {
1345 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
1346 {
1347 m_rootAgents.Remove(avatar.UUID);
1348 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
1349 }
1350 }
1351 }
1352 }
1353
1354 /// <summary>
1355 /// Event Handler for when the client logs out.
1356 /// </summary>
1357 /// <param name="AgentId"></param>
1358 private void ClientLoggedOut(LLUUID AgentId)
1359 {
1360 lock (m_rootAgents)
1361 {
1362 if (m_rootAgents.ContainsKey(AgentId))
1363 {
1364 m_rootAgents.Remove(AgentId);
1365 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
1366 }
1367 }
1368 }
1369
1370 /// <summary>
1371 /// Call this when the client disconnects.
1372 /// </summary>
1373 /// <param name="client"></param>
1374 public void ClientClosed(IClientAPI client)
1375 {
1376 ClientClosed(client.AgentId);
1377 }
1378
1379 /// <summary>
1380 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
1381 /// </summary>
1382 /// <param name="avatar"></param>
1383 /// <param name="localLandID"></param>
1384 /// <param name="regionID"></param>
1385 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
1386 {
1387 lock (m_rootAgents)
1388 {
1389 if (m_rootAgents.ContainsKey(avatar.UUID))
1390 {
1391 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
1392 {
1393 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
1394 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1395 // Claim User! my user! Mine mine mine!
1396 if (m_MoneyAddress.Length > 0)
1397 {
1398 Scene RegionItem = GetSceneByUUID(regionID);
1399 if (RegionItem != null)
1400 {
1401 Hashtable hresult =
1402 claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1403 if ((bool) hresult["success"] == true)
1404 {
1405 int funds = 0;
1406 try
1407 {
1408 funds = (Int32) hresult["funds"];
1409 }
1410 catch (InvalidCastException)
1411 {
1412 }
1413 SetLocalFundsForAgentID(avatar.UUID, funds);
1414 }
1415 else
1416 {
1417 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1418 }
1419 }
1420 }
1421 }
1422 }
1423 else
1424 {
1425 lock (m_rootAgents)
1426 {
1427 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
1428 }
1429 if (m_MoneyAddress.Length > 0)
1430 {
1431 Scene RegionItem = GetSceneByUUID(regionID);
1432 if (RegionItem != null)
1433 {
1434 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
1435 if ((bool) hresult["success"] == true)
1436 {
1437 int funds = 0;
1438 try
1439 {
1440 funds = (Int32) hresult["funds"];
1441 }
1442 catch (InvalidCastException)
1443 {
1444 }
1445 SetLocalFundsForAgentID(avatar.UUID, funds);
1446 }
1447 else
1448 {
1449 avatar.ControllingClient.SendAgentAlertMessage((string) hresult["errorMessage"], true);
1450 }
1451 }
1452 }
1453
1454 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
1455 }
1456 }
1457 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
1458 }
1459
1460 #endregion
1481 } 1461 }
1482 1462
1483 public enum TransactionType : int 1463 public enum TransactionType : int
1484 { 1464 {
1485 SystemGenerated=0, 1465 SystemGenerated = 0,
1486 RegionMoneyRequest=1, 1466 RegionMoneyRequest = 1,
1487 Gift=2, 1467 Gift = 2,
1488 Purchase=3 1468 Purchase = 3
1489
1490 } 1469 }
1491} \ No newline at end of file 1470} \ No newline at end of file