Merge branch 'development' into feature/keybindings

This commit is contained in:
Jeroen Ketelaar
2016-06-13 18:05:28 +02:00
committed by GitHub
17 changed files with 390 additions and 677 deletions
+30
View File
@@ -0,0 +1,30 @@
- name: priority:low
color: bfe5bf
- name: priority:medium
color: bfe5bf
- name: priority:high
color: bfe5bf
- name: status:accepted
color: fef2c0
- name: status:unconfirmed
color: fef2c0
- name: status:needs more info
color: fef2c0
- name: status:rejected
color: fef2c0
- name: status:under consideration
color: fef2c0
- name: type:bug
color: f7c6c7
- name: type:feature
color: f7c6c7
- name: type:improvement
color: f7c6c7
- name: type:question
color: f7c6c7
- name: os:windows
color: "666699"
- name: os:mac
color: "666699"
- name: os:other
color: "666699"
+4
View File
@@ -42,3 +42,7 @@ If you'd like to have either or both the client and the API in your project, use
</dependencies> </dependencies>
``` ```
**For the latest versions of our dependencies, please check our examples on [the Maven Repository](https://github.com/Parabot/Maven-Repository/tree/master/examples)** **For the latest versions of our dependencies, please check our examples on [the Maven Repository](https://github.com/Parabot/Maven-Repository/tree/master/examples)**
#### Labels
Labels are created with [GHLabel](https://github.com/jimmycuadra/ghlabel), whereas the yml is located in the .github directory
-6
View File
@@ -36,12 +36,6 @@
</repositories> </repositories>
<dependencies> <dependencies>
<dependency>
<groupId>naga</groupId>
<artifactId>naga</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>javafx</groupId> <groupId>javafx</groupId>
<artifactId>javafx</artifactId> <artifactId>javafx</artifactId>
@@ -15,7 +15,7 @@ public class Configuration {
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_SERVER_SETTINGS = "http://bdn.parabot.org/api/get.php?action=get_settings";
public static final String GET_BOT_VERSION = "http://v3.bdn.parabot.org/api/bot/list/client?latest=true"; 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/";
public static final String REGISTRATION_PAGE = "https://www.parabot.org/community/register/"; public static final String REGISTRATION_PAGE = "https://www.parabot.org/community/register/";
@@ -23,8 +23,13 @@ public class Configuration {
public static final String DATA_API = "http://bdn.parabot.org/api/v2/data/"; public static final String DATA_API = "http://bdn.parabot.org/api/v2/data/";
public static final String ITEM_API = DATA_API + "items/"; public static final String ITEM_API = DATA_API + "items/";
public static final String COMPARE_VERSION_URL = "http://v3.bdn.parabot.org/api/bot/compare/%s/%s";
public static final String COMPARE_CHECKSUM_URL = "http://v3.bdn.parabot.org/api/bot/checksum/%s/%s";
public static final Version BOT_VERSION = ProjectProperties.getProjectVersion(); public static final Version BOT_VERSION = ProjectProperties.getProjectVersion();
public static final String BOT_TITLE = "Parabot"; public static final String BOT_TITLE = "Parabot";
public static final String BOT_SLOGAN = "The best RuneScape private server bot"; public static final String BOT_SLOGAN = "The best RuneScape private server bot";
public static final String NIGHTLY_APPEND = "nightly=true";
} }
@@ -14,7 +14,6 @@ import org.parabot.environment.input.Keyboard;
import org.parabot.environment.input.Mouse; import org.parabot.environment.input.Mouse;
import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.randoms.RandomHandler; import org.parabot.environment.scripts.randoms.RandomHandler;
import org.parabot.environment.scripts.uliratha.UlirathaClient;
import org.parabot.environment.servers.ServerProvider; import org.parabot.environment.servers.ServerProvider;
import java.applet.Applet; import java.applet.Applet;
@@ -49,7 +48,6 @@ public class Context {
private Mouse mouse; private Mouse mouse;
private Keyboard keyboard; private Keyboard keyboard;
private ServerProviderInfo providerInfo; private ServerProviderInfo providerInfo;
private UlirathaClient ulirathaClient;
private JSONParser jsonParser; private JSONParser jsonParser;
private PrintStream defaultOut; private PrintStream defaultOut;
@@ -354,14 +352,6 @@ public class Context {
return username; return username;
} }
public UlirathaClient getUlirathaClient() {
return ulirathaClient;
}
public void setUlirathaClient(UlirathaClient ulirathaClient) {
this.ulirathaClient = ulirathaClient;
}
public static void setUsername(String username) { public static void setUsername(String username) {
Context.username = username; Context.username = username;
} }
+29 -71
View File
@@ -24,7 +24,7 @@ import java.security.NoSuchAlgorithmException;
*/ */
@SuppressWarnings("Duplicates") @SuppressWarnings("Duplicates")
public class Core { public class Core {
public static boolean mDebug;
private static boolean debug; private static boolean debug;
private static boolean verbose; private static boolean verbose;
private static boolean dump; private static boolean dump;
@@ -78,7 +78,7 @@ public class Core {
Core.dump = dump; Core.dump = dump;
} }
public static void disableSec(){ public static void disableSec() {
UILog.log( UILog.log(
"Security Warning", "Security Warning",
"Disabling the securty manager is ill advised.\n" "Disabling the securty manager is ill advised.\n"
@@ -88,7 +88,7 @@ public class Core {
Core.secure = false; Core.secure = false;
} }
public static boolean isSecure(){ public static boolean isSecure() {
return secure; return secure;
} }
@@ -130,9 +130,10 @@ public class Core {
/** /**
* Checks the version of the bot using a checksum of the jar comparison against checksum given by the website * Checks the version of the bot using a checksum of the jar comparison against checksum given by the website
*
* @return <b>true</b> if no new version is found, otherwise <b>false</b>. * @return <b>true</b> if no new version is found, otherwise <b>false</b>.
*/ */
private static boolean checksumValid(){ private static boolean checksumValid() {
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile()); File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
if (f.isFile()) { if (f.isFile()) {
try { try {
@@ -151,18 +152,15 @@ public class Core {
byte[] mdbytes = md.digest(); byte[] mdbytes = md.digest();
StringBuilder sb = new StringBuilder(""); StringBuilder sb = new StringBuilder("");
for (int i = 0; i < mdbytes.length; i++) { for (byte mdbyte : mdbytes) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1)); sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1));
} }
String result; String result;
if ((result = WebUtil.getContents("http://bdn.parabot.org/api/v2/bot/checksum", "checksum=" + URLEncoder.encode(sb.toString(), "UTF-8"))) != null) { if ((result = WebUtil.getContents(String.format(Configuration.COMPARE_CHECKSUM_URL, "client", currentVersion.get()), "checksum=" + URLEncoder.encode(sb.toString(), "UTF-8"))) != null) {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(result); JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(result);
if (!(boolean) object.get("result")){ System.out.println(object.get("result"));
Core.verbose("Latest checksum: " + sb.toString()); return Boolean.parseBoolean((String) object.get("result"));
Core.verbose("Latest checksum: " + object.get("current"));
return false;
}
} }
} }
} catch (NoSuchAlgorithmException | ParseException | IOException | URISyntaxException e) { } catch (NoSuchAlgorithmException | ParseException | IOException | URISyntaxException e) {
@@ -172,64 +170,25 @@ public class Core {
return true; return true;
} }
/**
* @Deprecated use #validVersion instead
*
* Checks the version of the bot using a variable comparison from the bot code and the Parabot website
*
* @return <b>true</b> if no new version is found, otherwise <b>false</b>.
*/
private static boolean versionValid(){
BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION);
try {
String version = null;
if (br != null) {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
version = (String) object.get("result");
}
if (version != null) {
if (!Configuration.BOT_VERSION.equals(version)) {
Core.verbose("Our version: " + Configuration.BOT_VERSION);
Core.verbose("Latest version: " + version);
return false;
}
}
} catch (NumberFormatException | IOException | ParseException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}
/** /**
* Compares the latest version from the BDN and the current version * Compares the latest version from the BDN and the current version
* *
* @return True if the current version is equal or higher than the latest version, false if lower than the latest version * @return True if the current version is equal or higher than the latest version, false if lower than the latest version
*/ */
public static boolean validVersion() { public static boolean validVersion() {
BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION); String url = String.format(Configuration.COMPARE_VERSION_URL, "client", currentVersion.get());
BufferedReader br = WebUtil.getReader(url);
try { try {
latestVersion = null;
if (br != null) { if (br != null) {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br); JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(br);
latestVersion = new Version((String) object.get("version")); boolean latest = Boolean.parseBoolean((String) object.get("result"));
if (!latest) {
Directories.clearCache();
} }
if (latestVersion != null) { return latest;
if (Configuration.BOT_VERSION.compareTo(latestVersion) < 0) {
Core.verbose("Our version: " + Configuration.BOT_VERSION.get());
Core.verbose("Latest version: " + latestVersion.get());
return false;
} }
} } catch (IOException | ParseException e) {
} catch (NumberFormatException | IOException | ParseException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
try { try {
@@ -247,13 +206,13 @@ public class Core {
/** /**
* Validates the cache and removes the cache contents if required * Validates the cache and removes the cache contents if required
*/ */
private static void validateCache(){ private static void validateCache() {
File[] cache = Directories.getCachePath().listFiles(); File[] cache = Directories.getCachePath().listFiles();
Integer lowest = null; Integer lowest = null;
if (cache != null) { if (cache != null) {
for (File f : cache) { for (File f : cache) {
int date = (int) (f.lastModified()/ 1000); int date = (int) (f.lastModified() / 1000);
if (lowest == null || date < lowest){ if (lowest == null || date < lowest) {
lowest = date; lowest = date;
} }
} }
@@ -261,10 +220,10 @@ public class Core {
try { try {
JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(WebUtil.getContents("http://bdn.parabot.org/api/v2/bot/cache", "date=" + lowest)); JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(WebUtil.getContents("http://bdn.parabot.org/api/v2/bot/cache", "date=" + lowest));
if ((boolean) object.get("result")){ if ((boolean) object.get("result")) {
Core.verbose("Making space for the latest cache files"); Core.verbose("Making space for the latest cache files");
Directories.clearCache(); Directories.clearCache();
}else{ } else {
Core.verbose("Cache is up to date"); Core.verbose("Cache is up to date");
} }
} catch (MalformedURLException | ParseException e) { } catch (MalformedURLException | ParseException e) {
@@ -281,18 +240,17 @@ public class Core {
Core.verbose("Checking for updates..."); Core.verbose("Checking for updates...");
validateCache(); validateCache();
if ((validVersion() && checksumValid()) || (!checksumValid() && currentVersion.compareTo(latestVersion) >= 0)){ if (validate) {
if (validVersion() && checksumValid()) {
Core.verbose("No updates available."); Core.verbose("No updates available.");
return true; return true;
}else{ } else {
Core.verbose("Updates available..."); Core.verbose("Updates available...");
return false; return false;
} }
} }else{
Core.verbose("Validation disabled");
public static void debug(int i) { return true;
if(mDebug) {
System.out.println("DEBUG: " + i);
} }
} }
} }
@@ -0,0 +1,16 @@
package org.parabot.core.io;
/**
* @author JKetelaar
*/
public class NoProgressListener implements ProgressListener {
@Override
public void onProgressUpdate(double value) {
}
@Override
public void updateDownloadSpeed(double mbPerSecond) {
}
}
@@ -1,72 +0,0 @@
package org.parabot.core.lib.naga;
import org.parabot.core.Core;
import org.parabot.core.Directories;
import org.parabot.core.build.BuildPath;
import org.parabot.core.lib.Library;
import java.io.File;
import java.net.URL;
/**
* @author JKetelaar
*/
public class Naga extends Library {
private static boolean valid;
@Override
public void init() {
if (!hasJar()) {
System.err.println("Failed to load javafx... [jar missing]");
return;
}
Core.verbose("Adding javafx jar file to build path: "
+ getJarFileURL().getPath());
BuildPath.add(getJarFileURL());
try {
Class.forName("javafx.application.Application");
valid = true;
} catch (ClassNotFoundException e) {
System.err
.println("Failed to add javafx to build path, or incorrupt download");
}
Core.verbose("JavaFX initialized.");
}
@Override
public boolean isAdded() {
return valid;
}
@Override
public File getJarFile() {
return new File(Directories.getCachePath(), "naga.jar");
}
@Override
public URL getDownloadLink() {
try {
return new URL("http://bdn.parabot.org/api/v2/data/dependencies/naga");
} catch (Throwable t) {
t.printStackTrace();
}
return null;
}
@Override
public boolean requiresJar() {
return true;
}
@Override
public String getLibraryName() {
return "Naga";
}
public static boolean isValid() {
return valid;
}
}
@@ -4,6 +4,7 @@ import org.parabot.core.Configuration;
import org.parabot.core.Context; import org.parabot.core.Context;
import org.parabot.core.Core; import org.parabot.core.Core;
import org.parabot.core.Directories; import org.parabot.core.Directories;
import org.parabot.core.io.NoProgressListener;
import org.parabot.core.io.ProgressListener; import org.parabot.core.io.ProgressListener;
import org.parabot.environment.api.utils.WebUtil; import org.parabot.environment.api.utils.WebUtil;
@@ -51,17 +52,7 @@ public class PublicRandoms extends RandomParser {
return; return;
} }
String downloadLink = Configuration.GET_RANDOMS; String downloadLink = Configuration.GET_RANDOMS;
WebUtil.downloadFile(new URL(downloadLink), random, new ProgressListener() { WebUtil.downloadFile(new URL(downloadLink), random, new NoProgressListener());
@Override
public void onProgressUpdate(double v) {
}
@Override
public void updateDownloadSpeed(double v) {
}
});
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -1,8 +1,6 @@
package org.parabot.core.ui; package org.parabot.core.ui;
import org.parabot.core.Context;
import org.parabot.core.ui.components.GamePanel; import org.parabot.core.ui.components.GamePanel;
import org.parabot.environment.scripts.uliratha.UlirathaClient;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@@ -63,10 +61,7 @@ public class Logger extends JPanel {
instance.model.addElement(message); instance.model.addElement(message);
if (uliratha){ if (uliratha){
UlirathaClient client; // TODO: Implement latest Uliratha
if ((client = Context.getInstance().getUlirathaClient()) != null) {
client.sendMessage(message);
}
} }
int last = instance.list.getModel().getSize() - 1; int last = instance.list.getModel().getSize() - 1;
@@ -4,7 +4,6 @@ import org.parabot.core.Core;
import org.parabot.core.desc.ServerDescription; import org.parabot.core.desc.ServerDescription;
import org.parabot.core.lib.Library; import org.parabot.core.lib.Library;
import org.parabot.core.lib.javafx.JavaFX; import org.parabot.core.lib.javafx.JavaFX;
import org.parabot.core.lib.naga.Naga;
import org.parabot.core.parsers.servers.ServerParser; import org.parabot.core.parsers.servers.ServerParser;
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;
@@ -30,7 +29,6 @@ public class Environment {
LinkedList<Library> libs = new LinkedList<>(); LinkedList<Library> libs = new LinkedList<>();
libs.add(new JavaFX()); libs.add(new JavaFX());
libs.add(new Naga());
for(Library lib : libs) { for(Library lib : libs) {
if (lib.requiresJar()) { if (lib.requiresJar()) {
@@ -22,6 +22,10 @@ public class Version implements Comparable<Version> {
return this.version; return this.version;
} }
public boolean isNightly(){
return this.version.contains("RC");
}
@Override @Override
public int compareTo(Version that) { public int compareTo(Version that) {
if (that == null) { if (that == null) {
@@ -5,17 +5,12 @@ import org.parabot.core.io.ProgressListener;
import org.parabot.core.io.SizeInputStream; import org.parabot.core.io.SizeInputStream;
import java.io.*; import java.io.*;
import java.net.MalformedURLException; import java.net.*;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
/** /**
*
* A WebUtil class fetches data from an URL * A WebUtil class fetches data from an URL
* *
* @author Everel * @author Everel
*
*/ */
public class WebUtil { public class WebUtil {
@@ -226,6 +221,7 @@ public class WebUtil {
/** /**
* Downloads a file on the internet * Downloads a file on the internet
*
* @param url * @param url
* @param destination * @param destination
* @param listener * @param listener
@@ -258,6 +254,7 @@ public class WebUtil {
/** /**
* Downloads a file on the internet * Downloads a file on the internet
*
* @param url * @param url
* @param destination * @param destination
* @param listener * @param listener
@@ -290,6 +287,7 @@ public class WebUtil {
/** /**
* Converts file format to url format * Converts file format to url format
*
* @param file * @param file
* @return url to file * @return url to file
*/ */
@@ -303,9 +301,27 @@ public class WebUtil {
} }
public static JSONParser getJsonParser() { public static JSONParser getJsonParser() {
if (jsonParser == null){ if (jsonParser == null) {
jsonParser = new JSONParser(); jsonParser = new JSONParser();
} }
return jsonParser; return jsonParser;
} }
public static URI appendUri(String uri, String appendQuery) {
try {
URI oldUri = new URI(uri);
String newQuery = oldUri.getQuery();
if (newQuery == null) {
newQuery = appendQuery;
} else {
newQuery += "&" + appendQuery;
}
return new URI(oldUri.getScheme(), oldUri.getAuthority(),
oldUri.getPath(), newQuery, oldUri.getFragment());
} catch (URISyntaxException e) {
e.printStackTrace();
}
return null;
}
} }
@@ -123,11 +123,6 @@ public class Script implements Runnable {
this.state = STATE_STOPPED; this.state = STATE_STOPPED;
context.setRunningScript(null); context.setRunningScript(null);
if (context.getUlirathaClient() != null) {
context.getUlirathaClient().disconnect();
context.setUlirathaClient(null);
}
BotUI.getInstance().toggleRun(); BotUI.getInstance().toggleRun();
Core.verbose("Done."); Core.verbose("Done.");
} }
@@ -8,7 +8,6 @@ import org.parabot.core.ui.utils.UILog;
import org.parabot.environment.api.utils.WebUtil; import org.parabot.environment.api.utils.WebUtil;
import org.parabot.environment.scripts.Script; import org.parabot.environment.scripts.Script;
import org.parabot.environment.scripts.loader.JavaScriptLoader; import org.parabot.environment.scripts.loader.JavaScriptLoader;
import org.parabot.environment.scripts.uliratha.UlirathaExecuter;
import javax.swing.*; import javax.swing.*;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@@ -77,9 +76,6 @@ public class BDNScriptsExecuter extends ScriptExecuter {
script.setScriptID(this.id); script.setScriptID(this.id);
super.finalize(tg, script); super.finalize(tg, script);
if (manager.getAccount().getApi() != null) {
new UlirathaExecuter(manager.getAccount().getApi()).start(this.id);
}
} catch (NoClassDefFoundError | ClassNotFoundException ignored) { } catch (NoClassDefFoundError | ClassNotFoundException ignored) {
UILog.log("Error", "Failed to load BDN 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 (Throwable t) { } catch (Throwable t) {
@@ -1,158 +0,0 @@
package org.parabot.environment.scripts.uliratha;
import naga.ExceptionObserver;
import naga.NIOService;
import naga.NIOSocket;
import naga.SocketObserver;
import naga.packetreader.RegularPacketReader;
import naga.packetwriter.RegularPacketWriter;
import org.parabot.core.ui.Logger;
import java.io.*;
/**
* @author JKetelaar
*/
public class UlirathaClient extends Thread {
private String host;
private int port;
private NIOSocket socket;
private boolean connected;
private int scriptID;
private String api;
private boolean valid;
public UlirathaClient(String host, int port, int scriptID, String api) {
this.host = host;
this.port = port;
this.scriptID = scriptID;
this.api = api;
}
@Override
public void run() {
connect();
}
private void connect() {
try {
NIOService service = new NIOService();
service.setExceptionObserver(new ExceptionObserver() {
@Override
public void notifyExceptionThrown(Throwable throwable) {
throwable.printStackTrace();
if (valid) {
reconnect();
connected = false;
}
}
});
socket = service.openSocket(host, port);
socket.setPacketReader(new RegularPacketReader(4, true));
socket.setPacketWriter(new RegularPacketWriter(4, true));
socket.listen(new SocketObserver() {
public void connectionOpened(NIOSocket nioSocket) {
try {
sendObjects(nioSocket, new Object[]{76, scriptID, api});
} catch (IOException e) {
e.printStackTrace();
}
}
public void packetReceived(NIOSocket socket, byte[] packet) {
try {
DataInputStream stream = new DataInputStream(new ByteArrayInputStream(packet));
int packetID = stream.readInt();
switch (packetID){
case 75:
valid = stream.readBoolean();
if (valid) {
Logger.addMessage("We're connected with the Uliratha server!", false);
connected = true;
}else{
socket.close();
}
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void packetSent(NIOSocket nioSocket, Object o) {
}
public void connectionBroken(NIOSocket nioSocket, Exception exception) {
if (valid) {
Logger.addMessage("We lost connection with the Uliratha server, reconnecting...", false);
reconnect();
connected = false;
}else{
Logger.addMessage("We're disconnected from the Uliratha server", false);
}
}
});
while (true) {
service.selectBlocking();
}
} catch (IOException e) {
if (valid) {
reconnect();
connected = false;
}
}
}
private void reconnect() {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
connect();
}
public boolean isConnected() {
return connected;
}
public void disconnect(){
valid = false;
socket.close();
}
private void sendObjects(NIOSocket socket, Object[] objects) throws IOException {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream dataStream = new DataOutputStream(stream);
for (Object o : objects) {
if (o instanceof String) {
dataStream.writeUTF((String) o);
} else if (o instanceof Integer) {
dataStream.writeInt((Integer) o);
} else if (o instanceof byte[]) {
dataStream.write((byte[]) o);
} else if (o instanceof Long) {
dataStream.writeLong((Long) o);
} else if (o instanceof Boolean) {
dataStream.writeBoolean((Boolean) o);
}
}
dataStream.flush();
final byte[] content = stream.toByteArray();
dataStream.close();
socket.write(content);
}
public void sendMessage(String message){
try {
sendObjects(socket, new Object[]{83, message});
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -1,49 +0,0 @@
package org.parabot.environment.scripts.uliratha;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.parabot.core.Context;
import org.parabot.environment.api.utils.WebUtil;
import java.io.IOException;
/**
* @author JKetelaar
*/
public class UlirathaExecuter {
private String api;
private static boolean isVip = true;
public UlirathaExecuter(String api){
this.api = api;
}
public void start(int scriptID){
if (UlirathaExecuter.isVip) {
String vipUrl = "http://bdn.parabot.org/api/v2/user/" + api + "/vip";
JSONParser parser = new JSONParser();
try {
JSONObject vipObject = (JSONObject) parser.parse(WebUtil.getReader(vipUrl));
boolean isVip = (boolean) vipObject.get("result");
if (isVip) {
String serverUrl = "http://bdn.parabot.org/api/v2/clients/server";
JSONObject serverObject = (JSONObject) parser.parse(WebUtil.getReader(serverUrl));
JSONObject detailsObject = (JSONObject) serverObject.get("result");
String host = (String) detailsObject.get("host");
long port = (long) detailsObject.get("port");
UlirathaClient client = new UlirathaClient(host, (int) port, scriptID, api);
client.start();
Context.getInstance().setUlirathaClient(client);
}else{
UlirathaExecuter.isVip = false;
}
} catch (IOException | ParseException | ClassCastException e) {
e.printStackTrace();
}
}
}
}