WIP. Probably need to cherry pick stuff out of here.
Added ClientConnection and server-side handshake. Added MessageSerialiser and Deserialiser. #story[1095]
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
package mock.model;
|
||||
|
||||
import network.Messages.BoatLocation;
|
||||
import network.Messages.BoatStatus;
|
||||
import network.Messages.*;
|
||||
import network.Messages.Enums.BoatLocationDeviceEnum;
|
||||
import network.Messages.LatestMessages;
|
||||
import network.Messages.RaceStatus;
|
||||
import network.Utils.AC35UnitConverter;
|
||||
import shared.model.Bearing;
|
||||
import shared.model.CompoundMark;
|
||||
@@ -21,10 +18,6 @@ public class RaceServer {
|
||||
private MockRace race;
|
||||
private LatestMessages latestMessages;
|
||||
|
||||
/**
|
||||
* The sequence number of the latest RaceStatus message sent or received.
|
||||
*/
|
||||
private int raceStatusSequenceNumber = 1;
|
||||
|
||||
/**
|
||||
* The sequence number of the latest BoatLocation message sent or received.
|
||||
@@ -39,10 +32,31 @@ public class RaceServer {
|
||||
|
||||
|
||||
/**
|
||||
* Parses an individual marker boat, and sends it to mockOutput.
|
||||
* @param mark The marker boat to parse.
|
||||
* Parses the race to create a snapshot, and places it in latestMessages.
|
||||
*/
|
||||
private void parseIndividualMark(Mark mark) {
|
||||
public void parseSnapshot() {
|
||||
|
||||
List<AC35Data> snapshotMessages = new ArrayList<>();
|
||||
|
||||
//Parse the boat locations.
|
||||
snapshotMessages.addAll(parseBoatLocations());
|
||||
|
||||
//Parse the marks.
|
||||
snapshotMessages.addAll(parseMarks());
|
||||
|
||||
//Parse the race status.
|
||||
snapshotMessages.add(parseRaceStatus());
|
||||
|
||||
latestMessages.setSnapshot(snapshotMessages);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses an individual marker boat, and returns it.
|
||||
* @param mark The marker boat to parse.
|
||||
* @return The BoatLocation message.
|
||||
*/
|
||||
private BoatLocation parseIndividualMark(Mark mark) {
|
||||
//Create message.
|
||||
BoatLocation boatLocation = new BoatLocation(
|
||||
mark.getSourceID(),
|
||||
@@ -57,13 +71,17 @@ public class RaceServer {
|
||||
//Iterates the sequence number.
|
||||
this.boatLocationSequenceNumber++;
|
||||
|
||||
this.latestMessages.setBoatLocation(boatLocation);
|
||||
return boatLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the compound marker boats through mock output.
|
||||
* Parse the compound marker boats, and returns a list of BoatLocation messages.
|
||||
* @return BoatLocation messages for each mark.
|
||||
*/
|
||||
public void parseMarks() {
|
||||
private List<BoatLocation> parseMarks() {
|
||||
|
||||
List<BoatLocation> markLocations = new ArrayList<>(race.getCompoundMarks().size());
|
||||
|
||||
for (CompoundMark compoundMark : race.getCompoundMarks()) {
|
||||
|
||||
//Get the individual marks from the compound mark.
|
||||
@@ -72,31 +90,40 @@ public class RaceServer {
|
||||
|
||||
//If they aren't null, parse them (some compound marks only have one mark).
|
||||
if (mark1 != null) {
|
||||
this.parseIndividualMark(mark1);
|
||||
markLocations.add(this.parseIndividualMark(mark1));
|
||||
}
|
||||
|
||||
if (mark2 != null) {
|
||||
this.parseIndividualMark(mark2);
|
||||
markLocations.add(this.parseIndividualMark(mark2));
|
||||
}
|
||||
}
|
||||
|
||||
return markLocations;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parse the boats in the race, and send it to mockOutput.
|
||||
* Parse the boats in the race, and returns all of their BoatLocation messages.
|
||||
* @return List of BoatLocation messages, for each boat.
|
||||
*/
|
||||
public void parseBoatLocations() {
|
||||
private List<BoatLocation> parseBoatLocations() {
|
||||
|
||||
List<BoatLocation> boatLocations = new ArrayList<>(race.getBoats().size());
|
||||
|
||||
//Parse each boat.
|
||||
for (MockBoat boat : race.getBoats()) {
|
||||
this.parseIndividualBoatLocation(boat);
|
||||
boatLocations.add(this.parseIndividualBoatLocation(boat));
|
||||
}
|
||||
|
||||
return boatLocations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an individual boat, and sends it to mockOutput.
|
||||
* Parses an individual boat, and returns it.
|
||||
* @param boat The boat to parse.
|
||||
* @return The BoatLocation message.
|
||||
*/
|
||||
private void parseIndividualBoatLocation(MockBoat boat) {
|
||||
private BoatLocation parseIndividualBoatLocation(MockBoat boat) {
|
||||
|
||||
BoatLocation boatLocation = new BoatLocation(
|
||||
boat.getSourceID(),
|
||||
@@ -111,16 +138,17 @@ public class RaceServer {
|
||||
//Iterates the sequence number.
|
||||
this.boatLocationSequenceNumber++;
|
||||
|
||||
this.latestMessages.setBoatLocation(boatLocation);
|
||||
return boatLocation;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Parses the race status, and sends it to mockOutput.
|
||||
* Parses the race status, and returns it.
|
||||
* @return The race status message.
|
||||
*/
|
||||
public void parseRaceStatus() {
|
||||
private RaceStatus parseRaceStatus() {
|
||||
|
||||
//A race status message contains a list of boat statuses.
|
||||
List<BoatStatus> boatStatuses = new ArrayList<>();
|
||||
@@ -151,6 +179,6 @@ public class RaceServer {
|
||||
race.getRaceType(),
|
||||
boatStatuses);
|
||||
|
||||
this.latestMessages.setRaceStatus(raceStatus);
|
||||
return raceStatus;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user