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.cs75
1 files changed, 35 insertions, 40 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 7d46d92..8c9c006 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -143,10 +143,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, 143 npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0,
144 int.MaxValue); 144 int.MaxValue);
145 145
146 m_log.DebugFormat( 146// m_log.DebugFormat(
147 "[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}",
148 firstname, lastname, npcAvatar.AgentId, owner, 148// firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName);
149 senseAsAgent, position, scene.RegionInfo.RegionName);
150 149
151 AgentCircuitData acd = new AgentCircuitData(); 150 AgentCircuitData acd = new AgentCircuitData();
152 acd.AgentID = npcAvatar.AgentId; 151 acd.AgentID = npcAvatar.AgentId;
@@ -169,36 +168,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC
169 } 168 }
170 */ 169 */
171 170
172 lock (m_avatars) 171 ManualResetEvent ev = new ManualResetEvent(false);
173 {
174 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode,
175 acd);
176 scene.AddNewClient(npcAvatar, PresenceType.Npc);
177 172
178 ScenePresence sp; 173 Util.FireAndForget(delegate(object x) {
179 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) 174 lock (m_avatars)
180 { 175 {
181 /* 176 scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd);
182 m_log.DebugFormat( 177 scene.AddNewClient(npcAvatar, PresenceType.Npc);
183 "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}",
184 sp.Name, sp.UUID);
185 */
186
187 sp.CompleteMovement(npcAvatar, false);
188 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
189 m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}",
190 npcAvatar.AgentId, sp.Name);
191 178
192 return npcAvatar.AgentId; 179 ScenePresence sp;
193 } 180 if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp))
194 else 181 {
195 { 182 sp.CompleteMovement(npcAvatar, false);
196 m_log.WarnFormat( 183 m_avatars.Add(npcAvatar.AgentId, npcAvatar);
197 "[NPC MODULE]: Could not find scene presence for NPC {0} {1}", 184// m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name);
198 sp.Name, sp.UUID); 185 }
199 return UUID.Zero;
200 } 186 }
201 } 187 ev.Set();
188 });
189
190 ev.WaitOne();
191
192// m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId);
193
194 return npcAvatar.AgentId;
202 } 195 }
203 196
204 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, 197 public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos,
@@ -211,10 +204,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC
211 ScenePresence sp; 204 ScenePresence sp;
212 if (scene.TryGetScenePresence(agentID, out sp)) 205 if (scene.TryGetScenePresence(agentID, out sp))
213 { 206 {
214 m_log.DebugFormat( 207// m_log.DebugFormat(
215 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 208// "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
216 sp.Name, pos, scene.RegionInfo.RegionName, 209// sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
217 noFly, landAtTarget);
218 210
219 sp.MoveToTarget(pos, noFly, landAtTarget); 211 sp.MoveToTarget(pos, noFly, landAtTarget);
220 sp.SetAlwaysRun = running; 212 sp.SetAlwaysRun = running;
@@ -385,10 +377,8 @@ namespace OpenSim.Region.OptionalModules.World.NPC
385 */ 377 */
386 scene.RemoveClient(agentID, false); 378 scene.RemoveClient(agentID, false);
387 m_avatars.Remove(agentID); 379 m_avatars.Remove(agentID);
388 /* 380
389 m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", 381// m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name);
390 agentID, av.Name);
391 */
392 return true; 382 return true;
393 } 383 }
394 } 384 }
@@ -405,9 +395,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC
405 { 395 {
406 NPCAvatar av; 396 NPCAvatar av;
407 if (m_avatars.TryGetValue(npcID, out av)) 397 if (m_avatars.TryGetValue(npcID, out av))
398 {
399 if (npcID == callerID)
400 return true;
408 return CheckPermissions(av, callerID); 401 return CheckPermissions(av, callerID);
402 }
409 else 403 else
404 {
410 return false; 405 return false;
406 }
411 } 407 }
412 } 408 }
413 409
@@ -419,8 +415,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
419 /// <returns>true if they do, false if they don't.</returns> 415 /// <returns>true if they do, false if they don't.</returns>
420 private bool CheckPermissions(NPCAvatar av, UUID callerID) 416 private bool CheckPermissions(NPCAvatar av, UUID callerID)
421 { 417 {
422 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || 418 return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID || av.AgentId == callerID;
423 av.OwnerID == callerID;
424 } 419 }
425 } 420 }
426} 421}