diff options
-rw-r--r-- | src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java b/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java index 26aa93c..265bfc7 100644 --- a/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java +++ b/src/main/java/de/bwlehrpool/bwlp_guac/TunnelListener.java @@ -7,7 +7,7 @@ import org.apache.guacamole.net.event.listener.Listener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; +import java.util.HashMap; /** * A listener to track whether a user currently is connected to a tunnel. @@ -16,10 +16,10 @@ public class TunnelListener implements Listener { private static final Logger LOGGER = LoggerFactory.getLogger(TunnelListener.class); - private static final HashSet<String> usersWithTunnel = new HashSet<String>(); + private static final HashMap<String, Integer> userTunnelCount = new HashMap<String, Integer>(); public static boolean hasTunnel(String username) { - return usersWithTunnel.contains(username); + return userTunnelCount.get(username) != null; } @Override @@ -27,12 +27,24 @@ public class TunnelListener implements Listener { if (event instanceof TunnelConnectEvent) { String username = ((TunnelConnectEvent)event).getCredentials().getUsername(); LOGGER.info("User " + username + " connected to a tunnel."); - usersWithTunnel.add(username); + + Integer count = userTunnelCount.get(username); + if (count == null) count = 1; + else count++; + userTunnelCount.put(username, count); + + LOGGER.info("Tunnel count: " + count); } else if (event instanceof TunnelCloseEvent) { String username = ((TunnelCloseEvent)event).getCredentials().getUsername(); LOGGER.info("User " + username + " closed a tunnel."); - usersWithTunnel.remove(username); + + Integer count = userTunnelCount.get(username); + if (count != null) { + if (count > 1) userTunnelCount.put(username, count - 1); + else userTunnelCount.remove(username); + LOGGER.info("Tunnel count: " + (count - 1)); + } } } |