aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/RegionInfo.cs1
-rw-r--r--OpenSim/Grid/GridServer/GridManager.cs17
-rw-r--r--OpenSim/Region/Communications/OGS1/OGS1GridServices.cs1
-rw-r--r--OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs885
-rw-r--r--OpenSim/Region/Environment/Modules/FriendsModule.cs2
-rw-r--r--bin/OpenSim.ini.example9
6 files changed, 898 insertions, 17 deletions
diff --git a/OpenSim/Framework/RegionInfo.cs b/OpenSim/Framework/RegionInfo.cs
index da20edc..f19f1db 100644
--- a/OpenSim/Framework/RegionInfo.cs
+++ b/OpenSim/Framework/RegionInfo.cs
@@ -216,6 +216,7 @@ namespace OpenSim.Framework
216 public string MasterAvatarFirstName = String.Empty; 216 public string MasterAvatarFirstName = String.Empty;
217 public string MasterAvatarLastName = String.Empty; 217 public string MasterAvatarLastName = String.Empty;
218 public string MasterAvatarSandboxPassword = String.Empty; 218 public string MasterAvatarSandboxPassword = String.Empty;
219 public string regionSecret = LLUUID.Random().ToString();
219 public string proxyUrl = ""; 220 public string proxyUrl = "";
220 public LLUUID originRegionID = LLUUID.Zero; 221 public LLUUID originRegionID = LLUUID.Zero;
221 222
diff --git a/OpenSim/Grid/GridServer/GridManager.cs b/OpenSim/Grid/GridServer/GridManager.cs
index 7b41f6e..ba526c0 100644
--- a/OpenSim/Grid/GridServer/GridManager.cs
+++ b/OpenSim/Grid/GridServer/GridManager.cs
@@ -530,7 +530,22 @@ namespace OpenSim.Grid.GridServer
530 530
531 sim.regionRecvKey = String.Empty; 531 sim.regionRecvKey = String.Empty;
532 sim.regionSendKey = String.Empty; 532 sim.regionSendKey = String.Empty;
533 sim.regionSecret = Config.SimRecvKey; 533
534 if (requestData.ContainsKey("region_secret"))
535 {
536 string regionsecret = (string)requestData["region_secret"];
537 if (regionsecret.Length > 0)
538 sim.regionSecret = regionsecret;
539 else
540 sim.regionSecret = Config.SimRecvKey;
541
542 }
543 else
544 {
545 sim.regionSecret = Config.SimRecvKey;
546 }
547
548
534 sim.regionDataURI = String.Empty; 549 sim.regionDataURI = String.Empty;
535 sim.regionAssetURI = Config.DefaultAssetServer; 550 sim.regionAssetURI = Config.DefaultAssetServer;
536 sim.regionAssetRecvKey = Config.AssetRecvKey; 551 sim.regionAssetRecvKey = Config.AssetRecvKey;
diff --git a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
index 22bb0f0..8c40d3e 100644
--- a/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
+++ b/OpenSim/Region/Communications/OGS1/OGS1GridServices.cs
@@ -112,6 +112,7 @@ namespace OpenSim.Region.Communications.OGS1
112 GridParams["map-image-id"] = regionInfo.EstateSettings.terrainImageID.ToString(); 112 GridParams["map-image-id"] = regionInfo.EstateSettings.terrainImageID.ToString();
113 GridParams["originUUID"] = regionInfo.originRegionID.ToString(); 113 GridParams["originUUID"] = regionInfo.originRegionID.ToString();
114 GridParams["server_uri"] = regionInfo.ServerURI; 114 GridParams["server_uri"] = regionInfo.ServerURI;
115 GridParams["region_secret"] = regionInfo.regionSecret;
115 116
116 // part of an initial brutish effort to provide accurate information (as per the xml region spec) 117 // part of an initial brutish effort to provide accurate information (as per the xml region spec)
117 // wrt the ownership of a given region 118 // wrt the ownership of a given region
diff --git a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
index 8d6e9fd..aabb2d1 100644
--- a/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
+++ b/OpenSim/Region/Environment/Modules/BetaGridLikeMoneyModule.cs
@@ -26,20 +26,38 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Net;
32using System.Net.Sockets;
33using System.Xml;
30using libsecondlife; 34using libsecondlife;
31using Nini.Config; 35using Nini.Config;
32using OpenSim.Framework; 36using OpenSim.Framework;
33using OpenSim.Region.Environment.Interfaces; 37using OpenSim.Region.Environment.Interfaces;
34using OpenSim.Region.Environment.Scenes; 38using OpenSim.Region.Environment.Scenes;
39using Nwc.XmlRpc;
40
35using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs; 41using MoneyTransferArgs = OpenSim.Region.Environment.Scenes.EventManager.MoneyTransferArgs;
36 42
37namespace OpenSim.Region.Environment.Modules 43namespace OpenSim.Region.Environment.Modules
38{ 44{
45 /// <summary>
46 /// 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 /// </summary>
39 public class BetaGridLikeMoneyModule: IRegionModule 49 public class BetaGridLikeMoneyModule: IRegionModule
40 { 50 {
41 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); 51 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
42 52
53 /// <summary>
54 /// Region UUIDS indexed by AgentID
55 /// </summary>
56 Dictionary<LLUUID, LLUUID> m_rootAgents = new Dictionary<LLUUID, LLUUID>();
57
58 /// <summary>
59 /// Scenes by Region Handle
60 /// </summary>
43 private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>(); 61 private Dictionary<ulong,Scene> m_scenel = new Dictionary<ulong,Scene>();
44 62
45 private IConfigSource m_gConfig; 63 private IConfigSource m_gConfig;
@@ -55,7 +73,7 @@ namespace OpenSim.Region.Environment.Modules
55 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>(); 73 private Dictionary<LLUUID, int> m_KnownClientFunds = new Dictionary<LLUUID, int>();
56 74
57 private bool gridmode = false; 75 private bool gridmode = false;
58 76 private Scene XMLRPCHandler;
59 private float EnergyEfficiency = 0f; 77 private float EnergyEfficiency = 0f;
60 private int ObjectCapacity = 45000; 78 private int ObjectCapacity = 45000;
61 private int ObjectCount = 0; 79 private int ObjectCount = 0;
@@ -73,11 +91,21 @@ namespace OpenSim.Region.Environment.Modules
73 private int PriceUpload = 0; 91 private int PriceUpload = 0;
74 private int TeleportMinPrice = 0; 92 private int TeleportMinPrice = 0;
75 private int UserLevelPaysFees = 2; 93 private int UserLevelPaysFees = 2;
94 private string m_MoneyAddress = String.Empty;
95 private string m_LandAddress = String.Empty;
76 96
77 float TeleportPriceExponent = 0f; 97 float TeleportPriceExponent = 0f;
78 98
99 /// <summary>
100 /// Where Stipends come from and Fees go to.
101 /// </summary>
79 LLUUID EconomyBaseAccount = LLUUID.Zero; 102 LLUUID EconomyBaseAccount = LLUUID.Zero;
80 103
104 /// <summary>
105 /// Startup
106 /// </summary>
107 /// <param name="scene"></param>
108 /// <param name="config"></param>
81 public void Initialise(Scene scene, IConfigSource config) 109 public void Initialise(Scene scene, IConfigSource config)
82 { 110 {
83 m_gConfig = config; 111 m_gConfig = config;
@@ -94,6 +122,31 @@ namespace OpenSim.Region.Environment.Modules
94 { 122 {
95 lock (m_scenel) 123 lock (m_scenel)
96 { 124 {
125 if (m_scenel.Count == 0)
126 {
127 XMLRPCHandler = scene;
128
129 // To use the following you need to add:
130 // -helperuri <ADDRESS TO HERE OR grid MONEY SERVER>
131 // to the command line parameters you use to start up your client
132 // This commonly looks like -helperuri http://127.0.0.1:9000/
133
134 if (m_MoneyAddress.Length > 0)
135 {
136 // Centralized grid structure using OpenSimWi Redux revision 9+
137 scene.AddXmlRPCHandler("dynamic_balance_update_request", GridMoneyUpdate);
138 }
139 else
140 {
141 // Local Server.. enables functionality only.
142 scene.AddXmlRPCHandler("getCurrencyQuote", quote_func);
143 scene.AddXmlRPCHandler("buyCurrency", buy_func);
144 scene.AddXmlRPCHandler("preflightBuyLandPrep", preflightBuyLandPrep_func);
145 scene.AddXmlRPCHandler("buyLandPrep", landBuy_func);
146 }
147
148
149 }
97 150
98 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle)) 151 if (m_scenel.ContainsKey(scene.RegionInfo.RegionHandle))
99 { 152 {
@@ -109,10 +162,18 @@ namespace OpenSim.Region.Environment.Modules
109 scene.EventManager.OnMoneyTransfer += MoneyTransferAction; 162 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
110 scene.EventManager.OnClientClosed += ClientClosed; 163 scene.EventManager.OnClientClosed += ClientClosed;
111 scene.EventManager.OnNewInventoryItemUploadComplete += NewInventoryItemEconomyHandler; 164 scene.EventManager.OnNewInventoryItemUploadComplete += NewInventoryItemEconomyHandler;
165 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
166 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
167 scene.EventManager.OnClientClosed += ClientLoggedOut;
112 168
113 } 169 }
114 } 170 }
115 171 /// <summary>
172 /// Parse Configuration
173 /// </summary>
174 /// <param name="scene"></param>
175 /// <param name="startupConfig"></param>
176 /// <param name="config"></param>
116 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config) 177 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string config)
117 { 178 {
118 if (config == "Startup" && startupConfig != null) 179 if (config == "Startup" && startupConfig != null)
@@ -145,12 +206,18 @@ namespace OpenSim.Region.Environment.Modules
145 m_stipend = startupConfig.GetInt("UserStipend", 500); 206 m_stipend = startupConfig.GetInt("UserStipend", 500);
146 m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10); 207 m_minFundsBeforeRefresh = startupConfig.GetInt("IssueStipendWhenClientIsBelowAmount", 10);
147 m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true); 208 m_keepMoneyAcrossLogins = startupConfig.GetBoolean("KeepMoneyAcrossLogins", true);
209 m_MoneyAddress = startupConfig.GetString("CurrencyServer", String.Empty);
210 m_LandAddress = startupConfig.GetString("LandServer", String.Empty);
148 } 211 }
149 212
150 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter. 213 // Send ObjectCapacity to Scene.. Which sends it to the SimStatsReporter.
151 scene.SetObjectCapacity(ObjectCapacity); 214 scene.SetObjectCapacity(ObjectCapacity);
152 } 215 }
153 216
217 /// <summary>
218 /// New Client Event Handler
219 /// </summary>
220 /// <param name="client"></param>
154 private void OnNewClient(IClientAPI client) 221 private void OnNewClient(IClientAPI client)
155 { 222 {
156 // Here we check if we're in grid mode 223 // Here we check if we're in grid mode
@@ -159,7 +226,58 @@ namespace OpenSim.Region.Environment.Modules
159 226
160 if (gridmode) 227 if (gridmode)
161 { 228 {
162 CheckExistAndRefreshFunds(client.AgentId); 229 if (m_MoneyAddress.Length == 0)
230 {
231
232 CheckExistAndRefreshFunds(client.AgentId);
233 }
234 else
235 {
236 //client.SecureSessionId;
237 Scene s = GetRandomScene();
238 if (s != null)
239 {
240 //s.RegionInfo.RegionHandle;
241 LLUUID agentID = LLUUID.Zero;
242 int funds = 0;
243
244 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(client.AgentId, client.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret);
245 if ((bool)hbinfo["success"] == true)
246 {
247
248 Helpers.TryParse((string)hbinfo["agentId"], out agentID);
249 try
250 {
251 funds = (Int32)hbinfo["funds"];
252 }
253 catch (ArgumentException)
254 {
255 }
256 catch (FormatException)
257 {
258 }
259 catch (OverflowException)
260 {
261 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentID);
262 client.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
263 }
264 catch (InvalidCastException)
265 {
266 funds = 0;
267 }
268
269 m_KnownClientFunds[agentID] = funds;
270 }
271 else
272 {
273 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentID, (string)hbinfo["errorMessage"]);
274 client.SendAlertMessage((string)hbinfo["errorMessage"]);
275 }
276 SendMoneyBalance(client, agentID, client.SessionId, LLUUID.Zero);
277
278 }
279 }
280
163 } 281 }
164 else 282 else
165 { 283 {
@@ -170,19 +288,34 @@ namespace OpenSim.Region.Environment.Modules
170 client.OnEconomyDataRequest += EconomyDataRequestHandler; 288 client.OnEconomyDataRequest += EconomyDataRequestHandler;
171 client.OnMoneyBalanceRequest += SendMoneyBalance; 289 client.OnMoneyBalanceRequest += SendMoneyBalance;
172 client.OnLogout += ClientClosed; 290 client.OnLogout += ClientClosed;
173 291
174 292
175 } 293 }
176 294
295 #region event Handlers
296
297 /// <summary>
298 /// When the client closes the connection we remove their accounting info from memory to free up resources.
299 /// </summary>
300 /// <param name="AgentID"></param>
177 public void ClientClosed(LLUUID AgentID) 301 public void ClientClosed(LLUUID AgentID)
178 { 302 {
179 lock (m_KnownClientFunds) 303 lock (m_KnownClientFunds)
180 { 304 {
181 if (!m_keepMoneyAcrossLogins) 305 if (m_keepMoneyAcrossLogins && m_MoneyAddress.Length == 0)
306 {
307 }
308 else
309 {
182 m_KnownClientFunds.Remove(AgentID); 310 m_KnownClientFunds.Remove(AgentID);
311 }
183 } 312 }
184 } 313 }
185 314
315 /// <summary>
316 /// Event called Economy Data Request handler.
317 /// </summary>
318 /// <param name="agentId"></param>
186 public void EconomyDataRequestHandler(LLUUID agentId) 319 public void EconomyDataRequestHandler(LLUUID agentId)
187 { 320 {
188 IClientAPI user = LocateClientObject(agentId); 321 IClientAPI user = LocateClientObject(agentId);
@@ -196,6 +329,11 @@ namespace OpenSim.Region.Environment.Modules
196 } 329 }
197 } 330 }
198 331
332 /// <summary>
333 /// THis method gets called when someone pays someone else as a gift.
334 /// </summary>
335 /// <param name="osender"></param>
336 /// <param name="e"></param>
199 private void MoneyTransferAction (Object osender, MoneyTransferArgs e) 337 private void MoneyTransferAction (Object osender, MoneyTransferArgs e)
200 { 338 {
201 IClientAPI sender = null; 339 IClientAPI sender = null;
@@ -228,6 +366,13 @@ namespace OpenSim.Region.Environment.Modules
228 } 366 }
229 } 367 }
230 368
369 /// <summary>
370 /// A new inventory item came in, so we must charge if we're configured to do so!
371 /// </summary>
372 /// <param name="Uploader"></param>
373 /// <param name="AssetID"></param>
374 /// <param name="AssetName"></param>
375 /// <param name="userlevel"></param>
231 private void NewInventoryItemEconomyHandler(LLUUID Uploader, LLUUID AssetID, String AssetName, int userlevel) 376 private void NewInventoryItemEconomyHandler(LLUUID Uploader, LLUUID AssetID, String AssetName, int userlevel)
232 { 377 {
233 // Presumably a normal grid would actually send this information to a server somewhere. 378 // Presumably a normal grid would actually send this information to a server somewhere.
@@ -244,6 +389,144 @@ namespace OpenSim.Region.Environment.Modules
244 389
245 } 390 }
246 391
392 /// <summary>
393 /// Event Handler for when a root agent becomes a child agent
394 /// </summary>
395 /// <param name="avatar"></param>
396 private void MakeChildAgent(ScenePresence avatar)
397 {
398
399 lock (m_rootAgents)
400 {
401 if (m_rootAgents.ContainsKey(avatar.UUID))
402 {
403 if (m_rootAgents[avatar.UUID] == avatar.Scene.RegionInfo.originRegionID)
404 {
405 m_rootAgents.Remove(avatar.UUID);
406 m_log.Info("[MONEY]: Removing " + avatar.Firstname + " " + avatar.Lastname + " as a root agent");
407 }
408
409 }
410 }
411
412 }
413
414 /// <summary>
415 /// Event Handler for when the client logs out.
416 /// </summary>
417 /// <param name="AgentId"></param>
418 private void ClientLoggedOut(LLUUID AgentId)
419 {
420 lock (m_rootAgents)
421 {
422 if (m_rootAgents.ContainsKey(AgentId))
423 {
424 m_rootAgents.Remove(AgentId);
425 //m_log.Info("[MONEY]: Removing " + AgentId + ". Agent logged out.");
426 }
427 }
428 }
429
430 /// <summary>
431 /// Call this when the client disconnects.
432 /// </summary>
433 /// <param name="client"></param>
434 public void ClientClosed(IClientAPI client)
435 {
436 ClientClosed(client.AgentId);
437 }
438
439 /// <summary>
440 /// Event Handler for when an Avatar enters one of the parcels in the simulator.
441 /// </summary>
442 /// <param name="avatar"></param>
443 /// <param name="localLandID"></param>
444 /// <param name="regionID"></param>
445 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
446 {
447 lock (m_rootAgents)
448 {
449 if (m_rootAgents.ContainsKey(avatar.UUID))
450 {
451 if (avatar.Scene.RegionInfo.originRegionID != m_rootAgents[avatar.UUID])
452 {
453 m_rootAgents[avatar.UUID] = avatar.Scene.RegionInfo.originRegionID;
454 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
455 // Claim User! my user! Mine mine mine!
456 if (m_MoneyAddress.Length > 0)
457 {
458 Scene RegionItem = GetSceneByUUID(regionID);
459 if (RegionItem != null)
460 {
461 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
462 if ((bool)hresult["success"] == true)
463 {
464 int funds = 0;
465 try
466 {
467 funds = (Int32)hresult["funds"];
468 }
469 catch (InvalidCastException)
470 {
471
472 }
473 SetLocalFundsForAgentID(avatar.UUID, funds);
474 }
475 else
476 {
477 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
478 }
479 }
480 }
481 }
482 }
483 else
484 {
485 lock (m_rootAgents)
486 {
487 m_rootAgents.Add(avatar.UUID, avatar.Scene.RegionInfo.originRegionID);
488 }
489 if (m_MoneyAddress.Length > 0)
490 {
491 Scene RegionItem = GetSceneByUUID(regionID);
492 if (RegionItem != null)
493 {
494 Hashtable hresult = claim_user(avatar.UUID, avatar.ControllingClient.SecureSessionId, regionID, RegionItem.RegionInfo.regionSecret);
495 if ((bool)hresult["success"] == true)
496 {
497 int funds = 0;
498 try
499 {
500 funds = (Int32)hresult["funds"];
501 }
502 catch (InvalidCastException)
503 {
504
505 }
506 SetLocalFundsForAgentID(avatar.UUID, funds);
507 }
508 else
509 {
510 avatar.ControllingClient.SendAgentAlertMessage((string)hresult["errorMessage"], true);
511 }
512 }
513 }
514
515 //m_log.Info("[MONEY]: Claiming " + avatar.Firstname + " " + avatar.Lastname + " in region:" + avatar.RegionHandle + ".");
516 }
517 }
518 //m_log.Info("[FRIEND]: " + avatar.Name + " status:" + (!avatar.IsChildAgent).ToString());
519 }
520
521 #endregion
522
523 /// <summary>
524 /// Transfer money This currently does Gifts only.
525 /// </summary>
526 /// <param name="Sender"></param>
527 /// <param name="Receiver"></param>
528 /// <param name="amount"></param>
529 /// <returns></returns>
247 private bool doMoneyTranfer(LLUUID Sender, LLUUID Receiver, int amount) 530 private bool doMoneyTranfer(LLUUID Sender, LLUUID Receiver, int amount)
248 { 531 {
249 bool result = false; 532 bool result = false;
@@ -267,10 +550,20 @@ namespace OpenSim.Region.Environment.Modules
267 // Make a record for them so they get the updated balance when they login 550 // Make a record for them so they get the updated balance when they login
268 CheckExistAndRefreshFunds(Receiver); 551 CheckExistAndRefreshFunds(Receiver);
269 } 552 }
553 if (m_enabled)
554 {
555 if (m_MoneyAddress.Length == 0)
556 {
557 //Add the amount to the Receiver's funds
558 m_KnownClientFunds[Receiver] += amount;
559 result = true;
560 }
561 else
562 {
270 563
271 //Add the amount to the Receiver's funds 564 result = TransferMoneyonMoneyServer(Sender, Receiver, amount);
272 m_KnownClientFunds[Receiver] += amount; 565 }
273 result = true; 566 }
274 } 567 }
275 else 568 else
276 { 569 {
@@ -286,7 +579,12 @@ namespace OpenSim.Region.Environment.Modules
286 } 579 }
287 return result; 580 return result;
288 } 581 }
289 582 #region Utility Helpers
583 /// <summary>
584 /// Locates a IClientAPI for the client specified
585 /// </summary>
586 /// <param name="AgentID"></param>
587 /// <returns></returns>
290 private IClientAPI LocateClientObject(LLUUID AgentID) 588 private IClientAPI LocateClientObject(LLUUID AgentID)
291 { 589 {
292 ScenePresence tPresence = null; 590 ScenePresence tPresence = null;
@@ -314,11 +612,71 @@ namespace OpenSim.Region.Environment.Modules
314 return null; 612 return null;
315 } 613 }
316 614
317 public void ClientClosed(IClientAPI client) 615 private Scene LocateSceneClientIn(LLUUID AgentId)
318 { 616 {
319 ClientClosed(client.AgentId); 617 lock (m_scenel)
618 {
619 foreach (Scene _scene in m_scenel.Values)
620 {
621 ScenePresence tPresence = _scene.GetScenePresence(AgentId);
622 if (tPresence != null)
623 {
624 if (!tPresence.IsChildAgent)
625 {
626 return _scene;
627 }
628 }
629
630 }
631
632 }
633 return null;
320 } 634 }
321 635
636 /// <summary>
637 /// Utility function Gets a Random scene in the instance. For when which scene exactly you're doing something with doesn't matter
638 /// </summary>
639 /// <returns></returns>
640 public Scene GetRandomScene()
641 {
642 lock (m_scenel)
643 {
644 foreach (Scene rs in m_scenel.Values)
645 return rs;
646 }
647 return null;
648
649 }
650 /// <summary>
651 /// Utility function to get a Scene by RegionID in a module
652 /// </summary>
653 /// <param name="RegionID"></param>
654 /// <returns></returns>
655 public Scene GetSceneByUUID(LLUUID RegionID)
656 {
657 lock (m_scenel)
658 {
659 foreach (Scene rs in m_scenel.Values)
660 {
661 if (rs.RegionInfo.originRegionID == RegionID)
662 {
663 return rs;
664 }
665 }
666 }
667 return null;
668 }
669 #endregion
670
671
672
673 /// <summary>
674 /// Sends the the stored money balance to the client
675 /// </summary>
676 /// <param name="client"></param>
677 /// <param name="agentID"></param>
678 /// <param name="SessionID"></param>
679 /// <param name="TransactionID"></param>
322 public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID) 680 public void SendMoneyBalance(IClientAPI client, LLUUID agentID, LLUUID SessionID, LLUUID TransactionID)
323 { 681 {
324 if (client.AgentId == agentID && client.SessionId == SessionID) 682 if (client.AgentId == agentID && client.SessionId == SessionID)
@@ -342,6 +700,11 @@ namespace OpenSim.Region.Environment.Modules
342 } 700 }
343 } 701 }
344 702
703 #region local Fund Management
704 /// <summary>
705 /// Ensures that the agent accounting data is set up in this instance.
706 /// </summary>
707 /// <param name="agentID"></param>
345 private void CheckExistAndRefreshFunds(LLUUID agentID) 708 private void CheckExistAndRefreshFunds(LLUUID agentID)
346 { 709 {
347 lock (m_KnownClientFunds) 710 lock (m_KnownClientFunds)
@@ -359,7 +722,11 @@ namespace OpenSim.Region.Environment.Modules
359 } 722 }
360 } 723 }
361 } 724 }
362 725 /// <summary>
726 /// Gets the amount of Funds for an agent
727 /// </summary>
728 /// <param name="AgentID"></param>
729 /// <returns></returns>
363 private int GetFundsForAgentID(LLUUID AgentID) 730 private int GetFundsForAgentID(LLUUID AgentID)
364 { 731 {
365 int returnfunds = 0; 732 int returnfunds = 0;
@@ -376,6 +743,488 @@ namespace OpenSim.Region.Environment.Modules
376 } 743 }
377 return returnfunds; 744 return returnfunds;
378 } 745 }
746 private void SetLocalFundsForAgentID(LLUUID AgentID, int amount)
747 {
748 lock (m_KnownClientFunds)
749 {
750 if (m_KnownClientFunds.ContainsKey(AgentID))
751 {
752 m_KnownClientFunds[AgentID] = amount;
753 }
754 else
755 {
756 m_KnownClientFunds.Add(AgentID, amount);
757 }
758 }
759
760 }
761
762 #endregion
763
764 /// <summary>
765 /// Gets the current balance for the user from the Grid Money Server
766 /// </summary>
767 /// <param name="agentId"></param>
768 /// <param name="secureSessionID"></param>
769 /// <param name="regionId"></param>
770 /// <param name="regionSecret"></param>
771 /// <returns></returns>
772 public Hashtable GetBalanceForUserFromMoneyServer(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
773 {
774
775 Hashtable MoneyBalanceRequestParams = new Hashtable();
776 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
777 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
778 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
779 MoneyBalanceRequestParams["secret"] = regionSecret;
780 MoneyBalanceRequestParams["currencySecret"] = ""; // per - region/user currency secret gotten from the money system
781
782 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulator_user_balance_request");
783
784 return MoneyRespData;
785 }
786
787
788
789 /// <summary>
790 /// Generic XMLRPC client abstraction
791 /// </summary>
792 /// <param name="ReqParams">Hashtable containing parameters to the method</param>
793 /// <param name="method">Method to invoke</param>
794 /// <returns>Hashtable with success=>bool and other values</returns>
795 public Hashtable genericCurrencyXMLRPCRequest(Hashtable ReqParams, string method)
796 {
797 ArrayList SendParams = new ArrayList();
798 SendParams.Add(ReqParams);
799 // Send Request
800 XmlRpcResponse MoneyResp;
801 try
802 {
803 XmlRpcRequest BalanceRequestReq = new XmlRpcRequest(method, SendParams);
804 MoneyResp = BalanceRequestReq.Send(m_MoneyAddress, 30000);
805 }
806 catch (WebException ex)
807 {
808
809 m_log.ErrorFormat(
810 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
811 m_MoneyAddress, ex);
812
813 Hashtable ErrorHash = new Hashtable();
814 ErrorHash["success"] = false;
815 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
816 ErrorHash["errorURI"] = "";
817
818 return ErrorHash;
819 //throw (ex);
820 }
821 catch (SocketException ex)
822 {
823
824 m_log.ErrorFormat(
825 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
826 m_MoneyAddress, ex);
827
828 Hashtable ErrorHash = new Hashtable();
829 ErrorHash["success"] = false;
830 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
831 ErrorHash["errorURI"] = "";
832
833 return ErrorHash;
834 //throw (ex);
835 }
836 catch (XmlException ex)
837 {
838 m_log.ErrorFormat(
839 "[MONEY]: Unable to connect to Money Server {0}. Exception {1}",
840 m_MoneyAddress, ex);
841
842 Hashtable ErrorHash = new Hashtable();
843 ErrorHash["success"] = false;
844 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
845 ErrorHash["errorURI"] = "";
846
847 return ErrorHash;
848
849 }
850 if (MoneyResp.IsFault)
851 {
852 Hashtable ErrorHash = new Hashtable();
853 ErrorHash["success"] = false;
854 ErrorHash["errorMessage"] = "Unable to manage your money at this time. Purchases may be unavailable";
855 ErrorHash["errorURI"] = "";
856
857 return ErrorHash;
858
859 }
860 Hashtable MoneyRespData = (Hashtable)MoneyResp.Value;
861
862 return MoneyRespData;
863 }
864 /// <summary>
865 /// This informs the Money Grid Server that the avatar is in this simulator
866 /// </summary>
867 /// <param name="agentId"></param>
868 /// <param name="secureSessionID"></param>
869 /// <param name="regionId"></param>
870 /// <param name="regionSecret"></param>
871 /// <returns></returns>
872 public Hashtable claim_user(LLUUID agentId, LLUUID secureSessionID, LLUUID regionId, string regionSecret)
873 {
874
875 Hashtable MoneyBalanceRequestParams = new Hashtable();
876 MoneyBalanceRequestParams["agentId"] = agentId.ToString();
877 MoneyBalanceRequestParams["secureSessionId"] = secureSessionID.ToString();
878 MoneyBalanceRequestParams["regionId"] = regionId.ToString();
879 MoneyBalanceRequestParams["secret"] = regionSecret;
880
881 Hashtable MoneyRespData = genericCurrencyXMLRPCRequest(MoneyBalanceRequestParams, "simulator_claim_user_request");
882 IClientAPI sendMoneyBal = LocateClientObject(agentId);
883 if (sendMoneyBal != null)
884 {
885 SendMoneyBalance(sendMoneyBal, agentId, sendMoneyBal.SessionId, LLUUID.Zero);
886 }
887 return MoneyRespData;
888 }
889
890 /// <summary>
891 /// Informs the Money Grid Server of a transfer.
892 /// </summary>
893 /// <param name="sourceId"></param>
894 /// <param name="destId"></param>
895 /// <param name="amount"></param>
896 /// <returns></returns>
897 public bool TransferMoneyonMoneyServer(LLUUID sourceId, LLUUID destId, int amount)
898 {
899 string description = "Gift";
900 int aggregatePermInventory = 0;
901 int aggregatePermNextOwner = 0;
902 int flags = 0;
903 int transactiontype = 0;
904 bool rvalue = false;
905
906 IClientAPI cli = LocateClientObject(sourceId);
907 if (cli != null)
908 {
909
910 Scene userScene = null;
911 lock (m_rootAgents)
912 {
913 userScene = GetSceneByUUID(m_rootAgents[sourceId]);
914 }
915 if (userScene != null)
916 {
917 Hashtable ht = new Hashtable();
918 ht["agentId"] = sourceId.ToString();
919 ht["secureSessionId"] = cli.SecureSessionId.ToString();
920 ht["regionId"] = userScene.RegionInfo.originRegionID.ToString();
921 ht["secret"] = userScene.RegionInfo.regionSecret;
922 ht["currencySecret"] = " ";
923 ht["destId"] = destId.ToString();
924 ht["cash"] = amount;
925 ht["aggregatePermInventory"] = aggregatePermInventory;
926 ht["aggregatePermNextOwner"] = aggregatePermNextOwner;
927 ht["flags"] = flags;
928 ht["transactionType"] = transactiontype;
929 ht["description"] = description;
930
931 Hashtable hresult = genericCurrencyXMLRPCRequest(ht, "region_move_money");
932
933 if ((bool)hresult["success"] == true)
934 {
935 int funds1 = 0;
936 int funds2 = 0;
937 try
938 {
939 funds1 = (Int32)hresult["funds"];
940 }
941 catch(InvalidCastException)
942 {
943 funds1 = 0;
944 }
945 SetLocalFundsForAgentID(sourceId, funds1);
946 if (m_KnownClientFunds.ContainsKey(destId))
947 {
948 try
949 {
950 funds2 = (Int32)hresult["funds2"];
951 }
952 catch (InvalidCastException)
953 {
954 funds2 = 0;
955 }
956 SetLocalFundsForAgentID(destId, funds2);
957 }
958
959
960 rvalue = true;
961 }
962 else
963 {
964 cli.SendAgentAlertMessage((string)hresult["errorMessage"], true);
965 }
966
967 }
968 }
969 else
970 {
971 m_log.ErrorFormat("[MONEY]: Client {0} not found", sourceId.ToString());
972 }
973
974 return rvalue;
975
976 }
977
978
979 public XmlRpcResponse GridMoneyUpdate(XmlRpcRequest request)
980 {
981 m_log.Debug("[MONEY]: Dynamic balance update called.");
982 Hashtable requestData = (Hashtable)request.Params[0];
983
984 if (requestData.ContainsKey("agentId"))
985 {
986 LLUUID agentId = LLUUID.Zero;
987
988 Helpers.TryParse((string)requestData["agentId"], out agentId);
989 if (agentId != LLUUID.Zero)
990 {
991 IClientAPI aClient = LocateClientObject(agentId);
992 if (aClient != null)
993 {
994 Scene s = LocateSceneClientIn(agentId);
995 if (s != null)
996 {
997 if (m_MoneyAddress.Length > 0)
998 {
999 Hashtable hbinfo = GetBalanceForUserFromMoneyServer(aClient.AgentId, aClient.SecureSessionId, s.RegionInfo.originRegionID.ToString(), s.RegionInfo.regionSecret);
1000 if ((bool)hbinfo["success"] == true)
1001 {
1002 int funds = 0;
1003 Helpers.TryParse((string)hbinfo["agentId"], out agentId);
1004 try
1005 {
1006 funds = (Int32)hbinfo["funds"];
1007 }
1008 catch (ArgumentException)
1009 {
1010 }
1011 catch (FormatException)
1012 {
1013 }
1014 catch (OverflowException)
1015 {
1016 m_log.ErrorFormat("[MONEY]: While getting the Currency for user {0}, the return funds overflowed.", agentId);
1017 aClient.SendAlertMessage("Unable to get your money balance, money operations will be unavailable");
1018 }
1019 catch (InvalidCastException)
1020 {
1021 funds = 0;
1022 }
1023
1024 SetLocalFundsForAgentID(agentId, funds);
1025 }
1026 else
1027 {
1028 m_log.WarnFormat("[MONEY]: Getting Money for user {0} failed with the following message:{1}", agentId, (string)hbinfo["errorMessage"]);
1029 aClient.SendAlertMessage((string)hbinfo["errorMessage"]);
1030 }
1031 }
1032 SendMoneyBalance(aClient, agentId, aClient.SessionId, LLUUID.Zero);
1033 }
1034 else
1035 {
1036 m_log.Debug("[MONEY]: Got balance request update for agent that is here, but couldn't find which scene.");
1037 }
1038 }
1039 else
1040 {
1041 m_log.Debug("[MONEY]: Got balance request update for agent that isn't here.");
1042 }
1043
1044 }
1045 else
1046 {
1047 m_log.Debug("[MONEY]: invalid agentId specified, dropping.");
1048 }
1049 }
1050 else
1051 {
1052 m_log.Debug("[MONEY]: no agentId specified, dropping.");
1053 }
1054 XmlRpcResponse r = new XmlRpcResponse();
1055 Hashtable rparms = new Hashtable();
1056 rparms["success"] = true;
1057
1058 r.Value = rparms;
1059 return r;
1060 }
1061
1062# region Standalone box enablers only
1063
1064 public XmlRpcResponse quote_func(XmlRpcRequest request)
1065 {
1066 Hashtable requestData = (Hashtable)request.Params[0];
1067 LLUUID agentId = LLUUID.Zero;
1068 int amount = 0;
1069 Hashtable quoteResponse = new Hashtable();
1070 XmlRpcResponse returnval = new XmlRpcResponse();
1071
1072 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1073 {
1074 Helpers.TryParse((string)requestData["agentId"], out agentId);
1075 try
1076 {
1077 amount = (Int32)requestData["currencyBuy"];
1078 }
1079 catch (InvalidCastException)
1080 {
1081
1082 }
1083 Hashtable currencyResponse = new Hashtable();
1084 currencyResponse.Add("estimatedCost", 0);
1085 currencyResponse.Add("currencyBuy", amount);
1086
1087 quoteResponse.Add("success", true);
1088 quoteResponse.Add("currency", currencyResponse);
1089 quoteResponse.Add("confirm", "asdfad9fj39ma9fj");
1090
1091 returnval.Value = quoteResponse;
1092 return returnval;
1093 }
1094
1095
1096
1097 quoteResponse.Add("success", false);
1098 quoteResponse.Add("errorMessage", "Invalid parameters passed to the quote box");
1099 quoteResponse.Add("errorURI", "http://www.opensimulator.org/wiki");
1100 returnval.Value = quoteResponse;
1101 return returnval;
1102 }
1103 public XmlRpcResponse buy_func(XmlRpcRequest request)
1104 {
1105
1106 Hashtable requestData = (Hashtable)request.Params[0];
1107 LLUUID agentId = LLUUID.Zero;
1108 int amount = 0;
1109 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1110 {
1111 Helpers.TryParse((string)requestData["agentId"], out agentId);
1112 try
1113 {
1114 amount = (Int32)requestData["currencyBuy"];
1115 }
1116 catch (InvalidCastException)
1117 {
1118
1119 }
1120 if (agentId != LLUUID.Zero)
1121 {
1122 lock (m_KnownClientFunds)
1123 {
1124 if (m_KnownClientFunds.ContainsKey(agentId))
1125 {
1126 m_KnownClientFunds[agentId] += amount;
1127 }
1128 else
1129 {
1130 m_KnownClientFunds.Add(agentId, amount);
1131 }
1132 }
1133 IClientAPI client = LocateClientObject(agentId);
1134 if (client != null)
1135 {
1136 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero);
1137 }
1138 }
1139 }
1140 XmlRpcResponse returnval = new XmlRpcResponse();
1141 Hashtable returnresp = new Hashtable();
1142 returnresp.Add("success", true);
1143 returnval.Value = returnresp;
1144 return returnval;
1145 }
1146
1147 public XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request)
1148 {
1149 XmlRpcResponse ret = new XmlRpcResponse();
1150 Hashtable retparam = new Hashtable();
1151 Hashtable membershiplevels = new Hashtable();
1152 ArrayList levels = new ArrayList();
1153 Hashtable level = new Hashtable();
1154 level.Add("id", "00000000-0000-0000-0000-000000000000");
1155 level.Add("description", "some level");
1156 levels.Add(level);
1157 //membershiplevels.Add("levels",levels);
1158
1159 Hashtable landuse = new Hashtable();
1160 landuse.Add("upgrade", false);
1161 landuse.Add("action", "http://invaliddomaininvalid.com/");
1162
1163 Hashtable currency = new Hashtable();
1164 currency.Add("estimatedCost", 0);
1165
1166 Hashtable membership = new Hashtable();
1167 membershiplevels.Add("upgrade", false);
1168 membershiplevels.Add("action", "http://invaliddomaininvalid.com/");
1169 membershiplevels.Add("levels", membershiplevels);
1170
1171 retparam.Add("success", true);
1172 retparam.Add("currency", currency);
1173 retparam.Add("membership", membership);
1174 retparam.Add("landuse", landuse);
1175 retparam.Add("confirm", "asdfajsdkfjasdkfjalsdfjasdf");
1176
1177 ret.Value = retparam;
1178
1179 return ret;
1180
1181 }
1182 public XmlRpcResponse landBuy_func(XmlRpcRequest request)
1183 {
1184 XmlRpcResponse ret = new XmlRpcResponse();
1185 Hashtable retparam = new Hashtable();
1186 Hashtable requestData = (Hashtable)request.Params[0];
1187
1188 LLUUID agentId = LLUUID.Zero;
1189 int amount = 0;
1190 if (requestData.ContainsKey("agentId") && requestData.ContainsKey("currencyBuy"))
1191 {
1192 Helpers.TryParse((string)requestData["agentId"], out agentId);
1193 try
1194 {
1195 amount = (Int32)requestData["currencyBuy"];
1196 }
1197 catch (InvalidCastException)
1198 {
1199
1200 }
1201 if (agentId != LLUUID.Zero)
1202 {
1203 lock (m_KnownClientFunds)
1204 {
1205 if (m_KnownClientFunds.ContainsKey(agentId))
1206 {
1207 m_KnownClientFunds[agentId] += amount;
1208 }
1209 else
1210 {
1211 m_KnownClientFunds.Add(agentId, amount);
1212 }
1213 }
1214 IClientAPI client = LocateClientObject(agentId);
1215 if (client != null)
1216 {
1217 SendMoneyBalance(client, agentId, client.SessionId, LLUUID.Zero);
1218 }
1219 }
1220 }
1221 retparam.Add("success", true);
1222 ret.Value = retparam;
1223
1224 return ret;
1225
1226 }
1227#endregion
379 1228
380 public void PostInitialise() 1229 public void PostInitialise()
381 { 1230 {
@@ -395,4 +1244,12 @@ namespace OpenSim.Region.Environment.Modules
395 get { return true; } 1244 get { return true; }
396 } 1245 }
397 } 1246 }
1247 public enum TransactionType : int
1248 {
1249 SystemGenerated=0,
1250 RegionMoneyRequest=1,
1251 Gift=2,
1252 Purchase=3
1253
1254 }
398} 1255}
diff --git a/OpenSim/Region/Environment/Modules/FriendsModule.cs b/OpenSim/Region/Environment/Modules/FriendsModule.cs
index fc14df7..fad297e 100644
--- a/OpenSim/Region/Environment/Modules/FriendsModule.cs
+++ b/OpenSim/Region/Environment/Modules/FriendsModule.cs
@@ -190,7 +190,7 @@ namespace OpenSim.Region.Environment.Modules
190 List<LLUUID> updateUsers = new List<LLUUID>(); 190 List<LLUUID> updateUsers = new List<LLUUID>();
191 foreach (FriendListItem fli in lfli) 191 foreach (FriendListItem fli in lfli)
192 { 192 {
193 if (fli.onlinestatus = true) 193 if (fli.onlinestatus == true)
194 { 194 {
195 updateUsers.Add(fli.Friend); 195 updateUsers.Add(fli.Friend);
196 } 196 }
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example
index 85a24e6..1cca2b5 100644
--- a/bin/OpenSim.ini.example
+++ b/bin/OpenSim.ini.example
@@ -306,7 +306,14 @@ snapshot_cache_directory = "DataSnapshot"
306data_services="http://metaverseink.com/cgi-bin/register.py" 306data_services="http://metaverseink.com/cgi-bin/register.py"
307 307
308[Economy] 308[Economy]
309; These economy values get used in the BetaGridLikeMoneyModule 309; These economy values get used in the BetaGridLikeMoneyModule. - This module is for demonstration only -
310; In grid mode, use this currency XMLRPC server. Leave blank for normal functionality
311CurrencyServer = ""
312; "http://192.168.1.127/currency.php"
313
314; In grid mode, this is the land XMLRPC server. Leave blank for normal functionality
315LandServer = ""
316;"http://192.168.1.127/landtool.php"
310 317
311; 45000 is the highest value that the sim could possibly report because of protocol constraints 318; 45000 is the highest value that the sim could possibly report because of protocol constraints
312ObjectCapacity = 45000 319ObjectCapacity = 45000