4 Commits

Author SHA1 Message Date
Colbster937
8dbd01f016 remove temp files 2025-05-08 11:25:06 -05:00
Colbster937
71ad3059cc use .replaceAll instead of .replace 2025-05-08 11:24:44 -05:00
Colbster937
c5a2b1002f Fix OriginBlacklist on bungeecord 2025-05-08 11:12:46 -05:00
Colbster937
4d0f0542ca Fix OriginBlacklist on bungeecord 2025-05-08 11:12:27 -05:00
3 changed files with 32 additions and 20 deletions

View File

@@ -8,7 +8,7 @@ plugins {
group = 'dev.colbster937' group = 'dev.colbster937'
version = '1.0.3' version = '1.0.4'
description = 'A reimplementation of OriginBlacklist for EaglerXServer' description = 'A reimplementation of OriginBlacklist for EaglerXServer'
def targetJavaVersion = 17 def targetJavaVersion = 17

View File

@@ -66,14 +66,14 @@ public class Base {
if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) { if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
for (String origin1 : config.blacklist.origins) { for (String origin1 : config.blacklist.origins) {
if (matches(origin, origin1)) { if (matches(origin, origin1)) {
e.setKickMessage(kick("origin", "website", origin)); setKickMessage(e, kick("origin", "website", origin, conn.getWebSocketHost()));
webhook(conn, origin, brand, "origin"); webhook(conn, origin, brand, "origin");
return; return;
} }
} }
} else { } else {
if (origin != "null" || origin != null) { if (origin != "null" || origin != null) {
e.setKickMessage(kick("origin", "website", origin)); setKickMessage(e, kick("origin", "website", origin, conn.getWebSocketHost()));
webhook(conn, "null", brand, "origin"); webhook(conn, "null", brand, "origin");
return; return;
} }
@@ -81,7 +81,7 @@ public class Base {
if (brand != "null" && brand != null) { if (brand != "null" && brand != null) {
for (String brand1 : config.blacklist.brands) { for (String brand1 : config.blacklist.brands) {
if (matches(brand, brand1)) { if (matches(brand, brand1)) {
e.setKickMessage(kick("brand", "client", brand)); setKickMessage(e, kick("brand", "client", brand, conn.getWebSocketHost()));
webhook(conn, origin, brand, "brand"); webhook(conn, origin, brand, "brand");
return; return;
} }
@@ -89,19 +89,29 @@ public class Base {
} }
} }
public static void setKickMessage(IEaglercraftClientBrandEvent e, Component msg) {
try {
e.setKickMessage(msg);
} catch (Throwable ignored) {
String msg1 = LegacyComponentSerializer.legacySection().serialize(msg);
e.setKickMessage(msg1);
}
}
public static void handleMOTD(IEaglercraftMOTDEvent e) { public static void handleMOTD(IEaglercraftMOTDEvent e) {
if (config.messages.motd.enabled) { if (config.messages.motd.enabled) {
IMOTDConnection conn = e.getMOTDConnection(); IMOTDConnection conn = e.getMOTDConnection();
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN); String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
List<String> m = List.of(config.messages.motd.text.split("\n")).stream() List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
.map(line -> line .map(line -> line
.replace("%blocktype%", "origin") .replaceAll("%blocktype%", "origin")
.replace("%easyblocktype%", "website") .replaceAll("%easyblocktype%", "website")
.replace("%blocked%", origin)) .replaceAll("%blocked%", origin)
.replaceAll("%host%", conn.getWebSocketHost()))
.map(line -> LegacyComponentSerializer.legacySection().serialize( .map(line -> LegacyComponentSerializer.legacySection().serialize(
MiniMessage.miniMessage().deserialize( MiniMessage.miniMessage().deserialize(
line line
) )
)).collect(Collectors.toList()); )).collect(Collectors.toList());
if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) { if ((origin != "null" || origin != null) && !config.blacklist.missing_origin) {
for (String origin1 : config.blacklist.origins) { for (String origin1 : config.blacklist.origins) {
@@ -151,12 +161,13 @@ 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) { public static Component kick(String type, String easytype, String value, String host) {
return MiniMessage.miniMessage().deserialize( return MiniMessage.miniMessage().deserialize(
config.messages.kick config.messages.kick
.replace("%blocktype%", type) .replaceAll("%blocktype%", type)
.replace("%easyblocktype%", easytype) .replaceAll("%easyblocktype%", easytype)
.replace("%blocked%", value) .replaceAll("%blocked%", value)
.replaceAll("%host%", host)
); );
} }
@@ -166,9 +177,10 @@ public class Base {
String addr = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined"; String addr = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined";
String protocol = plr.isEaglerXRewindPlayer() String protocol = plr.isEaglerXRewindPlayer()
? (String.valueOf(plr.getRewindProtocolVersion()) != null ? String.valueOf(plr.getRewindProtocolVersion()) : "undefined") ? (String.valueOf(plr.getRewindProtocolVersion()) != null ? String.valueOf(plr.getRewindProtocolVersion()) : "undefined")
: (String.valueOf(plr.getMinecraftProtocol()) != null ? String.valueOf(plr.getMinecraftProtocol()) : "undefined"); : (String.valueOf(plr.getMinecraftProtocol()) != null ? String.valueOf(plr.getMinecraftProtocol()) : "undefined");
String rewind = plr.isEaglerXRewindPlayer() ? "Yes" : "No"; String rewind = plr.isEaglerXRewindPlayer() ? "Yes" : "No";
String host = plr.getWebSocketHost();
String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT); String userAgent = plr.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
if (userAgent == null || userAgent.isEmpty()) userAgent = "undefined"; if (userAgent == null || userAgent.isEmpty()) userAgent = "undefined";
@@ -178,11 +190,11 @@ public class Base {
"embeds": [ "embeds": [
{ {
"title": "Player Information", "title": "Player Information",
"description": "🎮 **Name:** %s\\n🏠 **Address:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s" "description": "🎮 **Name:** %s\\n🏠 **Address:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s"
} }
] ]
} }
""", type, plr.getAuthUsername(), addr, protocol, origin, brand, userAgent, rewind); """, type, plr.getAuthUsername(), addr, protocol, origin, brand, host, userAgent, rewind);
try { try {
HttpURLConnection conn = (HttpURLConnection) new URL(webhook).openConnection(); HttpURLConnection conn = (HttpURLConnection) new URL(webhook).openConnection();

View File

@@ -3,6 +3,7 @@ messages:
# - %blocked% - The player's origin/brand that was blocked # - %blocked% - The player's origin/brand that was blocked
# - %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
kick: | kick: |
<red>This %easyblocktype% is not allowed on the server!</red> <red>This %easyblocktype% is not allowed on the server!</red>
@@ -63,7 +64,6 @@ discord:
# :> # :>