Fixed issue where some clients used #getNetworkInterfaces

This commit is contained in:
JKetelaar
2014-12-15 01:02:33 +01:00
parent 32e89b8615
commit 9d59a5e2ff
3 changed files with 104 additions and 11 deletions
+1 -1
View File
@@ -182,7 +182,7 @@ public class Context {
gameApplet.setSize(appletSize);
panel.add(gameApplet);
panel.validate();
gameApplet.init();
gameApplet.start();
java.util.Timer t = new java.util.Timer();
+79 -10
View File
@@ -1,9 +1,17 @@
package org.parabot.core;
import org.parabot.Landing;
import org.parabot.environment.api.utils.WebUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* The core of parabot
@@ -88,18 +96,62 @@ public class Core {
}
/**
* Checks for updates.
*
* @return <b>true</b> if no update is required, otherwise <b>false</b>.
* Checks the version of the bot using a checksum of the jar comparison against checksum given by the website
* @return <b>true</b> if no new version is found, otherwise <b>false</b>.
*/
public static boolean isValid() {
Core.verbose("Checking for updates...");
private static boolean checksumValid(){
String checksum = "";
File f = new File(Landing.class.getProtectionDomain().getCodeSource().getLocation().getFile());
if (f.isFile()) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
try (InputStream is = Files.newInputStream(Paths.get(f.getAbsolutePath()))) {
DigestInputStream dis = new DigestInputStream(is, md);
} catch (IOException e) {
e.printStackTrace();
}
byte[] digest = md.digest();
for (byte aDigest : digest) {
checksum += Integer.toString((aDigest & 0xff) + 0x100, 16).substring(1);
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
//TODO Get checksum from BDN and verify
// BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION);
// try {
// double version = Double.parseDouble(br.readLine());
// if (Configuration.BOT_VERSION != version) {
// Core.verbose("Updates available...");
// return false;
// }
// } catch (NumberFormatException | IOException e) {
// e.printStackTrace();
// } finally {
// try {
// br.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
return true;
}
/**
* Checks the version of the bot using a variable comparison from the bot code and the Parabot website
* @return <b>true</b> if no new version is found, otherwise <b>false</b>.
*/
private static boolean versionValid(){
BufferedReader br = WebUtil.getReader(Configuration.GET_BOT_VERSION);
try {
double version = Double.parseDouble(br.readLine());
if (Configuration.BOT_VERSION >= version) {
Core.verbose("No updates available.");
return true;
if (Configuration.BOT_VERSION < version) {
return false;
}
} catch (NumberFormatException | IOException e) {
e.printStackTrace();
@@ -110,8 +162,25 @@ public class Core {
e.printStackTrace();
}
}
Core.verbose("Updates available...");
return false;
return true;
}
/**
* Checks for updates.
*
* @return <b>true</b> if no update is required, otherwise <b>false</b>.
*/
public static boolean isValid() {
Core.verbose("Checking for updates...");
if (versionValid() && checksumValid()){
Core.verbose("No updates available.");
return true;
}else{
Core.verbose("Updates available...");
return false;
}
}
public static void debug(int i) {
@@ -2,6 +2,9 @@ package org.parabot.core.network;
import java.net.InetAddress;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.NoSuchElementException;
public class NetworkInterface {
public static byte[] mac = new byte[] { 11, 11, 11, 11, 11, 11 };
@@ -19,6 +22,27 @@ public class NetworkInterface {
return mac;
}
public static Enumeration<NetworkInterface> getNetworkInterfaces()
throws SocketException {
final ArrayList<NetworkInterface> netifs = new ArrayList<>();
return new Enumeration<NetworkInterface>() {
private int i = 0;
public NetworkInterface nextElement() {
if (i < netifs.size()) {
NetworkInterface netif = netifs.get(i++);
return netif;
} else {
throw new NoSuchElementException();
}
}
public boolean hasMoreElements() {
return (i < netifs.size());
}
};
}
public static byte[] getRealHardwareAddress() throws SocketException{
if (realMac != null)
return realMac;