mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 08:39:33 +00:00
Remove Version/Update Checking As Launcher Will Do This
This commit is contained in:
@@ -12,7 +12,6 @@ import org.parabot.core.ui.utils.UILog;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,13 +45,6 @@ public final class Landing {
|
|||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Core.hasValidation() && !Core.isValid()) {
|
|
||||||
if (Core.newVersionAlert() == JOptionPane.YES_OPTION) {
|
|
||||||
Core.downloadNewVersion();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Core.verbose("Starting 2006Scape...");
|
Core.verbose("Starting 2006Scape...");
|
||||||
ServerSelector.initServer = "2006Scape";
|
ServerSelector.initServer = "2006Scape";
|
||||||
new BotUI();
|
new BotUI();
|
||||||
@@ -110,10 +102,6 @@ public final class Landing {
|
|||||||
case "-no_sec":
|
case "-no_sec":
|
||||||
Core.disableSec();
|
Core.disableSec();
|
||||||
break;
|
break;
|
||||||
case "-no_validation":
|
|
||||||
case "-ignore_updates":
|
|
||||||
Core.disableValidation();
|
|
||||||
break;
|
|
||||||
case "-uuid":
|
case "-uuid":
|
||||||
Core.setQuickLaunchByUuid(Integer.parseInt(args[++i]));
|
Core.setQuickLaunchByUuid(Integer.parseInt(args[++i]));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ public class Configuration extends org.parabot.api.Configuration {
|
|||||||
public static final String GET_SERVER_PROVIDER_TYPE = "http://v3.bdn.parabot.org/api/bot/server/type?server=%s";
|
public static final String GET_SERVER_PROVIDER_TYPE = "http://v3.bdn.parabot.org/api/bot/server/type?server=%s";
|
||||||
public static final String SERVER_PROVIDER_INFO = "http://v3.bdn.parabot.org/api/bot/list/%s?latest=true";
|
public static final String SERVER_PROVIDER_INFO = "http://v3.bdn.parabot.org/api/bot/list/%s?latest=true";
|
||||||
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
|
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
|
||||||
public static final String API_DOWNLOAD_BOT = "http://v3.bdn.parabot.org/api/bot/download/client";
|
|
||||||
public static final String DOWNLOAD_BOT = "http://bdn.parabot.org/versions/";
|
|
||||||
public static final String DATA_API = "http://bdn.parabot.org/api/v2/data/";
|
public static final String DATA_API = "http://bdn.parabot.org/api/v2/data/";
|
||||||
public static final String ITEM_API = DATA_API + "items/";
|
public static final String ITEM_API = DATA_API + "items/";
|
||||||
|
|
||||||
|
|||||||
@@ -27,22 +27,11 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public class Core {
|
public class Core {
|
||||||
|
|
||||||
private static final Version currentVersion = Configuration.BOT_VERSION;
|
|
||||||
private static int quickLaunchByUuid = -1; // used like -server, but denoted by an Int rather than the server name
|
private static int quickLaunchByUuid = -1; // used like -server, but denoted by an Int rather than the server name
|
||||||
private static boolean verbose;
|
private static boolean verbose;
|
||||||
private static boolean dump;
|
private static boolean dump;
|
||||||
private static boolean validate = true;
|
|
||||||
private static boolean secure = true;
|
private static boolean secure = true;
|
||||||
|
|
||||||
public static void disableValidation() {
|
|
||||||
Core.validate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasValidation() {
|
|
||||||
return validate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getQuickLaunchByUuid() {
|
public static int getQuickLaunchByUuid() {
|
||||||
return quickLaunchByUuid;
|
return quickLaunchByUuid;
|
||||||
}
|
}
|
||||||
@@ -113,128 +102,6 @@ public class Core {
|
|||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Compares the latest version from the BDN and the current version
|
|
||||||
*
|
|
||||||
* @return True if the current version is equal or higher than the latest version, false if lower than the latest version
|
|
||||||
*/
|
|
||||||
public static boolean validVersion() {
|
|
||||||
String url = String.format(Configuration.COMPARE_VERSION_URL, "client", currentVersion.get());
|
|
||||||
|
|
||||||
BufferedReader br = WebUtil.getReader(url);
|
|
||||||
try {
|
|
||||||
if (br != null) {
|
|
||||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
|
|
||||||
boolean latest = (Boolean) object.get("result");
|
|
||||||
if (!latest) {
|
|
||||||
Directories.clearCache();
|
|
||||||
}
|
|
||||||
Core.verbose("Local version: " + currentVersion.get() + ". " + (latest ? "This is up to date." : "This is Out Of Date. Cache will be cleared."));
|
|
||||||
return latest;
|
|
||||||
}
|
|
||||||
} catch (IOException | ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (br != null) {
|
|
||||||
br.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void downloadNewVersion() {
|
|
||||||
UILog.log("Updates",
|
|
||||||
"Please download the newest version of Parabot at "
|
|
||||||
+ Configuration.DOWNLOAD_BOT + (currentVersion.isNightly() ? Configuration.NIGHTLY_APPEND : ""),
|
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
URI uri = URI.create(Configuration.API_DOWNLOAD_BOT + (currentVersion.isNightly() ? Configuration.NIGHTLY_APPEND : ""));
|
|
||||||
try {
|
|
||||||
Desktop.getDesktop().browse(uri);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Connection Error",
|
|
||||||
"Error", JOptionPane.ERROR_MESSAGE);
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks for updates.
|
|
||||||
*
|
|
||||||
* @return <b>true</b> if no update is required, otherwise <b>false</b>.
|
|
||||||
*/
|
|
||||||
public static boolean isValid() {
|
|
||||||
Core.verbose("Checking for updates...");
|
|
||||||
validateCache();
|
|
||||||
|
|
||||||
if (validate) {
|
|
||||||
if (validVersion() && checksumValid()) {
|
|
||||||
Core.verbose("No updates available.");
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
Core.verbose("Updates available...");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Core.verbose("Validation disabled");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alerts the user that there is a new version
|
|
||||||
*/
|
|
||||||
public static int newVersionAlert() {
|
|
||||||
return UILog.alert("Parabot Update", "There's a new version of Parabot! \nDo you wish to download it?\n\nThe current version could have some problems!", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks the version of the bot using a checksum of the jar comparison against checksum given by the website
|
|
||||||
*
|
|
||||||
* @return <b>true</b> if no new version is found, otherwise <b>false</b>.
|
|
||||||
*/
|
|
||||||
private static boolean checksumValid() {
|
|
||||||
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
|
|
||||||
if (f.isFile()) {
|
|
||||||
try {
|
|
||||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
||||||
File location = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
|
|
||||||
if (location.exists()) {
|
|
||||||
FileInputStream fis = new FileInputStream(location);
|
|
||||||
byte[] dataBytes = new byte[1024];
|
|
||||||
|
|
||||||
int nread;
|
|
||||||
|
|
||||||
while ((nread = fis.read(dataBytes)) != -1) {
|
|
||||||
md.update(dataBytes, 0, nread);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] mdbytes = md.digest();
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (byte mdbyte : mdbytes) {
|
|
||||||
sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
String result;
|
|
||||||
if ((result = WebUtil.getContents(String.format(Configuration.COMPARE_CHECKSUM_URL, "client", currentVersion.get()), "checksum=" + URLEncoder.encode(sb.toString(), "UTF-8"))) != null) {
|
|
||||||
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(result);
|
|
||||||
boolean upToDate = (boolean) object.get("result");
|
|
||||||
Core.verbose("Local checksum: " + URLEncoder.encode(sb.toString(), "UTF-8") + ". " + (upToDate ? "This matches BDN and is up to date." : "BDN mismatch, must be Out Of Date."));
|
|
||||||
return upToDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NoSuchAlgorithmException | ParseException | IOException | URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that removes the cache contents after 3 days
|
* Method that removes the cache contents after 3 days
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user