From 4e6f94198d1620dde681380dcab62ae5d25ab730 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Wed, 1 May 2024 22:38:05 -0400 Subject: [PATCH] fixes and patches --- .../me/ayunami2000/ayunpictojava/Main.java | 54 +++++++------------ src/main/resources/www/index.html | 8 +-- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/main/java/me/ayunami2000/ayunpictojava/Main.java b/src/main/java/me/ayunami2000/ayunpictojava/Main.java index 79fee60..286288c 100644 --- a/src/main/java/me/ayunami2000/ayunpictojava/Main.java +++ b/src/main/java/me/ayunami2000/ayunpictojava/Main.java @@ -68,6 +68,8 @@ public class Main { private static String[] chatFilterAttrs = null; private static String[] chatFilterRooms = null; private static float chatFilterThresh = 0.65f; + + private static final Set connections = new HashSet<>(); private static Tesseract tess = null; @@ -663,39 +665,6 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) thro remoteAddressField.setAccessible(true); remoteAddressField.set(ctx.channel(), new InetSocketAddress(ip, 0)); } - int i = 0; - for (ChannelHandlerContext ctxx : USERS_A.values()) { - InetAddress ipp = ((InetSocketAddress) ctxx.channel().remoteAddress()).getAddress(); - if (ipp.getHostAddress().equalsIgnoreCase(ip)) i++; - if (i >= 5) { - ctx.close(); - return; - } - } - for (ChannelHandlerContext ctxx : USERS_B.values()) { - InetAddress ipp = ((InetSocketAddress) ctxx.channel().remoteAddress()).getAddress(); - if (ipp.getHostAddress().equalsIgnoreCase(ip)) i++; - if (i >= 5) { - ctx.close(); - return; - } - } - for (ChannelHandlerContext ctxx : USERS_C.values()) { - InetAddress ipp = ((InetSocketAddress) ctxx.channel().remoteAddress()).getAddress(); - if (ipp.getHostAddress().equalsIgnoreCase(ip)) i++; - if (i >= 5) { - ctx.close(); - return; - } - } - for (ChannelHandlerContext ctxx : USERS_D.values()) { - InetAddress ipp = ((InetSocketAddress) ctxx.channel().remoteAddress()).getAddress(); - if (ipp.getHostAddress().equalsIgnoreCase(ip)) i++; - if (i >= 5) { - ctx.close(); - return; - } - } for (JsonElement jsonElement : banList) if (jsonElement.getAsString().equals(ip)) { ctx.close(); @@ -707,6 +676,21 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) thro pipeline.addLast("websocket-frametojson", new WebSocketFrameToJsonObjectDecoder()); pipeline.addLast("websocket-jsontoframe", new JsonObjectToWebSocketFrameEncoder()); pipeline.addLast("server-handler", new ServerHandler()); + Set tmp = new HashSet<>(connections); + int i = 0; + for (Channel connection : tmp) { + if (!connection.isOpen()) { + connections.remove(connection); + continue; + } + InetAddress ipp = ((InetSocketAddress) connection.remoteAddress()).getAddress(); + if (ipp.getHostAddress().equalsIgnoreCase(ip)) i++; + if (i >= 5) { + ctx.close(); + return; + } + } + connections.add(ctx.channel()); } else { pipeline.addLast(new HttpStaticFileServerHandler(web)); } @@ -1104,7 +1088,9 @@ protected void channelRead0(ChannelHandlerContext ctx, JsonObject jsonObject) { if (name.length() > 10) name = name.substring(0, 10); player.addProperty("name", name); int color = player.remove("color").getAsInt(); - if (color < 0 || color > 16777215) color = 0; + if (color < 0 || color > 16777215) color = 14013909; + Color ccc = new Color(color); + if (ccc.getRed() + ccc.getGreen() + ccc.getBlue() >= 2.5 * 255) color = 14013909; player.addProperty("color", color); ctx.channel().attr(PLAYER_DATA).set(player); res = new JsonObject(); diff --git a/src/main/resources/www/index.html b/src/main/resources/www/index.html index 3284ed8..cb0849e 100644 --- a/src/main/resources/www/index.html +++ b/src/main/resources/www/index.html @@ -24,7 +24,7 @@ - + @@ -224,8 +224,8 @@
Username:
@@ -330,7 +330,7 @@ object.value = object.value.replace(/[^\w\s]/gi, ''); } - let token = false; // set this to true if no captcha + let token = true; // set this to true if no captcha function setVerificationToken(t) { token = t;