|
|
|
|
@ -60,7 +60,6 @@ public class NetworkInterface {
|
|
|
|
|
for(Map.Entry<ClientAddress, HostGame> tableEntry: matchTable.getMatchTable().entrySet()) {
|
|
|
|
|
HostGame game = tableEntry.getValue();
|
|
|
|
|
if(game != null) {
|
|
|
|
|
System.out.println(game.getIp());
|
|
|
|
|
games.add(game);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -70,7 +69,6 @@ public class NetworkInterface {
|
|
|
|
|
byte[] message = encoder.encode(new HostGamesRequest(games));
|
|
|
|
|
System.out.println(LocalDateTime.now() + ": Sending " + games.size() + " game/s");
|
|
|
|
|
for(ClientAddress address: clientsAddresses) {
|
|
|
|
|
System.out.println("sending to: " + address.getIp());
|
|
|
|
|
serverSocket.send(new DatagramPacket(message, message.length, InetAddress.getByName(address.getIp()), 4941));
|
|
|
|
|
}
|
|
|
|
|
} catch (InvalidMessageException | IOException e) {
|
|
|
|
|
@ -99,9 +97,6 @@ public class NetworkInterface {
|
|
|
|
|
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
|
|
|
|
serverSocket.receive(receivePacket);
|
|
|
|
|
|
|
|
|
|
// System.out.println(receivePacket.getAddress());
|
|
|
|
|
// System.out.println(this.clientsAddresses);
|
|
|
|
|
|
|
|
|
|
BinaryMessageDecoder messageDecoder = new BinaryMessageDecoder(receivePacket.getData());
|
|
|
|
|
switch (MessageType.fromByte(messageDecoder.getHeaderMessageType())){
|
|
|
|
|
case HOST_GAME:
|
|
|
|
|
@ -110,6 +105,7 @@ public class NetworkInterface {
|
|
|
|
|
HostGame newKnownGame;
|
|
|
|
|
try{
|
|
|
|
|
newKnownGame = (HostGame) decoder.decode(messageDecoder.getMessageBody());
|
|
|
|
|
newKnownGame.setIp(receivePacket.getAddress().getHostAddress());
|
|
|
|
|
this.matchTable.addEntry(new ClientAddress(receivePacket.getAddress().getHostAddress(), receivePacket.getPort()), newKnownGame);
|
|
|
|
|
|
|
|
|
|
}catch (InvalidMessageException e){
|
|
|
|
|
|