Flash commit, start of better auth system

This commit is contained in:
TheTrouper
2023-07-09 19:22:45 -05:00
parent c41a3794e0
commit d33d2ed837
4 changed files with 37 additions and 35 deletions

View File

@@ -43,13 +43,17 @@ public final class Sentinel extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
log.info("Your server ID is: " + Authenticator.getServerID()); log.info("Your server ID is: " + Authenticator.getServerID());
try { switch (Authenticator.authorize(Config.license, Authenticator.getServerID())) {
if (!Authenticator.hasPaid()) { case "AUTHORIZED" -> {
log.info("Open a ticket with this message if the plugin doesnt work. " + Authenticator.getServerID()); 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 // Files
getConfig().options().copyDefaults(); getConfig().options().copyDefaults();

View File

@@ -26,6 +26,7 @@ public abstract class Config {
return config.getString("config.plugin.prefix"); return config.getString("config.plugin.prefix");
} }
} }
public static String license;
public static String webhook; public static String webhook;
public static List<String> trustedPlayers; public static List<String> trustedPlayers;
public static boolean blockSpecificCommands; public static boolean blockSpecificCommands;
@@ -72,6 +73,7 @@ public abstract class Config {
public static void loadConfiguration() { public static void loadConfiguration() {
Sentinel.prefix = config.getString("config.plugin.prefix"); Sentinel.prefix = config.getString("config.plugin.prefix");
license = config.getString("config.plugin.license");
// antiNuke // antiNuke
webhook = config.getString("config.plugin.webhook"); webhook = config.getString("config.plugin.webhook");
trustedPlayers = config.getStringList("config.plugin.trusted"); trustedPlayers = config.getStringList("config.plugin.trusted");

View File

@@ -30,38 +30,33 @@ public class Authenticator {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public static List<String> readLines(BufferedReader reader) {
public static String authorize(String license, String serverID) {
try { try {
List<String> lines = new ArrayList<>(); URL url = new URL("https://sentinelauth.000webhostapp.com");
String line = reader.readLine(); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
while (line != null) { String line;
lines.add(line); while ((line = reader.readLine()) != null) {
line = reader.readLine(); 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(); reader.close();
return lines; } catch (IOException e) {
} e.printStackTrace();
catch (Exception ex) {
ex.printStackTrace();
}
return new ArrayList<>();
}
public static List<String> serverIDS(List<String> strings) {
return strings.stream().filter(string -> string.contains("<p>")).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<String> ids = serverIDS(readLines(bufferedReader));
ids = ArrayUtils.toNewList(ids, string -> string.replaceAll("</p>", "").replaceAll("<p>", "").trim());
if (!ids.contains(getServerID())) {
throw new RuntimeException();
}
return false;
} catch (Exception e) {
throw new IllegalStateException("YOU SHALL NOT PASS! " + getServerID());
} }
return "UNREGISTERED";
} }
public static String getServerID() { public static String getServerID() {
return encrypt(IP.getHostAddress()); return encrypt(IP.getHostAddress());

View File

@@ -11,11 +11,12 @@
# Be sure to check out their amazing discord bot! # Be sure to check out their amazing discord bot!
config : config :
plugin: plugin:
license: "beta" # if you are a beta tester, leave this value as "beta"
# -------------------------------- # --------------------------------
# Anti-Nuke Setup (Do this first) # 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 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 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 - "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. 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.