diff --git a/data/net.xml b/data/net.xml
new file mode 100644
index 00000000..fe5da2a3
--- /dev/null
+++ b/data/net.xml
@@ -0,0 +1,12 @@
+
+
+ 143690958001225849100503496893758066948984921380482659564113596152800934352119496873386875214251264258425208995167316497331786595942754290983849878549630226741961610780416197036711585670124061149988186026407785250364328460839202438651793652051153157765358767514800252431284681765433239888090564804146588087023
+ 124425314960550024206991065332877157931472210939505789558012215720454903710618146200843877022273818555405810618059191162604008259757866640421952188957253368398733319663236323097864278319463888334484786055755767881706264786840339899269810859874287402892848784247637729987603089254067178011764721326471352835473
+
+
+
+ 80
+ 43594
+ 43595
+
+
\ No newline at end of file
diff --git a/data/rsa.xml b/data/rsa.xml
deleted file mode 100644
index abe68a05..00000000
--- a/data/rsa.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
- 143690958001225849100503496893758066948984921380482659564113596152800934352119496873386875214251264258425208995167316497331786595942754290983849878549630226741961610780416197036711585670124061149988186026407785250364328460839202438651793652051153157765358767514800252431284681765433239888090564804146588087023
- 124425314960550024206991065332877157931472210939505789558012215720454903710618146200843877022273818555405810618059191162604008259757866640421952188957253368398733319663236323097864278319463888334484786055755767881706264786840339899269810859874287402892848784247637729987603089254067178011764721326471352835473
-
\ No newline at end of file
diff --git a/src/org/apollo/net/NetworkConstants.java b/src/org/apollo/net/NetworkConstants.java
index af65c9f4..56c3e20b 100644
--- a/src/org/apollo/net/NetworkConstants.java
+++ b/src/org/apollo/net/NetworkConstants.java
@@ -11,17 +11,20 @@ import org.apollo.net.session.Session;
import org.apollo.util.xml.XmlNode;
import org.apollo.util.xml.XmlParser;
+import com.google.common.base.Preconditions;
+
/**
* Holds various network-related constants such as port numbers.
*
* @author Graham
+ * @author Major
*/
public final class NetworkConstants {
/**
* The HTTP port.
*/
- public static final int HTTP_PORT = 80;
+ public static final int HTTP_PORT;
/**
* The number of seconds before a connection becomes idle.
@@ -31,7 +34,7 @@ public final class NetworkConstants {
/**
* The JAGGRAB port.
*/
- public static final int JAGGRAB_PORT = 43595;
+ public static final int JAGGRAB_PORT;
/**
* The exponent used when decrypting the RSA block.
@@ -46,7 +49,7 @@ public final class NetworkConstants {
/**
* The service port.
*/
- public static final int SERVICE_PORT = 43594;
+ public static final int SERVICE_PORT;
/**
* The {@link Session} {@link AttributeKey}.
@@ -59,26 +62,39 @@ public final class NetworkConstants {
public static final int STRING_TERMINATOR = 10;
static {
- try (InputStream is = new FileInputStream("data/rsa.xml")) {
- XmlNode rsa = new XmlParser().parse(is);
- if (!rsa.getName().equals("rsa")) {
- throw new IOException("Root node name is not 'rsa'.");
+ try (InputStream is = new FileInputStream("data/net.xml")) {
+ XmlNode net = new XmlParser().parse(is);
+ if (!net.getName().equals("net")) {
+ throw new IOException("Root node name is not 'net'.");
}
+ XmlNode rsa = net.getChild("rsa");
+ Preconditions.checkState(rsa != null, "Root node must have a child named 'rsa'.");
+
XmlNode modulus = rsa.getChild("modulus"), exponent = rsa.getChild("private-exponent");
- if (modulus == null || exponent == null) {
- throw new IOException("Root node must have two children - 'modulus' and 'private-exponent'.");
- }
+ Preconditions.checkState(modulus != null && exponent != null,
+ "Rsa node must have two children: 'modulus' and 'private-exponent'.");
RSA_MODULUS = new BigInteger(modulus.getValue());
RSA_EXPONENT = new BigInteger(exponent.getValue());
- } catch (Exception e) {
- throw new ExceptionInInitializerError(e);
+
+ XmlNode ports = net.getChild("ports");
+ Preconditions.checkState(ports != null, "Root node must have a child named 'ports'.");
+
+ XmlNode http = ports.getChild("http"), service = ports.getChild("service"), jaggrab = ports.getChild("jaggrab");
+ Preconditions.checkState(http != null && service != null && jaggrab != null,
+ "Ports node must have three children: 'http', 'service', and 'jaggrab'.");
+
+ HTTP_PORT = Integer.parseInt(http.getValue());
+ SERVICE_PORT = Integer.parseInt(service.getValue());
+ JAGGRAB_PORT = Integer.parseInt(jaggrab.getValue());
+ } catch (Exception exception) {
+ throw new ExceptionInInitializerError(new IOException("Error parsing net.xml.", exception));
}
}
/**
- * Default private constructor to prevent instantiation by other classes.
+ * Sole private constructor to prevent instantiation.
*/
private NetworkConstants() {