Fixed race status sent in race status messages

#story[829]
This commit is contained in:
Michael Rausch
2017-04-30 17:46:56 +12:00
parent 1cf55f3e96
commit 6491efec4c
2 changed files with 9 additions and 11 deletions
@@ -24,7 +24,7 @@ public class ServerThread implements Runnable, Observer {
private final int RACE_START_STATUS_PERIOD = 1000/2; private final int RACE_START_STATUS_PERIOD = 1000/2;
private final int BOAT_LOCATION_PERIOD = 1000/5; private final int BOAT_LOCATION_PERIOD = 1000/5;
private final int PORT_NUMBER = 8085; private final int PORT_NUMBER = 8085;
private final int TIME_TILL_RACE_START = 20; private final int TIME_TILL_RACE_START = 20*1000;
private static final int LOG_LEVEL = 1; private static final int LOG_LEVEL = 1;
public ServerThread(String threadName){ public ServerThread(String threadName){
@@ -80,10 +80,9 @@ public class ServerThread implements Runnable, Observer {
RaceStatus raceStatus; RaceStatus raceStatus;
boolean thereAreBoatsNotFinished = false; boolean thereAreBoatsNotFinished = false;
for (Boat b : boats){ for (Boat b : boats){
if (raceStarted){ if (!raceStarted){
boatStatus = BoatStatus.RACING; boatStatus = BoatStatus.PRESTART;
thereAreBoatsNotFinished = true; thereAreBoatsNotFinished = true;
} }
else if(boatsFinished.get(b.getSourceID())){ else if(boatsFinished.get(b.getSourceID())){
@@ -103,7 +102,7 @@ public class ServerThread implements Runnable, Observer {
raceStatus = RaceStatus.STARTED; raceStatus = RaceStatus.STARTED;
} }
else{ else{
long currentTime = System.currentTimeMillis()/1000; long currentTime = System.currentTimeMillis();
long timeDifference = startTime - currentTime; long timeDifference = startTime - currentTime;
if (timeDifference > 60*3){ if (timeDifference > 60*3){
@@ -166,7 +165,7 @@ public class ServerThread implements Runnable, Observer {
Message raceStartStatusMessage = new RaceStartStatusMessage(server.getSequenceNumber(), startTime , 1, Message raceStartStatusMessage = new RaceStartStatusMessage(server.getSequenceNumber(), startTime , 1,
RaceStartNotificationType.SET_RACE_START_TIME); RaceStartNotificationType.SET_RACE_START_TIME);
try { try {
if (startTime < System.currentTimeMillis()/1000 && !raceStarted){ if (startTime < System.currentTimeMillis() && !raceStarted){
startRaceSim(); startRaceSim();
raceStarted = true; raceStarted = true;
serverLog("Race Started", 0); serverLog("Race Started", 0);
@@ -237,7 +236,7 @@ public class ServerThread implements Runnable, Observer {
// Wait for client to connect // Wait for client to connect
server.start(); server.start();
startTime = (System.currentTimeMillis()/1000) + TIME_TILL_RACE_START; startTime = System.currentTimeMillis() + TIME_TILL_RACE_START;
startSendingHeartbeats(); startSendingHeartbeats();
sendXml(); sendXml();
@@ -39,7 +39,7 @@ public class RaceStatusMessage extends Message{
*/ */
public RaceStatusMessage(long raceId, RaceStatus raceStatus, long expectedStartTime, WindDirection raceWindDirection, public RaceStatusMessage(long raceId, RaceStatus raceStatus, long expectedStartTime, WindDirection raceWindDirection,
long windSpeed, long numBoatsInRace, RaceType raceType, long sourceId, List<BoatSubMessage> boats){ long windSpeed, long numBoatsInRace, RaceType raceType, long sourceId, List<BoatSubMessage> boats){
currentTime = System.currentTimeMillis() / 1000L; currentTime = System.currentTimeMillis();
this.raceId = raceId; this.raceId = raceId;
this.raceStatus = raceStatus; this.raceStatus = raceStatus;
this.expectedStartTime = expectedStartTime; this.expectedStartTime = expectedStartTime;
@@ -71,10 +71,10 @@ public class RaceStatusMessage extends Message{
writeHeaderToBuffer(); writeHeaderToBuffer();
putByte((byte) MESSAGE_VERSION); putByte((byte) MESSAGE_VERSION);
putInt((int) currentTime, 6); putInt(currentTime, 6);
putInt((int) raceId, 4); putInt((int) raceId, 4);
putByte((byte) raceStatus.getCode()); putByte((byte) raceStatus.getCode());
putInt((int) expectedStartTime, 6); putInt(expectedStartTime, 6);
putInt((int) raceWindDirection.getCode(), 2); putInt((int) raceWindDirection.getCode(), 2);
putInt((int) windSpeed, 2); putInt((int) windSpeed, 2);
putByte((byte) numBoatsInRace); putByte((byte) numBoatsInRace);
@@ -87,7 +87,6 @@ public class RaceStatusMessage extends Message{
writeCRC(); writeCRC();
rewind(); rewind();
outputStream.write(getBuffer()); outputStream.write(getBuffer());
} }
} }