From c893761319f7e61d13b2d2301180d0f227fde1a9 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 13 Oct 2009 12:50:59 -0700 Subject: * Unregister event handlers in LLUDPServer when a client logs out and disconnects * Move ViewerEffect handling to Scene.PacketHandlers * Removing the unused CloseAllAgents function * Trimming ClientManager down. This class needs to be reworked to keep LLUDP circuit codes from intruding into the abstract OpenSim core code --- OpenSim/Framework/ClientManager.cs | 163 +++---------------------------------- 1 file changed, 13 insertions(+), 150 deletions(-) (limited to 'OpenSim/Framework/ClientManager.cs') diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs index 094a3ff..5ebbbc1 100644 --- a/OpenSim/Framework/ClientManager.cs +++ b/OpenSim/Framework/ClientManager.cs @@ -34,120 +34,33 @@ using OpenMetaverse.Packets; namespace OpenSim.Framework { - public delegate void ForEachClientDelegate(IClientAPI client); - public class ClientManager { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private Dictionary m_clients; - - public ClientManager() - { - m_clients = new Dictionary(); - } + private Dictionary m_clients = new Dictionary(); - public void ForEachClient(ForEachClientDelegate whatToDo) + public void Add(uint circuitCode, IClientAPI client) { - IClientAPI[] LocalClients; lock (m_clients) - { - LocalClients = new IClientAPI[m_clients.Count]; - m_clients.Values.CopyTo(LocalClients, 0); - } - - for (int i = 0; i < LocalClients.Length; i++) - { - try - { - whatToDo(LocalClients[i]); - } - catch (Exception e) - { - m_log.Warn("[CLIENT]: Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString()); - } - } + m_clients.Add(circuitCode, client); } - public void Remove(uint id) + public bool Remove(uint circuitCode) { lock (m_clients) - { - m_clients.Remove(id); - } - } - - public void Add(uint id, IClientAPI client) - { - lock (m_clients) - { - m_clients.Add(id, client); - } - } - - /// - /// Pass incoming packet to client. - /// - /// uint identifying the connection/client. - /// object containing the packet. - public void InPacket(uint circuitCode, object packet) - { - IClientAPI client; - bool tryGetRet = false; - - lock (m_clients) - tryGetRet = m_clients.TryGetValue(circuitCode, out client); - - if (tryGetRet) - { - client.InPacket(packet); - } + return m_clients.Remove(circuitCode); } - public void CloseAllAgents(uint circuitCode) + public bool TryGetClient(uint circuitCode, out IClientAPI user) { - IClientAPI client; - bool tryGetRet = false; lock (m_clients) - tryGetRet = m_clients.TryGetValue(circuitCode, out client); - if (tryGetRet) - { - CloseAllCircuits(client.AgentId); - } - } - - public void CloseAllCircuits(UUID agentId) - { - uint[] circuits = GetAllCircuits(agentId); - // We're using a for loop here so changes to the circuits don't cause it to completely fail. - - for (int i = 0; i < circuits.Length; i++) - { - IClientAPI client; - try - { - bool tryGetRet = false; - lock (m_clients) - tryGetRet = m_clients.TryGetValue(circuits[i], out client); - if (tryGetRet) - { - Remove(client.CircuitCode); - client.Close(false); - } - } - catch (Exception e) - { - m_log.Error(string.Format("[CLIENT]: Unable to shutdown circuit for: {0}\n Reason: {1}", agentId, e)); - } - } + return m_clients.TryGetValue(circuitCode, out user); } - // [Obsolete("Using Obsolete to drive development is invalid. Obsolete presumes that something new has already been created to replace this.")] - public uint[] GetAllCircuits(UUID agentId) + public void ForEachClient(Action action) { - List circuits = new List(); - // Wasteful, I know - IClientAPI[] LocalClients = new IClientAPI[0]; + IClientAPI[] LocalClients; lock (m_clients) { LocalClients = new IClientAPI[m_clients.Count]; @@ -156,65 +69,15 @@ namespace OpenSim.Framework for (int i = 0; i < LocalClients.Length; i++) { - if (LocalClients[i].AgentId == agentId) + try { - circuits.Add(LocalClients[i].CircuitCode); + action(LocalClients[i]); } - } - return circuits.ToArray(); - } - - public List GetAllCircuitCodes() - { - List circuits; - - lock (m_clients) - { - circuits = new List(m_clients.Keys); - } - - return circuits; - } - - public void ViewerEffectHandler(IClientAPI sender, List args) - { - // TODO: don't create new blocks if recycling an old packet - List effectBlock = new List(); - for (int i = 0; i < args.Count; i++) - { - ViewerEffectPacket.EffectBlock effect = new ViewerEffectPacket.EffectBlock(); - effect.AgentID = args[i].AgentID; - effect.Color = args[i].Color; - effect.Duration = args[i].Duration; - effect.ID = args[i].ID; - effect.Type = args[i].Type; - effect.TypeData = args[i].TypeData; - effectBlock.Add(effect); - } - ViewerEffectPacket.EffectBlock[] effectBlockArray = effectBlock.ToArray(); - - IClientAPI[] LocalClients; - lock (m_clients) - { - LocalClients = new IClientAPI[m_clients.Count]; - m_clients.Values.CopyTo(LocalClients, 0); - } - - for (int i = 0; i < LocalClients.Length; i++) - { - if (LocalClients[i].AgentId != sender.AgentId) + catch (Exception e) { - LocalClients[i].SendViewerEffect(effectBlockArray); + m_log.Warn("[CLIENT]: Unable to do ForEachClient for one of the clients" + "\n Reason: " + e.ToString()); } } } - - public bool TryGetClient(uint circuitId, out IClientAPI user) - { - lock (m_clients) - { - return m_clients.TryGetValue(circuitId, out user); - } - } } } -- cgit v1.1