From f67d0ce9851c5591ba555ff98425181f3c57acf9 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 22:12:18 -0500 Subject: [PATCH 01/19] [TASK] Formatted code --- .../environment/servers/ServerProvider.java | 49 ++++++++++--------- .../servers/loader/ServerLoader.java | 5 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/parabot/environment/servers/ServerProvider.java b/src/main/java/org/parabot/environment/servers/ServerProvider.java index ae9b5ba..78ca006 100644 --- a/src/main/java/org/parabot/environment/servers/ServerProvider.java +++ b/src/main/java/org/parabot/environment/servers/ServerProvider.java @@ -77,7 +77,7 @@ public abstract class ServerProvider implements Opcodes { return; } - HookParser parser = hookFile.getParser(); + HookParser parser = hookFile.getParser(); Injectable[] injectables = parser.getInjectables(); if (injectables == null) { @@ -92,17 +92,18 @@ public abstract class ServerProvider implements Opcodes { index++; } } catch (NullPointerException ex) { - if(!crashed) { + if (!crashed) { Injectable inj = injectables[index]; - int resp = UILog.alert("Outdated client", "This server currently has outdated hooks, please report it to a member of the Parabot staff.\r\n\r\n" + - "Broken hook:\r\n"+inj, new Object[]{"Close", "Report here..."}, JOptionPane.ERROR_MESSAGE); + int resp = UILog.alert("Outdated client", "This server currently has outdated hooks, please report it to the Parabot staff.\r\n\r\n" + + "Broken hook:\r\n" + inj, new Object[]{ "Close", "Report here..." }, JOptionPane.ERROR_MESSAGE); - if(resp == 1) { + if (resp == 1) { URI uri = URI.create(Configuration.COMMUNITY_PAGE + "forum/135-reports/"); try { Desktop.getDesktop().browse(uri); - } catch (IOException ignore) {} + } catch (IOException ignore) { + } } } crashed = true; @@ -112,20 +113,6 @@ public abstract class ServerProvider implements Opcodes { Context.getInstance().setHookParser(parser); } - private HookFile fetchHookFile() { - HookFile hookFile = getHookFile(); - if (hookFile != null) { - return hookFile; - } - - URL hookLocation = getHooks(); - if (hookLocation == null) { - return null; - } - - return new HookFile(hookLocation, HookFile.TYPE_XML); - } - /** * Add custom items to the bot menu bar * @@ -156,16 +143,16 @@ public abstract class ServerProvider implements Opcodes { public void initMouse() { final Context context = Context.getInstance(); - final Applet applet = context.getApplet(); - final Mouse mouse = new Mouse(applet); + final Applet applet = context.getApplet(); + final Mouse mouse = new Mouse(applet); applet.addMouseListener(mouse); applet.addMouseMotionListener(mouse); context.setMouse(mouse); } public void initKeyboard() { - final Context context = Context.getInstance(); - final Applet applet = context.getApplet(); + final Context context = Context.getInstance(); + final Applet applet = context.getApplet(); final Keyboard keyboard = new Keyboard(applet); applet.addKeyListener(keyboard); context.setKeyboard(keyboard); @@ -191,4 +178,18 @@ public abstract class ServerProvider implements Opcodes { } + private HookFile fetchHookFile() { + HookFile hookFile = getHookFile(); + if (hookFile != null) { + return hookFile; + } + + URL hookLocation = getHooks(); + if (hookLocation == null) { + return null; + } + + return new HookFile(hookLocation, HookFile.TYPE_XML); + } + } diff --git a/src/main/java/org/parabot/environment/servers/loader/ServerLoader.java b/src/main/java/org/parabot/environment/servers/loader/ServerLoader.java index 4ed965b..7f214a6 100644 --- a/src/main/java/org/parabot/environment/servers/loader/ServerLoader.java +++ b/src/main/java/org/parabot/environment/servers/loader/ServerLoader.java @@ -29,8 +29,9 @@ public class ServerLoader extends ASMClassLoader { public final String[] getServerClassNames() { final List classNames = new ArrayList(); for (ClassNode c : classPath.classes.values()) { - if (c.superName.replace('/', '.').equals( - ServerProvider.class.getName())) { + if (c.superName + .replace('/', '.') + .equals(ServerProvider.class.getName())) { classNames.add(c.name.replace('/', '.')); } } From 00b09a64f54418929ce0538e774280f97bdd524f Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:07:31 -0500 Subject: [PATCH 02/19] [CLEANUP] Formatted code --- .../executers/LocalPublicServerExecuter.java | 10 +++++----- .../servers/executers/LocalServerExecuter.java | 4 ++-- .../servers/executers/PublicServerExecuter.java | 17 ++++++++--------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/parabot/environment/servers/executers/LocalPublicServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/LocalPublicServerExecuter.java index 3f06b14..b52574c 100644 --- a/src/main/java/org/parabot/environment/servers/executers/LocalPublicServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/LocalPublicServerExecuter.java @@ -24,9 +24,9 @@ import java.net.URL; * @author JKetelaar */ public class LocalPublicServerExecuter extends ServerExecuter { - private String serverName; - private String serverUrl; - private String providerUrl; + private String serverName; + private String serverUrl; + private String providerUrl; private ServerProviderInfo serverProviderInfo; public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) { @@ -80,8 +80,8 @@ public class LocalPublicServerExecuter extends ServerExecuter { BuildPath.add(destination.toURI().toURL()); - ServerLoader serverLoader = new ServerLoader(classPath); - final String[] classNames = serverLoader.getServerClassNames(); + ServerLoader serverLoader = new ServerLoader(classPath); + final String[] classNames = serverLoader.getServerClassNames(); if (classNames.length == 0) { UILog.log( "Error", diff --git a/src/main/java/org/parabot/environment/servers/executers/LocalServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/LocalServerExecuter.java index 1ff3a40..f509ecc 100644 --- a/src/main/java/org/parabot/environment/servers/executers/LocalServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/LocalServerExecuter.java @@ -16,8 +16,8 @@ import java.net.MalformedURLException; */ public class LocalServerExecuter extends ServerExecuter { private final Constructor serverProviderConstructor; - private ClassPath classPath; - private String serverName; + private ClassPath classPath; + private String serverName; public LocalServerExecuter(Constructor serverProviderConstructor, ClassPath classPath, final String serverName) { diff --git a/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java index a316586..b8d2f77 100644 --- a/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/PublicServerExecuter.java @@ -36,10 +36,9 @@ public class PublicServerExecuter extends ServerExecuter { } }; - private String serverName; - - private PBLocalPreferences settings; private final String cacheVersionKey = "cachedProviderVersion"; + private String serverName; + private PBLocalPreferences settings; public PublicServerExecuter(final String serverName) { this.serverName = serverName; @@ -58,14 +57,14 @@ public class PublicServerExecuter extends ServerExecuter { Core.verbose("Downloading: " + jarUrl + " ..."); String providerVersion = serverProviderInfo.getProviderVersion(); - if(providerVersion == null) { + if (providerVersion == null) { providerVersion = "error"; } - settings = new PBLocalPreferences(serverProviderInfo.getClientCRC32()+".json"); - if(settings.getSetting(cacheVersionKey) != null) { + settings = new PBLocalPreferences(serverProviderInfo.getClientCRC32() + ".json"); + if (settings.getSetting(cacheVersionKey) != null) { Core.verbose(String.format("Latest provider version: %s, local provider version: %s", settings.getSetting(cacheVersionKey), providerVersion)); - if(!settings.getSetting(cacheVersionKey).equals(providerVersion)) { + if (!settings.getSetting(cacheVersionKey).equals(providerVersion)) { Core.verbose("Local provider outdated, clearing cache."); Directories.clearCache(); } @@ -88,8 +87,8 @@ public class PublicServerExecuter extends ServerExecuter { BuildPath.add(destination.toURI().toURL()); - ServerLoader serverLoader = new ServerLoader(classPath); - final String[] classNames = serverLoader.getServerClassNames(); + ServerLoader serverLoader = new ServerLoader(classPath); + final String[] classNames = serverLoader.getServerClassNames(); if (classNames == null || classNames.length == 0) { UILog.log( "Error", From a32c3fa30b3bab625caa35f3694df090d7f8691b Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:07:45 -0500 Subject: [PATCH 03/19] [TASK] Added UILog with default value option --- src/main/java/org/parabot/core/ui/utils/UILog.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/org/parabot/core/ui/utils/UILog.java b/src/main/java/org/parabot/core/ui/utils/UILog.java index d1261f6..ffa4552 100644 --- a/src/main/java/org/parabot/core/ui/utils/UILog.java +++ b/src/main/java/org/parabot/core/ui/utils/UILog.java @@ -39,4 +39,9 @@ public class UILog { return JOptionPane.showOptionDialog(null, message, title, JOptionPane.YES_NO_CANCEL_OPTION, messageType, null, options, null); } + + public static int alert(final String title, final String message, Object[] options, int initialValue, int messageType) { + return JOptionPane.showOptionDialog(null, message, title, + JOptionPane.YES_NO_CANCEL_OPTION, messageType, null, options, initialValue); + } } From 32ce5c0cdaea4cd2d5d2c65d4b69cc1ea2776fd8 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:07:54 -0500 Subject: [PATCH 04/19] [FEATURE] Added exception handlers --- .../handlers/exceptions/ExceptionHandler.java | 88 ++++++++++++ .../exceptions/FileExceptionHandler.java | 125 ++++++++++++++++++ .../servers/executers/ServerExecuter.java | 10 +- 3 files changed, 221 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/parabot/environment/handlers/exceptions/ExceptionHandler.java create mode 100644 src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java diff --git a/src/main/java/org/parabot/environment/handlers/exceptions/ExceptionHandler.java b/src/main/java/org/parabot/environment/handlers/exceptions/ExceptionHandler.java new file mode 100644 index 0000000..198a55a --- /dev/null +++ b/src/main/java/org/parabot/environment/handlers/exceptions/ExceptionHandler.java @@ -0,0 +1,88 @@ +package org.parabot.environment.handlers.exceptions; + +/** + * Class to be implemented that allows multiple types of exception handlers + */ +public abstract class ExceptionHandler implements Thread.UncaughtExceptionHandler { + /** + * The name of the exception handler + */ + private final String name; + + /** + * The status of the exception handler; Defines if the exception handler is enabled or disabled + */ + private boolean enabled = true; + + /** + * The type the handler is meant for + */ + private ExceptionType exceptionType; + + public ExceptionHandler(String name, ExceptionType exceptionType) { + this.name = name; + this.exceptionType = exceptionType; + } + + @Override + public void uncaughtException(Thread t, Throwable e) { + this.handle(e); + } + + /** + * Writes the exception to class extending this abstract class + * + * @param e + */ + public abstract void handle(Throwable e); + + /** + * Returns if the exception handler is enabled or disabled + * + * @return + */ + public boolean isEnabled() { + return enabled; + } + + /** + * Sets the enabled status of the exception handler + * + * @param enabled + * + * @return + */ + public ExceptionHandler setEnabled(boolean enabled) { + this.enabled = enabled; + return this; + } + + public ExceptionType getExceptionType() { + return exceptionType; + } + + public ExceptionHandler setExceptionType(ExceptionType exceptionType) { + this.exceptionType = exceptionType; + return this; + } + + public String getName() { + return name; + } + + public enum ExceptionType { + SERVER("Server"), + SCRIPT("Script"), + CLIENT("Client"); + + private String name; + + ExceptionType(String name) { + this.name = name; + } + + public String getName() { + return name; + } + } +} diff --git a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java new file mode 100644 index 0000000..f32f105 --- /dev/null +++ b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java @@ -0,0 +1,125 @@ +package org.parabot.environment.handlers.exceptions; + +import org.parabot.core.Directories; +import org.parabot.core.ui.utils.UILog; +import org.parabot.environment.api.utils.FileUtil; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.io.IOException; + +/** + * Writes exceptions to a file and reports the file location back to the user + */ +public class FileExceptionHandler extends ExceptionHandler { + /** + * Directory where the reports get written to + */ + private final File reportsDirectory; + + /** + * Defines if the alert should popup during this client instance again + */ + private boolean ignored = false; + + /** + * Initializes the exception handler and ensures the reports directory is created and writable + */ + public FileExceptionHandler(ExceptionType exceptionType) { + super("File exception handler", exceptionType); + + this.reportsDirectory = new File(Directories.getWorkspace(), "reports"); + if (!this.reportsDirectory.exists() || !this.reportsDirectory.isDirectory()) { + this.reportsDirectory.mkdir(); + } + + this.cleanOldErrors(); + } + + @Override + public void handle(Throwable e) { + File report = new File(this.reportsDirectory, "report-" + (System.currentTimeMillis() / 1000) + ".txt"); + try { + report.createNewFile(); + + StringBuilder reportContent = new StringBuilder(); + reportContent.append(e.getMessage() + "\n\n"); + + for (StackTraceElement stackTraceElement : e.getStackTrace()) { + reportContent.append(stackTraceElement); + } + + FileUtil.writeFileContents(report, reportContent.toString()); + + if (!ignored) { + displayAlert(report); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public boolean isIgnored() { + return ignored; + } + + public FileExceptionHandler setIgnored(boolean ignored) { + this.ignored = ignored; + return this; + } + + public File getReportsDirectory() { + return reportsDirectory; + } + + /** + * Displays the dialog of the alert + * + * @param report + */ + private void displayAlert(File report) { + int response = UILog.alert( + "Error occurred", + "We are sorry to inform you that an error occurred within Parabot.\n\n" + + "The error has been written to a report file.\n" + + "Please report the error to the Parabot staff with as much information as possible.", + new Object[]{ + "Close", + "Open report", + "Ignore " + this.getExceptionType().getName().toLowerCase() + " errors" }, + 1, + JOptionPane.WARNING_MESSAGE + ); + + switch (response) { + case 1: + try { + Desktop.getDesktop().open(report); + } catch (Exception ex) { + ex.printStackTrace(); + } + break; + case 2: + ignored = true; + break; + + } + } + + /** + * Remove errors older than 24 hours + */ + private void cleanOldErrors() { + File[] reports = this.reportsDirectory.listFiles(); + if (reports != null) { + for (File report : reports) { + if (report.isFile()) { + if ((System.currentTimeMillis() - report.lastModified()) / 1000 > 60 * 60 * 24) { + report.delete(); + } + } + } + } + } +} diff --git a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java index cae7c5f..1fd6df9 100644 --- a/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java +++ b/src/main/java/org/parabot/environment/servers/executers/ServerExecuter.java @@ -3,6 +3,8 @@ package org.parabot.environment.servers.executers; import org.parabot.core.Context; import org.parabot.core.ui.BotUI; import org.parabot.core.ui.components.PaintComponent; +import org.parabot.environment.handlers.exceptions.ExceptionHandler; +import org.parabot.environment.handlers.exceptions.FileExceptionHandler; import org.parabot.environment.servers.ServerProvider; /** @@ -15,7 +17,7 @@ public abstract class ServerExecuter { public abstract void run(); public void finalize(final ServerProvider provider, final String serverName) { - new Thread(new Runnable() { + Thread serverThread = new Thread(new Runnable() { @Override public void run() { try { @@ -30,7 +32,11 @@ public abstract class ServerExecuter { t.printStackTrace(); } } - }).start(); + }); + + serverThread.setUncaughtExceptionHandler(new FileExceptionHandler(ExceptionHandler.ExceptionType.SERVER)); + + serverThread.start(); } } From 19bb75f09b87874d137c907947c319d5f57fa7fd Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:12:22 -0500 Subject: [PATCH 05/19] [TASK] Added Unit test --- .../exceptions/FileExceptionHandler.java | 4 +-- .../org/parabot/FileExceptionHandlerTest.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/test/java/org/parabot/FileExceptionHandlerTest.java diff --git a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java index f32f105..1f3df55 100644 --- a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java +++ b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java @@ -46,8 +46,8 @@ public class FileExceptionHandler extends ExceptionHandler { StringBuilder reportContent = new StringBuilder(); reportContent.append(e.getMessage() + "\n\n"); - for (StackTraceElement stackTraceElement : e.getStackTrace()) { - reportContent.append(stackTraceElement); + for (int i = 0; i < e.getStackTrace().length; i++) { + reportContent.append((i > 0 ? " " : "") + e.getStackTrace()[i] + "\n"); } FileUtil.writeFileContents(report, reportContent.toString()); diff --git a/src/test/java/org/parabot/FileExceptionHandlerTest.java b/src/test/java/org/parabot/FileExceptionHandlerTest.java new file mode 100644 index 0000000..f4077ac --- /dev/null +++ b/src/test/java/org/parabot/FileExceptionHandlerTest.java @@ -0,0 +1,28 @@ +package org.parabot; + +import org.junit.Assert; +import org.junit.Test; +import org.parabot.environment.handlers.exceptions.ExceptionHandler; +import org.parabot.environment.handlers.exceptions.FileExceptionHandler; + +import java.io.File; + +public class FileExceptionHandlerTest { + + @Test + public void test() { + FileExceptionHandler serverHandler = new FileExceptionHandler(ExceptionHandler.ExceptionType.SERVER); + serverHandler.setIgnored(true); + + File[] reports = serverHandler.getReportsDirectory().listFiles(); + int reportCount = 0; + if (reports != null) { + reportCount = reports.length; + } + + Exception exception = new Exception("Test"); + serverHandler.handle(exception); + + Assert.assertTrue(serverHandler.getReportsDirectory().listFiles().length > reportCount); + } +} From 223171f03f107ae561d99adcdb77faf772986106 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:28:36 -0500 Subject: [PATCH 06/19] [TASK] Added exception handler to client --- src/main/java/org/parabot/Landing.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index b5ff725..f732797 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -11,10 +11,11 @@ import org.parabot.core.network.proxy.ProxyType; import org.parabot.core.ui.BotUI; import org.parabot.core.ui.ServerSelector; import org.parabot.core.ui.utils.UILog; +import org.parabot.environment.handlers.exceptions.ExceptionHandler; +import org.parabot.environment.handlers.exceptions.FileExceptionHandler; import javax.swing.*; import java.io.File; -import java.io.IOException; /** * Parabot v2.7 @@ -27,7 +28,8 @@ public final class Landing { private static String username; private static String password; - public static void main(String... args) throws IOException { + public static void main(String... args) { + Thread.setDefaultUncaughtExceptionHandler(new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT)); if (Context.getJavaVersion() >= 9) { UILog.log("Parabot", "Parabot doesn't support Java 9+ currently. Please downgrade to Java 8 to ensure Parabot is working correctly."); From 6d0643cd3b7b49803de904c4c7a27d6e3144bc7c Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:28:51 -0500 Subject: [PATCH 07/19] [TASK] Adjusted exception handler unit test --- .../org/parabot/FileExceptionHandlerTest.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/parabot/FileExceptionHandlerTest.java b/src/test/java/org/parabot/FileExceptionHandlerTest.java index f4077ac..7066c7f 100644 --- a/src/test/java/org/parabot/FileExceptionHandlerTest.java +++ b/src/test/java/org/parabot/FileExceptionHandlerTest.java @@ -1,28 +1,39 @@ package org.parabot; -import org.junit.Assert; import org.junit.Test; import org.parabot.environment.handlers.exceptions.ExceptionHandler; import org.parabot.environment.handlers.exceptions.FileExceptionHandler; -import java.io.File; - public class FileExceptionHandlerTest { @Test - public void test() { - FileExceptionHandler serverHandler = new FileExceptionHandler(ExceptionHandler.ExceptionType.SERVER); - serverHandler.setIgnored(true); + public void manualTest() { + FileExceptionHandler handler = new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT); + handler.setIgnored(true); - File[] reports = serverHandler.getReportsDirectory().listFiles(); - int reportCount = 0; - if (reports != null) { - reportCount = reports.length; + Exception exception = new NullPointerException("Manual test"); + handler.handle(exception); + } + + @Test + public void threadHandlerTest() { + FileExceptionHandler handler = new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT); + handler.setIgnored(true); + + Thread thread = new Thread() { + @Override + public void run() throws NullPointerException { + throw new NullPointerException("Thread test"); + } + }; + + thread.setUncaughtExceptionHandler(handler); + thread.start(); + + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + e.printStackTrace(); } - - Exception exception = new Exception("Test"); - serverHandler.handle(exception); - - Assert.assertTrue(serverHandler.getReportsDirectory().listFiles().length > reportCount); } } From 1bb1617721be2da3aa7d49b78fd9f1197a33e891 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:29:03 -0500 Subject: [PATCH 08/19] [TASK] Added exception type to file name --- .../environment/handlers/exceptions/FileExceptionHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java index 1f3df55..793a05f 100644 --- a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java +++ b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java @@ -39,7 +39,7 @@ public class FileExceptionHandler extends ExceptionHandler { @Override public void handle(Throwable e) { - File report = new File(this.reportsDirectory, "report-" + (System.currentTimeMillis() / 1000) + ".txt"); + File report = new File(this.reportsDirectory, "report-" + this.getExceptionType().getName().toLowerCase() + "-" + (System.currentTimeMillis() / 1000) + ".txt"); try { report.createNewFile(); From 40aa30e8687ab19293f050a575b67b6d57929042 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:35:41 -0500 Subject: [PATCH 09/19] [CLEANUP] Formatted code --- .../exceptions/FileExceptionHandler.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java index 793a05f..e72c355 100644 --- a/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java +++ b/src/main/java/org/parabot/environment/handlers/exceptions/FileExceptionHandler.java @@ -13,11 +13,24 @@ import java.io.IOException; * Writes exceptions to a file and reports the file location back to the user */ public class FileExceptionHandler extends ExceptionHandler { + /** + * The default index of all options to be selected when the popup appears + */ + private static final int defaultOptionIndex = 1; + /** * Directory where the reports get written to */ private final File reportsDirectory; + /** + * All possible options to select when the popup appears + */ + private final Object[] options = new Object[]{ + "Close", + "Open report", + "Ignore " + this.getExceptionType().getName().toLowerCase() + " errors" }; + /** * Defines if the alert should popup during this client instance again */ @@ -44,10 +57,14 @@ public class FileExceptionHandler extends ExceptionHandler { report.createNewFile(); StringBuilder reportContent = new StringBuilder(); - reportContent.append(e.getMessage() + "\n\n"); + reportContent.append("Message: ").append(e.getMessage()).append("\n\n"); + reportContent.append(e.toString()).append("\n\n"); for (int i = 0; i < e.getStackTrace().length; i++) { - reportContent.append((i > 0 ? " " : "") + e.getStackTrace()[i] + "\n"); + if (i > 0) { + reportContent.append("\t"); + } + reportContent.append(e.getStackTrace()[i]).append("\n"); } FileUtil.writeFileContents(report, reportContent.toString()); @@ -84,11 +101,8 @@ public class FileExceptionHandler extends ExceptionHandler { "We are sorry to inform you that an error occurred within Parabot.\n\n" + "The error has been written to a report file.\n" + "Please report the error to the Parabot staff with as much information as possible.", - new Object[]{ - "Close", - "Open report", - "Ignore " + this.getExceptionType().getName().toLowerCase() + " errors" }, - 1, + this.options, + defaultOptionIndex, JOptionPane.WARNING_MESSAGE ); From a7141c42682dc83cbb67b53cfb4914265fcc143f Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:36:31 -0500 Subject: [PATCH 10/19] [TASK] Removed exit of Java 9+ --- src/main/java/org/parabot/Landing.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index f732797..c08d80f 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -33,12 +33,11 @@ public final class Landing { if (Context.getJavaVersion() >= 9) { UILog.log("Parabot", "Parabot doesn't support Java 9+ currently. Please downgrade to Java 8 to ensure Parabot is working correctly."); - System.exit(0); } if (!System.getProperty("os.arch").contains("64")) { UILog.log("Parabot", "You are not running a 64-bit version of Java, this might cause the client to lag or crash unexpectedly.\r\n" + - "It's recommended to upgrade to a 64-bit version."); + "It is recommended to upgrade to a 64-bit version."); } parseArgs(args); From f18eb89f2e14b86cff43b1b94778935191665634 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:37:29 -0500 Subject: [PATCH 11/19] [TASK] Added dump when debug is enabled --- src/main/java/org/parabot/Landing.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index c08d80f..469dd9b 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -81,11 +81,11 @@ public final class Landing { switch (arg.toLowerCase()) { case "-createdirs": Directories.validate(); - System.out - .println(TranslationHelper.translate(("DIRECTORIES_CREATED"))); + System.out.println(TranslationHelper.translate(("DIRECTORIES_CREATED"))); System.exit(0); break; case "-debug": + Core.setDump(true); case "-offlinemode": Core.setDebug(true); break; From 67b99604f6cbac35b51fc4160425cb905726184b Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:38:24 -0500 Subject: [PATCH 12/19] [TASK] Added -ignore_updates option --- src/main/java/org/parabot/Landing.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index 469dd9b..06d6899 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -147,6 +147,7 @@ public final class Landing { Core.disableSec(); break; case "-no_validation": + case "-ignore_updates": Core.disableValidation(); break; case "-uuid": From ac337ce599e4e7bfb23d0ed1ab7be04d8687b6c1 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:40:16 -0500 Subject: [PATCH 13/19] [TASK] Added extra parameter for proxy authentication --- src/main/java/org/parabot/Landing.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index 06d6899..a8ae513 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -131,14 +131,9 @@ public final class Landing { break; case "-proxy": ProxyType type = ProxyType.valueOf(args[++i].toUpperCase()); - if (type == null) { - System.err.println(TranslationHelper.translate("INVALID_PROXY_TYPE") + args[i]); - System.exit(1); - return; - } - ProxySocket.setProxy(type, args[++i], - Integer.parseInt(args[++i])); + ProxySocket.setProxy(type, args[++i], Integer.parseInt(args[++i])); break; + case "-proxy_auth": case "-auth": ProxySocket.auth = true; ProxySocket.setLogin(args[++i], args[++i]); From d3b92059379cf95fc59b9406b4b1f248c4fbc493 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:40:44 -0500 Subject: [PATCH 14/19] [CLEANUP] Updated javadocs --- src/main/java/org/parabot/Landing.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index a8ae513..a2c9e68 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -18,10 +18,8 @@ import javax.swing.*; import java.io.File; /** - * Parabot v2.7 - * * @author Everel, JKetelaar, Matt, Dane - * @version 2.7 + * @version 2.8.1 * @see Homepage */ public final class Landing { From 61031f9bce16fc37ad0f6e88ec9dd4b69bb6ffe2 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:41:01 -0500 Subject: [PATCH 15/19] [CLEANUP] Set javadocs to https --- src/main/java/org/parabot/Landing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/parabot/Landing.java b/src/main/java/org/parabot/Landing.java index a2c9e68..c870393 100644 --- a/src/main/java/org/parabot/Landing.java +++ b/src/main/java/org/parabot/Landing.java @@ -20,7 +20,7 @@ import java.io.File; /** * @author Everel, JKetelaar, Matt, Dane * @version 2.8.1 - * @see Homepage + * @see Homepage */ public final class Landing { private static String username; From 7946761711248692d28f63ec18caa3dce4decfe4 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:45:04 -0500 Subject: [PATCH 16/19] [TASK] Changed scope from provided to test for JUnit --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d7c7d90..f755993 100755 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ junit junit 4.12 - provided + test org.parabot From 01d7addd7830275082620a8f8875eae92d5a2f16 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:45:39 -0500 Subject: [PATCH 17/19] [TASK] Adjusted project description --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f755993..97e8f79 100755 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ Parabot client - The only perfect open source (Runescape private server) bot! + The best open-source (Runescape Private Server) bot http://www.parabot.org/ From e7e417aa39b5c2b6b5c924850efaf57318d0e561 Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Tue, 21 May 2019 23:46:32 -0500 Subject: [PATCH 18/19] [BUGFIX] Fixed location of distribution --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 97e8f79..2a0c814 100755 --- a/pom.xml +++ b/pom.xml @@ -191,13 +191,13 @@ false parabot-maven Custom Maven Repository - ftp://maven.parabot.org + ftp://maven.parabot.org/public_html default parabot-maven Frontend Parabot Maven - ftp://maven.parabot.org/docs/${artifactId}/ + ftp://maven.parabot.org/public_html/docs/${artifactId}/ From 3b9f99fbde0393454b8b2426929dd4d499610eaa Mon Sep 17 00:00:00 2001 From: Jeroen Ketelaar Date: Wed, 22 May 2019 00:58:10 -0500 Subject: [PATCH 19/19] [TASK] Added option to add custom Parser --- .../org/parabot/core/parsers/scripts/ScriptParser.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/parabot/core/parsers/scripts/ScriptParser.java b/src/main/java/org/parabot/core/parsers/scripts/ScriptParser.java index a7e5d1f..cbb4ad2 100644 --- a/src/main/java/org/parabot/core/parsers/scripts/ScriptParser.java +++ b/src/main/java/org/parabot/core/parsers/scripts/ScriptParser.java @@ -18,9 +18,10 @@ public abstract class ScriptParser { public static final Map SCRIPT_CACHE = new HashMap<>(); + private static final ArrayList parsers = new ArrayList<>(); + public static ScriptDescription[] getDescriptions() { SCRIPT_CACHE.clear(); - final ArrayList parsers = new ArrayList<>(); if (Core.inLoadLocal()) { parsers.add(new LocalJavaScripts()); parsers.add(new BDNScripts()); @@ -47,6 +48,9 @@ public abstract class ScriptParser { return SORTED_SCRIPT_CACHE.keySet().toArray(new ScriptDescription[SORTED_SCRIPT_CACHE.size()]); } - public abstract void execute(); + public static final void addParser(ScriptParser parser) { + parsers.add(parser); + } + public abstract void execute(); } \ No newline at end of file