mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
Added Uliratha
This commit is contained in:
@@ -6,7 +6,8 @@ package org.parabot.core;
|
||||
* @author Everel
|
||||
*/
|
||||
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 LOGIN_SERVER = "https://www.parabot.org/community/api/login.php?username=%s&password=%s";
|
||||
public static final String LOGIN_SERVER = "http://bdn.parabot.org/api/v2/users/login";
|
||||
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";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.parabot.core;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.parabot.core.asm.ASMClassLoader;
|
||||
import org.parabot.core.classpath.ClassPath;
|
||||
import org.parabot.core.desc.ServerProviderInfo;
|
||||
@@ -13,6 +14,7 @@ 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;
|
||||
@@ -47,6 +49,8 @@ public class Context {
|
||||
private Mouse mouse;
|
||||
private Keyboard keyboard;
|
||||
private ServerProviderInfo providerInfo;
|
||||
private UlirathaClient ulirathaClient;
|
||||
private JSONParser jsonParser;
|
||||
|
||||
private Context(final ServerProvider serverProvider) {
|
||||
threadGroups.put(Thread.currentThread().getThreadGroup(), this);
|
||||
@@ -57,6 +61,8 @@ public class Context {
|
||||
this.classPath = new ClassPath();
|
||||
this.classLoader = new ASMClassLoader(classPath);
|
||||
this.randomHandler = new RandomHandler();
|
||||
|
||||
this.jsonParser = new JSONParser();
|
||||
|
||||
}
|
||||
|
||||
@@ -325,7 +331,19 @@ 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;
|
||||
}
|
||||
|
||||
public JSONParser getJsonParser() {
|
||||
return jsonParser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,11 @@ import java.nio.file.Paths;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The core of parabot
|
||||
*
|
||||
* @author Everel
|
||||
* @author Everel, JKetelaar
|
||||
*/
|
||||
public class Core {
|
||||
public static boolean mDebug;
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.net.URLEncoder;
|
||||
public class Account {
|
||||
private String username;
|
||||
private String password;
|
||||
private String api;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,8 +26,14 @@ public class Account {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
public Account(String username, String password, String api) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.api = api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets user's parabot account name
|
||||
* @return username.
|
||||
*/
|
||||
@@ -68,4 +75,7 @@ public class Account {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getApi() {
|
||||
return api;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.parabot.core.forum;
|
||||
|
||||
import org.json.simple.JSONObject;
|
||||
import org.parabot.core.Configuration;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.parsers.scripts.BDNScripts;
|
||||
@@ -9,6 +10,8 @@ import org.parabot.environment.api.utils.WebUtil;
|
||||
import org.parabot.environment.scripts.executers.BDNScriptsExecuter;
|
||||
import org.parabot.environment.servers.executers.PublicServerExecuter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -61,20 +64,25 @@ public final class AccountManager {
|
||||
if (account != null) {
|
||||
throw new IllegalStateException("Already logged in.");
|
||||
}
|
||||
String contents;
|
||||
JSONObject result;
|
||||
try {
|
||||
contents = WebUtil.getContents(String.format(
|
||||
Configuration.LOGIN_SERVER,
|
||||
URLEncoder.encode(user, "UTF-8"),
|
||||
URLEncoder.encode(pass, "UTF-8")));
|
||||
BufferedReader contents = WebUtil.getReader(WebUtil.getConnection(
|
||||
new URL(Configuration.LOGIN_SERVER),
|
||||
URLEncoder.encode(user, "UTF-8"),
|
||||
URLEncoder.encode(pass, "UTF-8")));
|
||||
result = (JSONObject) WebUtil.getJsonParser().parse(contents);
|
||||
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (contents.equals("correct")) {
|
||||
account = new Account(user, pass);
|
||||
return true;
|
||||
if (result != null){
|
||||
if (result.get("complete") != null) {
|
||||
String api = (String) ((JSONObject) result.get("data")).get("api");
|
||||
account = new Account(user, pass, api);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
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 String getLibraryName() {
|
||||
return "Naga";
|
||||
}
|
||||
|
||||
public static boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
}
|
||||
@@ -15,70 +15,71 @@ import java.awt.event.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* The bot user interface
|
||||
*
|
||||
*
|
||||
* @author Dane, Everel, Paradox
|
||||
*
|
||||
*/
|
||||
public class BotUI extends JFrame implements ActionListener, ComponentListener, WindowListener {
|
||||
|
||||
private static final long serialVersionUID = -2126184292879805519L;
|
||||
private static BotUI instance;
|
||||
private static JDialog dialog;
|
||||
|
||||
private JMenuItem run, pause, stop;
|
||||
private boolean runScript, pauseScript;
|
||||
private static final long serialVersionUID = -2126184292879805519L;
|
||||
private static BotUI instance;
|
||||
private static JDialog dialog;
|
||||
|
||||
public BotUI(String username, String password) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("BotUI already created");
|
||||
}
|
||||
instance = this;
|
||||
//WebLookAndFeel.install();
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
private JMenuItem run, pause, stop;
|
||||
private boolean runScript, pauseScript;
|
||||
|
||||
setTitle("Parabot");
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
createMenu();
|
||||
public BotUI(String username, String password) {
|
||||
if (instance != null) {
|
||||
throw new IllegalStateException("BotUI already created");
|
||||
}
|
||||
instance = this;
|
||||
//WebLookAndFeel.install();
|
||||
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
addComponentListener(this);
|
||||
addWindowListener(this);
|
||||
setTitle("Parabot");
|
||||
setResizable(false);
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
createMenu();
|
||||
|
||||
add(GamePanel.getInstance());
|
||||
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
||||
add(Logger.getInstance(), BorderLayout.SOUTH);
|
||||
setLayout(new BorderLayout());
|
||||
addComponentListener(this);
|
||||
addWindowListener(this);
|
||||
|
||||
SwingUtil.setParabotIcons(this);
|
||||
add(GamePanel.getInstance());
|
||||
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
||||
add(Logger.getInstance(), BorderLayout.SOUTH);
|
||||
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
BotDialog.getInstance(this);
|
||||
SwingUtil.setParabotIcons(this);
|
||||
|
||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||
BotDialog.getInstance().setVisible(false);
|
||||
}
|
||||
}
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
BotDialog.getInstance(this);
|
||||
|
||||
public static BotUI getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void createMenu() {
|
||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||
BotDialog.getInstance().setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static BotUI getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void createMenu() {
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
JMenu file = new JMenu("File");
|
||||
JMenu scripts = new JMenu("Script");
|
||||
|
||||
JMenuItem screenshot = new JMenuItem("Create screenshot");
|
||||
JMenuItem proxy = new JMenuItem("Network");
|
||||
JMenuItem randoms = new JMenuItem("Randoms");
|
||||
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
||||
JMenuItem randoms = new JMenuItem("Randoms");
|
||||
JMenuItem dialog = new JCheckBoxMenuItem("Disable dialog");
|
||||
|
||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||
dialog.setSelected(true);
|
||||
}
|
||||
JMenuItem api = new JMenuItem("Set API key");
|
||||
|
||||
if (!OperatingSystem.getOS().equals(OperatingSystem.WINDOWS)) {
|
||||
dialog.setSelected(true);
|
||||
}
|
||||
|
||||
JMenuItem explorer = new JMenuItem("Reflection explorer");
|
||||
JMenuItem exit = new JMenuItem("Exit");
|
||||
@@ -94,166 +95,176 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
||||
stop.setEnabled(false);
|
||||
stop.setIcon(new ImageIcon(Images.getResource("/org/parabot/core/ui/images/stop.png")));
|
||||
|
||||
screenshot.addActionListener(this);
|
||||
proxy.addActionListener(this);
|
||||
randoms.addActionListener(this);
|
||||
dialog.addActionListener(this);
|
||||
randoms.addActionListener(this);
|
||||
dialog.addActionListener(this);
|
||||
explorer.addActionListener(this);
|
||||
exit.addActionListener(this);
|
||||
|
||||
run.addActionListener(this);
|
||||
pause.addActionListener(this);
|
||||
stop.addActionListener(this);
|
||||
api.addActionListener(this);
|
||||
|
||||
file.add(screenshot);
|
||||
file.add(proxy);
|
||||
file.add(randoms);
|
||||
file.add(dialog);
|
||||
file.add(randoms);
|
||||
file.add(dialog);
|
||||
file.add(explorer);
|
||||
file.add(exit);
|
||||
|
||||
scripts.add(run);
|
||||
scripts.add(pause);
|
||||
scripts.add(stop);
|
||||
|
||||
menuBar.add(file);
|
||||
menuBar.add(scripts);
|
||||
file.add(exit);
|
||||
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
scripts.add(run);
|
||||
scripts.add(pause);
|
||||
scripts.add(stop);
|
||||
scripts.add(api);
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
menuBar.add(file);
|
||||
menuBar.add(scripts);
|
||||
|
||||
switch (command) {
|
||||
case "Exit":
|
||||
System.exit(0);
|
||||
break;
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String command = e.getActionCommand();
|
||||
|
||||
switch (command) {
|
||||
case "Set API key":
|
||||
String api = JOptionPane.showInputDialog(this, "You can gather your API key from http://bdn.parabot.org/account/");
|
||||
break;
|
||||
case "Create screenshot":
|
||||
JOptionPane.showMessageDialog(this, "We are still working on this...");
|
||||
break;
|
||||
case "Exit":
|
||||
System.exit(0);
|
||||
break;
|
||||
case "Network":
|
||||
NetworkUI.getInstance().setVisible(true);
|
||||
break;
|
||||
case "Randoms":
|
||||
ArrayList<String> randoms = new ArrayList<>();
|
||||
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
||||
randoms.add(r.getName());
|
||||
}
|
||||
RandomUI.getInstance().openFrame(randoms);
|
||||
break;
|
||||
case "Reflection explorer":
|
||||
new ReflectUI().setVisible(true);
|
||||
break;
|
||||
case "Randoms":
|
||||
ArrayList<String> randoms = new ArrayList<>();
|
||||
for (Random r : Context.getInstance().getRandomHandler().getRandoms()) {
|
||||
randoms.add(r.getName());
|
||||
}
|
||||
RandomUI.getInstance().openFrame(randoms);
|
||||
break;
|
||||
case "Reflection explorer":
|
||||
new ReflectUI().setVisible(true);
|
||||
break;
|
||||
case "Run":
|
||||
if(pauseScript) {
|
||||
pauseScript = false;
|
||||
pause.setEnabled(true);
|
||||
run.setEnabled(false);
|
||||
setScriptState(Script.STATE_RUNNING);
|
||||
break;
|
||||
}
|
||||
new ScriptSelector().setVisible(true);
|
||||
break;
|
||||
if (pauseScript) {
|
||||
pauseScript = false;
|
||||
pause.setEnabled(true);
|
||||
run.setEnabled(false);
|
||||
setScriptState(Script.STATE_RUNNING);
|
||||
break;
|
||||
}
|
||||
new ScriptSelector().setVisible(true);
|
||||
break;
|
||||
case "Pause":
|
||||
setScriptState(Script.STATE_PAUSE);
|
||||
pause.setEnabled(false);
|
||||
run.setEnabled(true);
|
||||
pauseScript = true;
|
||||
break;
|
||||
setScriptState(Script.STATE_PAUSE);
|
||||
pause.setEnabled(false);
|
||||
run.setEnabled(true);
|
||||
pauseScript = true;
|
||||
break;
|
||||
case "Stop":
|
||||
setScriptState(Script.STATE_STOPPED);
|
||||
break;
|
||||
setScriptState(Script.STATE_STOPPED);
|
||||
break;
|
||||
case "Disable dialog":
|
||||
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid command: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setDialog(JDialog dialog) {
|
||||
BotUI.dialog = dialog;
|
||||
}
|
||||
BotDialog.getInstance().setVisible(!dialog.isVisible());
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid command: " + command);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
if(dialog == null || !isVisible()) {
|
||||
return;
|
||||
}
|
||||
Point gameLocation = GamePanel.getInstance().getLocationOnScreen();
|
||||
dialog.setLocation(gameLocation.x, gameLocation.y);
|
||||
}
|
||||
|
||||
public void toggleRun() {
|
||||
runScript = !runScript;
|
||||
if(runScript) {
|
||||
scriptRunning();
|
||||
} else {
|
||||
scriptStopped();
|
||||
}
|
||||
}
|
||||
|
||||
private void scriptRunning() {
|
||||
run.setEnabled(false);
|
||||
pause.setEnabled(true);
|
||||
stop.setEnabled(true);
|
||||
}
|
||||
|
||||
private void scriptStopped() {
|
||||
run.setEnabled(true);
|
||||
pause.setEnabled(false);
|
||||
stop.setEnabled(false);
|
||||
}
|
||||
|
||||
private void setScriptState(int state) {
|
||||
if (Context.getInstance().getRunningScript() != null) {
|
||||
Context.getInstance().getRunningScript().setState(state);
|
||||
}
|
||||
}
|
||||
protected void setDialog(JDialog dialog) {
|
||||
BotUI.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if(isVisible()) {
|
||||
BotDialog.getInstance().setSize(getSize());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
if (dialog == null || !isVisible()) {
|
||||
return;
|
||||
}
|
||||
Point gameLocation = GamePanel.getInstance().getLocationOnScreen();
|
||||
dialog.setLocation(gameLocation.x, gameLocation.y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
}
|
||||
public void toggleRun() {
|
||||
runScript = !runScript;
|
||||
if (runScript) {
|
||||
scriptRunning();
|
||||
} else {
|
||||
scriptStopped();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
private void scriptRunning() {
|
||||
run.setEnabled(false);
|
||||
pause.setEnabled(true);
|
||||
stop.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(WindowEvent arg0) {
|
||||
}
|
||||
private void scriptStopped() {
|
||||
run.setEnabled(true);
|
||||
pause.setEnabled(false);
|
||||
stop.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(WindowEvent arg0) {
|
||||
}
|
||||
private void setScriptState(int state) {
|
||||
if (Context.getInstance().getRunningScript() != null) {
|
||||
Context.getInstance().getRunningScript().setState(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
if (isVisible()) {
|
||||
BotDialog.getInstance().setSize(getSize());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent arg0) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public void componentShown(ComponentEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent arg0) {
|
||||
if(isVisible()) {
|
||||
BotDialog.getInstance().setVisible(false);
|
||||
BotDialog.getInstance().setVisible(true);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent arg0) {
|
||||
@Override
|
||||
public void windowActivated(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void windowClosed(WindowEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent arg0) {
|
||||
}
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(WindowEvent arg0) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeiconified(WindowEvent arg0) {
|
||||
if (isVisible()) {
|
||||
BotDialog.getInstance().setVisible(false);
|
||||
BotDialog.getInstance().setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowIconified(WindowEvent arg0) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(WindowEvent arg0) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.parabot.core.ui;
|
||||
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.ui.components.GamePanel;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -46,5 +47,9 @@ public class Logger extends JPanel {
|
||||
|
||||
public static void addMessage(String message){
|
||||
instance.model.addElement(message);
|
||||
|
||||
if (Context.getInstance().getUlirathaClient() != null) {
|
||||
Context.getInstance().getUlirathaClient().sendMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LoginUI extends JFrame {
|
||||
} else {
|
||||
Core.verbose("Failed to log in.");
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Incorrect username or password.", "Error",
|
||||
"Incorrect username or password. Have you tried logging into http://bdn.parabot.org/account/", "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -29,6 +30,7 @@ public class Environment {
|
||||
|
||||
LinkedList<Library> libs = new LinkedList<>();
|
||||
libs.add(new JavaFX());
|
||||
libs.add(new Naga());
|
||||
|
||||
for(Library lib : libs) {
|
||||
if(!lib.hasJar()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.parabot.environment.api.utils;
|
||||
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.parabot.core.io.ProgressListener;
|
||||
import org.parabot.core.io.SizeInputStream;
|
||||
|
||||
@@ -17,6 +18,9 @@ import java.net.URLEncoder;
|
||||
*
|
||||
*/
|
||||
public class WebUtil {
|
||||
|
||||
private static JSONParser jsonParser;
|
||||
|
||||
private static String agent = "Mozilla/5.0 (Wind0ws NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1";
|
||||
|
||||
/**
|
||||
@@ -267,4 +271,10 @@ public class WebUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONParser getJsonParser() {
|
||||
if (jsonParser == null){
|
||||
jsonParser = new JSONParser();
|
||||
}
|
||||
return jsonParser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.parabot.environment.scripts;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.Core;
|
||||
import org.parabot.core.ui.BotUI;
|
||||
import org.parabot.core.ui.Logger;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.scripts.framework.*;
|
||||
import org.parabot.environment.scripts.framework.Frameworks;
|
||||
@@ -66,14 +67,6 @@ public class Script implements Runnable {
|
||||
public final void run() {
|
||||
Context context = Context.getInstance();
|
||||
|
||||
// Core.verbose("Initializing security manager...");
|
||||
// String previousPolicy = System.getProperty("java.security.policy");
|
||||
// SecurityManager previousSecurityManager = System.getSecurityManager();
|
||||
|
||||
// System.setProperty("java.security.policy", Directories.getSettingsPath() + "/java.policy");
|
||||
// SecurityManagerDemo sm = new SecurityManagerDemo();
|
||||
// System.setSecurityManager(sm);
|
||||
|
||||
Core.verbose("Initializing script...");
|
||||
context.getServerProvider().initScript(this);
|
||||
Core.verbose("Done.");
|
||||
@@ -102,7 +95,7 @@ public class Script implements Runnable {
|
||||
frameWorkType = TYPE_OTHER;
|
||||
}
|
||||
Core.verbose("Running script...");
|
||||
System.out.println("Script started.");
|
||||
Logger.addMessage("Script started.");
|
||||
try {
|
||||
while(this.state != STATE_STOPPED) {
|
||||
if(context.getRandomHandler().checkAndRun()) {
|
||||
@@ -122,13 +115,17 @@ public class Script implements Runnable {
|
||||
}
|
||||
Core.verbose("Script stopped/finished, unloading and stopping...");
|
||||
onFinish();
|
||||
System.out.println("Script stopped.");
|
||||
Logger.addMessage("Script stopped.");
|
||||
context.getServerProvider().unloadScript(this);
|
||||
this.state = STATE_STOPPED;
|
||||
context.setRunningScript(null);
|
||||
|
||||
if (context.getUlirathaClient() != null) {
|
||||
context.getUlirathaClient().disconnect();
|
||||
context.setUlirathaClient(null);
|
||||
}
|
||||
|
||||
BotUI.getInstance().toggleRun();
|
||||
// System.setProperty("java.security.policy", previousPolicy);
|
||||
// System.setSecurityManager(previousSecurityManager);
|
||||
Core.verbose("Done.");
|
||||
}
|
||||
|
||||
@@ -167,4 +164,7 @@ public class Script implements Runnable {
|
||||
Time.sleep(ms);
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ 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;
|
||||
@@ -35,7 +36,7 @@ public class BDNScriptsExecuter extends ScriptExecuter {
|
||||
};
|
||||
|
||||
private int id = -1;
|
||||
|
||||
|
||||
public BDNScriptsExecuter(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
@@ -47,51 +48,52 @@ public class BDNScriptsExecuter extends ScriptExecuter {
|
||||
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
|
||||
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 ////////
|
||||
|
||||
|
||||
// succesfull request, jar returned
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(urlConnection);
|
||||
|
||||
final JavaScriptLoader loader = new JavaScriptLoader(classPath);
|
||||
final String[] scriptClasses = loader.getScriptClassNames();
|
||||
if(scriptClasses == null || scriptClasses.length == 0) {
|
||||
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 BDN script, error: [Multiple scripts found in jar file.]");
|
||||
return;
|
||||
}
|
||||
|
||||
final String className = scriptClasses[0];
|
||||
try {
|
||||
final Class<?> scriptClass = loader.loadClass(className);
|
||||
final Constructor<?> con = scriptClass.getConstructor();
|
||||
final Script script = (Script) con.newInstance();
|
||||
super.finalize(tg, script);
|
||||
} 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 BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
//// END JAR LOADING ////
|
||||
|
||||
} else {
|
||||
UILog.log("Error", "Failed to load BDN script, error: [Unknown content type: " + contentType + "]", JOptionPane.ERROR_MESSAGE);
|
||||
switch (contentType) {
|
||||
case "text/html":
|
||||
// failed to fetch script
|
||||
UILog.log("Error", "Failed to load BDN script, error: [Page returned: " + WebUtil.getContents(urlConnection) + "]", JOptionPane.ERROR_MESSAGE);
|
||||
break;
|
||||
case "application/jar":
|
||||
//// JAR LOADING PART ////////
|
||||
// succesfull request, jar returned
|
||||
final ClassPath classPath = new ClassPath();
|
||||
classPath.addJar(urlConnection);
|
||||
|
||||
final JavaScriptLoader loader = new JavaScriptLoader(classPath);
|
||||
final String[] scriptClasses = loader.getScriptClassNames();
|
||||
if (scriptClasses == null || scriptClasses.length == 0) {
|
||||
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 BDN script, error: [Multiple scripts found in jar file.]");
|
||||
return;
|
||||
}
|
||||
|
||||
final String className = scriptClasses[0];
|
||||
try {
|
||||
final Class<?> scriptClass = loader.loadClass(className);
|
||||
final Constructor<?> con = scriptClass.getConstructor();
|
||||
final Script script = (Script) con.newInstance();
|
||||
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) {
|
||||
t.printStackTrace();
|
||||
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
//// END JAR LOADING ////
|
||||
break;
|
||||
default:
|
||||
UILog.log("Error", "Failed to load BDN script, error: [Unknown content type: " + contentType + "]", JOptionPane.ERROR_MESSAGE);
|
||||
break;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
UILog.log("Error", "Failed to load BDN script, post the stacktrace/error on the parabot forums.", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package org.parabot.environment.scripts.executers;
|
||||
|
||||
public class SecurityManagerDemo extends SecurityManager {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
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 {
|
||||
System.out.println("Connecting....");
|
||||
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!");
|
||||
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) {
|
||||
reconnect();
|
||||
connected = 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package org.parabot.environment.servers.executers;
|
||||
import org.parabot.core.Context;
|
||||
import org.parabot.core.parsers.randoms.RandomParser;
|
||||
import org.parabot.core.ui.components.PaintComponent;
|
||||
import org.parabot.environment.scripts.executers.SecurityManagerDemo;
|
||||
import org.parabot.environment.servers.ServerProvider;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user