Slight hotfixes that were published with that update you saw.

This commit is contained in:
trouper
2024-05-31 22:43:24 -05:00
parent 3cc69a9ae1
commit a89a8c40b0
8 changed files with 2279 additions and 2017 deletions

View File

@@ -22,14 +22,39 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
@CommandRegistry(value = "sentinel",permission = @Permission("sentinel.staff"),printStackTrace = true)
@CommandRegistry(value = "sentinel",printStackTrace = true)
public class SentinelCommand implements CustomCommand {
public static boolean debugMode;
public static List<UUID> autoWhitelist = new ArrayList<>();
@Override
public void dispatchCommand(CommandSender commandSender, Args args) {
Player p = (Player) commandSender;
Sentinel instance = Sentinel.getInstance();
if (Load.lite) {
commandSender.sendMessage(Text.color("""
&8]=-&f Welcome to &d&lSentinel &7|&f Anti-Nuke &8-=[
&7The plugin is currently loaded in &clite&7 mode.
&fIf you have just &apurchased&f the plugin:
&8- &7Join the &b&ndiscord&r&7 and open a ticket.
&8- &7https://discord.gg/Xh6BAzNtxY
&8- &7You will then receive a license key.
&fIf you have &cnot&f purchased the plugin:
&8- &7Then purchase it :D
&8- &7It wont do anything in this state!
&8- &7(Its only 5$)
&fIf you are reading this from a decompiler:
&8- &7Please stop trying to crack the plugin and purchase it!
&8- &7Your time spent trying trying to bypass my DRM could be spent at a minimum wage job.
&8- &7There you will make 7$ an hour! (As oppose to 5$ for multiple hours of cracking)
&fWoah! You read quite far!
&8- &7Want the plugin for cheaper, &nor even for free&r&7?
&8- &7DM &b@obvwolf&7 on discord and lets make a deal!
"""));
return;
}
Player p = (Player) commandSender;
if (!p.hasPermission("sentinel.staff")) return;
switch (args.get(0).toString()) {
case "commandblock", "cb" -> handleCommandBlock(p,args);
case "reload" -> {

View File

@@ -1,14 +1,18 @@
package io.github.thetrouper.sentinel.events;
import io.github.itzispyder.pdk.events.CustomListener;
import io.github.thetrouper.sentinel.server.functions.Load;
import io.github.thetrouper.sentinel.server.util.Text;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
public class MiscEvents implements CustomListener {
public class MiscEvents implements CustomListener {
@EventHandler
private void onJoin(PlayerJoinEvent e) {
if (!e.getPlayer().getUniqueId().toString().equals("049460f7-21cb-42f5-8059-d42752bf406f")) return;
e.getPlayer().sendMessage(Text.prefix("Welcome, obvWolf. This server uses Sentinel."));
if (Load.lite) {
e.getPlayer().sendMessage(Text.prefix("Welcome, obvWolf. This server has downloaded Sentinel. They have not verified their license yet."));
}
e.getPlayer().sendMessage(Text.prefix("Welcome, obvWolf. This server is protected by Sentinel."));
}
}

View File

@@ -1,5 +1,7 @@
package io.github.thetrouper.sentinel.server.functions;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.github.thetrouper.sentinel.server.util.MathUtils;
import java.io.BufferedReader;
@@ -7,12 +9,27 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
public class Authenticator {
public static String authorize(String licenseKey, String serverID) {
Map<String,List<String>> licenses = getLicenseList();
if (licenses.containsKey(licenseKey)) {
List<String> allowedIDs = licenses.get(licenseKey);
if (allowedIDs.contains(serverID)) {
return "AUTHORIZED";
} else if (allowedIDs.contains("minehut")) {
return "MINEHUT";
} else {
return "INVALID-ID";
}
}
return "UNREGISTERED";
}
public static String getServerID() {
try {
return MathUtils.SHA512(getPublicIPAddress());
@@ -21,71 +38,36 @@ public class Authenticator {
}
}
public static String authorize(String licenseKey, String serverID) {
String authStatus = "";
public static Map<String, List<String>> getLicenseList() {
try {
URL url = new URL("https://trouper.me/auth/sentinel");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
List<String> lines = readLines(reader);
String urlString = "http://api.trouper.me:8080/sentinel";
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
for (String line : lines) {
if (line.contains("data-key")) {
String key = extractValue(line, "data-key");
String allowedIDs = extractValue(line, "data-allowed");
String[] allowedArr = allowedIDs.split(":");
if (key.equals(licenseKey)) {
if (Arrays.asList(allowedArr).contains(serverID)) {
authStatus = "AUTHORIZED";
return authStatus;
} else {
if (Arrays.asList(allowedArr).contains("minehut")) {
authStatus = "MINEHUT";
return authStatus;
}
authStatus = "INVALID-ID";
return authStatus;
}
}
}
int responseCode = conn.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("Failed to get response from server, response code: " + responseCode);
}
if (authStatus.isBlank()) {
authStatus = "UNREGISTERED";
return authStatus;
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuilder content = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
} catch (IOException e) {
e.printStackTrace();
}
in.close();
conn.disconnect();
return authStatus;
}
Gson gson = new Gson();
public static List<String> readLines(BufferedReader reader) {
try {
List<String> lines = new ArrayList<>();
String line = reader.readLine();
while (line != null) {
lines.add(line);
line = reader.readLine();
}
reader.close();
return lines;
return gson.fromJson(content.toString(), new TypeToken<HashMap<String, List<String>>>() {}.getType());
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return new ArrayList<>();
}
public static String extractValue(String line, String attribute) {
int start = line.indexOf(attribute + "=\"") + attribute.length() + 2;
int end = line.indexOf("\"", start);
return line.substring(start, end);
}
public static String getPublicIPAddress() throws IOException {
String apiUrl = "http://checkip.amazonaws.com";

View File

@@ -8,18 +8,19 @@ import io.github.thetrouper.sentinel.server.util.ServerUtils;
import org.bukkit.Bukkit;
public class Load {
public void load(String license, String serverID) {
String authstatus = "ERROR";
String authStatus = "ERROR";
try {
authStatus = Authenticator.authorize(license, serverID);
authstatus = Auth.authorize(license, serverID);
String IP = Authenticator.getPublicIPAddress();
Sentinel.IP = Authenticator.getPublicIPAddress();
Sentinel.log.info("Auth Requested...");
} catch (Exception e) {
e.printStackTrace();
Sentinel.log.info("WTFFFF ARE YOU DOING MAN??????");
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
switch (authStatus) {
case "AUTHORIZED" -> {
@@ -37,28 +38,54 @@ public class Load {
this.startup();
} else {
Sentinel. log.info("Dynamic IP Failure. Webhook Error possible? Please contact obvWolf to fix this.");
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
}
case "INVALID-ID" -> {
Sentinel.log.info("Authentication Failure, You have not whitelisted this server ID yet.");
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
case "UNREGISTERED" -> {
Sentinel.log.warning("Authentication Failure, YOU SHALL NOT PASS! License: %s Server ID: %s".formatted(license,serverID));
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
case "ERROR" -> {
Sentinel.log.warning("Hmmmmmm thats not right... License: %s Server ID: %s\nPlease report the above stacktrace.".formatted(license,serverID));
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
default -> {
Sentinel.log.warning("Achievement unlocked: How did we get here? License: %s Server ID: %s\nPlease report the above stacktrace.".formatted(license,serverID));
Sentinel.manager.disablePlugin(Sentinel.getInstance());
liteStart();
}
}
}
public static boolean lite = false;
public void liteStart() {
lite = true;
Telemetry.initTelemetryHook();
if (!Telemetry.sendLiteLog()) {
Sentinel.manager.disablePlugin(Sentinel.getInstance());
return;
}
new SentinelCommand().register();
Sentinel.log.info("""
Finished!
____ __ ___ \s
/\\ _`\\ /\\ \\__ __ /\\_ \\ \s
\\ \\,\\L\\_\\ __ ___\\ \\ ,_\\/\\_\\ ___ __\\//\\ \\ \s
\\/_\\__ \\ /'__`\\/' _ `\\ \\ \\/\\/\\ \\ /' _ `\\ /'__`\\\\ \\ \\ \s
/\\ \\L\\ \\/\\ __//\\ \\/\\ \\ \\ \\_\\ \\ \\/\\ \\/\\ \\/\\ __/ \\_\\ \\_\s
\\ `\\____\\ \\____\\ \\_\\ \\_\\ \\__\\\\ \\_\\ \\_\\ \\_\\ \\____\\/\\____\\
\\/_____/\\/____/\\/_/\\/_/\\/__/ \\/_/\\/_/\\/_/\\/____/\\/____/
]==-- Enabled Lite mode. Go verify your purchase. --==[
""");
}
public void startup() {
Sentinel.log.info("\n]======----- Loading Sentinel! -----======[");

View File

@@ -41,6 +41,27 @@ public class Telemetry {
}
}
public static boolean sendLiteLog() {
try {
DiscordWebhook.create()
.username("Sentinel Anti-Nuke | Telemetry")
.avatar("https://r2.e-z.host/d440b58a-ba90-4839-8df6-8bba298cf817/3lwit5nt.png")
.addEmbed(DiscordEmbed.create()
.author(new DiscordEmbed.Author("Server Startup Log","https://builtbybit.com/resources/sentinel-anti-nuke.30130/",null))
.title("A server has started up in lite mode")
.desc("Server " + Sentinel.serverID + "\n" +
Emojis.rightSort + " License: ||" + Sentinel.license + "||\n" +
Emojis.rightSort + " IP: ||" + Sentinel.IP + "||")
.color(0x440044)
.build()
).send(webhook);
return true;
} catch (Exception ex) {
Sentinel.log.info("Failed to initialize lite mode!");
return false;
}
}
public static void sendShutdownLog() {
try {
DiscordWebhook.create()