From 2b893c930931a344815d5d5a7b011af4e6a2927e Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 2 Apr 2016 14:27:26 -0400 Subject: [PATCH] Initial import of client --- .gitignore | 1 + pom.xml | 51 ++++++++++ .../net/runelite/client/ConfigLoader.java | 93 +++++++++++++++++++ .../java/net/runelite/client/Launcher.java | 22 +++++ src/main/java/net/runelite/client/RSStub.java | 67 +++++++++++++ .../java/net/runelite/client/RuneLite.java | 20 ++++ .../net/runelite/client/ui/ClientPanel.java | 47 ++++++++++ .../java/net/runelite/client/ui/ClientUI.java | 65 +++++++++++++ .../net/runelite/client/ConfigLoaderTest.java | 27 ++++++ 9 files changed, 393 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/net/runelite/client/ConfigLoader.java create mode 100644 src/main/java/net/runelite/client/Launcher.java create mode 100644 src/main/java/net/runelite/client/RSStub.java create mode 100644 src/main/java/net/runelite/client/RuneLite.java create mode 100644 src/main/java/net/runelite/client/ui/ClientPanel.java create mode 100644 src/main/java/net/runelite/client/ui/ClientUI.java create mode 100644 src/test/java/net/runelite/client/ConfigLoaderTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..a6f89c2da7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000000..4be61dba3e --- /dev/null +++ b/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + net.runelite.rs + client + 1.0-SNAPSHOT + + + UTF-8 + 1.8 + 1.8 + + + + + runelite + sftp://192.168.1.2/var/www/rs/repo + + + + + + net.runelite.rs + api + 1.0-SNAPSHOT + + + net.runelite + launcher + 1.0.0-SNAPSHOT + + + + junit + junit + 4.12 + test + + + + + + + org.apache.maven.wagon + wagon-ssh + 2.10 + + + + \ No newline at end of file diff --git a/src/main/java/net/runelite/client/ConfigLoader.java b/src/main/java/net/runelite/client/ConfigLoader.java new file mode 100644 index 0000000000..9af73b845a --- /dev/null +++ b/src/main/java/net/runelite/client/ConfigLoader.java @@ -0,0 +1,93 @@ +package net.runelite.client; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +public class ConfigLoader +{ + private static URL configURL; + + public static final String CODEBASE = "codebase"; + public static final String INITIAL_JAR = "initial_jar"; + public static final String INITIAL_CLASS = "initial_class"; + public static final String APP_MINWIDTH = "applet_minwidth"; + public static final String APP_MINHEIGHT = "applet_minheight"; + + private final Map properties = new HashMap<>(), + appletProperties = new HashMap<>(); + + static + { + try + { + configURL = new URL("http://192.168.1.2/rs/jav_config.ws"); + //configURL = new URL("http://oldschool1.runescape.com/jav_config.ws"); // https redirects us to rs3 + } + catch (MalformedURLException ex) + { + ex.printStackTrace(); + } + } + + public void fetch() throws IOException + { + URLConnection conn = configURL.openConnection(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) + { + String str; + + while ((str = in.readLine()) != null) + { + int idx = str.indexOf('='); + + if (idx == -1) + continue; + + String s = str.substring(0, idx); + + if (s.equals("param")) + { + str = str.substring(idx + 1); + idx = str.indexOf('='); + s = str.substring(0, idx); + + appletProperties.put(s, str.substring(idx + 1)); + } + else if (s.equals("msg")) + { + // ignore + } + else + { + properties.put(s, str.substring(idx + 1)); + } + } + } + } + + public String getProperty(String name) + { + return properties.get(name); + } + + public Map getProperties() + { + return properties; + } + + public String getAppletProperty(String name) + { + return appletProperties.get(name); + } + + public Map getAppletProperties() + { + return appletProperties; + } +} diff --git a/src/main/java/net/runelite/client/Launcher.java b/src/main/java/net/runelite/client/Launcher.java new file mode 100644 index 0000000000..718073d454 --- /dev/null +++ b/src/main/java/net/runelite/client/Launcher.java @@ -0,0 +1,22 @@ +package net.runelite.client; + +import java.util.logging.Level; +import java.util.logging.Logger; +import net.runelite.launcher.Launchable; + +public class Launcher implements Launchable +{ + @Override + public void run() + { + try + { + new RuneLite().start(); + } + catch (Exception ex) + { + Logger.getLogger(Launcher.class.getName()).log(Level.SEVERE, null, ex); + } + } + +} diff --git a/src/main/java/net/runelite/client/RSStub.java b/src/main/java/net/runelite/client/RSStub.java new file mode 100644 index 0000000000..1c7966e31a --- /dev/null +++ b/src/main/java/net/runelite/client/RSStub.java @@ -0,0 +1,67 @@ +package net.runelite.client; + +import java.applet.Applet; +import java.applet.AppletContext; +import java.applet.AppletStub; +import java.awt.Dimension; +import java.net.MalformedURLException; +import java.net.URL; + +public class RSStub implements AppletStub +{ + private final ConfigLoader config; + private final Applet app; + + public RSStub(ConfigLoader config, Applet app) + { + this.config = config; + this.app = app; + } + + @Override + public boolean isActive() + { + return true; + } + + @Override + public URL getDocumentBase() + { + return getCodeBase(); + } + + @Override + public URL getCodeBase() + { + try + { + return new URL(config.getProperty(ConfigLoader.CODEBASE)); + } + catch (MalformedURLException ex) + { + return null; + } + } + + @Override + public String getParameter(String name) + { + return config.getAppletProperty(name); + } + + @Override + public AppletContext getAppletContext() + { + return null; + } + + @Override + public void appletResize(int width, int height) + { + Dimension d = new Dimension(width, height); + + app.setSize(d); + app.setPreferredSize(d); + } + +} diff --git a/src/main/java/net/runelite/client/RuneLite.java b/src/main/java/net/runelite/client/RuneLite.java new file mode 100644 index 0000000000..ec16437acb --- /dev/null +++ b/src/main/java/net/runelite/client/RuneLite.java @@ -0,0 +1,20 @@ +package net.runelite.client; + +import net.runelite.client.ui.ClientUI; + + +public class RuneLite +{ + private ClientUI gui; + + public static void main(String[] args) throws Exception + { + new RuneLite().start(); + } + + public void start() throws Exception + { + gui = new ClientUI(); + gui.setVisible(true); + } +} diff --git a/src/main/java/net/runelite/client/ui/ClientPanel.java b/src/main/java/net/runelite/client/ui/ClientPanel.java new file mode 100644 index 0000000000..8cf5f4bd56 --- /dev/null +++ b/src/main/java/net/runelite/client/ui/ClientPanel.java @@ -0,0 +1,47 @@ +package net.runelite.client.ui; + +import java.applet.Applet; +import java.awt.Color; +import java.awt.Dimension; +import java.net.URL; +import java.net.URLClassLoader; +import javax.swing.JPanel; +import net.runelite.client.ConfigLoader; +import net.runelite.client.RSStub; + +final class ClientPanel extends JPanel +{ + + public ClientPanel() throws Exception + { + setSize(new Dimension(ClientUI.PANEL_WIDTH, ClientUI.PANEL_HEIGHT)); + setMinimumSize(new Dimension(ClientUI.PANEL_WIDTH, ClientUI.PANEL_HEIGHT)); + setPreferredSize(new Dimension(ClientUI.PANEL_WIDTH, ClientUI.PANEL_HEIGHT)); + setBackground(Color.black); + + Applet rs = dl(); + rs.setSize(this.getSize()); + rs.init(); + rs.start(); + this.add(rs); + } + + private Applet dl() throws Exception + { + ConfigLoader config = new ConfigLoader(); + + config.fetch(); + + //URL clientUrl = new URL(config.getProperty(ConfigLoader.CODEBASE) + config.getProperty(ConfigLoader.INITIAL_JAR)); + URL clientUrl = new URL("http://192.168.1.2/rs/" + config.getProperty(ConfigLoader.INITIAL_JAR)); + String initialClass = config.getProperty(ConfigLoader.INITIAL_CLASS).replace(".class", ""); + + URLClassLoader loader = new URLClassLoader(new URL[]{ clientUrl }); + Class clientClass = loader.loadClass(initialClass); + + Applet rs = (Applet) clientClass.newInstance(); + + rs.setStub(new RSStub(config, rs)); + return rs; + } +} \ No newline at end of file diff --git a/src/main/java/net/runelite/client/ui/ClientUI.java b/src/main/java/net/runelite/client/ui/ClientUI.java new file mode 100644 index 0000000000..4320f05825 --- /dev/null +++ b/src/main/java/net/runelite/client/ui/ClientUI.java @@ -0,0 +1,65 @@ +package net.runelite.client.ui; + +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.logging.Logger; +import javax.swing.JFrame; +import javax.swing.JOptionPane; +import javax.swing.JPopupMenu; +import javax.swing.JScrollPane; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +public final class ClientUI extends JFrame +{ + public static final int PANEL_WIDTH = 765, PANEL_HEIGHT = 503, LOG_HEIGHT = 120; + + private static final Logger log = Logger.getLogger(ClientUI.class.getName()); + + private ClientPanel panel; + + public ClientUI() throws Exception + { + init(); + pack(); + setTitle("RuneLite"); + setLocationRelativeTo(getOwner()); + setMinimumSize(getSize()); + setResizable(true); + } + + private void init() throws Exception { + setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); + + addWindowListener(new WindowAdapter() + { + @Override + public void windowClosing(WindowEvent e) + { + checkExit(); + } + }); + + JPopupMenu.setDefaultLightWeightPopupEnabled(false); + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ignored) + { + } + + panel = new ClientPanel(); + add(panel); + } + + private void checkExit() + { + int result = JOptionPane.showConfirmDialog(this, "Are you sure you want to exit?", "Exit", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); + + if (result == JOptionPane.OK_OPTION) + { + System.exit(0); + } + } +} \ No newline at end of file diff --git a/src/test/java/net/runelite/client/ConfigLoaderTest.java b/src/test/java/net/runelite/client/ConfigLoaderTest.java new file mode 100644 index 0000000000..ba34ce18b4 --- /dev/null +++ b/src/test/java/net/runelite/client/ConfigLoaderTest.java @@ -0,0 +1,27 @@ +package net.runelite.client; + +import java.io.IOException; +import org.junit.Test; + +/** + * + * @author Adam + */ +public class ConfigLoaderTest +{ + @Test + public void test() throws IOException + { + ConfigLoader loader = new ConfigLoader(); + loader.fetch(); + + for (String key : loader.getProperties().keySet()) + System.out.println(key + ": " + loader.getProperty(key)); + + System.out.println("Applet properties:"); + + for (String key : loader.getAppletProperties().keySet()) + System.out.println(key + ": " + loader.getAppletProperty(key)); + } + +}