mirror of
https://github.com/colbster937/originblacklist.git
synced 2025-12-14 23:07:42 +00:00
udpate
This commit is contained in:
@@ -8,7 +8,7 @@ plugins {
|
|||||||
|
|
||||||
|
|
||||||
group = 'dev.colbster937'
|
group = 'dev.colbster937'
|
||||||
version = '1.1.1'
|
version = '1.1.2'
|
||||||
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
|
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
|
||||||
def targetJavaVersion = 17
|
def targetJavaVersion = 17
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public class Base {
|
|||||||
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();
|
String name = conn.getUsername();
|
||||||
|
String ip = getAddr(conn);
|
||||||
String notAllowed1 = "not allowed on the server";
|
String notAllowed1 = "not allowed on the server";
|
||||||
String notAllowed2 = "not allowed";
|
String notAllowed2 = "not allowed";
|
||||||
|
|
||||||
@@ -96,11 +97,18 @@ public class Base {
|
|||||||
for (String name1 : config.blacklist.players) {
|
for (String name1 : config.blacklist.players) {
|
||||||
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
|
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
|
||||||
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
|
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
|
||||||
webhook(conn, origin, name, "player");
|
webhook(conn, origin, brand, "player");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ip != null && !ip.equalsIgnoreCase("null")) {
|
||||||
|
if (ipblacklist.check(ip)) {
|
||||||
|
setKick(e, formatKickMessage("ip address", "ip", notAllowed1, notAllowed2, ip, conn.getWebSocketHost()));
|
||||||
|
webhook(conn, origin, brand, "ip");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setKick(IEaglercraftLoginEvent e, Component msg) {
|
public static void setKick(IEaglercraftLoginEvent e, Component msg) {
|
||||||
@@ -114,30 +122,61 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
||||||
if (config.messages.motd.enabled) {
|
if (!config.messages.motd.enabled) return;
|
||||||
IMOTDConnection conn = e.getMOTDConnection();
|
|
||||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
|
||||||
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
|
|
||||||
.map(line -> line
|
|
||||||
.replaceAll("%blocktype%", "origin")
|
|
||||||
.replaceAll("%easyblocktype%", "website")
|
|
||||||
.replaceAll("%notallowed1%", "blacklisted")
|
|
||||||
.replaceAll("%notallowed2%", "blacklisted")
|
|
||||||
.replaceAll("%blocked%", origin)
|
|
||||||
.replaceAll("%host%", conn.getWebSocketHost()))
|
|
||||||
.map(line -> LegacyComponentSerializer.legacySection().serialize(
|
|
||||||
MiniMessage.miniMessage().deserialize(line)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (origin != null && !origin.equals("null")) {
|
IMOTDConnection conn = e.getMOTDConnection();
|
||||||
for (String origin1 : config.blacklist.origins) {
|
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||||
if (matches(origin, origin1)) {
|
String host = conn.getWebSocketHost() != null ? conn.getWebSocketHost() : "";
|
||||||
setMOTD(conn, m);
|
String ip = getAddr(conn);
|
||||||
return;
|
|
||||||
}
|
String blocktype1 = null;
|
||||||
|
String easyblocktype1 = null;
|
||||||
|
String blocked1 = null;
|
||||||
|
|
||||||
|
if (origin != null && !"null".equals(origin)) {
|
||||||
|
for (String origin2 : config.blacklist.origins) {
|
||||||
|
if (matches(origin, origin2)) {
|
||||||
|
blocktype1 = "origin";
|
||||||
|
easyblocktype1 = "website";
|
||||||
|
blocked1 = origin;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (blocktype1 == null && ip != null && !"null".equalsIgnoreCase(ip)) {
|
||||||
|
boolean blocked = ipblacklist != null && ipblacklist.check(ip);
|
||||||
|
if (!blocked) {
|
||||||
|
for (String ip2 : config.blacklist.ips) {
|
||||||
|
if (matches(ip, ip2)) { blocked = true; break; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blocked) {
|
||||||
|
blocktype1 = "ip address";
|
||||||
|
easyblocktype1 = "ip";
|
||||||
|
blocked1 = ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blocktype1 == null) return;
|
||||||
|
|
||||||
|
final String finalBlocktype = blocktype1;
|
||||||
|
final String finalEasyblocktype = easyblocktype1;
|
||||||
|
final String finalBlocked = blocked1;
|
||||||
|
|
||||||
|
List<String> m = List.of(config.messages.motd.text.split("\n")).stream()
|
||||||
|
.map(line -> line
|
||||||
|
.replace("%blocktype%", finalBlocktype)
|
||||||
|
.replace("%easyblocktype%", finalEasyblocktype)
|
||||||
|
.replace("%notallowed1%", "blacklisted")
|
||||||
|
.replace("%notallowed2%", "blacklisted")
|
||||||
|
.replace("%blocked%", finalBlocked)
|
||||||
|
.replace("%host%", host))
|
||||||
|
.map(line -> LegacyComponentSerializer.legacySection()
|
||||||
|
.serialize(MiniMessage.miniMessage().deserialize(line)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
setMOTD(conn, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setMOTD(IMOTDConnection conn, List<String> m) {
|
public static void setMOTD(IMOTDConnection conn, List<String> m) {
|
||||||
@@ -172,30 +211,18 @@ public class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String handlePre(String ip, String name) {
|
|
||||||
if (ip != null && !ip.equalsIgnoreCase("null")) {
|
|
||||||
for (String ip1 : Base.config.blacklist.ips) {
|
|
||||||
if (ipblacklist.check(ip)) {
|
|
||||||
Component kick = formatKickMessage("ip address", "ip", "blacklisted", "blacklisted", ip, "");
|
|
||||||
return LegacyComponentSerializer.legacySection().serialize(kick);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean matches(String text1, String text2) {
|
public static boolean matches(String text1, String text2) {
|
||||||
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
return text1.toLowerCase().matches(text2.replace(".", "\\.").replaceAll("\\*", ".*").toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
|
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
|
||||||
String help = "";
|
String help = "";
|
||||||
if (type != "player") {
|
if ("player".equals(type)) {
|
||||||
help = config.messages.help.generic;
|
help = config.messages.help.player;
|
||||||
} else if (type == "ip") {
|
} else if ("ip address".equals(type)) {
|
||||||
help = config.messages.help.ip;
|
help = config.messages.help.ip;
|
||||||
} else {
|
} else {
|
||||||
help = config.messages.help.player;
|
help = config.messages.help.generic;
|
||||||
}
|
}
|
||||||
return MiniMessage.miniMessage().deserialize(
|
return MiniMessage.miniMessage().deserialize(
|
||||||
config.messages.kick
|
config.messages.kick
|
||||||
@@ -229,7 +256,7 @@ public class Base {
|
|||||||
"embeds": [
|
"embeds": [
|
||||||
{
|
{
|
||||||
"title": "Player Information",
|
"title": "Player Information",
|
||||||
"description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **User Agent:** %s\\n⏪ **Rewind:** %s"
|
"description": "🎮 **Name:** %s\\n🏠 **IP:** %s\\n🌄 **PVN:** %s\\n🌐 **Origin:** %s\\n🔋 **Brand:** %s\\n🪑 **Host:** %s\\n🧊 **UA:** %s\\n⏪ **Rewind:** %s"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -255,8 +282,14 @@ public class Base {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getAddr(IEaglerLoginConnection plr) {
|
public static String getAddr(IEaglerLoginConnection conn) {
|
||||||
var addr1 = plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined";
|
var addr1 = conn.getPlayerAddress() != null ? conn.getPlayerAddress().toString().substring(1) : "0.0.0.0:0";
|
||||||
|
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
|
||||||
|
return addr2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getAddr(IMOTDConnection conn) {
|
||||||
|
var addr1 = conn.getSocketAddress() != null ? conn.getSocketAddress().toString().substring(1) : "0.0.0.0:0";
|
||||||
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
|
var addr2 = addr1.lastIndexOf(':') != -1 ? addr1.substring(0, addr1.lastIndexOf(':')) : addr1;
|
||||||
return addr2;
|
return addr2;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,14 +51,4 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
|
||||||
String ip = event.getAddress().getHostAddress();
|
|
||||||
String name = event.getName();
|
|
||||||
String blacklisted = Base.handlePre(ip, name);
|
|
||||||
if (!blacklisted.equals("false")) {
|
|
||||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, blacklisted);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,15 +50,4 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPreLogin(PreLoginEvent event) {
|
|
||||||
String ip = event.getConnection().getAddress().getAddress().getHostAddress();
|
|
||||||
String name = event.getConnection().getName();
|
|
||||||
String blacklisted = Base.handlePre(ip, name);
|
|
||||||
if (!blacklisted.equals("false")) {
|
|
||||||
event.setCancelReason(blacklisted);
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,4 @@ public class OriginBlacklistVelocity {
|
|||||||
public void onMOTD(EaglercraftMOTDEvent event) {
|
public void onMOTD(EaglercraftMOTDEvent event) {
|
||||||
Base.handleMOTD(event);
|
Base.handleMOTD(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onPreLogin(PreLoginEvent event) {
|
|
||||||
String ip = event.getConnection().getRemoteAddress().getAddress().toString();
|
|
||||||
String name = event.getUsername();
|
|
||||||
String blacklisted = Base.handlePre(ip, name);
|
|
||||||
if (!blacklisted.equals("false")) {
|
|
||||||
event.setResult(PreLoginEvent.PreLoginComponentResult.denied(Component.text(blacklisted)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ messages:
|
|||||||
enabled: true
|
enabled: true
|
||||||
text: |
|
text: |
|
||||||
<red>This %easyblocktype% is %notallowed2%!</red>
|
<red>This %easyblocktype% is %notallowed2%!</red>
|
||||||
<dark_gray>»</dark_gray> <gray>%blocked%</gray> <dark_gray>«</dark_gray>
|
<dark_gray>»</dark_gray> <gray>%blocked%</gray>
|
||||||
icon: "blacklisted.png"
|
icon: "blacklisted.png"
|
||||||
|
|
||||||
# Origin + Brand blacklist supports wildcards
|
# Origin + Brand blacklist supports wildcards
|
||||||
|
|||||||
Reference in New Issue
Block a user