mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 02:57:41 +00:00
Compare commits
9 Commits
6e1d5d132c
...
v1.1.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eab1eb27e7 | ||
|
|
0b6e9e1b83 | ||
|
|
07fa4bc21c | ||
|
|
b10882c65f | ||
|
|
ee4b14bf30 | ||
|
|
c913d9d34e | ||
|
|
bfed49407f | ||
|
|
d4541c9de4 | ||
|
|
58e9819c3a |
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
- name: Build Jar
|
||||
run: |
|
||||
gradle wrapper
|
||||
./gradlew shadowJar
|
||||
./gradlew clean shadowJar
|
||||
|
||||
- name: Publish Jar
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
- name: Extract Version
|
||||
id: version
|
||||
run: |
|
||||
VERSION=$(grep "^version" build.gradle | head -n 1 | cut -d\' -f2)
|
||||
VERSION="$(./gradlew -q properties | sed -n 's/^version: //p' | head -n 1)"
|
||||
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Remove Existing Release
|
||||
|
||||
86
build.gradle
86
build.gradle
@@ -1,86 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'eclipse'
|
||||
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.8'
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1'
|
||||
id("xyz.jpenilla.run-velocity") version "2.3.1"
|
||||
}
|
||||
|
||||
|
||||
group = 'dev.colbster937'
|
||||
version = '1.1.0'
|
||||
description = 'A reimplementation of OriginBlacklist for EaglerXServer'
|
||||
def targetJavaVersion = 17
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = "papermc-repo"
|
||||
url = "https://repo.papermc.io/repository/maven-public/"
|
||||
}
|
||||
maven {
|
||||
name = "sonatype"
|
||||
url = "https://oss.sonatype.org/content/groups/public/"
|
||||
}
|
||||
maven {
|
||||
name = "spigotmc-repo"
|
||||
url = "https://hub.spigotmc.org/nexus/content/repositories/public/"
|
||||
}
|
||||
maven {
|
||||
name = "md_5"
|
||||
url = "https://repo.md-5.net/content/repositories/releases/"
|
||||
}
|
||||
maven {
|
||||
name = "aikar"
|
||||
url = "https://repo.aikar.co/nexus/content/groups/aikar/"
|
||||
}
|
||||
maven {
|
||||
name = "lax1dude"
|
||||
url = "https://repo.lax1dude.net/repository/releases/"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
compileOnly("org.bukkit:bukkit:1.8-R0.1-SNAPSHOT")
|
||||
compileOnly("net.md-5:bungeecord-api:1.8-SNAPSHOT")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-velocity:1.0.0")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-bungee:1.0.0")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-bukkit:1.0.0")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.20.0")
|
||||
implementation("com.github.seancfoley:ipaddress:5.3.4")
|
||||
}
|
||||
|
||||
tasks {
|
||||
runVelocity {
|
||||
velocityVersion("3.3.0-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
|
||||
}
|
||||
|
||||
processResources {
|
||||
filesMatching(['plugin.yml', 'bungee.yml', 'velocity-plugin.json', 'Base.java']) {
|
||||
expand(
|
||||
version: project.version,
|
||||
description: project.description
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate 'org.yaml.snakeyaml', 'dev.colbster937.shaded.snakeyaml'
|
||||
relocate 'inet.ipaddr', 'dev.colbster937.shaded.ipaddr'
|
||||
archiveVersion.set('')
|
||||
archiveClassifier.set('')
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach {
|
||||
options.encoding = 'UTF-8'
|
||||
options.release.set(targetJavaVersion)
|
||||
}
|
||||
70
build.gradle.kts
Normal file
70
build.gradle.kts
Normal file
@@ -0,0 +1,70 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("eclipse")
|
||||
id("org.jetbrains.gradle.plugin.idea-ext") version "1.1.8"
|
||||
id("com.gradleup.shadow") version "9.3.0"
|
||||
id("xyz.jpenilla.run-velocity") version "2.3.1"
|
||||
}
|
||||
|
||||
group = "dev.colbster937"
|
||||
version = "1.1.3"
|
||||
description = "A reimplementation of OriginBlacklist for EaglerXServer"
|
||||
|
||||
val targetJavaVersion = 17
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/repositories/public/")
|
||||
maven("https://repo.md-5.net/content/repositories/releases/")
|
||||
maven("https://repo.aikar.co/nexus/content/groups/aikar/")
|
||||
maven("https://repo.lax1dude.net/repository/releases/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
compileOnly("org.bukkit:bukkit:1.8-R0.1-SNAPSHOT")
|
||||
compileOnly("net.md-5:bungeecord-api:1.8-SNAPSHOT")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-velocity:1.0.0")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-bungee:1.0.0")
|
||||
compileOnly("net.lax1dude.eaglercraft.backend:api-bukkit:1.0.0")
|
||||
implementation("org.yaml:snakeyaml:2.2")
|
||||
implementation("net.kyori:adventure-text-serializer-legacy:4.20.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.20.0")
|
||||
implementation("com.github.seancfoley:ipaddress:5.3.4")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks {
|
||||
named<xyz.jpenilla.runvelocity.task.RunVelocity>("runVelocity") {
|
||||
velocityVersion("3.4.0-SNAPSHOT")
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json", "Base.java")) {
|
||||
expand(
|
||||
mapOf(
|
||||
"version" to project.version,
|
||||
"description" to project.description
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("org.yaml.snakeyaml", "dev.colbster937.shaded.snakeyaml")
|
||||
relocate("inet.ipaddr", "dev.colbster937.shaded.ipaddr")
|
||||
archiveVersion.set("")
|
||||
archiveClassifier.set("")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(targetJavaVersion)
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
rootProject.name = 'OriginBlacklist'
|
||||
@@ -69,6 +69,7 @@ public class Base {
|
||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
String brand = conn.getEaglerBrandString();
|
||||
String name = conn.getUsername();
|
||||
String ip = getAddr(conn);
|
||||
String notAllowed1 = "not allowed on the server";
|
||||
String notAllowed2 = "not allowed";
|
||||
|
||||
@@ -96,11 +97,18 @@ public class Base {
|
||||
for (String name1 : config.blacklist.players) {
|
||||
if (matches(name, name1) || (name.length() > 16 || name.length() < 3)) {
|
||||
setKick(e, formatKickMessage("player", "username", notAllowed1, notAllowed2, name, conn.getWebSocketHost()));
|
||||
webhook(conn, origin, name, "player");
|
||||
webhook(conn, origin, brand, "player");
|
||||
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) {
|
||||
@@ -114,30 +122,61 @@ public class Base {
|
||||
}
|
||||
|
||||
public static void handleMOTD(IEaglercraftMOTDEvent e) {
|
||||
if (config.messages.motd.enabled) {
|
||||
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 (!config.messages.motd.enabled) return;
|
||||
|
||||
if (origin != null && !origin.equals("null")) {
|
||||
for (String origin1 : config.blacklist.origins) {
|
||||
if (matches(origin, origin1)) {
|
||||
setMOTD(conn, m);
|
||||
return;
|
||||
}
|
||||
IMOTDConnection conn = e.getMOTDConnection();
|
||||
String origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
String host = conn.getWebSocketHost() != null ? conn.getWebSocketHost() : "";
|
||||
String ip = getAddr(conn);
|
||||
|
||||
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) {
|
||||
@@ -170,18 +209,8 @@ public class Base {
|
||||
getLogger().error(ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
conn.sendToUser();
|
||||
conn.disconnect();
|
||||
}
|
||||
|
||||
public static boolean matches(String text1, String text2) {
|
||||
@@ -190,12 +219,12 @@ public class Base {
|
||||
|
||||
public static Component formatKickMessage(String type, String easytype, String notAllowed1, String notAllowed2, String value, String host) {
|
||||
String help = "";
|
||||
if (type != "player") {
|
||||
help = config.messages.help.generic;
|
||||
} else if (type == "ip") {
|
||||
if ("player".equals(type)) {
|
||||
help = config.messages.help.player;
|
||||
} else if ("ip address".equals(type)) {
|
||||
help = config.messages.help.ip;
|
||||
} else {
|
||||
help = config.messages.help.player;
|
||||
help = config.messages.help.generic;
|
||||
}
|
||||
return MiniMessage.miniMessage().deserialize(
|
||||
config.messages.kick
|
||||
@@ -229,7 +258,7 @@ public class Base {
|
||||
"embeds": [
|
||||
{
|
||||
"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 +284,16 @@ public class Base {
|
||||
});
|
||||
}
|
||||
|
||||
public static String getAddr(IEaglerLoginConnection plr) {
|
||||
return (plr.getPlayerAddress() != null ? plr.getPlayerAddress().toString().substring(1) : "undefined:undefined").split(":")[0];
|
||||
public static String getAddr(IEaglerLoginConnection conn) {
|
||||
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;
|
||||
return addr2;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
|
||||
@@ -22,6 +22,9 @@ public class IPBlacklist {
|
||||
if (addr.startsWith("/")) {
|
||||
addr1 = addr.substring(1);
|
||||
}
|
||||
if (addr1.startsWith("[") && addr1.endsWith("]")) {
|
||||
addr1 = addr1.substring(1, addr1.length() - 1);
|
||||
}
|
||||
ip = new IPAddressString(addr1).toAddress();
|
||||
} catch (AddressStringException e) {
|
||||
throw new RuntimeException("Invalid IP address: " + addr, e);
|
||||
|
||||
@@ -5,8 +5,9 @@ import net.lax1dude.eaglercraft.backend.server.api.bukkit.EaglerXServerAPI;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftLoginEvent;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.bukkit.event.EaglercraftMOTDEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@@ -47,18 +48,8 @@ public class OriginBlacklistBukkit extends JavaPlugin implements Listener {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onMOTD(EaglercraftMOTDEvent 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.md_5.bungee.api.event.PreLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
|
||||
public class OriginBlacklistBungee extends Plugin implements Listener {
|
||||
|
||||
@@ -46,19 +47,8 @@ public class OriginBlacklistBungee extends Plugin implements Listener {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMOTD(EaglercraftMOTDEvent 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.colbster937.originblacklist.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
@@ -51,18 +52,8 @@ public class OriginBlacklistVelocity {
|
||||
Base.handleConnection(event);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onMOTD(EaglercraftMOTDEvent 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
|
||||
text: |
|
||||
<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"
|
||||
|
||||
# Origin + Brand blacklist supports wildcards
|
||||
|
||||
Reference in New Issue
Block a user