aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs160
1 files changed, 102 insertions, 58 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 3f25bcf..7d46d92 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,34 +118,35 @@ 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}",
129 firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName); 148 firstname, lastname, npcAvatar.AgentId, owner,
149 senseAsAgent, position, scene.RegionInfo.RegionName);
130 150
131 AgentCircuitData acd = new AgentCircuitData(); 151 AgentCircuitData acd = new AgentCircuitData();
132 acd.AgentID = npcAvatar.AgentId; 152 acd.AgentID = npcAvatar.AgentId;
@@ -134,42 +154,55 @@ namespace OpenSim.Region.OptionalModules.World.NPC
134 acd.lastname = lastname; 154 acd.lastname = lastname;
135 acd.ServiceURLs = new Dictionary<string, object>(); 155 acd.ServiceURLs = new Dictionary<string, object>();
136 156
137 AvatarAppearance npcAppearance = new AvatarAppearance(appearance, true); 157 AvatarAppearance npcAppearance = new AvatarAppearance(appearance,
158 true);
138 acd.Appearance = npcAppearance; 159 acd.Appearance = npcAppearance;
139 160
140// for (int i = 0; i < acd.Appearance.Texture.FaceTextures.Length; i++) 161 /*
141// { 162 for (int i = 0;
142// m_log.DebugFormat( 163 i < acd.Appearance.Texture.FaceTextures.Length; i++)
143// "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}", 164 {
144// acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); 165 m_log.DebugFormat(
145// } 166 "[NPC MODULE]: NPC avatar {0} has texture id {1} : {2}",
167 acd.AgentID, i,
168 acd.Appearance.Texture.FaceTextures[i]);
169 }
170 */
146 171
147 lock (m_avatars) 172 lock (m_avatars)
148 { 173 {
149 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); 174 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
175 acd);
150 scene.AddNewClient(npcAvatar, PresenceType.Npc); 176 scene.AddNewClient(npcAvatar, PresenceType.Npc);
151 177
152 ScenePresence sp; 178 ScenePresence sp;
153 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 179 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
154 { 180 {
155// m_log.DebugFormat( 181 /*
156// "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); 182 m_log.DebugFormat(
183 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
184 sp.Name, sp.UUID);
185 */
157 186
158 sp.CompleteMovement(npcAvatar, false); 187 sp.CompleteMovement(npcAvatar, false);
159 m_avatars.Add(npcAvatar.AgentId, npcAvatar); 188 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
160 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); 189 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}",
190 npcAvatar.AgentId, sp.Name);
161 191
162 return npcAvatar.AgentId; 192 return npcAvatar.AgentId;
163 } 193 }
164 else 194 else
165 { 195 {
166 m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); 196 m_log.WarnFormat(
197 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}",
198 sp.Name, sp.UUID);
167 return UUID.Zero; 199 return UUID.Zero;
168 } 200 }
169 } 201 }
170 } 202 }
171 203
172 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) 204 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
205 bool noFly, bool landAtTarget, bool running)
173 { 206 {
174 lock (m_avatars) 207 lock (m_avatars)
175 { 208 {
@@ -179,12 +212,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
179 if (scene.TryGetScenePresence(agentID, out sp)) 212 if (scene.TryGetScenePresence(agentID, out sp))
180 { 213 {
181 m_log.DebugFormat( 214 m_log.DebugFormat(
182 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 215 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
183 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); 216 sp.Name, pos, scene.RegionInfo.RegionName,
217 noFly, landAtTarget);
184 218
185 sp.MoveToTarget(pos, noFly, landAtTarget); 219 sp.MoveToTarget(pos, noFly, landAtTarget);
186 sp.SetAlwaysRun = running; 220 sp.SetAlwaysRun = running;
187 221
188 return true; 222 return true;
189 } 223 }
190 } 224 }
@@ -257,9 +291,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC
257 ScenePresence sp; 291 ScenePresence sp;
258 if (scene.TryGetScenePresence(agentID, out sp)) 292 if (scene.TryGetScenePresence(agentID, out sp))
259 { 293 {
260 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); 294 sp.HandleAgentRequestSit(m_avatars[agentID], agentID,
261 // sp.HandleAgentSit(m_avatars[agentID], agentID); 295 partID, Vector3.Zero);
262 296 //sp.HandleAgentSit(m_avatars[agentID], agentID);
297
263 return true; 298 return true;
264 } 299 }
265 } 300 }
@@ -268,7 +303,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
268 return false; 303 return false;
269 } 304 }
270 305
271 public bool Whisper(UUID agentID, Scene scene, string text, int channel) 306 public bool Whisper(UUID agentID, Scene scene, string text,
307 int channel)
272 { 308 {
273 lock (m_avatars) 309 lock (m_avatars)
274 { 310 {
@@ -343,16 +379,23 @@ namespace OpenSim.Region.OptionalModules.World.NPC
343 NPCAvatar av; 379 NPCAvatar av;
344 if (m_avatars.TryGetValue(agentID, out av)) 380 if (m_avatars.TryGetValue(agentID, out av))
345 { 381 {
346// m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); 382 /*
383 m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove",
384 agentID, av.Name);
385 */
347 scene.RemoveClient(agentID, false); 386 scene.RemoveClient(agentID, false);
348 m_avatars.Remove(agentID); 387 m_avatars.Remove(agentID);
349 388 /*
350 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); 389 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}",
390 agentID, av.Name);
391 */
351 return true; 392 return true;
352 } 393 }
353 } 394 }
354 395 /*
355// m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", agentID); 396 m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove",
397 agentID);
398 */
356 return false; 399 return false;
357 } 400 }
358 401
@@ -376,7 +419,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
376 /// <returns>true if they do, false if they don't.</returns> 419 /// <returns>true if they do, false if they don't.</returns>
377 private bool CheckPermissions(NPCAvatar av, UUID callerID) 420 private bool CheckPermissions(NPCAvatar av, UUID callerID)
378 { 421 {
379 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; 422 return callerID == UUID.Zero || av.OwnerID == UUID.Zero ||
423 av.OwnerID == callerID;
380 } 424 }
381 } 425 }
382} 426}