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