Skip to content
Snippets Groups Projects
Commit 35328e73 authored by Elrabu's avatar Elrabu
Browse files

eb093: update: improved server class

parent 66ddcf21
No related branches found
No related tags found
5 merge requests!74V1,!73Initial commit,!71Merge DataBase into Development,!54Update: coreMaps.json (added new maps),!53Multiplayer
......@@ -36,7 +36,6 @@ public class ConnectionHandler {
ConnectionThread connectionthread = new ConnectionThread(client);
connectionthread.start();
}
private static class ConnectionThread extends Thread {
......
......@@ -78,16 +78,12 @@ public class Server {
}
public synchronized void run() {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(() -> {
try {
BufferedReader localIn = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
PrintWriter localOut = new PrintWriter(clientSocket.getOutputStream(), true);
String inputLine = localIn.readLine();
if (inputLine != null) {
String inputLine;
while ((inputLine = localIn.readLine()) != null) {
// Assuming that the input line is a comma-separated list of integers
String[] coordinates = inputLine.split(",");
cords = new int[coordinates.length];
......@@ -157,27 +153,14 @@ public class Server {
localOut.println(Arrays.toString(returncords));
localOut.flush();
}
log.info("Player (X Y) : " + px + " " + py + " Attacking : " + playerAttacking + " direction : " + playerWalkDirection + " HP: " + playerHealth);
log.info("Enemy (X Y) : " + enemyx + " " + enemyy + " Attacking : " + enemyAttacking + " direction : " + enemyWalkDirection + " HP: " + enemyHealth);
log.info("Player (X Y) : " + px + " " + py + " Attacking : " + playerAttacking + " direction : " + playerWalkDirection + " HP: " + playerHealth);
log.info("Enemy (X Y) : " + enemyx + " " + enemyy + " Attacking : " + enemyAttacking + " direction : " + enemyWalkDirection + " HP: " + enemyHealth);
//check if server was shut down:W
if (!isServerRunning) {
executorService.shutdown();
try {
if (!executorService.awaitTermination(5, TimeUnit.SECONDS)) {
executorService.shutdownNow();
}
} catch (InterruptedException e) {
log.error("Error waiting for executor service termination: " + e.getMessage());
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}, 0, 50, TimeUnit.MILLISECONDS);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment