From 54df0e08f5a7cb6d38c0d269087d9109ec111385 Mon Sep 17 00:00:00 2001 From: Seth <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Sun, 9 Aug 2020 17:49:20 -0700 Subject: [PATCH] Revert "Permbans are now indefinite bans." This reverts commit 4003db6dd9d5fadb7d8a215df9ca79369386ccd9. --- .../totalfreedommod/BackupManager.java | 4 +- .../banning/IndefiniteBan.java | 63 -------- .../banning/IndefiniteBanList.java | 140 ------------------ .../totalfreedommod/banning/PermbanList.java | 92 ++++++++++++ ...and_indefban.java => Command_permban.java} | 15 +- ...le_indefbans.java => Module_permbans.java} | 12 +- src/main/resources/indefinitebans.yml | 15 -- src/main/resources/permbans.yml | 10 ++ 8 files changed, 119 insertions(+), 232 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java rename src/main/java/me/totalfreedom/totalfreedommod/command/{Command_indefban.java => Command_permban.java} (57%) rename src/main/java/me/totalfreedom/totalfreedommod/httpd/module/{Module_indefbans.java => Module_permbans.java} (71%) delete mode 100644 src/main/resources/indefinitebans.yml create mode 100644 src/main/resources/permbans.yml diff --git a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java index e70bbf36..43f84789 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/BackupManager.java @@ -1,7 +1,7 @@ package me.totalfreedom.totalfreedommod; import java.io.File; -import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList; +import me.totalfreedom.totalfreedommod.banning.PermbanList; import me.totalfreedom.totalfreedommod.config.YamlConfig; import me.totalfreedom.totalfreedommod.permissions.PermissionConfig; import me.totalfreedom.totalfreedommod.punishments.PunishmentList; @@ -29,7 +29,7 @@ public class BackupManager extends FreedomService public void createAllBackups() { createBackups(TotalFreedomMod.CONFIG_FILENAME, true); - createBackups(IndefiniteBanList.CONFIG_FILENAME); + createBackups(PermbanList.CONFIG_FILENAME); createBackups(PermissionConfig.PERMISSIONS_FILENAME, true); createBackups(PunishmentList.CONFIG_FILENAME); createBackups("database.db"); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java deleted file mode 100644 index 1e3efcbe..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBan.java +++ /dev/null @@ -1,63 +0,0 @@ -package me.totalfreedom.totalfreedommod.banning; - -import com.google.common.collect.Lists; -import java.util.List; -import java.util.UUID; -import lombok.Getter; -import lombok.Setter; -import me.totalfreedom.totalfreedommod.config.IConfig; -import me.totalfreedom.totalfreedommod.util.FLog; -import org.bukkit.configuration.ConfigurationSection; - -public class IndefiniteBan implements IConfig -{ - - @Getter - @Setter - private String username = null; - @Getter - @Setter - private UUID uuid = null; - @Getter - private final List ips = Lists.newArrayList(); - @Getter - @Setter - private String reason = null; - - public IndefiniteBan() - { - } - - @Override - public void loadFrom(ConfigurationSection cs) - { - this.username = cs.getName(); - try - { - String strUUID = cs.getString("uuid", null); - if (strUUID != null) - { - UUID uuid = UUID.fromString(strUUID); - this.uuid = uuid; - } - } - catch (IllegalArgumentException e) - { - FLog.warning("Failed to load indefinite banned UUID for " + this.username + ". Make sure the UUID is in the correct format with dashes."); - } - this.ips.clear(); - this.ips.addAll(cs.getStringList("ips")); - this.reason = cs.getString("reason", null); - } - - @Override - public void saveTo(ConfigurationSection cs) - { - } - - @Override - public boolean isValid() - { - return username != null; - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java deleted file mode 100644 index 042cdf75..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/banning/IndefiniteBanList.java +++ /dev/null @@ -1,140 +0,0 @@ -package me.totalfreedom.totalfreedommod.banning; - -import com.google.common.base.Strings; -import com.google.common.collect.Sets; -import java.util.Set; -import java.util.UUID; -import lombok.Getter; -import me.totalfreedom.totalfreedommod.FreedomService; -import me.totalfreedom.totalfreedommod.config.ConfigEntry; -import me.totalfreedom.totalfreedommod.config.YamlConfig; -import me.totalfreedom.totalfreedommod.util.FLog; -import me.totalfreedom.totalfreedommod.util.FUtil; -import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerLoginEvent; - -public class IndefiniteBanList extends FreedomService -{ - - public static final String CONFIG_FILENAME = "indefinitebans.yml"; - - @Getter - private final Set indefBans = Sets.newHashSet(); - - @Getter - private int nameBanCount = 0; - - @Getter - private int uuidBanCount = 0; - - @Getter - private int ipBanCount = 0; - - @Override - public void onStart() - { - indefBans.clear(); - - final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true); - config.load(); - - for (String name : config.getKeys(false)) - { - if (!config.isConfigurationSection(name)) - { - FLog.warning("Could not load indefinite ban for " + name + ": Invalid format!"); - continue; - } - - IndefiniteBan indefBan = new IndefiniteBan(); - ConfigurationSection cs = config.getConfigurationSection(name); - indefBan.loadFrom(cs); - - if (!indefBan.isValid()) - { - FLog.warning("Not adding indefinite ban for " + name + ": Missing information."); - continue; - } - - indefBans.add(indefBan); - } - - updateCount(); - - FLog.info("Loaded " + nameBanCount + " indefinite name bans, " + uuidBanCount + " UUID bans, and " + ipBanCount + " ip bans"); - } - - @Override - public void onStop() - { - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerLogin(PlayerLoginEvent event) - { - final String username = event.getPlayer().getName(); - final UUID uuid = event.getPlayer().getUniqueId(); - final String ip = FUtil.getIp(event); - - String bannedBy = ""; - IndefiniteBan ban = null; - - for (IndefiniteBan indefBan : indefBans) - { - if (username.toLowerCase().equals(indefBan.getUsername().toLowerCase())) - { - bannedBy = "username"; - ban = indefBan; - break; - } - else if (indefBan.getUuid() != null && indefBan.getUuid().equals(uuid)) - { - bannedBy = "UUID"; - ban = indefBan; - break; - } - else if (indefBan.getIps().contains(ip)) - { - bannedBy = "IP address"; - ban = indefBan; - break; - } - } - - if (ban != null) - { - String kickMessage = ChatColor.RED + "Your " + bannedBy + " is indefinitely banned from this server."; - String reason = ban.getReason(); - if (!Strings.isNullOrEmpty(reason)) - { - kickMessage += "\nReason: " + ChatColor.GOLD + reason; - } - String appealURL = ConfigEntry.SERVER_INDEFBAN_URL.getString(); - if (!Strings.isNullOrEmpty(appealURL)) - { - kickMessage += ChatColor.RED + "\n\nRelease procedures are available at\n" + ChatColor.GOLD + ConfigEntry.SERVER_INDEFBAN_URL.getString(); - } - event.disallow(PlayerLoginEvent.Result.KICK_OTHER, kickMessage); - } - } - - private void updateCount() - { - nameBanCount = 0; - uuidBanCount = 0; - ipBanCount = 0; - - for (IndefiniteBan indefBan : indefBans) - { - nameBanCount += 1; - if (indefBan.getUuid() != null) - { - uuidBanCount += 1; - } - ipBanCount += indefBan.getIps().size(); - } - } -} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java new file mode 100644 index 00000000..7265bab6 --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/banning/PermbanList.java @@ -0,0 +1,92 @@ +package me.totalfreedom.totalfreedommod.banning; + +import com.google.common.collect.Sets; +import java.util.Set; +import lombok.Getter; +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.config.YamlConfig; +import me.totalfreedom.totalfreedommod.util.FLog; +import me.totalfreedom.totalfreedommod.util.FUtil; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerLoginEvent; + +public class PermbanList extends FreedomService +{ + + public static final String CONFIG_FILENAME = "permbans.yml"; + + @Getter + private final Set permbannedNames = Sets.newHashSet(); + @Getter + private final Set permbannedIps = Sets.newHashSet(); + + @Override + public void onStart() + { + permbannedNames.clear(); + permbannedIps.clear(); + + final YamlConfig config = new YamlConfig(plugin, CONFIG_FILENAME, true); + config.load(); + + for (String name : config.getKeys(false)) + { + permbannedNames.add(name.toLowerCase().trim()); + permbannedIps.addAll(config.getStringList(name)); + } + + FLog.info("Loaded " + permbannedIps.size() + " perm IP bans and " + permbannedNames.size() + " perm username bans."); + } + + @Override + public void onStop() + { + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerLogin(PlayerLoginEvent event) + { + final String username = event.getPlayer().getName(); + final String ip = FUtil.getIp(event); + + // Permbanned IPs + for (String testIp : getPermbannedIps()) + { + if (FUtil.fuzzyIpMatch(testIp, ip, 4)) + { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, + ChatColor.RED + "Your IP address is permanently banned from this server.\n" + + "Release procedures are available at\n" + + ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString()); + return; + } + } + + // Permbanned usernames + for (String testPlayer : getPermbannedNames()) + { + if (testPlayer.equalsIgnoreCase(username)) + { + event.disallow(PlayerLoginEvent.Result.KICK_OTHER, + ChatColor.RED + "Your username is permanently banned from this server.\n" + + "Release procedures are available at\n" + + ChatColor.GOLD + ConfigEntry.SERVER_PERMBAN_URL.getString()); + return; + } + } + + } + + public Set getPermbannedNames() + { + return this.permbannedNames; + } + + public Set getPermbannedIps() + { + return this.permbannedIps; + } +} diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java similarity index 57% rename from src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java rename to src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java index 32f5f1bb..ba8f8ef8 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_indefban.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_permban.java @@ -1,13 +1,14 @@ package me.totalfreedom.totalfreedommod.command; import me.totalfreedom.totalfreedommod.rank.Rank; +import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE) -@CommandParameters(description = "Reload the indefinite ban list.", usage = "/ reload", aliases = "ib") -public class Command_indefban extends FreedomCommand +@CommandParameters(description = "Reload the permban list.", usage = "/ reload", aliases = "pb") +public class Command_permban extends FreedomCommand { @Override @@ -23,10 +24,12 @@ public class Command_indefban extends FreedomCommand return false; } - msg("Reloading the indefinite ban list..."); - plugin.im.onStop(); - plugin.im.onStart(); - msg("Reloaded the indefinite ban list."); + msg("Reloading permban list...", ChatColor.RED); + plugin.pm.onStop(); + plugin.pm.onStart(); + msg("Reloaded permban list."); + msg(plugin.pm.getPermbannedIps().size() + " IPs and " + + plugin.pm.getPermbannedNames().size() + " usernames loaded."); return true; } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_permbans.java similarity index 71% rename from src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java rename to src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_permbans.java index 152390b3..a26c3d05 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_indefbans.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_permbans.java @@ -3,14 +3,14 @@ package me.totalfreedom.totalfreedommod.httpd.module; import java.io.File; import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.admin.Admin; -import me.totalfreedom.totalfreedommod.banning.IndefiniteBanList; +import me.totalfreedom.totalfreedommod.banning.PermbanList; import me.totalfreedom.totalfreedommod.httpd.HTTPDaemon; import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; -public class Module_indefbans extends HTTPDModule +public class Module_permbans extends HTTPDModule { - public Module_indefbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + public Module_permbans(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) { super(plugin, session); } @@ -18,17 +18,17 @@ public class Module_indefbans extends HTTPDModule @Override public NanoHTTPD.Response getResponse() { - File permbanFile = new File(plugin.getDataFolder(), IndefiniteBanList.CONFIG_FILENAME); + File permbanFile = new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME); final String remoteAddress = socket.getInetAddress().getHostAddress(); if (!isAuthorized(remoteAddress)) { return new NanoHTTPD.Response(NanoHTTPD.Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, - "You may not view the indefinite ban list. Your IP, " + remoteAddress + ", is not registered to an admin on the server."); + "You may not view the permban list. Your IP, " + remoteAddress + ", is not registered to an admin on the server."); } if (permbanFile.exists()) { - return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), IndefiniteBanList.CONFIG_FILENAME)); + return HTTPDaemon.serveFileBasic(new File(plugin.getDataFolder(), PermbanList.CONFIG_FILENAME)); } else { diff --git a/src/main/resources/indefinitebans.yml b/src/main/resources/indefinitebans.yml deleted file mode 100644 index 4e4404ce..00000000 --- a/src/main/resources/indefinitebans.yml +++ /dev/null @@ -1,15 +0,0 @@ -# -# TotalFreedomMod Indefinite Bans -# - -badplayer1: - uuid: '123e4567-e89b-12d3-a456-426614174000' - ips: - - 123.123.123.123 - - 321.321.321.321 - reason: 'bad player' -badplayer2: - ips: - - 111.111.111.111 -badplayer3: - ips: [] diff --git a/src/main/resources/permbans.yml b/src/main/resources/permbans.yml new file mode 100644 index 00000000..0df32bba --- /dev/null +++ b/src/main/resources/permbans.yml @@ -0,0 +1,10 @@ +# +# TotalFreedomMod 5.5 Permanent Bans +# + +badplayer1: + - 123.123.123.123 + - 321.321.321.321 +badplayer2: + - 111.111.111.111 +badplayer3: []