diff --git a/parabotv2/src/org/parabot/Landing.java b/parabotv2/src/org/parabot/Landing.java
index a2d17cb..31e10f8 100644
--- a/parabotv2/src/org/parabot/Landing.java
+++ b/parabotv2/src/org/parabot/Landing.java
@@ -5,50 +5,86 @@ import javax.swing.UIManager;
import org.parabot.core.Core;
import org.parabot.core.Directories;
+import org.parabot.core.forum.AccountManager;
+import org.parabot.core.ui.LoginUI;
import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.utils.UILog;
/**
* Parabot v2
*
- * @author Clisprail (Parnassian)
+ * @author Everel/Parnassian
* @author Matt, Dane
- * @version 2.0
+ * @version 2.01
*/
public final class Landing {
+ // forum account
+ private static String username = null;
+ private static String password = null;
public static void main(String... args) {
parseArgs(args);
+
+ Core.verbose("Debug mode: " + Core.inDebugMode());
+
try {
+ Core.verbose("Setting look and feel: "
+ + UIManager.getSystemLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Throwable t) {
t.printStackTrace();
}
- Directories.validate();
- if(!Core.inDebugMode()) {
- UILog.log("Error", "You can only run parabot in debug mode.", JOptionPane.ERROR_MESSAGE);
+
+ if (!Core.inDebugMode() && !Core.isValid()) {
+ UILog.log(
+ "Updates",
+ "Please download the newest version of parabot at http://www.parabot.org/",
+ JOptionPane.INFORMATION_MESSAGE);
return;
}
- ServerSelector.getInstance();
+
+ Core.verbose("Validating directories...");
+ Directories.validate();
+ Core.verbose("Validating account manager...");
+ AccountManager.validate();
+
+ if (username != null && password != null) {
+ new LoginUI(username, password);
+ username = null;
+ password = null;
+ return;
+ }
+
+ Core.verbose("Starting login gui...");
+ new LoginUI().setVisible(true);
}
-
+
private static void parseArgs(String... args) {
- for(int i = 0; i < args.length; i++) {
- final String arg = args[i];
- switch(arg) {
+ for (int i = 0; i < args.length; i++) {
+ final String arg = args[i].toLowerCase();
+ switch (arg) {
case "-createdirs":
Directories.validate();
- System.out.println("Directories created, you can now run parabot.");
+ System.out
+ .println("Directories created, you can now run parabot.");
System.exit(0);
break;
case "-debug":
Core.setDebug(true);
break;
+ case "-v":
+ case "-verbose":
+ Core.setVerbose(true);
+ break;
case "-server":
ServerSelector.initServer = args[++i];
break;
+ case "-login":
+ username = args[++i];
+ password = args[++i];
+ break;
}
-
+
}
}
diff --git a/parabotv2/src/org/parabot/core/Configuration.java b/parabotv2/src/org/parabot/core/Configuration.java
new file mode 100644
index 0000000..db20979
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/Configuration.java
@@ -0,0 +1,18 @@
+package org.parabot.core;
+
+/**
+ *
+ * @author Everel
+ *
+ */
+public class Configuration {
+ public static final String LOGIN_SERVER = "http://www.parabot.org/community/api/login.php?username=%s&password=%s";
+ public static final String SDN_SCRIPTS = "http://sdn.parabot.org/scripts.php?user=%s";
+ public static final String GET_SDN_SCRIPT = "http://sdn.parabot.org/getscript.php?user=%s&pass=%s&scriptid=%d";
+ public static final String GET_SERVER_PROVIDERS = "http://sdn.parabot.org/list/providers.php";
+ public static final String GET_SERVER_PROVIDER = "http://sdn.parabot.org/providers/%s";
+ public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
+
+ public static final double BOT_VERSION = 2.01;
+
+}
diff --git a/parabotv2/src/org/parabot/core/Context.java b/parabotv2/src/org/parabot/core/Context.java
index 707e577..6d49fbc 100644
--- a/parabotv2/src/org/parabot/core/Context.java
+++ b/parabotv2/src/org/parabot/core/Context.java
@@ -6,7 +6,6 @@ import java.util.HashMap;
import java.util.TimerTask;
import org.parabot.core.asm.ASMClassLoader;
-import org.parabot.core.bot.loader.BotLoader;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.paint.PaintDebugger;
import org.parabot.core.parsers.HookParser;
@@ -21,7 +20,7 @@ import org.parabot.environment.servers.ServerProvider;
/**
* Game context
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Context {
@@ -53,6 +52,7 @@ public class Context {
this.serverProvider = serverProvider;
id++;
this.classPath = new ClassPath();
+ classLoader = new ASMClassLoader(classPath);
}
/**
@@ -69,13 +69,8 @@ public class Context {
return threadGroups.values().iterator().next();
}
- /**
- * Sets the ServerProvider class loader
- *
- * @param serverEnvironment
- */
- public void setEnvironment(ASMClassLoader serverEnvironment) {
- classLoader = new BotLoader(classPath, serverEnvironment);
+ public void setEnvironment() {
+ classLoader = new ASMClassLoader(classPath);
}
/**
@@ -157,12 +152,18 @@ public class Context {
* Loads the game
*/
public void load() {
+ Core.verbose("Parsing server jar...");
serverProvider.parseJar();
+ Core.verbose("Done.");
+ Core.verbose("Injecting hooks...");
serverProvider.injectHooks();
+ Core.verbose("Done.");
+ Core.verbose("Fetching game applet...");;
gameApplet = serverProvider.fetchApplet();
if (getClient() == null) {
setClientInstance(gameApplet);
}
+ Core.verbose("Applet fetched.");
serverProvider.addMenuItems(BotUI.getInstance().getJMenuBar());
BotUI.getInstance().validate();
final GamePanel panel = GamePanel.getInstance();
@@ -176,8 +177,12 @@ public class Context {
gameApplet.setBounds(0, 0, 765, 503);
}
}, 1000);
+ Core.verbose("Initializing mouse...");
serverProvider.initMouse();
+ Core.verbose("Done.");
+ Core.verbose("Initializing keyboard...");
serverProvider.initKeyboard();
+ Core.verbose("Done.");
}
/**
@@ -190,7 +195,7 @@ public class Context {
}
/**
- * Gets class loader from this context
+ * Gets class loader of server from this context
*
* @return class loader
*/
diff --git a/parabotv2/src/org/parabot/core/Core.java b/parabotv2/src/org/parabot/core/Core.java
index de13b30..ae8f42f 100644
--- a/parabotv2/src/org/parabot/core/Core.java
+++ b/parabotv2/src/org/parabot/core/Core.java
@@ -1,23 +1,86 @@
package org.parabot.core;
+import java.io.BufferedReader;
+import java.io.IOException;
+
+import org.parabot.environment.api.utils.WebUtil;
+
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Core {
private static boolean debug = false;
+ private static boolean verbose = false;
- public static void setDebug(boolean debug) {
+ /**
+ * Enabled debug mode
+ *
+ * @param debug
+ */
+ public static void setDebug(final boolean debug) {
Core.debug = debug;
}
/**
- * @return if the botclient is in debug mode.
+ * @return if the client is in debug mode.
*/
public static boolean inDebugMode() {
return debug;
}
+ /**
+ * @return if the client is in verbose mode.
+ */
+ public static boolean inVerboseMode() {
+ return verbose;
+ }
+
+ /**
+ * Sets verbose mode
+ *
+ * @param verbose
+ * - enabled
+ */
+ public static void setVerbose(final boolean verbose) {
+ Core.verbose = verbose;
+ }
+
+ public static void verbose(final String line) {
+ if (verbose) {
+ System.out.println(line);
+ }
+ }
+
+ /**
+ * Checks for updates.
+ *
+ * @return true if no update is required, otherwise false.
+ */
+ public static boolean isValid() {
+ Core.verbose("Checking for updates...");
+ BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION);
+ try {
+ double version = Double.parseDouble(br.readLine());
+ if (Configuration.BOT_VERSION == version) {
+ Core.verbose("No updates available.");
+ return true;
+ }
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ } finally {
+ try {
+ br.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ Core.verbose("Updates available...");
+ return false;
+ }
+
}
diff --git a/parabotv2/src/org/parabot/core/Directories.java b/parabotv2/src/org/parabot/core/Directories.java
index 2a94a51..6deaa7a 100644
--- a/parabotv2/src/org/parabot/core/Directories.java
+++ b/parabotv2/src/org/parabot/core/Directories.java
@@ -13,7 +13,7 @@ import org.parabot.environment.OperatingSystem;
/**
*
- * @author Clisprail
+ * @author Everel
* @author Matt
*
*/
@@ -31,6 +31,7 @@ public class Directories {
cached.put("Root", new File(System.getProperty("user.home")));
}
+ Core.verbose("Caching directories...");
cached.put("Root", getDefaultDirectory());
cached.put("Workspace", new File(cached.get("Root"), "/Parabot/"));
cached.put("Sources", new File(cached.get("Root"), "/Parabot/scripts/sources/"));
@@ -38,6 +39,8 @@ public class Directories {
cached.put("Resources", new File(cached.get("Root"), "/Parabot/scripts/resources/"));
cached.put("Settings", new File(cached.get("Root"), "/Parabot/settings/"));
cached.put("Servers", new File(cached.get("Root"), "/Parabot/servers/"));
+ cached.put("Cache", new File(cached.get("Root"), "/Parabot/cache/"));
+ Core.verbose("Directories cached.");
}
/**
@@ -102,6 +105,15 @@ public class Directories {
public static File getServerPath() {
return cached.get("Servers");
}
+
+ /**
+ * Returns the Parabot cache folder.
+ *
+ * @return
+ */
+ public static File getCachePath() {
+ return cached.get("Cache");
+ }
/**
* Validates all directories and makes them if necessary
@@ -118,10 +130,15 @@ public class Directories {
files.add(getScriptSourcesPath());
files.add(getScriptCompiledPath());
files.add(getResourcesPath());
+ files.add(getCachePath());
while (files.size() > 0) {
final File file = files.poll();
if (!file.exists()) {
+ Core.verbose("Generating directory: " + file.getAbsolutePath());
file.mkdirs();
+ if(!file.exists()) {
+ System.err.println("Failed to make directory: " + file.getAbsolutePath());
+ }
}
}
}
diff --git a/parabotv2/src/org/parabot/core/WebConstants.java b/parabotv2/src/org/parabot/core/WebConstants.java
deleted file mode 100644
index f5cf97b..0000000
--- a/parabotv2/src/org/parabot/core/WebConstants.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package org.parabot.core;
-
-public class WebConstants {
- public static final String HOME = "http://parnassian.host56.com/";
- public static final String SERVER_MANIFEST = HOME + "servers/manifest.dat";
-
-}
diff --git a/parabotv2/src/org/parabot/core/asm/ASMClassLoader.java b/parabotv2/src/org/parabot/core/asm/ASMClassLoader.java
index 15d891b..052952c 100644
--- a/parabotv2/src/org/parabot/core/asm/ASMClassLoader.java
+++ b/parabotv2/src/org/parabot/core/asm/ASMClassLoader.java
@@ -14,6 +14,12 @@ import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
import org.parabot.core.classpath.ClassPath;
+/**
+ *
+ * @author Everel
+ * @author Matt
+ *
+ */
public class ASMClassLoader extends ClassLoader {
private Map> classCache = new HashMap>();
diff --git a/parabotv2/src/org/parabot/core/asm/ASMUtils.java b/parabotv2/src/org/parabot/core/asm/ASMUtils.java
index e62bf27..a71fc4f 100644
--- a/parabotv2/src/org/parabot/core/asm/ASMUtils.java
+++ b/parabotv2/src/org/parabot/core/asm/ASMUtils.java
@@ -1,33 +1,104 @@
package org.parabot.core.asm;
+import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.MethodNode;
import org.parabot.core.Context;
/**
*
- * @author Clisprail
- *
+ * @author Everel
+ *
*/
-public class ASMUtils {
-
+public class ASMUtils implements Opcodes {
+
public static FieldNode getField(ClassNode node, String fieldName) {
- for(final FieldNode fieldNode : node.fields) {
- if(fieldNode.name.equals(fieldName)) {
+ for (final FieldNode fieldNode : node.fields) {
+ if (fieldNode.name.equals(fieldName)) {
return fieldNode;
}
}
return null;
}
-
+
public static ClassNode getClass(String className) {
Context context = Context.resolve();
- for(ClassNode node : context.getClassPath().classes.values()) {
- if(node.name.equals(className)) {
+ for (ClassNode node : context.getClassPath().classes.values()) {
+ if (node.name.equals(className)) {
return node;
}
}
return null;
}
+ public static MethodNode getMethod(final String className,
+ final String methodName, final String methodDesc) {
+ return getMethod(getClass(className), methodName, methodDesc);
+ }
+
+ public static MethodNode getMethod(final ClassNode location,
+ final String methodName, final String methodDesc) {
+ for (MethodNode mn : location.methods) {
+ if (mn.name.equals(methodName) && mn.desc.equals(methodDesc)) {
+ return mn;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return right opcode for desc
+ *
+ * @param desc
+ * @return return opcode
+ */
+ public static int getReturnOpcode(String desc) {
+ desc = desc.substring(desc.indexOf("L") + 1);
+ if (desc.length() > 1) {
+ return ARETURN;
+ }
+ final char c = desc.charAt(0);
+ switch (c) {
+ case 'I':
+ case 'Z':
+ case 'B':
+ case 'S':
+ case 'C':
+ return IRETURN;
+ case 'J':
+ return LRETURN;
+ case 'F':
+ return FRETURN;
+ case 'D':
+ return DRETURN;
+ case 'V': // void, method desc
+ return RETURN;
+ }
+ throw new RuntimeException("Wrong desc type: " + c);
+ }
+
+ public static int getLoadOpcode(String desc) {
+ desc = desc.substring(desc.indexOf("L") + 1);
+ if (desc.length() > 1) {
+ return ALOAD;
+ }
+ final char c = desc.charAt(0);
+ switch (c) {
+ case 'I':
+ case 'Z':
+ case 'B':
+ case 'S':
+ case 'C':
+ return ILOAD;
+ case 'J':
+ return LLOAD;
+ case 'F':
+ return FLOAD;
+ case 'D':
+ return DLOAD;
+ }
+ throw new RuntimeException("eek " + c);
+ }
+
}
diff --git a/parabotv2/src/org/parabot/core/asm/Injector.java b/parabotv2/src/org/parabot/core/asm/Injector.java
deleted file mode 100644
index e8b38cc..0000000
--- a/parabotv2/src/org/parabot/core/asm/Injector.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package org.parabot.core.asm;
-
-public class Injector {
-
-}
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddCallbackAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddCallbackAdapter.java
new file mode 100644
index 0000000..995e660
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddCallbackAdapter.java
@@ -0,0 +1,54 @@
+package org.parabot.core.asm.adapters;
+
+import org.objectweb.asm.Label;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Type;
+import org.objectweb.asm.tree.InsnList;
+import org.objectweb.asm.tree.LabelNode;
+import org.objectweb.asm.tree.MethodInsnNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.objectweb.asm.tree.VarInsnNode;
+import org.parabot.core.asm.ASMUtils;
+import org.parabot.core.asm.interfaces.Injectable;
+
+/**
+ *
+ * Injects a callback, invokes a given static method
+ *
+ * @author Everel
+ *
+ */
+public class AddCallbackAdapter implements Injectable, Opcodes {
+ private MethodNode method;
+ private String invokeClass;
+ private String invokeMethod;
+ private String desc;
+ private int[] args;
+
+ public AddCallbackAdapter(final MethodNode method,
+ final String invokeClass, final String invokeMethod,
+ final String desc, final int[] args) {
+ this.method = method;
+ this.invokeClass = invokeClass;
+ this.invokeMethod = invokeMethod;
+ this.desc = desc;
+ this.args = args;
+ }
+
+ @Override
+ public void inject() {
+ final Type[] types = Type.getArgumentTypes(this.method.desc);
+ InsnList inject = new InsnList();
+ Label l0 = new Label();
+ inject.add(new LabelNode(l0));
+ for (int arg : args) {
+ inject.add(new VarInsnNode(ASMUtils.getLoadOpcode(types[arg - 1]
+ .getDescriptor()), arg));
+ }
+ inject.add(new MethodInsnNode(INVOKESTATIC,
+ this.invokeClass, this.invokeMethod,
+ this.desc));
+ this.method.instructions.insert(inject);
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddGetterAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddGetterAdapter.java
index a16776a..6ddb8bb 100644
--- a/parabotv2/src/org/parabot/core/asm/adapters/AddGetterAdapter.java
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddGetterAdapter.java
@@ -7,13 +7,15 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.Core;
+import org.parabot.core.asm.ASMUtils;
import org.parabot.core.asm.interfaces.Injectable;
/**
* Adds a method into a Classnode which returns a field
*
- * @author Clisprail
- *
+ * @author Everel
+ *
*/
public class AddGetterAdapter implements Opcodes, Injectable {
private ClassNode into = null;
@@ -23,18 +25,26 @@ public class AddGetterAdapter implements Opcodes, Injectable {
private String returnDesc = null;
private boolean staticField = false;
private boolean staticMethod = false;
-
+
/**
*
- * @param into - classnode to inject getter method in
- * @param fieldLocation - classnode where field is located
- * @param fieldName - field name to get
- * @param methodName - method name of getter
- * @param returnDesc - return type of method, can be null for default return
- * @param staticMethod - pass true if you want the method to be static
+ * @param into
+ * - classnode to inject getter method in
+ * @param fieldLocation
+ * - classnode where field is located
+ * @param fieldName
+ * - field name to get
+ * @param methodName
+ * - method name of getter
+ * @param returnDesc
+ * - return type of method, can be null for default return
+ * @param staticMethod
+ * - pass true if you want the method to be static
*/
- public AddGetterAdapter(final ClassNode into, final ClassNode fieldLocation, final FieldNode fieldNode,
- final String methodName, final String returnDesc, final boolean staticMethod) {
+ public AddGetterAdapter(final ClassNode into,
+ final ClassNode fieldLocation, final FieldNode fieldNode,
+ final String methodName, final String returnDesc,
+ final boolean staticMethod) {
this.into = into;
this.fieldLocation = fieldLocation;
this.fieldNode = fieldNode;
@@ -43,14 +53,15 @@ public class AddGetterAdapter implements Opcodes, Injectable {
this.staticField = Modifier.isStatic(fieldNode.access);
this.staticMethod = staticMethod;
}
-
+
/**
*
* @param fieldLocation
* @param fieldNode
* @param methodName
*/
- public AddGetterAdapter(final ClassNode fieldLocation, final FieldNode fieldNode, final String methodName) {
+ public AddGetterAdapter(final ClassNode fieldLocation,
+ final FieldNode fieldNode, final String methodName) {
this.into = fieldLocation;
this.fieldLocation = fieldLocation;
this.fieldNode = fieldNode;
@@ -59,57 +70,68 @@ public class AddGetterAdapter implements Opcodes, Injectable {
this.staticField = Modifier.isStatic(fieldNode.access);
this.staticMethod = false;
}
-
-
+
/**
- * Validates if this getter can be injected, if not a runtime exception is thrown
+ * Validates if this getter can be injected, if not a runtime exception is
+ * thrown
*/
public void validate() {
- if(methodName == null) {
+ if (methodName == null) {
throw new RuntimeException("Null method name");
}
- if(into == null) {
+ if (into == null) {
final StringBuilder sb = new StringBuilder();
- sb.append("Into ClassNode is null, at : ").append(methodName).append("()");
+ sb.append("Into ClassNode is null, at : ").append(methodName)
+ .append("()");
throw new RuntimeException(sb.toString());
}
- if(fieldNode == null) {
+ if (fieldNode == null) {
final StringBuilder sb = new StringBuilder();
- sb.append("FieldLocation ClassNode is null, at : ").append(methodName).append("()");
+ sb.append("FieldLocation ClassNode is null, at : ")
+ .append(methodName).append("()");
throw new RuntimeException(sb.toString());
}
- if(fieldNode == null) {
+ if (fieldNode == null) {
final StringBuilder sb = new StringBuilder();
- sb.append("FieldNode is null, at : ").append(methodName).append("()");
+ sb.append("FieldNode is null, at : ").append(methodName)
+ .append("()");
throw new RuntimeException(sb.toString());
}
- for(final MethodNode methodNode : into.methods) {
- if(methodNode.name.equals(methodName)) {
+ for (final MethodNode methodNode : into.methods) {
+ if (methodNode.name.equals(methodName)) {
final Type[] args = Type.getArgumentTypes(methodNode.desc);
- if(args != null && args.length != 0) {
+ if (args != null && args.length != 0) {
continue;
}
final StringBuilder sb = new StringBuilder();
- sb.append("Duplicated method detected. ").append(methodName).append("() in ").append(into.name);
+ sb.append("Duplicated method detected. ").append(methodName)
+ .append("() in ").append(into.name);
throw new RuntimeException(sb.toString());
}
}
}
-
+
/**
* Injects this the method getter
*/
@Override
public void inject() {
- MethodNode method = new MethodNode(ACC_PUBLIC | (staticMethod ? ACC_STATIC : 0), methodName, "()" + returnDesc, null, null);
+ Core.verbose("Injecting: " + this.toString());
+
+ MethodNode method = new MethodNode(ACC_PUBLIC
+ | (staticMethod ? ACC_STATIC : 0), methodName, "()"
+ + returnDesc, null, null);
if (!staticField) {
method.visitVarInsn(ALOAD, 0);
}
- method.visitFieldInsn(staticField ? GETSTATIC : GETFIELD, fieldLocation.name, fieldNode.name, fieldNode.desc);
+ method.visitFieldInsn(staticField ? GETSTATIC : GETFIELD,
+ fieldLocation.name, fieldNode.name, fieldNode.desc);
if (!fieldNode.desc.equals(returnDesc)) {
if (returnDesc.contains("L")) {
if (!returnDesc.contains("[")) {
- method.visitTypeInsn(CHECKCAST,returnDesc.replaceFirst("L", "").replaceAll(";", ""));
+ method.visitTypeInsn(CHECKCAST,
+ returnDesc.replaceFirst("L", "")
+ .replaceAll(";", ""));
} else {
method.visitTypeInsn(CHECKCAST, returnDesc);
}
@@ -119,38 +141,21 @@ public class AddGetterAdapter implements Opcodes, Injectable {
if (fieldNode.desc.equals("J") && returnDesc.equals("I"))
method.visitInsn(L2I);
- method.visitInsn(getReturnOpcode(returnDesc));
+ method.visitInsn(ASMUtils.getReturnOpcode(returnDesc));
method.visitMaxs(1, 1);
into.methods.add(method);
}
-
- /**
- * Return right opcode for desc
- * @param desc
- * @return return opcode
- */
- private static int getReturnOpcode(String desc) {
- desc = desc.substring(desc.indexOf("L") + 1);
- if (desc.length() > 1) {
- return ARETURN;
- }
- final char c = desc.charAt(0);
- switch (c)
- {
- case 'I':
- case 'Z':
- case 'B':
- case 'S':
- case 'C':
- return IRETURN;
- case 'J':
- return LRETURN;
- case 'F':
- return FRETURN;
- case 'D':
- return DRETURN;
- }
- throw new RuntimeException("Wrong desc type: " + c);
+
+ @Override
+ public String toString() {
+ return new StringBuilder("[Injectable: getter, into classname: ")
+ .append(into.name).append(", field classname: ")
+ .append(fieldLocation.name).append(", field name: ")
+ .append(fieldNode.name).append(", field desc: ")
+ .append(fieldNode.desc).append(", method name: ")
+ .append(methodName).append(", return desc: ")
+ .append(returnDesc).append(", static method: ")
+ .append(staticMethod).append(", static field: ")
+ .append(staticField).append("]").toString();
}
-
}
\ No newline at end of file
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddInterfaceAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddInterfaceAdapter.java
index cde2ca4..a4ea32a 100644
--- a/parabotv2/src/org/parabot/core/asm/adapters/AddInterfaceAdapter.java
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddInterfaceAdapter.java
@@ -1,12 +1,13 @@
package org.parabot.core.asm.adapters;
import org.objectweb.asm.tree.ClassNode;
+import org.parabot.core.Core;
import org.parabot.core.asm.ASMUtils;
import org.parabot.core.asm.interfaces.Injectable;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class AddInterfaceAdapter implements Injectable {
@@ -35,11 +36,16 @@ public class AddInterfaceAdapter implements Injectable {
@Override
public void inject() {
+ Core.verbose("Injecting: " + this.toString());
addInterface(node, accessorPackage + interfaceClass);
}
protected static void addInterface(ClassNode cg, String i) {
- System.out.println(" ^ " + cg.name + " implements " + i);
cg.interfaces.add(i);
}
+
+ @Override
+ public String toString() {
+ return new StringBuilder("[Injectable: interface, into classname: ").append(node.name).append(", interface: ").append(accessorPackage).append(interfaceClass).append("]").toString();
+ }
}
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddInvokerAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddInvokerAdapter.java
new file mode 100644
index 0000000..2895fbd
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddInvokerAdapter.java
@@ -0,0 +1,66 @@
+package org.parabot.core.asm.adapters;
+
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.asm.ASMUtils;
+import org.parabot.core.asm.interfaces.Injectable;
+
+/**
+ *
+ * Injects a method which invokes an other method
+ *
+ * @author Everel
+ *
+ */
+public class AddInvokerAdapter implements Opcodes, Injectable {
+ private ClassNode into = null;
+ private ClassNode methodLocation = null;
+ private MethodNode mn = null;
+ private String argsDesc = null;
+ private String returnDesc = null;
+ private String methodName = null;
+
+ public AddInvokerAdapter(final ClassNode methodLocation,
+ final ClassNode into, final MethodNode mn, final String argsDesc,
+ final String returnDesc, final String methodName) {
+ this.into = into;
+ this.methodLocation = methodLocation;
+ this.mn = mn;
+ this.argsDesc = argsDesc;
+ this.returnDesc = returnDesc;
+ this.methodName = methodName;
+ }
+
+ @Override
+ public void inject() {
+ MethodNode m = new MethodNode(ACC_PUBLIC, this.methodName,
+ this.argsDesc + this.returnDesc, null, null);
+
+ boolean isStatic = (this.mn.access & ACC_STATIC) != 0;
+
+ if (!isStatic)
+ m.visitVarInsn(ALOAD, 0);
+
+ if (!this.argsDesc.equals("()"))
+ for (int i = 1; i < this.argsDesc.length() - 1; i++)
+ m.visitVarInsn(ASMUtils.getLoadOpcode(this.argsDesc.substring(
+ i, i + 1)), i);
+
+ m.visitMethodInsn(isStatic ? INVOKESTATIC : INVOKEVIRTUAL,
+ methodLocation.name, mn.name, mn.desc);
+ if (this.returnDesc.contains("L")) {
+ if (!this.returnDesc.contains("[")) {
+ m.visitTypeInsn(CHECKCAST, this.returnDesc
+ .replaceFirst("L", "").replaceAll(";", ""));
+ } else {
+ m.visitTypeInsn(CHECKCAST, this.returnDesc);
+ }
+ }
+
+ m.visitInsn(ASMUtils.getReturnOpcode(this.returnDesc));
+ m.visitMaxs(0, 0);
+ this.into.methods.add(m);
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddSetterAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddSetterAdapter.java
index d5ab966..d23ffc0 100644
--- a/parabotv2/src/org/parabot/core/asm/adapters/AddSetterAdapter.java
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddSetterAdapter.java
@@ -4,13 +4,14 @@ import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.Core;
import org.parabot.core.asm.interfaces.Injectable;
/**
* Injects methods which sets a field
*
- * @author Clisprail
- *
+ * @author Everel
+ *
*/
public class AddSetterAdapter implements Opcodes, Injectable {
private ClassNode fieldLocation = null;
@@ -19,8 +20,9 @@ public class AddSetterAdapter implements Opcodes, Injectable {
private String name = null;
private String desc = null;
private boolean methodStatic = false;
-
- public AddSetterAdapter(ClassNode fieldLocation, ClassNode into, FieldNode field, String name, String desc, boolean methodStatic) {
+
+ public AddSetterAdapter(ClassNode fieldLocation, ClassNode into,
+ FieldNode field, String name, String desc, boolean methodStatic) {
this.fieldLocation = fieldLocation;
this.into = into;
this.field = field;
@@ -28,24 +30,32 @@ public class AddSetterAdapter implements Opcodes, Injectable {
this.desc = desc;
this.methodStatic = methodStatic;
}
-
- public AddSetterAdapter(ClassNode fieldLocation, ClassNode into, FieldNode field, String name, String desc) {
+
+ public AddSetterAdapter(ClassNode fieldLocation, ClassNode into,
+ FieldNode field, String name, String desc) {
this(fieldLocation, into, field, name, desc, false);
}
-
- private static void addSetter(ClassNode fieldLocation, ClassNode into, FieldNode field, String name, String desc, boolean methodStatic) {
+
+ private static void addSetter(ClassNode fieldLocation, ClassNode into,
+ FieldNode field, String name, String desc, boolean methodStatic) {
if (desc.contains("L") && !desc.endsWith("Ljava/lang/String;"))
desc = "Ljava/lang/Object;";
- MethodNode method = new MethodNode(ACC_PUBLIC | (methodStatic ? ACC_STATIC : 0), name, "(" + desc + ")V", null, null);
+ MethodNode method = new MethodNode(ACC_PUBLIC
+ | (methodStatic ? ACC_STATIC : 0), name, "(" + desc + ")V",
+ null, null);
boolean isStatic = (field.access & ACC_STATIC) > 0;
if (!isStatic) {
method.visitVarInsn(ALOAD, 0);
}
- if (desc.equals("I"))
+ if (desc.equals("I")) {
method.visitVarInsn(ILOAD, 1);
- else
+ } else if (desc.equals("J")) {
+ method.visitVarInsn(Opcodes.LLOAD, 1);
+ } else {
method.visitVarInsn(ALOAD, 1);
- method.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, fieldLocation.name, field.name, field.desc);
+ }
+ method.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD,
+ fieldLocation.name, field.name, field.desc);
method.visitInsn(RETURN);
method.visitMaxs(2, 2);
into.methods.add(method);
@@ -56,8 +66,20 @@ public class AddSetterAdapter implements Opcodes, Injectable {
*/
@Override
public void inject() {
+ Core.verbose("Injecting: " + this.toString());
addSetter(fieldLocation, into, field, name, desc, methodStatic);
-
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder("[Injectable: setter, into classname: ")
+ .append(into.name).append(", field classname: ")
+ .append(fieldLocation.name).append(", field name: ")
+ .append(field.name).append(", field desc: ").append(field.desc)
+ .append(", method name: ").append(name)
+ .append(", method desc: ").append(desc)
+ .append(", static method: ").append(methodStatic).append("]")
+ .toString();
}
}
diff --git a/parabotv2/src/org/parabot/core/asm/adapters/AddSuperAdapter.java b/parabotv2/src/org/parabot/core/asm/adapters/AddSuperAdapter.java
index 73c0468..80889f9 100644
--- a/parabotv2/src/org/parabot/core/asm/adapters/AddSuperAdapter.java
+++ b/parabotv2/src/org/parabot/core/asm/adapters/AddSuperAdapter.java
@@ -7,18 +7,24 @@ import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.Core;
import org.parabot.core.asm.ASMUtils;
import org.parabot.core.asm.interfaces.Injectable;
+/**
+ *
+ * @author Everel
+ *
+ */
public class AddSuperAdapter implements Injectable {
private ClassNode node = null;
private String superClass = null;
-
+
public AddSuperAdapter(final ClassNode node, final String superClass) {
this.node = node;
this.superClass = superClass;
}
-
+
public AddSuperAdapter(final String className, final String superClass) {
this.node = ASMUtils.getClass(className);
this.superClass = superClass;
@@ -26,10 +32,12 @@ public class AddSuperAdapter implements Injectable {
@Override
public void inject() {
+ Core.verbose("Injecting: " + this.toString());
setSuper(node, superClass);
}
-
- private static final void setSuper(final ClassNode node, final String superClass) {
+
+ private static final void setSuper(final ClassNode node,
+ final String superClass) {
ListIterator> mli = node.methods.listIterator();
while (mli.hasNext()) {
MethodNode mn = (MethodNode) mli.next();
@@ -48,4 +56,11 @@ public class AddSuperAdapter implements Injectable {
node.superName = superClass;
}
+ @Override
+ public String toString() {
+ return new StringBuilder("[Injectable: super, class name: ")
+ .append(node.name).append(", super: ").append(superClass)
+ .append("]").toString();
+ }
+
}
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Callback.java b/parabotv2/src/org/parabot/core/asm/wrappers/Callback.java
new file mode 100644
index 0000000..2d658c3
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Callback.java
@@ -0,0 +1,48 @@
+package org.parabot.core.asm.wrappers;
+
+import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.asm.ASMUtils;
+import org.parabot.core.asm.adapters.AddCallbackAdapter;
+import org.parabot.core.asm.interfaces.Injectable;
+
+/**
+ *
+ * @author Everel
+ *
+ */
+public class Callback implements Injectable {
+ private MethodNode method;
+ private String invokeClass;
+ private String invokeMethod;
+ private String desc;
+ private int[] args;
+
+ public Callback(final String className, final String methodName,
+ final String methodDesc, final String callbackClass,
+ final String callbackMethod, final String callbackDesc, String args) {
+ this.method = ASMUtils.getMethod(className, methodName, methodDesc);
+ this.invokeClass = callbackClass;
+ this.invokeMethod = callbackMethod;
+ this.desc = callbackDesc;
+ if (args.contains(",")) {
+ final String[] strArgs = args.split(",");
+ this.args = new int[strArgs.length];
+ for (int i = 0; i < this.args.length; i++) {
+ this.args[i] = Integer.parseInt(strArgs[i]);
+ }
+ } else {
+ this.args = new int[] { Integer.parseInt(args) };
+ }
+ }
+
+ @Override
+ public void inject() {
+ getAdapter().inject();
+ }
+
+ public AddCallbackAdapter getAdapter() {
+ return new AddCallbackAdapter(this.method, this.invokeClass,
+ this.invokeMethod, this.desc, this.args);
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Getter.java b/parabotv2/src/org/parabot/core/asm/wrappers/Getter.java
index 9cf2f09..fa93b2e 100644
--- a/parabotv2/src/org/parabot/core/asm/wrappers/Getter.java
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Getter.java
@@ -8,7 +8,7 @@ import org.parabot.core.asm.interfaces.Injectable;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Getter implements Injectable {
@@ -35,7 +35,6 @@ public class Getter implements Injectable {
this.fieldLocation = ASMUtils.getClass(fieldLocation);
this.fieldNode = ASMUtils.getField(ASMUtils.getClass(fieldLocation), fieldNode);
this.methodName = methodName;
- System.out.println(fieldNode);
this.returnDesc = returnDesc == null ? this.fieldNode.desc : returnDesc;
this.staticMethod = staticMethod;
}
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Interface.java b/parabotv2/src/org/parabot/core/asm/wrappers/Interface.java
index f82a664..26a631c 100644
--- a/parabotv2/src/org/parabot/core/asm/wrappers/Interface.java
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Interface.java
@@ -5,7 +5,7 @@ import org.parabot.core.asm.interfaces.Injectable;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Interface implements Injectable {
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Invoker.java b/parabotv2/src/org/parabot/core/asm/wrappers/Invoker.java
new file mode 100644
index 0000000..9bf9cd3
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Invoker.java
@@ -0,0 +1,68 @@
+package org.parabot.core.asm.wrappers;
+
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.MethodNode;
+import org.parabot.core.asm.ASMUtils;
+import org.parabot.core.asm.adapters.AddInvokerAdapter;
+import org.parabot.core.asm.interfaces.Injectable;
+
+/**
+ *
+ * @author Everel
+ *
+ */
+public class Invoker implements Injectable {
+ private ClassNode into = null;
+ private ClassNode methodLocation = null;
+ private MethodNode mn = null;
+ private String argsDesc = null;
+ private String returnDesc = null;
+ private String methodName = null;
+
+ public Invoker(String methodLoc, String invMethName, String argsDesc,
+ String returnDesc, String methodName) {
+ this(methodLoc, methodLoc, invMethName, argsDesc, returnDesc,
+ methodName);
+ }
+
+ public Invoker(String into, String methodLoc, String invMethName,
+ String argsDesc, String returnDesc, String methodName) {
+ this.into = ASMUtils.getClass(into);
+ this.methodLocation = ASMUtils.getClass(methodLoc);
+ this.mn = getMethod(this.methodLocation, invMethName, argsDesc);
+ this.returnDesc = returnDesc;
+ this.methodName = methodName;
+ this.argsDesc = argsDesc;
+ }
+
+ private static MethodNode getMethod(ClassNode into, String name, String desc) {
+ for (MethodNode m : into.methods) {
+ String s = m.desc.substring(0, m.desc.indexOf(')') + 1);
+ if (m.name.equals(name) && s.equals(desc)) {
+ return m;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Short route for getAdaptar().inject();
+ *
+ * @see AddInvokerAdapter#inject
+ */
+ @Override
+ public void inject() {
+ getAdapter().inject();
+ }
+
+ /**
+ * Gets the AddInvokerAdapter
+ *
+ * @return AddInvokerAdapter
+ */
+ public AddInvokerAdapter getAdapter() {
+ return new AddInvokerAdapter(this.methodLocation, this.into, this.mn,
+ this.argsDesc, this.returnDesc, this.methodName);
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Setter.java b/parabotv2/src/org/parabot/core/asm/wrappers/Setter.java
index d2a97a1..1483350 100644
--- a/parabotv2/src/org/parabot/core/asm/wrappers/Setter.java
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Setter.java
@@ -8,7 +8,7 @@ import org.parabot.core.asm.interfaces.Injectable;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Setter implements Injectable {
diff --git a/parabotv2/src/org/parabot/core/asm/wrappers/Super.java b/parabotv2/src/org/parabot/core/asm/wrappers/Super.java
index ba498d7..f452f5e 100644
--- a/parabotv2/src/org/parabot/core/asm/wrappers/Super.java
+++ b/parabotv2/src/org/parabot/core/asm/wrappers/Super.java
@@ -4,7 +4,7 @@ import org.parabot.core.asm.adapters.AddSuperAdapter;
import org.parabot.core.asm.interfaces.Injectable;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class Super implements Injectable {
diff --git a/parabotv2/src/org/parabot/core/bot/loader/BotLoader.java b/parabotv2/src/org/parabot/core/bot/loader/BotLoader.java
deleted file mode 100644
index fa3457e..0000000
--- a/parabotv2/src/org/parabot/core/bot/loader/BotLoader.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.parabot.core.bot.loader;
-
-import org.parabot.core.asm.ASMClassLoader;
-import org.parabot.core.classpath.ClassPath;
-
-/**
- * Handles client class calls
- *
- * @author Clisprail
- *
- */
-public class BotLoader extends ASMClassLoader {
-
- public BotLoader(ClassPath classPath, ASMClassLoader serverProvider) {
- super(classPath);
- }
-
-}
diff --git a/parabotv2/src/org/parabot/core/build/BuildPath.java b/parabotv2/src/org/parabot/core/build/BuildPath.java
index 5b25051..11d31d3 100644
--- a/parabotv2/src/org/parabot/core/build/BuildPath.java
+++ b/parabotv2/src/org/parabot/core/build/BuildPath.java
@@ -6,7 +6,7 @@ import java.net.URLClassLoader;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class BuildPath {
diff --git a/parabotv2/src/org/parabot/core/classpath/ClassPath.java b/parabotv2/src/org/parabot/core/classpath/ClassPath.java
index 337c0d7..4af6ee5 100644
--- a/parabotv2/src/org/parabot/core/classpath/ClassPath.java
+++ b/parabotv2/src/org/parabot/core/classpath/ClassPath.java
@@ -2,69 +2,143 @@ package org.parabot.core.classpath;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.ClassNode;
+import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
+import org.parabot.core.io.SizeInputStream;
+import org.parabot.core.ui.components.VerboseLoader;
/**
*
- * @author Clisprail
+ * @author Everel
* @author Matt
*/
public class ClassPath {
public final HashMap classes = new HashMap();
public final Map resources = new HashMap();
-
+
private boolean isJar = false;
private boolean parseJar = true;
private ArrayList jarFiles = new ArrayList();
-
+
public URL lastParsed = null;
-
+
public ClassPath() {
-
+
}
-
+
public ClassPath(final boolean isJar) {
this.isJar = isJar;
}
+
+ public void addJar(final File file) {
+ try {
+ addJar(file.toURI().toURL());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void addJar(final URL url) {
+ this.lastParsed = url;
+ try {
+ addJar(url.openConnection());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
/**
- * Adds jar to this classpath
- * @param jarLocation
+ * Adds a jar to this classpath
+ *
+ * @param url
*/
- public void addJar(final String jarLocation) {
- JarParser.parseJar(this, jarLocation);
+ public void addJar(final URLConnection connection) {
+ try {
+ final int size = connection.getContentLength();
+ final SizeInputStream sizeInputStream = new SizeInputStream(
+ connection.getInputStream(), size, VerboseLoader.get());
+ final ZipInputStream zin = new ZipInputStream(sizeInputStream);
+ ZipEntry e;
+ while ((e = zin.getNextEntry()) != null) {
+ if (e.isDirectory())
+ continue;
+ if (e.getName().endsWith(".class")) {
+ loadClass(zin);
+ } else {
+ loadResource(e.getName(), zin);
+ }
+ VerboseLoader.setState("Downloading: " + e.getName());
+ }
+ zin.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ VerboseLoader.get().onProgressUpdate(100);
+ }
+
+
+
+ /**
+ * Adds a jar to this classpath
+ *
+ * @param url
+ * - in string format
+ */
+ public void addJar(final String url) {
+ try {
+ addJar(new URL(url));
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Whether jar files should be parsed or ignored
+ *
+ * @param enabled
+ */
+ public void parseJarFiles(final boolean enabled) {
+ this.parseJar = enabled;
}
/**
- * Adds jar to this classpath
- * @param jarLocation
+ * Finds and loads all classes/jar files in folder
+ * @param directory
*/
- public void addJar(final URL jarLocation) {
- JarParser.parseJar(this, jarLocation.toString());
- }
-
- public void parseJarFiles(final boolean enabled) {
- this.parseJar = enabled;
+ public void addClasses(final File directory) {
+ if(directory == null || !directory.isDirectory()) {
+ throw new IllegalArgumentException("Not a valid directory.");
+ }
+ addClasses(directory, null);
}
/**
* Finds and loads all classes/jar files in folder
*
- * @param file to find class / jar files
+ * @param file
+ * to find class / jar files
* @param root
*/
- public void loadClasses(final File f, File root) {
+ public void addClasses(final File f, File root) {
if (f == null)
return;
if (!f.exists()) {
@@ -77,21 +151,22 @@ public class ClassPath {
if (f1 == null) {
continue;
} else if (f1.isDirectory()) {
- loadClasses(f1, root);
+ addClasses(f1, root);
} else {
try (FileInputStream fin = new FileInputStream(f1)) {
if (f1.getName().endsWith(".class"))
loadClass(fin);
else if (f.equals(root) && f1.getName().endsWith(".jar")) {
jarFiles.add(f1.toURI().toURL());
- if(this.parseJar) {
- // if enabled, there may be problem with duplicate class names.......
- loadClasses(f1.toURI().toURL());
+ if (this.parseJar) {
+ // if enabled, there may be problem with duplicate
+ // class names.......
+ addJar(f1.toURI().toURL());
}
} else {
String path = f1.toURI().relativize(root.toURI())
.getPath();
- Resources.loadResource(this, path, fin);
+ loadResource(path, fin);
}
} catch (Exception e) {
e.printStackTrace();
@@ -100,71 +175,114 @@ public class ClassPath {
}
}
- /**
- * Loads classes from zip/jar files
- *
- * @param url to file
- */
- public void loadClasses(URL u) {
- this.lastParsed = u;
- try (ZipInputStream zin = new ZipInputStream(u.openStream())) {
- ZipEntry e;
- while ((e = zin.getNextEntry()) != null) {
- if (e.isDirectory())
- continue;
- if (e.getName().endsWith(".class")) {
- loadClass(zin);
- } else {
- Resources.loadResource(this, e.getName(), zin);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
/**
* Loads class from input stream
*
* @param inputstream
* @throws IOException
*/
- private void loadClass(InputStream in) throws IOException {
+ protected void loadClass(InputStream in) throws IOException {
ClassReader cr = new ClassReader(in);
ClassNode cn = new ClassNode();
- //cr.accept(cn, 0);
cr.accept(cn, 0);
- //cr.accept(cn, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classes.put(cn.name, cn);
}
-
/**
- * Dumps the classnodes into a jar
+ * Determines if this classpath represents a jar file
*
- * @param jarName
+ * @return if this classpath represents a jar file
*/
- public void dump(final String jarName) {
- JarDumper.dump(this, jarName);
- }
-
public boolean isJar() {
return isJar;
}
-
+
+ /**
+ * Gets all jar files in this classpath
+ *
+ * @return array of classpath
+ */
public ClassPath[] getJarFiles() {
final ClassPath[] jars = new ClassPath[jarFiles.size()];
- for(int i = 0; i < jarFiles.size(); i++) {
+ for (int i = 0; i < jarFiles.size(); i++) {
final ClassPath classPath = new ClassPath(true);
- classPath.loadClasses(jarFiles.get(i));
+ classPath.addJar(jarFiles.get(i));
jars[i] = classPath;
}
return jars;
}
-
+
+ /**
+ * Dumps a resource from a input stream
+ *
+ * @param classPath
+ * @param name
+ * @param inputstream
+ * @throws IOException
+ */
+ private void loadResource(final String name, final InputStream in)
+ throws IOException {
+ final File f = File.createTempFile("bot", ".tmp",
+ Directories.getTempDirectory());
+ f.deleteOnExit();
+ try (OutputStream out = new FileOutputStream(f)) {
+ byte[] buffer = new byte[1024];
+ int len;
+ while ((len = in.read(buffer)) != -1)
+ out.write(buffer, 0, len);
+ } catch (IOException e) {
+ }
+ this.resources.put(name, f.toURI().toURL());
+ }
+
+ /**
+ * Adds this jar to buildpath
+ */
public void addToBuildPath() {
BuildPath.add(lastParsed);
}
+ /**
+ * Dump this classPath classes to a jar file
+ *
+ * @param fileName
+ */
+ public void dump(final String fileName) {
+ dump(new File(fileName));
+ }
+
+ /**
+ * Dump this classPath classes to a jar file
+ *
+ * @param file
+ */
+ public void dump(final File file) {
+ try {
+ dump(new FileOutputStream(file));
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Dumps this classPath classes to a jar file
+ * @param stream
+ */
+ public void dump(final FileOutputStream stream) {
+ try {
+ JarOutputStream out = new JarOutputStream(stream);
+ for (ClassNode cn : this.classes.values()) {
+ JarEntry je = new JarEntry(cn.name + ".class");
+ out.putNextEntry(je);
+ ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+ cn.accept(cw);
+ out.write(cw.toByteArray());
+ }
+ out.close();
+ stream.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/parabotv2/src/org/parabot/core/classpath/JarDumper.java b/parabotv2/src/org/parabot/core/classpath/JarDumper.java
deleted file mode 100644
index f9eaa52..0000000
--- a/parabotv2/src/org/parabot/core/classpath/JarDumper.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package org.parabot.core.classpath;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.tree.ClassNode;
-
-/**
- *
- * @author Clisprail
- *
- */
-public class JarDumper {
-
- /**
- * Dumps classnodes to a jar file
- * @param classPath
- * @param fileName
- */
- public static void dump(final ClassPath classPath, final String fileName) {
- try {
- FileOutputStream stream = new FileOutputStream(new File(fileName));
- JarOutputStream out = new JarOutputStream(stream);
- for (ClassNode cn : classPath.classes.values()) {
- JarEntry je = new JarEntry(cn.name + ".class");
- out.putNextEntry(je);
- ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
- cn.accept(cw);
- out.write(cw.toByteArray());
- }
- out.close();
- stream.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/parabotv2/src/org/parabot/core/classpath/JarParser.java b/parabotv2/src/org/parabot/core/classpath/JarParser.java
deleted file mode 100644
index b65459b..0000000
--- a/parabotv2/src/org/parabot/core/classpath/JarParser.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.parabot.core.classpath;
-
-import java.net.JarURLConnection;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.tree.ClassNode;
-
-/**
- *
- * A class for parsing a jar file
- *
- * @author Clisprail
- *
- */
-public class JarParser {
-
- /**
- * Parses a jar from an URL
- * @param classPath
- * @param jarLocation
- */
- public static void parseJar(final ClassPath classPath, final String jarLocation) {
- try {
- URL jarURL = new URL("jar:" + jarLocation + "!/");
- JarURLConnection jarConnection = (JarURLConnection) jarURL
- .openConnection();
- JarFile theJar = jarConnection.getJarFile();
- Enumeration> en = theJar.entries();
- while (en.hasMoreElements()) {
- JarEntry entry = (JarEntry) en.nextElement();
- if (entry.getName().endsWith(".class")) {
- ClassReader cr = new ClassReader(
- theJar.getInputStream(entry));
- ClassNode cn = new ClassNode();
- cr.accept(cn, 0);
- classPath.classes.put(cn.name, cn);
- } else if (!entry.isDirectory()
- && !entry.getName().startsWith("META-INF")) {
- Resources.loadResource(classPath, entry.getName(), theJar.getInputStream(entry));
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-}
diff --git a/parabotv2/src/org/parabot/core/classpath/Resources.java b/parabotv2/src/org/parabot/core/classpath/Resources.java
deleted file mode 100644
index 5834f9e..0000000
--- a/parabotv2/src/org/parabot/core/classpath/Resources.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package org.parabot.core.classpath;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-import org.parabot.core.Directories;
-
-/**
- *
- * @author Clisprail
- * @author Matt
- */
-public class Resources {
-
- /**
- * Dumps a resource from a input stream
- * @param classPath
- * @param name
- * @param inputstream
- * @throws IOException
- */
- public static void loadResource(final ClassPath classPath, final String name, final InputStream in)
- throws IOException {
- File f = File.createTempFile("bot", ".tmp", Directories.getTempDirectory());
- f.deleteOnExit();
- try (OutputStream out = new FileOutputStream(f)) {
- byte[] buffer = new byte[1024];
- int len;
- while ((len = in.read(buffer)) != -1)
- out.write(buffer, 0, len);
- } catch (IOException e) {
- }
- classPath.resources.put(name, f.toURI().toURL());
- }
-
-}
diff --git a/parabotv2/src/org/parabot/core/desc/ScriptDescription.java b/parabotv2/src/org/parabot/core/desc/ScriptDescription.java
index 3fe9eae..e20c073 100644
--- a/parabotv2/src/org/parabot/core/desc/ScriptDescription.java
+++ b/parabotv2/src/org/parabot/core/desc/ScriptDescription.java
@@ -1,5 +1,11 @@
package org.parabot.core.desc;
+/**
+ * Holds information about a script
+ *
+ * @author Everel
+ *
+ */
public class ScriptDescription {
public String scriptName = null;
public String author = null;
@@ -7,19 +13,122 @@ public class ScriptDescription {
public double version = 0;
public String description = null;
public String[] servers = null;
- public int scriptIndex = -1;
+ public String isVip = null;
+ public String isPremium = null;
+ public int sdnId = -1;
+ public String jarName = null;
+ /**
+ * The ScriptManifest
+ *
+ * @param scriptName
+ * @param author
+ * @param category
+ * @param version
+ * @param description
+ * @param servers
+ */
public ScriptDescription(final String scriptName, final String author,
final String category, final double version,
- final String description, final String[] servers,
- final int scriptIndex) {
+ final String description, final String[] servers) {
+ this(scriptName, author, category, version, description, servers, null,
+ null, -1, null);
+ }
+
+ /**
+ * Used for SDN script (see SDNScripts parser)
+ *
+ * @param jarName
+ * @param scriptName
+ * @param author
+ * @param category
+ * @param version
+ * @param description
+ * @param servers
+ * @param sdnId
+ */
+ public ScriptDescription(final String jarName, final String scriptName,
+ final String author, final String category, final double version,
+ final String description, final String[] servers, final int sdnId) {
+ this(scriptName, author, category, version, description, servers, null,
+ null, sdnId, jarName);
+ }
+
+ /**
+ * Used by bot (java scripts and python scripts) and SDN Manager (sdn
+ * manager is a private program)
+ *
+ * @param scriptName
+ * @param author
+ * @param category
+ * @param version
+ * @param description
+ * @param servers
+ * @param vip
+ * @param premium
+ */
+ public ScriptDescription(final String scriptName, final String author,
+ final String category, final double version,
+ final String description, final String[] servers, final String vip,
+ final String premium) {
+ this(scriptName, author, category, version, description, servers, vip,
+ premium, -1, null);
+ }
+
+ /**
+ * Main constructor
+ *
+ * @param scriptName
+ * @param author
+ * @param category
+ * @param version
+ * @param description
+ * @param servers
+ * @param vip
+ * @param premium
+ * @param sdnId
+ * @param jarName
+ */
+ public ScriptDescription(final String scriptName, final String author,
+ final String category, final double version,
+ final String description, final String[] servers, final String vip,
+ final String premium, final int sdnId, final String jarName) {
this.scriptName = scriptName;
this.author = author;
this.category = category;
this.version = version;
this.description = description;
this.servers = servers;
- this.scriptIndex = scriptIndex;
+ this.isVip = vip;
+ this.isPremium = premium;
+ this.sdnId = sdnId;
+ this.jarName = jarName;
}
+ @Override
+ public String toString() {
+ final StringBuilder b = new StringBuilder();
+ b.append("[name: ").append(this.scriptName).append(", author: ")
+ .append(this.author).append(", category: ")
+ .append(this.category).append(", version: ")
+ .append(this.version).append(", description: ")
+ .append(this.description).append(", servers: ");
+ for (int i = 0; i < this.servers.length; i++) {
+ b.append(this.servers[i]);
+ if (i < (this.servers.length - 1)) {
+ b.append(" ");
+ }
+ }
+ b.append(", vip: ")
+ .append(this.isVip == null ? "unknown" : this.isVip)
+ .append(", premium: ")
+ .append(this.isPremium == null ? "unknown" : this.isPremium)
+ .append(", sdn id: ")
+ .append(this.sdnId == -1 ? "unknown" : Integer
+ .toString(this.sdnId)).append(", jarname: ")
+ .append(this.jarName == null ? "unknown" : this.jarName)
+ .append("]");
+
+ return b.toString();
+ }
}
diff --git a/parabotv2/src/org/parabot/core/desc/ServerDescription.java b/parabotv2/src/org/parabot/core/desc/ServerDescription.java
index 22cf5b9..58810e3 100644
--- a/parabotv2/src/org/parabot/core/desc/ServerDescription.java
+++ b/parabotv2/src/org/parabot/core/desc/ServerDescription.java
@@ -1,16 +1,25 @@
package org.parabot.core.desc;
+/**
+ *
+ * @author Everel
+ *
+ */
public class ServerDescription {
public String serverName = null;
public String author = null;
- public int revision = 0;
- public int providerIndex = -1;
-
- public ServerDescription(final String serverName, final String author, final int revision, final int providerIndex) {
+ public double revision = 0;
+
+ public ServerDescription(final String serverName, final String author,
+ final double revision) {
this.serverName = serverName;
this.author = author;
this.revision = revision;
- this.providerIndex = providerIndex;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("[Server: %s, Author: %s, Revision: %.1f]", this.serverName, this.author, this.revision);
}
}
diff --git a/parabotv2/src/org/parabot/core/forum/Account.java b/parabotv2/src/org/parabot/core/forum/Account.java
new file mode 100644
index 0000000..298128b
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/forum/Account.java
@@ -0,0 +1,42 @@
+package org.parabot.core.forum;
+
+/**
+ *
+ * Class which holds parabot forum account user and pass, only specific classes
+ * have access to it unless it's a modified version of parabot intended to
+ * steal user information.
+ *
+ * @author Everel
+ *
+ */
+public class Account {
+ private String username = null;
+ private String password = null;
+
+ /**
+ *
+ * @param username - UTF-8 encoded forum account username
+ * @param password - UTF-8 encoded forum account password
+ */
+ public Account(final String username, final String password) {
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Gets user's parabot account name
+ * @return username, already URL UTF-8 encoded.
+ */
+ public String getUsername() {
+ return this.username;
+ }
+
+ /**
+ * Gets user's parabot password
+ * @return password, already URL UTF-8 encoded.
+ */
+ public String getPassword() {
+ return this.password;
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/forum/AccountManager.java b/parabotv2/src/org/parabot/core/forum/AccountManager.java
new file mode 100644
index 0000000..228651d
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/forum/AccountManager.java
@@ -0,0 +1,76 @@
+package org.parabot.core.forum;
+
+import java.net.URLEncoder;
+import java.util.ArrayList;
+
+import org.parabot.core.Configuration;
+import org.parabot.core.Core;
+import org.parabot.core.parsers.scripts.SDNScripts;
+import org.parabot.core.ui.LoginUI;
+import org.parabot.environment.api.utils.WebUtil;
+import org.parabot.environment.scripts.SDNScriptExecuter;
+
+/**
+ * Handles logging in to parabot forum, only certain classes may use this class.
+ *
+ * @author Everel
+ *
+ */
+public final class AccountManager {
+ private static boolean validated = false;
+ private static AccountManager instance = null;
+
+ private Account account = null;
+
+ private AccountManager() {
+
+ }
+
+ public static final void validate() {
+ if (validated) {
+ return;
+ }
+ instance = new AccountManager();
+
+ Core.verbose("Initializing account manager accessors...");
+ final ArrayList accessors = new ArrayList();
+ accessors.add(SDNScripts.MANAGER_FETCHER);
+ accessors.add(LoginUI.MANAGER_FETCHER);
+ accessors.add(SDNScriptExecuter.MANAGER_FETCHER);
+
+ for (final AccountManagerAccess accessor : accessors) {
+ accessor.setManager(instance);
+ }
+ Core.verbose("Account managers initialized.");
+ }
+
+ public final boolean isLoggedIn() {
+ return account != null;
+ }
+
+ public final Account getAccount() {
+ return account;
+ }
+
+ public final boolean login(final String user, final String pass) {
+ if (account != null) {
+ throw new IllegalStateException("Already logged in.");
+ }
+ String contents = null;
+ try {
+ contents = WebUtil.getContents(String.format(
+ Configuration.LOGIN_SERVER,
+ URLEncoder.encode(user, "UTF-8"),
+ URLEncoder.encode(pass, "UTF-8")));
+ } catch (Throwable t) {
+ return false;
+ }
+
+ if (contents.equals("correct")) {
+ account = new Account(user, pass);
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/forum/AccountManagerAccess.java b/parabotv2/src/org/parabot/core/forum/AccountManagerAccess.java
new file mode 100644
index 0000000..76e19ac
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/forum/AccountManagerAccess.java
@@ -0,0 +1,7 @@
+package org.parabot.core.forum;
+
+public interface AccountManagerAccess {
+
+ public void setManager(AccountManager manager);
+
+}
diff --git a/parabotv2/src/org/parabot/core/io/ProgressListener.java b/parabotv2/src/org/parabot/core/io/ProgressListener.java
new file mode 100644
index 0000000..130c0b4
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/io/ProgressListener.java
@@ -0,0 +1,9 @@
+package org.parabot.core.io;
+
+public interface ProgressListener {
+
+ public void onProgressUpdate(double value);
+
+ public void updateDownloadSpeed(double mbPerSecond);
+
+}
diff --git a/parabotv2/src/org/parabot/core/io/SizeInputStream.java b/parabotv2/src/org/parabot/core/io/SizeInputStream.java
new file mode 100644
index 0000000..4d6857a
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/io/SizeInputStream.java
@@ -0,0 +1,63 @@
+package org.parabot.core.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class SizeInputStream extends InputStream {
+ private InputStream in = null;
+
+ private double size = 0;
+
+ public int bytesRead = 0;
+
+ private ProgressListener l;
+
+ private long startTime = 0L;
+
+ public SizeInputStream(InputStream in, int size, ProgressListener l) {
+ this.in = in;
+ this.size = size;
+ this.l = l;
+ this.startTime = System.currentTimeMillis();
+ }
+
+ public int available() {
+ return ((int) size - bytesRead);
+ }
+
+ public int read() throws IOException {
+ int b = in.read();
+ if (b != -1) {
+ bytesRead++;
+ }
+ updateListener();
+ return b;
+ }
+
+ public int read(byte[] b) throws IOException {
+ int read = in.read(b);
+ bytesRead += read;
+ updateListener();
+ return read;
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException {
+ int read = in.read(b, off, len);
+ bytesRead += read;
+ updateListener();
+ return read;
+ }
+
+ private void updateListener() {
+ if(l != null) {
+ double percent = ( bytesRead / size) * 100.0D;
+ l.onProgressUpdate(percent);
+
+ long curTime = System.currentTimeMillis();
+ double timeSeconds = (curTime - startTime) / 1000.0D;
+ double speed = bytesRead / (1024.0D * 1024.0D) / timeSeconds;
+ l.updateDownloadSpeed(speed);
+ }
+ }
+}
+
diff --git a/parabotv2/src/org/parabot/core/jython/Jython.java b/parabotv2/src/org/parabot/core/jython/Jython.java
new file mode 100644
index 0000000..a5c0287
--- /dev/null
+++ b/parabotv2/src/org/parabot/core/jython/Jython.java
@@ -0,0 +1,89 @@
+package org.parabot.core.jython;
+
+import java.io.File;
+import java.net.URL;
+
+import org.parabot.core.Core;
+import org.parabot.core.Directories;
+import org.parabot.core.build.BuildPath;
+
+/**
+ *
+ * @author Everel
+ *
+ */
+public class Jython {
+ private static boolean valid = false;
+
+ /**
+ * Determines if jython jar has been downloaded.
+ * @return false if jython jar has not been downloaded.....
+ */
+ public static final boolean hasJar() {
+ return getJarFile().exists();
+ }
+
+ /**
+ * Adds the jython jar to the build path
+ */
+ public static void init() {
+ if(!hasJar()) {
+ System.err.println("Failed to load jython... [jar missing]");
+ return;
+ }
+ Core.verbose("Adding jyton jar file to build path: " + getLocalJarFile().getPath());
+ BuildPath.add(getLocalJarFile());
+
+ try {
+ Class.forName("org.python.Version");
+ valid = true;
+ } catch (ClassNotFoundException e) {
+ System.err.println("Failed to add jython to build path, or incorrupt download");
+ }
+
+ Core.verbose("Jython initialized.");
+ }
+
+ /**
+ * Determines if jython jar has been successfully added to the buildpath
+ * @return if jython jar was successfully added to the buildpath
+ */
+ public static boolean isValid() {
+ return valid;
+ }
+
+ /**
+ * Gets jython's local jar file
+ * @return file
+ */
+ public static final File getJarFile() {
+ return new File(Directories.getCachePath(), "jython.jar");
+ }
+
+ /**
+ * Gets jython's local jar file in URL format
+ * @return URL
+ */
+ public static final URL getLocalJarFile() {
+ try {
+ return getJarFile().toURI().toURL();
+ } catch (Throwable t ) {
+ t.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Location where jython jar is located on the parabot site
+ * @return URL
+ */
+ public static final URL getDownloadLink() {
+ try {
+ return new URL("http://bot.parabot.org/libs/jython.jar");
+ } catch (Throwable t ) {
+ t.printStackTrace();
+ }
+ return null;
+ }
+
+}
diff --git a/parabotv2/src/org/parabot/core/logging/LabelLogHandler.java b/parabotv2/src/org/parabot/core/logging/LabelLogHandler.java
index f0a6491..9788726 100644
--- a/parabotv2/src/org/parabot/core/logging/LabelLogHandler.java
+++ b/parabotv2/src/org/parabot/core/logging/LabelLogHandler.java
@@ -7,13 +7,11 @@ import java.util.logging.LogRecord;
import javax.swing.JLabel;
-public class LabelLogHandler extends Handler
-{
+public class LabelLogHandler extends Handler {
public final JLabel label = new JLabel();
private final Color defaultColor;
- public LabelLogHandler()
- {
+ public LabelLogHandler() {
super();
defaultColor = label.getForeground();
}
@@ -29,14 +27,14 @@ public class LabelLogHandler extends Handler
@Override
public void publish(final LogRecord record) {
StringBuilder b = new StringBuilder(record.getMessage());
-
+
if (record.getLevel().intValue() > Level.WARNING.intValue()) {
label.setForeground(new Color(0xcc0000));
} else {
label.setForeground(defaultColor);
b.append(" ...");
}
-
+
label.setText(new String(b));
}
}
diff --git a/parabotv2/src/org/parabot/core/logging/SystemConsoleHandler.java b/parabotv2/src/org/parabot/core/logging/SystemConsoleHandler.java
index 52eeb14..a27041d 100644
--- a/parabotv2/src/org/parabot/core/logging/SystemConsoleHandler.java
+++ b/parabotv2/src/org/parabot/core/logging/SystemConsoleHandler.java
@@ -1,6 +1,7 @@
package org.parabot.core.logging;
import java.util.logging.ConsoleHandler;
+import java.util.logging.LogRecord;
/**
* Logs to System.out
@@ -10,4 +11,10 @@ public class SystemConsoleHandler extends ConsoleHandler {
super();
setOutputStream(System.out);
}
+
+ @Override
+ public void publish(final LogRecord logRecord) {
+ System.out.println("PUBLISH");
+ System.out.println(logRecord.getMessage());
+ }
}
diff --git a/parabotv2/src/org/parabot/core/paint/PaintDebugger.java b/parabotv2/src/org/parabot/core/paint/PaintDebugger.java
index ba12815..7453174 100644
--- a/parabotv2/src/org/parabot/core/paint/PaintDebugger.java
+++ b/parabotv2/src/org/parabot/core/paint/PaintDebugger.java
@@ -10,7 +10,7 @@ import org.parabot.core.Context;
/**
*
- * @author Clisprail
+ * @author Everel
*
*/
public class PaintDebugger {
diff --git a/parabotv2/src/org/parabot/core/parsers/HookParser.java b/parabotv2/src/org/parabot/core/parsers/HookParser.java
index 2332a45..80a76db 100644
--- a/parabotv2/src/org/parabot/core/parsers/HookParser.java
+++ b/parabotv2/src/org/parabot/core/parsers/HookParser.java
@@ -9,8 +9,10 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.parabot.core.asm.adapters.AddInterfaceAdapter;
import org.parabot.core.asm.interfaces.Injectable;
+import org.parabot.core.asm.wrappers.Callback;
import org.parabot.core.asm.wrappers.Getter;
import org.parabot.core.asm.wrappers.Interface;
+import org.parabot.core.asm.wrappers.Invoker;
import org.parabot.core.asm.wrappers.Setter;
import org.parabot.core.asm.wrappers.Super;
import org.parabot.environment.api.utils.WebUtil;
@@ -21,56 +23,60 @@ import org.w3c.dom.NodeList;
/**
*
- * Parses an XML files which injects the hooks and other bytecode manipulation methods
+ * Parses an XML files which injects the hooks and other bytecode manipulation
+ * methods
+ *
+ * @author Everel
*
- * @author Clisprail
- *
*/
public class HookParser {
private Document doc = null;
private boolean parsedInterfaces = false;
private HashMap interfaceMap = new HashMap();
-
+
private HashMap constants = new HashMap();
-
+
public HookParser(URL url) {
try {
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory
+ .newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(WebUtil.getInputStream(url));
doc.getDocumentElement().normalize();
- if(!doc.getDocumentElement().getNodeName().equals("injector")) {
+ if (!doc.getDocumentElement().getNodeName().equals("injector")) {
throw new RuntimeException("Incorrect hook file.");
}
} catch (Throwable t) {
throw new RuntimeException("Unable to parse hooks " + t);
}
}
-
+
public final Interface[] getInterfaces() {
parsedInterfaces = true;
- final NodeList interfaceRootList = doc.getElementsByTagName("interfaces");
- switch(interfaceRootList.getLength()) {
- case 0:
+ final NodeList interfaceRootList = doc
+ .getElementsByTagName("interfaces");
+ switch (interfaceRootList.getLength()) {
+ case 0:
return null;
case 1:
break;
default:
- throw new RuntimeException("Hook file may not contains multiple tags ");
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
}
final Node node = interfaceRootList.item(0);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
final Element interfaceRoot = (Element) node;
final NodeList interfaces = interfaceRoot.getElementsByTagName("add");
- if(interfaces.getLength() == 0) {
+ if (interfaces.getLength() == 0) {
return null;
}
final ArrayList interfaceList = new ArrayList();
- for(int x = 0; x < interfaces.getLength(); x++) {
+ for (int x = 0; x < interfaces.getLength(); x++) {
final Node n = interfaces.item(x);
- if(n.getNodeType() != Node.ELEMENT_NODE) {
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final Element addInterface = (Element) n;
@@ -82,30 +88,31 @@ public class HookParser {
}
return interfaceList.toArray(new Interface[interfaceList.size()]);
}
-
+
public final Super[] getSupers() {
final NodeList interfaceRootList = doc.getElementsByTagName("supers");
- switch(interfaceRootList.getLength()) {
- case 0:
+ switch (interfaceRootList.getLength()) {
+ case 0:
return null;
case 1:
break;
default:
- throw new RuntimeException("Hook file may not contains multiple tags ");
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
}
final Node node = interfaceRootList.item(0);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
final Element superRoot = (Element) node;
final NodeList supers = superRoot.getElementsByTagName("add");
- if(supers.getLength() == 0) {
+ if (supers.getLength() == 0) {
return null;
}
final ArrayList superList = new ArrayList();
- for(int x = 0; x < supers.getLength(); x++) {
+ for (int x = 0; x < supers.getLength(); x++) {
final Node n = supers.item(x);
- if(n.getNodeType() != Node.ELEMENT_NODE) {
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final Element addSuper = (Element) n;
@@ -116,188 +123,358 @@ public class HookParser {
}
return superList.toArray(new Super[superList.size()]);
}
-
+
public final Getter[] getGetters() {
final NodeList getterRootList = doc.getElementsByTagName("getters");
- switch(getterRootList.getLength()) {
- case 0:
+ switch (getterRootList.getLength()) {
+ case 0:
return null;
case 1:
break;
default:
- throw new RuntimeException("Hook file may not contains multiple tags ");
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
}
final Node node = getterRootList.item(0);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
final Element getterRoot = (Element) node;
final NodeList getters = getterRoot.getElementsByTagName("add");
- if(getters.getLength() == 0) {
+ if (getters.getLength() == 0) {
return null;
}
final ArrayList getterList = new ArrayList();
- for(int x = 0; x < getters.getLength(); x++) {
+ for (int x = 0; x < getters.getLength(); x++) {
final Node n = getters.item(x);
- if(n.getNodeType() != Node.ELEMENT_NODE) {
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final Element addGetter = (Element) n;
- if(isSet("classname", addGetter) && isSet("accessor", addGetter)) {
- throw new RuntimeException("Can't set classname and accessor tag together.");
+ if (isSet("classname", addGetter) && isSet("accessor", addGetter)) {
+ throw new RuntimeException(
+ "Can't set classname and accessor tag together.");
}
- if(isSet("accessor", addGetter) && !parsedInterfaces) {
- throw new RuntimeException("You'll need to parse interfaces first.");
+ if (isSet("accessor", addGetter) && !parsedInterfaces) {
+ throw new RuntimeException(
+ "You'll need to parse interfaces first.");
}
- final String className = isSet("classname", addGetter) ? getValue("classname", addGetter) : interfaceMap.get(getValue("accessor", addGetter));
- final String into = isSet("into", addGetter) ? getValue("into", addGetter) : className;
+ final String className = isSet("classname", addGetter) ? getValue(
+ "classname", addGetter) : interfaceMap.get(getValue(
+ "accessor", addGetter));
+ final String into = isSet("into", addGetter) ? getValue("into",
+ addGetter) : className;
final String fieldName = getValue("field", addGetter);
final String methodName = getValue("methodname", addGetter);
- boolean staticMethod = isSet("methstatic", addGetter) ? (getValue("methstatic", addGetter).equals("true")) : false;
- String returnDesc = isSet("desc", addGetter) ? getValue("desc", addGetter) : null;
+ boolean staticMethod = isSet("methstatic", addGetter) ? (getValue(
+ "methstatic", addGetter).equals("true")) : false;
+ String returnDesc = isSet("desc", addGetter) ? getValue("desc",
+ addGetter) : null;
String array = "";
- if(returnDesc != null && returnDesc.contains("%s")) {
+ if (returnDesc != null && returnDesc.contains("%s")) {
StringBuilder str = new StringBuilder();
- if(returnDesc.startsWith("[")) {
- for( int i=0; i injectables = new ArrayList();
Interface[] interfaces = getInterfaces();
- if(interfaces != null) {
- for(Interface inf : interfaces) {
+ if (interfaces != null) {
+ for (Interface inf : interfaces) {
injectables.add(inf);
}
}
Getter[] getters = getGetters();
- if(getters != null) {
- for(Getter get : getters) {
+ if (getters != null) {
+ for (Getter get : getters) {
injectables.add(get);
}
}
Setter[] setters = getSetters();
- if(setters != null) {
- for(Setter set : setters) {
+ if (setters != null) {
+ for (Setter set : setters) {
injectables.add(set);
}
}
Super[] supers = getSupers();
- if(supers != null) {
- for(Super sup : supers) {
+ if (supers != null) {
+ for (Super sup : supers) {
injectables.add(sup);
}
}
+ Invoker[] invokers = getInvokers();
+ if (invokers != null) {
+ for (Invoker vok : invokers) {
+ injectables.add(vok);
+ }
+ }
+ Callback[] callbacks = getCallbacks();
+ if (callbacks != null) {
+ for (Callback callback : callbacks) {
+ injectables.add(callback);
+ }
+ }
return injectables.toArray(new Injectable[injectables.size()]);
}
-
+
public final Setter[] getSetters() {
final NodeList setterRootList = doc.getElementsByTagName("setters");
- switch(setterRootList.getLength()) {
- case 0:
+ switch (setterRootList.getLength()) {
+ case 0:
return null;
case 1:
break;
default:
- throw new RuntimeException("Hook file may not contains multiple tags ");
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
}
final Node node = setterRootList.item(0);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
final Element setterRoot = (Element) node;
final NodeList setters = setterRoot.getElementsByTagName("add");
- if(setters.getLength() == 0) {
+ if (setters.getLength() == 0) {
return null;
}
final ArrayList setterList = new ArrayList();
- for(int x = 0; x < setters.getLength(); x++) {
+ for (int x = 0; x < setters.getLength(); x++) {
final Node n = setters.item(x);
- if(n.getNodeType() != Node.ELEMENT_NODE) {
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final Element addSetter = (Element) n;
- if(isSet("classname", addSetter) && isSet("accessor", addSetter)) {
- throw new RuntimeException("Can't set classname and accessor tag together.");
+ if (isSet("classname", addSetter) && isSet("accessor", addSetter)) {
+ throw new RuntimeException(
+ "Can't set classname and accessor tag together.");
}
- if(isSet("accessor", addSetter) && !parsedInterfaces) {
- throw new RuntimeException("You'll need to parse interfaces first.");
+ if (isSet("accessor", addSetter) && !parsedInterfaces) {
+ throw new RuntimeException(
+ "You'll need to parse interfaces first.");
}
- final String className = isSet("classname", addSetter) ? getValue("classname", addSetter) : interfaceMap.get(getValue("accessor", addSetter));
- final String into = isSet("into", addSetter) ? getValue("into", addSetter) : className;
+ final String className = isSet("classname", addSetter) ? getValue(
+ "classname", addSetter) : interfaceMap.get(getValue(
+ "accessor", addSetter));
+ final String into = isSet("into", addSetter) ? getValue("into",
+ addSetter) : className;
final String fieldName = getValue("field", addSetter);
final String methodName = getValue("methodname", addSetter);
- boolean staticMethod = isSet("methstatic", addSetter) ? (getValue("methstatic", addSetter).equals("true")) : false;
- String returnDesc = isSet("desc", addSetter) ? getValue("desc", addSetter) : null;
+ boolean staticMethod = isSet("methstatic", addSetter) ? (getValue(
+ "methstatic", addSetter).equals("true")) : false;
+ String returnDesc = isSet("desc", addSetter) ? getValue("desc",
+ addSetter) : null;
String array = "";
- if(returnDesc != null && returnDesc.contains("%s")) {
+ if (returnDesc != null && returnDesc.contains("%s")) {
StringBuilder str = new StringBuilder();
- if(returnDesc.startsWith("[")) {
- for( int i=0; i 0;
- }
-
- private static final String getValue(String tag, Element element) {
- NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
- Node node = (Node) nodes.item(0);
- return node.getNodeValue();
- }
-
- public final HashMap getConstants() {
- if(!constants.isEmpty()) {
- return constants;
- }
- final NodeList constantsRootList = doc.getElementsByTagName("constants");
- switch(constantsRootList.getLength()) {
- case 0:
+
+ public final Invoker[] getInvokers() {
+ final NodeList invokerRootList = doc.getElementsByTagName("invokers");
+ switch (invokerRootList.getLength()) {
+ case 0:
return null;
case 1:
break;
default:
- throw new RuntimeException("Hook file may not contains multiple tags ");
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
+ }
+ final Node node = invokerRootList.item(0);
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ return null;
+ }
+ final Element invokerRoot = (Element) node;
+ final NodeList invokers = invokerRoot.getElementsByTagName("add");
+ if (invokers.getLength() == 0) {
+ return null;
+ }
+ final ArrayList invokerList = new ArrayList();
+ for (int x = 0; x < invokers.getLength(); x++) {
+ final Node n = invokers.item(x);
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+ final Element addInvoker = (Element) n;
+ if (isSet("classname", addInvoker) && isSet("accessor", addInvoker)) {
+ throw new RuntimeException(
+ "Can't set classname and accessor tag together.");
+ }
+ if (isSet("accessor", addInvoker) && !parsedInterfaces) {
+ throw new RuntimeException(
+ "You'll need to parse interfaces first.");
+ }
+ final String className = isSet("classname", addInvoker) ? getValue(
+ "classname", addInvoker) : interfaceMap.get(getValue(
+ "accessor", addInvoker));
+ final String into = isSet("into", addInvoker) ? getValue("into",
+ addInvoker) : className;
+ final String methodName = getValue("methodname", addInvoker);
+ final String invMethodName = getValue("invokemethod", addInvoker);
+ final String argsDesc = getValue("argsdesc", addInvoker);
+ String returnDesc = isSet("desc", addInvoker) ? resolveDesc(getValue(
+ "desc", addInvoker)) : null;
+
+ final Invoker invoker = new Invoker(into, className, invMethodName,
+ argsDesc, returnDesc, methodName);
+ invokerList.add(invoker);
+ }
+ return invokerList.toArray(new Invoker[invokerList.size()]);
+ }
+
+ public final Callback[] getCallbacks() {
+ final NodeList callbackRootList = doc.getElementsByTagName("callbacks");
+ switch (callbackRootList.getLength()) {
+ case 0:
+ return null;
+ case 1:
+ break;
+ default:
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
+ }
+ final Node node = callbackRootList.item(0);
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
+ return null;
+ }
+ final Element callbackRoot = (Element) node;
+ final NodeList callbacks = callbackRoot.getElementsByTagName("add");
+ if (callbacks.getLength() == 0) {
+ return null;
+ }
+ final ArrayList callbackList = new ArrayList();
+ for (int x = 0; x < callbacks.getLength(); x++) {
+ final Node n = callbacks.item(x);
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
+ continue;
+ }
+ final Element addCallback = (Element) n;
+ if (isSet("classname", addCallback)
+ && isSet("accessor", addCallback)) {
+ throw new RuntimeException(
+ "Can't set classname and accessor tag together.");
+ }
+ if (isSet("accessor", addCallback) && !parsedInterfaces) {
+ throw new RuntimeException(
+ "You'll need to parse interfaces first.");
+ }
+ final String className = isSet("classname", addCallback) ? getValue(
+ "classname", addCallback) : interfaceMap.get(getValue(
+ "accessor", addCallback));
+
+ final String methodName = getValue("methodname", addCallback);
+ final String callClass = getValue("callclass", addCallback);
+ final String callMethod = getValue("callmethod", addCallback);
+ final String callDesc = getValue("calldesc", addCallback);
+ final String callArgs = getValue("callargs", addCallback);
+ final String desc = getValue("desc", addCallback);
+
+ final Callback callback = new Callback(className, methodName, desc,
+ callClass, callMethod, callDesc, callArgs);
+ callbackList.add(callback);
+ }
+ return callbackList.toArray(new Callback[callbackList.size()]);
+ }
+
+ private static String resolveDesc(String returnDesc) {
+ String array = "";
+ if (returnDesc != null && returnDesc.contains("%s")) {
+ StringBuilder str = new StringBuilder();
+ if (returnDesc.startsWith("[")) {
+ for (int i = 0; i < returnDesc.length(); i++) {
+ if (returnDesc.charAt(i) == '[') {
+ array += '[';
+ }
+ }
+ returnDesc = returnDesc.replaceAll("\\[", "");
+ }
+ str.append(array)
+ .append('L')
+ .append(String.format(returnDesc,
+ AddInterfaceAdapter.getAccessorPackage()))
+ .append(";");
+ returnDesc = str.toString();
+ }
+ return returnDesc;
+ }
+
+ private static final boolean isSet(String tag, Element element) {
+ return element.getElementsByTagName(tag).getLength() > 0;
+ }
+
+ private static final String getValue(String tag, Element element) {
+ NodeList nodes = element.getElementsByTagName(tag).item(0)
+ .getChildNodes();
+ Node node = (Node) nodes.item(0);
+ return node.getNodeValue();
+ }
+
+ public final HashMap getConstants() {
+ if (!constants.isEmpty()) {
+ return constants;
+ }
+ final NodeList constantsRootList = doc
+ .getElementsByTagName("constants");
+ switch (constantsRootList.getLength()) {
+ case 0:
+ return null;
+ case 1:
+ break;
+ default:
+ throw new RuntimeException(
+ "Hook file may not contains multiple tags ");
}
final Node node = constantsRootList.item(0);
- if(node.getNodeType() != Node.ELEMENT_NODE) {
+ if (node.getNodeType() != Node.ELEMENT_NODE) {
return null;
}
final Element constantRoot = (Element) node;
final NodeList constantsList = constantRoot.getElementsByTagName("add");
- if(constantsList.getLength() == 0) {
+ if (constantsList.getLength() == 0) {
// return empty hashmap
return constants;
}
- for(int x = 0; x < constantsList.getLength(); x++) {
+ for (int x = 0; x < constantsList.getLength(); x++) {
final Node n = constantsList.item(x);
- if(n.getNodeType() != Node.ELEMENT_NODE) {
+ if (n.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
final Element addConstant = (Element) n;
@@ -307,7 +484,5 @@ public class HookParser {
}
return constants;
}
-
-
}
diff --git a/parabotv2/src/org/parabot/core/parsers/ServerManifestParser.java b/parabotv2/src/org/parabot/core/parsers/ServerManifestParser.java
deleted file mode 100644
index 4b9fb02..0000000
--- a/parabotv2/src/org/parabot/core/parsers/ServerManifestParser.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package org.parabot.core.parsers;
-
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.parabot.core.Core;
-import org.parabot.core.Directories;
-import org.parabot.core.classpath.ClassPath;
-import org.parabot.core.desc.ServerDescription;
-import org.parabot.environment.servers.ServerManifest;
-import org.parabot.environment.servers.ServerProvider;
-import org.parabot.environment.servers.loader.ServerLoader;
-
-/**
- *
- * @author Clisprail
- *
- */
-public class ServerManifestParser {
- public static Map cache = new HashMap();
-
- /**
- * Gets server descriptions
- *
- * @return list of descriptions
- */
- public ServerDescription[] getDescriptions() {
- if (Core.inDebugMode()) {
- return localDesc();
- }
- return publicDesc();
- }
-
- private ServerDescription[] publicDesc() {
- return null;
- }
-
- private ServerDescription[] localDesc() {
- // parse classes in server directories
- final ClassPath basePath = new ClassPath();
- basePath.parseJarFiles(false);
- basePath.loadClasses(Directories.getServerPath(), null);
-
-
- ArrayList classPaths = new ArrayList();
- classPaths.add(basePath);
- for (final ClassPath classPath : basePath.getJarFiles()) {
- classPaths.add(classPath);
- }
- // list of descriptions
- final List allDescs = new ArrayList();
-
- for (final ClassPath path : classPaths) {
- final List descs = new ArrayList();
- // init the server loader
- final ServerLoader loader = new ServerLoader(path);
- // list of providers
- final List providers = new ArrayList();
-
- // loop through all classes which extends the 'ServerProvider' class
- for (final String className : loader.getServerClassNames()) {
- try {
- // get class
- final Class> serverProviderClass = loader.loadClass(className);
- // get annotation
- final Object annotation = serverProviderClass
- .getAnnotation(ServerManifest.class);
- if (annotation == null) {
- throw new RuntimeException("Missing manifest at "
- + className);
- }
- // cast object annotation to server manifest annotation
- final ServerManifest manifest = (ServerManifest) annotation;
- // get constructor
- final Constructor> con = serverProviderClass.getConstructor();
- final ServerProvider server = (ServerProvider) con.newInstance();
- providers.add(server);
- descs.add(new ServerDescription(manifest.name(), manifest
- .author(), 0, providers.size() - 1));
- } catch (Throwable t) {
- t.printStackTrace();
- }
- }
- if (providers.isEmpty()) {
- continue;
- }
- final ServerCache cachedServer = new ServerCache(loader, providers.toArray(new ServerProvider[providers.size()]));
- for (final ServerDescription desc : descs) {
- allDescs.add(desc);
- cache.put(desc, cachedServer);
- }
- }
- return allDescs.toArray(new ServerDescription[allDescs.size()]);
- }
-
- public class ServerCache {
- private ServerLoader serverLoader = null;
- private ServerProvider[] serverProviders = null;
-
- private ServerCache(final ServerLoader serverLoader,
- final ServerProvider[] serverProviders) {
- this.serverLoader = serverLoader;
- this.serverProviders = serverProviders;
- }
-
- public ServerLoader getLoader() {
- return serverLoader;
- }
-
- public ServerProvider[] getProviders() {
- return serverProviders;
- }
- }
-
-}
diff --git a/parabotv2/src/org/parabot/core/parsers/ScriptManifestParser.java b/parabotv2/src/org/parabot/core/parsers/scripts/LocalJavaScripts.java
similarity index 53%
rename from parabotv2/src/org/parabot/core/parsers/ScriptManifestParser.java
rename to parabotv2/src/org/parabot/core/parsers/scripts/LocalJavaScripts.java
index 056afef..90dbee0 100644
--- a/parabotv2/src/org/parabot/core/parsers/ScriptManifestParser.java
+++ b/parabotv2/src/org/parabot/core/parsers/scripts/LocalJavaScripts.java
@@ -1,52 +1,32 @@
-package org.parabot.core.parsers;
+package org.parabot.core.parsers.scripts;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.desc.ScriptDescription;
+import org.parabot.environment.scripts.LocalScriptExecuter;
import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.ScriptManifest;
-import org.parabot.environment.scripts.loader.ScriptLoader;
+import org.parabot.environment.scripts.loader.JavaScriptLoader;
/**
*
- * @author Clisprail
- *
+ * @author Everel
+ *
*/
-public class ScriptManifestParser {
-
- public static Map scriptCache = new HashMap();
+public class LocalJavaScripts extends ScriptParser {
- /**
- * Gets server descriptions
- *
- * @return list of descriptions
- */
- public ScriptDescription[] getDescriptions() {
- scriptCache.clear();
- if (Core.inDebugMode()) {
- return localDesc();
- }
- return publicDesc();
- }
-
- private ScriptDescription[] publicDesc() {
- return null;
- }
-
- private ScriptDescription[] localDesc() {
+ @Override
+ public void execute() {
// parse classes in server directories
final ClassPath path = new ClassPath();
- path.loadClasses(Directories.getScriptCompiledPath(), null);
+ path.addClasses(Directories.getScriptCompiledPath());
// init the script loader
- final ScriptLoader loader = new ScriptLoader(path);
+ final JavaScriptLoader loader = new JavaScriptLoader(path);
// list of scripts
final List