mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
[TASK] Improved the Server loader
This commit is contained in:
@@ -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_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 = "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_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 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 API_DOWNLOAD_BOT = "http://bdn.parabot.org/api/v2/bot/download/client/";
|
||||||
public static final String DOWNLOAD_BOT = "http://bdn.parabot.org/versions/";
|
public static final String DOWNLOAD_BOT = "http://bdn.parabot.org/versions/";
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ public class Directories {
|
|||||||
* @param extension The extension to be searched for, including the dot (like .json)
|
* @param extension The extension to be searched for, including the dot (like .json)
|
||||||
* @return An array of of files that match the request
|
* @return An array of of files that match the request
|
||||||
*/
|
*/
|
||||||
private File[] listFilesWithExtension(File directory, final String extension){
|
public static File[] listFilesWithExtension(File directory, final String extension){
|
||||||
return directory.listFiles(new FilenameFilter() {
|
return directory.listFiles(new FilenameFilter() {
|
||||||
public boolean accept(File dir, String filename) {
|
public boolean accept(File dir, String filename) {
|
||||||
return filename.endsWith(extension);
|
return filename.endsWith(extension);
|
||||||
@@ -320,7 +320,7 @@ public class Directories {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private File[] listJSONFiles(File directory) {
|
public static File[] listJSONFiles(File directory) {
|
||||||
return listFilesWithExtension(directory, ".json");
|
return listFilesWithExtension(directory, ".json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package org.parabot.core.desc;
|
|||||||
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
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.Core;
|
||||||
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 javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -29,40 +32,44 @@ public class ServerProviderInfo {
|
|||||||
this.properties = new Properties();
|
this.properties = new Properties();
|
||||||
this.settings = new HashMap<>();
|
this.settings = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
String line;
|
|
||||||
Core.verbose("Reading info: " + providerInfo);
|
Core.verbose("Reading info: " + providerInfo);
|
||||||
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString()), username, password);
|
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString()), username, password);
|
||||||
|
|
||||||
//TODO Make this one line (web sided)
|
JSONObject jsonObject = (JSONObject) WebUtil.getJsonParser().parse(br);
|
||||||
JSONParser parser = new JSONParser();
|
for (Object o : jsonObject.entrySet()) {
|
||||||
if ((line = br.readLine()) != null) {
|
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
|
||||||
JSONObject jsonObject = (JSONObject) parser.parse(line);
|
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
|
||||||
for (Object o : jsonObject.entrySet()) {
|
JSONObject object = (JSONObject) pairs.getValue();
|
||||||
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) o;
|
parseSettings(object);
|
||||||
if (String.valueOf(pairs.getKey()).equalsIgnoreCase("settings")){
|
}else {
|
||||||
JSONObject object = (JSONObject) pairs.getValue();
|
properties.put(String.valueOf(pairs.getKey()), String.valueOf(pairs.getValue()));
|
||||||
for (Object settingObject : object.entrySet()){
|
}
|
||||||
Map.Entry<?, ?> settingValue = (Map.Entry<?, ?>) settingObject;
|
}
|
||||||
String key = (String) settingValue.getKey();
|
if (br != null) {
|
||||||
long value = (Long) settingValue.getValue();
|
br.close();
|
||||||
settings.put(key, (int) value);
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
}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) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerProviderInfo(){
|
||||||
|
try {
|
||||||
|
BufferedReader br = WebUtil.getReader(new URL(Configuration.GET_SERVER_SETTINGS));
|
||||||
|
JSONObject settings = (JSONObject) WebUtil.getJsonParser().parse(br);
|
||||||
|
} catch (ParseException | IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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() {
|
public URL getClient() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
package org.parabot.core.parsers.servers;
|
package org.parabot.core.parsers.servers;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
import org.parabot.core.Directories;
|
import org.parabot.core.Directories;
|
||||||
import org.parabot.core.classpath.ClassPath;
|
import org.parabot.core.classpath.ClassPath;
|
||||||
import org.parabot.core.desc.ServerDescription;
|
import org.parabot.core.desc.ServerDescription;
|
||||||
|
import org.parabot.environment.api.utils.WebUtil;
|
||||||
import org.parabot.environment.servers.ServerManifest;
|
import org.parabot.environment.servers.ServerManifest;
|
||||||
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;
|
||||||
@@ -66,7 +71,20 @@ 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 clientClass = (String) object.get("client-class");
|
||||||
|
|
||||||
|
JSONObject locations = (JSONObject) object.get("locations");
|
||||||
|
String server = (String) locations.get("server");
|
||||||
|
String hooks = (String) locations.get("hooks");
|
||||||
|
|
||||||
|
} catch (IOException | ParseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,10 +56,8 @@ public class PublicServerExecuter extends ServerExecuter {
|
|||||||
serverProviderInfo.getCRC32() + ".jar");
|
serverProviderInfo.getCRC32() + ".jar");
|
||||||
final String jarUrl = Configuration.GET_SERVER_PROVIDER
|
final String jarUrl = Configuration.GET_SERVER_PROVIDER
|
||||||
+ this.serverName;
|
+ this.serverName;
|
||||||
System.out.println(jarUrl);
|
|
||||||
|
|
||||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||||
|
|
||||||
|
|
||||||
if(destination.exists()) {
|
if(destination.exists()) {
|
||||||
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
Core.verbose("Found cached server provider [CRC32: " + serverProviderInfo.getCRC32() + "]");
|
||||||
|
|||||||
Reference in New Issue
Block a user