Thread: Any Version Website (Game Launcher) + Client Loader

Results 1 to 10 of 10
  1. #1 Any Version Website (Game Launcher) + Client Loader 
    Registered Member
    Join Date
    Dec 2013
    Posts
    419
    Thanks given
    127
    Thanks received
    85
    Rep Power
    349
    Hi, this is just a crappy tool I made to load a fully working HTML5 website in Java and have a "play" button on that website that will load the .jar client in another window.
    I think the code is very poorly written however it should be fully functioning.

    Just take into consideration I'm not the best coder and I know you experts will flame me for it! KThxbye

    Please please note: You need JavaFX to compile. JavaFX is including with the default JRE (I was using JRE8) however it may not be included in JDK.

    The code is in this spoiler tag.
    [spoil]
    Code:
    package com.swagger;
    
    import com.swagger.html.Browser;
    
    public class Main {
    
    	public static void main(String[] args) {
    		Browser b = new Browser();
    		b.loadURL("http://mywebsite.com/game-launcher/");
    	}
    
    }
    Code:
    package com.swagger.client;
    
    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.net.URL;
    import java.net.URLClassLoader;
    
    import javax.swing.JFrame;
    
    public final class ClientLoader {
    	public static void loadClient(String address) throws Exception {
    		URL url = new URL(address);
    		WebCrawler crawler = new WebCrawler(url);
    		ClientStub stub = new ClientStub(url, crawler);
    		crawler.start();
    		
    		URLClassLoader loader = new URLClassLoader(new URL[] { new URL(address + crawler.getProperty("archive-name")) });
    		
    		Class<?> appletClass = loader.loadClass(crawler.getProperty("main-class"));
    		Applet applet = Applet.class.cast(appletClass.getConstructor().newInstance());
    		applet.setStub(stub);
            applet.setPreferredSize(new Dimension(765, 503));
            
            JFrame frame = new JFrame("RuneScape");
            frame.setLayout(new BorderLayout());
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new BorderLayout());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(applet, BorderLayout.NORTH);
            frame.getContentPane().setBackground(Color.BLACK);
            frame.setResizable(false);
            frame.setVisible(true);
            frame.pack();
            frame.setLocationRelativeTo(null);
            
            applet.init();
            applet.start();
    	}
    }
    Code:
    package com.swagger.client;
    
    import java.applet.AppletContext;
    import java.applet.AppletStub;
    import java.net.URL;
    
    public final class ClientStub implements AppletStub {
    	private final URL url;
    	private final WebCrawler crawler;
    
    	public ClientStub(URL url, WebCrawler crawler) {
    		this.url = url;
    		this.crawler = crawler;
    	}
    
    	@Override
    	public boolean isActive() {
    		return true;
    	}
    
    	@Override
    	public URL getDocumentBase() {
    		return url;
    	}
    
    	@Override
    	public URL getCodeBase() {
    		return url;
    	}
    
    	@Override
    	public String getParameter(String name) {
    		return crawler.getProperty(name);
    	}
    
    	@Override
    	public AppletContext getAppletContext() {
    		throw new RuntimeException("called getAppletContext()");
    	}
    
    	@Override
    	public void appletResize(int width, int height) {
    
    	}
    }
    Code:
    package com.swagger.client;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public final class WebCrawler {
    	private static final Pattern ARCHIVE_PATTERN = Pattern.compile("archive=(.*)\\s+");
    	private static final Pattern PARAMETER_PATTERN = Pattern.compile("<param name=([^\\s]+)\\s+value=([^>]*)>");
    	private final Map<String, String> properties = new HashMap<>();
    	private final URL url;
    
    	public WebCrawler(URL url) {
    		this.url = url;
    	}
    
    	public String getProperty(String key) {
    		return properties.get(key);
    	}
    
    	public void start() throws IOException {
    		readWebContents(url);
    	}
    
    	private void readWebContents(URL url) throws IOException {
    		HttpURLConnection connection = HttpURLConnection.class.cast(url.openConnection());
    		StringBuilder contents = new StringBuilder();
    		try (BufferedReader stream = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
    			String read;
    			while ((read = stream.readLine()) != null) {
    				contents.append(read);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			parseWebContents(contents.toString());
    		}
    	}
    
    	private void parseWebContents(String contents) {
    		Matcher matcher = PARAMETER_PATTERN.matcher(contents);
    		while (matcher.find()) {
    			String[] tokens = cleanHtml(matcher.group()).split(" ");
    			String key = tokens[0].split("=")[1];
    			String value = join(tokens[1].split("="), 1);
    			properties.put(key, value);
    		}
    		
    		matcher = ARCHIVE_PATTERN.matcher(contents);
    		if (matcher.find()) {
    			String[] tokens = matcher.group().split(" ");
    			properties.put("archive-name", tokens[0].split("=")[1].replaceAll("\"", ""));
    			properties.put("main-class", tokens[1].split("=")[1].replaceAll("\"", "").replaceAll(".class", ""));
    		}
    	}
    	
    	private static String cleanHtml(String string) {
    		string = string.replaceAll("\"", "");
    		string = string.replaceAll("<param ", "");
    		string = string.substring(0, string.length() - 1);
    		return string;
    	}
    
    	private static String join(String[] strings, int offset) {
    		StringBuffer sb = new StringBuffer();
    		for (int i = offset; i < strings.length; ++i) {
    			sb.append(strings[i]);
    		}
    		return sb.toString();
    	}
    }
    Code:
    package com.swagger.html;
    
    import java.net.MalformedURLException;
    import java.net.URL;
    
    import com.swagger.client.ClientLoader;
    
    import javafx.application.Platform;
    
    public final class Browser implements Runnable {
    	private final Display display;
    	private Thread t;
    	private boolean running;
    
    	public Browser() {
    		display = new Display();
    		start();
    	}
    	
    	@Override
    	public void run() {
    		while (running) {
    			if (display != null && display.getWebEngine() != null) {
    				if (display.getWebEngine().getLocation().contains("client")) {
    						try {
    							ClientLoader.loadClient(display.getWebEngine().getLocation());
    						} catch (Exception e) {
    							e.printStackTrace();
    							//TODO: Give the user some sort of error message
    							//JDialogeBox thingy?
    						}
    						display.getFrame().setVisible(false);
    						display.getFrame().dispose();
    						stop();
    					}
    				} 
    			}
    			
    			try {
    				Thread.sleep(1000);
    			} catch (InterruptedException e) {
    				/* Ignore */
    			}
    	}
    	
    	private void start() {
    		if (t == null) {
    			running = true;
    			t = new Thread(this);
    			t.start();
    		}
    	}
    	
    	private void stop() {
    		if (t != null) {
    			running = false;
    			try {
    				t.join();
    			} catch (InterruptedException e) {
    				/* Ignore */
    			}
    			t = null;
    		}
    	}
    	
    	public void loadURL(String url) {
    		Platform.runLater(() -> {
    			String tmp = toURL(url);
    			if (tmp == null) {
    				tmp = toURL("http://" + url);
    			}
    			display.getWebEngine().load(tmp);
    		});
    	}
    
    	private static String toURL(String str) {
    		try {
    			return new URL(str).toExternalForm();
    		} catch (MalformedURLException exception) {
    			return null;
    		}
    	}
    }
    Code:
    package com.swagger.html;
    
    import java.awt.Dimension;
    
    import javax.swing.JFrame;
    
    import javafx.application.Platform;
    import javafx.embed.swing.JFXPanel;
    import javafx.scene.Scene;
    import javafx.scene.web.WebEngine;
    import javafx.scene.web.WebView;
    
    public class Display {
    	private final JFrame frame;
    	private final JFXPanel jfxPanel;
    	private WebEngine engine;
    
    	public Display() {
    		frame = new JFrame();
    		jfxPanel = new JFXPanel();
    		init();
    	}
    
    	private void init() {
    		createScene();
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setPreferredSize(new Dimension(1024, 600));
    		frame.setLocationRelativeTo(null);
    		frame.getContentPane().add(jfxPanel);
    		frame.pack();
    		frame.setVisible(true);
    	}
    
    	private void createScene() {
    		Platform.runLater(() -> {
    			WebView view = new WebView();
    			engine = view.getEngine();
    			jfxPanel.setScene(new Scene(view));
    		});
    	}
    	
    	public JFrame getFrame() {
    		return frame;
    	}
    	
    	public WebEngine getWebEngine() {
    		return engine;
    	}
    }
    [/spoil]

    Okay once that's added, in Main.java make sure you add the link to the webpage that will act like a "game launcher".

    Lastly you will now need to go old school and make a client folder on your website that has a index.html with the following code and the client.jar
    URL should look like this: http://mydomain.com/client/client.jar

    The index.html should look like this:
    [spoil]
    Code:
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>Webclient</title>
        <style
          applet { }
    
        </style>
      </head>
    
      <body>
        Client is loading please wait...<br>
        <applet archive="loader.jar" code="loader.class" width="765" height="503">
          <!-- These parms tags are not really required depending on client -->
          <param name="worldid" value="1" />
          <param name="members" value="1" />
          <param name="modewhat" value="0" />
          <param name="modewhere" value="0" />
          <param name="safemode" value="0" />
          <param name="game" value="0" />
          <param name="js" value="1" />
          <param name="lang" value="0" />
          <param name="affid" value="0" />
          <param name="lowmem" value="0" />
          <param name="settings" value="kKmok3kJqOeN6D3mDdihco3oPeYN2KFy6W5--vZUbNA" />
        </applet>
      </body>
    
    </html>
    [/spoil]

    Here's an image of the final product:
    In my example I used the rune-server play button as my action to start the client lol (you can edit this action in Browser.java)

    [spoil]
    [/spoil]

    Credits to Imthenull on Moparscape for releasing a OSRS loader ages ago on Moparscape. I ripped his code to run the client. No need to reinvent the wheel
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Member Any Version Website (Game Launcher) + Client Loader Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    gj bro

    Attached imageAttached image
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Coding coding coding...

    Ivo's Avatar
    Join Date
    Mar 2008
    Age
    33
    Posts
    1,425
    Thanks given
    30
    Thanks received
    147
    Rep Power
    2017
    Intresting stuff, ill check it out and see if i can turn it into something useful.
    Reply With Quote  
     

  6. #4  
    Banned

    Join Date
    Jul 2015
    Posts
    607
    Thanks given
    520
    Thanks received
    660
    Rep Power
    0
    Really nice, was looking for something similar a while ago!
    Rep'd
    Reply With Quote  
     

  7. #5  
    Banned
    Join Date
    Dec 2015
    Posts
    75
    Thanks given
    17
    Thanks received
    10
    Rep Power
    0
    Sweet man, gonna see if I can add this
    Reply With Quote  
     

  8. #6  
    Registered Member
    Join Date
    Dec 2013
    Posts
    419
    Thanks given
    127
    Thanks received
    85
    Rep Power
    349
    Didn't except these types of responses
    thx
    Reply With Quote  
     

  9. #7  
    The One And Only

    01053's Avatar
    Join Date
    Apr 2011
    Age
    28
    Posts
    2,887
    Thanks given
    417
    Thanks received
    885
    Rep Power
    856
    Dat package name tho. gj
    Reply With Quote  
     

  10. #8  
    Registered Member
    Optimum's Avatar
    Join Date
    Apr 2012
    Posts
    3,570
    Thanks given
    871
    Thanks received
    1,745
    Rep Power
    5000
    good job

    Quote Originally Posted by DownGrade View Post
    Don't let these no life creeps get to you, its always the same on here. They'd rather spend hours upon hours in the rune-server spam section then getting laid! ha ha!Its honestly pathetic i haven't seen so many lowlifes in my life its actually insane i wish that this section would just vanish its probably the only way to get these people out of the community...
    PLEASE BE AWARE OF IMPOSTERS MY DISCORD ID: 362240000760348683
    Reply With Quote  
     

  11. #9  
    Registered Member
    Vippy's Avatar
    Join Date
    Oct 2014
    Age
    25
    Posts
    2,572
    Thanks given
    984
    Thanks received
    1,933
    Rep Power
    5000
    Interesting I'll check this out when I get home
    Reply With Quote  
     

  12. #10  
    あきらめない
    mexile's Avatar
    Join Date
    Nov 2015
    Posts
    135
    Thanks given
    26
    Thanks received
    21
    Rep Power
    23
    GJ on this!
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Lite Game Launcher [Any Revision]
    By Chaz in forum Snippets
    Replies: 24
    Last Post: 09-27-2013, 10:52 PM
  2. RS 317-377 (or any old engine) client loader
    By Songoty in forum Requests
    Replies: 0
    Last Post: 11-23-2012, 08:42 AM
  3. Replies: 2
    Last Post: 07-04-2011, 07:00 AM
  4. Desktop Client Loader - Version 2
    By Songoty in forum Tutorials
    Replies: 20
    Last Post: 09-03-2010, 02:58 AM
  5. [REQ]Silabsoft client any version
    By NeW0rldL0rd in forum Requests
    Replies: 6
    Last Post: 06-04-2008, 04:45 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •