updating match table to store ip and port of clients and hosts
#story[1188]
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package model;
|
||||
|
||||
public class ClientAdress {
|
||||
private String ip;
|
||||
private int port;
|
||||
|
||||
public ClientAdress(String ip, int port) {
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = ip != null ? ip.hashCode() : 0;
|
||||
result = 31 * result + port;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ip='" + ip + '\'' +
|
||||
", port=" + port+"]";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
package model;
|
||||
|
||||
|
||||
import network.Messages.HostGame;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -15,15 +17,18 @@ public class MatchTable {
|
||||
this.matchTable = new HashMap<TableKey, List>();
|
||||
}
|
||||
|
||||
public void addEntry(ArrayList newEntry) {
|
||||
public void addEntry(HostGame newEntry) {
|
||||
//create a key from the ip and port
|
||||
TableKey entryKey = new TableKey((String) newEntry.get(0), (Integer) newEntry.get(1));
|
||||
TableKey entryKey = new TableKey( newEntry.getIp(), newEntry.getPort());
|
||||
|
||||
//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));
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -31,4 +36,10 @@ public class MatchTable {
|
||||
public HashMap<TableKey, List> getMatchTable() {
|
||||
return matchTable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[MatchTable=" + matchTable +
|
||||
']';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,4 +27,11 @@ public class TableKey {
|
||||
result = 31 * result + ip.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ip='" + ip + '\'' +
|
||||
", port=" + port +
|
||||
']';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user