diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 84e705a91d..139dc3b3e4 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -119,6 +119,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP #region Properties + public LLUDPClient UDPClient { get { return m_udpClient; } } public UUID SecureSessionId { get { return m_secureSessionId; } } public IScene Scene { get { return m_scene; } } public UUID SessionId { get { return m_sessionId; } } @@ -504,7 +505,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP + "Any further actions taken will not be processed.\n" + "Please relog", true); - m_udpServer.SendPacket(m_agentId, packet, ThrottleOutPacketType.Unknown, false); + OutPacket(packet, ThrottleOutPacketType.Unknown); // There may be a better way to do this. Perhaps kick? Not sure this propogates notifications to // listeners yet, though. diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs index 06fa3e2e49..abf3882d69 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPClientCollection.cs @@ -40,14 +40,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP { #region IComparers - private sealed class UUIDComparer : IComparer - { - public int Compare(UUID x, UUID y) - { - return x.Guid.CompareTo(y.Guid); - } - } - private sealed class IPEndPointComparer : IComparer { public int Compare(IPEndPoint x, IPEndPoint y) @@ -60,91 +52,46 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion IComparers - private ImmutableMap m_dict1; - private ImmutableMap m_dict2; - private LLUDPClient[] m_array; + private ImmutableMap m_dict; public UDPClientCollection() { - m_dict1 = new ImmutableMap(new UUIDComparer()); - m_dict2 = new ImmutableMap(new IPEndPointComparer()); - m_array = new LLUDPClient[0]; + m_dict = new ImmutableMap(new IPEndPointComparer()); } - public void Add(UUID key1, IPEndPoint key2, LLUDPClient value) + public void Add(IPEndPoint key, LLUDPClient value) { - m_dict1 = m_dict1.Add(key1, value); - m_dict2 = m_dict2.Add(key2, value); - - // Copy the array by hand - LLUDPClient[] oldArray = m_array; - int oldLength = oldArray.Length; - LLUDPClient[] newArray = new LLUDPClient[oldLength + 1]; - - for (int i = 0; i < oldLength; i++) - newArray[i] = oldArray[i]; - newArray[oldLength] = value; - - m_array = newArray; + m_dict = m_dict.Add(key, value); } - public void Remove(UUID key1, IPEndPoint key2) + public void Remove(IPEndPoint key) { - m_dict1 = m_dict1.Delete(key1); - m_dict2 = m_dict2.Delete(key2); - - LLUDPClient[] oldArray = m_array; - int oldLength = oldArray.Length; - - // Copy the array by hand - - LLUDPClient[] newArray = new LLUDPClient[oldLength - 1]; - int j = 0; - - for (int i = 0; i < oldLength; i++) - { - if (oldArray[i].AgentID != key1) - newArray[j++] = oldArray[i]; - } - - m_array = newArray; + m_dict = m_dict.Delete(key); } public void Clear() { - m_dict1 = new ImmutableMap(new UUIDComparer()); - m_dict2 = new ImmutableMap(new IPEndPointComparer()); - m_array = new LLUDPClient[0]; + m_dict = new ImmutableMap(new IPEndPointComparer()); } public int Count { - get { return m_array.Length; } - } - - public bool ContainsKey(UUID key) - { - return m_dict1.ContainsKey(key); + get { return m_dict.Count; } } public bool ContainsKey(IPEndPoint key) { - return m_dict2.ContainsKey(key); - } - - public bool TryGetValue(UUID key, out LLUDPClient value) - { - return m_dict1.TryGetValue(key, out value); + return m_dict.ContainsKey(key); } public bool TryGetValue(IPEndPoint key, out LLUDPClient value) { - return m_dict2.TryGetValue(key, out value); + return m_dict.TryGetValue(key, out value); } public void ForEach(Action action) { - Parallel.ForEach(m_array, action); + Parallel.ForEach(m_dict.Values, action); } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 1e6927fadf..a6aa048d05 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -181,22 +181,14 @@ namespace OpenSim.Region.ClientStack.LindenUDP return x == m_location; } - public void RemoveClient(IClientAPI client) + public void RemoveClient(LLUDPClient udpClient) { - m_scene.ClientManager.Remove(client.CircuitCode); - client.Close(false); + m_log.Debug("[LLUDPSERVER]: Removing LLUDPClient for " + udpClient.ClientAPI.Name); - LLUDPClient udpClient; - if (clients.TryGetValue(client.AgentId, out udpClient)) - { - m_log.Debug("[LLUDPSERVER]: Removing LLUDPClient for " + client.Name); - udpClient.Shutdown(); - clients.Remove(client.AgentId, udpClient.RemoteEndPoint); - } - else - { - m_log.Warn("[LLUDPSERVER]: Failed to remove LLUDPClient for " + client.Name); - } + m_scene.ClientManager.Remove(udpClient.CircuitCode); + udpClient.ClientAPI.Close(false); + udpClient.Shutdown(); + clients.Remove(udpClient.RemoteEndPoint); } public void BroadcastPacket(Packet packet, ThrottleOutPacketType category, bool sendToPausedAgents, bool allowSplitting) @@ -230,15 +222,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } - public void SendPacket(UUID agentID, Packet packet, ThrottleOutPacketType category, bool allowSplitting) - { - LLUDPClient client; - if (clients.TryGetValue(agentID, out client)) - SendPacket(client, packet, category, allowSplitting); - else - m_log.Warn("[LLUDPSERVER]: Attempted to send a packet to unknown agentID " + agentID); - } - public void SendPacket(LLUDPClient client, Packet packet, ThrottleOutPacketType category, bool allowSplitting) { // CoarseLocationUpdate packets cannot be split in an automated way @@ -391,7 +374,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP { m_log.Warn("[LLUDPSERVER]: Ack timeout, disconnecting " + client.ClientAPI.Name); - RemoveClient(client.ClientAPI); + RemoveClient(client); return; } } @@ -647,23 +630,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void AddClient(uint circuitCode, UUID agentID, UUID sessionID, IPEndPoint remoteEndPoint, AuthenticateResponse sessionInfo) { // Create the LLUDPClient - LLUDPClient client = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); + LLUDPClient udpClient = new LLUDPClient(this, m_throttleRates, m_throttle, circuitCode, agentID, remoteEndPoint); // Create the LLClientView - LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, client, sessionInfo, agentID, sessionID, circuitCode); + LLClientView clientApi = new LLClientView(remoteEndPoint, m_scene, this, udpClient, sessionInfo, agentID, sessionID, circuitCode); clientApi.OnViewerEffect += m_scene.ClientManager.ViewerEffectHandler; clientApi.OnLogout += LogoutHandler; - clientApi.OnConnectionClosed += RemoveClient; + clientApi.OnConnectionClosed += + delegate(IClientAPI client) + { if (client is LLClientView) RemoveClient(((LLClientView)client).UDPClient); }; // Start the IClientAPI m_scene.ClientManager.Add(circuitCode, clientApi); clientApi.Start(); // Give LLUDPClient a reference to IClientAPI - client.ClientAPI = clientApi; + udpClient.ClientAPI = clientApi; // Add the new client to our list of tracked clients - clients.Add(agentID, client.RemoteEndPoint, client); + clients.Add(udpClient.RemoteEndPoint, udpClient); } private void AcknowledgePacket(LLUDPClient client, uint ack, int currentTime, bool fromResend) @@ -798,7 +783,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void LogoutHandler(IClientAPI client) { client.SendLogoutPacket(); - RemoveClient(client); + if (client is LLClientView) + RemoveClient(((LLClientView)client).UDPClient); } } }