disallow duplicate usernames lol

This commit is contained in:
ayunami2000 2022-07-06 19:29:26 -04:00
parent 9d45885acb
commit 36bfd5469e
2 changed files with 4 additions and 0 deletions

View File

@ -111,6 +111,10 @@ public class WebSocketProxy extends WebSocketServer {
byte[] uname = new byte[unameLen]; byte[] uname = new byte[unameLen];
for (int i = 0; i < uname.length; i++) uname[i] = msg[5 + i * 2]; for (int i = 0; i < uname.length; i++) uname[i] = msg[5 + i * 2];
String username = new String(uname); String username = new String(uname);
if (Main.clients.values().stream().anyMatch(client -> client.username.equals(username))) {
conn.close();
return;
}
Client selfClient = new Client(username); Client selfClient = new Client(username);
Main.clients.put(conn, selfClient); Main.clients.put(conn, selfClient);
new Thread(() -> { new Thread(() -> {