Source fully compatible with the BDN

This commit is contained in:
JKetelaar
2015-01-09 12:02:58 +01:00
parent 3f6cac6060
commit b0dc598e6b
6 changed files with 38 additions and 40 deletions
@@ -15,7 +15,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
public String[] servers;
public String isVip;
public String isPremium;
public int sdnId;
public int bdnId;
/**
* The ScriptManifest
@@ -35,7 +35,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
}
/**
* Used for SDN script (see SDNScripts parser)
* Used for BDN script (see BDNScripts parser)
*
* @param scriptName
* @param author
@@ -43,17 +43,17 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
* @param version
* @param description
* @param servers
* @param sdnId
* @param bdnId
*/
public ScriptDescription(final String scriptName,
final String author, final String category, final double version,
final String description, final String[] servers, final int sdnId) {
final String description, final String[] servers, final int bdnId) {
this(scriptName, author, category, version, description, servers, null,
null, sdnId);
null, bdnId);
}
/**
* Used by bot (java scripts and python scripts) and SDN Manager (sdn
* Used by bot (java scripts and python scripts) and BDN Manager (bdn
* manager is a private program)
*
* @param scriptName
@@ -84,12 +84,12 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
* @param servers
* @param vip
* @param premium
* @param sdnId
* @param bdnId
*/
public ScriptDescription(final String scriptName, final String author,
final String category, final double version,
final String description, final String[] servers, final String vip,
final String premium, final int sdnId) {
final String premium, final int bdnId) {
this.scriptName = scriptName;
this.author = author;
this.category = category;
@@ -98,7 +98,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
this.servers = servers;
this.isVip = vip;
this.isPremium = premium;
this.sdnId = sdnId;
this.bdnId = bdnId;
}
@Override
@@ -121,9 +121,9 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
.append(this.isVip == null ? "unknown" : this.isVip)
.append(", premium: ")
.append(this.isPremium == null ? "unknown" : this.isPremium)
.append(", sdn id: ")
.append(this.sdnId == -1 ? "unknown" : Integer
.toString(this.sdnId))
.append(", bdn id: ")
.append(this.bdnId == -1 ? "unknown" : Integer
.toString(this.bdnId))
.append("]");
return b.toString();
@@ -2,11 +2,11 @@ package org.parabot.core.forum;
import org.parabot.core.Configuration;
import org.parabot.core.Core;
import org.parabot.core.parsers.scripts.SDNScripts;
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.WebUtil;
import org.parabot.environment.scripts.executers.SDNScriptExecuter;
import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
import org.parabot.environment.servers.executers.PublicServerExecuter;
import java.net.URLEncoder;
@@ -37,9 +37,9 @@ public final class AccountManager {
Core.verbose("Initializing account manager accessors...");
final ArrayList<AccountManagerAccess> accessors = new ArrayList<AccountManagerAccess>();
accessors.add(SDNScripts.MANAGER_FETCHER);
accessors.add(BDNScripts.MANAGER_FETCHER);
accessors.add(VerboseLoader.MANAGER_FETCHER);
accessors.add(SDNScriptExecuter.MANAGER_FETCHER);
accessors.add(BDNScriptsExecuter.MANAGER_FETCHER);
accessors.add(PublicServers.MANAGER_FETCHER);
accessors.add(PublicServerExecuter.MANAGER_FETCHER);
@@ -8,24 +8,24 @@ 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.SDNScriptExecuter;
import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
import java.io.BufferedReader;
import java.net.URL;
/**
* Parses scripts stored on the SDN of Parabot
* Parses scripts stored on the BDN of Parabot
*
* @author Paradox, Everel
*/
public class SDNScripts extends ScriptParser {
public class BDNScripts extends ScriptParser {
private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override
public final void setManager(AccountManager manager) {
SDNScripts.manager = manager;
BDNScripts.manager = manager;
}
};
@@ -47,7 +47,7 @@ public class SDNScripts extends ScriptParser {
while ((line = br.readLine()) != null) {
JSONObject jsonObject = (JSONObject) parser.parse(line);
int sdnId = Integer.parseInt(String.valueOf(jsonObject.get("id")));
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")));
@@ -56,8 +56,8 @@ public class SDNScripts extends ScriptParser {
final ScriptDescription desc = new ScriptDescription(scriptName,
author, category, version, description,
null, sdnId);
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
null, bdnId);
SCRIPT_CACHE.put(desc, new BDNScriptsExecuter(bdnId));
}
@@ -25,11 +25,11 @@ public abstract class ScriptParser {
final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>();
if (Core.inLoadLocal()) {
parsers.add(new LocalJavaScripts());
parsers.add(new SDNScripts());
parsers.add(new BDNScripts());
} else if (Core.inDebugMode()) {
parsers.add(new LocalJavaScripts());
} else {
parsers.add(new SDNScripts());
parsers.add(new BDNScripts());
}
Core.verbose("Parsing scripts...");
@@ -16,12 +16,12 @@ import java.net.URLConnection;
/**
*
* Loads a script from the SDN
* Loads a script from the BDN
*
* @author Everel
*
*/
public class SDNScriptExecuter extends ScriptExecuter {
public class BDNScriptsExecuter extends ScriptExecuter {
private static AccountManager manager;
@@ -29,14 +29,14 @@ public class SDNScriptExecuter extends ScriptExecuter {
@Override
public final void setManager(AccountManager manager) {
SDNScriptExecuter.manager = manager;
BDNScriptsExecuter.manager = manager;
}
};
private int id = -1;
public SDNScriptExecuter(final int id) {
public BDNScriptsExecuter(final int id) {
this.id = id;
}
@@ -49,7 +49,7 @@ public class SDNScriptExecuter extends ScriptExecuter {
final String contentType = urlConnection.getHeaderField("Content-type");
if(contentType.equals("text/html")) {
// failed to fetch script
UILog.log("Error", new StringBuilder("Failed to load SDN script, error: [Page returned: ").append(WebUtil.getContents(urlConnection)).append("]").toString(), JOptionPane.ERROR_MESSAGE);
UILog.log("Error", "Failed to load BDN script, error: [Page returned: " + WebUtil.getContents(urlConnection) + "]", JOptionPane.ERROR_MESSAGE);
} else if(contentType.equals("application/jar")) {
//// JAR LOADING PART ////////
@@ -62,10 +62,10 @@ public class SDNScriptExecuter extends ScriptExecuter {
final JavaScriptLoader loader = new JavaScriptLoader(classPath);
final String[] scriptClasses = loader.getScriptClassNames();
if(scriptClasses == null || scriptClasses.length == 0) {
UILog.log("Error", "Failed to load SDN script, error: [No script found in jar file.]", JOptionPane.ERROR_MESSAGE);
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 SDN script, error: [Multiple scripts found in jar file.]");
UILog.log("Error", "Failed to load BDN script, error: [Multiple scripts found in jar file.]");
return;
}
@@ -75,24 +75,22 @@ public class SDNScriptExecuter extends ScriptExecuter {
final Constructor<?> con = scriptClass.getConstructor();
final Script script = (Script) con.newInstance();
super.finalize(tg, script);
} catch (NoClassDefFoundError ignored) {
UILog.log("Error", "Failed to load SDN script, error: [This server provider does not support this script]", JOptionPane.ERROR_MESSAGE);
} catch(ClassNotFoundException ignored) {
UILog.log("Error", "Failed to load SDN script, error: [This server provider does not support this script]", JOptionPane.ERROR_MESSAGE);
} 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 SDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
}
//// END JAR LOADING ////
} else {
UILog.log("Error", new StringBuilder("Failed to load SDN script, error: [Unknown content type: ").append(contentType).append("]").toString(), JOptionPane.ERROR_MESSAGE);
UILog.log("Error", "Failed to load BDN script, error: [Unknown content type: " + contentType + "]", JOptionPane.ERROR_MESSAGE);
}
} catch (Throwable t) {
t.printStackTrace();
UILog.log("Error", "Failed to load SDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
}
}
@@ -23,7 +23,7 @@ import java.net.URL;
/**
*
* Fetches a server provider from the Parabot SDN
* Fetches a server provider from the Parabot BDN
*
* @author Everel
*