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[] servers;
public String isVip; public String isVip;
public String isPremium; public String isPremium;
public int sdnId; public int bdnId;
/** /**
* The ScriptManifest * 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 scriptName
* @param author * @param author
@@ -43,17 +43,17 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
* @param version * @param version
* @param description * @param description
* @param servers * @param servers
* @param sdnId * @param bdnId
*/ */
public ScriptDescription(final String scriptName, public ScriptDescription(final String scriptName,
final String author, final String category, final double version, 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, 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) * manager is a private program)
* *
* @param scriptName * @param scriptName
@@ -84,12 +84,12 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
* @param servers * @param servers
* @param vip * @param vip
* @param premium * @param premium
* @param sdnId * @param bdnId
*/ */
public ScriptDescription(final String scriptName, final String author, public ScriptDescription(final String scriptName, final String author,
final String category, final double version, final String category, final double version,
final String description, final String[] servers, final String vip, 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.scriptName = scriptName;
this.author = author; this.author = author;
this.category = category; this.category = category;
@@ -98,7 +98,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
this.servers = servers; this.servers = servers;
this.isVip = vip; this.isVip = vip;
this.isPremium = premium; this.isPremium = premium;
this.sdnId = sdnId; this.bdnId = bdnId;
} }
@Override @Override
@@ -121,9 +121,9 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
.append(this.isVip == null ? "unknown" : this.isVip) .append(this.isVip == null ? "unknown" : this.isVip)
.append(", premium: ") .append(", premium: ")
.append(this.isPremium == null ? "unknown" : this.isPremium) .append(this.isPremium == null ? "unknown" : this.isPremium)
.append(", sdn id: ") .append(", bdn id: ")
.append(this.sdnId == -1 ? "unknown" : Integer .append(this.bdnId == -1 ? "unknown" : Integer
.toString(this.sdnId)) .toString(this.bdnId))
.append("]"); .append("]");
return b.toString(); return b.toString();
@@ -2,11 +2,11 @@ package org.parabot.core.forum;
import org.parabot.core.Configuration; import org.parabot.core.Configuration;
import org.parabot.core.Core; 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.parsers.servers.PublicServers;
import org.parabot.core.ui.components.VerboseLoader; import org.parabot.core.ui.components.VerboseLoader;
import org.parabot.environment.api.utils.WebUtil; 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 org.parabot.environment.servers.executers.PublicServerExecuter;
import java.net.URLEncoder; import java.net.URLEncoder;
@@ -37,9 +37,9 @@ public final class AccountManager {
Core.verbose("Initializing account manager accessors..."); Core.verbose("Initializing account manager accessors...");
final ArrayList<AccountManagerAccess> accessors = new ArrayList<AccountManagerAccess>(); final ArrayList<AccountManagerAccess> accessors = new ArrayList<AccountManagerAccess>();
accessors.add(SDNScripts.MANAGER_FETCHER); accessors.add(BDNScripts.MANAGER_FETCHER);
accessors.add(VerboseLoader.MANAGER_FETCHER); accessors.add(VerboseLoader.MANAGER_FETCHER);
accessors.add(SDNScriptExecuter.MANAGER_FETCHER); accessors.add(BDNScriptsExecuter.MANAGER_FETCHER);
accessors.add(PublicServers.MANAGER_FETCHER); accessors.add(PublicServers.MANAGER_FETCHER);
accessors.add(PublicServerExecuter.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.AccountManager;
import org.parabot.core.forum.AccountManagerAccess; import org.parabot.core.forum.AccountManagerAccess;
import org.parabot.environment.api.utils.WebUtil; 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.io.BufferedReader;
import java.net.URL; import java.net.URL;
/** /**
* Parses scripts stored on the SDN of Parabot * Parses scripts stored on the BDN of Parabot
* *
* @author Paradox, Everel * @author Paradox, Everel
*/ */
public class SDNScripts extends ScriptParser { public class BDNScripts extends ScriptParser {
private static AccountManager manager; private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() { public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@Override @Override
public final void setManager(AccountManager manager) { 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) { while ((line = br.readLine()) != null) {
JSONObject jsonObject = (JSONObject) parser.parse(line); 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 scriptName = String.valueOf(jsonObject.get("name"));
String author = String.valueOf(jsonObject.get("author")); String author = String.valueOf(jsonObject.get("author"));
double version = Double.parseDouble(String.valueOf(jsonObject.get("version"))); double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
@@ -56,8 +56,8 @@ public class SDNScripts extends ScriptParser {
final ScriptDescription desc = new ScriptDescription(scriptName, final ScriptDescription desc = new ScriptDescription(scriptName,
author, category, version, description, author, category, version, description,
null, sdnId); null, bdnId);
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId)); SCRIPT_CACHE.put(desc, new BDNScriptsExecuter(bdnId));
} }
@@ -25,11 +25,11 @@ public abstract class ScriptParser {
final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>(); final ArrayList<ScriptParser> parsers = new ArrayList<ScriptParser>();
if (Core.inLoadLocal()) { if (Core.inLoadLocal()) {
parsers.add(new LocalJavaScripts()); parsers.add(new LocalJavaScripts());
parsers.add(new SDNScripts()); parsers.add(new BDNScripts());
} else if (Core.inDebugMode()) { } else if (Core.inDebugMode()) {
parsers.add(new LocalJavaScripts()); parsers.add(new LocalJavaScripts());
} else { } else {
parsers.add(new SDNScripts()); parsers.add(new BDNScripts());
} }
Core.verbose("Parsing scripts..."); 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 * @author Everel
* *
*/ */
public class SDNScriptExecuter extends ScriptExecuter { public class BDNScriptsExecuter extends ScriptExecuter {
private static AccountManager manager; private static AccountManager manager;
@@ -29,14 +29,14 @@ public class SDNScriptExecuter extends ScriptExecuter {
@Override @Override
public final void setManager(AccountManager manager) { public final void setManager(AccountManager manager) {
SDNScriptExecuter.manager = manager; BDNScriptsExecuter.manager = manager;
} }
}; };
private int id = -1; private int id = -1;
public SDNScriptExecuter(final int id) { public BDNScriptsExecuter(final int id) {
this.id = id; this.id = id;
} }
@@ -49,7 +49,7 @@ public class SDNScriptExecuter extends ScriptExecuter {
final String contentType = urlConnection.getHeaderField("Content-type"); final String contentType = urlConnection.getHeaderField("Content-type");
if(contentType.equals("text/html")) { if(contentType.equals("text/html")) {
// failed to fetch script // 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")) { } else if(contentType.equals("application/jar")) {
//// JAR LOADING PART //////// //// JAR LOADING PART ////////
@@ -62,10 +62,10 @@ public class SDNScriptExecuter extends ScriptExecuter {
final JavaScriptLoader loader = new JavaScriptLoader(classPath); final JavaScriptLoader loader = new JavaScriptLoader(classPath);
final String[] scriptClasses = loader.getScriptClassNames(); final String[] scriptClasses = loader.getScriptClassNames();
if(scriptClasses == null || scriptClasses.length == 0) { 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; return;
} else if(scriptClasses.length > 1) { } 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; return;
} }
@@ -75,24 +75,22 @@ public class SDNScriptExecuter extends ScriptExecuter {
final Constructor<?> con = scriptClass.getConstructor(); final Constructor<?> con = scriptClass.getConstructor();
final Script script = (Script) con.newInstance(); final Script script = (Script) con.newInstance();
super.finalize(tg, script); super.finalize(tg, script);
} catch (NoClassDefFoundError ignored) { } catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log("Error", "Failed to load SDN script, error: [This server provider does not support this script]", JOptionPane.ERROR_MESSAGE); UILog.log("Error", "Failed to load BDN 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 (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); 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 //// //// END JAR LOADING ////
} else { } 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) { } catch (Throwable t) {
t.printStackTrace(); 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 * @author Everel
* *