added the new program for holding known games

#stroy[1188]
main
hba56 8 years ago
parent 7086af6057
commit 5b6b0a9978

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>team-7</artifactId>
<groupId>seng302</groupId>
<version>2.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<name>matchBrowser</name>
<artifactId>matchBrowser</artifactId>
<version>2.0</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>app.Main</Main-Class>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
</manifestEntries>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,7 @@
package app;
/**
* Used when starting the matchmaking browser
*/
public class Main {
}

@ -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<TableKey, List> matchTable;
public MatchTable() {
this.matchTable = new HashMap<TableKey, List>();
}
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<newEntry.size(); i++) {
entryItems.add(newEntry.get(i));
}
this.matchTable.put(entryKey, entryItems);
}
public HashMap<TableKey, List> getMatchTable() {
return matchTable;
}
}

@ -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;
}
}

@ -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);
}
}
}

@ -0,0 +1,7 @@
package networkInterface;
/**
* Holds the connection to the network for output
*/
public class OutInterface {
}

@ -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));
}
}
Loading…
Cancel
Save