mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-04 08:39:23 +00:00
[CLEANUP] Reformatted code
This commit is contained in:
@@ -9,44 +9,42 @@ import org.parabot.environment.servers.executers.ServerExecuter;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads locally stored server providers
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
@Deprecated
|
||||
public class LocalServerExecuter extends ServerExecuter {
|
||||
private final ServerProvider serverProvider;
|
||||
private ClassPath classPath;
|
||||
private String serverName;
|
||||
private final ServerProvider serverProvider;
|
||||
private ClassPath classPath;
|
||||
private String serverName;
|
||||
|
||||
public LocalServerExecuter(ServerProvider serverProvider,
|
||||
ClassPath classPath, final String serverName) {
|
||||
this.serverProvider = serverProvider;
|
||||
this.classPath = classPath;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
public LocalServerExecuter(ServerProvider serverProvider,
|
||||
ClassPath classPath, final String serverName) {
|
||||
this.serverProvider = serverProvider;
|
||||
this.classPath = classPath;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// add jar or directory to buildpath.
|
||||
if (this.classPath.isJar()) {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
super.finalize(this.serverProvider, this.serverName);
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
// add jar or directory to buildpath.
|
||||
if (this.classPath.isJar()) {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
super.finalize(this.serverProvider, this.serverName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@ import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* A server manifest
|
||||
* @author Everel
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ServerManifest {
|
||||
|
||||
String author();
|
||||
String author();
|
||||
|
||||
String name();
|
||||
String name();
|
||||
|
||||
double version();
|
||||
double version();
|
||||
|
||||
Type type();
|
||||
Type type();
|
||||
|
||||
}
|
||||
|
||||
@@ -10,141 +10,140 @@ import org.parabot.environment.input.Mouse;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.applet.AppletStub;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.*;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Provides a server to the bot
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public abstract class ServerProvider implements Opcodes {
|
||||
|
||||
/**
|
||||
* Get the game/applet dimensions
|
||||
* @return game/applet dimensions
|
||||
*/
|
||||
public Dimension getGameDimensions() {
|
||||
return new Dimension(765, 503);
|
||||
}
|
||||
/**
|
||||
* Get the game/applet dimensions
|
||||
*
|
||||
* @return game/applet dimensions
|
||||
*/
|
||||
public Dimension getGameDimensions() {
|
||||
return new Dimension(765, 503);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hooks to parse
|
||||
*
|
||||
* @deprecated use getHookFile() now
|
||||
* @return URL to hooks file
|
||||
*/
|
||||
@Deprecated
|
||||
public URL getHooks() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get hook file to parse
|
||||
* @return hook file
|
||||
*/
|
||||
public HookFile getHookFile() {
|
||||
return null;
|
||||
}
|
||||
* Hooks to parse
|
||||
*
|
||||
* @return URL to hooks file
|
||||
*
|
||||
* @deprecated use getHookFile() now
|
||||
*/
|
||||
@Deprecated
|
||||
public URL getHooks() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Jar to parse
|
||||
*
|
||||
* @return URL to client jar
|
||||
*/
|
||||
public abstract URL getJar();
|
||||
/**
|
||||
* Get hook file to parse
|
||||
*
|
||||
* @return hook file
|
||||
*/
|
||||
public HookFile getHookFile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract Applet fetchApplet();
|
||||
/**
|
||||
* Jar to parse
|
||||
*
|
||||
* @return URL to client jar
|
||||
*/
|
||||
public abstract URL getJar();
|
||||
|
||||
public String getAccessorsPackage() {
|
||||
return null;
|
||||
}
|
||||
public abstract Applet fetchApplet();
|
||||
|
||||
public void injectHooks() {
|
||||
HookFile hookFile = fetchHookFile();
|
||||
|
||||
if(hookFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HookParser parser = hookFile.getParser();
|
||||
Injectable[] injectables = parser.getInjectables();
|
||||
if (injectables == null) {
|
||||
return;
|
||||
}
|
||||
for (Injectable inj : injectables) {
|
||||
inj.inject();
|
||||
}
|
||||
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);
|
||||
}
|
||||
public String getAccessorsPackage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add custom items to the bot menu bar
|
||||
*
|
||||
* @param bar
|
||||
* menu bar to add items on
|
||||
*/
|
||||
public void addMenuItems(JMenuBar bar) {
|
||||
}
|
||||
public void injectHooks() {
|
||||
HookFile hookFile = fetchHookFile();
|
||||
|
||||
public AppletStub getStub() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setClientInstance(Object client) {
|
||||
Context.getInstance().setClientInstance(client);
|
||||
}
|
||||
if (hookFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void parseJar() {
|
||||
Context.getInstance().getClassPath().addJar(getJar());
|
||||
}
|
||||
|
||||
public void initScript(Script script) {
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
public void initMouse() {
|
||||
final Context context = Context.getInstance();
|
||||
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 Keyboard keyboard = new Keyboard(applet);
|
||||
applet.addKeyListener(keyboard);
|
||||
context.setKeyboard(keyboard);
|
||||
}
|
||||
|
||||
public void unloadScript(Script script) {
|
||||
|
||||
}
|
||||
HookParser parser = hookFile.getParser();
|
||||
Injectable[] injectables = parser.getInjectables();
|
||||
if (injectables == null) {
|
||||
return;
|
||||
}
|
||||
for (Injectable inj : injectables) {
|
||||
inj.inject();
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param bar menu bar to add items on
|
||||
*/
|
||||
public void addMenuItems(JMenuBar bar) {
|
||||
}
|
||||
|
||||
public AppletStub getStub() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setClientInstance(Object client) {
|
||||
Context.getInstance().setClientInstance(client);
|
||||
}
|
||||
|
||||
public void parseJar() {
|
||||
Context.getInstance().getClassPath().addJar(getJar());
|
||||
}
|
||||
|
||||
public void initScript(Script script) {
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
public void initMouse() {
|
||||
final Context context = Context.getInstance();
|
||||
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 Keyboard keyboard = new Keyboard(applet);
|
||||
applet.addKeyListener(keyboard);
|
||||
context.setKeyboard(keyboard);
|
||||
}
|
||||
|
||||
public void unloadScript(Script script) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.parabot.environment.servers;
|
||||
|
||||
/**
|
||||
*
|
||||
* Server provider type
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
* @author Everel
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
INJECTION, REFLECTION, COLOR, LOADER, OTHER
|
||||
|
||||
INJECTION, REFLECTION, COLOR, LOADER, OTHER
|
||||
|
||||
}
|
||||
|
||||
+91
-96
@@ -1,14 +1,11 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
import org.parabot.core.forum.AccountManager;
|
||||
import org.parabot.core.forum.AccountManagerAccess;
|
||||
import org.parabot.core.ui.components.VerboseLoader;
|
||||
import org.parabot.core.ui.utils.UILog;
|
||||
import org.parabot.environment.api.utils.FileUtil;
|
||||
@@ -22,113 +19,111 @@ import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Fetches a server provider from the local config file
|
||||
*
|
||||
*
|
||||
* @author JKetelaar
|
||||
*
|
||||
*/
|
||||
public class LocalPublicServerExecuter extends ServerExecuter {
|
||||
private String serverName;
|
||||
private String serverUrl;
|
||||
private String providerUrl;
|
||||
private ServerProviderInfo serverProviderInfo;
|
||||
private String serverName;
|
||||
private String serverUrl;
|
||||
private String providerUrl;
|
||||
private ServerProviderInfo serverProviderInfo;
|
||||
|
||||
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
|
||||
this.serverName = serverName;
|
||||
this.serverUrl = serverUrl;
|
||||
this.providerUrl = providerUrl;
|
||||
this.serverProviderInfo = serverProviderInfo;
|
||||
}
|
||||
public LocalPublicServerExecuter(final String serverName, final ServerProviderInfo serverProviderInfo, String serverUrl, String providerUrl) {
|
||||
this.serverName = serverName;
|
||||
this.serverUrl = serverUrl;
|
||||
this.providerUrl = providerUrl;
|
||||
this.serverProviderInfo = serverProviderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
|
||||
Core.verbose("Downloading: " + providerUrl + " ...");
|
||||
|
||||
if(destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(providerUrl)).exists()){
|
||||
FileUtil.copyFile(local, destination);
|
||||
Core.verbose("Server provider copied...");
|
||||
}else {
|
||||
WebUtil.downloadFile(new URL(providerUrl), destination, VerboseLoader.get());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
}
|
||||
Core.verbose("Downloading: " + providerUrl + " ...");
|
||||
|
||||
final File clientDestination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getClientCRC32() + ".jar");
|
||||
if (destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(providerUrl)).exists()) {
|
||||
FileUtil.copyFile(local, destination);
|
||||
Core.verbose("Server provider copied...");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(providerUrl), destination, VerboseLoader.get());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
}
|
||||
|
||||
Core.verbose("Downloading: " + serverUrl + " ...");
|
||||
final File clientDestination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getClientCRC32() + ".jar");
|
||||
|
||||
if(clientDestination.exists()) {
|
||||
Core.verbose("Found cached client [CRC32: " + serverProviderInfo.getClientCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(serverUrl)).exists()){
|
||||
FileUtil.copyFile(local, clientDestination);
|
||||
Core.verbose("Server client copied...");
|
||||
}else {
|
||||
WebUtil.downloadFile(new URL(serverUrl), clientDestination, VerboseLoader.get());
|
||||
Core.verbose("Server client downloaded...");
|
||||
}
|
||||
}
|
||||
Core.verbose("Downloading: " + serverUrl + " ...");
|
||||
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(destination);
|
||||
if (clientDestination.exists()) {
|
||||
Core.verbose("Found cached client [CRC32: " + serverProviderInfo.getClientCRC32() + "]");
|
||||
} else {
|
||||
File local;
|
||||
if ((local = new File(serverUrl)).exists()) {
|
||||
FileUtil.copyFile(local, clientDestination);
|
||||
Core.verbose("Server client copied...");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(serverUrl), clientDestination, VerboseLoader.get());
|
||||
Core.verbose("Server client downloaded...");
|
||||
}
|
||||
}
|
||||
|
||||
BuildPath.add(destination.toURI().toURL());
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(destination);
|
||||
|
||||
ServerLoader serverLoader = new ServerLoader(classPath);
|
||||
final String[] classNames = serverLoader.getServerClassNames();
|
||||
if (classNames.length == 0) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [No provider found in jar file.]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} else if (classNames.length > 1) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [Multiple providers found in jar file.]");
|
||||
return;
|
||||
}
|
||||
BuildPath.add(destination.toURI().toURL());
|
||||
|
||||
final String className = classNames[0];
|
||||
try {
|
||||
final Class<?> providerClass = serverLoader
|
||||
.loadClass(className);
|
||||
final Constructor<?> con = providerClass.getConstructor();
|
||||
final ServerProvider serverProvider = (ServerProvider) con
|
||||
.newInstance();
|
||||
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
|
||||
super.finalize(serverProvider, this.serverName);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [This server provider is not compatible with this version of parabot]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
ServerLoader serverLoader = new ServerLoader(classPath);
|
||||
final String[] classNames = serverLoader.getServerClassNames();
|
||||
if (classNames.length == 0) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [No provider found in jar file.]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} else if (classNames.length > 1) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [Multiple providers found in jar file.]");
|
||||
return;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
final String className = classNames[0];
|
||||
try {
|
||||
final Class<?> providerClass = serverLoader
|
||||
.loadClass(className);
|
||||
final Constructor<?> con = providerClass.getConstructor();
|
||||
final ServerProvider serverProvider = (ServerProvider) con
|
||||
.newInstance();
|
||||
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
|
||||
super.finalize(serverProvider, this.serverName);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [This server provider is not compatible with this version of parabot]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,53 @@
|
||||
package org.parabot.environment.servers.executers;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.Directories;
|
||||
import org.parabot.core.build.BuildPath;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads locally stored server providers
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class LocalServerExecuter extends ServerExecuter {
|
||||
private final Constructor<?> serverProviderConstructor;
|
||||
private ClassPath classPath;
|
||||
private String serverName;
|
||||
private final Constructor<?> serverProviderConstructor;
|
||||
private ClassPath classPath;
|
||||
private String serverName;
|
||||
|
||||
public LocalServerExecuter(Constructor<?> serverProviderConstructor,
|
||||
ClassPath classPath, final String serverName) {
|
||||
this.serverProviderConstructor = serverProviderConstructor;
|
||||
this.classPath = classPath;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
public LocalServerExecuter(Constructor<?> serverProviderConstructor,
|
||||
ClassPath classPath, final String serverName) {
|
||||
this.serverProviderConstructor = serverProviderConstructor;
|
||||
this.classPath = classPath;
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// add jar or directory to buildpath.
|
||||
if (this.classPath.isJar()) {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
try {
|
||||
super.finalize((ServerProvider) serverProviderConstructor.newInstance(), this.serverName);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
// add jar or directory to buildpath.
|
||||
if (this.classPath.isJar()) {
|
||||
Core.verbose("Adding server provider jar to buildpath: "
|
||||
+ this.classPath.lastParsed.toString());
|
||||
this.classPath.addToBuildPath();
|
||||
} else {
|
||||
Core.verbose("Adding server providers directory to buildpath: "
|
||||
+ Directories.getServerPath().getPath());
|
||||
try {
|
||||
BuildPath.add(Directories.getServerPath().toURI().toURL());
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// finalize
|
||||
try {
|
||||
super.finalize((ServerProvider) serverProviderConstructor.newInstance(), this.serverName);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,106 +16,100 @@ import org.parabot.environment.servers.ServerProvider;
|
||||
import org.parabot.environment.servers.loader.ServerLoader;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* Fetches a server provider from the Parabot BDN
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*/
|
||||
public class PublicServerExecuter extends ServerExecuter {
|
||||
private String serverName;
|
||||
|
||||
private static AccountManager manager;
|
||||
private static AccountManager manager;
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
|
||||
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PublicServerExecuter.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setManager(AccountManager manager) {
|
||||
PublicServerExecuter.manager = manager;
|
||||
}
|
||||
};
|
||||
private String serverName;
|
||||
|
||||
};
|
||||
public PublicServerExecuter(final String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
|
||||
public PublicServerExecuter(final String serverName) {
|
||||
this.serverName = serverName;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
|
||||
+ this.serverName), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
|
||||
+ this.serverName), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly(), serverName);
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
final String jarUrl = String.format(Configuration.GET_SERVER_PROVIDER, Configuration.BOT_VERSION.isNightly(), serverName);
|
||||
|
||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||
|
||||
if(destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(jarUrl), destination,
|
||||
VerboseLoader.get());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||
|
||||
if (destination.exists()) {
|
||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||
} else {
|
||||
WebUtil.downloadFile(new URL(jarUrl), destination,
|
||||
VerboseLoader.get());
|
||||
Core.verbose("Server provider downloaded...");
|
||||
}
|
||||
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(destination);
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(destination);
|
||||
|
||||
BuildPath.add(destination.toURI().toURL());
|
||||
BuildPath.add(destination.toURI().toURL());
|
||||
|
||||
ServerLoader serverLoader = new ServerLoader(classPath);
|
||||
final String[] classNames = serverLoader.getServerClassNames();
|
||||
if (classNames == null || classNames.length == 0) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [No provider found in jar file.]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} else if (classNames.length > 1) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [Multiple providers found in jar file.]");
|
||||
return;
|
||||
}
|
||||
ServerLoader serverLoader = new ServerLoader(classPath);
|
||||
final String[] classNames = serverLoader.getServerClassNames();
|
||||
if (classNames == null || classNames.length == 0) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [No provider found in jar file.]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
} else if (classNames.length > 1) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [Multiple providers found in jar file.]");
|
||||
return;
|
||||
}
|
||||
|
||||
final String className = classNames[0];
|
||||
try {
|
||||
final Class<?> providerClass = serverLoader
|
||||
.loadClass(className);
|
||||
final Constructor<?> con = providerClass.getConstructor();
|
||||
final ServerProvider serverProvider = (ServerProvider) con
|
||||
.newInstance();
|
||||
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
|
||||
super.finalize(serverProvider, this.serverName);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
final String className = classNames[0];
|
||||
try {
|
||||
final Class<?> providerClass = serverLoader
|
||||
.loadClass(className);
|
||||
final Constructor<?> con = providerClass.getConstructor();
|
||||
final ServerProvider serverProvider = (ServerProvider) con
|
||||
.newInstance();
|
||||
Context.getInstance(serverProvider).setProviderInfo(serverProviderInfo);
|
||||
super.finalize(serverProvider, this.serverName);
|
||||
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, error: [This server provider is not compitable with this version of parabot]",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
UILog.log(
|
||||
"Error",
|
||||
"Failed to load server provider, post the stacktrace/error on the parabot forums.",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,44 @@
|
||||
package org.parabot.environment.servers.loader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* An environment to load a server
|
||||
*
|
||||
*
|
||||
* @author Everel
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ServerLoader extends ASMClassLoader {
|
||||
private ClassPath classPath;
|
||||
private ClassPath classPath;
|
||||
|
||||
public ServerLoader(ClassPath classPath) {
|
||||
super(classPath);
|
||||
this.classPath = classPath;
|
||||
}
|
||||
public ServerLoader(ClassPath classPath) {
|
||||
super(classPath);
|
||||
this.classPath = classPath;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets all classes that extends ServerProvider
|
||||
* @return string array of class names that extends ServerProvider
|
||||
*/
|
||||
public final String[] getServerClassNames() {
|
||||
final List<String> classNames = new ArrayList<String>();
|
||||
for (ClassNode c : classPath.classes.values())
|
||||
if (c.superName.replace('/', '.').equals(
|
||||
ServerProvider.class.getName())) {
|
||||
classNames.add(c.name.replace('/', '.'));
|
||||
}
|
||||
return classNames.toArray(new String[classNames.size()]);
|
||||
}
|
||||
|
||||
public ClassPath getClassPath() {
|
||||
return classPath;
|
||||
}
|
||||
/**
|
||||
* Gets all classes that extends ServerProvider
|
||||
*
|
||||
* @return string array of class names that extends ServerProvider
|
||||
*/
|
||||
public final String[] getServerClassNames() {
|
||||
final List<String> classNames = new ArrayList<String>();
|
||||
for (ClassNode c : classPath.classes.values()) {
|
||||
if (c.superName.replace('/', '.').equals(
|
||||
ServerProvider.class.getName())) {
|
||||
classNames.add(c.name.replace('/', '.'));
|
||||
}
|
||||
}
|
||||
return classNames.toArray(new String[classNames.size()]);
|
||||
}
|
||||
|
||||
public ClassPath getClassPath() {
|
||||
return classPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user