From 0b1726b524934c2020aaf2b1f130219fb87003fd Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Mon, 26 Oct 2009 16:48:43 -0700 Subject: Removing the ClientManager reference from IScene and hiding it entirely inside Scene as an implementation detail. This will reduce programming error and make it easier to refactor the avatar vs client vs presence mess later on --- OpenSim/Framework/IScene.cs | 1 - OpenSim/Region/Application/OpenSim.cs | 4 ++-- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 14 ++++++------ OpenSim/Region/Framework/Scenes/Scene.cs | 25 +++++++++++++++++----- OpenSim/Region/Framework/Scenes/SceneBase.cs | 7 +----- 5 files changed, 30 insertions(+), 21 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/IScene.cs b/OpenSim/Framework/IScene.cs index f34027d..8067052 100644 --- a/OpenSim/Framework/IScene.cs +++ b/OpenSim/Framework/IScene.cs @@ -62,7 +62,6 @@ namespace OpenSim.Framework RegionInfo RegionInfo { get; } RegionStatus RegionStatus { get; set; } - ClientManager ClientManager { get; } IConfigSource Config { get; } float TimeDilation { get; } diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs index 0366d94..b448182 100644 --- a/OpenSim/Region/Application/OpenSim.cs +++ b/OpenSim/Region/Application/OpenSim.cs @@ -970,12 +970,12 @@ namespace OpenSim m_sceneManager.ForEachScene( delegate(Scene scene) { - scene.ClientManager.ForEachSync( + scene.ForEachClient( delegate(IClientAPI client) { connections.AppendFormat("{0}: {1} ({2}) from {3} on circuit {4}\n", scene.RegionInfo.RegionName, client.Name, client.AgentId, client.RemoteEndPoint, client.CircuitCode); - } + }, false ); } ); diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index dee0a39..e3233da 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -583,10 +583,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Determine which agent this packet came from IClientAPI client; - if (!m_scene.ClientManager.TryGetValue(address, out client) || !(client is LLClientView)) + if (!m_scene.TryGetClient(address, out client) || !(client is LLClientView)) { - m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + - " in " + m_scene.RegionInfo.RegionName + ", currently tracking " + m_scene.ClientManager.Count + " clients"); + m_log.Debug("[LLUDPSERVER]: Received a " + packet.Type + " packet from an unrecognized source: " + address + " in " + m_scene.RegionInfo.RegionName); return; } @@ -764,8 +763,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP { // Create the LLUDPClient LLUDPClient udpClient = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); + IClientAPI existingClient; - if (!m_scene.ClientManager.ContainsKey(agentID)) + if (!m_scene.TryGetClient(agentID, out existingClient)) { // Create the LLClientView LLClientView client = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); @@ -785,7 +785,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { // Remove this client from the scene IClientAPI client; - if (m_scene.ClientManager.TryGetValue(udpClient.AgentID, out client)) + if (m_scene.TryGetClient(udpClient.AgentID, out client)) client.Close(); } @@ -877,7 +877,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Handle outgoing packets, resends, acknowledgements, and pings for each // client. m_packetSent will be set to true if a packet is sent - m_scene.ClientManager.ForEachSync(clientPacketHandler); + m_scene.ForEachClient(clientPacketHandler, false); // If nothing was sent, sleep for the minimum amount of time before a // token bucket could get more tokens @@ -942,7 +942,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP } // Make sure this client is still alive - if (m_scene.ClientManager.TryGetValue(udpClient.AgentID, out client)) + if (m_scene.TryGetClient(udpClient.AgentID, out client)) { try { diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 91367db..7eafef7 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -2482,7 +2482,7 @@ namespace OpenSim.Region.Framework.Scenes /// public override void AddNewClient(IClientAPI client) { - ClientManager.Add(client); + m_clientManager.Add(client); CheckHeartbeat(); SubscribeToClientEvents(client); @@ -3121,7 +3121,7 @@ namespace OpenSim.Region.Framework.Scenes // Remove the avatar from the scene m_sceneGraph.RemoveScenePresence(agentID); - ClientManager.Remove(agentID); + m_clientManager.Remove(agentID); try { @@ -4256,10 +4256,25 @@ namespace OpenSim.Region.Framework.Scenes public void ForEachClient(Action action) { - if (m_useAsyncWhenPossible) - ClientManager.ForEach(action); + ForEachClient(action, m_useAsyncWhenPossible); + } + + public void ForEachClient(Action action, bool doAsynchronous) + { + if (doAsynchronous) + m_clientManager.ForEach(action); else - ClientManager.ForEachSync(action); + m_clientManager.ForEachSync(action); + } + + public bool TryGetClient(UUID avatarID, out IClientAPI client) + { + return m_clientManager.TryGetValue(avatarID, out client); + } + + public bool TryGetClient(System.Net.IPEndPoint remoteEndPoint, out IClientAPI client) + { + return m_clientManager.TryGetValue(remoteEndPoint, out client); } public void ForEachSOG(Action action) diff --git a/OpenSim/Region/Framework/Scenes/SceneBase.cs b/OpenSim/Region/Framework/Scenes/SceneBase.cs index cf5c3c8..82731d1 100644 --- a/OpenSim/Region/Framework/Scenes/SceneBase.cs +++ b/OpenSim/Region/Framework/Scenes/SceneBase.cs @@ -102,12 +102,7 @@ namespace OpenSim.Region.Framework.Scenes private readonly Mutex _primAllocateMutex = new Mutex(false); - private readonly ClientManager m_clientManager = new ClientManager(); - - public ClientManager ClientManager - { - get { return m_clientManager; } - } + protected readonly ClientManager m_clientManager = new ClientManager(); public float TimeDilation { -- cgit v1.1