mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Fixed an issue where buffers aren't being sent properly
Tags #Story[829]
This commit is contained in:
@@ -22,6 +22,6 @@ public class App extends Application
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new ServerThread("Racevision Test Server");
|
new ServerThread("Racevision Test Server");
|
||||||
//new Thread(new Simulator(1000)).run();
|
//new Thread(new Simulator(1000)).run();
|
||||||
launch(args);
|
//launch(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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 = 10;
|
private final int TIME_TILL_RACE_START = 20;
|
||||||
private static final int LOG_LEVEL = 1;
|
private static final int LOG_LEVEL = 1;
|
||||||
|
|
||||||
public ServerThread(String threadName){
|
public ServerThread(String threadName){
|
||||||
@@ -103,11 +103,22 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
raceStatus = RaceStatus.STARTED;
|
raceStatus = RaceStatus.STARTED;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
raceStatus = RaceStatus.PRESTART;
|
long currentTime = System.currentTimeMillis()/1000;
|
||||||
|
long timeDifference = startTime - currentTime;
|
||||||
|
|
||||||
|
if (timeDifference > 60*3){
|
||||||
|
raceStatus = RaceStatus.PRESTART;
|
||||||
|
}
|
||||||
|
else if (timeDifference > 60){
|
||||||
|
raceStatus = RaceStatus.WARNING;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
raceStatus = RaceStatus.PREPARATORY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
raceStatus = RaceStatus.NOTACTIVE;
|
raceStatus = RaceStatus.TERMINATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.EAST,
|
return new RaceStatusMessage(1, raceStatus, startTime, WindDirection.EAST,
|
||||||
@@ -171,21 +182,23 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
}, 0, RACE_START_STATUS_PERIOD);
|
}, 0, RACE_START_STATUS_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start sending race start status messages until race starts
|
||||||
|
*/
|
||||||
private void startSendingRaceStatusMessages(){
|
private void startSendingRaceStatusMessages(){
|
||||||
serverLog("Sending Race Status Messages", 0);
|
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
t.schedule(new TimerTask() {
|
t.schedule(new TimerTask() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Message statusMessage = getRaceStatusMessage();
|
Message raceStatusMessage = getRaceStatusMessage();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server.send(statusMessage);
|
server.send(raceStatusMessage);
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, 100, RACE_STATUS_PERIOD);
|
}, 0, RACE_STATUS_PERIOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -221,16 +234,18 @@ public class ServerThread implements Runnable, Observer {
|
|||||||
serverLog("Failed to bind socket: " + e.getMessage(), 0);
|
serverLog("Failed to bind socket: " + e.getMessage(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
startTime = (System.currentTimeMillis()/1000) + TIME_TILL_RACE_START;
|
|
||||||
|
|
||||||
// Wait for client to connect
|
// Wait for client to connect
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
|
startTime = (System.currentTimeMillis()/1000) + TIME_TILL_RACE_START;
|
||||||
|
|
||||||
startSendingHeartbeats();
|
startSendingHeartbeats();
|
||||||
sendXml();
|
sendXml();
|
||||||
startSendingRaceStartStatusMessages();
|
startSendingRaceStartStatusMessages();
|
||||||
startSendingRaceStatusMessages();
|
startSendingRaceStatusMessages();
|
||||||
|
|
||||||
|
//serverLog("Sending Race Status Messages", 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class StreamingServerSocket {
|
|||||||
//System.out.println(client);
|
//System.out.println(client);
|
||||||
message.send(client);
|
message.send(client);
|
||||||
|
|
||||||
|
|
||||||
seqNum++;
|
seqNum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public class BoatLocationMessage extends Message {
|
|||||||
|
|
||||||
heading = (heading + 180.0) % 360.0;
|
heading = (heading + 180.0) % 360.0;
|
||||||
|
|
||||||
long headingToSend = (long)((heading/360.0)*65535.0);
|
long headingToSend = (long)((heading/360.0)*49152.0);
|
||||||
|
|
||||||
putByte((byte) messageVersionNumber);
|
putByte((byte) messageVersionNumber);
|
||||||
putInt(time, 6);
|
putInt(time, 6);
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public class Heartbeat extends Message {
|
|||||||
putUnsignedInt(seqNo, 4);
|
putUnsignedInt(seqNo, 4);
|
||||||
|
|
||||||
writeCRC();
|
writeCRC();
|
||||||
|
rewind();
|
||||||
|
|
||||||
outputStream.write(getBuffer());
|
outputStream.write(getBuffer());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ public class MarkRoundingMessage extends Message{
|
|||||||
putByte((byte) markId);
|
putByte((byte) markId);
|
||||||
|
|
||||||
writeCRC();
|
writeCRC();
|
||||||
|
rewind();
|
||||||
|
|
||||||
outputStream.write(getBuffer());
|
outputStream.write(getBuffer());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ public enum MessageType {
|
|||||||
RACE_STATUS(12),
|
RACE_STATUS(12),
|
||||||
DISPLAY_TEXT_MESSAGE(20),
|
DISPLAY_TEXT_MESSAGE(20),
|
||||||
XML_MESSAGE(26),
|
XML_MESSAGE(26),
|
||||||
RACE_START_STATUS(20),
|
RACE_START_STATUS(27),
|
||||||
YACHT_EVENT_CODE(29),
|
YACHT_EVENT_CODE(29),
|
||||||
YACHT_ACTION_CODE(31),
|
YACHT_ACTION_CODE(31),
|
||||||
CHATTER_TEXT(36),
|
CHATTER_TEXT(36),
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ public class RaceStartStatusMessage extends Message {
|
|||||||
putUnsignedByte((byte) notificationType.getType());
|
putUnsignedByte((byte) notificationType.getType());
|
||||||
|
|
||||||
writeCRC();
|
writeCRC();
|
||||||
|
rewind();
|
||||||
|
|
||||||
outputStream.write(getBuffer());
|
outputStream.write(getBuffer());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ public class RaceStatusMessage extends Message{
|
|||||||
}
|
}
|
||||||
|
|
||||||
writeCRC();
|
writeCRC();
|
||||||
|
rewind();
|
||||||
|
|
||||||
|
|
||||||
outputStream.write(getBuffer());
|
outputStream.write(getBuffer());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public class XMLMessage extends Message{
|
|||||||
putBytes(content.getBytes());
|
putBytes(content.getBytes());
|
||||||
|
|
||||||
writeCRC();
|
writeCRC();
|
||||||
|
rewind();
|
||||||
|
|
||||||
outputStream.write(getBuffer());
|
outputStream.write(getBuffer());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user