added the new program for holding known games
#stroy[1188]
This commit is contained in:
@@ -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 {
|
||||
}
|
||||
Reference in New Issue
Block a user