add to opensim.ini a list of stun servers and send it to viewers in simulator features cap

This commit is contained in:
UbitUmarov
2026-02-25 19:37:02 +00:00
parent 044b5f69aa
commit fc607035c8
3 changed files with 58 additions and 9 deletions

View File

@@ -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<string>(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<OSHHTPHost>();
m_gateKeeperAlias ??= new HashSet<OSHHTPHost>();
m_gateKeeperAlias.Add(tmp);
}
}
@@ -431,6 +431,7 @@ namespace OpenSim.Framework
m_gridUrlAlias[i++] = a.URI;
}
string home = Util.GetConfigVarFromSections<string>(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<OSHHTPHost>();
m_homeURLAlias ??= new HashSet<OSHHTPHost>();
m_homeURLAlias.Add(tmp);
}
}
}
string[] namessections = new string[] { "Const", "GridInfo", "SimulatorFeatures" };
string[] namessections = ["Const", "GridInfo", "SimulatorFeatures"];
m_GridName = Util.GetConfigVarFromSections<string>(config, "GridName", namessections, string.Empty);
if (string.IsNullOrEmpty(m_GridName))
m_GridName = Util.GetConfigVarFromSections<string>(config, "gridname", namessections, string.Empty);
@@ -504,7 +504,8 @@ namespace OpenSim.Framework
m_DestinationGuideURL = tmpuri.URI;
}
m_economyURL = Util.GetConfigVarFromSections<string>(config, "economy", new string[] { "Economy", "GridInfo" });
m_economyURL = Util.GetConfigVarFromSections<string>(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<string>(config, "StunServers", ["Const", "Startup", "GridInfo", "SimulatorFeatures"], string.Empty);
if (!string.IsNullOrWhiteSpace(stunservers))
{
string[] stuns = stunservers.Split(',');
List<string> stunsarr = new List<string>(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<string> values = new List<string>(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;
}
}
}
}

View File

@@ -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);
}
}
}
}

View File

@@ -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.