Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Deleted tps, fixed brand null, fixed namecheck.
Browse files Browse the repository at this point in the history
Former-commit-id: fafc106
  • Loading branch information
PolskiStevek committed Jan 12, 2020
1 parent a5e58d6 commit 7dfc5ff
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 109 deletions.
19 changes: 12 additions & 7 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<excludes>
<exclude>com.comphenix.protocol</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -105,7 +100,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -134,7 +129,17 @@
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
<version>4.4.0</version>
<scope>compile</scope>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>cglib-nodep</artifactId>
<groupId>cglib</groupId>
</exclusion>
<exclusion>
<artifactId>BukkitExecutors</artifactId>
<groupId>com.comphenix.executors</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<properties>
Expand Down
9 changes: 2 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<excludes>
<exclude>com.comphenix.protocol</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
Expand All @@ -77,8 +72,7 @@
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.14-SNAPSHOT</version>
<type>jar</type>
<version>1.15-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

Expand All @@ -92,6 +86,7 @@
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib-API</artifactId>
<version>4.4.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
92 changes: 46 additions & 46 deletions src/main/java/me/ishift/epicguard/bukkit/GuardBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import me.ishift.epicguard.bukkit.task.AttackTask;
import me.ishift.epicguard.bukkit.task.GuiRefreshTask;
import me.ishift.epicguard.bukkit.task.SaveTask;
import me.ishift.epicguard.bukkit.util.ExactTPS;
import me.ishift.epicguard.bukkit.util.MessagesBukkit;
import me.ishift.epicguard.bukkit.util.Metrics;
import me.ishift.epicguard.bukkit.util.MiscUtil;
Expand All @@ -23,7 +22,6 @@
import me.ishift.epicguard.universal.util.ServerType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -35,67 +33,35 @@

public class GuardBukkit extends JavaPlugin {
public static final String PERMISSION = "epicguard.admin";
public static File dataFolder;
public static FileConfiguration config;

public static void loadConfig() {
try {
Config.FIREWALL = config.getBoolean("firewall");
Config.FIREWALL_BL = config.getString("firewall.command-blacklist");
Config.FIREWALL_WL = config.getString("firewall.command-whitelist");
Config.CONNECT_SPEED = config.getInt("speed.connection");
Config.PING_SPEED = config.getInt("speed.ping-speed");
Config.AUTO_WHITELIST = config.getBoolean("auto-whitelist.enabled");
Config.AUTO_WHITELIST_TIME = config.getInt("auto-whitelist.time");
Config.ANTIBOT_QUERY_1 = config.getString("antibot.checkers.1.adress");
Config.ANTIBOT_QUERY_2 = config.getString("antibot.checkers.2.adress");
Config.ANTIBOT_QUERY_3 = config.getString("antibot.checkers.3.adress");
Config.ANTIBOT_QUERY_CONTAINS = config.getStringList("antibot.checkers.responses");
Config.COUNTRIES = config.getStringList("countries.list");
Config.COUNTRY_MODE = config.getString("countries.mode");
Config.ANTIBOT = config.getBoolean("antibot.enabled");
Config.UPDATER = config.getBoolean("updater");
Config.ATTACK_TIMER = config.getLong("speed.attack-timer-reset");
Config.JOIN_SPEED = config.getInt("speed.join-speed");
Config.TAB_COMPLETE_BLOCK = config.getBoolean("fully-block-tab-complete");
Config.BLOCKED_COMMANDS = config.getStringList("command-protection.list");
Config.ALLOWED_COMMANDS = config.getStringList("allowed-commands.list");
Config.OP_PROTECTION_LIST = config.getStringList("op-protection.list");
Config.OP_PROTECTION_ALERT = config.getString("op-protection.alert");
Config.OP_PROTECTION_COMMAND = config.getString("op-protection.command");
Config.ALLOWED_COMMANDS_BYPASS = config.getString("allowed-commands.bypass");
Config.BLOCKED_COMMANDS_ENABLE = config.getBoolean("command-protection.enabled");
Config.ALLOWED_COMMANDS_ENABLE = config.getBoolean("allowed-commands.enabled");
Config.OP_PROTECTION_ENABLE = config.getBoolean("op-protection.enabled");
Config.IP_HISTORY_ENABLE = config.getBoolean("ip-history.enabled");
Config.FORCE_REJOIN = config.getBoolean("antibot.force-rejoin");
Config.PEX_PROTECTION = config.getBoolean("op-protection.pex-protection");
Config.NAME_CONTAINS = config.getStringList("antibot.name-contains");
} catch (Exception e) {
Logger.throwException(e);
}
public static GuardBukkit getInstance() {
return JavaPlugin.getPlugin(GuardBukkit.class);
}

@Override
public void onEnable() {
try {
final long ms = System.currentTimeMillis();
dataFolder = this.getDataFolder();
this.saveDefaultConfig();
config = YamlConfiguration.loadConfiguration(new File(dataFolder + "/config.yml"));

this.createDirectories();
loadConfig();

new Logger(ServerType.SPIGOT);
LogoPrinter.print();

new GeoAPI(ServerType.SPIGOT);
new Metrics(this);
new NMSUtil();
new DataFileManager(dataFolder + "/data/data_flat.yml");

NMSUtil.init();
new DataFileManager(this.getDataFolder() + "/data/data_flat.yml");
DataFileManager.save();
MessagesBukkit.load();
Logger.info("NMS Version: " + NMSUtil.getVersion());

this.registerTasks();
this.registerListeners();

GuiMain.eq = Bukkit.createInventory(null, 45, "EpicGuard Management Menu");
GuiPlayers.inv = Bukkit.createInventory(null, 36, "EpicGuard Player Manager");

Expand All @@ -118,9 +84,44 @@ public void onDisable() {
}
}

public static void loadConfig() {
final FileConfiguration config = getInstance().getConfig();
Config.FIREWALL = config.getBoolean("firewall");
Config.FIREWALL_BL = config.getString("firewall.command-blacklist");
Config.FIREWALL_WL = config.getString("firewall.command-whitelist");
Config.CONNECT_SPEED = config.getInt("speed.connection");
Config.PING_SPEED = config.getInt("speed.ping-speed");
Config.AUTO_WHITELIST = config.getBoolean("auto-whitelist.enabled");
Config.AUTO_WHITELIST_TIME = config.getInt("auto-whitelist.time");
Config.ANTIBOT_QUERY_1 = config.getString("antibot.checkers.1.adress");
Config.ANTIBOT_QUERY_2 = config.getString("antibot.checkers.2.adress");
Config.ANTIBOT_QUERY_3 = config.getString("antibot.checkers.3.adress");
Config.ANTIBOT_QUERY_CONTAINS = config.getStringList("antibot.checkers.responses");
Config.COUNTRIES = config.getStringList("countries.list");
Config.COUNTRY_MODE = config.getString("countries.mode");
Config.ANTIBOT = config.getBoolean("antibot.enabled");
Config.UPDATER = config.getBoolean("updater");
Config.ATTACK_TIMER = config.getLong("speed.attack-timer-reset");
Config.JOIN_SPEED = config.getInt("speed.join-speed");
Config.TAB_COMPLETE_BLOCK = config.getBoolean("fully-block-tab-complete");
Config.BLOCKED_COMMANDS = config.getStringList("command-protection.list");
Config.ALLOWED_COMMANDS = config.getStringList("allowed-commands.list");
Config.OP_PROTECTION_LIST = config.getStringList("op-protection.list");
Config.OP_PROTECTION_ALERT = config.getString("op-protection.alert");
Config.OP_PROTECTION_COMMAND = config.getString("op-protection.command");
Config.ALLOWED_COMMANDS_BYPASS = config.getString("allowed-commands.bypass");
Config.BLOCKED_COMMANDS_ENABLE = config.getBoolean("command-protection.enabled");
Config.ALLOWED_COMMANDS_ENABLE = config.getBoolean("allowed-commands.enabled");
Config.OP_PROTECTION_ENABLE = config.getBoolean("op-protection.enabled");
Config.IP_HISTORY_ENABLE = config.getBoolean("ip-history.enabled");
Config.FORCE_REJOIN = config.getBoolean("antibot.force-rejoin");
Config.PEX_PROTECTION = config.getBoolean("op-protection.pex-protection");
Config.NAME_CONTAINS = config.getStringList("antibot.name-contains");
}

private void registerListeners() {
PluginManager pm = this.getServer().getPluginManager();
pm.registerEvents(new PlayerPreLoginListener(), this);
pm.registerEvents(new PreLoginListener(), this);
pm.registerEvents(new ServerListPingListener(), this);
pm.registerEvents(new PlayerJoinListener(), this);
pm.registerEvents(new PlayerQuitListener(), this);
Expand All @@ -135,7 +136,6 @@ private void registerTasks() {
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new GuiRefreshTask(), 0L, 40L);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new AttackTask(), 0L, Config.ATTACK_TIMER);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new SaveTask(), 0L, 5000L);
Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new ExactTPS(), 100L, 1L);
}

private void createDirectories() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
break;
case "reload":
p.sendMessage(ChatUtil.fix(MessagesBukkit.PREFIX + "&7Reloading config..."));
GuardBukkit.getInstance().reloadConfig();
GuardBukkit.loadConfig();
MessagesBukkit.load();
p.sendMessage(ChatUtil.fix(MessagesBukkit.PREFIX + "&aSuccesfully &7reloaded config!"));
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/me/ishift/epicguard/bukkit/gui/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import me.ishift.epicguard.bukkit.manager.AttackManager;
import me.ishift.epicguard.bukkit.manager.BlacklistManager;
import me.ishift.epicguard.bukkit.manager.DataFileManager;
import me.ishift.epicguard.bukkit.util.ExactTPS;
import me.ishift.epicguard.bukkit.util.ItemBuilder;
import me.ishift.epicguard.bukkit.util.ServerUtils;
import me.ishift.epicguard.bukkit.util.Updater;
Expand All @@ -28,7 +27,6 @@ public static void show(Player p) {
l1.add(ChatUtil.fix("&8>> &7Plugin version&8: &a" + Updater.currentVersion + (Updater.updateAvaible ? " &4&l[Outdated!]" : "")));
l1.add(ChatUtil.fix("&8>> &7Server&8: &f" + Bukkit.getServer().getBukkitVersion()));
l1.add(ChatUtil.fix("&8>> &7RAM Usage&8: &a" + ServerUtils.getMemoryUsage() + "&8/&6" + ServerUtils.getTotalMemory()));
l1.add(ChatUtil.fix("&8>> &7TPS&8: &a" + ExactTPS.getTPS()));
ItemStack i1 = new ItemBuilder(Material.BEDROCK).setTitle("&8>> &aBasic Information &8«").addLores(l1).build();

List<String> l2 = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void addChannel(Player p, String channel) {
try {
p.getClass().getMethod("addChannel", String.class).invoke(p, channel);
} catch (Exception e) {
Logger.throwException(e);
Logger.debug("Exception in class: " + e.getClass().getName());
}
}

Expand All @@ -24,7 +24,7 @@ public void onPluginMessageReceived(String channel, Player player, byte[] bytes)
User u = UserManager.getUser(player);
u.setBrand(brand);
} catch (Exception e) {
Logger.throwException(e);
Logger.debug("Exception in class: " + e.getClass().getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ public class PlayerJoinListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent e) {
try {
Player p = e.getPlayer();
final Player p = e.getPlayer();

if (NMSUtil.isOldVersion()) {
BrandPluginMessageListener.addChannel(p, "MC|BRAND");
} else {
BrandPluginMessageListener.addChannel(p, "MINECRAFT:BRAND");
}

String adress = p.getAddress().getAddress().getHostAddress();
final String adress = p.getAddress().getAddress().getHostAddress();
UserManager.addUser(p);
Updater.notify(p);
AttackManager.handleAttack(AttackType.JOIN);

User u = UserManager.getUser(p);
final User u = UserManager.getUser(p);
// IP History manager
if (Config.IP_HISTORY_ENABLE) {
List<String> history = DataFileManager.getDataFile().getStringList("history." + p.getName());
Expand All @@ -52,7 +53,7 @@ public void onJoin(PlayerJoinEvent e) {
}

// Brand Verification
CustomFile customFile = FileManager.getFile(GuardBukkit.dataFolder + "/brand.yml");
final CustomFile customFile = FileManager.getFile(GuardBukkit.getInstance().getDataFolder() + "/brand.yml");
if (customFile.getConfig().getBoolean("channel-verification.enabled")) {
Bukkit.getScheduler().runTaskLater(GuardBukkit.getPlugin(GuardBukkit.class), () -> {
if (p.isOnline()) {
Expand All @@ -66,7 +67,7 @@ public void onJoin(PlayerJoinEvent e) {
}
}
}
}, 20L);
}, 30L);
}

// Auto whitelisting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.ishift.epicguard.universal.AttackType;
import me.ishift.epicguard.universal.Config;
import me.ishift.epicguard.universal.check.GeoCheck;
import me.ishift.epicguard.universal.check.NameContainsCheck;
import me.ishift.epicguard.universal.check.ProxyCheck;
import me.ishift.epicguard.universal.util.GeoAPI;
import me.ishift.epicguard.universal.util.KickReason;
Expand All @@ -14,28 +15,39 @@
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;

public class PlayerPreLoginListener implements Listener {
public class PreLoginListener implements Listener {

@EventHandler
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
try {
final String adress = event.getAddress().getHostAddress();
final String name = event.getName();

if (adress.equals("127.0.0.1")) {
return;
}

final String country = GeoAPI.getDatabase().country(event.getAddress()).getCountry().getIsoCode();
DataFileManager.checkedConnections++;
Logger.debug(" ");
Logger.debug("###### CONNECTION CHECKER - INFO LOG #####");
Logger.debug("Player: " + name);
Logger.debug("Adress: " + adress);
Logger.debug("Country: " + country);
Logger.debug(" ");
Logger.debug(" # DETECTION LOG:");
Logger.debug("# DETECTION LOG:");
AttackManager.handleAttack(AttackType.CONNECT);

if (BlacklistManager.checkWhitelist(adress)) {
Logger.debug("+ Whitelist Check - Passed");
return;
}

if (BlacklistManager.check(adress)) {
AttackManager.handleDetection("Blacklist", name, adress, event, KickReason.BLACKLIST, false);
return;
}

if (GeoCheck.check(country)) {
AttackManager.handleDetection("Geographical", name, adress, event, KickReason.GEO, true);
return;
Expand All @@ -50,8 +62,8 @@ public void onPreLogin(AsyncPlayerPreLoginEvent event) {
return;
}

if (BlacklistManager.check(adress)) {
AttackManager.handleDetection("Blacklist", name, adress, event, KickReason.BLACKLIST, false);
if (NameContainsCheck.check(name)) {
AttackManager.handleDetection("Name Contains", name, adress, event, KickReason.BLACKLIST, true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ public static void setRejoinData(List<String> rejoinData) {
}

public static void handleDetection(String reason, String nick, String adress, AsyncPlayerPreLoginEvent event, KickReason kickReason, boolean blacklist) {
closeConnection(event, kickReason);
Logger.debug("- " + reason + " - DETECTED & BLOCKED");
if (blacklist) {
BlacklistManager.add(adress);
Logger.debug("- This IP has been blacklisted.");
}
closeConnection(event, kickReason);
Logger.debug("- " + reason + " - FAILED");
if (getConnectPerSecond() > 5) {
Notificator.title(MessagesBukkit.ATTACK_TITLE.replace("{CPS}", String.valueOf(getConnectPerSecond())), MessagesBukkit.ATTACK_SUBTITLE.replace("{MAX}", String.valueOf(getTotalBots())));
}
Expand Down
Loading

0 comments on commit 7dfc5ff

Please sign in to comment.