diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index 3f25bcf..f16927c 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -124,9 +124,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
124 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); | 124 | NPCAvatar npcAvatar = new NPCAvatar(firstname, lastname, position, owner, senseAsAgent, scene); |
125 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); | 125 | npcAvatar.CircuitCode = (uint)Util.RandomClass.Next(0, int.MaxValue); |
126 | 126 | ||
127 | m_log.DebugFormat( | 127 | // m_log.DebugFormat( |
128 | "[NPC MODULE]: Creating NPC {0} {1} {2}, owner={3}, senseAsAgent={4} at {5} in {6}", | 128 | // "[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); | 129 | // firstname, lastname, npcAvatar.AgentId, owner, senseAsAgent, position, scene.RegionInfo.RegionName); |
130 | 130 | ||
131 | AgentCircuitData acd = new AgentCircuitData(); | 131 | AgentCircuitData acd = new AgentCircuitData(); |
132 | acd.AgentID = npcAvatar.AgentId; | 132 | acd.AgentID = npcAvatar.AgentId; |
@@ -144,29 +144,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
144 | // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); | 144 | // acd.AgentID, i, acd.Appearance.Texture.FaceTextures[i]); |
145 | // } | 145 | // } |
146 | 146 | ||
147 | lock (m_avatars) | 147 | ManualResetEvent ev = new ManualResetEvent(false); |
148 | { | ||
149 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); | ||
150 | scene.AddNewClient(npcAvatar, PresenceType.Npc); | ||
151 | 148 | ||
152 | ScenePresence sp; | 149 | Util.FireAndForget(delegate(object x) { |
153 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | 150 | lock (m_avatars) |
154 | { | 151 | { |
155 | // m_log.DebugFormat( | 152 | scene.AuthenticateHandler.AddNewCircuit(npcAvatar.CircuitCode, acd); |
156 | // "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); | 153 | scene.AddNewClient(npcAvatar, PresenceType.Npc); |
157 | |||
158 | sp.CompleteMovement(npcAvatar, false); | ||
159 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | ||
160 | m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); | ||
161 | 154 | ||
162 | return npcAvatar.AgentId; | 155 | ScenePresence sp; |
163 | } | 156 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) |
164 | else | 157 | { |
165 | { | 158 | sp.CompleteMovement(npcAvatar, false); |
166 | m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); | 159 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); |
167 | return UUID.Zero; | 160 | // m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); |
161 | } | ||
168 | } | 162 | } |
169 | } | 163 | ev.Set(); |
164 | }); | ||
165 | |||
166 | ev.WaitOne(); | ||
167 | |||
168 | // m_log.DebugFormat("[NPC MODULE]: Created NPC with id {0}", npcAvatar.AgentId); | ||
169 | |||
170 | return npcAvatar.AgentId; | ||
170 | } | 171 | } |
171 | 172 | ||
172 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) | 173 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) |
@@ -178,9 +179,9 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
178 | ScenePresence sp; | 179 | ScenePresence sp; |
179 | if (scene.TryGetScenePresence(agentID, out sp)) | 180 | if (scene.TryGetScenePresence(agentID, out sp)) |
180 | { | 181 | { |
181 | m_log.DebugFormat( | 182 | // m_log.DebugFormat( |
182 | "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", | 183 | // "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", |
183 | sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); | 184 | // sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); |
184 | 185 | ||
185 | sp.MoveToTarget(pos, noFly, landAtTarget); | 186 | sp.MoveToTarget(pos, noFly, landAtTarget); |
186 | sp.SetAlwaysRun = running; | 187 | sp.SetAlwaysRun = running; |
@@ -347,7 +348,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
347 | scene.RemoveClient(agentID, false); | 348 | scene.RemoveClient(agentID, false); |
348 | m_avatars.Remove(agentID); | 349 | m_avatars.Remove(agentID); |
349 | 350 | ||
350 | m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); | 351 | // m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); |
351 | return true; | 352 | return true; |
352 | } | 353 | } |
353 | } | 354 | } |
@@ -362,9 +363,15 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
362 | { | 363 | { |
363 | NPCAvatar av; | 364 | NPCAvatar av; |
364 | if (m_avatars.TryGetValue(npcID, out av)) | 365 | if (m_avatars.TryGetValue(npcID, out av)) |
366 | { | ||
367 | if (npcID == callerID) | ||
368 | return true; | ||
365 | return CheckPermissions(av, callerID); | 369 | return CheckPermissions(av, callerID); |
370 | } | ||
366 | else | 371 | else |
372 | { | ||
367 | return false; | 373 | return false; |
374 | } | ||
368 | } | 375 | } |
369 | } | 376 | } |
370 | 377 | ||
@@ -376,7 +383,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
376 | /// <returns>true if they do, false if they don't.</returns> | 383 | /// <returns>true if they do, false if they don't.</returns> |
377 | private bool CheckPermissions(NPCAvatar av, UUID callerID) | 384 | private bool CheckPermissions(NPCAvatar av, UUID callerID) |
378 | { | 385 | { |
379 | return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID; | 386 | return callerID == UUID.Zero || av.OwnerID == UUID.Zero || av.OwnerID == callerID || av.AgentId == callerID; |
380 | } | 387 | } |
381 | } | 388 | } |
382 | } | 389 | } |