mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
MarkRounding Message now sent out correctly.
Added submark seqID attribute to each mark of a compound mark from parsing xml Added Rounding side attribute to each individual mark as read from the xml RoundingSide enum now has a method to get Enum from String literal Now store the closest mark to each yacht in each update for purpose of knowing which mark they round Minor code tidying, Added logger to serverToClientThread, removed 'serverLog' method removed obsolete code
This commit is contained in:
@@ -18,6 +18,8 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.Checksum;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import seng302.gameServer.server.messages.BoatActionType;
|
||||
import seng302.gameServer.server.messages.BoatLocationMessage;
|
||||
import seng302.gameServer.server.messages.BoatStatus;
|
||||
@@ -46,8 +48,7 @@ import seng302.utilities.XMLGenerator;
|
||||
*/
|
||||
public class ServerToClientThread implements Runnable, Observer {
|
||||
|
||||
private static final Integer LOG_LEVEL = 1;
|
||||
private static final Integer MAX_ID_ATTEMPTS = 10;
|
||||
private Logger logger = LoggerFactory.getLogger(ServerToClientThread.class);
|
||||
|
||||
private Thread thread;
|
||||
|
||||
@@ -57,11 +58,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
|
||||
private ByteArrayOutputStream crcBuffer;
|
||||
|
||||
private Boolean userIdentified = false;
|
||||
private Boolean connected = true;
|
||||
private Boolean updateClient = true;
|
||||
// private Boolean initialisedRace = true;
|
||||
|
||||
private Integer seqNo;
|
||||
private Integer sourceId;
|
||||
|
||||
@@ -120,13 +116,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
GameState.addPlayer(new Player(socket, yacht));
|
||||
}
|
||||
|
||||
static void serverLog(String message, int logLevel) {
|
||||
if (logLevel <= LOG_LEVEL) {
|
||||
System.out.println(
|
||||
"[SERVER " + LocalDateTime.now().toLocalTime().toString() + "] " + message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Observable o, Object arg) {
|
||||
if (arg != null) {
|
||||
@@ -172,20 +161,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
while (socket.isConnected()) {
|
||||
|
||||
try {
|
||||
//Perform a write if it is time to as delegated by the MainServerThread
|
||||
if (updateClient) {
|
||||
// TODO: 13/07/17 wmu16 - Write out game state - some function that would write all appropriate messages to this output stream
|
||||
// ChatterMessage chatterMessage = new ChatterMessage(4, 14, "Hello, it's me");
|
||||
// sendMessage(chatterMessage);
|
||||
// try {
|
||||
// GameState.outputState(os);
|
||||
// } catch (IOException e) {
|
||||
// System.out.println("IO error in server thread upon writing to output stream");
|
||||
// }
|
||||
// sendBoatLocationPackets();
|
||||
updateClient = false;
|
||||
}
|
||||
|
||||
crcBuffer = new ByteArrayOutputStream();
|
||||
sync1 = readByte();
|
||||
sync2 = readByte();
|
||||
@@ -219,7 +194,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
serverLog("Packet has been dropped", 1);
|
||||
logger.warn("Packet has been dropped", 1);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -257,27 +232,6 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
sendMessage(xmlMessage);
|
||||
}
|
||||
|
||||
public void updateClient() {
|
||||
sendBoatLocationPackets();
|
||||
updateClient = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tries to confirm the connection just accepted.
|
||||
* Sends ID, expects that ID echoed for confirmation,
|
||||
* if so, sends a confirmation packet back to that connection
|
||||
* Creates a player instance with that ID and this thread and adds it to the GameState
|
||||
* If not, close the socket and end the threads execution
|
||||
*
|
||||
* @param id the id to try and assign to the connection
|
||||
* @return A boolean indicating if it was a successful handshake
|
||||
*/
|
||||
private Boolean threeWayHandshake(Integer id) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void closeSocket() {
|
||||
try {
|
||||
socket.close();
|
||||
@@ -295,7 +249,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
crcBuffer.write(currentByte);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
serverLog("Socket read failed", 1);
|
||||
logger.warn("Socket read failed", 1);
|
||||
}
|
||||
if (currentByte == -1) {
|
||||
throw new Exception();
|
||||
@@ -324,7 +278,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
//serverLog("Player " + sourceId + " side socket disconnected", 1);
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
serverLog("Message send failed", 1);
|
||||
logger.warn("Message send failed", 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +288,7 @@ public class ServerToClientThread implements Runnable, Observer {
|
||||
}
|
||||
|
||||
|
||||
private void sendBoatLocationPackets() {
|
||||
public void sendBoatLocationPackets() {
|
||||
ArrayList<Yacht> yachts = new ArrayList<>(GameState.getYachts().values());
|
||||
for (Yacht yacht : yachts) {
|
||||
// System.out.println("[SERVER] Lat: " + yacht.getLocation().getLat() + " Lon: " + yacht.getLocation().getLng());
|
||||
|
||||
Reference in New Issue
Block a user