From c15869438c2084e57a42f92ef8d3ef77315d497e Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 10 May 2020 21:27:23 +0100 Subject: [PATCH] move currency-base-uri simulator feature to global settings, based on [Economy] economy setting on opensim.ini. make sampleMoney honour it --- .../Linden/Caps/SimulatorFeaturesModule.cs | 26 ++++++++++++++++--- .../Interfaces/ISimulatorFeaturesModule.cs | 1 + .../World/MoneyModule/SampleMoneyModule.cs | 22 +++++++++------- bin/OpenSim.ini.example | 4 +++ 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs index 3459c268b2..cb60850d4f 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/SimulatorFeaturesModule.cs @@ -84,6 +84,8 @@ namespace OpenSim.Region.ClientStack.Linden static private UUID m_scriptSyntaxID = UUID.Zero; static private byte[] m_scriptSyntaxXML = null; + static private string m_economyURL = null; + #region ISharedRegionModule Members public void Initialise(IConfigSource source) @@ -115,6 +117,8 @@ namespace OpenSim.Region.ClientStack.Linden m_doScriptSyntax = config.GetBoolean("ScriptSyntax", m_doScriptSyntax); } + m_economyURL = Util.GetConfigVarFromSections(source, "economy", new string[] { "Economy", "GridInfo" }); + ReadScriptSyntax(); AddDefaultFeatures(); } @@ -197,17 +201,18 @@ namespace OpenSim.Region.ClientStack.Linden extrasMap["AnimationSet"] = true; // TODO: Take these out of here into their respective modules, like map-server-url - if (m_SearchURL != string.Empty) + if (!string.IsNullOrWhiteSpace(m_SearchURL)) extrasMap["search-server-url"] = m_SearchURL; if (!string.IsNullOrEmpty(m_DestinationGuideURL)) extrasMap["destination-guide-url"] = m_DestinationGuideURL; if (m_ExportSupported) extrasMap["ExportSupported"] = true; - if (m_GridURL != string.Empty) + if (!string.IsNullOrWhiteSpace(m_GridURL)) extrasMap["GridURL"] = m_GridURL; - if (m_GridName != string.Empty) + if (!string.IsNullOrWhiteSpace(m_GridName)) extrasMap["GridName"] = m_GridName; - + if(!string.IsNullOrWhiteSpace(m_economyURL)) + extrasMap["currency-base-uri"] = Util.AppendEndSlash(m_economyURL); if (extrasMap.Count > 0) m_features["OpenSimExtras"] = extrasMap; } @@ -263,6 +268,19 @@ namespace OpenSim.Region.ClientStack.Linden return m_features.TryGetValue(name, out value); } + public bool TryGetOpenSimExtraFeature(string name, out OSD value) + { + value = null; + lock (m_features) + { + if (!m_features.TryGetValue("OpenSimExtras", out OSD extra)) + return false; + if(!(extra is OSDMap)) + return false; + return (extra as OSDMap).TryGetValue(name, out value); + } + } + public OSDMap GetFeatures() { lock (m_features) diff --git a/OpenSim/Region/Framework/Interfaces/ISimulatorFeaturesModule.cs b/OpenSim/Region/Framework/Interfaces/ISimulatorFeaturesModule.cs index 49ef22f876..c80439b70b 100644 --- a/OpenSim/Region/Framework/Interfaces/ISimulatorFeaturesModule.cs +++ b/OpenSim/Region/Framework/Interfaces/ISimulatorFeaturesModule.cs @@ -43,6 +43,7 @@ namespace OpenSim.Region.Framework.Interfaces void AddOpenSimExtraFeature(string name, OSD value); bool RemoveFeature(string name); bool TryGetFeature(string name, out OSD value); + bool TryGetOpenSimExtraFeature(string name, out OSD value); OSDMap GetFeatures(); } } diff --git a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs index 2f136dc998..ad9a473b09 100644 --- a/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs +++ b/OpenSim/Region/OptionalModules/World/MoneyModule/SampleMoneyModule.cs @@ -67,7 +67,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule // private UUID EconomyBaseAccount = UUID.Zero; private Dictionary m_rpcHandlers; - private string m_economyURL; + private string m_localEconomyURL; private float EnergyEfficiency = 1f; // private ObjectPaid handerOnObjectPaid; @@ -142,10 +142,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule { if (m_scenel.Count == 0) { - m_economyURL = scene.RegionInfo.ServerURI; - if(!string.IsNullOrWhiteSpace(m_economyURL) && m_economyURL[m_economyURL.Length - 1] == '/') - m_economyURL = m_economyURL.Substring(0, m_economyURL.Length - 1); - + m_localEconomyURL = scene.RegionInfo.ServerURI; m_rpcHandlers = new Dictionary(); m_rpcHandlers.Add("getCurrencyQuote", quote_func); m_rpcHandlers.Add("buyCurrency", buy_func); @@ -186,10 +183,12 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule if (!m_enabled) return; - if (!string.IsNullOrWhiteSpace(m_economyURL)) + ISimulatorFeaturesModule fm = scene.RequestModuleInterface(); + if (fm != null && !string.IsNullOrWhiteSpace(m_localEconomyURL)) { - ISimulatorFeaturesModule fm = scene.RequestModuleInterface(); - fm?.AddOpenSimExtraFeature("currency-base-uri", m_economyURL); + if(fm.TryGetOpenSimExtraFeature("currency-base-uri", out OSD tmp)) + return; + fm.AddOpenSimExtraFeature("currency-base-uri", Util.AppendEndSlash(m_localEconomyURL)); } } @@ -278,7 +277,7 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule m_enabled = false; return; } - + if(economyConfig == null) return; @@ -495,6 +494,8 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule Hashtable currencyResponse = new Hashtable(); currencyResponse.Add("estimatedCost", 0); + currencyResponse.Add("estimatedLocalCost", " 0 Euros"); + currencyResponse.Add("currencyBuy", amount); Hashtable quoteResponse = new Hashtable(); @@ -502,6 +503,9 @@ namespace OpenSim.Region.OptionalModules.World.MoneyModule quoteResponse.Add("currency", currencyResponse); quoteResponse.Add("confirm", "asdfad9fj39ma9fj"); + //quoteResponse.Add("success", false); + //quoteResponse.Add("errorMessage", "There is currency"); + //quoteResponse.Add("errorURI", "http://opensimulator.org"); XmlRpcResponse returnval = new XmlRpcResponse(); returnval.Value = quoteResponse; return returnval; diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index c60aee7f28..4c156bfc4e 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -916,6 +916,10 @@ ; To use other modules you need to override this setting ; economymodule = BetaGridLikeMoneyModule + ; the url of the economy service. + ; this must match the grid economy setting (also known as helperURI or CurrencyServer, etc) + ; economy = https://the.currency.machine.fdqn:port/folder/folder... + ;# {SellEnabled} {} {Enable selling for 0?} {true false} true ; The default economy module only implements just enough to allow free actions (transfer of objects, etc). ; There is no intention to implement anything further in core OpenSimulator.