updating match table to store ip and port of clients and hosts

#story[1188]
This commit is contained in:
hba56
2017-08-31 13:45:04 +12:00
parent 960b1213fb
commit 9161f69547
8 changed files with 99 additions and 26 deletions
@@ -17,6 +17,7 @@ import shared.model.Bearing;
import shared.model.Constants;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
@@ -206,8 +207,8 @@ public class Event {
* @return hostGame Ac35DataType
*/
public HostGame getHostedGameData() throws IOException{
InetAddress ip = InetAddress.getByName("localhost");
return new HostGame(ip.getHostAddress(), 3779,(byte) 1,(byte) 1, RaceStatusEnum.PRESTART, (byte) 1, (byte) 1);
String ip = Inet4Address.getLocalHost().getHostAddress();
return new HostGame(ip, 3779,(byte) 1,(byte) 1, RaceStatusEnum.PRESTART, (byte) 1, (byte) 1);
}
}
@@ -21,13 +21,14 @@ public class HostedGamesRequestDecoder implements MessageDecoder{
List<HostGame> knownGames = new ArrayList<>();
int byteIndex = 4;
for (int i = 0; i < numberOfGames; i++){
knownGames.add((HostGame) lineDecoder.decode(Arrays.copyOfRange(encodedMessage, byteIndex, byteIndex+14)));
knownGames.add((HostGame) lineDecoder.decode(Arrays.copyOfRange(encodedMessage, byteIndex, byteIndex+13)));
byteIndex += 13;
}
return new HostGamesRequest(knownGames);
} catch (Exception e) {
e.printStackTrace();
throw new InvalidMessageException("Could not decode Host game message.", e);
}
}
@@ -9,11 +9,9 @@ import network.Messages.Enums.MessageType;
import network.Messages.HostGamesRequest;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.*;
import java.util.ArrayList;
import java.util.Enumeration;
/**
* UDP interface for the matchBrowser to send out hosted game info and get in other hosts info
@@ -31,6 +29,7 @@ public class MatchBrowserInterface {
try {
this.IPAddress = InetAddress.getByName("localhost");
} catch (UnknownHostException e) {
e.printStackTrace();
}
this.port = 3779;
}