From d33d2ed837ce9cd21dad766f83b8756edb13ad45 Mon Sep 17 00:00:00 2001 From: TheTrouper <93684527+thetrouper@users.noreply.github.com> Date: Sun, 9 Jul 2023 19:22:45 -0500 Subject: [PATCH] Flash commit, start of better auth system --- .../github/thetrouper/sentinel/Sentinel.java | 16 +++--- .../thetrouper/sentinel/data/Config.java | 2 + .../server/functions/Authenticator.java | 51 +++++++++---------- src/main/resources/config.yml | 3 +- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/src/main/java/io/github/thetrouper/sentinel/Sentinel.java b/src/main/java/io/github/thetrouper/sentinel/Sentinel.java index 5c51a41..5724e1b 100644 --- a/src/main/java/io/github/thetrouper/sentinel/Sentinel.java +++ b/src/main/java/io/github/thetrouper/sentinel/Sentinel.java @@ -43,13 +43,17 @@ public final class Sentinel extends JavaPlugin { @Override public void onEnable() { log.info("Your server ID is: " + Authenticator.getServerID()); - try { - if (!Authenticator.hasPaid()) { - log.info("Open a ticket with this message if the plugin doesnt work. " + Authenticator.getServerID()); + switch (Authenticator.authorize(Config.license, Authenticator.getServerID())) { + case "AUTHORIZED" -> { + log.info("Authentication Success!"); + } + case "INVALID-ID" -> { + log.info("Authentication Failure, You have not whitelisted this server ID yet."); + } + case "UNREGISTERED" -> { + log.info("YOU SHALL NOT PASS! License: " + Config.license + " Server ID: " + Authenticator.getServerID()); + throw new IllegalStateException("YOU SHALL NOT PASS! License: " + Config.license + " Server ID: " + Authenticator.getServerID()); } - } catch (IOException e) { - log.info("Open a ticket with this message if the plugin doesnt work. " + Authenticator.getServerID()); - throw new RuntimeException(e); } // Files getConfig().options().copyDefaults(); diff --git a/src/main/java/io/github/thetrouper/sentinel/data/Config.java b/src/main/java/io/github/thetrouper/sentinel/data/Config.java index 8d3e790..c801a3f 100644 --- a/src/main/java/io/github/thetrouper/sentinel/data/Config.java +++ b/src/main/java/io/github/thetrouper/sentinel/data/Config.java @@ -26,6 +26,7 @@ public abstract class Config { return config.getString("config.plugin.prefix"); } } + public static String license; public static String webhook; public static List trustedPlayers; public static boolean blockSpecificCommands; @@ -72,6 +73,7 @@ public abstract class Config { public static void loadConfiguration() { Sentinel.prefix = config.getString("config.plugin.prefix"); + license = config.getString("config.plugin.license"); // antiNuke webhook = config.getString("config.plugin.webhook"); trustedPlayers = config.getStringList("config.plugin.trusted"); diff --git a/src/main/java/io/github/thetrouper/sentinel/server/functions/Authenticator.java b/src/main/java/io/github/thetrouper/sentinel/server/functions/Authenticator.java index 555c4f3..7c102b0 100644 --- a/src/main/java/io/github/thetrouper/sentinel/server/functions/Authenticator.java +++ b/src/main/java/io/github/thetrouper/sentinel/server/functions/Authenticator.java @@ -30,38 +30,33 @@ public class Authenticator { throw new RuntimeException(e); } } - public static List readLines(BufferedReader reader) { + + public static String authorize(String license, String serverID) { try { - List lines = new ArrayList<>(); - String line = reader.readLine(); - while (line != null) { - lines.add(line); - line = reader.readLine(); + URL url = new URL("https://sentinelauth.000webhostapp.com"); + BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); + String line; + while ((line = reader.readLine()) != null) { + if (line.contains(license)) { + String[] parts = line.split(":"); + if (parts.length > 1) { + String[] allowedIDs = parts[1].split("\\s+"); + for (String id : allowedIDs) { + if (id.equals(serverID)) { + reader.close(); + return "AUTHORIZED"; + } + } + } + reader.close(); + return "INVALID-ID"; + } } reader.close(); - return lines; - } - catch (Exception ex) { - ex.printStackTrace(); - } - return new ArrayList<>(); - } - public static List serverIDS(List strings) { - return strings.stream().filter(string -> string.contains("

")).toList(); - } - public static boolean hasPaid() throws IOException { - try { - URL url = new URL("https://thetrouper.github.io/CUSTOMERS.html"); - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(url.openStream())); - List ids = serverIDS(readLines(bufferedReader)); - ids = ArrayUtils.toNewList(ids, string -> string.replaceAll("

", "").replaceAll("

", "").trim()); - if (!ids.contains(getServerID())) { - throw new RuntimeException(); - } - return false; - } catch (Exception e) { - throw new IllegalStateException("YOU SHALL NOT PASS! " + getServerID()); + } catch (IOException e) { + e.printStackTrace(); } + return "UNREGISTERED"; } public static String getServerID() { return encrypt(IP.getHostAddress()); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f710a3f..b4a41e1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -11,11 +11,12 @@ # Be sure to check out their amazing discord bot! config : plugin: + license: "beta" # if you are a beta tester, leave this value as "beta" # -------------------------------- # Anti-Nuke Setup (Do this first) # -------------------------------- prefix: "§d§lSentinel §8» §7" # Prefix of the plugin. Line below is the discord webhook for logs to be sent to - webhook: "https://discord.com/api/webhooks/1126363806147289088/UfWz9jdmXpZ4f2kqqsKK6mx4NmZyknhHNzGuAHYSx30iSLCPwqf66AiToZn2rItAmAym" + webhook: "https://discord.com/api/webhooks/id/token" trusted: # List the UUIDs of players who are trusted, will bypass the plugin and be immune to logs and are able to re-op themeselves - "049460f7-21cb-42f5-8059-d42752bf406f" # obvWolf block-specific: true # Defaulted true | Weather or not to block ALL plugin specific commands from non-trusted members (EX: minecraft:execute) these will not be logged.