packets can now be sent from client to match server
#story[1188]
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package networkInterface;
|
||||
|
||||
import network.BinaryMessageDecoder;
|
||||
import network.Exceptions.InvalidMessageException;
|
||||
import network.MessageDecoders.HostGameMessageDecoder;
|
||||
import network.MessageDecoders.HostedGamesRequestDecoder;
|
||||
import network.Messages.HostGame;
|
||||
import network.Messages.HostGamesRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -34,16 +37,33 @@ public class NetworkInterface {
|
||||
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
|
||||
serverSocket.receive(receivePacket);
|
||||
|
||||
//decode and update table
|
||||
HostedGamesRequestDecoder decoder = new HostedGamesRequestDecoder();
|
||||
HostGamesRequest newKnownGames;
|
||||
try{
|
||||
newKnownGames = (HostGamesRequest) decoder.decode(receivePacket.getData());
|
||||
System.out.println(newKnownGames.getKnownGames().get(0));
|
||||
}catch (InvalidMessageException e){
|
||||
System.err.println("Message received that is not a hostedGamesRequest packet");
|
||||
BinaryMessageDecoder messageDecoder = new BinaryMessageDecoder(receivePacket.getData());
|
||||
switch (messageDecoder.getHeaderMessageType()){
|
||||
case 108:
|
||||
//decode and update table
|
||||
HostGameMessageDecoder decoder = new HostGameMessageDecoder();
|
||||
HostGame newKnownGame;
|
||||
try{
|
||||
newKnownGame = (HostGame) decoder.decode(messageDecoder.getMessageBody());
|
||||
System.out.println(newKnownGame.getIp());
|
||||
}catch (InvalidMessageException e){
|
||||
System.err.println("Message received that is not a hostedGame packet");
|
||||
}
|
||||
break;
|
||||
case 109:
|
||||
//decode and update table
|
||||
HostedGamesRequestDecoder decoder2 = new HostedGamesRequestDecoder();
|
||||
HostGamesRequest newKnownGames;
|
||||
try{
|
||||
newKnownGames = (HostGamesRequest) decoder2.decode(receivePacket.getData());
|
||||
System.out.println(newKnownGames);
|
||||
}catch (InvalidMessageException e){
|
||||
System.err.println("Message received that is not a hostedGamesRequest packet");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//client ip and port
|
||||
InetAddress IPAddress = receivePacket.getAddress();
|
||||
int port = receivePacket.getPort();
|
||||
|
||||
Reference in New Issue
Block a user