From 3e54b7866823da0b9546995f93038460faf4b665 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Wed, 31 Jan 2024 13:06:53 +0000 Subject: [PATCH] avoid sending pbr lludp messages to older viewers --- OpenSim/Capabilities/Caps.cs | 60 ++++++++++++---- OpenSim/Capabilities/CapsHandlers.cs | 47 ++++++++++++- OpenSim/Capabilities/LLSD.cs | 70 +++++++++++-------- .../Linden/Caps/BunchOfCaps/BunchOfCaps.cs | 10 +-- .../Linden/Caps/ObjectCaps/ObjectAdd.cs | 4 +- .../ClientStack/Linden/UDP/LLClientView.cs | 10 +-- .../Framework/Caps/CapabilitiesModule.cs | 3 +- 7 files changed, 142 insertions(+), 62 deletions(-) diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs index 7d5182db79..f91f7d2a9d 100644 --- a/OpenSim/Capabilities/Caps.cs +++ b/OpenSim/Capabilities/Caps.cs @@ -115,14 +115,15 @@ namespace OpenSim.Framework.Capabilities } [Flags] - public enum CapsFlags:uint + public enum CapsFlags: uint { None = 0, SentSeeds = 1, ObjectAnim = 0x100, WLEnv = 0x200, - AdvEnv = 0x400 + AdvEnv = 0x400, + PBR = 0x800 } public CapsFlags Flags { get; set;} @@ -268,22 +269,22 @@ namespace OpenSim.Framework.Capabilities lock (m_pollServiceHandlers) { - foreach (KeyValuePair kvp in m_pollServiceHandlers) + foreach (KeyValuePair kvp in m_pollServiceHandlers) { if (!requestedCaps.Contains(kvp.Key)) continue; - string hostName = m_httpListenerHostName; - uint port = (MainServer.Instance is null) ? 0 : MainServer.Instance.Port; - string protocol = "http"; + string hostName = m_httpListenerHostName; + uint port = (MainServer.Instance is null) ? 0 : MainServer.Instance.Port; + string protocol = "http"; - if (MainServer.Instance.UseSSL) - { - hostName = MainServer.Instance.SSLCommonName; - port = MainServer.Instance.SSLPort; - protocol = "https"; - } - caps[kvp.Key] = string.Format("{0}://{1}:{2}{3}", protocol, hostName, port, kvp.Value.Url); + if (MainServer.Instance.UseSSL) + { + hostName = MainServer.Instance.SSLCommonName; + port = MainServer.Instance.SSLPort; + protocol = "https"; + } + caps[kvp.Key] = string.Format("{0}://{1}:{2}{3}", protocol, hostName, port, kvp.Value.Url); } } @@ -300,6 +301,39 @@ namespace OpenSim.Framework.Capabilities return caps; } + public Hashtable GetCapsDetails2(bool excludeSeed, HashSet requestedCaps) + { + Hashtable caps = CapsHandlers.GetCapsDetails2(excludeSeed, requestedCaps); + + lock (m_pollServiceHandlers) + { + foreach (KeyValuePair kvp in m_pollServiceHandlers) + { + if (!requestedCaps.Contains(kvp.Key)) + continue; + + if (MainServer.Instance.UseSSL) + caps[kvp.Key] = $"https://{MainServer.Instance.SSLCommonName}:{MainServer.Instance.SSLPort}{kvp.Value.Url}"; + else + { + if(MainServer.Instance is null) + caps[kvp.Key] = $"http://{m_httpListenerHostName}:0{kvp.Value.Url}"; + else + caps[kvp.Key] = $"http://{m_httpListenerHostName}:{MainServer.Instance.Port}{kvp.Value.Url}"; + } + } + } + + // Add the external too + foreach (KeyValuePair kvp in ExternalCapsHandlers) + { + if (requestedCaps.Contains(kvp.Key)) + caps[kvp.Key] = kvp.Value; + } + + return caps; + } + public void Activate() { m_capsActive.Set(); diff --git a/OpenSim/Capabilities/CapsHandlers.cs b/OpenSim/Capabilities/CapsHandlers.cs index 9b4c9874af..13ac2b7e43 100644 --- a/OpenSim/Capabilities/CapsHandlers.cs +++ b/OpenSim/Capabilities/CapsHandlers.cs @@ -40,8 +40,8 @@ namespace OpenSim.Framework.Capabilities /// public class CapsHandlers { - private Dictionary m_capsHandlers = new Dictionary(); - private ConcurrentDictionary m_capsSimpleHandlers = new ConcurrentDictionary(); + private readonly Dictionary m_capsHandlers = new Dictionary(); + private readonly ConcurrentDictionary m_capsSimpleHandlers = new ConcurrentDictionary(); private IHttpServer m_httpListener; private string m_httpListenerHostName; private uint m_httpListenerPort; @@ -188,7 +188,7 @@ namespace OpenSim.Framework.Capabilities lock (m_capsHandlers) { - for(int i = 0; i < requestedCaps.Count; ++i) + for (int i = 0; i < requestedCaps.Count; ++i) { string capsName = requestedCaps[i]; if (excludeSeed && "SEED" == capsName) @@ -209,6 +209,47 @@ namespace OpenSim.Framework.Capabilities return caps; } + public Hashtable GetCapsDetails2(bool excludeSeed, HashSet requestedCaps) + { + Hashtable caps = new Hashtable(); + + string protocol = m_useSSL ? "https://" : "http://"; + string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString(); + + if (requestedCaps is null) + { + lock (m_capsHandlers) + { + foreach (KeyValuePair kvp in m_capsSimpleHandlers) + caps[kvp.Key] = baseUrl + kvp.Value.Path; + foreach (KeyValuePair kvp in m_capsHandlers) + caps[kvp.Key] = baseUrl + kvp.Value.Path; + } + return caps; + } + + lock (m_capsHandlers) + { + foreach(string capsName in requestedCaps) + { + if (excludeSeed && "SEED".Equals(capsName)) + continue; + + if (m_capsSimpleHandlers.TryGetValue(capsName, out ISimpleStreamHandler shdr)) + { + caps[capsName] = baseUrl + shdr.Path; + continue; + } + if (m_capsHandlers.TryGetValue(capsName, out IRequestHandler chdr)) + { + caps[capsName] = baseUrl + chdr.Path; + } + } + } + + return caps; + } + /// /// Returns a copy of the dictionary of all the HTTP cap handlers /// diff --git a/OpenSim/Capabilities/LLSD.cs b/OpenSim/Capabilities/LLSD.cs index 840d412324..d4f50b7fca 100644 --- a/OpenSim/Capabilities/LLSD.cs +++ b/OpenSim/Capabilities/LLSD.cs @@ -27,6 +27,7 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Globalization; using System.IO; using System.Security.Cryptography; @@ -136,10 +137,10 @@ namespace OpenSim.Framework.Capabilities return; } - if (obj is string) + if (obj is string s) { writer.WriteStartElement(String.Empty, "string", String.Empty); - writer.WriteString((string) obj); + writer.WriteString(s); writer.WriteEndElement(); } else if (obj is int) @@ -154,9 +155,8 @@ namespace OpenSim.Framework.Capabilities writer.WriteString(obj.ToString()); writer.WriteEndElement(); } - else if (obj is bool) + else if (obj is bool b) { - bool b = (bool) obj; writer.WriteStartElement(String.Empty, "boolean", String.Empty); writer.WriteString(b ? "1" : "0"); writer.WriteEndElement(); @@ -165,29 +165,38 @@ namespace OpenSim.Framework.Capabilities { throw new Exception("ulong in LLSD is currently not implemented, fix me!"); } - else if (obj is UUID) + else if (obj is UUID u) { - UUID u = (UUID) obj; writer.WriteStartElement(String.Empty, "uuid", String.Empty); writer.WriteString(u.ToString()); writer.WriteEndElement(); } - else if (obj is Hashtable) + else if (obj is Hashtable h) { - Hashtable h = obj as Hashtable; - writer.WriteStartElement(String.Empty, "map", String.Empty); - foreach (string key in h.Keys) + writer.WriteStartElement(string.Empty, "map", string.Empty); + foreach (DictionaryEntry de in h) { - writer.WriteStartElement(String.Empty, "key", String.Empty); - writer.WriteString(key); + writer.WriteStartElement(string.Empty, "key", string.Empty); + writer.WriteString((string)de.Key); writer.WriteEndElement(); - LLSDWriteOne(writer, h[key]); + LLSDWriteOne(writer, de.Value); } writer.WriteEndElement(); } - else if (obj is ArrayList) + else if (obj is Dictionary dict) + { + writer.WriteStartElement(String.Empty, "map", String.Empty); + foreach (KeyValuePair kvp in dict) + { + writer.WriteStartElement(String.Empty, "key", String.Empty); + writer.WriteString(kvp.Key); + writer.WriteEndElement(); + LLSDWriteOne(writer, kvp.Value); + } + writer.WriteEndElement(); + } + else if (obj is ArrayList a) { - ArrayList a = obj as ArrayList; writer.WriteStartElement(String.Empty, "array", String.Empty); foreach (object item in a) { @@ -195,26 +204,24 @@ namespace OpenSim.Framework.Capabilities } writer.WriteEndElement(); } - else if (obj is byte[]) + else if (obj is List lsto) { - byte[] b = obj as byte[]; - writer.WriteStartElement(String.Empty, "binary", String.Empty); + writer.WriteStartElement(string.Empty, "array", string.Empty); + foreach (object item in lsto) + { + LLSDWriteOne(writer, item); + } + writer.WriteEndElement(); + } + else if (obj is byte[] bytes) + { + writer.WriteStartElement(string.Empty, "binary", string.Empty); writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); writer.WriteString("base64"); writer.WriteEndAttribute(); - //// Calculate the length of the base64 output - //long length = (long)(4.0d * b.Length / 3.0d); - //if (length % 4 != 0) length += 4 - (length % 4); - - //// Create the char[] for base64 output and fill it - //char[] tmp = new char[length]; - //int i = Convert.ToBase64CharArray(b, 0, b.Length, tmp, 0); - - //writer.WriteString(new String(tmp)); - - writer.WriteString(Convert.ToBase64String(b)); + writer.WriteString(Convert.ToBase64String(bytes)); writer.WriteEndElement(); } else @@ -455,7 +462,7 @@ namespace OpenSim.Framework.Capabilities private static string GetSpaces(int count) { StringBuilder b = new StringBuilder(); - for (int i = 0; i < count; i++) b.Append(" "); + for (int i = 0; i < count; i++) b.Append(' '); return b.ToString(); } @@ -465,6 +472,7 @@ namespace OpenSim.Framework.Capabilities /// /// /// + /* public static String LLSDDump(object obj, int indent) { if (obj == null) @@ -659,7 +667,7 @@ namespace OpenSim.Framework.Capabilities throw new Exception("Unknown value type"); } } - +*/ private static int FindEnd(string llsd, int start) { int end = llsd.IndexOfAny(new char[] {',', ']', '}'}); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs index 81d7c82470..1240f33abb 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs @@ -35,7 +35,6 @@ using System.Net; using System.Threading; using System.Reflection; using System.Text; -using System.Web; using OpenMetaverse; using OpenMetaverse.StructuredData; @@ -82,8 +81,7 @@ namespace OpenSim.Region.ClientStack.Linden public partial class BunchOfCaps { - private static readonly ILog m_log = - LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Scene m_Scene; private UUID m_AgentID; @@ -421,7 +419,7 @@ namespace OpenSim.Region.ClientStack.Linden return; } - List validCaps = new List(); + HashSet validCaps = new(); foreach (OSD c in capsRequested) { @@ -432,10 +430,12 @@ namespace OpenSim.Region.ClientStack.Linden m_HostCapsObj.Flags |= Caps.CapsFlags.WLEnv; else if (cstr.Equals("ExtEnvironment")) m_HostCapsObj.Flags |= Caps.CapsFlags.AdvEnv; + else if(cstr.Equals("ModifyMaterialParams")) + m_HostCapsObj.Flags |= Caps.CapsFlags.PBR; validCaps.Add(cstr); } - string result = LLSDHelpers.SerialiseLLSDReply(m_HostCapsObj.GetCapsDetails(true, validCaps)); + string result = LLSDHelpers.SerialiseLLSDReply(m_HostCapsObj.GetCapsDetails2(true, validCaps)); httpResponse.RawBuffer = Util.UTF8NBGetbytes(result); httpResponse.StatusCode = (int)HttpStatusCode.OK; //m_log.DebugFormat("[CAPS] CapsRequest {0}", result); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs index e10db8d5df..b912879711 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/ObjectCaps/ObjectAdd.cs @@ -334,8 +334,6 @@ namespace OpenSim.Region.ClientStack.Linden obj.InvalidateDeepEffectivePerms(); - m_scene.PhysicsScene.AddPhysicsActorTaint(rootpart.PhysActor); - httpResponse.StatusCode = (int)HttpStatusCode.OK; httpResponse.RawBuffer = Util.UTF8NBGetbytes(String.Format("local_id{0}", ConvertUintToBytes(obj.LocalId))); } @@ -348,7 +346,7 @@ namespace OpenSim.Region.ClientStack.Linden return Utils.BytesToUInt(tmp); } - private string ConvertUintToBytes(uint val) + private static string ConvertUintToBytes(uint val) { byte[] resultbytes = Utils.UIntToBytes(val); if (BitConverter.IsLittleEndian) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index 04f23bf5f5..21b5404886 100755 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs @@ -27,8 +27,6 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Linq; using System.Net; using System.Reflection; using System.Runtime; @@ -348,6 +346,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private const uint MaxTransferBytesPerPacket = 600; private bool m_SupportObjectAnimations; + private bool m_SupportPBR; /// /// Maintain a record of all the objects killed. This allows us to stop an update being sent from the @@ -4969,7 +4968,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP useCompressUpdate = grp.IsViewerCachable; istree = (part.Shape.PCode == (byte)PCode.Grass || part.Shape.PCode == (byte)PCode.NewTree || part.Shape.PCode == (byte)PCode.Tree); - if((updateFlags & PrimUpdateFlags.MaterialOvr) != 0) + if((m_SupportPBR && (updateFlags & PrimUpdateFlags.MaterialOvr) != 0)) hasMaterialOverride = !istree && part.Shape.RenderMaterials is not null; } else if (update.Entity is ScenePresence presence) @@ -5490,8 +5489,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } - IEventQueue eq = Scene.RequestModuleInterface(); - if (needMaterials is not null && eq is not null) + if (needMaterials is not null) { foreach (SceneObjectPart sop in needMaterials) { @@ -13993,6 +13991,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP ret |= 0x4000; if ((cap.Flags & Caps.CapsFlags.AdvEnv) != 0) ret |= 0x8000; + if ((cap.Flags & Caps.CapsFlags.PBR) != 0) + m_SupportPBR = true; } } diff --git a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs index 6ff184c56a..3fd63a0d16 100644 --- a/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Caps/CapabilitiesModule.cs @@ -222,8 +222,7 @@ namespace OpenSim.Region.CoreModules.Framework m_capsPaths[agent.AgentID] = agent.CapsPath; lock (m_childrenSeeds) - m_childrenSeeds[agent.AgentID] - = ((agent.ChildrenCapSeeds == null) ? new Dictionary() : agent.ChildrenCapSeeds); + m_childrenSeeds[agent.AgentID] = (agent.ChildrenCapSeeds ?? new Dictionary()); } public string GetCapsPath(UUID agentId)