mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
made server send appropriate racestatus flags in the race status packet #pair[mra106, ptg19] #story[1109]
This commit is contained in:
@@ -62,7 +62,7 @@ public class GameState implements Runnable {
|
||||
yachts = new HashMap<>();
|
||||
markOrder = new MarkOrder(); //This could be instantiated at some point with a select map?
|
||||
|
||||
startTime = System.currentTimeMillis() + 20000;
|
||||
startTime = System.currentTimeMillis() + 60000;
|
||||
|
||||
new Thread(this).start(); //Run the auto updates on the game state
|
||||
}
|
||||
@@ -166,6 +166,9 @@ public class GameState implements Runnable {
|
||||
public void update() {
|
||||
Long timeInterval = System.currentTimeMillis() - previousUpdateTime;
|
||||
previousUpdateTime = System.currentTimeMillis();
|
||||
if (System.currentTimeMillis() > startTime) {
|
||||
GameState.setCurrentStage(GameStages.RACING);
|
||||
}
|
||||
for (Yacht yacht : yachts.values()) {
|
||||
yacht.update(timeInterval);
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
|
||||
private XMLGenerator xml;
|
||||
|
||||
private static final int PRESTART_TIME = 60 * -1000;
|
||||
private static final int WARNING_TIME = 30 * -1000;
|
||||
private static final int PREPATORY_TIME = 10 * -1000;
|
||||
|
||||
|
||||
public ServerToClientThread(Socket socket) {
|
||||
this.socket = socket;
|
||||
seqNo = 0;
|
||||
@@ -211,8 +216,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO: 24/07/17 zyt10 - fix a logic here when a client disconnected
|
||||
// serverLog("ERROR OCCURRED, CLOSING SERVER CONNECTION: " + socket.getRemoteSocketAddress().toString(), 1);
|
||||
closeSocket();
|
||||
return;
|
||||
}
|
||||
@@ -368,12 +371,26 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
boatSubMessages.add(m);
|
||||
}
|
||||
|
||||
if (GameState.getCurrentStage() == GameStages.RACING) {
|
||||
raceStatus = RaceStatus.STARTED;
|
||||
long timeTillStart = System.currentTimeMillis() - GameState.getStartTime();
|
||||
|
||||
if (GameState.getCurrentStage() == GameStages.LOBBYING) {
|
||||
raceStatus = RaceStatus.PRESTART;
|
||||
} else if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
|
||||
raceStatus = RaceStatus.PRESTART;
|
||||
|
||||
if (timeTillStart > WARNING_TIME) {
|
||||
raceStatus = RaceStatus.WARNING;
|
||||
}
|
||||
|
||||
if (timeTillStart > PREPATORY_TIME) {
|
||||
raceStatus = RaceStatus.PREPARATORY;
|
||||
}
|
||||
} else {
|
||||
raceStatus = RaceStatus.WARNING;
|
||||
raceStatus = RaceStatus.STARTED;
|
||||
}
|
||||
|
||||
System.out.println("raceStatus.ger = " + raceStatus.getCode());
|
||||
|
||||
sendMessage(new RaceStatusMessage(1, raceStatus, GameState.getStartTime(), GameState.getWindDirection(),
|
||||
GameState.getWindSpeedMMS().longValue(), GameState.getPlayers().size(),
|
||||
RaceType.MATCH_RACE, 1, boatSubMessages));
|
||||
|
||||
@@ -59,6 +59,7 @@ public class StreamParser {
|
||||
long currentTime = bytesToLong(Arrays.copyOfRange(payload, 1, 7));
|
||||
long raceId = bytesToLong(Arrays.copyOfRange(payload, 7, 11));
|
||||
int raceStatus = payload[11];
|
||||
System.out.println(raceStatus);
|
||||
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
|
||||
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
|
||||
long rawWindSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
|
||||
|
||||
Reference in New Issue
Block a user