mirror of
https://github.com/colbster937/originblacklist.git
synced 2026-02-04 11:07:41 +00:00
Compare commits
4 Commits
v2.0.0
...
v2.0.1+342
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34226ec549 | ||
|
|
1aa22606b2 | ||
|
|
a483b6ccc5 | ||
|
|
a78fa33de8 |
1
.github/workflows/gradle.yml
vendored
1
.github/workflows/gradle.yml
vendored
@@ -4,6 +4,7 @@ on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [ main ]
|
||||
paths: [ src/**, build.gradle.kts, settings.gradle.kts ]
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
@@ -9,16 +9,18 @@
|
||||
- [x] Client brand based blacklisting
|
||||
- [x] Username based blacklisting
|
||||
- [x] IP based blacklisting
|
||||
- [x] JSON5 based configuration
|
||||
- [x] Kick message customization
|
||||
- [x] Blacklist MOTD customization
|
||||
- [x] MiniMessage and legacy formattings supported
|
||||
- [x] Plugin update checker
|
||||
- [ ] Send blacklist logs to a webhook
|
||||
- [x] Send blacklist logs to a webhook
|
||||
- [ ] Ingame blacklist management command
|
||||
- [ ] Subscribe to an auto-updating blacklist
|
||||
- [ ] Reverse blacklist (whitelist)
|
||||
|
||||
<h2>Download</h2>
|
||||
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/tag/v1.1.3">https://github.com/WebMCDevelopment/originblacklist/releases/tag/v1.1.3</a></b>
|
||||
The latest release can be found at <b><a href="https://github.com/WebMCDevelopment/originblacklist/releases/latest/">https://github.com/WebMCDevelopment/originblacklist/releases/latest/</a></b>
|
||||
|
||||
<h2>Building</h2>
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ val PLUGIN_NAME = "OriginBlacklist"
|
||||
val PLUGIN_IDEN = "originblacklist"
|
||||
val PLUGIN_DOMN = "xyz.webmc"
|
||||
val PLUGIN_DESC = "An eaglercraft client blacklist plugin."
|
||||
val PLUGIN_VERS = "2.0.0"
|
||||
val PLUGIN_VERS = "2.0.1"
|
||||
val PLUGIN_SITE = "https://github.com/WebMCDevelopment/$PLUGIN_IDEN"
|
||||
val PLUGIN_DEPA = listOf("EaglercraftXServer")
|
||||
val PLUGIN_DEPB = listOf("EaglercraftXServer")
|
||||
|
||||
@@ -2,6 +2,7 @@ package xyz.webmc.originblacklist.base;
|
||||
|
||||
import xyz.webmc.originblacklist.base.config.OriginBlacklistConfig;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumBlacklistType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumConnectionType;
|
||||
import xyz.webmc.originblacklist.base.enums.EnumLogLevel;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistLoginEvent;
|
||||
import xyz.webmc.originblacklist.base.events.OriginBlacklistMOTDEvent;
|
||||
@@ -9,9 +10,13 @@ import xyz.webmc.originblacklist.base.util.IOriginBlacklistPlugin;
|
||||
import xyz.webmc.originblacklist.base.util.OPlayer;
|
||||
import xyz.webmc.originblacklist.base.util.UpdateChecker;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
@@ -25,12 +30,14 @@ import inet.ipaddr.IPAddressString;
|
||||
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.EnumWebSocketHeader;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.IEaglerLoginConnection;
|
||||
import net.lax1dude.eaglercraft.backend.server.api.query.IMOTDConnection;
|
||||
|
||||
public final class OriginBlacklist {
|
||||
public static final Semver REQUIRED_API_VER = new Semver("1.0.2");
|
||||
public static final String GENERIC_STR = "generic";
|
||||
public static final String UNKNOWN_STR = "unknown";
|
||||
public static final String GENERIC_STR = "GENERIC";
|
||||
public static final String UNKNOWN_STR = "UNKNOWN";
|
||||
public static final String PLUGIN_REPO = "WebMCDevelopment/originblacklist";
|
||||
public static final int BSTATS_ID = 28776;
|
||||
|
||||
@@ -66,6 +73,7 @@ public final class OriginBlacklist {
|
||||
this.plugin.kickPlayer(this.getBlacklistedComponent("kick", blacklisted.getArrayString(),
|
||||
blacklisted.getAltString(), blacklisted.getString(), "not allowed", "not allowed on the server",
|
||||
blacklisted_value, blacklisted.getActionString()), event);
|
||||
this.sendWebhooks(event, blacklisted);
|
||||
final String name = player.getName();
|
||||
if (isNonNull(name)) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Prevented blacklisted player " + name + " from joining.");
|
||||
@@ -185,14 +193,105 @@ public final class OriginBlacklist {
|
||||
return MiniMessage.miniMessage().deserialize(str);
|
||||
}
|
||||
|
||||
private final void sendWebhooks(final OriginBlacklistLoginEvent event, final EnumBlacklistType type) {
|
||||
Json5Element element = this.config.get("discord.enabled");
|
||||
if (element.getAsBoolean()) {
|
||||
final OPlayer player = event.getPlayer();
|
||||
final EnumConnectionType connType = event.getConnectionType();
|
||||
final String userAgent;
|
||||
if (connType == EnumConnectionType.EAGLER) {
|
||||
final IEaglerLoginConnection loginConn = event.getEaglerEvent().getLoginConnection();
|
||||
userAgent = loginConn.getWebSocketHeader(EnumWebSocketHeader.HEADER_USER_AGENT);
|
||||
} else {
|
||||
userAgent = UNKNOWN_STR;
|
||||
}
|
||||
final byte[] payload = String.format(
|
||||
"""
|
||||
{
|
||||
"content": "Blocked a blacklisted %s from joining",
|
||||
"embeds": [
|
||||
{
|
||||
"title": "-------- Player Information --------",
|
||||
"description": "**→ Name:** %s\\n**→ Origin:** %s\\n**→ Brand:** %s\\n**→ IP Address:** %s\\n**→ Protocol Version:** %s\\n**→ User Agent:** %s\\n**→ Rewind:** %s\\n**→ Player Type:** %s",
|
||||
"color": 15801922,
|
||||
"fields": [],
|
||||
"footer": {
|
||||
"text": "OriginBlacklist v%s",
|
||||
"icon_url": "https://raw.githubusercontent.com/%s/refs/heads/main/icon.png"
|
||||
}
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"type": 1,
|
||||
"components": [
|
||||
{
|
||||
"type": 2,
|
||||
"style": 5,
|
||||
"label": "Get the Plugin",
|
||||
"url": "https://github.com/%s",
|
||||
"emoji": {
|
||||
"name": "🌐"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
""",
|
||||
type.getAltString(),
|
||||
player.getName().replaceAll("_", "\\_"),
|
||||
player.getOrigin(),
|
||||
player.getBrand(),
|
||||
player.getAddr(),
|
||||
player.getPVN(),
|
||||
userAgent,
|
||||
player.isRewind() ? "YES" : "NO",
|
||||
connType.toString(),
|
||||
this.plugin.getPluginVersion(),
|
||||
PLUGIN_REPO,
|
||||
PLUGIN_REPO
|
||||
).getBytes();
|
||||
element = this.config.get("discord.webhook_urls");
|
||||
if (element instanceof Json5Array) {
|
||||
for (final Json5Element _element : element.getAsJson5Array()) {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
final URL url = new URL(_element.getAsString());
|
||||
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
conn.setDoOutput(true);
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
conn.connect();
|
||||
final OutputStream os = conn.getOutputStream();
|
||||
os.write(payload);
|
||||
os.close();
|
||||
|
||||
final int code = conn.getResponseCode();
|
||||
if (code < 200 || code >= 300) {
|
||||
this.plugin.log(EnumLogLevel.WARN, "Webhook failed (HTTP " + code + ")");
|
||||
}
|
||||
|
||||
conn.disconnect();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void checkForUpdate() {
|
||||
(new Thread(() -> {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
this.updateAvailable = UpdateChecker.checkForUpdate(PLUGIN_REPO, this.plugin.getPluginVersion(),
|
||||
this.config.get("update_checker.allow_snapshots").getAsBoolean());
|
||||
if (this.updateAvailable) {
|
||||
this.plugin.log(EnumLogLevel.INFO, "Update Available! Download at https://github.com/" + PLUGIN_REPO + ".git");
|
||||
this.plugin.log(EnumLogLevel.INFO, "An update is available! Download it at https://github.com/" + PLUGIN_REPO + ".git");
|
||||
}
|
||||
})).run();
|
||||
});
|
||||
}
|
||||
|
||||
public static final String getComponentString(final Component comp) {
|
||||
|
||||
@@ -69,8 +69,8 @@ public class OriginBlacklistCommand implements ICommand {
|
||||
public void usage(CommandContext ctx) {
|
||||
ctx.reply("<aqua>Commands:</aqua>");
|
||||
ctx.reply("<gray> - /originblacklist reload</gray>");
|
||||
//ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
||||
//ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></gray>");
|
||||
// ctx.reply("<gray> - /originblacklist add <brand/origin/name/ip> <value></gray>");
|
||||
// ctx.reply("<gray> - /originblacklist remove <brand/origin/name/ip> <value></gray>");
|
||||
ctx.reply("<gray> - /originblacklist list</gray>");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public enum EnumBlacklistType {
|
||||
this.str = str;
|
||||
this.alt = alt;
|
||||
this.arr = arr;
|
||||
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR;
|
||||
this.act = OriginBlacklist.isNonNull(act) ? act : OriginBlacklist.GENERIC_STR.toLowerCase();
|
||||
}
|
||||
|
||||
public final String getString() {
|
||||
|
||||
@@ -16,28 +16,37 @@ public final class OPlayer {
|
||||
private final String name;
|
||||
private final UUID uuid;
|
||||
private final String brand;
|
||||
private final boolean rewind;
|
||||
private final int pvn;
|
||||
|
||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid, final String addr,
|
||||
final String brand) {
|
||||
final String brand, final int pvn) {
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
if (conn != null) {
|
||||
this.origin = conn.getWebSocketHeader(EnumWebSocketHeader.HEADER_ORIGIN);
|
||||
this.addr = formatSocketAddress(conn.getSocketAddress());
|
||||
if (conn instanceof IEaglerLoginConnection) {
|
||||
this.brand = ((IEaglerLoginConnection) conn).getEaglerBrandString();
|
||||
final IEaglerLoginConnection loginConn = (IEaglerLoginConnection) conn;
|
||||
this.brand = loginConn.getEaglerBrandString();
|
||||
this.rewind = loginConn.isEaglerXRewindPlayer();
|
||||
this.pvn = this.rewind ? loginConn.getRewindProtocolVersion() : loginConn.getMinecraftProtocol();
|
||||
} else {
|
||||
this.brand = OriginBlacklist.UNKNOWN_STR;
|
||||
this.rewind = false;
|
||||
this.pvn = pvn;
|
||||
}
|
||||
} else {
|
||||
this.origin = OriginBlacklist.UNKNOWN_STR;
|
||||
this.addr = formatIPAddress(addr);
|
||||
this.brand = brand;
|
||||
this.rewind = false;
|
||||
this.pvn = pvn;
|
||||
}
|
||||
}
|
||||
|
||||
public OPlayer(final IEaglerConnection conn, final String name, final UUID uuid) {
|
||||
this(conn, name, uuid, null, null);
|
||||
this(conn, name, uuid, null, null, -1);
|
||||
}
|
||||
|
||||
public final String getOrigin() {
|
||||
@@ -60,6 +69,14 @@ public final class OPlayer {
|
||||
return this.brand;
|
||||
}
|
||||
|
||||
public final boolean isRewind() {
|
||||
return this.rewind;
|
||||
}
|
||||
|
||||
public final int getPVN() {
|
||||
return this.pvn;
|
||||
}
|
||||
|
||||
private static final String formatIPAddress(String addr) {
|
||||
if (addr.startsWith("/")) {
|
||||
addr = addr.substring(1);
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import org.semver4j.Semver;
|
||||
import org.semver4j.Semver.VersionDiff;
|
||||
|
||||
import de.marhali.json5.Json5;
|
||||
import de.marhali.json5.Json5Array;
|
||||
@@ -22,6 +23,7 @@ public class UpdateChecker {
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5000);
|
||||
conn.setReadTimeout(5000);
|
||||
conn.connect();
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
Json5Element element = json5.parse(reader);
|
||||
if (element instanceof Json5Array) {
|
||||
@@ -32,12 +34,13 @@ public class UpdateChecker {
|
||||
final Json5Object obj = element.getAsJson5Object();
|
||||
final String tag = obj.get("tag_name").getAsString();
|
||||
final Semver ver = new Semver(tag.substring(1));
|
||||
if (ver.isGreaterThan(currentVersion)) {
|
||||
if (ver.isGreaterThan(currentVersion) && (allowPreRelease || currentVersion.diff(ver) != VersionDiff.BUILD)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
conn.disconnect();
|
||||
return false;
|
||||
} catch (final Throwable t) {
|
||||
t.printStackTrace();
|
||||
|
||||
@@ -106,14 +106,14 @@ public final class OriginBlacklistBukkit extends JavaPlugin implements Listener,
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaLogin(final AsyncPlayerPreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, event.getName(), event.getUniqueId(),
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, OriginBlacklist.UNKNOWN_STR, -1);
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaMOTD(final ServerListPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null,
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null);
|
||||
event.getAddress() != null ? event.getAddress().toString() : null, null, -1);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,19 +104,19 @@ public final class OriginBlacklistBungee extends Plugin implements Listener, IOr
|
||||
public final void onJavaLogin(final PostLoginEvent event) {
|
||||
final ProxiedPlayer aPlayer = event.getPlayer();
|
||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getName(), aPlayer.getUniqueId(),
|
||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand());
|
||||
aPlayer.getAddress().toString(), aPlayer.getClientBrand(), event.getPlayer().getPendingConnection().getVersion());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public final void onJavaHandshake(final PreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), OriginBlacklist.UNKNOWN_STR, event.getConnection().getVersion());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null);
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getAddress().toString(), null, -1);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public final void onJavaLogin(final PreLoginEvent event) {
|
||||
final OPlayer player = new OPlayer(null, event.getUsername(), event.getUniqueId(),
|
||||
event.getConnection().getRemoteAddress().toString(), null);
|
||||
event.getConnection().getRemoteAddress().toString(), OriginBlacklist.UNKNOWN_STR, event.getConnection().getProtocolVersion().getProtocol());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
@@ -128,14 +128,14 @@ public final class OriginBlacklistVelocity implements IOriginBlacklistPlugin {
|
||||
public final void onJavaHandshake(final PlayerClientBrandEvent event) {
|
||||
final Player aPlayer = (Player) event.getPlayer();
|
||||
final OPlayer bPlayer = new OPlayer(null, aPlayer.getUsername(), aPlayer.getUniqueId(),
|
||||
aPlayer.getRemoteAddress().getAddress().toString(), event.getBrand());
|
||||
aPlayer.getRemoteAddress().getAddress().toString(), event.getBrand(), event.getPlayer().getProtocolVersion().getProtocol());
|
||||
this.blacklist.handleLogin(new OriginBlacklistLoginEvent(null, event, EnumConnectionType.JAVA, bPlayer));
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public final void onJavaMOTD(final ProxyPingEvent event) {
|
||||
final OPlayer player = new OPlayer(null, null, null, event.getConnection().getRemoteAddress().getHostString(),
|
||||
null);
|
||||
null, -1);
|
||||
this.blacklist.handleMOTD(new OriginBlacklistMOTDEvent(null, event, EnumConnectionType.JAVA, player));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user