Thread: URL Management

Results 1 to 5 of 5
  1. #1 URL Management 
    Banned
    Join Date
    Feb 2015
    Age
    18
    Posts
    44
    Thanks given
    32
    Thanks received
    11
    Rep Power
    0
    Don't flame.

    Create a .dat file and upload it to your host and put the url inside the URL string and be sure to add the urls in the file separated as in:

    Code:
    http://www.bestrsps.com/play
    http://www.bestrsps.com/forum
    http://www.bestrsps.com/download
    The use of it is highlighted inside the URLManager class. Make sure to add the correct imports. You might end up with errors so be sure to post them below and someone here or I will give it an attempt to help fix.

    Code:
    import java.util.List;
    
    public final class URLManager {
        
        /**
         * Put your server name here in lowercase.
         */
        public static String SERVER_NAME = "";
        
        /**
         * Put your server url here.
         */
        public static String URL = "http://www.myserver.com/"+"/urllist.dat";
    
        public URLManager() {
            parse(new String[]{ URL });
        }
    
        /**
         * Parses the worlds from the specified url into an array of URL instances.
         *   @Param url
         *   @return
         */
        public void parse(String[] urls) {
            List<String> lines = URLUtils.getLines(urls);
            if (lines != null) {
                this.urls = new String[lines.size()][];
                for (int index = 0; index < this.urls.length; index++) {
                    String[] args = lines.get(index).split(" ");
                    this.urls[index] = args;
                }
            } else {
                System.out.println("An error occurred while creating the URL list.");
            }
        }
    
        /**
         * Finds the url for the specified string.
         *   @Param toFind
         *   @return
         */
        private String[] find(String toFind) {
            if (urls == null) {
                return null;
            }
            for (String[] list : urls) {
                for (String url : list) {
                    if (url.contains(toFind)) {
                        return list;
                    }
                }
            }
            System.out.println("could not find url: " + toFind);
            return null;
        }
             
        /**
         * Returns the url for the world list.
         *   @return
         */
           public String[] getWorldList() {
            return find("world");
        }
    
        /**
         * The URLs.
         */
        private String[][] urls;
    
    }
    Code:
    public final class URLUtils {
    
        /**
         * Retrieves the lines from one of the specified urls.
         *   @Param urls
         *   @return
         */
        public final static List<String> getLines(String[] urls) {
            if (urls == null) {
                return null;
            }
            for (String url : urls) {
                try {
                    byte[] urlData = DataUtilities.getData(new URL(url));
                    if (urlData == null) {
                        System.out.println("The data retrieved from the url '" + url + "' was null.");
                        continue;
                    }
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(urlData)));
                    List<String> lines = new ArrayList<String>();
                    while (true) {
                        String line = bufferedReader.readLine();
                        if (line == null) {
                            break;
                        }
                        if (line.startsWith("//")) {
                            continue;
                        }
                        lines.add(line);
                    }
                    return lines;
                } catch (MalformedURLException e) {
                    System.out.println("The lines were requested from a Malformed URL.");
                    continue;
                } catch (IOException e) {
                    System.out.println("The lines were requested and received incorrectly.");
                    continue;
                }
            }
            return null;
        }
    
    }
    Code:
    public final class DataUtilities {
    
        /**
         * Generates a Jagex hash for the specified string.
         *
         *   @Param string
         *   @return
         */
        public static int getHash(String string) {
            int identifier = 0;
            string = string.toUpperCase();
            for (int index = 0; index < string.length(); index++) {
                identifier = (identifier * 61 + string.charAt(index)) - 32;
            }
            return identifier;
        }
    
        /**
         * Returns the specified string as an MD5 hash.
         *   @Param string
         *   @return
         */
        public static String getMD5(String string) {
            try {
                java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
                byte[] array = md.digest(string.getBytes());
                StringBuffer hash = new StringBuffer();
                for (int i = 0; i < array.length; ++i) {
                    hash.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
                }
                return hash.toString();
            } catch (java.security.NoSuchAlgorithmException e) {
            }
            return null;
        }
    
        /**
         * Returns the file as a byte array.
         *
         *   @Param name
         *   @return
         */
        public static byte[] getData(String name) {
            File file = new File(PathManager.getDirectory() + name);
            if (!file.exists()) {
                System.out.println("file '" + file.getAbsolutePath() + "' doesn't exist");
                return null;
            }
            byte[] data = null;
            try {
                data = new byte[(int) file.length()];
                FileInputStream fis = new FileInputStream(file);
                fis.read(data);
                fis.close();
                return data;
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (data != null) {
                    data = null;
                }
            }
            return null;
        }
    
        /**
         * Returns the file as a byte array.
         *
         *   @Param file
         *   @return
         */
        public static byte[] getData(File file) {
            try {
                byte[] data = new byte[(int) file.length()];
                FileInputStream fis = new FileInputStream(file);
                fis.read(data);
                fis.close();
                return data;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        
        /**
         * Gets the file data from the specified URL.
         *   @Param url
         *   @return
         */
        public static byte[] getData(URL url) {
            try {
                URLConnection connection = url.openConnection();
                int length = connection.getContentLength();
                if (length < 0) {
                    return null;
                }
                byte[] data = new byte[length];
                InputStream inputstream = connection.getInputStream();
                int off = 0;
                while (off < length) {
                    int len = length - off;
                    if (len > 1000) {
                        len = 1000;
                    }
                    int read = inputstream.read(data, off, len);
                    if (read < 0) {
                        throw new EOFException();
                    }
                    off += read;
                }
                inputstream.close();
                return data;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        /**
         * Compresses the raw data in gzip format.
         *
         *   @Param raw
         *   @return
         */
        public static byte[] compress(byte[] raw) {
            try {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                GZIPOutputStream gzo = new GZIPOutputStream(bos);
                try {
                    gzo.write(raw, 0, raw.length);
                } finally {
                    gzo.flush();
                    bos.flush();
                    gzo.close();
                    bos.close();
                }
                return bos.toByteArray();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    
        /**
         * Decompresses the data from gzip.
         *
         *   @Param data
         *   @return
         * @throws IOException
         */
        public static byte[] decompress(byte[] data) {
            byte[] decompressed = null;
            ByteArrayOutputStream out = null;
            try {
                GZIPInputStream gzi = new GZIPInputStream(new ByteArrayInputStream(data));
                out = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                int len;
                while ((len = gzi.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                decompressed = out.toByteArray();
                return decompressed;
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                decompressed = null;
                try {
                    out.flush();
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return data;
        }
    
        /**
         * Writes data to the specified file.
         *
         *   @Param file
         *   @Param data
         */
        public static void write(String file, byte[] data) {
            try {
                if (data != null) {
                    OutputStream out = new FileOutputStream(file);
                    out.write(data);
                    out.flush();
                    out.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    Code:
    public final class PathManager {
    
        /**
         * Returns the cache directory.
         * If it cannot find the default directory or it cannot be made, it will revert to a local
         * folder relative to the location the client was started from.
         *   @return
         */
        
        /**
         * Directory strings.
         */
        private static String CACHE_DIRECTORY;
        private static String WORKING_DIRECTORY;
        
        /**
         * Put server cache name here.
         */
        private static String CACHE_NAME = "";
    
        public static final String getDirectory(){
            if (CACHE_DIRECTORY == null) {
                CACHE_DIRECTORY = getInitialDirectory();
            }
            return CACHE_DIRECTORY;
        }
        
        private static final String getInitialDirectory() {
            String file_store = "."+CACHE_NAME;
            try {
                String path = System.getProperty("user.home") + System.getProperty("file.separator");
                File loc = new File(path + file_store);
                if (!loc.exists()) {
                    if (loc.mkdirs()) {
                        System.out.println("[PathManager] The cache directory was created successfully: " + loc.getAbsolutePath());
                    } else {
                        System.out.println("[PathManager] An error occurred while creating the cache directory: " + loc.getAbsolutePath());
                    }
                }
                if (loc.exists()) {
                    return path + file_store + System.getProperty("file.separator");
                }
            } catch (Exception _ex) {
            }
            String location = ".\\cache\\";
            File loc = new File(location);
            if (!loc.exists()) {
                if (loc.mkdirs()) {
                    System.out.println("[PathManager] The cache directory was created successfully: " + loc.getAbsolutePath());
                } else {
                    System.out.println("[PathManager] An error occurred while creating the cache directory: " + loc.getAbsolutePath());
                }
            }
            return location;
        }
    
        public static final String getWorkingDirectory() {
            if (WORKING_DIRECTORY == null) {
                WORKING_DIRECTORY = getInitialWorkingDirectory();
            }
            return WORKING_DIRECTORY;
        }
    
        /**
         * Returns the working directory.
         *   @return
         */
        private static final String getInitialWorkingDirectory() {
            File dir = new File(getDirectory()+ "\\working\\");
            if (!dir.exists()) {
                if (dir.mkdirs()) {
                    System.out.println("[PathManager] The working directory was created successfully: " + dir.getAbsolutePath());
                } else {
                    System.out.println("[PathManager] An error occurred while creating working cache directory: " + dir.getAbsolutePath());
                }
            }
            return getDirectory() + "\\working\\";
        }
    
    }
    Use Eclipse.

    Credits: Soulsplit
    Reply With Quote  
     

  2. #2  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Lol none of this is your code, this is ripped from a very old (over 1+ years) SS client leak.

    I don't care if it's posted, if someone can find use for it then that's cool. But this isn't yours .
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    hacker's Avatar
    Join Date
    Jun 2013
    Posts
    1,409
    Thanks given
    576
    Thanks received
    580
    Rep Power
    5000
    Lol is all this code necessary for this?
    Attached image
    Reply With Quote  
     

  4. #4  
    Retired. Stop PMing me.


    Galkon's Avatar
    Join Date
    Nov 2007
    Age
    17
    Posts
    7,526
    Thanks given
    1,805
    Thanks received
    2,830
    Rep Power
    5000
    Quote Originally Posted by Hacker View Post
    Lol is all this code necessary for this?
    No, it's 2 years old and was the first version of a world list in the client. Plus the class for cache directory location and such.
    Attached image
    Reply With Quote  
     

  5. Thankful user:


  6. #5  
    Registered Member
    Join Date
    Nov 2012
    Posts
    171
    Thanks given
    2
    Thanks received
    4
    Rep Power
    0
    how would i go about using this in my spiritloader.java or try loading mainfilecache.dat trough a url?
    galkon or anyone?
    New project I've been working on, Bettss ,
    Spoiler for BIG PICTURES :



    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. Replies: 17
    Last Post: 07-05-2008, 09:49 AM
  2. Server Runtime Manager v1.1
    By meiscooldude in forum Tools
    Replies: 1
    Last Post: 06-16-2008, 07:18 PM
  3. Server Runtime Manager
    By meiscooldude in forum Tools
    Replies: 4
    Last Post: 06-14-2008, 04:42 PM
  4. URL suggest [rep++]
    By A2 Alex in forum Chat
    Replies: 8
    Last Post: 06-05-2008, 12:57 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
  •