Improve startup checks for invalid settings

This commit is contained in:
libraryaddict 2019-06-29 13:38:20 +12:00
parent 5e1ed00434
commit fd2f7e4fbc
4 changed files with 155 additions and 55 deletions

View File

@ -53,7 +53,7 @@ public class LibsDisguises extends JavaPlugin {
getLogger().info("Build Date: " + pluginYml.getString("build-date"));
LibsPremium.check(getDescription().getVersion());
LibsPremium.check(getDescription().getVersion(), getFile());
if (!LibsPremium.isPremium()) {
getLogger().severe("You must purchase the plugin to use support for 1.14!");
@ -243,6 +243,14 @@ public class LibsDisguises extends JavaPlugin {
continue;
}
// Invalidate invalid distribution
if (LibsPremium.isPremium() && LibsPremium.getPaidInformation() != null &&
LibsPremium.getPaidInformation().getDownloadID().equals("-1895736039")) {
throw new IllegalStateException(
"Error while checking pi rate on startup! Please re-download the jar from SpigotMC before " +
"reporting this error!");
}
disguiseType.setWatcherClass(watcherClass);
if (DisguiseValues.getDisguiseValues(disguiseType) != null) {

View File

@ -1,67 +1,38 @@
package me.libraryaddict.disguise.utilities;
import com.comphenix.protocol.PacketType;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.craftbukkit.libs.org.apache.commons.io.IOUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by libraryaddict on 2/06/2017.
*/
public class LibsPremium {
private static class PluginInformation {
private String userID;
private boolean premium;
private String version;
private String buildNumber;
private String buildDate;
public PluginInformation(String userID, boolean premium, String version, String buildNumber, String buildDate) {
this.userID = userID;
this.premium = premium;
this.version = version;
this.buildNumber = buildNumber;
this.buildDate = buildDate;
}
public String getUserID() {
return userID;
}
public boolean isPremium() {
return premium;
}
public String getVersion() {
return version;
}
public String getBuildNumber() {
return buildNumber;
}
public String getBuildDate() {
return buildDate;
}
public Date getParsedBuildDate() {
try {
return new SimpleDateFormat("dd/MM/yyyy HH:mm").parse(getBuildDate());
}
catch (ParseException e) {
return null;
}
}
}
private static Boolean thisPluginIsPaidFor;
/**
* Information of the actively running plugin
*/
private static PluginInformation pluginInformation;
/**
* Information of the plugin used to activate premium, if exists
*/
private static PluginInformation paidInformation;
public static PluginInformation getPluginInformation() {
return pluginInformation;
}
public static PluginInformation getPaidInformation() {
return paidInformation;
}
/**
* @return Account ID if downloaded through SpigotMC
@ -92,8 +63,11 @@ public class LibsPremium {
return !userID.contains("__USER__");
}
/**
* Returns true if this plugin is premium
*/
public static Boolean isPremium() {
return thisPluginIsPaidFor == null ? !getUserID().contains("__USER__") : thisPluginIsPaidFor;
return thisPluginIsPaidFor == null ? isPremium(getUserID()) : thisPluginIsPaidFor;
}
/**
@ -143,11 +117,15 @@ public class LibsPremium {
Boolean premium;
String userId = null;
String downloadId = null;
String resourceId = null;
if (oldJarFile) {
premium = (Boolean) c.getMethod("isPremium").invoke(null);
} else {
userId = (String) c.getMethod("getUserID").invoke(null);
resourceId = (String) c.getMethod("getResourceID").invoke(null);
downloadId = (String) c.getMethod("getDownloadID").invoke(null);
premium = isPremium(userId);
}
@ -172,7 +150,8 @@ public class LibsPremium {
String pluginVersion = config.getString("version");
return new PluginInformation(userId, premium, pluginVersion, pluginBuildNumber, pluginBuildDate);
return new PluginInformation(userId, resourceId, downloadId, premium, pluginVersion, pluginBuildNumber,
pluginBuildDate);
}
}
@ -211,7 +190,8 @@ public class LibsPremium {
plugin.getBuildDate());
if (plugin.isPremium()) {
if (!isValidVersion(version, plugin.getVersion()) || plugin.getUserID() == null) {
if (!isValidVersion(version, plugin.getVersion()) || plugin.getUserID() == null ||
plugin.getDownloadID() == null) {
DisguiseUtilities.getLogger().warning(
"You have an old Lib's Disguises jar (" + file.getName() + " " + fileInfo +
") in the LibsDisguises folder! For security purposes, please replace this with a" +
@ -220,6 +200,8 @@ public class LibsPremium {
continue;
}
paidInformation = plugin;
thisPluginIsPaidFor = true;
// Found a premium Lib's Disguises jar (v5.2.6, build #40, created 16/02/2019)
DisguiseUtilities.getLogger().info("Found a premium Lib's Disguises jar (" + fileInfo + ")");
@ -251,12 +233,42 @@ public class LibsPremium {
total += Character.getNumericValue(c);
}
return String.format("%s(%s)", userID, total);
return String.format("%s (%s)", userID, total);
}
public static void check(String version) {
public static void check(String version, File file) {
thisPluginIsPaidFor = isPremium();
try {
pluginInformation = getInformation(file);
}
catch (Exception e) {
String pluginBuildDate = "??/??/????";
YamlConfiguration config = new YamlConfiguration();
try {
config.loadFromString(IOUtils.toString(LibsDisguises.getInstance().getResource("plugin.yml"), "UTF-8"));
// If plugin.yml contains a build-date
if (config.contains("build-date")) {
pluginBuildDate = config.getString("build-date");
}
}
catch (InvalidConfigurationException | IOException ex) {
ex.printStackTrace();
}
String buildNo = LibsDisguises.getInstance().getBuildNo();
if (buildNo != null && buildNo.matches("[0-9]+")) {
buildNo = "#" + buildNo;
}
pluginInformation = new PluginInformation(getUserID(), getResourceID(), getDownloadID(),
isPremium(getUserID()), version, buildNo, pluginBuildDate);
}
if (!isPremium() || !LibsDisguises.getInstance().isReleaseBuild()) {
doSecondaryCheck(version);
} else {
@ -264,7 +276,11 @@ public class LibsPremium {
}
if (isPremium()) {
DisguiseUtilities.getLogger().info("Premium enabled, thank you for supporting Lib's Disguises!");
boolean prem =
getPaidInformation() == null ? getPluginInformation().isLegit() : getPaidInformation().isLegit();
DisguiseUtilities.getLogger()
.info("Premium enabled, thank you for supporting Lib's Disguises!" + (!prem ? "!" : ""));
}
}
}

View File

@ -6,6 +6,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.plugin.PluginInformation;
import java.util.Collection;
import java.util.HashMap;
@ -42,7 +43,22 @@ public class MetricsInitalizer {
final String premiumType;
if (LibsPremium.isPremium()) {
if (plugin.isReleaseBuild()) {
PluginInformation info = LibsPremium.getPaidInformation();
if (info == null) {
info = LibsPremium.getPluginInformation();
}
boolean customPremium = !info.getUserID().matches("[0-9]+") || info.getUserID().equals("1") ||
!LibsPremium.getResourceID().equals("32453") || !info.getDownloadID().matches("-?[0-9]+");
if (customPremium) {
if (plugin.isReleaseBuild() && LibsPremium.getPaidInformation() == null) {
premiumType = "Custom Plugin";
} else {
premiumType = "Custom Builds";
}
} else if (plugin.isReleaseBuild()) {
premiumType = "Paid Plugin";
} else {
premiumType = "Paid Builds";

View File

@ -0,0 +1,60 @@
package me.libraryaddict.disguise.utilities.plugin;
import me.libraryaddict.disguise.utilities.LibsPremium;
/**
* Created by libraryaddict on 20/06/2019.
*/
public class PluginInformation {
private String userID;
private String resourceID;
private String downloadID;
private boolean premium;
private String version;
private String buildNumber;
private String buildDate;
public PluginInformation(String userID, String resourceID, String downloadID, boolean premium, String version,
String buildNumber, String buildDate) {
this.userID = userID;
this.resourceID = resourceID;
this.downloadID = downloadID;
this.premium = premium;
this.version = version;
this.buildNumber = buildNumber;
this.buildDate = buildDate;
}
public String getUserID() {
return userID;
}
public String getResourceID() {
return resourceID;
}
public String getDownloadID() {
return downloadID;
}
public boolean isPremium() {
return premium;
}
public String getVersion() {
return version;
}
public String getBuildNumber() {
return buildNumber;
}
public String getBuildDate() {
return buildDate;
}
public boolean isLegit() {
return getUserID().matches("[0-9]+") && LibsPremium.getResourceID().equals("32453") &&
getDownloadID().matches("-?[0-9]+");
}
}