mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Whole new revision for BDN support
This commit is contained in:
@@ -7,18 +7,13 @@ package org.parabot.core;
|
||||
*/
|
||||
public class Configuration {
|
||||
public static final String LOGIN_SERVER = "https://www.parabot.org/community/api/login.php?username=%s&password=%s";
|
||||
public static final String SDN_SCRIPTS_JSON = "http://sdn.parabot.org/scripts.php?method=json&user=%s";
|
||||
public static final String GET_SDN_SCRIPT = "http://sdn.parabot.org/getscript.php?user=%s&pass=%s&scriptid=%d";
|
||||
public static final String GET_SERVER_PROVIDERS_JSON = "http://sdn.parabot.org/providers/index.php?method=json";
|
||||
public static final String GET_SERVER_PROVIDER = "http://sdn.parabot.org/providers/provider.php?id=";
|
||||
public static final String GET_SERVER_PROVIDER_INFO = "http://sdn.parabot.org/providers/getInformation.php?id=";
|
||||
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_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_INFO = "http://bdn.parabot.org/api/get.php?action=server_information&name=";
|
||||
public static final String GET_BOT_VERSION = "http://bot.parabot.org/version.txt";
|
||||
public static final String REGISTRATION_PAGE = "https://www.parabot.org/community/index.php?app=core&module=global§ion=register";
|
||||
|
||||
public static final double BOT_VERSION = 2.1;
|
||||
|
||||
/* Unused - But might be useful in the future
|
||||
public static final String SDN_SCRIPTS = "http://sdn.parabot.org/scripts.php?user=%s";
|
||||
public static final String GET_SERVER_PROVIDERS = "http://sdn.parabot.org/providers/index.php";
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
public String isVip;
|
||||
public String isPremium;
|
||||
public int sdnId;
|
||||
public String jarName;
|
||||
|
||||
/**
|
||||
/**
|
||||
* The ScriptManifest
|
||||
*
|
||||
* @param scriptName
|
||||
@@ -32,13 +31,12 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
final String category, final double version,
|
||||
final String description, final String[] servers) {
|
||||
this(scriptName, author, category, version, description, servers, null,
|
||||
null, -1, null);
|
||||
null, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for SDN script (see SDNScripts parser)
|
||||
*
|
||||
* @param jarName
|
||||
*
|
||||
* @param scriptName
|
||||
* @param author
|
||||
* @param category
|
||||
@@ -47,11 +45,11 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
* @param servers
|
||||
* @param sdnId
|
||||
*/
|
||||
public ScriptDescription(final String jarName, final String scriptName,
|
||||
public ScriptDescription(final String scriptName,
|
||||
final String author, final String category, final double version,
|
||||
final String description, final String[] servers, final int sdnId) {
|
||||
this(scriptName, author, category, version, description, servers, null,
|
||||
null, sdnId, jarName);
|
||||
null, sdnId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +70,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
final String description, final String[] servers, final String vip,
|
||||
final String premium) {
|
||||
this(scriptName, author, category, version, description, servers, vip,
|
||||
premium, -1, null);
|
||||
premium, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,12 +85,11 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
* @param vip
|
||||
* @param premium
|
||||
* @param sdnId
|
||||
* @param jarName
|
||||
*/
|
||||
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 jarName) {
|
||||
final String premium, final int sdnId) {
|
||||
this.scriptName = scriptName;
|
||||
this.author = author;
|
||||
this.category = category;
|
||||
@@ -102,8 +99,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
this.isVip = vip;
|
||||
this.isPremium = premium;
|
||||
this.sdnId = sdnId;
|
||||
this.jarName = jarName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -127,8 +123,7 @@ public class ScriptDescription implements Comparable<ScriptDescription> {
|
||||
.append(this.isPremium == null ? "unknown" : this.isPremium)
|
||||
.append(", sdn id: ")
|
||||
.append(this.sdnId == -1 ? "unknown" : Integer
|
||||
.toString(this.sdnId)).append(", jarname: ")
|
||||
.append(this.jarName == null ? "unknown" : this.jarName)
|
||||
.toString(this.sdnId))
|
||||
.append("]");
|
||||
|
||||
return b.toString();
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ServerProviderInfo {
|
||||
try {
|
||||
String line;
|
||||
Core.verbose("Reading info: " + providerInfo);
|
||||
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString() + "&method=json"), username, password);
|
||||
BufferedReader br = WebUtil.getReader(new URL(providerInfo.toString()), username, password);
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
if ((line = br.readLine()) != null) {
|
||||
@@ -52,7 +52,7 @@ public class ServerProviderInfo {
|
||||
|
||||
public URL getClient() {
|
||||
try {
|
||||
return new URL(properties.getProperty("client"));
|
||||
return new URL(properties.getProperty("client_jar"));
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class ServerProviderInfo {
|
||||
|
||||
public URL getExtendedHookFile() {
|
||||
try {
|
||||
return new URL(properties.get("hooks") + "&extended=true");
|
||||
return new URL(properties.getProperty("hooks") /*+ "&extended=true"*/);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
return getHookFile();
|
||||
@@ -78,27 +78,23 @@ public class ServerProviderInfo {
|
||||
}
|
||||
|
||||
public String getClientClass() {
|
||||
return properties.getProperty("clientClass");
|
||||
return properties.getProperty("client_class");
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return properties.getProperty("serverName");
|
||||
return properties.getProperty("name");
|
||||
}
|
||||
|
||||
public long getCRC32() {
|
||||
if (properties.get("crc32") != null) {
|
||||
return Long.parseLong(properties.getProperty("crc32"));
|
||||
} else {
|
||||
return System.currentTimeMillis() / 1000 / 60 / 60 / 24;
|
||||
}
|
||||
return Long.parseLong(properties.getProperty("provider_crc32"));
|
||||
}
|
||||
|
||||
public long getClientCRC32() {
|
||||
return Long.parseLong(properties.getProperty("clientCrc32"));
|
||||
return Long.parseLong(properties.getProperty("client_crc32"));
|
||||
}
|
||||
|
||||
public int getBankTabs() {
|
||||
return Integer.parseInt(properties.getProperty("bankTabs"));
|
||||
return Integer.parseInt(properties.getProperty("bank_tabs"));
|
||||
}
|
||||
|
||||
public Properties getProperties() {
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package org.parabot.core.parsers.scripts;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.net.URL;
|
||||
|
||||
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.SDNScriptExecuter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Parses scripts stored on the SDN of Parabot
|
||||
*
|
||||
@@ -38,22 +39,22 @@ public class SDNScripts extends ScriptParser {
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
BufferedReader br = WebUtil.getReader(new URL(String.format(Configuration.SDN_SCRIPTS_JSON, manager.getAccount()
|
||||
.getURLUsername())));
|
||||
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);
|
||||
String jarName = String.valueOf(jsonObject.get("jarname"));
|
||||
int sdnId = Integer.parseInt(String.valueOf(jsonObject.get("scriptid")));
|
||||
String scriptName = String.valueOf(jsonObject.get("scriptname"));
|
||||
int sdnId = 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(jarName, scriptName,
|
||||
final ScriptDescription desc = new ScriptDescription(scriptName,
|
||||
author, category, version, description,
|
||||
null, sdnId);
|
||||
SCRIPT_CACHE.put(desc, new SDNScriptExecuter(sdnId));
|
||||
|
||||
@@ -34,7 +34,7 @@ public class PublicServers extends ServerParser {
|
||||
public void execute() {
|
||||
try {
|
||||
BufferedReader br = WebUtil.getReader(new URL(
|
||||
Configuration.GET_SERVER_PROVIDERS_JSON), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
Configuration.GET_SERVER_PROVIDERS), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
String line;
|
||||
|
||||
JSONParser parser = new JSONParser();
|
||||
@@ -44,11 +44,10 @@ public class PublicServers extends ServerParser {
|
||||
String name = String.valueOf(jsonObject.get("name"));
|
||||
String author = String.valueOf(jsonObject.get("author"));
|
||||
double version = Double.parseDouble(String.valueOf(jsonObject.get("version")));
|
||||
int serverID = Integer.parseInt(String.valueOf(jsonObject.get("id")));
|
||||
|
||||
ServerDescription desc = new ServerDescription(name,
|
||||
author, version);
|
||||
SERVER_CACHE.put(desc, new PublicServerExecuter(name, serverID));
|
||||
SERVER_CACHE.put(desc, new PublicServerExecuter(name));
|
||||
}
|
||||
|
||||
br.close();
|
||||
|
||||
@@ -134,7 +134,7 @@ public class WebUtil {
|
||||
|
||||
/**
|
||||
* Opens a connection
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @return URLConnection to URL
|
||||
*/
|
||||
@@ -148,7 +148,7 @@ public class WebUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static BufferedReader getReader(final URL url, String username, String password) {
|
||||
try {
|
||||
String data = URLEncoder.encode("username", "UTF-8") + "=" + username;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.parabot.environment.input;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* A virtual mouse, dispatches mouse events to a component
|
||||
@@ -138,7 +137,7 @@ public class Mouse implements MouseListener, MouseMotionListener {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,7 +43,9 @@ public class SDNScriptExecuter extends ScriptExecuter {
|
||||
@Override
|
||||
public void run(ThreadGroup tg) {
|
||||
try {
|
||||
final URLConnection urlConnection = WebUtil.getConnection(new URL(String.format(Configuration.GET_SDN_SCRIPT, manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword(), this.id)));
|
||||
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");
|
||||
if(contentType.equals("text/html")) {
|
||||
// failed to fetch script
|
||||
|
||||
@@ -30,7 +30,6 @@ import java.net.URL;
|
||||
*/
|
||||
public class PublicServerExecuter extends ServerExecuter {
|
||||
private String serverName;
|
||||
private int serverID;
|
||||
|
||||
private static AccountManager manager;
|
||||
|
||||
@@ -43,21 +42,20 @@ public class PublicServerExecuter extends ServerExecuter {
|
||||
|
||||
};
|
||||
|
||||
public PublicServerExecuter(final String serverName, final int serverID) {
|
||||
public PublicServerExecuter(final String serverName) {
|
||||
this.serverName = serverName;
|
||||
this.serverID = serverID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ServerProviderInfo serverProviderInfo = new ServerProviderInfo(new URL(Configuration.GET_SERVER_PROVIDER_INFO
|
||||
+ this.serverID), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
+ this.serverName), manager.getAccount().getURLUsername(), manager.getAccount().getURLPassword());
|
||||
|
||||
final File destination = new File(Directories.getCachePath(),
|
||||
serverProviderInfo.getCRC32() + ".jar");
|
||||
final String jarUrl = Configuration.GET_SERVER_PROVIDER
|
||||
+ this.serverID;
|
||||
+ this.serverName;
|
||||
|
||||
Core.verbose("Downloading: " + jarUrl + " ...");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user