Implemented a more reliable way for keystroke input and added boat action packet type so stream parser is able to read and decode the message appropriately.

#story[988] #pair[hyi25, zyt10]
This commit is contained in:
Zhi You Tan
2017-07-14 18:23:07 +12:00
parent 2809d0d832
commit 355f8543f5
5 changed files with 13 additions and 21 deletions
@@ -79,8 +79,8 @@ public class StartScreenController {
@FXML
public void connectButtonPressed() {
// TODO: 10/07/17 wmu16 - Finish function
String ipAddress = ipTextField.getText().trim();
StreamReceiver sr = new StreamReceiver(ipAddress, GameServerThread.PORT_NUMBER, "HostStream");
String ipAddress = ipTextField.getText().trim().toLowerCase();
StreamReceiver sr = new StreamReceiver(ipAddress, 4950, "HostStream");
sr.start();
}
}
@@ -11,7 +11,6 @@ import java.util.Comparator;
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.PriorityBlockingQueue;
@@ -146,6 +145,8 @@ public class StreamParser extends Thread {
extractAvgWind(packet);
break;
default:
//TODO: Haoming added something dumb here.
System.out.println(packet);
break;
}
} catch (NullPointerException e) {
@@ -16,6 +16,7 @@ public enum PacketType {
MARK_ROUNDING,
COURSE_WIND,
AVG_WIND,
BOAT_ACTION,
OTHER;
public static PacketType assignPacketType(int packetType){
@@ -44,6 +45,8 @@ public enum PacketType {
return COURSE_WIND;
case 47:
return AVG_WIND;
case 100:
return BOAT_ACTION;
default:
}
return OTHER;
@@ -8,17 +8,18 @@ import java.nio.channels.SocketChannel;
*/
public class BoatActionMessage extends Message{
private final MessageType MESSAGE_TYPE = MessageType.BOAT_ACTION;
private final int MESSAGE_VERSION = 1; //Always set to 1
private final int MESSAGE_SIZE = 1;
private BoatActionType actionType;
public BoatActionMessage(BoatActionType actionType) {
this.actionType = actionType;
setHeader(new Header(MessageType.BOAT_ACTION, 0, (short) 1)); // the second variable is the source id
}
@Override
public int getSize() {
return 0;
return MESSAGE_SIZE;
}
/**
@@ -30,7 +31,6 @@ public class BoatActionMessage extends Message{
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putUnsignedByte((byte) MESSAGE_VERSION);
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();