Remove BDN Account Login/Features & AutoLoad "2006Scape"

This commit is contained in:
Dark98
2021-10-06 15:09:18 +01:00
parent e040259e5e
commit 160ce2e72e
18 changed files with 12 additions and 795 deletions
+3 -3
View File
@@ -6,7 +6,7 @@
<groupId>org.parabot</groupId>
<artifactId>client</artifactId>
<version>2.8.2</version>
<version>3.0.0</version>
<packaging>jar</packaging>
@@ -78,7 +78,7 @@
</dependencies>
<build>
<finalName>Parabot-V${version}${build.version}</finalName>
<finalName>Parabot-V${project.version}${build.version}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
@@ -197,7 +197,7 @@
<site>
<id>parabot-maven</id>
<name>Frontend Parabot Maven</name>
<url>ftp://maven.parabot.org/public_html/docs/${artifactId}/</url>
<url>ftp://maven.parabot.org/public_html/docs/${project.artifactId}/</url>
</site>
</distributionManagement>
+3 -2
View File
@@ -4,7 +4,6 @@ import org.parabot.api.translations.TranslationHelper;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.network.NetworkInterface;
import org.parabot.core.network.proxy.ProxySocket;
import org.parabot.core.network.proxy.ProxyType;
@@ -60,7 +59,6 @@ public final class Landing {
}
Core.verbose(TranslationHelper.translate("VALIDATION_ACCOUNT_MANAGER"));
AccountManager.validate();
if (username != null && password != null) {
new BotUI(username, password);
@@ -70,6 +68,9 @@ public final class Landing {
}
Core.verbose(TranslationHelper.translate("STARTING_LOGIN_GUI"));
Core.setDebug(true); //offline mode
Directories.clearCache(); //clear cache
ServerSelector.initServer = "2006Scape";
new BotUI(null, null);
}
@@ -8,16 +8,10 @@ import org.parabot.environment.api.utils.Version;
* @author Everel
*/
public class Configuration extends org.parabot.api.Configuration {
public static final String LOGIN_SERVER = "http://bdn.parabot.org/api/v2/users/login";
public static final String GET_SCRIPTS = "http://bdn.parabot.org/api/get.php?action=scripts_scripts&server=";
public static final String GET_SCRIPT = "http://bdn.parabot.org/api/get.php?action=scripts_script&id=";
public static final String GET_SERVER_PROVIDER_TYPE = "http://v3.bdn.parabot.org/api/bot/server/type?server=%s";
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://v3.bdn.parabot.org/api/bot/download/provider?nightly=%s&server=%s";
public static final String SERVER_PROVIDER_INFO = "http://v3.bdn.parabot.org/api/bot/list/%s?latest=true";
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://v3.bdn.parabot.org/api/bot/download/client";
public static final String DOWNLOAD_BOT = "http://bdn.parabot.org/versions/";
public static final String GET_RANDOMS = "http://v3.bdn.parabot.org/api/bot/download/randoms";
@@ -1,6 +1,5 @@
package org.parabot.core.asm.hooks;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.parsers.hooks.HookParser;
import org.parabot.core.parsers.hooks.JSONHookParser;
import org.parabot.core.parsers.hooks.XMLHookParser;
@@ -35,18 +34,6 @@ public class HookFile {
return WebUtil.getInputStream(url);
}
public InputStream getInputStream(AccountManager manager) {
if (isLocal) {
return this.getInputStream();
} else {
try {
return WebUtil.getConnection(url, "apikey=" + manager.getAccount().getApi()).getInputStream();
} catch (IOException e) {
return null;
}
}
}
public HookParser getParser() {
switch (type) {
case TYPE_XML:
@@ -1,82 +0,0 @@
package org.parabot.core.forum;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
/**
* Class which holds parabot forum account user and pass, only specific classes
* have access to it unless it's a modified version of parabot intended to
* steal user information.
*
* @author Everel
*/
public class Account {
private final String username;
private final String password;
private String api;
/**
* @param username - Forum account username
* @param password - Forum account password
*/
public Account(final String username, final String password) {
this.username = username;
this.password = password;
}
public Account(String username, String password, String api) {
this.username = username;
this.password = password;
this.api = api;
}
/**
* Gets user's parabot account name
*
* @return username.
*/
public String getUsername() {
return this.username;
}
/**
* Gets user's parabot password
*
* @return password.
*/
public String getPassword() {
return this.password;
}
/**
* Gets user's parabot account name
*
* @return username, already URL UTF-8 encoded.
*/
public String getURLUsername() {
try {
return URLEncoder.encode(this.username, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
/**
* Gets user's password
*
* @return password, already URL UTF-8 encoded.
*/
public String getURLPassword() {
try {
return URLEncoder.encode(this.password, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
public String getApi() {
return api;
}
}
@@ -1,120 +0,0 @@
package org.parabot.core.forum;
import org.json.simple.JSONObject;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.Core;
import org.parabot.core.parsers.hooks.HookParser;
import org.parabot.core.parsers.scripts.BDNScripts;
import org.parabot.core.parsers.servers.PublicServers;
import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.environment.api.utils.PBPreferences;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
import org.parabot.environment.servers.executers.PublicServerExecuter;
import java.io.BufferedReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import javax.swing.JOptionPane;
/**
* Handles logging in to parabot forum, only certain classes may use this class.
*
* @author Everel
*/
public final class AccountManager {
private static boolean validated;
private static AccountManager instance;
private Account account;
private AccountManager() {
}
public static final void validate() {
if (validated) {
return;
}
validated = true;
instance = new AccountManager();
Core.verbose("Initializing account manager accessors...");
final ArrayList<AccountManagerAccess> accessors = new ArrayList<AccountManagerAccess>();
accessors.add(BDNScripts.MANAGER_FETCHER);
accessors.add(VerboseLoader.MANAGER_FETCHER);
accessors.add(BDNScriptsExecuter.MANAGER_FETCHER);
accessors.add(PublicServers.MANAGER_FETCHER);
accessors.add(PublicServerExecuter.MANAGER_FETCHER);
accessors.add(PBPreferences.MANAGER_FETCHER);
accessors.add(HookParser.MANAGER_FETCHER);
for (final AccountManagerAccess accessor : accessors) {
accessor.setManager(instance);
}
Core.verbose("Account managers initialized.");
}
public final boolean isLoggedIn() {
return account != null;
}
public final Account getAccount() {
return account;
}
public final boolean login(final String user, final String pass, boolean requestTwoStep) {
if (account != null) {
throw new IllegalStateException("Already logged in.");
}
JSONObject result = null;
if (!requestTwoStep) {
try {
BufferedReader contents = WebUtil.getReader(WebUtil.getConnection(
new URL(Configuration.LOGIN_SERVER),
URLEncoder.encode(user, "UTF-8"),
URLEncoder.encode(pass, "UTF-8")));
result = (JSONObject) WebUtil.getJsonParser().parse(contents);
} catch (Throwable t) {
t.printStackTrace();
return false;
}
} else {
try {
String two = JOptionPane.showInputDialog("Please provide your two factor authentication code\nYou can find this in either your email or the app you've setup");
if (two != null && two.length() > 0) {
String contents = WebUtil.getContents(Configuration.LOGIN_SERVER,
"username=" + URLEncoder.encode(user, "UTF-8") + "&password=" + URLEncoder.encode(pass, "UTF-8") + "&2fa=" + URLEncoder.encode(two, "UTF-8")
);
result = (JSONObject) WebUtil.getJsonParser().parse(contents);
}
} catch (Throwable t) {
t.printStackTrace();
return false;
}
}
if (result != null) {
if (result.get("complete") != null) {
String api = (String) ((JSONObject) result.get("data")).get("api");
account = new Account(user, pass, api);
Context.setUsername(user);
return true;
} else if (result.get("error") != null) {
String errorResult = (String) result.get("error");
if (errorResult.equals("2fa") || errorResult.equals("2fae")) {
return login(user, pass, true);
}
Core.verbose(errorResult);
return false;
}
}
return false;
}
}
@@ -1,12 +0,0 @@
package org.parabot.core.forum;
/**
* Gives access to account details
*
* @author Everel
*/
public interface AccountManagerAccess {
void setManager(AccountManager manager);
}
@@ -8,8 +8,6 @@ import org.parabot.core.asm.wrappers.Interface;
import org.parabot.core.asm.wrappers.Invoker;
import org.parabot.core.asm.wrappers.Setter;
import org.parabot.core.asm.wrappers.Super;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import java.util.ArrayList;
import java.util.Collections;
@@ -24,14 +22,6 @@ import java.util.Map;
*/
public abstract class HookParser {
protected static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
HookParser.manager = manager;
}
};
public HookParser(HookFile hookFile) {
}
@@ -41,7 +41,7 @@ public class XMLHookParser extends HookParser {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(hookFile.getInputStream(manager));
doc = dBuilder.parse(hookFile.getInputStream());
doc.getDocumentElement().normalize();
if (!doc.getDocumentElement().getNodeName().equals("injector")) {
throw new RuntimeException("Incorrect hook file.");
@@ -1,70 +0,0 @@
package org.parabot.core.parsers.scripts;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.parabot.core.Configuration;
import org.parabot.core.Context;
import org.parabot.core.desc.ScriptDescription;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
import java.io.BufferedReader;
import java.net.URL;
/**
* Parses scripts stored on the BDN of Parabot
*
* @author Paradox, Everel
*/
public class BDNScripts extends ScriptParser {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
BDNScripts.manager = manager;
}
};
@Override
public void execute() {
if (!manager.isLoggedIn()) {
System.err.println("Not logged in...");
return;
}
JSONParser parser = new JSONParser();
try {
BufferedReader br = WebUtil.getReader(new URL(
Configuration.GET_SCRIPTS + Context.getInstance().getServerProviderInfo().getServerName()),
manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
String line;
while ((line = br.readLine()) != null) {
JSONObject jsonObject = (JSONObject) parser.parse(line);
int bdnId = Integer.parseInt(String.valueOf(jsonObject.get("id")));
String scriptName = String.valueOf(jsonObject.get("name"));
String author = String.valueOf(jsonObject.get("author"));
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
String category = String.valueOf(jsonObject.get("category"));
String description = String.valueOf(jsonObject.get("description"));
final ScriptDescription desc = new ScriptDescription(scriptName,
author, category, version, description,
null, bdnId);
SCRIPT_CACHE.put(desc, new BDNScriptsExecuter(bdnId));
}
br.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
@@ -23,14 +23,7 @@ public abstract class ScriptParser {
public static ScriptDescription[] getDescriptions() {
SCRIPT_CACHE.clear();
parsers.clear();
if (Core.inLoadLocal()) {
parsers.add(new LocalJavaScripts());
parsers.add(new BDNScripts());
} else if (Core.inDebugMode()) {
parsers.add(new LocalJavaScripts());
} else {
parsers.add(new BDNScripts());
}
parsers.add(new LocalJavaScripts());
Core.verbose("Parsing scripts...");
for (final ScriptParser parser : parsers) {
@@ -1,63 +0,0 @@
package org.parabot.core.parsers.servers;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.parabot.core.Configuration;
import org.parabot.core.desc.ServerDescription;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.executers.PublicServerExecuter;
import java.io.BufferedReader;
import java.net.URL;
import javax.swing.JOptionPane;
/**
* Parses servers hosted on Parabot
*
* @author Paradox, Everel
*/
public class PublicServers extends ServerParser {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
PublicServers.manager = manager;
}
};
@Override
public void execute() {
try {
BufferedReader br = WebUtil.getReader(new URL(
Configuration.GET_SERVER_PROVIDERS), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
String line;
JSONParser parser = new JSONParser();
while ((line = br.readLine()) != null) {
JSONObject jsonObject = (JSONObject) parser.parse(line);
String name = String.valueOf(jsonObject.get("name"));
String author = String.valueOf(jsonObject.get("author"));
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
ServerDescription desc = new ServerDescription(name,
author, version);
SERVER_CACHE.put(desc, new PublicServerExecuter(name));
}
br.close();
} catch (Exception e) {
UILog.log("Error", "Failed to load public servers. Either disable your anti-virus or request support on the forums.", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
}
@@ -20,14 +20,7 @@ public abstract class ServerParser {
public static final ServerDescription[] getDescriptions() {
SERVER_CACHE.clear();
final ArrayList<ServerParser> parsers = new ArrayList<>();
if (Core.inLoadLocal()) {
parsers.add(new LocalServers());
parsers.add(new PublicServers());
} else if (Core.inDebugMode()) {
parsers.add(new LocalServers());
} else {
parsers.add(new PublicServers());
}
parsers.add(new LocalServers());
Core.verbose("Parsing server providers...");
for (final ServerParser parser : parsers) {
+1 -24
View File
@@ -2,7 +2,6 @@ package org.parabot.core.ui;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.ui.images.Images;
import org.parabot.core.ui.utils.SwingUtil;
import org.parabot.core.ui.utils.UILog;
@@ -35,7 +34,6 @@ import javax.swing.JTextField;
public class LoginUI extends JFrame {
private static final long serialVersionUID = 2032832552863466297L;
private static LoginUI instance;
private static AccountManager manager;
private JTextField txtUsername;
private JPasswordField txtPassword;
@@ -149,31 +147,10 @@ public class LoginUI extends JFrame {
public void attemptLogin() {
String username = txtUsername.getText();
String password = new String(txtPassword.getPassword());
if (username.length() > 0 && password.length() > 0) {
if (manager.login(username, password, false)) {
Core.verbose("Logged in.");
instance.dispose();
Core.verbose("Running server selector.");
ServerSelector.getInstance();
} else {
Core.verbose("Failed to log in.");
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
}
}
}
private void attempt(String user, String pass) {
Core.verbose("Logging in...");
if (manager.login(user, pass, false)) {
Core.verbose("Logged in.");
instance.dispose();
Core.verbose("Running server selector.");
ServerSelector.getInstance();
} else {
Core.verbose("Failed to log in.");
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
}
}
@@ -2,8 +2,6 @@ package org.parabot.core.ui.components;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.io.ProgressListener;
import org.parabot.core.ui.ServerSelector;
import org.parabot.core.ui.fonts.Fonts;
@@ -48,15 +46,6 @@ public class VerboseLoader extends JPanel implements ProgressListener {
private static final int STATE_SERVER_SELECT = 2;
private static VerboseLoader current;
private static String state = "Initializing loader...";
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
VerboseLoader.manager = manager;
}
};
private final BufferedImage background;
private final BufferedImage banner;
private final BufferedImage loginBox;
@@ -80,11 +69,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
setDoubleBuffered(true);
setOpaque(false);
if (username != null && password != null) {
if (Core.inDebugMode() || manager.login(username, password, false)) {
currentState = STATE_SERVER_SELECT;
}
}
currentState = STATE_SERVER_SELECT; //Force Server Select
if (currentState == STATE_AUTHENTICATION) {
addLoginPanel();
@@ -186,19 +171,6 @@ public class VerboseLoader extends JPanel implements ProgressListener {
login.setAlignmentX(Box.CENTER_ALIGNMENT);
login.setOpaque(false);
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (manager.login(userInput.getText(), passInput.getText(), false)) {
switchState(STATE_SERVER_SELECT);
} else {
Core.verbose("Failed to log in.");
UILog.log("Error", "Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", JOptionPane.ERROR_MESSAGE);
}
}
});
loginPanel.add(Box.createRigidArea(new Dimension(0, 8)));
loginPanel.add(usernameLabel);
loginPanel.add(Box.createRigidArea(new Dimension(0, 4)));
@@ -3,8 +3,6 @@ package org.parabot.environment.api.utils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
@@ -18,120 +16,11 @@ import java.util.Properties;
*/
public class PBPreferences {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
PBPreferences.manager = manager;
}
};
private final int scriptID;
private Properties properties;
public PBPreferences(int scriptID) {
this.scriptID = scriptID;
this.updateSettings();
}
/**
* Change a setting
*
* @param key
* @param value
*/
public void adjustSettings(Object key, Object value) {
this.addSetting(key, value);
}
/**
* Get a setting value
*
* @param key
*
* @return
*/
public Object getSetting(Object key) {
return this.properties.get(key);
}
/**
* Get a setting value as string
*
* @param key
*
* @return
*/
public String getSetting(String key) {
return this.properties.getProperty(key);
}
/**
* Remove a setting
*
* @param key
*/
public void removeSetting(Object key) {
try {
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/",
"apikey=" + manager.getAccount().getApi() +
"&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") +
"&script=" + scriptID
)
);
if ((boolean) result.get("result")) {
this.properties.remove(key);
}
} catch (ParseException | MalformedURLException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
/**
* Add a setting
*
* @param key
* @param value
*/
public void addSetting(Object key, Object value) {
try {
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/set/",
"apikey=" + manager.getAccount().getApi() +
"&key=" + URLEncoder.encode(String.valueOf(key), "UTF-8") +
"&value=" + URLEncoder.encode(String.valueOf(value), "UTF-8") +
"&script=" + scriptID
)
);
if ((boolean) result.get("result")) {
this.properties.put(key, value);
}
} catch (ParseException | MalformedURLException | UnsupportedEncodingException e) {
e.printStackTrace();
}
}
private void updateSettings() {
properties = new Properties();
try {
JSONObject result = (JSONObject) WebUtil.getJsonParser().parse(
WebUtil.getContents("http://bdn.parabot.org/api/v2/user/preferences/" + scriptID,
"apikey=" + manager.getAccount().getApi())
);
JSONArray resultArray;
if ((resultArray = ((JSONArray) result.get("result"))) != null) {
for (Object rObject : resultArray) {
JSONObject resultObject = (JSONObject) rObject;
for (Object map : resultObject.entrySet()) {
Map.Entry<?, ?> pairs = (Map.Entry<?, ?>) map;
properties.put(pairs.getKey(), pairs.getValue());
}
}
}
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
}
@@ -1,95 +0,0 @@
package org.parabot.environment.scripts.executers;
import org.parabot.core.Configuration;
import org.parabot.core.classpath.ClassPath;
import org.parabot.core.forum.AccountManager;
import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.loader.JavaScriptLoader;
import java.lang.reflect.Constructor;
import java.net.URL;
import java.net.URLConnection;
import javax.swing.JOptionPane;
/**
* Loads a script from the BDN
*
* @author Everel
*/
public class BDNScriptsExecuter extends ScriptExecuter {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
BDNScriptsExecuter.manager = manager;
}
};
private int id = -1;
public BDNScriptsExecuter(final int id) {
this.id = id;
}
@Override
public void run(ThreadGroup tg) {
try {
final URLConnection urlConnection = WebUtil.getConnection(new URL(
Configuration.GET_SCRIPT + this.id), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
final String contentType = urlConnection.getHeaderField("Content-type");
switch (contentType) {
case "text/html":
// failed to fetch script
UILog.log("Error", "Failed to load BDN script, error: [Page returned: " + WebUtil.getContents(urlConnection) + "]", JOptionPane.ERROR_MESSAGE);
break;
case "application/jar":
//// JAR LOADING PART ////////
// succesfull request, jar returned
final ClassPath classPath = new ClassPath();
classPath.addJar(urlConnection);
final JavaScriptLoader loader = new JavaScriptLoader(classPath);
final String[] scriptClasses = loader.getScriptClassNames();
if (scriptClasses == null || scriptClasses.length == 0) {
UILog.log("Error", "Failed to load BDN script, error: [No script found in jar file.]", JOptionPane.ERROR_MESSAGE);
return;
} else if (scriptClasses.length > 1) {
UILog.log("Error", "Failed to load BDN script, error: [Multiple scripts found in jar file.]");
return;
}
final String className = scriptClasses[0];
try {
final Class<?> scriptClass = loader.loadClass(className);
final Constructor<?> con = scriptClass.getConstructor();
final Script script = (Script) con.newInstance();
script.setScriptID(this.id);
super.finalize(tg, script);
} catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log("Error", "Failed to load BDN script, error: [This server provider does not support this script]", JOptionPane.ERROR_MESSAGE);
} catch (Throwable t) {
t.printStackTrace();
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
}
//// END JAR LOADING ////
break;
default:
UILog.log("Error", "Failed to load BDN script, error: [Unknown content type: " + contentType + "]", JOptionPane.ERROR_MESSAGE);
break;
}
} catch (Throwable t) {
t.printStackTrace();
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
}
}
}
@@ -1,137 +0,0 @@
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.PBLocalPreferences;
import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.servers.ServerProvider;
import org.parabot.environment.servers.loader.ServerLoader;
import java.io.File;
import java.lang.reflect.Constructor;
import java.net.URL;
import javax.swing.JOptionPane;
/**
* Fetches a server provider from the Parabot BDN
*
* @author Everel
*/
public class PublicServerExecuter extends ServerExecuter {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
PublicServerExecuter.manager = manager;
}
};
private final String cacheVersionKey = "cachedProviderVersion";
private final String serverName;
private PBLocalPreferences settings;
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());
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 + " ...");
String providerVersion = serverProviderInfo.getProviderVersion();
if (providerVersion == null) {
providerVersion = "error";
}
settings = new PBLocalPreferences(serverProviderInfo.getClientCRC32() + ".json");
if (settings.getSetting(cacheVersionKey) != null) {
Core.verbose(String.format("Latest provider version: %s, local provider version: %s", settings.getSetting(cacheVersionKey), providerVersion));
if (!settings.getSetting(cacheVersionKey).equals(providerVersion)) {
Core.verbose("Local provider outdated, clearing cache.");
Directories.clearCache();
}
} else {
Core.verbose("No local provider version in settings, adding to settings file");
}
settings.addSetting(cacheVersionKey, providerVersion);
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);
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;
}
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);
}
}
}