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
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();

View File

@@ -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<String> 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");

View File

@@ -30,38 +30,33 @@ public class Authenticator {
throw new RuntimeException(e);
}
}
public static List<String> readLines(BufferedReader reader) {
public static String authorize(String license, String serverID) {
try {
List<String> 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<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());
} catch (IOException e) {
e.printStackTrace();
}
return "UNREGISTERED";
}
public static String getServerID() {
return encrypt(IP.getHostAddress());

View File

@@ -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.