Bladeren bron

bunchofcaps config options are the same per region and nini reading is not light

UbitUmarov 7 maanden geleden
bovenliggende
commit
a5d6f2df02

+ 24 - 104
OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCaps.cs

@@ -88,6 +88,7 @@ namespace OpenSim.Region.ClientStack.Linden
         private UUID m_scopeID;
         private Caps m_HostCapsObj;
         private ModelCost m_ModelCost;
+        private BunchOfCapsConfigOptions ConfigOptions;
 
         // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule.
 
@@ -98,30 +99,11 @@ namespace OpenSim.Region.ClientStack.Linden
         public ItemUpdatedCallback ItemUpdatedCall = null;
         public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null;
         public GetClientDelegate GetClient = null;
-
-        private bool m_persistBakedTextures = false;
+        
         private IAssetService m_assetService;
         private bool m_dumpAssetsToFile = false;
         private string m_regionName;
 
-        private int m_levelUpload = 0;
-
-        private bool m_enableFreeTestUpload = false; // allows "TEST-" prefix hack
-        private bool m_ForceFreeTestUpload = false; // forces all uploads to be test
-
-        private bool m_enableModelUploadTextureToInventory = true; // place uploaded textures also in inventory
-                                                                    // may not be visible till relog
-
-        private bool m_RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!!
-        private UUID m_testAssetsCreatorID = UUID.Zero;
-
-        private float m_PrimScaleMin = 0.001f;
-
-        private bool m_AllowCapHomeLocation = true;
-        private bool m_AllowCapGroupMemberData = true;
-        private bool m_AllowCapLandResources = true;
-        private bool m_AllowCapAttachmentResources = true;
-
         private IUserManagement m_UserManager;
         private IUserAccountService m_userAccountService;
         private IMoneyModule m_moneyModule;
@@ -135,74 +117,15 @@ namespace OpenSim.Region.ClientStack.Linden
         }
         private FileAgentInventoryState m_FileAgentInventoryState = FileAgentInventoryState.idle;
 
-        public BunchOfCaps(Scene scene, UUID agentID, Caps caps)
+        public BunchOfCaps(Scene scene, UUID agentID, Caps caps, BunchOfCapsConfigOptions configOptions)
         {
             m_Scene = scene;
             m_AgentID = agentID;
             m_HostCapsObj = caps;
+            ConfigOptions = configOptions;
 
-            // create a model upload cost provider
-            m_ModelCost = new ModelCost(scene);
-
-            m_PrimScaleMin = m_ModelCost.PrimScaleMin;
-
-            IConfigSource config = m_Scene.Config;
-            if (config is not null)
-            {
-                IConfig sconfig = config.Configs["Startup"];
-                if (sconfig is not null)
-                {
-                    m_levelUpload = sconfig.GetInt("LevelUpload", 0);
-                }
-                if (m_levelUpload == 0)
-                {
-                    IConfig pconfig = config.Configs["Permissions"];
-                    if (pconfig is not null)
-                    {
-                        m_levelUpload = pconfig.GetInt("LevelUpload", 0);
-                    }
-                }
-
-                IConfig appearanceConfig = config.Configs["Appearance"];
-                if (appearanceConfig is not null)
-                {
-                    m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures);
-                }
-                // economy for model upload
-                IConfig EconomyConfig = config.Configs["Economy"];
-                if (EconomyConfig is not null)
-                {
-                    m_ModelCost.Econfig(EconomyConfig);
-
-                    m_enableModelUploadTextureToInventory = EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", m_enableModelUploadTextureToInventory);
-
-                    m_RestrictFreeTestUploadPerms = EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", m_RestrictFreeTestUploadPerms);
-                    m_enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", m_enableFreeTestUpload);
-                    m_ForceFreeTestUpload = EconomyConfig.GetBoolean("ForceFreeTestUpload", m_ForceFreeTestUpload);
-                    string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", "");
-                    if (!string.IsNullOrEmpty(testcreator))
-                    {
-                        if (UUID.TryParse(testcreator, out UUID id))
-                            m_testAssetsCreatorID = id;
-                    }
-                }
-
-                IConfig CapsConfig = config.Configs["ClientStack.LindenCaps"];
-                if (CapsConfig is not null)
-                {
-                    string homeLocationUrl = CapsConfig.GetString("Cap_HomeLocation", "localhost");
-                    m_AllowCapHomeLocation = !string.IsNullOrEmpty(homeLocationUrl);
-
-                    string GroupMemberDataUrl = CapsConfig.GetString("Cap_GroupMemberData", "localhost");
-                    m_AllowCapGroupMemberData = !string.IsNullOrEmpty(GroupMemberDataUrl);
-
-                    string LandResourcesUrl = CapsConfig.GetString("Cap_LandResources", "localhost");
-                     m_AllowCapLandResources = !string.IsNullOrEmpty(LandResourcesUrl);
-
-                    string AttachmentResourcesUrl = CapsConfig.GetString("Cap_AttachmentResources", "localhost");
-                    m_AllowCapAttachmentResources = !string.IsNullOrEmpty(AttachmentResourcesUrl);
-                }
-            }
+            //cache model upload cost provider
+            m_ModelCost = configOptions.ModelCost;
 
             m_assetService = m_Scene.AssetService;
             m_regionName = m_Scene.RegionInfo.RegionName;
@@ -212,7 +135,7 @@ namespace OpenSim.Region.ClientStack.Linden
             if (m_UserManager is null)
                 m_log.Error("[CAPS]: GetDisplayNames disabled because user management component not found");
 
-            UserAccount account = m_userAccountService.GetUserAccount(m_Scene.RegionInfo.ScopeID, m_AgentID);
+            UserAccount account = m_userAccountService?.GetUserAccount(m_Scene.RegionInfo.ScopeID, m_AgentID);
             if (account is null) // Hypergrid?
                 m_scopeID = m_Scene.RegionInfo.ScopeID;
             else
@@ -263,25 +186,25 @@ namespace OpenSim.Region.ClientStack.Linden
                 m_HostCapsObj.RegisterSimpleHandler("ResourceCostSelected",
                     new SimpleOSDMapHandler("POST", GetNewCapPath(), ResourceCostSelected));
  
-                if(m_AllowCapHomeLocation)
+                if(ConfigOptions.AllowCapHomeLocation)
                 {
                     m_HostCapsObj.RegisterSimpleHandler("HomeLocation",
                         new SimpleStreamHandler(GetNewCapPath(), HomeLocation));
                 }
 
-                if (m_AllowCapGroupMemberData)
+                if (ConfigOptions.AllowCapGroupMemberData)
                 {
                     m_HostCapsObj.RegisterSimpleHandler("GroupMemberData",
                         new SimpleStreamHandler(GetNewCapPath(), GroupMemberData));
                 }
 
-                if (m_AllowCapLandResources)
+                if (ConfigOptions.AllowCapLandResources)
                 {
                     m_HostCapsObj.RegisterSimpleHandler("LandResources",
                         new SimpleOSDMapHandler("POST", GetNewCapPath(), LandResources));
                 }
 
-                if (m_AllowCapAttachmentResources)
+                if (ConfigOptions.AllowCapAttachmentResources)
                 {
                     m_HostCapsObj.RegisterSimpleHandler("AttachmentResources",
                         new SimpleStreamHandler(GetNewCapPath(), AttachmentResources));
@@ -505,7 +428,7 @@ namespace OpenSim.Region.ClientStack.Linden
                 // check user level
                 if (avatar is not null)
                 {
-                    if (avatar.GodController.UserLevel < m_levelUpload)
+                    if (avatar.GodController.UserLevel < ConfigOptions.levelUpload)
                     {
                         LLSDAssetUploadError resperror = new LLSDAssetUploadError();
                         resperror.message = "Insufficient permissions to upload";
@@ -564,7 +487,7 @@ namespace OpenSim.Region.ClientStack.Linden
                     {
                         // check for test upload
 
-                        if (m_ForceFreeTestUpload) // all are test
+                        if (ConfigOptions.ForceFreeTestUpload) // all are test
                         {
                             if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it
                                 assetName = "TEST-" + assetName;
@@ -572,7 +495,7 @@ namespace OpenSim.Region.ClientStack.Linden
                             IsAtestUpload = true;
                         }
 
-                        else if (m_enableFreeTestUpload) // only if prefixed with "TEST-"
+                        else if (ConfigOptions.enableFreeTestUpload) // only if prefixed with "TEST-"
                         {
 
                             IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-"));
@@ -600,7 +523,7 @@ namespace OpenSim.Region.ClientStack.Linden
                             }
                         }
                     }
-                    else if (m_enableFreeTestUpload) // only if prefixed with "TEST-"
+                    else if (ConfigOptions.enableFreeTestUpload) // only if prefixed with "TEST-"
                     {
                         IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-"));
                         if(IsAtestUpload)
@@ -619,7 +542,7 @@ namespace OpenSim.Region.ClientStack.Linden
             string uploaderPath = GetNewCapPath();
             UUID texturesFolder = UUID.Zero;
 
-            if(!IsAtestUpload && m_enableModelUploadTextureToInventory)
+            if(!IsAtestUpload && ConfigOptions.enableModelUploadTextureToInventory)
                 texturesFolder = llsdRequest.texture_folder_id;
 
             AssetUploader uploader =
@@ -688,12 +611,12 @@ namespace OpenSim.Region.ClientStack.Linden
             UUID owner_id = m_HostCapsObj.AgentID;
             UUID creatorID;
 
-            bool istest = IsAtestUpload && m_enableFreeTestUpload;
+            bool istest = IsAtestUpload && ConfigOptions.enableFreeTestUpload;
 
-            bool restrictPerms = m_RestrictFreeTestUploadPerms && istest;
+            bool restrictPerms = ConfigOptions.RestrictFreeTestUploadPerms && istest;
 
-            if (istest && m_testAssetsCreatorID != UUID.Zero)
-                creatorID = m_testAssetsCreatorID;
+            if (istest && ConfigOptions.testAssetsCreatorID.IsNotZero())
+                creatorID = ConfigOptions.testAssetsCreatorID;
             else
                 creatorID = owner_id;
 
@@ -779,7 +702,7 @@ namespace OpenSim.Region.ClientStack.Linden
                     SceneObjectGroup grp = null;
 
                     // create and store texture assets
-                    bool doTextInv = (!istest && m_enableModelUploadTextureToInventory &&
+                    bool doTextInv = (!istest && ConfigOptions.enableModelUploadTextureToInventory &&
                                     texturesFolder != UUID.Zero);
 
 
@@ -904,6 +827,7 @@ namespace OpenSim.Region.ClientStack.Linden
                     }
 
                     int skipedMeshs = 0;
+                    float primScaleMin = m_ModelCost.PrimScaleMin;
                     // build prims from instances
                     for (int i = 0; i < instance_list.Count; i++)
                     {
@@ -912,7 +836,7 @@ namespace OpenSim.Region.ClientStack.Linden
                         // skip prims that are 2 small
                         Vector3 scale = inner_instance_list["scale"].AsVector3();
 
-                        if (scale.X < m_PrimScaleMin || scale.Y < m_PrimScaleMin || scale.Z < m_PrimScaleMin)
+                        if (scale.X < primScaleMin || scale.Y < primScaleMin || scale.Z < primScaleMin)
                         {
                             skipedMeshs++;
                             continue;
@@ -1553,12 +1477,8 @@ namespace OpenSim.Region.ClientStack.Linden
                     if (grp != null)
                     {
                         haveone = true;
-                        float linksetCost;
-                        float linksetPhysCost;
-                        float partCost;
-                        float partPhysCost;
 
-                        grp.GetResourcesCosts(part,out linksetCost,out linksetPhysCost,out partCost,out partPhysCost);
+                        grp.GetResourcesCosts(part, out float linksetCost, out float linksetPhysCost, out float partCost, out float partPhysCost);
 
                         LLSDxmlEncode2.AddMap(uuid.ToString(), lsl);
 

+ 88 - 6
OpenSim/Region/ClientStack/Linden/Caps/BunchOfCaps/BunchOfCapsModule.cs

@@ -26,8 +26,6 @@
  */
 
 using System;
-using System.Collections.Generic;
-using System.Reflection;
 
 using log4net;
 using Nini.Config;
@@ -44,14 +42,35 @@ using Caps = OpenSim.Framework.Capabilities.Caps;
 [assembly: AddinDependency("OpenSim.Region.Framework", OpenSim.VersionInfo.VersionNumber)]
 namespace OpenSim.Region.ClientStack.Linden
 {
+    public class BunchOfCapsConfigOptions
+    {
+        public ModelCost ModelCost;
+
+        public bool persistBakedTextures = false;
+        public bool enableModelUploadTextureToInventory = true; // place uploaded textures also in inventory
+                                                                // may not be visible till relog
+        public bool enableFreeTestUpload = false; // allows "TEST-" prefix hack
+        public bool ForceFreeTestUpload = false; // forces all uploads to be test
+
+        public bool RestrictFreeTestUploadPerms = false; // reduces also the permitions. Needs a creator defined!!
+
+        public int levelUpload = 0;
+
+        public bool AllowCapHomeLocation = true;
+        public bool AllowCapGroupMemberData = true;
+        public bool AllowCapLandResources = true;
+        public bool AllowCapAttachmentResources = true;
+
+        public UUID testAssetsCreatorID = UUID.Zero;
+    }
 
     [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "BunchOfCapsModule")]
     public class BunchOfCapsModule : INonSharedRegionModule
     {
-//        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 BunchOfCapsConfigOptions ConfigOptions = new();
 
         #region INonSharedRegionModule
 
@@ -68,7 +87,6 @@ namespace OpenSim.Region.ClientStack.Linden
         public void AddRegion(Scene scene)
         {
             m_Scene = scene;
-            m_Scene.EventManager.OnRegisterCaps += OnRegisterCaps;
         }
 
         public void RemoveRegion(Scene scene)
@@ -77,6 +95,70 @@ namespace OpenSim.Region.ClientStack.Linden
 
         public void RegionLoaded(Scene scene)
         {
+            ConfigOptions.ModelCost = new ModelCost(m_Scene);
+
+            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", 0);
+
+                if (ConfigOptions.levelUpload == 0)
+                {
+                    IConfig pconfig = config.Configs["Permissions"];
+                    if (pconfig is not null)
+                        ConfigOptions.levelUpload = pconfig.GetInt("LevelUpload", 0);
+                }
+
+                IConfig appearanceConfig = config.Configs["Appearance"];
+                if (appearanceConfig is not null)
+                {
+                    ConfigOptions.persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", ConfigOptions.persistBakedTextures);
+                }
+                // economy for model upload
+                IConfig EconomyConfig = config.Configs["Economy"];
+                if (EconomyConfig is not null)
+                {
+                    ConfigOptions.ModelCost.Econfig(EconomyConfig);
+
+                    ConfigOptions.enableModelUploadTextureToInventory =
+                        EconomyConfig.GetBoolean("MeshModelAllowTextureToInventory", ConfigOptions.enableModelUploadTextureToInventory);
+
+                    ConfigOptions.RestrictFreeTestUploadPerms =
+                        EconomyConfig.GetBoolean("m_RestrictFreeTestUploadPerms", ConfigOptions.RestrictFreeTestUploadPerms);
+
+                    ConfigOptions.enableFreeTestUpload = EconomyConfig.GetBoolean("AllowFreeTestUpload", ConfigOptions.enableFreeTestUpload);
+
+                    ConfigOptions.ForceFreeTestUpload =
+                        EconomyConfig.GetBoolean("ForceFreeTestUpload", ConfigOptions.ForceFreeTestUpload);
+
+                    string testcreator = EconomyConfig.GetString("TestAssetsCreatorID", "");
+                    if (!string.IsNullOrEmpty(testcreator))
+                    {
+                        if (UUID.TryParse(testcreator, out UUID id))
+                            ConfigOptions.testAssetsCreatorID = id;
+                    }
+                }
+
+                IConfig CapsConfig = config.Configs["ClientStack.LindenCaps"];
+                if (CapsConfig is not null)
+                {
+                    string homeLocationUrl = CapsConfig.GetString("Cap_HomeLocation", "localhost");
+                    ConfigOptions.AllowCapHomeLocation = !string.IsNullOrEmpty(homeLocationUrl);
+
+                    string GroupMemberDataUrl = CapsConfig.GetString("Cap_GroupMemberData", "localhost");
+                    ConfigOptions.AllowCapGroupMemberData = !string.IsNullOrEmpty(GroupMemberDataUrl);
+
+                    string LandResourcesUrl = CapsConfig.GetString("Cap_LandResources", "localhost");
+                    ConfigOptions.AllowCapLandResources = !string.IsNullOrEmpty(LandResourcesUrl);
+
+                    string AttachmentResourcesUrl = CapsConfig.GetString("Cap_AttachmentResources", "localhost");
+                    ConfigOptions.AllowCapAttachmentResources = !string.IsNullOrEmpty(AttachmentResourcesUrl);
+                }
+
+                m_Scene.EventManager.OnRegisterCaps += OnRegisterCaps;
+            }
         }
 
         public void PostInitialise() { }
@@ -84,7 +166,7 @@ namespace OpenSim.Region.ClientStack.Linden
 
         private void OnRegisterCaps(UUID agentID, Caps caps)
         {
-            new BunchOfCaps(m_Scene, agentID, caps);
+            _ = new BunchOfCaps(m_Scene, agentID, caps, ConfigOptions);
         }
 
     }

+ 2 - 2
OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs

@@ -901,7 +901,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
             //TerrainBase1
             //TerrainBase2
             //TerrainBase3
-            // this seem not obsolete, sending zero uuids
+            // this seem now obsolete, sending zero uuids
             // we should send the basic low resolution default ?
             zc.AddZeros(16 * 4);
             //TerrainDetail0
@@ -5520,7 +5520,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
                         inner = $"{{'id':i{sop.LocalId},'od':[],'te':[]}}";
 
                     byte[] innerB = Util.UTF8NBGetbytes(inner);
-                    if (innerB.Length > 4096 - 16)
+                    if (innerB.Length > UDPPacketBuffer.BUFFER_SIZE - 16)
                     {
                         m_log.Debug($"[LLCLIENTVIEW]: GenericStreamingMessage packet too large ({innerB.Length})");
                         continue;