29 using System.Collections;
30 using System.Collections.Generic;
32 using System.Reflection;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Servers;
40 using OpenSim.Framework.Servers.HttpServer;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 using OpenSim.Services.Interfaces;
58 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"SampleMoneyModule")]
61 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
68 private float EnergyEfficiency = 0f;
70 private bool m_enabled =
true;
71 private bool m_sellEnabled =
false;
73 private IConfigSource m_gConfig;
82 private Dictionary<ulong, Scene> m_scenel =
new Dictionary<ulong, Scene>();
86 private int ObjectCount = 0;
87 private int PriceEnergyUnit = 0;
88 private int PriceGroupCreate = 0;
89 private int PriceObjectClaim = 0;
90 private float PriceObjectRent = 0f;
91 private float PriceObjectScaleFactor = 0f;
92 private int PriceParcelClaim = 0;
93 private float PriceParcelClaimFactor = 0f;
94 private int PriceParcelRent = 0;
95 private int PricePublicObjectDecay = 0;
96 private int PricePublicObjectDelete = 0;
97 private int PriceRentLight = 0;
98 private int PriceUpload = 0;
99 private int TeleportMinPrice = 0;
101 private float TeleportPriceExponent = 0f;
104 #region IMoneyModule Members
106 #pragma warning disable 0067
108 #pragma warning restore 0067
110 public int UploadCharge
115 public int GroupCreationCharge
128 IConfig startupConfig = m_gConfig.Configs[
"Startup"];
129 IConfig economyConfig = m_gConfig.Configs[
"Economy"];
132 ReadConfigAndPopulate(startupConfig,
"Startup");
133 ReadConfigAndPopulate(economyConfig,
"Economy");
145 if (m_scenel.Count == 0)
156 httpServer.AddXmlRPCHandler(
"getCurrencyQuote", quote_func);
157 httpServer.AddXmlRPCHandler(
"buyCurrency", buy_func);
158 httpServer.AddXmlRPCHandler(
"preflightBuyLandPrep", preflightBuyLandPrep_func);
159 httpServer.AddXmlRPCHandler(
"buyLandPrep", landBuy_func);
165 m_scenel[scene.RegionInfo.RegionHandle] = scene;
169 m_scenel.Add(scene.RegionInfo.RegionHandle, scene);
173 scene.EventManager.OnNewClient += OnNewClient;
174 scene.EventManager.OnMoneyTransfer += MoneyTransferAction;
175 scene.EventManager.OnClientClosed += ClientClosed;
176 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
177 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
178 scene.EventManager.OnClientClosed += ClientLoggedOut;
179 scene.EventManager.OnValidateLandBuy += ValidateLandBuy;
180 scene.EventManager.OnLandBuy += processLandBuy;
196 public void ApplyCharge(UUID agentID,
int amount, MoneyTransactionType type,
string extraData)
200 public void ApplyCharge(UUID agentID,
int amount, MoneyTransactionType type)
208 public bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID,
int amount, UUID txn, out
string result)
210 result = String.Empty;
211 string description = String.Format(
"Object {0} pays {1}", resolveObjectName(objectID), resolveAgentName(toID));
213 bool give_result = doMoneyTransfer(fromID, toID, amount, 2, description);
216 BalanceUpdate(fromID, toID, give_result, description);
229 public Type ReplaceableInterface
236 get {
return "BetaGridLikeMoneyModule"; }
247 private void ReadConfigAndPopulate(IConfig startupConfig,
string config)
249 if (config ==
"Startup" && startupConfig != null)
251 m_enabled = (startupConfig.GetString(
"economymodule",
"BetaGridLikeMoneyModule") ==
"BetaGridLikeMoneyModule");
254 if (config ==
"Economy" && startupConfig != null)
256 PriceEnergyUnit = startupConfig.GetInt(
"PriceEnergyUnit", 100);
257 PriceObjectClaim = startupConfig.GetInt(
"PriceObjectClaim", 10);
258 PricePublicObjectDecay = startupConfig.GetInt(
"PricePublicObjectDecay", 4);
259 PricePublicObjectDelete = startupConfig.GetInt(
"PricePublicObjectDelete", 4);
260 PriceParcelClaim = startupConfig.GetInt(
"PriceParcelClaim", 1);
261 PriceParcelClaimFactor = startupConfig.GetFloat(
"PriceParcelClaimFactor", 1f);
262 PriceUpload = startupConfig.GetInt(
"PriceUpload", 0);
263 PriceRentLight = startupConfig.GetInt(
"PriceRentLight", 5);
264 TeleportMinPrice = startupConfig.GetInt(
"TeleportMinPrice", 2);
265 TeleportPriceExponent = startupConfig.GetFloat(
"TeleportPriceExponent", 2f);
266 EnergyEfficiency = startupConfig.GetFloat(
"EnergyEfficiency", 1);
267 PriceObjectRent = startupConfig.GetFloat(
"PriceObjectRent", 1);
268 PriceObjectScaleFactor = startupConfig.GetFloat(
"PriceObjectScaleFactor", 10);
269 PriceParcelRent = startupConfig.GetInt(
"PriceParcelRent", 1);
270 PriceGroupCreate = startupConfig.GetInt(
"PriceGroupCreate", -1);
271 m_sellEnabled = startupConfig.GetBoolean(
"SellEnabled",
false);
275 private void GetClientFunds(
IClientAPI client)
277 CheckExistAndRefreshFunds(client.
AgentId);
286 GetClientFunds(client);
289 client.OnEconomyDataRequest += EconomyDataRequestHandler;
290 client.OnMoneyBalanceRequest += SendMoneyBalance;
291 client.OnRequestPayPrice += requestPayPrice;
293 client.OnLogout += ClientClosed;
303 private bool doMoneyTransfer(UUID Sender, UUID Receiver,
int amount,
int transactiontype,
string description)
326 returnfunds = GetFundsForAgentID(agentID);
330 client.SendAlertMessage(e.Message +
" ");
333 client.SendMoneyBalance(TransactionID,
true,
new byte[0], returnfunds, 0, UUID.Zero,
false, UUID.Zero,
false, 0, String.Empty);
337 client.SendAlertMessage(
"Unable to send your money balance to you!");
345 foreach (
Scene s
in m_scenel.Values)
357 private string resolveObjectName(UUID objectID)
367 private string resolveAgentName(UUID agentID)
370 Scene scene = GetRandomScene();
371 UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, agentID);
374 string avatarname = account.FirstName +
" " + account.LastName;
380 "[MONEY]: Could not resolve user {0}",
387 private void BalanceUpdate(UUID senderID, UUID receiverID,
bool transactionresult,
string description)
389 IClientAPI sender = LocateClientObject(senderID);
390 IClientAPI receiver = LocateClientObject(receiverID);
392 if (senderID != receiverID)
396 sender.SendMoneyBalance(UUID.Random(), transactionresult,
Utils.StringToBytes(description), GetFundsForAgentID(senderID), 0, UUID.Zero,
false, UUID.Zero,
false, 0, String.Empty);
399 if (receiver != null)
401 receiver.SendMoneyBalance(UUID.Random(), transactionresult,
Utils.StringToBytes(description), GetFundsForAgentID(receiverID), 0, UUID.Zero,
false, UUID.Zero,
false, 0, String.Empty);
409 public XmlRpcResponse
UserAlert(XmlRpcRequest request, IPEndPoint remoteClient)
411 XmlRpcResponse ret =
new XmlRpcResponse();
412 Hashtable retparam =
new Hashtable();
413 Hashtable requestData = (Hashtable) request.Params[0];
419 UUID.TryParse((
string) requestData[
"agentId"], out agentId);
420 UUID.TryParse((string) requestData[
"soundId"], out soundId);
421 UUID.TryParse((string) requestData[
"regionId"], out regionId);
422 string text = (string) requestData[
"text"];
423 string secret = (string) requestData[
"secret"];
425 Scene userScene = GetSceneByUUID(regionId);
426 if (userScene != null)
431 IClientAPI client = LocateClientObject(agentId);
435 if (soundId !=
UUID.Zero)
436 client.SendPlayAttachedSound(soundId, UUID.Zero, UUID.Zero, 1.0f, 0);
438 client.SendBlueBoxMessage(UUID.Zero,
"", text);
440 retparam.Add(
"success",
true);
444 retparam.Add(
"success",
false);
449 retparam.Add(
"success",
false);
453 ret.Value = retparam;
457 # region Standalone box enablers only
459 public XmlRpcResponse
quote_func(XmlRpcRequest request, IPEndPoint remoteClient)
464 Hashtable quoteResponse =
new Hashtable();
465 XmlRpcResponse returnval =
new XmlRpcResponse();
468 Hashtable currencyResponse =
new Hashtable();
469 currencyResponse.Add(
"estimatedCost", 0);
470 currencyResponse.Add(
"currencyBuy", amount);
472 quoteResponse.Add(
"success",
true);
473 quoteResponse.Add(
"currency", currencyResponse);
474 quoteResponse.Add(
"confirm",
"asdfad9fj39ma9fj");
476 returnval.Value = quoteResponse;
483 public XmlRpcResponse
buy_func(XmlRpcRequest request, IPEndPoint remoteClient)
489 XmlRpcResponse returnval =
new XmlRpcResponse();
490 Hashtable returnresp =
new Hashtable();
491 returnresp.Add(
"success",
true);
492 returnval.Value = returnresp;
498 XmlRpcResponse ret =
new XmlRpcResponse();
499 Hashtable retparam =
new Hashtable();
500 Hashtable membershiplevels =
new Hashtable();
501 ArrayList levels =
new ArrayList();
502 Hashtable level =
new Hashtable();
503 level.Add(
"id",
"00000000-0000-0000-0000-000000000000");
504 level.Add(
"description",
"some level");
508 Hashtable landuse =
new Hashtable();
509 landuse.Add(
"upgrade",
false);
510 landuse.Add(
"action",
"http://invaliddomaininvalid.com/");
512 Hashtable currency =
new Hashtable();
513 currency.Add(
"estimatedCost", 0);
515 Hashtable membership =
new Hashtable();
516 membershiplevels.Add(
"upgrade",
false);
517 membershiplevels.Add(
"action",
"http://invaliddomaininvalid.com/");
518 membershiplevels.Add(
"levels", membershiplevels);
520 retparam.Add(
"success",
true);
521 retparam.Add(
"currency", currency);
522 retparam.Add(
"membership", membership);
523 retparam.Add(
"landuse", landuse);
524 retparam.Add(
"confirm",
"asdfajsdkfjasdkfjalsdfjasdf");
526 ret.Value = retparam;
531 public XmlRpcResponse
landBuy_func(XmlRpcRequest request, IPEndPoint remoteClient)
533 XmlRpcResponse ret =
new XmlRpcResponse();
534 Hashtable retparam =
new Hashtable();
540 retparam.Add(
"success",
true);
541 ret.Value = retparam;
548 #region local Fund Management
554 private void CheckExistAndRefreshFunds(UUID agentID)
564 private int GetFundsForAgentID(UUID AgentID)
578 #region Utility Helpers
585 private IClientAPI LocateClientObject(UUID AgentID)
592 foreach (
Scene _scene
in m_scenel.Values)
594 tPresence = _scene.GetScenePresence(AgentID);
595 if (tPresence != null)
599 rclient = tPresence.ControllingClient;
611 private Scene LocateSceneClientIn(UUID AgentId)
615 foreach (
Scene _scene
in m_scenel.Values)
618 if (tPresence != null)
638 foreach (
Scene rs
in m_scenel.Values)
653 foreach (
Scene rs
in m_scenel.Values)
666 #region event Handlers
680 client.SendPayPrice(objectID, root.PayPrice);
704 PriceObjectClaim, PriceObjectRent, PriceObjectScaleFactor, PriceParcelClaim, PriceParcelClaimFactor,
705 PriceParcelRent, PricePublicObjectDecay, PricePublicObjectDelete, PriceRentLight, PriceUpload,
706 TeleportMinPrice, TeleportPriceExponent);
709 private void ValidateLandBuy(Object osender,
EventManager.LandBuyArgs e)
715 e.economyValidated =
true;
721 private void processLandBuy(Object osender,
EventManager.LandBuyArgs e)
731 private void MoneyTransferAction(Object osender,
EventManager.MoneyTransferArgs e)
749 private void ClientLoggedOut(UUID AgentId,
Scene scene)
760 ClientClosed(client.
AgentId, null);
769 private void AvatarEnteringParcel(
ScenePresence avatar,
int localLandID, UUID regionID)
795 UUID sessionID, UUID groupID, UUID categoryID,
796 uint localID, byte saleType,
int salePrice)
800 remoteClient.SendBlueBoxMessage(UUID.Zero,
"",
"Buying is not implemented in this version");
806 remoteClient.SendBlueBoxMessage(UUID.Zero,
"",
"Buying anything for a price other than zero is not implemented");
824 remoteClient.SendAgentAlertMessage(
"Unable to buy now. The object was not found.",
false);
831 remoteClient.SendAgentAlertMessage(
"Cannot buy at this price. Buy Failed. If you continue to get this relog.",
false);
838 remoteClient.SendAgentAlertMessage(
"Cannot buy this way. Buy Failed. If you continue to get this relog.",
false);
844 module.BuyObject(remoteClient, categoryID, localID, saleType, salePrice);
847 public void MoveMoney(UUID fromAgentID, UUID toAgentID,
int amount,
string text)
void SendMoneyBalance(IClientAPI client, UUID agentID, UUID SessionID, UUID TransactionID)
Sends the the stored money balance to the client
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
Scene GetSceneByUUID(UUID RegionID)
Utility function to get a Scene by RegionID in a module
void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type)
XmlRpcResponse buy_func(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse landBuy_func(XmlRpcRequest request, IPEndPoint remoteClient)
bool UploadCovered(UUID agentID, int amount)
void ApplyCharge(UUID agentID, int amount, MoneyTransactionType type, string extraData)
OpenSim.Server.Handlers.Simulation.Utils Utils
bool ObjectGiveMoney(UUID objectID, UUID fromID, UUID toID, int amount, UUID txn, out string result)
void PostInitialise()
This is called exactly once after all the shared region-modules have been instanciated and IRegionMod...
void EconomyDataRequestHandler(IClientAPI user)
Event called Economy Data Request handler.
This is only the functionality required to make the functionality associated with money work (such as...
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
void requestPayPrice(IClientAPI client, UUID objectID)
void ClientClosed(IClientAPI client)
Call this when the client disconnects.
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
void Initialise(IConfigSource config)
Called on startup so the module can be configured.
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
void ApplyUploadCharge(UUID agentID, int amount, string text)
delegate void ObjectBuy(IClientAPI remoteClient, UUID agentID, UUID sessionID, UUID groupID, UUID categoryID, uint localID, byte saleType, int salePrice)
int GetBalance(UUID agentID)
void ObjectBuy(IClientAPI remoteClient, UUID agentID, UUID sessionID, UUID groupID, UUID categoryID, uint localID, byte saleType, int salePrice)
bool AmountCovered(UUID agentID, int amount)
void SendEconomyData(float EnergyEfficiency, int ObjectCapacity, int ObjectCount, int PriceEnergyUnit, int PriceGroupCreate, int PriceObjectClaim, float PriceObjectRent, float PriceObjectScaleFactor, int PriceParcelClaim, float PriceParcelClaimFactor, int PriceParcelRent, int PricePublicObjectDecay, int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
void MoveMoney(UUID fromAgentID, UUID toAgentID, int amount, string text)
delegate void ObjectPaid(UUID objectID, UUID agentID, int amount)
Interactive OpenSim region server
A class for triggering remote scene events.
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
XmlRpcResponse preflightBuyLandPrep_func(XmlRpcRequest request, IPEndPoint remoteClient)
XmlRpcResponse quote_func(XmlRpcRequest request, IPEndPoint remoteClient)
void ClientClosed(UUID AgentID, Scene scene)
When the client closes the connection we remove their accounting info from memory to free up resource...
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
virtual RegionInfo RegionInfo
Scene GetRandomScene()
Utility function Gets a Random scene in the instance. For when which scene exactly you're doing somet...
XmlRpcResponse UserAlert(XmlRpcRequest request, IPEndPoint remoteClient)
XMLRPC handler to send alert message and sound to client