aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-08-14 21:44:06 +0100
committerJustin Clark-Casey (justincc)2012-08-14 21:44:06 +0100
commitc42fe6c159d49535888937c3f219e028eb755efa (patch)
tree70f6932fe9ed33ec4ac09fe1deb5e34a712c7b03
parentPerform ownership transfer and permission propagation as well as needed (diff)
downloadopensim-SC-c42fe6c159d49535888937c3f219e028eb755efa.zip
opensim-SC-c42fe6c159d49535888937c3f219e028eb755efa.tar.gz
opensim-SC-c42fe6c159d49535888937c3f219e028eb755efa.tar.bz2
opensim-SC-c42fe6c159d49535888937c3f219e028eb755efa.tar.xz
Prevent race conditions when one thread removes an NPC SP before another thread has retreived it after checking whether the NPC exists.
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs64
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs25
2 files changed, 50 insertions, 39 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
index 1e85fb4..3f25bcf 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs
@@ -176,16 +176,17 @@ namespace OpenSim.Region.OptionalModules.World.NPC
176 if (m_avatars.ContainsKey(agentID)) 176 if (m_avatars.ContainsKey(agentID))
177 { 177 {
178 ScenePresence sp; 178 ScenePresence sp;
179 scene.TryGetScenePresence(agentID, out sp); 179 if (scene.TryGetScenePresence(agentID, out sp))
180 180 {
181 m_log.DebugFormat( 181 m_log.DebugFormat(
182 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}", 182 "[NPC MODULE]: Moving {0} to {1} in {2}, noFly {3}, landAtTarget {4}",
183 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); 183 sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget);
184 184
185 sp.MoveToTarget(pos, noFly, landAtTarget); 185 sp.MoveToTarget(pos, noFly, landAtTarget);
186 sp.SetAlwaysRun = running; 186 sp.SetAlwaysRun = running;
187 187
188 return true; 188 return true;
189 }
189 } 190 }
190 } 191 }
191 192
@@ -199,12 +200,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
199 if (m_avatars.ContainsKey(agentID)) 200 if (m_avatars.ContainsKey(agentID))
200 { 201 {
201 ScenePresence sp; 202 ScenePresence sp;
202 scene.TryGetScenePresence(agentID, out sp); 203 if (scene.TryGetScenePresence(agentID, out sp))
203 204 {
204 sp.Velocity = Vector3.Zero; 205 sp.Velocity = Vector3.Zero;
205 sp.ResetMoveToTarget(); 206 sp.ResetMoveToTarget();
206 207
207 return true; 208 return true;
209 }
208 } 210 }
209 } 211 }
210 212
@@ -222,9 +224,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
222 { 224 {
223 if (m_avatars.ContainsKey(agentID)) 225 if (m_avatars.ContainsKey(agentID))
224 { 226 {
225 ScenePresence sp;
226 scene.TryGetScenePresence(agentID, out sp);
227
228 m_avatars[agentID].Say(channel, text); 227 m_avatars[agentID].Say(channel, text);
229 228
230 return true; 229 return true;
@@ -240,9 +239,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
240 { 239 {
241 if (m_avatars.ContainsKey(agentID)) 240 if (m_avatars.ContainsKey(agentID))
242 { 241 {
243 ScenePresence sp;
244 scene.TryGetScenePresence(agentID, out sp);
245
246 m_avatars[agentID].Shout(channel, text); 242 m_avatars[agentID].Shout(channel, text);
247 243
248 return true; 244 return true;
@@ -259,11 +255,13 @@ namespace OpenSim.Region.OptionalModules.World.NPC
259 if (m_avatars.ContainsKey(agentID)) 255 if (m_avatars.ContainsKey(agentID))
260 { 256 {
261 ScenePresence sp; 257 ScenePresence sp;
262 scene.TryGetScenePresence(agentID, out sp); 258 if (scene.TryGetScenePresence(agentID, out sp))
263 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero); 259 {
264// sp.HandleAgentSit(m_avatars[agentID], agentID); 260 sp.HandleAgentRequestSit(m_avatars[agentID], agentID, partID, Vector3.Zero);
265 261 // sp.HandleAgentSit(m_avatars[agentID], agentID);
266 return true; 262
263 return true;
264 }
267 } 265 }
268 } 266 }
269 267
@@ -276,9 +274,6 @@ namespace OpenSim.Region.OptionalModules.World.NPC
276 { 274 {
277 if (m_avatars.ContainsKey(agentID)) 275 if (m_avatars.ContainsKey(agentID))
278 { 276 {
279 ScenePresence sp;
280 scene.TryGetScenePresence(agentID, out sp);
281
282 m_avatars[agentID].Whisper(channel, text); 277 m_avatars[agentID].Whisper(channel, text);
283 278
284 return true; 279 return true;
@@ -295,10 +290,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC
295 if (m_avatars.ContainsKey(agentID)) 290 if (m_avatars.ContainsKey(agentID))
296 { 291 {
297 ScenePresence sp; 292 ScenePresence sp;
298 scene.TryGetScenePresence(agentID, out sp); 293 if (scene.TryGetScenePresence(agentID, out sp))
299 sp.StandUp(); 294 {
295 sp.StandUp();
300 296
301 return true; 297 return true;
298 }
302 } 299 }
303 } 300 }
304 301
@@ -311,6 +308,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
311 { 308 {
312 if (m_avatars.ContainsKey(agentID)) 309 if (m_avatars.ContainsKey(agentID))
313 return m_avatars[agentID].Touch(objectID); 310 return m_avatars[agentID].Touch(objectID);
311
314 return false; 312 return false;
315 } 313 }
316 } 314 }
@@ -321,9 +319,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
321 { 319 {
322 NPCAvatar av; 320 NPCAvatar av;
323 if (m_avatars.TryGetValue(agentID, out av)) 321 if (m_avatars.TryGetValue(agentID, out av))
324 {
325 return av.OwnerID; 322 return av.OwnerID;
326 }
327 } 323 }
328 324
329 return UUID.Zero; 325 return UUID.Zero;
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index bcd1a6f..859ee93 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -2434,8 +2434,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2434 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) 2434 if (!npcModule.CheckPermissions(npcId, m_host.OwnerID))
2435 return new LSL_Vector(0, 0, 0); 2435 return new LSL_Vector(0, 0, 0);
2436 2436
2437 Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition; 2437 ScenePresence sp = World.GetScenePresence(npcId);
2438 return new LSL_Vector(pos.X, pos.Y, pos.Z); 2438
2439 if (sp != null)
2440 {
2441 Vector3 pos = sp.AbsolutePosition;
2442 return new LSL_Vector(pos.X, pos.Y, pos.Z);
2443 }
2439 } 2444 }
2440 2445
2441 return new LSL_Vector(0, 0, 0); 2446 return new LSL_Vector(0, 0, 0);
@@ -2503,9 +2508,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2503 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); 2508 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
2504 2509
2505 ScenePresence sp = World.GetScenePresence(npcId); 2510 ScenePresence sp = World.GetScenePresence(npcId);
2506 Quaternion rot = sp.Rotation;
2507 2511
2508 return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); 2512 if (sp != null)
2513 {
2514 Quaternion rot = sp.Rotation;
2515 return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W);
2516 }
2509 } 2517 }
2510 2518
2511 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); 2519 return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W);
@@ -2527,7 +2535,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2527 return; 2535 return;
2528 2536
2529 ScenePresence sp = World.GetScenePresence(npcId); 2537 ScenePresence sp = World.GetScenePresence(npcId);
2530 sp.Rotation = LSL_Api.Rot2Quaternion(rotation); 2538
2539 if (sp != null)
2540 sp.Rotation = LSL_Api.Rot2Quaternion(rotation);
2531 } 2541 }
2532 } 2542 }
2533 2543
@@ -2689,6 +2699,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2689 { 2699 {
2690 CheckThreatLevel(ThreatLevel.High, "osNpcTouch"); 2700 CheckThreatLevel(ThreatLevel.High, "osNpcTouch");
2691 m_host.AddScriptLPS(1); 2701 m_host.AddScriptLPS(1);
2702
2692 INPCModule module = World.RequestModuleInterface<INPCModule>(); 2703 INPCModule module = World.RequestModuleInterface<INPCModule>();
2693 int linkNum = link_num.value; 2704 int linkNum = link_num.value;
2694 if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS)) 2705 if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS))
@@ -2696,12 +2707,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2696 UUID npcId; 2707 UUID npcId;
2697 if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID)) 2708 if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID))
2698 return; 2709 return;
2710
2699 SceneObjectPart part = null; 2711 SceneObjectPart part = null;
2700 UUID objectId; 2712 UUID objectId;
2701 if (UUID.TryParse(LSL_String.ToString(object_key), out objectId)) 2713 if (UUID.TryParse(LSL_String.ToString(object_key), out objectId))
2702 part = World.GetSceneObjectPart(objectId); 2714 part = World.GetSceneObjectPart(objectId);
2715
2703 if (part == null) 2716 if (part == null)
2704 return; 2717 return;
2718
2705 if (linkNum != ScriptBaseClass.LINK_THIS) 2719 if (linkNum != ScriptBaseClass.LINK_THIS)
2706 { 2720 {
2707 if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT) 2721 if (linkNum == 0 || linkNum == ScriptBaseClass.LINK_ROOT)
@@ -2716,6 +2730,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2716 return; 2730 return;
2717 } 2731 }
2718 } 2732 }
2733
2719 module.Touch(npcId, part.UUID); 2734 module.Touch(npcId, part.UUID);
2720 } 2735 }
2721 } 2736 }