mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 08:39:09 +00:00
[TASK] Removed Naga totally, including Uliratha
This is temporarly, as long as there's no new version
This commit is contained in:
@@ -14,7 +14,6 @@ import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.input.Mouse;
|
||||
import org.parabot.environment.scripts.Script;
|
||||
import org.parabot.environment.scripts.randoms.RandomHandler;
|
||||
import org.parabot.environment.scripts.uliratha.UlirathaClient;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
import java.applet.Applet;
|
||||
@@ -49,7 +48,6 @@ public class Context {
|
||||
private Mouse mouse;
|
||||
private Keyboard keyboard;
|
||||
private ServerProviderInfo providerInfo;
|
||||
private UlirathaClient ulirathaClient;
|
||||
private JSONParser jsonParser;
|
||||
|
||||
private PrintStream defaultOut;
|
||||
@@ -354,14 +352,6 @@ public class Context {
|
||||
return username;
|
||||
}
|
||||
|
||||
public UlirathaClient getUlirathaClient() {
|
||||
return ulirathaClient;
|
||||
}
|
||||
|
||||
public void setUlirathaClient(UlirathaClient ulirathaClient) {
|
||||
this.ulirathaClient = ulirathaClient;
|
||||
}
|
||||
|
||||
public static void setUsername(String username) {
|
||||
Context.username = username;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.ui.components.GamePanel;
|
||||
import org.parabot.environment.scripts.uliratha.UlirathaClient;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -63,10 +61,7 @@ public class Logger extends JPanel {
|
||||
instance.model.addElement(message);
|
||||
|
||||
if (uliratha){
|
||||
UlirathaClient client;
|
||||
if ((client = Context.getInstance().getUlirathaClient()) != null) {
|
||||
client.sendMessage(message);
|
||||
}
|
||||
// TODO: Implement latest Uliratha
|
||||
}
|
||||
|
||||
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.lib.Library;
|
||||
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.ui.components.VerboseLoader;
|
||||
import org.parabot.environment.api.utils.WebUtil;
|
||||
@@ -30,7 +29,6 @@ public class Environment {
|
||||
|
||||
LinkedList<Library> libs = new LinkedList<>();
|
||||
libs.add(new JavaFX());
|
||||
libs.add(new Naga());
|
||||
|
||||
for(Library lib : libs) {
|
||||
if (lib.requiresJar()) {
|
||||
|
||||
@@ -123,11 +123,6 @@ public class Script implements Runnable {
|
||||
this.state = STATE_STOPPED;
|
||||
context.setRunningScript(null);
|
||||
|
||||
if (context.getUlirathaClient() != null) {
|
||||
context.getUlirathaClient().disconnect();
|
||||
context.setUlirathaClient(null);
|
||||
}
|
||||
|
||||
BotUI.getInstance().toggleRun();
|
||||
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.scripts.Script;
|
||||
import org.parabot.environment.scripts.loader.JavaScriptLoader;
|
||||
import org.parabot.environment.scripts.uliratha.UlirathaExecuter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -77,9 +76,6 @@ public class BDNScriptsExecuter extends ScriptExecuter {
|
||||
script.setScriptID(this.id);
|
||||
super.finalize(tg, script);
|
||||
|
||||
if (manager.getAccount().getApi() != null) {
|
||||
new UlirathaExecuter(manager.getAccount().getApi()).start(this.id);
|
||||
}
|
||||
} 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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user