mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Fixed issues with correct protocol implementation.
#issue[64] #fix #testmanual
This commit is contained in:
@@ -5,19 +5,19 @@ package seng302.gameServer.messages;
|
||||
*/
|
||||
public class BoatActionMessage extends Message{
|
||||
private final MessageType MESSAGE_TYPE = MessageType.BOAT_ACTION;
|
||||
private final int MESSAGE_SIZE = 1;
|
||||
private final int MESSAGE_SIZE = 5;
|
||||
private BoatAction actionType;
|
||||
|
||||
public BoatActionMessage(BoatAction actionType) {
|
||||
public BoatActionMessage(BoatAction actionType, int sourceId) {
|
||||
this.actionType = actionType;
|
||||
setHeader(new Header(MessageType.BOAT_ACTION, 0, (short) 1)); // the second variable is the source id
|
||||
setHeader(new Header(MessageType.BOAT_ACTION, sourceId, (short) MESSAGE_SIZE)); // the second variable is the source id
|
||||
allocateBuffer();
|
||||
writeHeaderToBuffer();
|
||||
// Write message fields
|
||||
putInt(actionType.getValue(), 1);
|
||||
putInt(sourceId, 4);
|
||||
writeCRC();
|
||||
rewind();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,8 +4,8 @@ package seng302.gameServer.messages;
|
||||
public class RegistrationRequestMessage extends Message {
|
||||
private static int MESSAGE_LENGTH = 2;
|
||||
|
||||
public RegistrationRequestMessage(ClientType type){
|
||||
setHeader(new Header(MessageType.REGISTRATION_REQUEST, 1, (short) getSize()));
|
||||
public RegistrationRequestMessage(ClientType type, int clientID){
|
||||
setHeader(new Header(MessageType.REGISTRATION_REQUEST, clientID, (short) getSize()));
|
||||
|
||||
allocateBuffer();
|
||||
writeHeaderToBuffer();
|
||||
|
||||
@@ -4,12 +4,14 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import javafx.scene.paint.Color;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.Colors;
|
||||
import seng302.model.Limit;
|
||||
import seng302.model.mark.CompoundMark;
|
||||
import seng302.model.mark.Corner;
|
||||
@@ -139,14 +141,26 @@ public class XMLParser {
|
||||
Node currentBoat = boatsList.item(i);
|
||||
if (currentBoat.getNodeName().equals("Boat")) {
|
||||
// Boat boat = new Boat(currentBoat);
|
||||
BoatMeshType boatMeshType;
|
||||
try {
|
||||
boatMeshType = BoatMeshType.valueOf(XMLParser.getNodeAttributeString(currentBoat, "Type"));
|
||||
} catch (IllegalArgumentException e){
|
||||
boatMeshType = BoatMeshType.DINGHY;
|
||||
}
|
||||
Color color;
|
||||
try {
|
||||
color = Color.web(getNodeAttributeString(currentBoat, "Color"));
|
||||
} catch (NullPointerException npe) {
|
||||
color = Colors.getColor(new Random().nextInt(8));
|
||||
}
|
||||
ClientYacht yacht = new ClientYacht(
|
||||
BoatMeshType.valueOf(XMLParser.getNodeAttributeString(currentBoat, "Type")),
|
||||
boatMeshType,
|
||||
XMLParser.getNodeAttributeInt(currentBoat, "SourceID"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "HullNum"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "ShortName"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "BoatName"),
|
||||
XMLParser.getNodeAttributeString(currentBoat, "Country"));
|
||||
yacht.setColour(Color.web(getNodeAttributeString(currentBoat, "Color")));
|
||||
yacht.setColour(color);
|
||||
competingBoats.put(yacht.getSourceId(), yacht);
|
||||
}
|
||||
}
|
||||
@@ -195,17 +209,20 @@ public class XMLParser {
|
||||
*/
|
||||
private static List<Token> extractTokens(Element docEle) {
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
NodeList tokenList = docEle.getElementsByTagName("Tokens").item(0).getChildNodes();
|
||||
for (int i = 0; i < tokenList.getLength(); i++) {
|
||||
Node tokenNode = tokenList.item(i);
|
||||
if (tokenNode.getNodeName().equals("Token")) {
|
||||
String tokenType = getNodeAttributeString(tokenNode, "TokenType");
|
||||
Double lat = getNodeAttributeDouble(tokenNode, "TargetLat");
|
||||
Double lng = getNodeAttributeDouble(tokenNode, "TargetLng");
|
||||
tokens.add(new Token(TokenType.valueOf(tokenType), lat, lng));
|
||||
try {
|
||||
NodeList tokenList = docEle.getElementsByTagName("Tokens").item(0).getChildNodes();
|
||||
for (int i = 0; i < tokenList.getLength(); i++) {
|
||||
Node tokenNode = tokenList.item(i);
|
||||
if (tokenNode.getNodeName().equals("Token")) {
|
||||
String tokenType = getNodeAttributeString(tokenNode, "TokenType");
|
||||
Double lat = getNodeAttributeDouble(tokenNode, "TargetLat");
|
||||
Double lng = getNodeAttributeDouble(tokenNode, "TargetLng");
|
||||
tokens.add(new Token(TokenType.valueOf(tokenType), lat, lng));
|
||||
}
|
||||
}
|
||||
} catch (NullPointerException npe) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public class ClientToServerThread implements Runnable {
|
||||
* Sends a request to the server asking for a source ID
|
||||
*/
|
||||
private void sendRegistrationRequest() {
|
||||
RegistrationRequestMessage requestMessage = new RegistrationRequestMessage(ClientType.PLAYER);
|
||||
RegistrationRequestMessage requestMessage = new RegistrationRequestMessage(ClientType.PLAYER, clientId);
|
||||
|
||||
try {
|
||||
os.write(requestMessage.getBuffer());
|
||||
@@ -193,7 +193,6 @@ public class ClientToServerThread implements Runnable {
|
||||
private void processRegistrationResponse(StreamPacket packet){
|
||||
int sourceId = (int) Message.bytesToLong(Arrays.copyOfRange(packet.getPayload(), 0, 3));
|
||||
int statusCode = (int) Message.bytesToLong(Arrays.copyOfRange(packet.getPayload(), 4,5));
|
||||
|
||||
RegistrationResponseStatus status = RegistrationResponseStatus.getResponseStatus(statusCode);
|
||||
|
||||
if (status.equals(RegistrationResponseStatus.SUCCESS_PLAYING)){
|
||||
@@ -243,7 +242,7 @@ public class ClientToServerThread implements Runnable {
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendBoatActionMessage(new BoatActionMessage(BoatAction.DOWNWIND));
|
||||
sendBoatActionMessage(new BoatActionMessage(BoatAction.DOWNWIND, clientId));
|
||||
}
|
||||
}, 0, PACKET_SENDING_INTERVAL_MS
|
||||
);
|
||||
@@ -256,14 +255,14 @@ public class ClientToServerThread implements Runnable {
|
||||
new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
sendBoatActionMessage(new BoatActionMessage(BoatAction.UPWIND));
|
||||
sendBoatActionMessage(new BoatActionMessage(BoatAction.UPWIND, clientId));
|
||||
}
|
||||
}, 0, PACKET_SENDING_INTERVAL_MS
|
||||
);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sendBoatActionMessage(new BoatActionMessage(actionType));
|
||||
sendBoatActionMessage(new BoatActionMessage(actionType, clientId));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,7 +398,11 @@ public class GameClient {
|
||||
}
|
||||
|
||||
if (gameKeyBind.getKeyCode(KeyAction.SAILS_STATE) == e.getCode()) { // sails in/sails out
|
||||
socketThread.sendBoatAction(BoatAction.SAILS_IN);
|
||||
if (allBoatsMap.get(socketThread.getClientId()).getSailIn()) {
|
||||
socketThread.sendBoatAction(BoatAction.SAILS_OUT);
|
||||
} else {
|
||||
socketThread.sendBoatAction(BoatAction.SAILS_IN);
|
||||
}
|
||||
allBoatsMap.get(socketThread.getClientId()).toggleSail();
|
||||
} else if (gameKeyBind.getKeyCode(KeyAction.UPWIND) == e.getCode()
|
||||
|| gameKeyBind.getKeyCode(KeyAction.DOWNWIND) == e.getCode()) {
|
||||
|
||||
@@ -88,7 +88,6 @@ public class FinishScreenViewController implements Initializable {
|
||||
|
||||
public void switchToStartScreenView() {
|
||||
Sounds.playButtonClick();
|
||||
//TODO merge fix
|
||||
setContentPane("/views/StartScreenView.fxml");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user