(1.0.0) First release, bungee support only

This commit is contained in:
lax1dude 2024-05-04 15:42:44 -07:00
parent 774c59998f
commit 0f853d4d4d
8 changed files with 149 additions and 106 deletions

BIN
OriginBlacklist.jar Normal file

Binary file not shown.

View File

@ -42,6 +42,7 @@ public class OriginBlacklist {
public final Collection<Pattern> regexLocalBlacklist = new ArrayList();
public final Collection<Pattern> regexBlacklistReplit = new ArrayList();
public final Collection<String> simpleWhitelist = new ArrayList();
private final Object localBlacklistLock = new Object();
private File localBlacklist = null;
private String subscriptionDownloadUserAgent = null;
private Collection<String> blacklistSubscriptions = null;
@ -248,6 +249,7 @@ public class OriginBlacklist {
}
}
}
synchronized(localBlacklistLock) {
if(localBlacklist.exists()) {
long lastLocalEdit = localBlacklist.lastModified();
if(lastLocalEdit != lastLocalUpdate) {
@ -301,7 +303,9 @@ public class OriginBlacklist {
}
}
}
}else {
return;
}
}
synchronized(regexBlacklist) {
if(!regexLocalBlacklist.isEmpty()) {
logger.warn("the blacklist file '" + localBlacklist.getName() + "' has been deleted");
@ -309,9 +313,9 @@ public class OriginBlacklist {
regexLocalBlacklist.clear();
}
}
}
public void addLocal(String o) {
synchronized(localBlacklistLock) {
String p = "^" + Pattern.quote(o.trim()) + "$";
ArrayList<String> lines = new ArrayList();
if(localBlacklist.exists()) {
@ -327,7 +331,7 @@ public class OriginBlacklist {
}
}
if(lines.isEmpty()) {
lines.add("#whitelist false");
lines.add("#whitelistMode: false");
lines.add("");
}
if(!lines.contains(p)) {
@ -336,15 +340,17 @@ public class OriginBlacklist {
for(String s : lines) {
os.println(s);
}
lastLocalUpdate = 0l;
update();
}catch(IOException ex) {
// ?
}
lastLocalUpdate = 0l;
update();
}
}
}
public boolean removeLocal(String o) {
synchronized(localBlacklistLock) {
String p = "^" + Pattern.quote(o.trim()) + "$";
ArrayList<String> lines = new ArrayList();
if(localBlacklist.exists()) {
@ -359,27 +365,38 @@ public class OriginBlacklist {
// ?
}
}
if(lines.contains(p)) {
lines.remove(p);
if(lines.remove(p)) {
try {
try(PrintWriter os = new PrintWriter(new FileWriter(localBlacklist))) {
for(String s : lines) {
os.println(s);
}
}
lastLocalUpdate = 0l;
update();
return true;
}catch(IOException ex) {
logger.error("Failed to save '" + localBlacklist.getName() + "'");
ex.printStackTrace();
return false;
}
lastLocalUpdate = 0l;
update();
return true;
}
return false;
}
}
public File getLocalBlacklist() {
return localBlacklist;
}
public static String removeProtocolFromOrigin(String s) {
if(s == null) return null;
int idx = s.indexOf("://");
if(idx != -1) {
return s.substring(idx + 3);
}else {
return s;
}
}
}

View File

@ -37,7 +37,7 @@ public class OriginBlacklistConfigBungee implements OriginBlacklistConfigAdapter
}
File configFile = new File(dataDir, "config.yml");
if(!configFile.exists()) {
try(InputStream defaultConf = OriginBlacklistConfigBungee.class.getResourceAsStream("../default_config.yml")) {
try(InputStream defaultConf = OriginBlacklistConfigBungee.class.getResourceAsStream("/net/lax1dude/eaglercraft/v1_8/plugin/origin_blacklist/default_config.yml")) {
try(OutputStream os = new FileOutputStream(configFile)) {
byte[] copyBuffer = new byte[1024];
int i;

View File

@ -41,7 +41,7 @@ public class OriginBlacklistListenerBungee implements Listener {
OriginBlacklist blacklist = plugin.list;
boolean shouldKick = true;
try {
shouldKick = (origin == null && blacklist.getBlockClientsWithNoOriginHeader()) || blacklist.test(origin);
shouldKick = origin == null ? blacklist.getBlockClientsWithNoOriginHeader() : blacklist.test(OriginBlacklist.removeProtocolFromOrigin(origin));
}catch(Throwable t) {
plugin.getLogger().log(Level.SEVERE, "Failed to check origin blacklist for: " + origin, t);
}
@ -50,7 +50,7 @@ public class OriginBlacklistListenerBungee implements Listener {
evt.setCancelled(true);
String msg = blacklist.getKickMessage();
if(msg != null) {
evt.setReason(new TextComponent());
evt.setReason(new TextComponent(msg));
}
}
}

View File

@ -42,16 +42,25 @@ public class CommandDomainBlock extends Command {
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is not online"));
}else {
if(user.getPendingConnection() instanceof EaglerInitialHandler) {
Object o = ((EaglerInitialHandler)user.getPendingConnection()).getOrigin();
String o = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)user.getPendingConnection()).getOrigin());
if(o != null) {
if("null".equals(o)) {
p0.sendMessage(new TextComponent(ChatColor.RED + "That user is on an offline download"));
}else {
OriginBlacklist bl = OriginBlacklistPluginBungee.getPlugin().list;
bl.addLocal((String)o);
bl.addLocal(o);
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
if(p.getPendingConnection() instanceof EaglerInitialHandler) {
String oo = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)p.getPendingConnection()).getOrigin());
if(oo != null) {
if(bl.test(oo)) {
p.disconnect(new TextComponent(bl.getKickMessage() == null ? "End of stream" : bl.getKickMessage()));
}
}
}
}
p0.sendMessage(new TextComponent(ChatColor.RED + "Domain of " + ChatColor.WHITE + p1[0] + ChatColor.RED + " is " + ChatColor.WHITE + o));
p0.sendMessage(new TextComponent(ChatColor.RED + "It was added to the local block list."));
user.disconnect(new TextComponent(bl.getKickMessage()));
}
}else {
p0.sendMessage(new TextComponent(ChatColor.RED + "Domain of " + p1[0] + " is unknown (desktop runtime?)"));

View File

@ -1,9 +1,13 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.command;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.server.EaglerInitialHandler;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlacklistPluginBungee;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
/**
@ -33,7 +37,18 @@ public class CommandDomainBlockDomain extends Command {
p0.sendMessage(new TextComponent(ChatColor.RED + "Please follow this command by a domain"));
return;
}
OriginBlacklistPluginBungee.getPlugin().list.addLocal(p1[0]);
OriginBlacklist bl = OriginBlacklistPluginBungee.getPlugin().list;
bl.addLocal(p1[0]);
for(ProxiedPlayer p : ProxyServer.getInstance().getPlayers()) {
if(p.getPendingConnection() instanceof EaglerInitialHandler) {
String o = OriginBlacklist.removeProtocolFromOrigin(((EaglerInitialHandler)p.getPendingConnection()).getOrigin());
if(o != null) {
if(bl.test(o)) {
p.disconnect(new TextComponent(bl.getKickMessage() == null ? "End of stream" : bl.getKickMessage()));
}
}
}
}
p0.sendMessage(new TextComponent(ChatColor.GREEN + "The domain '" + ChatColor.WHITE + p1[0] + ChatColor.GREEN + "' was added to the block list"));
}

View File

@ -1,11 +1,11 @@
origin_blacklist_kick_message: 'End of stream'
origin_blacklist_kick_message: "End of stream"
origin_blacklist_block_missing_origin_header: false
origin_blacklist_block_offline_download: false
origin_blacklist_block_replit_clients: false
enable_web_origin_blacklist: false
origin_blacklist_subscriptions:
- 'add url here'
- "add url here"
origin_blacklist_use_simple_whitelist: false
origin_blacklist_simple_whitelist:
- 'type the name of your client\'s domain here'
- '(if \'origin_blacklist_use_simple_whitelist\' is true)'
- "type the name of your client's domain here"
- "(if 'origin_blacklist_use_simple_whitelist' is true)"

View File

@ -3,3 +3,5 @@ main: net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.bungee.OriginBlackli
version: 1.0.0
description: Plugin for EaglercraftXBungee servers to add the "origin blacklist" feature from 1.5.2
author: lax1dude
depends:
- EaglercraftXBungee