Merge pull request #42 from Parabot/development

[MERGE] Development into master
This commit is contained in:
Jeroen Ketelaar
2016-01-10 19:18:59 +01:00
23 changed files with 464 additions and 86 deletions
+2 -8
View File
@@ -11,6 +11,7 @@ import org.parabot.core.network.proxy.ProxyType;
import org.parabot.core.ui.BotUI;
import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.JavaUtil;
import javax.swing.*;
import java.awt.*;
@@ -112,14 +113,7 @@ public final class Landing {
Directories.setServerCompiledDirectory(new File(args[++i]));
break;
case "-clearcache":
File[] cache = Directories.getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
if (f.exists() && f.canWrite()) {
f.delete();
}
}
}
Directories.clearCache();
break;
case "-mac":
byte[] mac = new byte[6];
@@ -15,6 +15,7 @@ public class Configuration {
public static final String GET_SERVER_PROVIDERS = "http://bdn.parabot.org/api/get.php?action=server_providers";
public static final String GET_SERVER_PROVIDER = "http://bdn.parabot.org/api/get.php?action=server_provider&name=";
public static final String GET_SERVER_PROVIDER_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
public static final String GET_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
public static final String GET_BOT_VERSION = "http://bdn.parabot.org/api/v2/bot/version";
public static final String API_DOWNLOAD_BOT = "http://bdn.parabot.org/api/v2/bot/download/client/";
public static final String DOWNLOAD_BOT = "http://bdn.parabot.org/versions/";
+14 -6
View File
@@ -18,8 +18,9 @@ import org.parabot.environment.scripts.uliratha.UlirathaClient;
import org.parabot.environment.servers.ServerProvider;
import java.applet.Applet;
import java.awt.Dimension;
import java.awt.*;
import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.TimerTask;
@@ -27,7 +28,7 @@ import java.util.TimerTask;
/**
* Game context
*
* @author Everel
* @author Everel, JKetelaar, Matt
*/
public class Context {
public static final HashMap<ThreadGroup, Context> threadGroups = new HashMap<ThreadGroup, Context>();
@@ -36,7 +37,6 @@ public class Context {
private static Context instance;
private static String username;
public boolean added;
private ASMClassLoader classLoader;
private ClassPath classPath;
private ServerProvider serverProvider;
@@ -52,6 +52,9 @@ public class Context {
private UlirathaClient ulirathaClient;
private JSONParser jsonParser;
private PrintStream defaultOut;
private PrintStream defaultErr = System.err;
private Context(final ServerProvider serverProvider) {
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
@@ -63,7 +66,9 @@ public class Context {
this.randomHandler = new RandomHandler();
this.jsonParser = new JSONParser();
this.defaultOut = System.out;
this.defaultErr = System.err;
}
public static Context getInstance(ServerProvider serverProvider) {
@@ -174,7 +179,7 @@ public class Context {
Applet applet = serverProvider.fetchApplet();
// if applet is null the server provider will call setApplet itself
if(applet != null) {
setApplet(applet);
setApplet(applet);
}
}
@@ -188,7 +193,7 @@ public class Context {
if (getClient() == null) {
setClientInstance(gameApplet);
}
Core.verbose("Applet fetched.");
final GamePanel panel = GamePanel.getInstance();
@@ -206,6 +211,7 @@ public class Context {
gameApplet.init();
gameApplet.start();
java.util.Timer t = new java.util.Timer();
t.schedule(new TimerTask() {
@Override
@@ -222,6 +228,8 @@ public class Context {
Core.verbose("Done.");
BotDialog.getInstance().validate();
System.setOut(this.defaultOut);
System.setErr(this.defaultErr);
}
/**
+14 -2
View File
@@ -1,6 +1,8 @@
package org.parabot.core;
import com.bugsnag.BeforeNotify;
import com.bugsnag.Client;
import com.bugsnag.Error;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import org.parabot.Landing;
@@ -301,11 +303,21 @@ public class Core {
}
public static void setBugsnagVersion(){
Core.bugsnagInstance.setReleaseStage(currentVersion.compareTo(latestVersion) >= 0 ? "development" : "production");
Core.bugsnagInstance.setReleaseStage(currentVersion != latestVersion ? "development" : "production");
}
public static void setBugsnagUser(String id, String email, String username){
Core.bugsnagInstance.setUser(id, email, username);
// TODO Check order of parameters
Core.bugsnagInstance.setUser(username, email, id);
}
public static void setBugsnagServer(String server){
Core.setBugsnagInformation("Server", "Server", server);
}
public static void setBugsnagInformation(String tab, String key, String value){
// TODO Should be checked if correct
Core.bugsnagInstance.addToTab(tab, key, value);
}
public static void debug(int i) {
+107 -25
View File
@@ -7,16 +7,14 @@ import org.parabot.environment.api.utils.StringUtils;
import org.parabot.environment.api.utils.WebUtil;
import javax.swing.*;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import java.util.*;
/**
* Holds parabot's used directories
* Holds and manages Parabot's used directories
*
* @author Everel
* @author JKetelaar
* @author Matt
*/
public class Directories {
@@ -45,34 +43,48 @@ public class Directories {
Core.verbose("Directories cached.");
clearCache(259200);
setHomeDirectory();
if (Core.isSecure()) {
setHomeDirectory();
}
}
private static void setHomeDirectory(){
File cache;
tempDir = StringUtils.randomString(12);
try {
if ((cache = new File(Directories.getCachePath(), "cache.json")).exists()){
if ((cache = new File(Directories.getSettingsPath(), "cache.json")).exists()){
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(cache));
String temp;
if ((temp = (String) object.get("homedir")) != null){
cached.put("Home", new File(cached.get("Root"), "/" + temp + "/"));
}
}else{
cache.createNewFile();
JSONObject object = new JSONObject();
object.put("homedir", tempDir);
FileWriter file = new FileWriter(cache);
file.write(object.toJSONString());
file.flush();
file.close();
cached.put("Home", new File(cached.get("Root"), "/" + tempDir + "/"));
cached.put("Home", createCacheDirectory(cache));
}
} catch (IOException | ParseException ignored) {
cached.put("Home", new File(cached.get("Root"), "/" + tempDir + "/"));
}
System.out.println("Setting server cache directory to: " + cached.get("Home"));
cached.get("Home").mkdirs();
if (!cached.get("Home").exists()) {
cached.get("Home").mkdirs();
}
System.out.println("Set temporary cache directory to: " + cached.get("Home"));
}
private static File createCacheDirectory(File cacheFile) throws IOException {
cacheFile.createNewFile();
JSONObject object = new JSONObject();
object.put("homedir", tempDir);
FileWriter file = new FileWriter(cacheFile);
file.write(object.toJSONString());
file.flush();
file.close();
File cacheDir = new File(cached.get("Root"), "/" + tempDir + "/");
if (!cacheDir.exists()) {
cacheDir.mkdirs();
}
return cacheDir;
}
/**
@@ -219,8 +231,9 @@ public class Directories {
* Clears the cache based on the latest modification
*
* @param remove A long that represents the amount of seconds that a file may have since the latest modification
* @param force Defines if the cache folder, within user.home, should also be removed
*/
private static void clearCache(int remove) {
public static void clearCache(int remove, boolean force){
File[] cache = getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
@@ -230,15 +243,84 @@ public class Directories {
}
}
}
}
public static void clearCache() {
File[] cache = getCachePath().listFiles();
if (cache != null) {
for (File f : cache) {
Core.verbose("Clearing " + f.getName() + " from cache...");
f.delete();
if (force){
File cacheFile;
if ((cacheFile = new File(Directories.getSettingsPath(), "cache.json")).exists()){
try {
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(cacheFile));
if (jsonObject != null){
Object dirObject;
if ((dirObject = jsonObject.get("homedir")) != null) {
String dir = (String) dirObject;
if (dir.length() > 0) {
File cacheDir = new File(cached.get("Root"), "/" + dir + "/");
removeDirectory(cacheDir);
createCacheDirectory(cacheFile);
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
}
}
private static void clearCache(int remove) {
clearCache(remove, false);
}
public static void clearCache() {
clearCache(0, true);
}
/**
* @param file Directory to be removed
*/
private static void removeDirectory(File file) {
if (file.isDirectory()) {
if (file.list().length == 0) {
file.delete();
Core.verbose("Directory is deleted : "
+ file.getAbsolutePath());
} else {
String files[] = file.list();
for (String temp : files) {
File fileDelete = new File(file, temp);
removeDirectory(fileDelete);
}
if (file.list().length == 0) {
file.delete();
Core.verbose("Directory is deleted : "
+ file.getAbsolutePath());
}
}
} else {
file.delete();
Core.verbose("File is deleted : " + file.getAbsolutePath());
}
}
/**
* Returns an array of files with from a given directory and a given extension
*
* @param directory The directory where should be searched
* @param extension The extension to be searched for, including the dot (like .json)
* @return An array of of files that match the request
*/
public static File[] listFilesWithExtension(File directory, final String extension){
return directory.listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) {
return filename.endsWith(extension);
}
});
}
public static File[] listJSONFiles(File directory) {
return listFilesWithExtension(directory, ".json");
}
}
@@ -20,7 +20,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
private String className;
private static PrintStream str_out, class_out;
private static PrintStream str_out, class_out, dec_out;
static {
redirects.put("java/awt/Toolkit", ToolkitRedirect.class);
@@ -40,6 +40,7 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
if (str_out == null && Core.shouldDump())
try {
str_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"strings.txt")));
dec_out = new PrintStream(new FileOutputStream(new File(Directories.getWorkspace(),"decrypted_strings.txt")));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -89,8 +90,13 @@ public class RedirectClassAdapter extends ClassVisitor implements Opcodes {
@Override
public void visitLdcInsn(Object o) {
if (o instanceof String && str_out != null)
if (o instanceof String && str_out != null) {
str_out.println(className + " " + o);
if (!className.toLowerCase().contains("parabot")) {
dec_out.println(o + ":");
dec_out.println();
}
}
super.visitLdcInsn(o);
}
@@ -48,7 +48,6 @@ public class AddGetterAdapter implements Opcodes, Injectable {
final ClassNode fieldLocation, final FieldNode fieldNode,
final String methodName, final String returnDesc,
final boolean staticMethod, final long multiplier) {
System.out.println(fieldNode.name);
this.into = into;
this.fieldLocation = fieldLocation;
this.fieldNode = fieldNode;
@@ -0,0 +1,8 @@
package org.parabot.core.asm.redirect;
/**
* @author JKetelaar
*/
public class URLRedirect{
}
@@ -2,17 +2,21 @@ package org.parabot.core.desc;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.zip.CRC32;
/**
* Gets the information for the selected server provider
@@ -29,40 +33,63 @@ public class ServerProviderInfo {
this.properties = new Properties();
this.settings = new HashMap<>();
try {
String line;
Core.verbose("Reading info: " + providerInfo);
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString()), username, password);
//TODO Make this one line (web sided)
JSONParser parser = new JSONParser();
if ((line = br.readLine()) != null) {
JSONObject jsonObject = (JSONObject) parser.parse(line);
for (Object o : jsonObject.entrySet()) {
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
JSONObject object = (JSONObject) pairs.getValue();
for (Object settingObject : object.entrySet()){
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
String key = (String) settingValue.getKey();
long value = (Long) settingValue.getValue();
settings.put(key, (int) value);
}
}else {
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
}
}
} else {
UILog.log(
"Error",
"Failed to load server provider, error: [No information about the provider found.]",
JOptionPane.ERROR_MESSAGE);
return;
}
br.close();
} catch (Exception e) {
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(br);
for (Object o : jsonObject.entrySet()) {
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
JSONObject object = (JSONObject) pairs.getValue();
parseSettings(object);
}else {
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
}
}
if (br != null) {
br.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs){
this.properties = new Properties();
this.settings = new HashMap<>();
try {
BufferedReader br = WebUtil.getReader(new URL(Configuration.GET_SERVER_SETTINGS));
JSONObject settings = (JSONObject) WebUtil.getJsonParser().parse(br);
parseSettings(settings);
} catch (ParseException | IOException e) {
e.printStackTrace();
}
this.properties.setProperty("client_jar", clientJar);
this.properties.setProperty("hooks", hooks);
this.properties.setProperty("name", name);
this.properties.setProperty("client_class", clientClass);
this.properties.setProperty("provider_crc32", String.valueOf(getCRC32(name, "provider")));
this.properties.setProperty("client_crc32", String.valueOf(getCRC32(name, "client")));
this.properties.setProperty("bank_tabs", String.valueOf(bankTabs));
}
private long getCRC32(String name, String type){
CRC32 crc = new CRC32();
name += "-" + type;
crc.update(name.getBytes());
return crc.getValue();
}
private void parseSettings(JSONObject object){
for (Object settingObject : object.entrySet()){
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
String key = (String) settingValue.getKey();
long value = (Long) settingValue.getValue();
settings.put(key, (int) value);
}
}
public URL getClient() {
try {
@@ -100,7 +127,7 @@ public class ServerProviderInfo {
}
public long getCRC32() {
return Long.parseLong(properties.getProperty("provider_crc32"));
return Long.parseLong(properties.getProperty("provider_crc32"));
}
public long getClientCRC32() {
@@ -41,6 +41,12 @@ public abstract class Library {
* @return url
*/
public abstract URL getDownloadLink();
/**
* Defines if the system requires a jar
* @return boolean
*/
public abstract boolean requiresJar();
/**
@@ -7,6 +7,7 @@ import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.lib.Library;
import org.parabot.environment.api.utils.JavaUtil;
/**
*
@@ -59,6 +60,11 @@ public class JavaFX extends Library {
return null;
}
@Override
public boolean requiresJar() {
return JavaUtil.JAVA_VERSION <= 1.7;
}
@Override
public String getLibraryName() {
return "JavaFX";
@@ -67,5 +73,4 @@ public class JavaFX extends Library {
public static boolean isValid() {
return valid;
}
}
@@ -56,6 +56,11 @@ public class Naga extends Library {
return null;
}
@Override
public boolean requiresJar() {
return true;
}
@Override
public String getLibraryName() {
return "Naga";
@@ -1,19 +1,41 @@
package org.parabot.core.parsers.servers;
import java.io.File;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
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.ServerDescription;
import org.parabot.core.desc.ServerProviderInfo;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.ServerManifest;
import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
import org.parabot.environment.servers.executers.LocalServerExecuter;
import org.parabot.environment.servers.executers.PublicServerExecuter;
import org.parabot.environment.servers.loader.ServerLoader;
import javax.swing.*;
/**
* Parses local server providers located in the servers directory
*
* @author Everel
* @author Everel, JKetelaar
*/
public class LocalServers extends ServerParser {
@@ -24,7 +46,7 @@ public class LocalServers extends ServerParser {
basePath.parseJarFiles(false);
basePath.addClasses(Directories.getServerPath());
final ArrayList<ClassPath> classPaths = new ArrayList<ClassPath>();
final ArrayList<ClassPath> classPaths = new ArrayList<>();
classPaths.add(basePath);
for (final ClassPath classPath : basePath.getJarFiles()) {
classPaths.add(classPath);
@@ -64,6 +86,34 @@ public class LocalServers extends ServerParser {
}
}
for (File file : Directories.listJSONFiles(Directories.getServerPath())){
try {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(new FileReader(file));
String name = (String) object.get("name");
String author = (String) object.get("author");
double version = (Double) object.get("version");
String clientClass = (String) object.get("client-class");
Object bank;
int bankTabs = 0;
if ((bank = object.get("bank")) != null){
bankTabs = (int) bank;
}
JSONObject locations = (JSONObject) object.get("locations");
String server = (String) locations.get("server");
String provider = (String) locations.get("provider");
String hooks = (String) locations.get("hooks");
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs);
System.out.println(server);
ServerDescription desc = new ServerDescription(name,
author, version);
SERVER_CACHE.put(desc, new LocalPublicServerExecuter(name, serverProviderInfo, server, provider));
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
}
}
@@ -33,7 +33,7 @@ public class Environment {
libs.add(new Naga());
for(Library lib : libs) {
if(!lib.hasJar()) {
if(!lib.hasJar() && lib.requiresJar()) {
Core.verbose("Downloading " + lib.getLibraryName() + "...");
VerboseLoader.setState("Downloading " + lib.getLibraryName() + "...");
WebUtil.downloadFile(lib.getDownloadLink(), lib.getJarFile(), VerboseLoader.get());
@@ -43,8 +43,7 @@ public class Environment {
lib.init();
}
Core.verbose("Loading server: " + desc.toString());
Core.verbose("Loading server: " + desc.toString() + "...");
ServerParser.SERVER_CACHE.get(desc).run();
@@ -2,7 +2,9 @@ package org.parabot.environment.api.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -65,4 +67,25 @@ public class FileUtil {
return null;
}
public static void copyFile(File sourceFile, File destFile)
throws IOException {
if (!sourceFile.exists()) {
return;
}
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
if (source != null) {
destination.transferFrom(source, 0, source.size());
}
if (source != null) {
source.close();
}
destination.close();
}
}
@@ -0,0 +1,15 @@
package org.parabot.environment.api.utils;
/**
* @author JKetelaar
*/
public class JavaUtil {
public static double JAVA_VERSION = getVersion();
static double getVersion () {
String version = System.getProperty("java.version");
int pos = version.indexOf('.');
pos = version.indexOf('.', pos+1);
return Double.parseDouble (version.substring (0, pos));
}
}
@@ -156,6 +156,7 @@ public class Script implements Runnable {
if(state < 0 || state > 2) {
throw new IllegalArgumentException("Illegal state");
}
Core.setBugsnagInformation("Script", "State", String.valueOf(state));
this.state = state;
}
@@ -180,5 +181,6 @@ public class Script implements Runnable {
public void setScriptID(int scriptID){
this.scriptID = scriptID;
Core.setBugsnagInformation("Script", "State", String.valueOf(scriptID));
}
}
@@ -15,6 +15,8 @@ import java.net.MalformedURLException;
* @author Everel
*
*/
@SuppressWarnings("Duplicates")
@Deprecated
public class LocalServerExecuter extends ServerExecuter {
private final ServerProvider serverProvider;
private ClassPath classPath;
@@ -0,0 +1,134 @@
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;
import org.parabot.environment.api.utils.WebUtil;
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 local config file
*
* @author JKetelaar
*
*/
public class LocalPublicServerExecuter extends ServerExecuter {
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;
}
@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...");
}
}
final File clientDestination = new File(Directories.getCachePath(),
serverProviderInfo.getClientCRC32() + ".jar");
Core.verbose("Downloading: " + serverUrl + " ...");
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...");
}
}
final ClassPath classPath = new ClassPath();
classPath.addJar(destination);
BuildPath.add(destination.toURI().toURL());
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;
}
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);
}
}
}
@@ -58,7 +58,6 @@ public class PublicServerExecuter extends ServerExecuter {
+ this.serverName;
Core.verbose("Downloading: " + jarUrl + " ...");
if(destination.exists()) {
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
@@ -1,10 +1,13 @@
package org.parabot.environment.servers.executers;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.parsers.randoms.RandomParser;
import org.parabot.core.ui.components.PaintComponent;
import org.parabot.environment.servers.ServerProvider;
import java.io.PrintStream;
/**
*
* Executes a server provider
@@ -21,11 +24,7 @@ public abstract class ServerExecuter {
@Override
public void run() {
try {
try{
org.parabot.environment.api.utils.WindowsPreferences.userRoot().remove("Software\\JavaSoft\\Prefs");
}catch (Exception e){
// Ikov likes to creates preference keys, doesn't it?
}
Core.setBugsnagServer(serverName);
Context context = Context.getInstance(provider);
context.load();