diff --git a/matchBrowser/pom.xml b/matchBrowser/pom.xml new file mode 100644 index 00000000..fb8cabe9 --- /dev/null +++ b/matchBrowser/pom.xml @@ -0,0 +1,82 @@ + + + + team-7 + seng302 + 2.0 + + 4.0.0 + + + jar + matchBrowser + matchBrowser + 2.0 + + + + junit + junit + 4.12 + test + + + + + org.mockito + mockito-all + 1.9.5 + + + + org.testng + testng + 6.11 + test + + + + + 1.8 + 1.8 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.3 + + + + + app.Main + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + package + + shade + + + + + + + + \ No newline at end of file diff --git a/matchBrowser/src/main/java/app/Main.java b/matchBrowser/src/main/java/app/Main.java new file mode 100644 index 00000000..e189c052 --- /dev/null +++ b/matchBrowser/src/main/java/app/Main.java @@ -0,0 +1,7 @@ +package app; + +/** + * Used when starting the matchmaking browser + */ +public class Main { +} diff --git a/matchBrowser/src/main/java/model/MatchTable.java b/matchBrowser/src/main/java/model/MatchTable.java new file mode 100644 index 00000000..d2798939 --- /dev/null +++ b/matchBrowser/src/main/java/model/MatchTable.java @@ -0,0 +1,34 @@ +package model; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * Holds a table object that stores current games + */ +public class MatchTable { + private HashMap matchTable; + + public MatchTable() { + this.matchTable = new HashMap(); + } + + public void addEntry(ArrayList newEntry) { + //create a key from the ip and port + TableKey entryKey = new TableKey((String) newEntry.get(0), (Integer) newEntry.get(1)); + + //get the rest of the entry and use it as the value + List entryItems = new ArrayList(); + for(int i = 2; i getMatchTable() { + return matchTable; + } +} diff --git a/matchBrowser/src/main/java/model/TableKey.java b/matchBrowser/src/main/java/model/TableKey.java new file mode 100644 index 00000000..6b803fd9 --- /dev/null +++ b/matchBrowser/src/main/java/model/TableKey.java @@ -0,0 +1,30 @@ +package model; + +/** + * Used to create a key made of an ip and port. + */ +public class TableKey { + + private final String ip; + private final int port; + + public TableKey(String ip, int port) { + this.ip = ip; + this.port = port; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof TableKey)) return false; + TableKey key = (TableKey) o; + return ip == key.ip && port == key.port; + } + + @Override + public int hashCode() { + int result = port; + result = 31 * result + ip.hashCode(); + return result; + } +} diff --git a/matchBrowser/src/main/java/networkInterface/InInterface.java b/matchBrowser/src/main/java/networkInterface/InInterface.java new file mode 100644 index 00000000..5d729e08 --- /dev/null +++ b/matchBrowser/src/main/java/networkInterface/InInterface.java @@ -0,0 +1,46 @@ +package networkInterface; + +import java.io.*; +import java.net.*; + +/** + * Holds the output for the network for + */ +public class InInterface { + private DatagramSocket serverSocket; + private byte[] receiveData = new byte[1024]; + private byte[] sendData = new byte[1024]; + + public InInterface(){ + try { + this.serverSocket = new DatagramSocket(3779); + + this.run(); + } catch (IOException e) { + System.err.println("Error listening on port: " + this.serverSocket.getLocalPort() + "."); + System.exit(-1); + } + + } + + private void run() throws IOException{ + while(true) { + DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); + serverSocket.receive(receivePacket); + + //decode and update table + + //client ip and port + InetAddress IPAddress = receivePacket.getAddress(); + int port = receivePacket.getPort(); + + + +// String capitalizedSentence = sentence.toUpperCase(); +// sendData = capitalizedSentence.getBytes(); +// DatagramPacket sendPacket = +// new DatagramPacket(sendData, sendData.length, IPAddress, port); +// serverSocket.send(sendPacket); + } + } +} diff --git a/matchBrowser/src/main/java/networkInterface/OutInterface.java b/matchBrowser/src/main/java/networkInterface/OutInterface.java new file mode 100644 index 00000000..18746004 --- /dev/null +++ b/matchBrowser/src/main/java/networkInterface/OutInterface.java @@ -0,0 +1,7 @@ +package networkInterface; + +/** + * Holds the connection to the network for output + */ +public class OutInterface { +} diff --git a/matchBrowser/src/test/java/model/MatchTableTest.java b/matchBrowser/src/test/java/model/MatchTableTest.java new file mode 100644 index 00000000..6c16cd9e --- /dev/null +++ b/matchBrowser/src/test/java/model/MatchTableTest.java @@ -0,0 +1,27 @@ +package model; + +import org.junit.Before; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; + +public class MatchTableTest { + private MatchTable testTable; + + @Before + public void setUp() { + testTable = new MatchTable(); + } + + @Test + public void testTable() { + ArrayList entry = new ArrayList(Arrays.asList("127.0.0.1", 4942, 1, 1, 2, 6, 1)); + + testTable.addEntry(entry); + + assertEquals(testTable.getMatchTable().get(new TableKey("127.0.0.1", 4942)), Arrays.asList(1, 1, 2, 6, 1)); + } +}