aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs26
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs124
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs11
3 files changed, 107 insertions, 54 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
index 7c693b6..d665126 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs
@@ -148,7 +148,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
148 OnInstantMessage(this, new GridInstantMessage(m_scene, 148 OnInstantMessage(this, new GridInstantMessage(m_scene,
149 m_uuid, m_firstname + " " + m_lastname, 149 m_uuid, m_firstname + " " + m_lastname,
150 target, 0, false, message, 150 target, 0, false, message,
151 UUID.Zero, false, Position, new byte[0])); 151 UUID.Zero, false, Position, new byte[0], true));
152 } 152 }
153 153
154 public void SendAgentOffline(UUID[] agentIDs) 154 public void SendAgentOffline(UUID[] agentIDs)
@@ -473,7 +473,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
473 public event MuteListEntryRemove OnRemoveMuteListEntry; 473 public event MuteListEntryRemove OnRemoveMuteListEntry;
474 public event GodlikeMessage onGodlikeMessage; 474 public event GodlikeMessage onGodlikeMessage;
475 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate; 475 public event GodUpdateRegionInfoUpdate OnGodUpdateRegionInfoUpdate;
476 476 public event GenericCall2 OnUpdateThrottles;
477#pragma warning restore 67 477#pragma warning restore 67
478 478
479 #endregion 479 #endregion
@@ -597,6 +597,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC
597 public virtual void SetChildAgentThrottle(byte[] throttle) 597 public virtual void SetChildAgentThrottle(byte[] throttle)
598 { 598 {
599 } 599 }
600
601 public void SetAgentThrottleSilent(int throttle, int setting)
602 {
603
604
605 }
600 public byte[] GetThrottlesPacked(float multiplier) 606 public byte[] GetThrottlesPacked(float multiplier)
601 { 607 {
602 return new byte[0]; 608 return new byte[0];
@@ -607,13 +613,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC
607 { 613 {
608 } 614 }
609 615
610 public virtual void SendChatMessage(string message, byte type, Vector3 fromPos, string fromName, 616 public virtual void SendChatMessage(
611 UUID fromAgentID, byte source, byte audible) 617 string message, byte type, Vector3 fromPos, string fromName,
618 UUID fromAgentID, UUID ownerID, byte source, byte audible)
612 { 619 {
613 } 620 }
614 621
615 public virtual void SendChatMessage(byte[] message, byte type, Vector3 fromPos, string fromName, 622 public virtual void SendChatMessage(
616 UUID fromAgentID, byte source, byte audible) 623 byte[] message, byte type, Vector3 fromPos, string fromName,
624 UUID fromAgentID, UUID ownerID, byte source, byte audible)
617 { 625 {
618 } 626 }
619 627
@@ -909,11 +917,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
909 917
910 public void Close() 918 public void Close()
911 { 919 {
912 Close(true); 920 Close(true, false);
913 } 921 }
914 922
915 public void Close(bool sendStop) 923 public void Close(bool sendStop, bool force)
916 { 924 {
925 // Remove ourselves from the scene
926 m_scene.RemoveClient(AgentId, false);
917 } 927 }
918 928
919 public void Start() 929 public void Start()
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index f16927c..8c9c006 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -29,37 +29,57 @@ using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Reflection; 30using System.Reflection;
31using System.Threading; 31using System.Threading;
32using Timer = System.Timers.Timer;
33
32using log4net; 34using log4net;
33using Nini.Config; 35using Nini.Config;
36using Mono.Addins;
34using OpenMetaverse; 37using OpenMetaverse;
38
35using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
37using OpenSim.Framework; 41using OpenSim.Framework;
38using Timer=System.Timers.Timer;
39using OpenSim.Services.Interfaces; 42using OpenSim.Services.Interfaces;
40 43
41namespace OpenSim.Region.OptionalModules.World.NPC 44namespace OpenSim.Region.OptionalModules.World.NPC
42{ 45{
43 public class NPCModule : IRegionModule, INPCModule 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NPCModule")]
47 public class NPCModule : INPCModule, ISharedRegionModule
44 { 48 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 49 private static readonly ILog m_log = LogManager.GetLogger(
50 MethodBase.GetCurrentMethod().DeclaringType);
51
52 private Dictionary<UUID, NPCAvatar> m_avatars =
53 new Dictionary<UUID, NPCAvatar>();
46 54
47 private Dictionary<UUID, NPCAvatar> m_avatars = new Dictionary<UUID, NPCAvatar>(); 55 public bool Enabled { get; private set; }
48 56
49 public void Initialise(Scene scene, IConfigSource source) 57 public void Initialise(IConfigSource source)
50 { 58 {
51 IConfig config = source.Configs["NPC"]; 59 IConfig config = source.Configs["NPC"];
52 60
53 if (config != null && config.GetBoolean("Enabled", false)) 61 Enabled = (config != null && config.GetBoolean("Enabled", false));
54 { 62 }
63
64 public void AddRegion(Scene scene)
65 {
66 if (Enabled)
55 scene.RegisterModuleInterface<INPCModule>(this); 67 scene.RegisterModuleInterface<INPCModule>(this);
56 } 68 }
69
70 public void RegionLoaded(Scene scene)
71 {
57 } 72 }
58 73
59 public void PostInitialise() 74 public void PostInitialise()
60 { 75 {
61 } 76 }
62 77
78 public void RemoveRegion(Scene scene)
79 {
80 scene.UnregisterModuleInterface<INPCModule>(this);
81 }
82
63 public void Close() 83 public void Close()
64 { 84 {
65 } 85 }
@@ -69,15 +89,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
69 get { return "NPCModule"; } 89 get { return "NPCModule"; }
70 } 90 }
71 91
72 public bool IsSharedModule 92 public Type ReplaceableInterface { get { return null; } }
73 {
74 get { return true; }
75 }
76 93
77 public bool IsNPC(UUID agentId, Scene scene) 94 public bool IsNPC(UUID agentId, Scene scene)
78 { 95 {
79 // FIXME: This implementation could not just use the ScenePresence.PresenceType (and callers could inspect 96 // FIXME: This implementation could not just use the
80 // that directly). 97 // ScenePresence.PresenceType (and callers could inspect that
98 // directly).
81 ScenePresence sp = scene.GetScenePresence(agentId); 99 ScenePresence sp = scene.GetScenePresence(agentId);
82 if (sp == null || sp.IsChildAgent) 100 if (sp == null || sp.IsChildAgent)
83 return false; 101 return false;
@@ -86,7 +104,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
86 return m_avatars.ContainsKey(agentId); 104 return m_avatars.ContainsKey(agentId);
87 } 105 }
88 106
89 public bool SetNPCAppearance(UUID agentId, AvatarAppearance appearance, Scene scene) 107 public bool SetNPCAppearance(UUID agentId,
108 AvatarAppearance appearance, Scene scene)
90 { 109 {
91 ScenePresence npc = scene.GetScenePresence(agentId); 110 ScenePresence npc = scene.GetScenePresence(agentId);
92 if (npc == null || npc.IsChildAgent) 111 if (npc == null || npc.IsChildAgent)
@@ -99,30 +118,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC
99 // Delete existing npc attachments 118 // Delete existing npc attachments
100 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false); 119 scene.AttachmentsModule.DeleteAttachmentsFromScene(npc, false);
101 120
102 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet since it doesn't transfer attachments 121 // XXX: We can't just use IAvatarFactoryModule.SetAppearance() yet
103 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); 122 // since it doesn't transfer attachments
123 AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
124 true);
104 npc.Appearance = npcAppearance; 125 npc.Appearance = npcAppearance;
105 126
106 // Rez needed npc attachments 127 // Rez needed npc attachments
107 scene.AttachmentsModule.RezAttachments(npc); 128 scene.AttachmentsModule.RezAttachments(npc);
108 129
109 IAvatarFactoryModule module = scene.RequestModuleInterface<IAvatarFactoryModule>(); 130 IAvatarFactoryModule module =
131 scene.RequestModuleInterface<IAvatarFactoryModule>();
110 module.SendAppearance(npc.UUID); 132 module.SendAppearance(npc.UUID);
111 133
112 return true; 134 return true;
113 } 135 }
114 136
115 public UUID CreateNPC( 137 public UUID CreateNPC(string firstname, string lastname,
116 string firstname, 138 Vector3 position, UUID owner, bool senseAsAgent, Scene scene,
117 string lastname, 139 AvatarAppearance appearance)
118 Vector3 position,
119 UUID owner,
120 bool senseAsAgent,
121 Scene scene,
122 AvatarAppearance appearance)
123 { 140 {
124 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); 141 NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position,
125 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); 142 owner, senseAsAgent, scene);
143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
144 int.MaxValue);
126 145
127// m_log.DebugFormat( 146// m_log.DebugFormat(
128// "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", 147// "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}",
@@ -134,15 +153,20 @@ namespace OpenSim.Region.OptionalModules.World.NPC
134 acd.lastname = lastname; 153 acd.lastname = lastname;
135 acd.ServiceURLs = new Dictionary<string, object>(); 154 acd.ServiceURLs = new Dictionary<string, object>();
136 155
137 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); 156 AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
157 true);
138 acd.Appearance = npcAppearance; 158 acd.Appearance = npcAppearance;
139 159
140// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) 160 /*
141// { 161 for (int i = 0;
142// m_log.DebugFormat( 162 i < acd.Appearance.Texture.FaceTextures.Length; i++)
143// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", 163 {
144// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); 164 m_log.DebugFormat(
145// } 165 "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
166 acd.AgentID, i,
167 acd.Appearance.Texture.FaceTextures[i]);
168 }
169 */
146 170
147 ManualResetEvent ev = new ManualResetEvent(false); 171 ManualResetEvent ev = new ManualResetEvent(false);
148 172
@@ -170,7 +194,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
170 return npcAvatar.AgentId; 194 return npcAvatar.AgentId;
171 } 195 }
172 196
173 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) 197 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
198 bool noFly, bool landAtTarget, bool running)
174 { 199 {
175 lock (m_avatars) 200 lock (m_avatars)
176 { 201 {
@@ -185,7 +210,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
185 210
186 sp.MoveToTarget(pos, noFly, landAtTarget); 211 sp.MoveToTarget(pos, noFly, landAtTarget);
187 sp.SetAlwaysRun = running; 212 sp.SetAlwaysRun = running;
188 213
189 return true; 214 return true;
190 } 215 }
191 } 216 }
@@ -258,9 +283,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
258 ScenePresence sp; 283 ScenePresence sp;
259 if (scene.TryGetScenePresence(agentID, out sp)) 284 if (scene.TryGetScenePresence(agentID, out sp))
260 { 285 {
261 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); 286 sp.HandleAgentRequestSit(m_avatars[agentID], agentID,
262 // sp.HandleAgentSit(m_avatars[agentID], agentID); 287 partID, Vector3.Zero);
263 288 //sp.HandleAgentSit(m_avatars[agentID], agentID);
289
264 return true; 290 return true;
265 } 291 }
266 } 292 }
@@ -269,7 +295,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
269 return false; 295 return false;
270 } 296 }
271 297
272 public bool Whisper(UUID agentID, Scene scene, string text, int channel) 298 public bool Whisper(UUID agentID, Scene scene, string text,
299 int channel)
273 { 300 {
274 lock (m_avatars) 301 lock (m_avatars)
275 { 302 {
@@ -344,7 +371,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
344 NPCAvatar av; 371 NPCAvatar av;
345 if (m_avatars.TryGetValue(agentID, out av)) 372 if (m_avatars.TryGetValue(agentID, out av))
346 { 373 {
347// m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); 374 /*
375 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
376 agentID, av.Name);
377 */
348 scene.RemoveClient(agentID, false); 378 scene.RemoveClient(agentID, false);
349 m_avatars.Remove(agentID); 379 m_avatars.Remove(agentID);
350 380
@@ -352,8 +382,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
352 return true; 382 return true;
353 } 383 }
354 } 384 }
355 385 /*
356// m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); 386 m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove",
387 agentID);
388 */
357 return false; 389 return false;
358 } 390 }
359 391
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 9179966..52ed846 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -117,6 +117,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
117 Assert.That(npc, Is.Not.Null); 117 Assert.That(npc, Is.Not.Null);
118 Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId)); 118 Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
119 Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname))); 119 Assert.That(m_umMod.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
120
121 IClientAPI client;
122 Assert.That(m_scene.TryGetClient(npcId, out client), Is.True);
123
124 // Have to account for both SP and NPC.
125 Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(2));
120 } 126 }
121 127
122 [Test] 128 [Test]
@@ -136,6 +142,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
136 ScenePresence deletedNpc = m_scene.GetScenePresence(npcId); 142 ScenePresence deletedNpc = m_scene.GetScenePresence(npcId);
137 143
138 Assert.That(deletedNpc, Is.Null); 144 Assert.That(deletedNpc, Is.Null);
145 IClientAPI client;
146 Assert.That(m_scene.TryGetClient(npcId, out client), Is.False);
147
148 // Have to account for SP still present.
149 Assert.That(m_scene.AuthenticateHandler.GetAgentCircuits().Count, Is.EqualTo(1));
139 } 150 }
140 151
141 [Test] 152 [Test]