diff --git a/src/main/java/data/BM.java b/src/main/java/data/BM.java index 76749a2..44404c8 100644 --- a/src/main/java/data/BM.java +++ b/src/main/java/data/BM.java @@ -6,16 +6,15 @@ import arc.struct.Seq; import arc.util.Log; +import util.AntiVpn; import util.Strings; public class BM { private static ArrayList bannedClients = new Seq().addAll("VALVE", "tuttop", "CODEX", "IGGGAMES", "IgruhaOrg", "FreeTP.Org").list(), defaultBannedNames = new Seq().addAll("[Server]", "[server]", "@e", "@a", "@p", "@t", "~").list(), - defaultBannedIps = new ArrayList<>(), bannedIps = new ArrayList<>(), bannedNames = new ArrayList<>(); - public static boolean antiVpn = false, antiVPNEnabled = true; public static void blacklistCommand(String[] arg) { ArrayList list = new ArrayList<>(); @@ -46,16 +45,16 @@ public static void blacklistCommand(String[] arg) { int max = best > 18+String.valueOf(bannedIps.size()).length() ? best+4 : 23+String.valueOf(bannedIps.size()).length(); Log.info("List of banned ip:"); - Log.info(Strings.lJust("| Custom list: Total: " + bannedIps.size(), max) + " Default list: Total: " + defaultBannedIps.size() + " (Anti VPN list)"); - for (int i=0; i 20) break; } try { - if (i == 20) builder.append(" | ...." + (defaultBannedIps.size()-i) + " more"); - else if (i < 20) builder.append(" | " + defaultBannedIps.get(i)); + if (i == 20) builder.append(" | ...." + (AntiVpn.vpnServersList.size()-i) + " more"); + else if (i < 20) builder.append(" | " + AntiVpn.vpnServersList.get(i)); } catch (IndexOutOfBoundsException e) {} Log.info(builder.toString()); @@ -133,6 +132,7 @@ public static void nameCheck(mindustry.gen.Player player) { if (bannedNames.contains(name) || defaultBannedNames.contains(name)) player.kick("[scarlet]Invalid nickname: []Please don't use [accent]'" + bannedNames.get(bannedNames.indexOf(name)) + "'[white] in your nickname."); + else if (bannedClients.contains(name)) player.con.kick("Ingenuine copy of Mindustry.\n\n" + "Mindustry is free on: [royal]https://anuke.itch.io/mindustry[]\n" @@ -140,8 +140,9 @@ else if (bannedClients.contains(name)) else if (bannedIps.contains(player.con.address)) player.kick("[scarlet]The IP you are using is blacklisted. [lightgray](your ip: " + player.ip() +")"); - else if (defaultBannedIps.contains(player.con.address) && antiVpn) - player.kick("[scarlet]Anti VPN is activated on this server! []Please deactivate your VPN to be able to connect to the server."); + + else if (AntiVpn.isEnabled && AntiVpn.checkIP(player.ip())) + player.kick("[scarlet]Anti VPN is activated on this server! []Please deactivate your VPN to be able to connect to the server."); } @SuppressWarnings("unchecked") @@ -155,47 +156,11 @@ public static void init() { bannedIps = Core.settings.getJson("bannedIpsList", Seq.class, Seq::new).list(); } else saveSettings(); - } catch (Exception e) { - saveSettings(); - init(); - } - - arc.files.Fi file = Core.files.local("config/ip-vpn-list.txt"); - - if (file.exists()) { - try { - Object[] list = file.readString().lines().toArray(); - for (Object line : list) defaultBannedIps.add((String) line); - } catch (Exception e) { - Core.net.httpGet("https://raw.githubusercontent.com/ZetaMap/moreCommands/main/ip-vpn-list.txt", s -> { - file.writeBytes(s.getResult()); - defaultBannedIps = new Seq().addAll((String[]) file.readString().lines().toArray()).list(); - }, f -> { - Log.err("The anti VPN file could not be downloaded from the web! It will therefore be deactivated"); - antiVpn = false; - antiVPNEnabled = false; - }); - } - - } else { - try { file.file().createNewFile(); } - catch (java.io.IOException e) {} - - Core.net.httpGet("https://raw.githubusercontent.com/ZetaMap/moreCommands/main/ip-vpn-list.txt", s -> { - file.writeBytes(s.getResult()); - Object[] list = file.readString().lines().toArray(); - for (Object line : list) defaultBannedIps.add((String) line); - }, f -> { - Log.err("The anti VPN file could not be downloaded from the web! It will therefore be deactivated"); - antiVpn = false; - antiVPNEnabled = false; - }); - } + } catch (Exception e) { saveSettings(); } } - private static void saveSettings() { + public static void saveSettings() { Core.settings.putJson("bannedNamesList", new Seq().addAll(bannedNames)); Core.settings.putJson("bannedIpsList", new Seq().addAll(bannedIps)); - Core.settings.forceSave(); } } diff --git a/src/main/java/moreCommandsPlugin.java b/src/main/java/moreCommandsPlugin.java index 6ac6972..064f77f 100644 --- a/src/main/java/moreCommandsPlugin.java +++ b/src/main/java/moreCommandsPlugin.java @@ -45,9 +45,9 @@ public class moreCommandsPlugin extends mindustry.mod.Plugin { //Called after all plugins have been created and commands have been registered. public void init() { - checkUpdates(); //Check if a new update is available + checkUpdates(); //check if a new update is available - //Filter for muted players and if tchat is disabled + //filter for muted players and if tchat is disabled netServer.admins.addChatFilter((p, m) -> { if (tchat) { if (TempData.get(p).isMuted) { @@ -64,7 +64,7 @@ public void init() { return m; }); - //Filter for players in GodMode + //filter for players in GodMode netServer.admins.addActionFilter(a -> { if ((a.type == ActionType.placeBlock || a.type == ActionType.breakBlock) && TempData.get(a.player).inGodmode) { if (a.type == ActionType.placeBlock) Call.constructFinish(a.tile, a.block, a.unit, (byte) a.rotation, a.player.team(), a.config); @@ -85,8 +85,10 @@ public void init() { } public moreCommandsPlugin() { + //init other classes and load settings... Effects.init(); BM.init(); + AntiVpn.init(true); loadSettings(); //clear VNW & RTV votes and disabled it on game over @@ -125,6 +127,9 @@ public moreCommandsPlugin() { Log.info("auto-pause: " + Groups.player.size() + " player connected -> Game unpaused..."); Call.sendMessage("[scarlet][Server]:[] Game unpaused..."); } + + //fix the admin bug + if (e.player.getInfo().admin) e.player.admin = true; }); Events.on(EventType.PlayerLeave.class, e -> { @@ -360,40 +365,54 @@ public void registerServerCommands(CommandHandler handler){ BM.blacklistCommand(arg); }); - handler.register("anti-vpn", "[on|off]", "Anti VPN service", arg -> { + handler.register("anti-vpn", "[on|off|limit] [number]", "Anti VPN service", arg -> { if (arg.length == 0) { - Log.info("Anti VPN is currently @.", BM.antiVpn ? "enabled" : "disabled"); + Log.info("Anti VPN is currently @.", AntiVpn.isEnabled ? "enabled" : "disabled"); return; } - if (BM.antiVPNEnabled) { - switch (arg[0]) { - case "on": case "true": - if (BM.antiVpn) { - Log.err("Disabled first!"); - return; - } - BM.antiVpn = true; - Log.info("Anti VPN enabled ..."); - saveSettings(); - break; - - case "off": case "false": - if (!BM.antiVpn) { - Log.err("Enabled first!"); - return; - } - BM.antiVpn = false; - Log.info("Anti VPN disabled ..."); - saveSettings(); - break; - - default: - Log.err("Invalid arguments. \n - Anti VPN is currently @.", BM.antiVpn ? "enabled" : "disabled"); - return; + switch (arg[0]) { + case "on": case "true": case "t": case "1": + if (AntiVpn.isEnabled) { + Log.err("Disabled first!"); + return; + } + AntiVpn.isEnabled = true; + AntiVpn.timesLeft = AntiVpn.timesLimit; + Log.info("Anti VPN enabled ..."); + if (!AntiVpn.fullLoaded) AntiVpn.init(); + saveSettings(); + break; + + case "off": case "false": case "f": case "0": + if (!AntiVpn.isEnabled) { + Log.err("Enabled first!"); + return; + } + AntiVpn.isEnabled = false; + Log.info("Anti VPN disabled ..."); + saveSettings(); + break; + + case "limit": + if (arg.length == 2) { + if(Strings.canParseInt(arg[1])){ + int number = Strings.parseInt(arg[1]); + + if (number < 999 && number > 1) { + AntiVpn.timesLimit = number; + Log.info("Set to @ ...", number); + AntiVpn.saveSettings(); + + } else Log.err("'number' must be less than 999 and greater than 1"); + } else Log.err("Please type a number"); + } else Log.info("The unsuccessful search limit is currently at @ tests.", AntiVpn.timesLimit); + break; + + default: + Log.err("Invalid arguments. \n - Anti VPN is currently @.", AntiVpn.isEnabled ? "enabled" : "disabled"); + return; } - } else Log.err("Anti VPN cannot be activated because it could not load properly."); - }); } @@ -452,7 +471,7 @@ public void registerClientCommands(CommandHandler handler){ else { MSG.get(player).setTarget(target); player.sendMessage("\n[gold]Private Message send to [white]" + target.name + "\n[gold]Content: [white]" + message); - target.sendMessage("\n[gold]Private Message: [white]" + player.name + "[gold] --> [sky]you[gold]\n--------------------------------\n[white]" + message); + target.sendMessage("\n[gold]Private Message: [white]" + player.name + "[gold] --> [sky]me[gold]\n--------------------------------\n[white]" + message); } } @@ -471,7 +490,7 @@ public void registerClientCommands(CommandHandler handler){ else { MSG.get(player).setTarget(target); player.sendMessage("\n[gold]Private Message send to [white]" + target.name + "\n[gold]Content: [white]" + arg[0]); - target.sendMessage("\n[gold]Private Message: [white]" + player.name + "[gold] --> [sky]you[gold]\n--------------------------------\n[white]" + arg[0]); + target.sendMessage("\n[gold]Private Message: [white]" + player.name + "[gold] --> [sky]me[gold]\n--------------------------------\n[white]" + arg[0]); } } } @@ -1294,6 +1313,11 @@ public void run() { if (netServer.admins.unbanPlayerID(arg[0])) Players.info(player, "Unbanned player: [accent]%s", arg[0]); else Players.err(player, "That IP/ID is not banned!"); }); + + handler.register("test", "test", (arg, player) -> { + player.getInfo().names = new Seq().addAll(player.name); + player.sendMessage(player.getInfo().names.toString()); + }); } private void loadSettings() { @@ -1302,18 +1326,15 @@ private void loadSettings() { String[] temp = Core.settings.getString("moreCommands").split(" \\| "); autoPause = Boolean.parseBoolean(temp[0]); tchat = Boolean.parseBoolean(temp[1]); - BM.antiVpn = Boolean.parseBoolean(temp[2]); } else saveSettings(); - } catch (Exception e) { - saveSettings(); - loadSettings(); - } + } catch (Exception e) { saveSettings(); } } private void saveSettings() { - Core.settings.put("moreCommands", String.join(" | ", autoPause+"", tchat+"", BM.antiVpn+"")); - Core.settings.forceSave(); + Core.settings.put("moreCommands", autoPause + " | " + tchat); + BM.saveSettings(); + AntiVpn.saveSettings(); } private void setHandler(CommandHandler handler) { diff --git a/src/main/java/util/AntiVpn.java b/src/main/java/util/AntiVpn.java new file mode 100644 index 0000000..50d2fd5 --- /dev/null +++ b/src/main/java/util/AntiVpn.java @@ -0,0 +1,108 @@ +package util; + +import java.util.ArrayList; + +import arc.Core; +import arc.util.Log; +import arc.util.serialization.Jval; + + +public class AntiVpn { + public static ArrayList vpnServersList = new ArrayList<>(); + public static int timesLeft = 10, timesLimit = timesLeft; + public static boolean isEnabled = false, vpnFileFound = true, fullLoaded = false; + + private boolean foundVpn = false; + + private AntiVpn() { + } + + + public static boolean checkIP(String ip) { + AntiVpn test = new AntiVpn(); + + Core.net.httpGet("https://vpnapi.io/api/" + ip, s -> { + Jval content = Jval.read(s.getResultAsString()); + + if (content.get("security") != null) test.foundVpn = content.get("security").asArray().get(0).asBool(); + timesLeft = timesLimit; + + }, f -> { + Log.err("Anti VPN: An error occurred while finding or processing the player's IP address." + + "\nError: " + f.getMessage()); + + if (vpnFileFound) { + Log.info("The search will be done by the reference file (less reliable)."); + test.foundVpn = vpnServersList.contains(ip); + timesLeft = timesLimit; + + } else { + Log.err("The reference file was not loaded. The player's IP will therefore not be verified."); + + if (timesLeft++ == timesLimit) { + Log.warn("The unsuccessful search limit has been reached. Anti VPN will be deactivated..."); + isEnabled = false; + + } else Log.warn("If this happens another '@' times, the anti VPN will be disabled!", timesLimit-timesLeft); + } + }); + + return test.foundVpn; + } + + public static void init() { init(false); } + public static void init(boolean loadSettings) { + if (loadSettings && Core.settings.has("AntiVpn")) { + try { + String[] temp = Core.settings.getString("AntiVpn").split(" \\| "); + isEnabled = Boolean.parseBoolean(temp[0]); + timesLimit = Integer.parseInt(temp[1]); + + } catch (Exception e) { saveSettings(); } + } + + if (isEnabled) { + arc.files.Fi file = Core.files.local("config/ip-vpn-list.txt"); + + if (file.exists()) { + try { + Log.info("Loading anti VPN file..."); + + for (Object line : file.readString().lines().toArray()) vpnServersList.add((String) line); + if (vpnServersList.get(0).equals("### Vpn servers list ###")) { + vpnServersList.remove(0); + + fullLoaded = true; + Log.info("File loaded!"); + return; + + } else { + vpnServersList.clear(); + Log.warn("You have an old version of the file, downloading the new file..."); + } + } catch (Exception e) { Log.err("The anti VPN file could not be load! Try to download the file..."); } + + } else { + Log.err("The anti VPN file was not found! Downloading the file from the web..."); + try { file.file().createNewFile(); } + catch (java.io.IOException e) {} + } + + Core.net.httpGet("https://raw.githubusercontent.com/ZetaMap/moreCommands/main/ip-vpn-list.txt", s -> { + file.writeBytes(s.getResult()); + Object[] list = file.readString().lines().toArray(); + for (Object line : list) vpnServersList.add((String) line); + + Log.info("File upload successful!"); + fullLoaded = true; + }, f -> { + Log.err("The anti VPN file could not be downloaded from the web! Searches will therefore only be done by web..."); + vpnFileFound = false; + }); + } + } + + public static void saveSettings() { + Core.settings.put("AntiVpn", isEnabled + " | " + timesLimit); + } +} diff --git a/src/main/resources/plugin.json b/src/main/resources/plugin.json index 2632f69..2f96105 100644 --- a/src/main/resources/plugin.json +++ b/src/main/resources/plugin.json @@ -4,5 +4,5 @@ "author": "ZetaMap", "main": "moreCommandsPlugin", "description": "This mindustry plugin add more commands for admins and players.", - "version": 8.5 + "version": 8.7 }