refactor: rename Scene.IncomingCloseAgent() to CloseAgent() in order to make it clear that all non-clientstack callers should be using this rather than RemoveClient() in order to step through the ScenePresence state machine properly.

Adds IScene.CloseAgent() to replace RemoveClient()
0.7.6-extended
Justin Clark-Casey (justincc) 2013-09-27 19:14:21 +01:00
parent 753cc93af5
commit e6c0267def
16 changed files with 43 additions and 53 deletions

View File

@ -86,7 +86,7 @@ namespace OpenSim.Framework
event restart OnRestart; event restart OnRestart;
/// <summary> /// <summary>
/// Add a new client and create a presence for it. All clients except initial login clients will starts off as a child agent /// Add a new agent. All agents except initial login clients will starts off as a child agent
/// - the later agent crossing will promote it to a root agent. /// - the later agent crossing will promote it to a root agent.
/// </summary> /// </summary>
/// <param name="client"></param> /// <param name="client"></param>
@ -96,14 +96,16 @@ namespace OpenSim.Framework
ISceneAgent AddNewClient(IClientAPI client, PresenceType type); ISceneAgent AddNewClient(IClientAPI client, PresenceType type);
/// <summary> /// <summary>
/// Remove the given client from the scene. /// Tell a single agent to disconnect from the region.
/// </summary> /// </summary>
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <param name="closeChildAgents">Close the neighbour child agents associated with this client.</param> /// <param name="force">
void RemoveClient(UUID agentID, bool closeChildAgents); /// Force the agent to close even if it might be in the middle of some other operation. You do not want to
/// force unless you are absolutely sure that the agent is dead and a normal close is not working.
/// </param>
bool CloseAgent(UUID agentID, bool force);
void Restart(); void Restart();
//RegionInfo OtherRegionUp(RegionInfo thisRegion);
string GetSimulatorVersion(); string GetSimulatorVersion();

View File

@ -452,7 +452,7 @@ namespace OpenSim
else else
presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n"); presence.ControllingClient.Kick("\nThe OpenSim manager kicked you out.\n");
presence.Scene.IncomingCloseAgent(presence.UUID, force); presence.Scene.CloseAgent(presence.UUID, force);
break; break;
} }
} }

View File

@ -96,7 +96,7 @@ namespace OpenSim.Region.ClientStack.Linden.Tests
UUID spId = TestHelpers.ParseTail(0x1); UUID spId = TestHelpers.ParseTail(0x1);
SceneHelpers.AddScenePresence(m_scene, spId); SceneHelpers.AddScenePresence(m_scene, spId);
m_scene.IncomingCloseAgent(spId, false); m_scene.CloseAgent(spId, false);
// TODO: Add more assertions for the other aspects of event queues // TODO: Add more assertions for the other aspects of event queues
Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0)); Assert.That(MainServer.Instance.GetPollServiceHandlerKeys().Count, Is.EqualTo(0));

View File

@ -1893,7 +1893,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
client.Kick("Simulator logged you out due to connection timeout."); client.Kick("Simulator logged you out due to connection timeout.");
} }
m_scene.IncomingCloseAgent(client.AgentId, true); m_scene.CloseAgent(client.AgentId, true);
} }
private void IncomingPacketHandler() private void IncomingPacketHandler()
@ -2234,7 +2234,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (!client.IsLoggingOut) if (!client.IsLoggingOut)
{ {
client.IsLoggingOut = true; client.IsLoggingOut = true;
m_scene.IncomingCloseAgent(client.AgentId, false); m_scene.CloseAgent(client.AgentId, false);
} }
} }
} }

View File

@ -60,9 +60,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
return null; return null;
} }
public override void RemoveClient(UUID agentID, bool someReason) {} public override bool CloseAgent(UUID agentID, bool force) { return true; }
// public override void CloseAllAgents(uint circuitcode) {}
public override bool CheckClient(UUID clientId, IPEndPoint endPoint) { return true; } public override bool CheckClient(UUID clientId, IPEndPoint endPoint) { return true; }
public override void OtherRegionUp(GridRegion otherRegion) { } public override void OtherRegionUp(GridRegion otherRegion) { }
public override bool TryGetScenePresence(UUID uuid, out ScenePresence sp) { sp = null; return false; } public override bool TryGetScenePresence(UUID uuid, out ScenePresence sp) { sp = null; return false; }

View File

@ -719,7 +719,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments.Tests
SceneObjectGroup rezzedAtt = presence.GetAttachments()[0]; SceneObjectGroup rezzedAtt = presence.GetAttachments()[0];
m_numberOfAttachEventsFired = 0; m_numberOfAttachEventsFired = 0;
scene.IncomingCloseAgent(presence.UUID, false); scene.CloseAgent(presence.UUID, false);
// Check that we can't retrieve this attachment from the scene. // Check that we can't retrieve this attachment from the scene.
Assert.That(scene.GetSceneObjectGroup(rezzedAtt.UUID), Is.Null); Assert.That(scene.GetSceneObjectGroup(rezzedAtt.UUID), Is.Null);

View File

@ -272,7 +272,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Gods
if (sp.IsChildAgent) if (sp.IsChildAgent)
return; return;
sp.ControllingClient.Kick(reason); sp.ControllingClient.Kick(reason);
sp.Scene.IncomingCloseAgent(sp.UUID, true); sp.Scene.CloseAgent(sp.UUID, true);
} }
private void OnIncomingInstantMessage(GridInstantMessage msg) private void OnIncomingInstantMessage(GridInstantMessage msg)

View File

@ -972,7 +972,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
{ {
if (!sp.Scene.IncomingPreCloseAgent(sp)) if (!sp.Scene.IncomingPreCloseClient(sp))
return; return;
// We need to delay here because Imprudence viewers, unlike v1 or v3, have a short (<200ms, <500ms) delay before // We need to delay here because Imprudence viewers, unlike v1 or v3, have a short (<200ms, <500ms) delay before
@ -983,7 +983,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// an agent cannot teleport back to this region if it has teleported away. // an agent cannot teleport back to this region if it has teleported away.
Thread.Sleep(2000); Thread.Sleep(2000);
sp.Scene.IncomingCloseAgent(sp.UUID, false); sp.Scene.CloseAgent(sp.UUID, false);
} }
else else
{ {
@ -1137,7 +1137,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
// Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone // Finally, let's close this previously-known-as-root agent, when the jump is outside the view zone
if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg)) if (NeedsClosing(sp.DrawDistance, oldRegionX, newRegionX, oldRegionY, newRegionY, reg))
{ {
if (!sp.Scene.IncomingPreCloseAgent(sp)) if (!sp.Scene.IncomingPreCloseClient(sp))
return; return;
// RED ALERT!!!! // RED ALERT!!!!
@ -1154,7 +1154,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
m_log.DebugFormat( m_log.DebugFormat(
"[ENTITY TRANSFER MODULE]: Closing agent {0} in {1} after teleport", sp.Name, Scene.Name); "[ENTITY TRANSFER MODULE]: Closing agent {0} in {1} after teleport", sp.Name, Scene.Name);
sp.Scene.IncomingCloseAgent(sp.UUID, false); sp.Scene.CloseAgent(sp.UUID, false);
} }
else else
{ {

View File

@ -311,7 +311,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
// "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate", // "[LOCAL SIMULATION CONNECTOR]: Found region {0} {1} to send AgentUpdate",
// s.RegionInfo.RegionName, destination.RegionHandle); // s.RegionInfo.RegionName, destination.RegionHandle);
m_scenes[destination.RegionID].IncomingCloseAgent(id, false, auth_token); m_scenes[destination.RegionID].CloseAgent(id, false, auth_token);
return true; return true;
} }

View File

@ -562,7 +562,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
if (!Scene.TeleportClientHome(user, s.ControllingClient)) if (!Scene.TeleportClientHome(user, s.ControllingClient))
{ {
s.ControllingClient.Kick("Your access to the region was revoked and TP home failed - you have been logged out."); s.ControllingClient.Kick("Your access to the region was revoked and TP home failed - you have been logged out.");
Scene.IncomingCloseAgent(s.UUID, false); Scene.CloseAgent(s.UUID, false);
} }
} }
} }
@ -797,7 +797,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
if (!Scene.TeleportClientHome(prey, s.ControllingClient)) if (!Scene.TeleportClientHome(prey, s.ControllingClient))
{ {
s.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out."); s.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out.");
Scene.IncomingCloseAgent(s.UUID, false); Scene.CloseAgent(s.UUID, false);
} }
} }
} }
@ -820,7 +820,7 @@ namespace OpenSim.Region.CoreModules.World.Estate
if (!Scene.TeleportClientHome(p.UUID, p.ControllingClient)) if (!Scene.TeleportClientHome(p.UUID, p.ControllingClient))
{ {
p.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out."); p.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out.");
Scene.IncomingCloseAgent(p.UUID, false); Scene.CloseAgent(p.UUID, false);
} }
} }
} }

View File

@ -1313,7 +1313,7 @@ namespace OpenSim.Region.Framework.Scenes
Thread.Sleep(500); Thread.Sleep(500);
// Stop all client threads. // Stop all client threads.
ForEachScenePresence(delegate(ScenePresence avatar) { IncomingCloseAgent(avatar.UUID, false); }); ForEachScenePresence(delegate(ScenePresence avatar) { CloseAgent(avatar.UUID, false); });
m_log.Debug("[SCENE]: Persisting changed objects"); m_log.Debug("[SCENE]: Persisting changed objects");
EventManager.TriggerSceneShuttingDown(this); EventManager.TriggerSceneShuttingDown(this);
@ -2976,7 +2976,7 @@ namespace OpenSim.Region.Framework.Scenes
{ {
PresenceService.LogoutAgent(sp.ControllingClient.SessionId); PresenceService.LogoutAgent(sp.ControllingClient.SessionId);
IncomingCloseAgent(sp.UUID, false); CloseAgent(sp.UUID, false);
} }
else else
{ {
@ -3398,7 +3398,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name='closeChildAgents'> /// <param name='closeChildAgents'>
/// Close the neighbour child agents associated with this client. /// Close the neighbour child agents associated with this client.
/// </param> /// </param>
public override void RemoveClient(UUID agentID, bool closeChildAgents) public void RemoveClient(UUID agentID, bool closeChildAgents)
{ {
AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID); AgentCircuitData acd = m_authenticateHandler.GetAgentCircuitData(agentID);
@ -3783,7 +3783,7 @@ namespace OpenSim.Region.Framework.Scenes
sp.Name, sp.UUID, RegionInfo.RegionName); sp.Name, sp.UUID, RegionInfo.RegionName);
if (sp.ControllingClient != null) if (sp.ControllingClient != null)
IncomingCloseAgent(sp.UUID, true); CloseAgent(sp.UUID, true);
sp = null; sp = null;
} }
@ -4424,7 +4424,7 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="force"></param> /// <param name="force"></param>
/// <param name="auth_token"></param> /// <param name="auth_token"></param>
/// <returns></returns> /// <returns></returns>
public bool IncomingCloseAgent(UUID agentID, bool force, string auth_token) public bool CloseAgent(UUID agentID, bool force, string auth_token)
{ {
//m_log.DebugFormat("[SCENE]: Processing incoming close agent {0} in region {1} with auth_token {2}", agentID, RegionInfo.RegionName, auth_token); //m_log.DebugFormat("[SCENE]: Processing incoming close agent {0} in region {1} with auth_token {2}", agentID, RegionInfo.RegionName, auth_token);
@ -4442,7 +4442,7 @@ namespace OpenSim.Region.Framework.Scenes
if (acd.SessionID.ToString() == auth_token) if (acd.SessionID.ToString() == auth_token)
{ {
return IncomingCloseAgent(agentID, force); return CloseAgent(agentID, force);
} }
else else
{ {
@ -4455,16 +4455,16 @@ namespace OpenSim.Region.Framework.Scenes
} }
/// <summary> /// <summary>
/// Tell a single agent to prepare to close. /// Tell a single client to prepare to close.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This should only be called if we may close the agent but there will be some delay in so doing. Meant for /// This should only be called if we may close the client but there will be some delay in so doing. Meant for
/// internal use - other callers should almost certainly called IncomingCloseAgent(). /// internal use - other callers should almost certainly called CloseClient().
/// </remarks> /// </remarks>
/// <param name="sp"></param> /// <param name="sp"></param>
/// <returns>true if pre-close state notification was successful. false if the agent /// <returns>true if pre-close state notification was successful. false if the agent
/// was not in a state where it could transition to pre-close.</returns> /// was not in a state where it could transition to pre-close.</returns>
public bool IncomingPreCloseAgent(ScenePresence sp) public bool IncomingPreCloseClient(ScenePresence sp)
{ {
lock (m_removeClientLock) lock (m_removeClientLock)
{ {
@ -4506,7 +4506,7 @@ namespace OpenSim.Region.Framework.Scenes
/// Force the agent to close even if it might be in the middle of some other operation. You do not want to /// Force the agent to close even if it might be in the middle of some other operation. You do not want to
/// force unless you are absolutely sure that the agent is dead and a normal close is not working. /// force unless you are absolutely sure that the agent is dead and a normal close is not working.
/// </param> /// </param>
public bool IncomingCloseAgent(UUID agentID, bool force) public override bool CloseAgent(UUID agentID, bool force)
{ {
ScenePresence sp; ScenePresence sp;
@ -4517,7 +4517,7 @@ namespace OpenSim.Region.Framework.Scenes
if (sp == null) if (sp == null)
{ {
m_log.DebugFormat( m_log.DebugFormat(
"[SCENE]: Called IncomingCloseAgent() with agent ID {0} but no such presence is in {1}", "[SCENE]: Called CloseClient() with agent ID {0} but no such presence is in {1}",
agentID, Name); agentID, Name);
return false; return false;
@ -4526,7 +4526,7 @@ namespace OpenSim.Region.Framework.Scenes
if (sp.LifecycleState != ScenePresenceState.Running && sp.LifecycleState != ScenePresenceState.PreRemove) if (sp.LifecycleState != ScenePresenceState.Running && sp.LifecycleState != ScenePresenceState.PreRemove)
{ {
m_log.DebugFormat( m_log.DebugFormat(
"[SCENE]: Called IncomingCloseAgent() for {0} in {1} but presence is already in state {2}", "[SCENE]: Called CloseClient() for {0} in {1} but presence is already in state {2}",
sp.Name, Name, sp.LifecycleState); sp.Name, Name, sp.LifecycleState);
return false; return false;

View File

@ -218,19 +218,7 @@ namespace OpenSim.Region.Framework.Scenes
public abstract ISceneAgent AddNewClient(IClientAPI client, PresenceType type); public abstract ISceneAgent AddNewClient(IClientAPI client, PresenceType type);
/// <summary> public abstract bool CloseAgent(UUID agentID, bool force);
/// Remove the given client from the scene.
/// </summary>
/// <remarks>
/// Only clientstack code should call this directly. All other code should call IncomingCloseAgent() instead
/// to properly operate the state machine and avoid race conditions with other close requests (such as directly
/// from viewers).
/// </remarks>
/// <param name='agentID'>ID of agent to close</param>
/// <param name='closeChildAgents'>
/// Close the neighbour child agents associated with this client.
/// </param>
public abstract void RemoveClient(UUID agentID, bool closeChildAgents);
public bool TryGetScenePresence(UUID agentID, out object scenePresence) public bool TryGetScenePresence(UUID agentID, out object scenePresence)
{ {

View File

@ -146,7 +146,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
} }
[Test] [Test]
public void TestCloseAgent() public void TestCloseClient()
{ {
TestHelpers.InMethod(); TestHelpers.InMethod();
// TestHelpers.EnableLogging(); // TestHelpers.EnableLogging();
@ -154,7 +154,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
TestScene scene = new SceneHelpers().SetupScene(); TestScene scene = new SceneHelpers().SetupScene();
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1)); ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
scene.IncomingCloseAgent(sp.UUID, false); scene.CloseAgent(sp.UUID, false);
Assert.That(scene.GetScenePresence(sp.UUID), Is.Null); Assert.That(scene.GetScenePresence(sp.UUID), Is.Null);
Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null); Assert.That(scene.AuthenticateHandler.GetAgentCircuitData(sp.UUID), Is.Null);

View File

@ -79,7 +79,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
// TODO: Need to add tests for other ICapabiltiesModule methods. // TODO: Need to add tests for other ICapabiltiesModule methods.
scene.IncomingCloseAgent(sp.UUID, false); scene.CloseAgent(sp.UUID, false);
Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null); Assert.That(capsMod.GetCapsForUser(spUuid), Is.Null);
// TODO: Need to add tests for other ICapabiltiesModule methods. // TODO: Need to add tests for other ICapabiltiesModule methods.

View File

@ -384,7 +384,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
agentID, av.Name); agentID, av.Name);
*/ */
scene.IncomingCloseAgent(agentID, false); scene.CloseAgent(agentID, false);
m_avatars.Remove(agentID); m_avatars.Remove(agentID);

View File

@ -2964,7 +2964,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
sp.ControllingClient.Kick(alert); sp.ControllingClient.Kick(alert);
// ...and close on our side // ...and close on our side
sp.Scene.IncomingCloseAgent(sp.UUID, false); sp.Scene.CloseAgent(sp.UUID, false);
} }
}); });
} }