From fbc10387c84078e5d815da818435efca75c20fd6 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 16 Jul 2021 01:52:03 +0100 Subject: [PATCH] add a optional limit on number of npcs per scene default = 40 --- OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 10 ++++++++++ bin/OpenSim.ini.example | 5 +++++ bin/OpenSimDefaults.ini | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index e0f5103a53..053e2ecae4 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -51,6 +51,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC private readonly Dictionary m_avatars = new Dictionary(); private NPCOptionsFlags m_NPCOptionFlags; + private int m_MaxNumberNPCperScene = 40; + public NPCOptionsFlags NPCOptionFlags {get {return m_NPCOptionFlags;}} public bool Enabled { get; private set; } @@ -74,6 +76,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC if(config.GetBoolean("NoNPCGroup", true)) m_NPCOptionFlags |= NPCOptionsFlags.NoNPCGroup; + + m_MaxNumberNPCperScene = config.GetInt("MaxNumberNPCsPerScene", m_MaxNumberNPCperScene); } } @@ -161,6 +165,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC Vector3 position, UUID agentID, UUID owner, string groupTitle, UUID groupID, bool senseAsAgent, Scene scene, AvatarAppearance appearance) { + if(m_MaxNumberNPCperScene > 0) + { + if(scene.GetRootNPCCount() >= m_MaxNumberNPCperScene) + return UUID.Zero; + } + NPCAvatar npcAvatar = null; string born = DateTime.UtcNow.ToString(); diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 99ae3d246c..1a7ef1f0a2 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -1208,6 +1208,11 @@ ;# {Enabled} {} {Enable Non Player Character (NPC) facilities} {true false} false ; Enabled = false + ;; max number of NPCs per scene default: 40 + ;; set to a negative value to allow any number + ;; note that a NPC is almost as heavy as a normal avatar, so you should limit them + ;; MaxNumberNPCsPerScene = 40 + ;; several options to control NPCs creation ;# {AllowNotOwned} {} {allow NPCs to be created not Owned} {true false} true diff --git a/bin/OpenSimDefaults.ini b/bin/OpenSimDefaults.ini index 55bdda9875..fa3335c040 100644 --- a/bin/OpenSimDefaults.ini +++ b/bin/OpenSimDefaults.ini @@ -2142,6 +2142,12 @@ [NPC] ;; Enable Non Player Character (NPC) facilities Enabled = false + + ;; max number of NPCs per scene default: 40 + ;; set to a negative value to allow any number + ;; note that a NPC is almost as heavy as a normal avatar, so you should limit them + ;; MaxNumberNPCsPerScene = 40 + ;; several options to control NPCs creation ;; allow NPCs to be created not Owned {true false} default: true