public override void RemoveClient(UUID agentID)
{
CheckHeartbeat();
bool childagentYN = false;
ScenePresence avatar = GetScenePresence(agentID);
if (avatar != null)
{
childagentYN = avatar.IsChildAgent;
if (avatar.ParentID != 0)
{
avatar.StandUp();
}
try
{
m_log.DebugFormat(
"[SCENE]: Removing {0} agent {1} from region {2}",
(childagentYN ? "child" : "root"), agentID, RegionInfo.RegionName);
m_sceneGraph.removeUserCount(!childagentYN);
CapsModule.RemoveCapsHandler(agentID);
// REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
// this method is doing is HORRIBLE!!!
avatar.Scene.NeedSceneCacheClear(avatar.UUID);
if (!avatar.IsChildAgent)
{
//List<ulong> childknownRegions = new List<ulong>();
//List<ulong> ckn = avatar.KnownChildRegionHandles;
//for (int i = 0; i < ckn.Count; i++)
//{
// childknownRegions.Add(ckn[i]);
//}
List<ulong> regions = new List<ulong>(avatar.KnownChildRegionHandles);
regions.Remove(RegionInfo.RegionHandle);
m_sceneGridService.SendCloseChildAgentConnections(agentID, regions);
}
m_eventManager.TriggerClientClosed(agentID, this);
}
catch (NullReferenceException)
{
// We don't know which count to remove it from
// Avatar is already disposed :/
}
m_eventManager.TriggerOnRemovePresence(agentID);
ForEachClient(
delegate(IClientAPI client)
{
//We can safely ignore null reference exceptions. It means the avatar is dead and cleaned up anyway
try { client.SendKillObject(avatar.RegionHandle, avatar.LocalId); }
catch (NullReferenceException) { }
});
IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
if (agentTransactions != null)
{
agentTransactions.RemoveAgentAssetTransactions(agentID);
}
// Remove the avatar from the scene
m_sceneGraph.RemoveScenePresence(agentID);
m_clientManager.Remove(agentID);
try
{
avatar.Close();
}
catch (NullReferenceException)
{
//We can safely ignore null reference exceptions. It means the avatar are dead and cleaned up anyway.
}
catch (Exception e)
{
m_log.Error("[SCENE] Scene.cs:RemoveClient exception: " + e.ToString());
}
m_authenticateHandler.RemoveCircuit(avatar.ControllingClient.CircuitCode);
CleanDroppedAttachments();
//m_log.InfoFormat("[SCENE] Memory pre GC {0}", System.GC.GetTotalMemory(false));
//m_log.InfoFormat("[SCENE] Memory post GC {0}", System.GC.GetTotalMemory(true));
}
}