Initial import of client

This commit is contained in:
Adam
2016-04-02 14:27:26 -04:00
commit 2b893c9309
9 changed files with 393 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target/

51
pom.xml Normal file
View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.runelite.rs</groupId>
<artifactId>client</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>runelite</id>
<url>sftp://192.168.1.2/var/www/rs/repo</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>net.runelite.rs</groupId>
<artifactId>api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.runelite</groupId>
<artifactId>launcher</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
</build>
</project>

View File

@@ -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<String, String> 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<String, String> getProperties()
{
return properties;
}
public String getAppletProperty(String name)
{
return appletProperties.get(name);
}
public Map<String, String> getAppletProperties()
{
return appletProperties;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}
}

View File

@@ -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));
}
}