From 23605cf93d110523320430d1c9dd2e83865fca01 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 11 Nov 2012 20:41:20 +0000 Subject: converting NPC module to ISharedRegionModule Signed-off-by: Diva Canto --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 31 +++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3f25bcf..b372c88 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -31,6 +31,7 @@ using System.Reflection; using System.Threading; using log4net; using Nini.Config; +using Mono.Addins; using OpenMetaverse; using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; @@ -40,26 +41,41 @@ using OpenSim.Services.Interfaces; namespace OpenSim.Region.OptionalModules.World.NPC { - public class NPCModule : IRegionModule, INPCModule + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + public class NPCModule : INPCModule, ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private Dictionary m_avatars = new Dictionary(); - public void Initialise(Scene scene, IConfigSource source) + public bool Enabled { get; private set; } + + public void Initialise(IConfigSource source) { IConfig config = source.Configs["NPC"]; - if (config != null && config.GetBoolean("Enabled", false)) - { + Enabled = (config != null && config.GetBoolean("Enabled", false)); + } + + public void AddRegion(Scene scene) + { + if (Enabled) scene.RegisterModuleInterface(this); - } + } + + public void RegionLoaded(Scene scene) + { } public void PostInitialise() { } + public void RemoveRegion(Scene scene) + { + scene.UnregisterModuleInterface(this); + } + public void Close() { } @@ -69,10 +85,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC get { return "NPCModule"; } } - public bool IsSharedModule - { - get { return true; } - } + public Type ReplaceableInterface { get { return null; } } public bool IsNPC(UUID agentId, Scene scene) { -- cgit v1.1 From f560d581bbeb420dccdfa80c574724deada8038b Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 11 Nov 2012 20:42:55 +0000 Subject: document & 80-character width terminal formatting Signed-off-by: Diva Canto --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 129 +++++++++++++-------- 1 file changed, 80 insertions(+), 49 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index b372c88..41e7097 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -29,14 +29,16 @@ using System; using System.Collections.Generic; using System.Reflection; using System.Threading; +using Timer = System.Timers.Timer; + using log4net; using Nini.Config; using Mono.Addins; using OpenMetaverse; + using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Scenes; using OpenSim.Framework; -using Timer=System.Timers.Timer; using OpenSim.Services.Interfaces; namespace OpenSim.Region.OptionalModules.World.NPC @@ -44,9 +46,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] public class NPCModule : INPCModule, ISharedRegionModule { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static readonly ILog m_log = LogManager.GetLogger( + MethodBase.GetCurrentMethod().DeclaringType); - private Dictionary m_avatars = new Dictionary(); + private Dictionary m_avatars = + new Dictionary(); public bool Enabled { get; private set; } @@ -89,8 +93,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC public bool IsNPC(UUID agentId, Scene scene) { - // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect - // that directly). + // FIXME: This implementation could not just use the + // ScenePresence.PresenceType (and callers could inspect that + // directly). ScenePresence sp = scene.GetScenePresence(agentId); if (sp == null || sp.IsChildAgent) return false; @@ -99,7 +104,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC return m_avatars.ContainsKey(agentId); } - public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene) + public bool SetNPCAppearance(UUID agentId, + AvatarAppearance appearance, Scene scene) { ScenePresence npc = scene.GetScenePresence(agentId); if (npc == null || npc.IsChildAgent) @@ -112,34 +118,35 @@ namespace OpenSim.Region.OptionalModules.World.NPC // Delete existing npc attachments scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); - // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments - AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); + // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet + // since it doesn't transfer attachments + AvatarAppearance npcAppearance = new AvatarAppearance(appearance, + true); npc.Appearance = npcAppearance; - + // Rez needed npc attachments scene.AttachmentsModule.RezAttachments(npc); - IAvatarFactoryModule module = scene.RequestModuleInterface(); + IAvatarFactoryModule module = + scene.RequestModuleInterface(); module.SendAppearance(npc.UUID); - + return true; } - public UUID CreateNPC( - string firstname, - string lastname, - Vector3 position, - UUID owner, - bool senseAsAgent, - Scene scene, - AvatarAppearance appearance) + public UUID CreateNPC(string firstname, string lastname, + Vector3 position, UUID owner, bool senseAsAgent, Scene scene, + AvatarAppearance appearance) { - NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); - npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); + NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, + owner, senseAsAgent, scene); + npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, + int.MaxValue); m_log.DebugFormat( - "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", - firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName); + "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", + firstname, lastname, npcAvatar.AgentId, owner, + senseAsAgent, position, scene.RegionInfo.RegionName); AgentCircuitData acd = new AgentCircuitData(); acd.AgentID = npcAvatar.AgentId; @@ -147,42 +154,55 @@ namespace OpenSim.Region.OptionalModules.World.NPC acd.lastname = lastname; acd.ServiceURLs = new Dictionary(); - AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); + AvatarAppearance npcAppearance = new AvatarAppearance(appearance, + true); acd.Appearance = npcAppearance; -// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) -// { -// m_log.DebugFormat( -// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", -// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); -// } + /* + for (int i = 0; + i < acd.Appearance.Texture.FaceTextures.Length; i++) + { + m_log.DebugFormat( + "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", + acd.AgentID, i, + acd.Appearance.Texture.FaceTextures[i]); + } + */ lock (m_avatars) { - scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); + scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, + acd); scene.AddNewClient(npcAvatar, PresenceType.Npc); ScenePresence sp; if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) { -// m_log.DebugFormat( -// "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); + /* + m_log.DebugFormat( + "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", + sp.Name, sp.UUID); + */ sp.CompleteMovement(npcAvatar, false); m_avatars.Add(npcAvatar.AgentId, npcAvatar); - m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); + m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", + npcAvatar.AgentId, sp.Name); return npcAvatar.AgentId; } else { - m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); + m_log.WarnFormat( + "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", + sp.Name, sp.UUID); return UUID.Zero; } } } - public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) + public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, + bool noFly, bool landAtTarget, bool running) { lock (m_avatars) { @@ -192,12 +212,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (scene.TryGetScenePresence(agentID, out sp)) { m_log.DebugFormat( - "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", - sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); + "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", + sp.Name, pos, scene.RegionInfo.RegionName, + noFly, landAtTarget); sp.MoveToTarget(pos, noFly, landAtTarget); sp.SetAlwaysRun = running; - + return true; } } @@ -270,9 +291,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC ScenePresence sp; if (scene.TryGetScenePresence(agentID, out sp)) { - sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); - // sp.HandleAgentSit(m_avatars[agentID], agentID); - + sp.HandleAgentRequestSit(m_avatars[agentID], agentID, + partID, Vector3.Zero); + //sp.HandleAgentSit(m_avatars[agentID], agentID); + return true; } } @@ -281,7 +303,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC return false; } - public bool Whisper(UUID agentID, Scene scene, string text, int channel) + public bool Whisper(UUID agentID, Scene scene, string text, + int channel) { lock (m_avatars) { @@ -356,16 +379,23 @@ namespace OpenSim.Region.OptionalModules.World.NPC NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { -// m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); + /* + m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", + agentID, av.Name); + */ scene.RemoveClient(agentID, false); m_avatars.Remove(agentID); - - m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); + /* + m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", + agentID, av.Name); + */ return true; } } - -// m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); + /* + m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", + agentID); + */ return false; } @@ -389,7 +419,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC /// true if they do, false if they don't. private bool CheckPermissions(NPCAvatar av, UUID callerID) { - return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; + return callerID == UUID.Zero || av.OwnerID == UUID.Zero || + av.OwnerID == callerID; } } } -- cgit v1.1 From 86903f23dd9c0e671fcc9854c031bcc0c6d6cc7f Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 12 Nov 2012 18:08:02 -0800 Subject: Cleanup on region modules: gave short node id's to all of them. --- OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 41e7097..7d46d92 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -43,7 +43,7 @@ using OpenSim.Services.Interfaces; namespace OpenSim.Region.OptionalModules.World.NPC { - [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] + [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NPCModule")] public class NPCModule : INPCModule, ISharedRegionModule { private static readonly ILog m_log = LogManager.GetLogger( -- cgit v1.1