Added scheduled match list broadcast to MatchBrowser

- Changed MatchTable to map ClientAddress to HostGame
- Send match list as HostedGamesRequest to multicast address (239.0.0.1:4941)

#story[1188]
This commit is contained in:
cbt24
2017-08-31 17:34:02 +12:00
parent d1c0797db7
commit 2f8daf757a
4 changed files with 58 additions and 46 deletions
@@ -1,10 +1,10 @@
package model;
public class ClientAdress {
public class ClientAddress {
private String ip;
private int port;
public ClientAdress(String ip, int port) {
public ClientAddress(String ip, int port) {
this.ip = ip;
this.port = port;
}
@@ -19,19 +19,13 @@ public class ClientAdress {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClientAdress that = (ClientAdress) o;
if (port != that.port) return false;
return ip != null ? ip.equals(that.ip) : that.ip == null;
return o != null && o instanceof ClientAddress && hashCode() == o.hashCode();
}
@Override
public int hashCode() {
int result = ip != null ? ip.hashCode() : 0;
result = 31 * result + port;
result *= 31;
return result;
}
@@ -11,29 +11,17 @@ import java.util.List;
* Holds a table object that stores current games
*/
public class MatchTable {
private HashMap<TableKey, List> matchTable;
private HashMap<ClientAddress, HostGame> matchTable;
public MatchTable() {
this.matchTable = new HashMap<TableKey, List>();
this.matchTable = new HashMap<>();
}
public void addEntry(String ip, int port, HostGame newEntry) {
//create a key from the ip and port
TableKey entryKey = new TableKey(ip, port);
//get the rest of the entry and use it as the value
List entryItems = new ArrayList();
entryItems.add(newEntry.getMap());
entryItems.add(newEntry.getSpeed());
entryItems.add(newEntry.getStatus());
entryItems.add(newEntry.getRequiredNumPlayers());
entryItems.add(newEntry.getCurrentNumPlayers());
this.matchTable.put(entryKey, entryItems);
public void addEntry(ClientAddress address, HostGame newEntry) {
this.matchTable.put(address, newEntry);
}
public HashMap<TableKey, List> getMatchTable() {
public HashMap<ClientAddress, HostGame> getMatchTable() {
return matchTable;
}