From 15d94735e7f9273ff7025cd971e6417193801d76 Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Thu, 11 Oct 2012 20:09:56 -0700 Subject: [PATCH] Use lower-case version of nickname as key into users map, to allow for case-insensitivity of nicknames. Fixes #19. --- src/net/socialgamer/cah/data/ConnectedUsers.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/net/socialgamer/cah/data/ConnectedUsers.java b/src/net/socialgamer/cah/data/ConnectedUsers.java index 947f28f..6395c6a 100644 --- a/src/net/socialgamer/cah/data/ConnectedUsers.java +++ b/src/net/socialgamer/cah/data/ConnectedUsers.java @@ -54,6 +54,9 @@ public class ConnectedUsers { */ public static final long PING_TIMEOUT = 45L * 1000L * 1000000L; + /** + * Key (username) must be stored in lower-case to facilitate case-insensitivity in nicks. + */ private final Map users = new HashMap(); /** @@ -62,7 +65,7 @@ public class ConnectedUsers { * @return True if {@code userName} is a connected user. */ public boolean hasUser(final String userName) { - return users.containsKey(userName); + return users.containsKey(userName.toLowerCase()); } /** @@ -73,7 +76,7 @@ public class ConnectedUsers { */ public void newUser(final User user) { synchronized (users) { - users.put(user.getNickname(), user); + users.put(user.getNickname().toLowerCase(), user); final HashMap data = new HashMap(); data.put(LongPollResponse.EVENT, LongPollEvent.NEW_PLAYER.toString()); data.put(LongPollResponse.NICKNAME, user.getNickname()); @@ -94,7 +97,7 @@ public class ConnectedUsers { synchronized (users) { if (users.containsValue(user)) { user.noLongerVaild(); - users.remove(user.getNickname()); + users.remove(user.getNickname().toLowerCase()); notifyRemoveUser(user, reason); } } @@ -108,7 +111,7 @@ public class ConnectedUsers { */ @Nullable public User getUser(final String nickname) { - return users.get(nickname); + return users.get(nickname.toLowerCase()); } /**