Skip to content

Commit

Permalink
fixes and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
ayunami2000 committed May 2, 2024
1 parent 7c2fc1b commit 4e6f941
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 38 deletions.
54 changes: 20 additions & 34 deletions src/main/java/me/ayunami2000/ayunpictojava/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Channel> connections = new HashSet<>();

private static Tesseract tess = null;

Expand Down Expand Up @@ -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();
Expand All @@ -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<Channel> 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));
}
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="twitter:title" content="PictoChat Online, by ayunami2000."/>
<meta property="twitter:description" content="PictoChat web app with a server written in Java! Source: https://github.com/ayunami2000/ayunpictojava"/>
<meta name="twitter:image" content="welcome.png"/>
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<script src="https://js.hcaptcha.com/1/api.js" async defer></script>
<script src="fontfaceobserver.js"></script>
<script src="howler.min.js"></script>
<script src="pixi.min.js"></script>
Expand Down Expand Up @@ -224,8 +224,8 @@
<img src="images/intro_bg.png" id="intro_bg"/>
<div id="main-settings">
<div id="captcha" style="transform: scale(calc(91 / 300)); height: 65px;"
class="cf-turnstile" data-theme="light" data-retry="never"
data-sitekey="0x4AAAAAAAE7tg6O9EI2mSfS" data-callback="setVerificationToken"
class="h-captcha" data-theme="light" data-retry="never"
data-sitekey="49043ad8-6b2d-4f6c-bfa5-a8c9f235e048" data-callback="setVerificationToken"
data-error-callback="setVerificationToken"></div>
<img src="images/logo_dc.png" id="logo" onclick="sounds.error.play()" title="Connecting... Please wait!" alt="Connect to PictoChat"/>
<div class="intro-text">Username:</div>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4e6f941

Please sign in to comment.