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