Fix: Server Persistence

This commit is contained in:
rubenpirreram
2026-05-10 20:09:19 +02:00
parent 6491eb3a85
commit 8106adb0d0
3 changed files with 143 additions and 78 deletions
@@ -4,6 +4,7 @@ package it.polimi.ingsw.gc14;
import it.polimi.ingsw.gc14.Controller.GameController;
import it.polimi.ingsw.gc14.Model.Game;
import it.polimi.ingsw.gc14.Model.GamePackage.GameStages;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
@@ -126,7 +127,7 @@ public class ServerLauncher {
BlockingQueue<NetworkEvent> actionQueue = new LinkedBlockingQueue<>();
GameController gameController = new GameController();
String IP;
boolean serverCrashed;
try {
IP=chooseNetworkInterface(new Scanner(System.in));
} catch (Exception e) {
@@ -136,7 +137,12 @@ public class ServerLauncher {
RMIServer serverRMI = new RMIServer(gameController, 1099, actionQueue, playerList,IP);
TCPServer serverTCP = new TCPServer(gameController, 8080, 8081,actionQueue, playerList);
ServerLauncher launcher = new ServerLauncher(actionQueue, gameController, serverRMI, serverTCP);
if(gameController.getModel() != null){
playerList.setLimit(gameController.getModel().getNPlayers());
serverCrashed = true;
} else {
serverCrashed = false;
}
playerList.setAction(()->{
new Thread(()->{
try {
@@ -149,8 +155,8 @@ public class ServerLauncher {
}).start();
});
serverRMI.start();
new Thread(()->{serverTCP.start();}).start();
serverRMI.start(serverCrashed);
new Thread(()->{serverTCP.start(serverCrashed);}).start();
}