rendered paste bodypackage impsoft.common.exemplar;import impsoft.common.ruler.ILoad;import impsoft.common.ruler.Server;import impsoft.nexus.bots.color.methods.StaticColorMethods;import impsoft.nexus.gui.GuiThread;import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.URL;import java.util.ArrayList;import java.util.regex.Matcher;import java.util.regex.Pattern;public class ServerList { public static Server servers[]; public static Server getServer(int world, int ignore[]) { if (world == -1) { for (int i = 0; i < servers.length; i++) { if (servers[i].memebers == false) { boolean good = true; for (int j = 0; j < ignore.length; j++) { if (servers[i].worldNumber == ignore[j]) { good = false; break; } } if (good) { return servers[i]; } } } } else if (world == -2) { for (int i = 0; i < servers.length; i++) { if (servers[i].memebers == true) { boolean good = true; for (int j = 0; j < ignore.length; j++) { if (servers[i].worldNumber == ignore[j]) { good = false; break; } } if (good) { return servers[i]; } } } } else { for (int i = 0; i < servers.length; i++) { if (servers[i].worldNumber == world) { return servers[i]; } } } return null; } private static void log(String message) { GuiThread.log(message); } private static void exception(Exception e) { GuiThread.exception(e); } public static void load() { System .setProperty( "http.agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060907 Firefox/1.5.0.7"); log("Downloading new server list..."); try { String data = null; if (ILoad.unsigned) data = grabData("http://runescape.com/serverlist.ws?plugin=2&lores.x=" + StaticColorMethods.random(1, 520) + "&lores.y=" + StaticColorMethods.random(1, 520)); else { data = grabData("http://runescape.com/serverlist.ws?plugin=0&lores.x=" + StaticColorMethods.random(1, 520) + "&lores.y=" + StaticColorMethods.random(1, 520)); } // System.out.print(data); servers = patternMatch(data); log("Server list updated. Servers:" + servers.length); } catch (Exception e) { log("Error loading new server list."); exception(e); servers = new Server[] { new Server(1000, "null", false, -1000) }; } sort(); // servers[1].getJarPath(); } private static void sort() { boolean change = true; while (change) { change = false; for (int i = 0; i < servers.length - 1; i++) { if (servers[i].population > servers[i + 1].population) { Server temp = servers[i]; servers[i] = servers[i + 1]; servers[i + 1] = temp; change = true; } } } } private static String grabData(String url) throws Exception { URL u = new URL(url); BufferedReader reader = new BufferedReader(new InputStreamReader(u .openStream())); String buff, data = ""; while ((buff = reader.readLine()) != null) data += buff + "\n"; data = data.replaceAll("=c>\n", "=c>"); return data; } private static Server[] patternMatch(String data) { data = data.replaceAll("\n", ""); // String PATTERN = "<td class=\"(free|members)\"><a href=\"http://" // + // "\\w+\\.runescape\\.com/lang/en/aff/runescape/game\\.ws\\?lowmem=0&plugin=0" // + "\">World \\d{1,3}</a> </td>"; String PATTERN = null; if (ILoad.unsigned) PATTERN = "<td class=\"(free|members)\"><a href=\"http://" + "\\w+\\.runescape\\.com/lang/en/aff/runescape/game\\.ws\\?lowmem=1&plugin=2" + "\">World \\d{1,3}</a> </td><td>\\d{1,4} Players</td>"; else PATTERN = "<td class=\"(free|members)\"><a href=\"http://" + "\\w+\\.runescape\\.com/lang/en/aff/runescape/game\\.ws\\?lowmem=1&plugin=0" + "\">World \\d{1,3}</a> </td><td>\\d{1,4} Players</td>"; Matcher m = Pattern.compile(PATTERN).matcher(data); ArrayList<Server> servers = new ArrayList<Server>(10); while (m.find()) { String matched = data.substring(m.start(), m.end()); int httpIdx = matched.indexOf("http://") + 7; int endPrefixIdx = matched.indexOf(".runes"); String prefix = matched.substring(httpIdx, endPrefixIdx); String world = matched.substring(matched.indexOf("World") + 5, matched.indexOf("</a> </td>")); String population = matched.substring(matched .indexOf("</a> </td><td>") + 14, matched.indexOf("Players") - 1); boolean p2p = matched.contains("members"); // map.put(world.trim(), prefix.trim() + ":" // + (p2p ? "members" : "free")); servers.add(new Server(Integer.parseInt(world.trim()), prefix .trim(), p2p, Integer.parseInt(population.trim()))); } Server serverArray[] = new Server[servers.size()]; for (int i = 0; i < serverArray.length; i++) { serverArray[i] = servers.get(i); } return serverArray; }}