mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 00:38:16 +00:00
Caching server providers now
This commit is contained in:
@@ -14,6 +14,6 @@ public class Configuration {
|
|||||||
public static final String GET_SERVER_PROVIDER_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
public static final String GET_SERVER_PROVIDER_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
||||||
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
||||||
|
|
||||||
public static final double BOT_VERSION = 2.05; // BETA
|
public static final double BOT_VERSION = 2.06;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.parabot.core;
|
|||||||
|
|
||||||
import org.parabot.core.asm.ASMClassLoader;
|
import org.parabot.core.asm.ASMClassLoader;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
|
import org.parabot.core.desc.ServerProviderInfo;
|
||||||
import org.parabot.core.paint.PaintDebugger;
|
import org.parabot.core.paint.PaintDebugger;
|
||||||
import org.parabot.core.parsers.hooks.HookParser;
|
import org.parabot.core.parsers.hooks.HookParser;
|
||||||
import org.parabot.core.ui.BotDialog;
|
import org.parabot.core.ui.BotDialog;
|
||||||
@@ -42,6 +43,7 @@ public class Context {
|
|||||||
private PaintDebugger paintDebugger;
|
private PaintDebugger paintDebugger;
|
||||||
private Mouse mouse;
|
private Mouse mouse;
|
||||||
private Keyboard keyboard;
|
private Keyboard keyboard;
|
||||||
|
private ServerProviderInfo providerInfo;
|
||||||
|
|
||||||
private Context(final ServerProvider serverProvider) {
|
private Context(final ServerProvider serverProvider) {
|
||||||
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
||||||
@@ -192,6 +194,25 @@ public class Context {
|
|||||||
public ServerProvider getServerProvider() {
|
public ServerProvider getServerProvider() {
|
||||||
return serverProvider;
|
return serverProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Sets provider info of this context
|
||||||
|
*
|
||||||
|
* @param providerInfo
|
||||||
|
*/
|
||||||
|
public void setProviderInfo(ServerProviderInfo providerInfo) {
|
||||||
|
this.providerInfo = providerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets ServerProvider info
|
||||||
|
* Can be null if this is not a public server provider
|
||||||
|
* @return info about this provider
|
||||||
|
*/
|
||||||
|
public ServerProviderInfo getServerProviderInfo() {
|
||||||
|
return this.providerInfo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets class loader of server from this context
|
* Gets class loader of server from this context
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import org.parabot.core.ui.components.VerboseLoader;
|
|||||||
* @author Everel
|
* @author Everel
|
||||||
* @author Matt
|
* @author Matt
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class ClassPath {
|
public class ClassPath {
|
||||||
public final HashMap<String, ClassNode> classes;
|
public final HashMap<String, ClassNode> classes;
|
||||||
public final Map<String, URL> resources;
|
public final Map<String, URL> resources;
|
||||||
@@ -194,10 +195,10 @@ public class ClassPath {
|
|||||||
ClassReader cr = new ClassReader(in);
|
ClassReader cr = new ClassReader(in);
|
||||||
ClassNode cn = new ClassNode();
|
ClassNode cn = new ClassNode();
|
||||||
cr.accept(cn, 0);
|
cr.accept(cn, 0);
|
||||||
RemappingClassAdapter rca = new RemappingClassAdapter(cn,classRemapper);
|
/*RemappingClassAdapter rca = new RemappingClassAdapter(cn,classRemapper);
|
||||||
ClassNode remapped = new ClassNode();
|
ClassNode remapped = new ClassNode();
|
||||||
cn.accept(rca);
|
cn.accept(rca);*/
|
||||||
classes.put(cn.name, remapped);
|
classes.put(cn.name, cn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package org.parabot.core.desc;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Everel
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ServerProviderInfo {
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
|
public ServerProviderInfo(URL providerInfo) {
|
||||||
|
this.properties = new Properties();
|
||||||
|
try {
|
||||||
|
String line;
|
||||||
|
BufferedReader br = WebUtil.getReader(providerInfo);
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
if(line.contains(": ")) {
|
||||||
|
properties.put(line.substring(0, line.indexOf(": ")), line.substring(line.indexOf(": ") + 2, line.length()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
br.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getClient() {
|
||||||
|
try {
|
||||||
|
return new URL(properties.getProperty("client"));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public URL getHookFile() {
|
||||||
|
try {
|
||||||
|
return new URL(properties.getProperty("hooks"));
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientClass() {
|
||||||
|
return properties.getProperty("clientClass");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerName() {
|
||||||
|
return properties.getProperty("serverName");
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCRC32() {
|
||||||
|
return Long.parseLong(properties.getProperty("crc32"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBankTabs() {
|
||||||
|
return Integer.parseInt(properties.getProperty("bankTabs"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
package org.parabot.environment.servers;
|
package org.parabot.environment.servers;
|
||||||
|
|
||||||
import org.parabot.core.Configuration;
|
import org.parabot.core.Configuration;
|
||||||
|
import org.parabot.core.Context;
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.build.BuildPath;
|
import org.parabot.core.build.BuildPath;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
|
import org.parabot.core.desc.ServerProviderInfo;
|
||||||
import org.parabot.core.ui.components.VerboseLoader;
|
import org.parabot.core.ui.components.VerboseLoader;
|
||||||
import org.parabot.core.ui.utils.UILog;
|
import org.parabot.core.ui.utils.UILog;
|
||||||
import org.parabot.environment.api.utils.WebUtil;
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
import org.parabot.environment.servers.loader.ServerLoader;
|
import org.parabot.environment.servers.loader.ServerLoader;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@@ -34,31 +37,38 @@ public class PublicServerExecuter extends ServerExecuter {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(this.serverID);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
UILog.log(
|
||||||
|
"Error",
|
||||||
|
"Failed to parse the server ID for the server provider, error: [Server ID is not an integer.]",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
|
||||||
|
+ this.serverID));
|
||||||
|
|
||||||
final File destination = new File(Directories.getCachePath(),
|
final File destination = new File(Directories.getCachePath(),
|
||||||
this.serverID);
|
serverProviderInfo.getCRC32() + ".jar");
|
||||||
final String jarUrl = Configuration.GET_SERVER_PROVIDER + this.serverID;
|
|
||||||
final String providerInfo = Configuration.GET_SERVER_PROVIDER_INFO + this.serverID;
|
|
||||||
|
final String jarUrl = Configuration.GET_SERVER_PROVIDER
|
||||||
try{
|
+ this.serverID;
|
||||||
Integer.parseInt(this.serverID);
|
|
||||||
}catch(NumberFormatException e){
|
|
||||||
UILog.log(
|
|
||||||
"Error",
|
|
||||||
"Failed to parse the server ID for the server provider, error: [Server ID is not an integer.]",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||||
|
|
||||||
WebUtil.downloadFile(new URL(jarUrl), destination,
|
|
||||||
VerboseLoader.get());
|
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...");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
WebUtil.downloadFile(new URL(providerInfo),
|
|
||||||
new File(System.getProperty("user.home") + "/serverProvider.pb"),
|
|
||||||
VerboseLoader.get());
|
|
||||||
|
|
||||||
Core.verbose("Server provider downloaded...");
|
|
||||||
|
|
||||||
final ClassPath classPath = new ClassPath();
|
final ClassPath classPath = new ClassPath();
|
||||||
classPath.addJar(destination);
|
classPath.addJar(destination);
|
||||||
|
|
||||||
@@ -86,6 +96,7 @@ public class PublicServerExecuter extends ServerExecuter {
|
|||||||
final Constructor<?> con = providerClass.getConstructor();
|
final Constructor<?> con = providerClass.getConstructor();
|
||||||
final ServerProvider serverProvider = (ServerProvider) con
|
final ServerProvider serverProvider = (ServerProvider) con
|
||||||
.newInstance();
|
.newInstance();
|
||||||
|
Context.getInstance().setProviderInfo(serverProviderInfo);
|
||||||
super.finalize(serverProvider, this.serverName);
|
super.finalize(serverProvider, this.serverName);
|
||||||
} catch (NoClassDefFoundError ignored) {
|
} catch (NoClassDefFoundError ignored) {
|
||||||
UILog.log(
|
UILog.log(
|
||||||
|
|||||||
Reference in New Issue
Block a user