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
- [x] Origin Blacklisting
- [x] Brand Blacklisting
- [x] Username blacklisting
- [x] Custom kick message
- [x] Custom blacklist MOTD
- [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.serializer.legacy.LegacyComponentSerializer;
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.IEaglercraftMOTDEvent;
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
@ -14,8 +13,6 @@ import java.awt.image.BufferedImage;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;
@ -69,41 +66,43 @@ public class Base {
IEaglerLoginConnection conn = e.getLoginConnection();
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
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) {
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");
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")) {
for (String brand1 : config.blacklist.brands) {
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");
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) {
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());
e.setKickMessage(msg);
} catch (Throwable ignored) {
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
e.setKickMessage(msg1);
@ -124,7 +123,7 @@ public class Base {
MiniMessage.miniMessage().deserialize(line)))
.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) {
if (matches(origin, origin1)) {
setMOTD(conn, m);
@ -173,9 +172,16 @@ public class Base {
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(
config.messages.kick
.replaceAll("%help%", help)
.replaceAll("%blocktype%", type)
.replaceAll("%easyblocktype%", easytype)
.replaceAll("%blocked%", value)

View File

@ -79,6 +79,7 @@ public class ConfigManager {
public static class Messages {
public String kick;
public MOTD motd;
public Help help;
}
public static class MOTD {
@ -86,4 +87,9 @@ public class ConfigManager {
public String text;
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
# - %easyblocktype% - Shows what the player was blocked for in an eagler-kid readable form
# - %host% - The IP the player pinged
# - %help% - The configured help message for the block type
kick: |
<red>This %easyblocktype% is not allowed on the server!</red>
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
%help%
<gray>Think this is a mistake? Join our discord:</gray>
<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:
enabled: true
@ -27,8 +35,8 @@ blacklist:
brands:
- "*dragonx*"
- "*piclient*"
missing_origin: false
blacklist_redirect: ""
players:
- "Admin"
discord:
webhook: ""
@ -47,15 +55,6 @@ discord: