internal static void DetachClient(AttachedClient client, string reason) { if (client == null) { return; } lock (addRemoveClientLock) { if (client.IsConnected()) { client.Disconnect(reason); } // Remove the client if (Clients.ContainsKey(client.TrackingId)) { Clients.Remove(client.TrackingId); } // Remove the client's focus on the character they may be tracking if (ClientFocusedCharacters.ContainsKey(client.TrackingId)) { ClientFocusedCharacters.Remove(client.TrackingId); } } }
internal static void AttachClient(AttachedClient client) { lock (addRemoveClientLock) { if (!Clients.ContainsKey(client.TrackingId)) { Clients.Add(client.TrackingId, client); } } }
internal static AttachedClient GetClientFromConnection(Connection connection) { lock (addRemoveClientLock) { var client = Clients.Values.FirstOrDefault(c => c.EqualsConnection(connection)); if (client == null) { client = new AttachedClient(); client.SetConnection(connection); AttachClient(client); } return(client); } }