mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Merge pull request #254 from Shadowrs/feature/override-randoms
Feature/override randoms
This commit is contained in:
@@ -50,7 +50,28 @@ public class ServerProviderInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN.
|
||||||
|
* @param clientJar Name of the client jar file
|
||||||
|
* @param hooks Name of the hooks file
|
||||||
|
* @param name Server name
|
||||||
|
* @param clientClass Entry class within the client jar
|
||||||
|
* @param bankTabs Bank tabs - only relevant for certain servers. Default 0
|
||||||
|
*/
|
||||||
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs) {
|
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs) {
|
||||||
|
this(clientJar, hooks, name, clientClass, bankTabs, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize configuration with data provided by {@link org.parabot.core.parsers.servers.LocalServers} from a {@code /parabot/servers/config.json} file. Also loads the default Settings map from the BDN.
|
||||||
|
* @param clientJar Name of the client jar file
|
||||||
|
* @param hooks Name of the hooks file
|
||||||
|
* @param name Server name
|
||||||
|
* @param clientClass Entry class within the client jar
|
||||||
|
* @param bankTabs Bank tabs - only relevant for certain servers. Default 0
|
||||||
|
* @param randoms A URL to an endpoint where the Randoms are located. Can be Null, in which case getRandoms() will fallback to the default BDN Randoms URL.
|
||||||
|
*/
|
||||||
|
public ServerProviderInfo(String clientJar, String hooks, String name, String clientClass, int bankTabs, String randoms) {
|
||||||
this.properties = new Properties();
|
this.properties = new Properties();
|
||||||
this.settings = new HashMap<>();
|
this.settings = new HashMap<>();
|
||||||
|
|
||||||
@@ -69,6 +90,7 @@ public class ServerProviderInfo {
|
|||||||
this.properties.setProperty("provider_crc32", String.valueOf(getCRC32(name, "provider")));
|
this.properties.setProperty("provider_crc32", String.valueOf(getCRC32(name, "provider")));
|
||||||
this.properties.setProperty("client_crc32", String.valueOf(getCRC32(name, "client")));
|
this.properties.setProperty("client_crc32", String.valueOf(getCRC32(name, "client")));
|
||||||
this.properties.setProperty("bank_tabs", String.valueOf(bankTabs));
|
this.properties.setProperty("bank_tabs", String.valueOf(bankTabs));
|
||||||
|
this.properties.setProperty("randoms_jar", randoms);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getCRC32(String name, String type) {
|
private long getCRC32(String name, String type) {
|
||||||
@@ -141,4 +163,23 @@ public class ServerProviderInfo {
|
|||||||
public HashMap<String, Integer> getSettings() {
|
public HashMap<String, Integer> getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the URL to download the Randoms JAR from.
|
||||||
|
* @return The provided URL in the server config JSON (denoted by 'randoms:') or, fallback to the default BDN URL.
|
||||||
|
*/
|
||||||
|
public URL getRandoms() {
|
||||||
|
try {
|
||||||
|
String randomsUrl = properties.getProperty("randoms_jar");
|
||||||
|
if (randomsUrl == null || randomsUrl.length() == 0) {
|
||||||
|
// Fallback to default BDN URL if there is no 'randoms' specified in the server JSON configuration.
|
||||||
|
randomsUrl = Configuration.GET_RANDOMS + (Configuration.BOT_VERSION.isNightly() ? Configuration.NIGHTLY_APPEND : "");
|
||||||
|
}
|
||||||
|
return new URL(randomsUrl);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
// Will never return null, unless the BDN URL is changed. It shouldn't be.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
package org.parabot.core.parsers.randoms;
|
package org.parabot.core.parsers.randoms;
|
||||||
|
|
||||||
import org.parabot.api.io.WebUtil;
|
|
||||||
import org.parabot.core.Configuration;
|
|
||||||
import org.parabot.core.Context;
|
|
||||||
import org.parabot.core.Core;
|
|
||||||
import org.parabot.core.Directories;
|
|
||||||
import org.parabot.core.io.NoProgressListener;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import org.parabot.api.io.WebUtil;
|
||||||
|
import org.parabot.api.output.Logger;
|
||||||
|
import org.parabot.core.Configuration;
|
||||||
|
import org.parabot.core.Context;
|
||||||
|
import org.parabot.core.Core;
|
||||||
|
import org.parabot.core.Directories;
|
||||||
|
import org.parabot.core.io.NoProgressListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author JKetelaar
|
* @author JKetelaar
|
||||||
@@ -23,12 +23,21 @@ public class PublicRandoms extends RandomParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void parse() {
|
public void parse() {
|
||||||
File myJar = new File(Directories.getCachePath() + File.separator + fileName);
|
|
||||||
if (!myJar.exists() || !myJar.canRead()) {
|
final File destination = new File(Directories.getCachePath() + File.separator + fileName);
|
||||||
download();
|
final URL overrideDownload = Context.getInstance().getServerProviderInfo().getRandoms();
|
||||||
|
if (overrideDownload == null) {
|
||||||
|
throw new NullPointerException("Unable to grab URL for Randoms jar. Default URL for BDN randoms must have changed!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Core.verbose(String.format("[%s] Destination: %s | dl: %s", getClass().getSimpleName(), destination, overrideDownload));
|
||||||
|
|
||||||
|
if (!destination.exists() || !destination.canRead()) {
|
||||||
|
Core.verbose(String.format("[%s] Missing %s - downloading from %s...", getClass().getSimpleName(), destination.getAbsolutePath(), overrideDownload));
|
||||||
|
download(destination, overrideDownload);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
URL url = myJar.toURI().toURL();
|
URL url = destination.toURI().toURL();
|
||||||
URL[] urls = new URL[]{ url };
|
URL[] urls = new URL[]{ url };
|
||||||
String server = Context.getInstance().getServerProviderInfo().getServerName();
|
String server = Context.getInstance().getServerProviderInfo().getServerName();
|
||||||
|
|
||||||
@@ -36,7 +45,7 @@ public class PublicRandoms extends RandomParser {
|
|||||||
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
|
Class<?> classToLoad = Class.forName("org.parabot.randoms.Core", true, child);
|
||||||
Method method = classToLoad.getDeclaredMethod("init", String.class);
|
Method method = classToLoad.getDeclaredMethod("init", String.class);
|
||||||
Object instance = classToLoad.newInstance();
|
Object instance = classToLoad.newInstance();
|
||||||
System.out.println(server);
|
Core.verbose(String.format("[%s] %s %s", getClass().getSimpleName(), "Initing core Randoms for", server));
|
||||||
method.invoke(instance, server);
|
method.invoke(instance, server);
|
||||||
Core.verbose("Successfully parsed public random!");
|
Core.verbose("Successfully parsed public random!");
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
|
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException | ClassNotFoundException | MalformedURLException e) {
|
||||||
@@ -45,17 +54,14 @@ public class PublicRandoms extends RandomParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void download() {
|
private void download(final File destination, URL downloadLink) {
|
||||||
try {
|
try {
|
||||||
File random = new File(Directories.getCachePath() + File.separator + fileName);
|
if (destination.exists()) {
|
||||||
if (random.exists()) {
|
|
||||||
Core.verbose("Public random dependency already exists, no need to download it...");
|
Core.verbose("Public random dependency already exists, no need to download it...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String downloadLink = ((Configuration.BOT_VERSION.isNightly()) ? Configuration.GET_RANDOMS + Configuration.NIGHTLY_APPEND : Configuration.GET_RANDOMS);
|
WebUtil.downloadFile(downloadLink, destination, new NoProgressListener());
|
||||||
|
|
||||||
WebUtil.downloadFile(new URL(downloadLink), random, new NoProgressListener());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
package org.parabot.core.parsers.servers;
|
package org.parabot.core.parsers.servers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.util.ArrayList;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
import org.parabot.core.Configuration;
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
@@ -13,12 +19,6 @@ import org.parabot.environment.servers.executers.LocalPublicServerExecuter;
|
|||||||
import org.parabot.environment.servers.executers.LocalServerExecuter;
|
import org.parabot.environment.servers.executers.LocalServerExecuter;
|
||||||
import org.parabot.environment.servers.loader.ServerLoader;
|
import org.parabot.environment.servers.loader.ServerLoader;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses local server providers located in the servers directory
|
* Parses local server providers located in the servers directory
|
||||||
*
|
*
|
||||||
@@ -93,11 +93,15 @@ public class LocalServers extends ServerParser {
|
|||||||
String server = (String) locations.get("server");
|
String server = (String) locations.get("server");
|
||||||
String provider = (String) locations.get("provider");
|
String provider = (String) locations.get("provider");
|
||||||
String hooks = (String) locations.get("hooks");
|
String hooks = (String) locations.get("hooks");
|
||||||
|
String randoms = (String) locations.get("randoms");
|
||||||
|
|
||||||
Core.verbose("[Local server]: " + name);
|
if (randoms == null) {
|
||||||
|
randoms = Configuration.GET_RANDOMS + (Configuration.BOT_VERSION.isNightly() ? Configuration.NIGHTLY_APPEND : "");
|
||||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs);
|
}
|
||||||
|
|
||||||
|
Core.verbose("[LocalServers]: Parsed server: " + name);
|
||||||
|
|
||||||
|
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(server, hooks, name, clientClass, bankTabs, randoms);
|
||||||
|
|
||||||
ServerDescription desc = new ServerDescription(name, author, version);
|
ServerDescription desc = new ServerDescription(name, author, version);
|
||||||
if (uuidStr != null && uuidStr.length() > 0) {
|
if (uuidStr != null && uuidStr.length() > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user