From 435636acdc50fed5d39ca851e7aafd0e7c6e6695 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 9 Apr 2026 20:02:41 +0100 Subject: [PATCH] cosmetics --- .../os-webrtc-janus/Janus/JanusMessages.cs | 4 - .../os-webrtc-janus/Janus/JanusPlugin.cs | 2 +- .../Janus/WebRtcJanusService.cs | 2 + OpenSim/Framework/Util.cs | 26 ++--- .../Region/Framework/Scenes/KeyframeMotion.cs | 4 +- OpenSim/Region/Framework/Scenes/Scene.cs | 4 +- .../Interfaces/IUserAccountService.cs | 102 ++++++++++-------- .../LLLoginService/LLLoginResponse.cs | 2 +- .../Services/LLLoginService/LLLoginService.cs | 30 +++--- 9 files changed, 86 insertions(+), 90 deletions(-) diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs index 195f4d6080..f829c87349 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusMessages.cs @@ -290,10 +290,6 @@ namespace osWebRtcVoice { get { - // The JSON response gives a long number (not a string) - // and the ODMap conversion interprets it as a long (OSDLong). - // If one just does a "ToString()" on the OSD object, you - // get an interpretation of the binary value. return dataSection.TryGetValue("id", out OSD oid) ? oid.AsLong().ToString() : string.Empty; } } diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/JanusPlugin.cs b/OpenSim/Addons/os-webrtc-janus/Janus/JanusPlugin.cs index e8986983b7..46bb25bae0 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/JanusPlugin.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/JanusPlugin.cs @@ -50,7 +50,7 @@ namespace osWebRtcVoice public string PluginId { get; private set; } public string PluginUri { get ; private set ; } - public bool IsConnected => !String.IsNullOrEmpty(PluginId); + public bool IsConnected => !string.IsNullOrEmpty(PluginId); // Wrapper around the session connection to Janus-gateway public JanusPlugin(JanusSession pSession, string pPluginName) diff --git a/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs b/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs index 96b6eeedeb..3e2f3b52ad 100644 --- a/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs +++ b/OpenSim/Addons/os-webrtc-janus/Janus/WebRtcJanusService.cs @@ -260,6 +260,8 @@ namespace osWebRtcVoice // IWebRtcVoiceService.ProvisionVoiceAccountRequest public OSDMap ProvisionVoiceAccountRequest(IVoiceViewerSession pSession, OSDMap pRequest, UUID pUserID, UUID pSceneID) { + // the bad refers to use of .Result + // that should not be used and may deadlock, due to poor ms design of all this specially async/await crap return ProvisionVoiceAccountRequestBAD(pSession, pRequest, pUserID, pSceneID).Result; } diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index d909aff8ad..11ff3e5ec3 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -2761,32 +2761,22 @@ namespace OpenSim.Framework public static byte ConvertMaturityToAccessLevel(uint maturity) { - byte retVal = 0; - switch (maturity) + return maturity switch { - case 0: //PG - retVal = 13; - break; - case 1: //Mature - retVal = 21; - break; - case 2: // Adult - retVal = 42; - break; - } - - return retVal; - + //0 => 13, //PG + 1 => 21, //Mature + 2 => 42, // Adult + _ => 13 // PG + }; } public static uint ConvertAccessLevelToMaturity(byte maturity) { if (maturity <= 13) return 0; - else if (maturity <= 21) + if (maturity <= 21) return 1; - else - return 2; + return 2; } /// diff --git a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs index dc02db1597..5268e5323b 100644 --- a/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs +++ b/OpenSim/Region/Framework/Scenes/KeyframeMotion.cs @@ -571,8 +571,8 @@ namespace OpenSim.Region.Framework.Scenes if (k.Rotation.HasValue) { if (direction == -1) - k.Rotation = Quaternion.Conjugate((Quaternion)k.Rotation); - k.Rotation = rot * k.Rotation; + k.Rotation = Quaternion.Conjugate(k.Rotation.Value); + k.Rotation = rot * k.Rotation.Value; } else { diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7d18fa4922..acbb63721c 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -3105,9 +3105,7 @@ namespace OpenSim.Region.Framework.Scenes { */ UserAccount uac = UserAccountService.GetUserAccount(RegionInfo.ScopeID, user); - if (uac is null) - return 0; - return uac.UserFlags; + return uac is null ? 0 : uac.UserFlags; //} } diff --git a/OpenSim/Services/Interfaces/IUserAccountService.cs b/OpenSim/Services/Interfaces/IUserAccountService.cs index c6f3ef35b0..1063669113 100644 --- a/OpenSim/Services/Interfaces/IUserAccountService.cs +++ b/OpenSim/Services/Interfaces/IUserAccountService.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Text; using OpenMetaverse; using OpenSim.Framework; @@ -92,7 +93,7 @@ namespace OpenSim.Services.Interfaces public int UserFlags; public string UserTitle; public string UserCountry; - public Boolean LocalToGrid = true; + public bool LocalToGrid = true; public Dictionary ServiceURLs; @@ -105,40 +106,39 @@ namespace OpenSim.Services.Interfaces public UserAccount(Dictionary kvp) { - if (kvp.ContainsKey("FirstName")) - FirstName = kvp["FirstName"].ToString(); - if (kvp.ContainsKey("LastName")) - LastName = kvp["LastName"].ToString(); - if (kvp.ContainsKey("Email")) - Email = kvp["Email"].ToString(); - if (kvp.ContainsKey("PrincipalID")) - UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID); - if (kvp.ContainsKey("ScopeID")) - UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID); - if (kvp.ContainsKey("UserLevel")) - UserLevel = Convert.ToInt32(kvp["UserLevel"].ToString()); - if (kvp.ContainsKey("UserFlags")) - UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString()); - if (kvp.ContainsKey("UserTitle")) - UserTitle = kvp["UserTitle"].ToString(); - if (kvp.ContainsKey("UserCountry")) - UserCountry = kvp["UserCountry"].ToString(); - if (kvp.ContainsKey("LocalToGrid")) - Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid); + object otmp; + if (kvp.TryGetValue("FirstName", out otmp)) + FirstName = otmp.ToString(); + if (kvp.TryGetValue("LastName", out otmp)) + LastName = otmp.ToString(); + if (kvp.TryGetValue("Email", out otmp)) + Email = otmp.ToString(); + if (kvp.TryGetValue("PrincipalID", out otmp)) + _ = UUID.TryParse(otmp.ToString(), out PrincipalID); + if (kvp.TryGetValue("ScopeID", out otmp)) + UUID.TryParse(otmp.ToString(), out ScopeID); + if (kvp.TryGetValue("UserLevel", out otmp)) + UserLevel = Convert.ToInt32(otmp.ToString()); + if (kvp.TryGetValue("UserFlags", out otmp)) + UserFlags = Convert.ToInt32(otmp.ToString()); + if (kvp.TryGetValue("UserTitle", out otmp)) + UserTitle = otmp.ToString(); + if (kvp.TryGetValue("UserCountry", out otmp)) + UserCountry = otmp.ToString(); + if (kvp.TryGetValue("LocalToGrid", out otmp)) + _ = bool.TryParse(otmp.ToString(), out LocalToGrid); - if (kvp.ContainsKey("Created")) - Created = Convert.ToInt32(kvp["Created"].ToString()); - if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null) + if (kvp.TryGetValue("Created", out otmp)) + Created = Convert.ToInt32(otmp.ToString()); + if (kvp.TryGetValue("ServiceURLs", out otmp) && otmp is string str) { ServiceURLs = new Dictionary(); - string str = kvp["ServiceURLs"].ToString(); - if (str != string.Empty) + if (str.Length > 0) { - string[] parts = str.Split(new char[] { ';' }); -// Dictionary dic = new Dictionary(); + string[] parts = str.Split(';'); foreach (string s in parts) { - string[] parts2 = s.Split(new char[] { '*' }); + string[] parts2 = s.Split('*'); if (parts2.Length == 2) ServiceURLs[parts2[0]] = parts2[1]; } @@ -148,25 +148,35 @@ namespace OpenSim.Services.Interfaces public Dictionary ToKeyValuePairs() { - Dictionary result = new Dictionary(); - result["FirstName"] = FirstName; - result["LastName"] = LastName; - result["Email"] = Email; - result["PrincipalID"] = PrincipalID.ToString(); - result["ScopeID"] = ScopeID.ToString(); - result["Created"] = Created.ToString(); - result["UserLevel"] = UserLevel.ToString(); - result["UserFlags"] = UserFlags.ToString(); - result["UserTitle"] = UserTitle; - result["UserCountry"] = UserCountry; - result["LocalToGrid"] = LocalToGrid.ToString(); - - string str = string.Empty; - foreach (KeyValuePair kvp in ServiceURLs) + Dictionary result = new() { - str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";"; + ["FirstName"] = FirstName, + ["LastName"] = LastName, + ["Email"] = Email, + ["PrincipalID"] = PrincipalID.ToString(), + ["ScopeID"] = ScopeID.ToString(), + ["Created"] = Created.ToString(), + ["UserLevel"] = UserLevel.ToString(), + ["UserFlags"] = UserFlags.ToString(), + ["UserTitle"] = UserTitle, + ["UserCountry"] = UserCountry, + ["LocalToGrid"] = LocalToGrid.ToString() + }; + + if(ServiceURLs.Count == 0) + result["ServiceURLs"] = string.Empty; + else + { + StringBuilder sb = osStringBuilderCache.Acquire(); + foreach (KeyValuePair kvp in ServiceURLs) + { + sb.Append(kvp.Key); + sb.Append('*'); + sb.Append(kvp.Value ?? ""); + sb.Append(';'); + } + result["ServiceURLs"] = osStringBuilderCache.GetStringAndRelease(sb); } - result["ServiceURLs"] = str; return result; } diff --git a/OpenSim/Services/LLLoginService/LLLoginResponse.cs b/OpenSim/Services/LLLoginService/LLLoginResponse.cs index d21f5ae49d..cacd2cd19d 100644 --- a/OpenSim/Services/LLLoginService/LLLoginResponse.cs +++ b/OpenSim/Services/LLLoginService/LLLoginResponse.cs @@ -437,7 +437,7 @@ namespace OpenSim.Services.LLLoginService + "," + "r" + userProfile.homelookat.Z.ToString() + "]}"; - lookAt = "[r0.99949799999999999756,r0.03166859999999999814,r0]"; + lookAt = "[r1,r0,r0]"; RegionX = (uint) 255232; RegionY = (uint) 254976; diff --git a/OpenSim/Services/LLLoginService/LLLoginService.cs b/OpenSim/Services/LLLoginService/LLLoginService.cs index a8758f478e..3f4fe515b1 100755 --- a/OpenSim/Services/LLLoginService/LLLoginService.cs +++ b/OpenSim/Services/LLLoginService/LLLoginService.cs @@ -1050,30 +1050,31 @@ namespace OpenSim.Services.LLLoginService // Old style: get the service keys from the DB foreach (KeyValuePair kvp in account.ServiceURLs) { - if (kvp.Value is not null) + if (kvp.Value is string svalue) { - aCircuit.ServiceURLs[kvp.Key] = kvp.Value; - - if (!aCircuit.ServiceURLs[kvp.Key].ToString().EndsWith("/")) - aCircuit.ServiceURLs[kvp.Key] = aCircuit.ServiceURLs[kvp.Key] + "/"; + if (svalue.EndsWith('/')) + aCircuit.ServiceURLs[kvp.Key] = kvp.Value; + else + aCircuit.ServiceURLs[kvp.Key] = svalue + '/'; } } - // New style: service keys start with SRV_; override the previous + // New style: service keys start with SRV_; override the previous string[] keys = m_LoginServerConfig.GetKeys(); if (keys.Length > 0) { bool newUrls = false; - IEnumerable serviceKeys = keys.Where(value => value.StartsWith("SRV_")); - foreach (string serviceKey in serviceKeys) + foreach (string serviceKey in keys) { - string keyName = serviceKey.Replace("SRV_", ""); + if(!serviceKey.StartsWith("SRV_")) + continue; + string keyName = serviceKey[4..]; string keyValue = m_LoginServerConfig.GetString(serviceKey, string.Empty); - if (!keyValue.EndsWith("/")) - keyValue += "/"; + if (!keyValue.EndsWith('/')) + keyValue += '/'; - if (!account.ServiceURLs.ContainsKey(keyName) || (account.ServiceURLs.ContainsKey(keyName) && (string)account.ServiceURLs[keyName] != keyValue)) + if (!account.ServiceURLs.TryGetValue(keyName, out object oserv) || !keyValue.Equals((string)oserv)) { account.ServiceURLs[keyName] = keyValue; newUrls = true; @@ -1083,9 +1084,9 @@ namespace OpenSim.Services.LLLoginService // m_log.DebugFormat("[LLLOGIN SERVICE]: found new key {0} {1}", keyName, aCircuit.ServiceURLs[keyName]); } - if (!account.ServiceURLs.ContainsKey("GatekeeperURI") && !string.IsNullOrEmpty(m_GatekeeperURL)) + if (!string.IsNullOrEmpty(m_GatekeeperURL) && (!account.ServiceURLs.TryGetValue("GatekeeperURI", out object ogate) || !m_GatekeeperURL.Equals((string)ogate))) { - m_log.DebugFormat("[LLLOGIN SERVICE]: adding gatekeeper uri {0}", m_GatekeeperURL); + m_log.Debug($"[LLLOGIN SERVICE]: adding gatekeeper uri {m_GatekeeperURL}"); account.ServiceURLs["GatekeeperURI"] = m_GatekeeperURL; newUrls = true; } @@ -1095,7 +1096,6 @@ namespace OpenSim.Services.LLLoginService if (newUrls) m_UserAccountService.StoreUserAccount(account); } - } private bool LaunchAgentDirectly(ISimulationService simConnector, GridRegion region, AgentCircuitData aCircuit, TeleportFlags flags, out string reason)