diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index df02c2f3f5..eb521a9dd2 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -2232,9 +2232,9 @@ namespace OpenSim.Framework
///
public static T GetConfigVarFromSections(IConfigSource config, string varname, string[] sections, object val)
{
- foreach (string section in sections.AsSpan())
+ for (int i = 0 ; i < sections.Length; i++)
{
- IConfig cnf = config.Configs[section];
+ IConfig cnf = config.Configs[sections[i]];
if (cnf == null)
continue;
@@ -2252,6 +2252,119 @@ namespace OpenSim.Framework
return (T)val;
}
+ ///
+ /// Gets the value of a configuration variable by looking into
+ /// multiple sections in order. Returns as soon one is found, ignoring other sections
+ ///
+ ///
+ /// If no value is found then the given default value is returned
+ ///
+ /// Type of the variable
+ /// The configuration object
+ /// The configuration variable
+ /// Ordered sequence of sections to look at
+ /// Default value
+ ///
+ public static T GetFirstConfigVarFromSections(IConfigSource config, string varname, string[] sections, object val)
+ {
+ for (int i = 0 ; i < sections.Length; i++)
+ {
+ IConfig cnf = config.Configs[sections[i]];
+ if (cnf == null)
+ continue;
+
+ string text = cnf.Get(varname);
+ if (!string.IsNullOrEmpty(text))
+ {
+ if (typeof(T) == typeof(string))
+ return Unsafe.As(ref text);
+
+ if (typeof(T) == typeof(bool))
+ {
+ bool b = bool.Parse(text);
+ return Unsafe.As(ref b);
+ }
+
+ if (typeof(T) == typeof(int))
+ {
+ int ti = int.Parse(text);
+ return Unsafe.As(ref ti);
+ }
+
+ if (typeof(T) == typeof(float))
+ {
+ float f = float.Parse(text);
+ return Unsafe.As(ref f);
+ }
+
+ if (typeof(T) == typeof(double))
+ {
+ double d = double.Parse(text);
+ return Unsafe.As(ref d);
+ }
+ }
+ }
+
+ return val == null ? default : (T) val;
+ }
+
+ ///
+ /// Gets the value of a configuration variable by looking into
+ /// multiple sections in order. Returns as soon one is found, ignoring other sections
+ ///
+ ///
+ /// If no value is found then the default value of T is returned
+ ///
+ /// Type of the variable
+ /// The configuration object
+ /// The configuration variable
+ /// Ordered sequence of sections to look at
+ ///
+
+ public static T GetFirstConfigVarFromSections(IConfigSource config, string varname, string[] sections)
+ {
+ for (int i = 0 ; i < sections.Length; i++)
+ {
+ IConfig cnf = config.Configs[sections[i]];
+ if (cnf == null)
+ continue;
+
+ string text = cnf.Get(varname);
+ if (!string.IsNullOrEmpty(text))
+ {
+ if (typeof(T) == typeof(string))
+ return Unsafe.As(ref text);
+
+ if (typeof(T) == typeof(bool))
+ {
+ bool b = bool.Parse(text);
+ return Unsafe.As(ref b);
+ }
+
+ if (typeof(T) == typeof(int))
+ {
+ int ti = int.Parse(text);
+ return Unsafe.As(ref ti);
+ }
+
+ if (typeof(T) == typeof(float))
+ {
+ float f = float.Parse(text);
+ return Unsafe.As(ref f);
+ }
+
+ if (typeof(T) == typeof(double))
+ {
+ double d = double.Parse(text);
+ return Unsafe.As(ref d);
+ }
+ }
+ }
+
+ return default;
+ }
+
+
public static void MergeEnvironmentToConfig(IConfigSource ConfigSource)
{
IConfig enVars = ConfigSource.Configs["Environment"];
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCapsModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCapsModule.cs
index e56be4808c..10cd07c928 100644
--- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCapsModule.cs
+++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCapsModule.cs
@@ -100,18 +100,7 @@ namespace OpenSim.Region.ClientStack.Linden
IConfigSource config = m_Scene.Config;
if (config is not null)
{
- IConfig sconfig = config.Configs["Startup"];
- if (sconfig is not null)
- ConfigOptions.levelUpload = sconfig.GetInt("LevelUpload", -9798);
-
- if (ConfigOptions.levelUpload == -9798)
- {
- IConfig pconfig = config.Configs["Permissions"];
- if (pconfig is not null)
- ConfigOptions.levelUpload = pconfig.GetInt("LevelUpload", 0);
- }
- if (ConfigOptions.levelUpload == -9798)
- ConfigOptions.levelUpload = 0;
+ ConfigOptions.levelUpload = Util.GetFirstConfigVarFromSections(config,"LevelUpload",["Permissions", "Startup"], 0);
IConfig appearanceConfig = config.Configs["Appearance"];
if (appearanceConfig is not null)
diff --git a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
index 10f5ca2076..f294372e72 100644
--- a/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
+++ b/OpenSim/Region/CoreModules/Agent/AssetTransaction/AssetTransactionModule.cs
@@ -58,21 +58,7 @@ namespace OpenSim.Region.CoreModules.Agent.AssetTransaction
public void Initialise(IConfigSource source)
{
if(source != null)
- {
- IConfig sconfig = source.Configs["Permissions"];
- if (sconfig != null)
- {
- m_levelUpload = sconfig.GetInt("LevelUpload", -9798);
- }
- if(m_levelUpload == -9798)
- {
- sconfig = source.Configs["Startup"];
- if (sconfig is not null)
- m_levelUpload = sconfig.GetInt("LevelUpload", 0);
- }
- if(m_levelUpload == -9798)
- m_levelUpload = 0;
- }
+ m_levelUpload = Util.GetFirstConfigVarFromSections(source,"LevelUpload",["Permissions", "Startup"], 0);
}
public void AddRegion(Scene scene)