matching table now stores the correct ip of the hosts

#story[1188]
This commit is contained in:
hba56
2017-08-31 13:55:16 +12:00
parent 9161f69547
commit a1fa09962a
3 changed files with 4 additions and 4 deletions
@@ -17,9 +17,9 @@ public class MatchTable {
this.matchTable = new HashMap<TableKey, List>(); this.matchTable = new HashMap<TableKey, List>();
} }
public void addEntry(HostGame newEntry) { public void addEntry(String ip, int port, HostGame newEntry) {
//create a key from the ip and port //create a key from the ip and port
TableKey entryKey = new TableKey( newEntry.getIp(), newEntry.getPort()); TableKey entryKey = new TableKey(ip, port);
//get the rest of the entry and use it as the value //get the rest of the entry and use it as the value
List entryItems = new ArrayList(); List entryItems = new ArrayList();
@@ -55,7 +55,7 @@ public class NetworkInterface {
try{ try{
newKnownGame = (HostGame) decoder.decode(messageDecoder.getMessageBody()); newKnownGame = (HostGame) decoder.decode(messageDecoder.getMessageBody());
this.matchTable.addEntry(newKnownGame); this.matchTable.addEntry(receivePacket.getAddress().getHostAddress(), receivePacket.getPort(), newKnownGame);
System.out.println(matchTable); System.out.println(matchTable);
}catch (InvalidMessageException e){ }catch (InvalidMessageException e){
@@ -22,7 +22,7 @@ public class MatchTableTest {
public void testTable() { public void testTable() {
HostGame entry = new HostGame("127.0.0.1", 4942, (byte)1, (byte)1, RaceStatusEnum.PRESTART, (byte)6, (byte)1); HostGame entry = new HostGame("127.0.0.1", 4942, (byte)1, (byte)1, RaceStatusEnum.PRESTART, (byte)6, (byte)1);
testTable.addEntry(entry); testTable.addEntry("127.0.0.1", 3779, entry);
assertEquals(testTable.getMatchTable().get(new TableKey("127.0.0.1", 4942)), Arrays.asList(1, 1, 2, 6, 1)); assertEquals(testTable.getMatchTable().get(new TableKey("127.0.0.1", 4942)), Arrays.asList(1, 1, 2, 6, 1));
} }