Key presses are transmitted to a host (but there is no host currently connected)

#pair[kre39,zyt10] #story[988]
This commit is contained in:
Kusal Ekanayake
2017-07-13 15:39:48 +12:00
parent 5ce34bed92
commit 78557a4536
7 changed files with 111 additions and 35 deletions
@@ -0,0 +1,40 @@
package seng302.server.messages;
import java.io.IOException;
import java.nio.channels.SocketChannel;
/**
* Created by kre39 on 12/07/17.
*/
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;
}
@Override
public int getSize() {
return 0;
}
/**
* Send this message as a stream of bytes
* @param outputStream The output stream to send the message
*/
public void send(SocketChannel outputStream) throws IOException {
System.out.println("Sending boat action type: " + actionType.toString());
allocateBuffer();
writeHeaderToBuffer();
// Write message fields
putUnsignedByte((byte) MESSAGE_VERSION);
putInt((int) BoatActionType.getBoatPacketType(actionType), 1);
writeCRC();
rewind();
outputStream.write(getBuffer());
}
}
@@ -0,0 +1,32 @@
package seng302.server.messages;
/**
* Created by kre39 on 12/07/17.
*/
public enum BoatActionType {
VMG,
SAILS_IN,
SAILS_OUT,
TACK_GYBE,
UPWIND,
DOWNWIND;
public static Short getBoatPacketType(BoatActionType type){
switch (type){
case VMG:
return 1;
case SAILS_IN:
return 2;
case SAILS_OUT:
return 3;
case TACK_GYBE:
return 4;
case UPWIND:
return 5;
case DOWNWIND:
return 6;
}
return 0;
}
}
@@ -16,7 +16,8 @@ public enum MessageType {
BOAT_LOCATION(37),
MARK_ROUNDING(38),
COURSE_WIND(44),
AVERAGE_WIND(47);
AVERAGE_WIND(47),
BOAT_ACTION(100);
private int code;