add several options for NPC creation so abusive use can be reduced (restrictive by default) UNTESTED

avinationmerge
UbitUmarov 2015-09-30 02:45:11 +01:00
parent 1124d14eb0
commit feb78b2910
4 changed files with 96 additions and 10 deletions

View File

@ -31,6 +31,16 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.Framework.Interfaces namespace OpenSim.Region.Framework.Interfaces
{ {
// option flags for NPCs
public enum NPCOptionsFlags : int
{
None = 0x00, // no flags (max restriction)
AllowNotOwned = 0x01, // allow NPCs to be created not Owned
AllowSenseAsAvatar = 0x02, // allow NPCs to set to be sensed as Avatars
AllowCloneOtherAvatars = 0x04, // allow NPCs to created cloning a avatar in region
NoNPCGroup = 0x08 // NPCs will have no group title, otherwise will have "- NPC -"
}
/// <summary> /// <summary>
/// Temporary interface. More methods to come at some point to make NPCs /// Temporary interface. More methods to come at some point to make NPCs
/// more object oriented rather than controlling purely through module /// more object oriented rather than controlling purely through module
@ -284,5 +294,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// agent, the agent is unowned or the agent was not an NPC. /// agent, the agent is unowned or the agent was not an NPC.
/// </returns> /// </returns>
UUID GetOwner(UUID agentID); UUID GetOwner(UUID agentID);
NPCOptionsFlags NPCOptionFlags {get;}
} }
} }

View File

@ -52,6 +52,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC
private Dictionary<UUID, NPCAvatar> m_avatars = private Dictionary<UUID, NPCAvatar> m_avatars =
new Dictionary<UUID, NPCAvatar>(); new Dictionary<UUID, NPCAvatar>();
private NPCOptionsFlags m_NPCOptionFlags;
public NPCOptionsFlags NPCOptionFlags {get {return m_NPCOptionFlags;}}
public bool Enabled { get; private set; } public bool Enabled { get; private set; }
public void Initialise(IConfigSource source) public void Initialise(IConfigSource source)
@ -59,6 +64,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC
IConfig config = source.Configs["NPC"]; IConfig config = source.Configs["NPC"];
Enabled = (config != null && config.GetBoolean("Enabled", false)); Enabled = (config != null && config.GetBoolean("Enabled", false));
m_NPCOptionFlags = NPCOptionsFlags.None;
if(Enabled)
{
bool opt = false;
opt = config.GetBoolean("AllowNotOwned", false);
if(opt)
m_NPCOptionFlags |= NPCOptionsFlags.AllowNotOwned;
opt = config.GetBoolean("AllowSenseAsAvatar", false);
if(opt)
m_NPCOptionFlags |= NPCOptionsFlags.AllowSenseAsAvatar;
opt = config.GetBoolean("AllowCloneOtherAvatars", false);
if(opt)
m_NPCOptionFlags |= NPCOptionsFlags.AllowCloneOtherAvatars;
opt = config.GetBoolean("NoNPCGroup", false);
if(opt)
m_NPCOptionFlags |= NPCOptionsFlags.NoNPCGroup;
}
} }
public void AddRegion(Scene scene) public void AddRegion(Scene scene)

View File

@ -142,7 +142,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
internal float m_ScriptDistanceFactor = 1.0f; internal float m_ScriptDistanceFactor = 1.0f;
internal bool m_debuggerSafe = false; internal bool m_debuggerSafe = false;
internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >(); internal Dictionary<string, FunctionPerms > m_FunctionPerms = new Dictionary<string, FunctionPerms >();
protected IUrlModule m_UrlModule = null; protected IUrlModule m_UrlModule = null;
public void Initialize( public void Initialize(
@ -196,7 +195,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
default: default:
break; break;
} }
} }
public override Object InitializeLifetimeService() public override Object InitializeLifetimeService()
{ {
@ -2578,7 +2577,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
return NpcCreate(firstname, lastname, position, notecard, false, false); // have to get the npc module also here to set the default Not Owned
INPCModule module = World.RequestModuleInterface<INPCModule>();
if(module == null)
return new LSL_Key(UUID.Zero.ToString());
bool owned = (module.NPCOptionFlags & NPCOptionsFlags.AllowNotOwned) == 0;
return NpcCreate(firstname, lastname, position, notecard, owned, false);
} }
public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options) public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard, int options)
@ -2595,7 +2601,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
private LSL_Key NpcCreate( private LSL_Key NpcCreate(
string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent) string firstname, string lastname, LSL_Vector position, string notecard, bool owned, bool senseAsAgent)
{ {
string groupTitle = String.Empty;
if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z))) if (!World.Permissions.CanRezObject(1, m_host.OwnerID, new Vector3((float)position.x, (float)position.y, (float)position.z)))
return new LSL_Key(UUID.Zero.ToString()); return new LSL_Key(UUID.Zero.ToString());
@ -2603,14 +2608,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
INPCModule module = World.RequestModuleInterface<INPCModule>(); INPCModule module = World.RequestModuleInterface<INPCModule>();
if (module != null) if (module != null)
{ {
string groupTitle = String.Empty;
AvatarAppearance appearance = null; AvatarAppearance appearance = null;
UUID id; // check creation options
if (UUID.TryParse(notecard, out id)) NPCOptionsFlags createFlags = module.NPCOptionFlags;
if((createFlags & NPCOptionsFlags.AllowNotOwned) == 0 && !owned)
{ {
ScenePresence clonePresence = World.GetScenePresence(id); OSSLError("Not owned NPCs disabled");
if (clonePresence != null) owned = true; // we should get here...
appearance = clonePresence.Appearance; }
if((createFlags & NPCOptionsFlags.AllowSenseAsAvatar) == 0 && senseAsAgent)
{
OSSLError("NPC allow sense as Avatar disabled");
senseAsAgent = false;
}
if((createFlags & NPCOptionsFlags.NoNPCGroup) == 0)
{
if (firstname != String.Empty || lastname != String.Empty)
{
if (firstname != "Shown outfit:")
groupTitle = "- NPC -";
}
}
if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0)
{
UUID id;
if (UUID.TryParse(notecard, out id))
{
ScenePresence clonePresence = World.GetScenePresence(id);
if (clonePresence != null)
appearance = clonePresence.Appearance;
}
} }
if (appearance == null) if (appearance == null)

View File

@ -1115,6 +1115,21 @@
;# {Enabled} {} {Enable Non Player Character (NPC) facilities} {true false} false ;# {Enabled} {} {Enable Non Player Character (NPC) facilities} {true false} false
; Enabled = false ; Enabled = false
;; several options to control NPCs creation
;; should only be set true on special uses.
;; allow NPCs to be created not Owned {true false} false
; AllowNotOwned = false
;; allow NPCs to set to be sensed as Avatars {true false} false
; AllowSenseAsAvatar = false
;; allow NPCs to created cloning any avatar in region {true false} false
; AllowCloneOtherAvatars = false
;; if true NPCs will have no group title, if false display "- NPC -" for easy identification {true false} false
; NoNPCGroup = false
[Terrain] [Terrain]
;# {InitialTerrain} {} {Initial terrain type} {pinhead-island flat} pinhead-island ;# {InitialTerrain} {} {Initial terrain type} {pinhead-island flat} pinhead-island