1.0.6 cool cool player blacklisting

This commit is contained in:
Colbster937 2025-05-13 19:15:57 -05:00
parent 0f80dded63
commit 16953bc708
4 changed files with 41 additions and 29 deletions

View File

@ -8,6 +8,7 @@ basically just a reimplementation of originblacklist but for eaglerxserver
### Features ### Features
- [x] Origin Blacklisting - [x] Origin Blacklisting
- [x] Brand Blacklisting - [x] Brand Blacklisting
- [x] Username blacklisting
- [x] Custom kick message - [x] Custom kick message
- [x] Custom blacklist MOTD - [x] Custom blacklist MOTD
- [x] MiniMessage formatting for messages - [x] MiniMessage formatting for messages

View File

@ -4,7 +4,6 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.lax1dude.eaglercraft.backend.server.api.*; import net.lax1dude.eaglercraft.backend.server.api.*;
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftClientBrandEvent;
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent; import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftLoginEvent;
import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent; import net.lax1dude.eaglercraft.backend.server.api.event.IEaglercraftMOTDEvent;
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection; import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
@ -14,8 +13,6 @@ import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.util.List; import java.util.List;
@ -69,41 +66,43 @@ public class Base {
IEaglerLoginConnection conn = e.getLoginConnection(); IEaglerLoginConnection conn = e.getLoginConnection();
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN); String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
String brand = conn.getEaglerBrandString(); String brand = conn.getEaglerBrandString();
String name = conn.getUsername();
if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) { if (origin != null && !origin.equals("null")) {
for (String origin1 : config.blacklist.origins) { for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) { if (matches(origin, origin1)) {
setKick(e, kick("origin", "website", origin, conn.getWebSocketHost())); setKick(e, formatKickMessage("origin", "website", origin, conn.getWebSocketHost()));
webhook(conn, origin, brand, "origin"); webhook(conn, origin, brand, "origin");
return; return;
} }
} }
} else if (origin != null && !origin.equals("null")) {
setKick(e, kick("origin", "website", origin, conn.getWebSocketHost()));
webhook(conn, "null", brand, "origin");
return;
} }
if (brand != null && !brand.equals("null")) { if (brand != null && !brand.equals("null")) {
for (String brand1 : config.blacklist.brands) { for (String brand1 : config.blacklist.brands) {
if (matches(brand, brand1)) { if (matches(brand, brand1)) {
setKick(e, kick("brand", "client", brand, conn.getWebSocketHost())); setKick(e, formatKickMessage("brand", "client", brand, conn.getWebSocketHost()));
webhook(conn, origin, brand, "brand"); webhook(conn, origin, brand, "brand");
return; return;
} }
} }
} }
if (name != null && !name.equals("null")) {
for (String name1 : config.blacklist.players) {
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
setKick(e, formatKickMessage("player", "username", name, conn.getWebSocketHost()));
webhook(conn, origin, name, "player");
return;
}
}
}
} }
public static void setKick(IEaglercraftLoginEvent e, Component msg) { public static void setKick(IEaglercraftLoginEvent e, Component msg) {
try { try {
String redir = config.blacklist.blacklist_redirect;
if (redir.equals("") || redir.equals("null")) {
e.setKickMessage(msg);
} else {
e.setKickRedirect(redir);
}
getLogger().info("Kicked " + e.getProfileUsername()); getLogger().info("Kicked " + e.getProfileUsername());
e.setKickMessage(msg);
} catch (Throwable ignored) { } catch (Throwable ignored) {
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg); String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
e.setKickMessage(msg1); e.setKickMessage(msg1);
@ -124,7 +123,7 @@ public class Base {
MiniMessage.miniMessage().deserialize(line))) MiniMessage.miniMessage().deserialize(line)))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (origin != null && !origin.equals("null") && !config.blacklist.missing_origin) { if (origin != null && !origin.equals("null")) {
for (String origin1 : config.blacklist.origins) { for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) { if (matches(origin, origin1)) {
setMOTD(conn, m); setMOTD(conn, m);
@ -173,9 +172,16 @@ public class Base {
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase()); return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
} }
public static Component kick(String type, String easytype, String value, String host) { public static Component formatKickMessage(String type, String easytype, String value, String host) {
String help = "";
if (type != "player") {
help = config.messages.help.generic;
} else {
help = config.messages.help.player;
}
return MiniMessage.miniMessage().deserialize( return MiniMessage.miniMessage().deserialize(
config.messages.kick config.messages.kick
.replaceAll("%help%", help)
.replaceAll("%blocktype%", type) .replaceAll("%blocktype%", type)
.replaceAll("%easyblocktype%", easytype) .replaceAll("%easyblocktype%", easytype)
.replaceAll("%blocked%", value) .replaceAll("%blocked%", value)

View File

@ -79,6 +79,7 @@ public class ConfigManager {
public static class Messages { public static class Messages {
public String kick; public String kick;
public MOTD motd; public MOTD motd;
public Help help;
} }
public static class MOTD { public static class MOTD {
@ -86,4 +87,9 @@ public class ConfigManager {
public String text; public String text;
public String icon; public String icon;
} }
public static class Help {
public String generic;
public String player;
}
} }

View File

@ -4,13 +4,21 @@ messages:
# - %blocktype% - Shows what the player was blocked for # - %blocktype% - Shows what the player was blocked for
# - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form # - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form
# - %host% - The IP the player pinged # - %host% - The IP the player pinged
# - %help% - The configured help message for the block type
kick: | kick: |
<red>This %easyblocktype% is not allowed on the server!</red> <red>This %easyblocktype% is not allowed on the server!</red>
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray> <dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
%help%
<gray>Think this is a mistake? Join our discord:</gray> <gray>Think this is a mistake? Join our discord:</gray>
<blue>discord.gg/changethisintheconfig</blue> <blue>discord.gg/changethisintheconfig</blue>
# Please note that help is only supported in the kick message, not the MOTD
help:
generic: "<gray>Please switch to a different %easyblocktype%.</gray>"
player: "<gray>Please change your %easyblocktype%.</gray>"
motd: motd:
enabled: true enabled: true
@ -27,8 +35,8 @@ blacklist:
brands: brands:
- "*dragonx*" - "*dragonx*"
- "*piclient*" - "*piclient*"
missing_origin: false players:
blacklist_redirect: "" - "Admin"
discord: discord:
webhook: "" webhook: ""
@ -47,15 +55,6 @@ discord: