From fc607035c8e89495634e56c83e653f895633225b Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 25 Feb 2026 19:37:02 +0000 Subject: [PATCH] add to opensim.ini a list of stun servers and send it to viewers in simulator features cap --- OpenSim/Framework/GridInfo.cs | 54 ++++++++++++++++++++---- OpenSim/Region/Framework/Scenes/Scene.cs | 6 +++ bin/OpenSim.ini.example | 7 ++- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/OpenSim/Framework/GridInfo.cs b/OpenSim/Framework/GridInfo.cs index 730d4fd09a..0ad9494c90 100644 --- a/OpenSim/Framework/GridInfo.cs +++ b/OpenSim/Framework/GridInfo.cs @@ -71,7 +71,7 @@ namespace OpenSim.Framework Flags = OSHTTPURIFlags.None; try { - Uri m_checkuri = new Uri(uri); + Uri m_checkuri = new(uri); if(m_checkuri.Scheme != Uri.UriSchemeHttp && m_checkuri.Scheme != Uri.UriSchemeHttps) return; @@ -368,10 +368,11 @@ namespace OpenSim.Framework private string m_SearchURL = string.Empty; private string m_DestinationGuideURL = string.Empty; private string m_economyURL = string.Empty; + private string[] m_StunServers = null; public GridInfo (IConfigSource config, string defaultURI = "") { - string[] sections = new string[] {"Const", "Startup", "Hypergrid"}; + string[] sections = ["Const", "Startup", "Hypergrid"]; string gatekeeper = Util.GetConfigVarFromSections(config, "GatekeeperURI", sections, string.Empty); if (string.IsNullOrEmpty(gatekeeper)) @@ -416,8 +417,7 @@ namespace OpenSim.Framework OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false); if (tmp.IsValidHost) { - if (m_gateKeeperAlias == null) - m_gateKeeperAlias = new HashSet(); + m_gateKeeperAlias ??= new HashSet(); m_gateKeeperAlias.Add(tmp); } } @@ -431,6 +431,7 @@ namespace OpenSim.Framework m_gridUrlAlias[i++] = a.URI; } + string home = Util.GetConfigVarFromSections(config, "HomeURI", sections, string.Empty); if (string.IsNullOrEmpty(home)) @@ -458,14 +459,13 @@ namespace OpenSim.Framework OSHHTPHost tmp = new OSHHTPHost(alias[i].Trim(), false); if (tmp.IsValidHost) { - if (m_homeURLAlias == null) - m_homeURLAlias = new HashSet(); + m_homeURLAlias ??= new HashSet(); m_homeURLAlias.Add(tmp); } } } - string[] namessections = new string[] { "Const", "GridInfo", "SimulatorFeatures" }; + string[] namessections = ["Const", "GridInfo", "SimulatorFeatures"]; m_GridName = Util.GetConfigVarFromSections(config, "GridName", namessections, string.Empty); if (string.IsNullOrEmpty(m_GridName)) m_GridName = Util.GetConfigVarFromSections(config, "gridname", namessections, string.Empty); @@ -504,7 +504,8 @@ namespace OpenSim.Framework m_DestinationGuideURL = tmpuri.URI; } - m_economyURL = Util.GetConfigVarFromSections(config, "economy", new string[] { "Economy", "GridInfo" }); + + m_economyURL = Util.GetConfigVarFromSections(config, "economy", ["Economy", "GridInfo"]); if (!string.IsNullOrEmpty(m_economyURL)) { tmpuri = new OSHTTPURI(m_economyURL.Trim(), true); @@ -515,6 +516,20 @@ namespace OpenSim.Framework } m_economyURL = tmpuri.URI; } + + string stunservers = Util.GetConfigVarFromSections(config, "StunServers", ["Const", "Startup", "GridInfo", "SimulatorFeatures"], string.Empty); + if (!string.IsNullOrWhiteSpace(stunservers)) + { + string[] stuns = stunservers.Split(','); + List stunsarr = new List(stuns.Length); + for (int i = 0; i < stuns.Length; ++i) + { + OSHHTPHost tmp = new OSHHTPHost(stuns[i].Trim(), false); + if (tmp.IsValidHost) + stunsarr.Add(tmp.URI); + } + m_StunServers = stunsarr.Count > 0 ? stunsarr.ToArray() : null; + } } public bool HasHGConfig @@ -685,6 +700,7 @@ namespace OpenSim.Framework } } + public string GridName { get { return m_GridName; } @@ -756,5 +772,27 @@ namespace OpenSim.Framework m_log.Error((tmp.IsValidHost ? "Could not resolve EconomyURL" : "EconomyURL is a invalid host ") + value ?? ""); } } + + public string[] StunServers + { + get { return m_StunServers; } + set + { + if(value.Length > 0) + { + List values = new List(value.Length); + for (int i = 0; i < value.Length; ++i) + { + OSHHTPHost tmp = new OSHHTPHost(value[i].Trim(), false); + if (tmp.IsValidHost) + values.Add(tmp.URI); + } + m_StunServers = values.Count > 0 ? values.ToArray() : null; + } + else + m_StunServers = null; + } + } + } } diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index d5c7c3cba3..7d18fa4922 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1293,6 +1293,12 @@ namespace OpenSim.Region.Framework.Scenes if (!string.IsNullOrEmpty(SceneGridInfo.EconomyURL)) fm.AddOpenSimExtraFeature("currency-base-uri", SceneGridInfo.EconomyURL); } + + if (SceneGridInfo.StunServers is not null) + { + string stuns = string.Join(',', SceneGridInfo.StunServers); + fm.AddFeature("stun-servers", stuns); + } } } } diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 769c163bf7..60c6ba1112 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -76,6 +76,8 @@ ; from outside their networks, using firewalls PrivatePort = "8003" + + [Startup] ;# {ConsolePrompt} {} {ConsolePrompt} {} "Region (\R) " ;; Console prompt @@ -364,7 +366,10 @@ ; NoVerifyCertHostname = true ;; having both options true does provide encryption but with low security ;; set both true if you don't care to use SSL, they are needed to contact regions or grids that do use it. - + + ;; list of stun servers, for now to tell viewers for webrtc support + StunServers = stun.l.google.com:19302, stun.cloudflare.com:3478 + [AccessControl] ;# {AllowedClients} {} {Bar (|) separated list of allowed clients} {} ;; Bar (|) separated list of viewers which may gain access to the regions.