diff --git a/parabotv2/src/org/parabot/core/Context.java b/parabotv2/src/org/parabot/core/Context.java
index e82a2b9..2b7e2e9 100644
--- a/parabotv2/src/org/parabot/core/Context.java
+++ b/parabotv2/src/org/parabot/core/Context.java
@@ -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();
diff --git a/parabotv2/src/org/parabot/core/Core.java b/parabotv2/src/org/parabot/core/Core.java
index c59adf8..ed40931 100644
--- a/parabotv2/src/org/parabot/core/Core.java
+++ b/parabotv2/src/org/parabot/core/Core.java
@@ -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 true if no update is required, otherwise false.
+ * Checks the version of the bot using a checksum of the jar comparison against checksum given by the website
+ * @return true if no new version is found, otherwise false.
*/
- 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 true if no new version is found, otherwise false.
+ */
+ 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 true if no update is required, otherwise false.
+ */
+ 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) {
diff --git a/parabotv2/src/org/parabot/core/network/NetworkInterface.java b/parabotv2/src/org/parabot/core/network/NetworkInterface.java
index 3610d25..2751dc5 100644
--- a/parabotv2/src/org/parabot/core/network/NetworkInterface.java
+++ b/parabotv2/src/org/parabot/core/network/NetworkInterface.java
@@ -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 getNetworkInterfaces()
+ throws SocketException {
+ final ArrayList netifs = new ArrayList<>();
+
+ return new Enumeration() {
+ 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;