Changed: Now Displays When a player is disconnected in GUI

This commit is contained in:
rubenpirreram
2026-05-27 20:48:14 +02:00
parent 06b6bc971f
commit 7fb5e7388a
5 changed files with 56 additions and 20 deletions
@@ -9,9 +9,7 @@ import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Totems;
import it.polimi.ingsw.gc14.Network.EventType;
import it.polimi.ingsw.gc14.Network.NetworkEvent;
import it.polimi.ingsw.gc14.Network.NetworkEvents.ApplyNextRound;
import it.polimi.ingsw.gc14.Network.NetworkEvents.EndedGame;
import it.polimi.ingsw.gc14.Network.NetworkEvents.TotemChoice;
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import it.polimi.ingsw.gc14.Network.RMI.Server.RMIServer;
import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
import it.polimi.ingsw.gc14.View.TUI.TUI;
@@ -111,19 +109,25 @@ public class ServerLauncher {
if(gameController.getModel()!=null && gameController.getModel().getCurrentState().getGameStage()!=GameStages.ENDED)
{
//if there is only one player ignore every event different by reconnection
if(disconnectionTimer!=null && event.getEventType() != EventType.RECONNECT_PLAYER)
if(disconnectionTimer!=null )
{
event.setIsError(true);
serverRMI.notifyAll(event);
serverTCP.notifyAll(event);
return false;
if(event.getEventType() != EventType.RECONNECT_PLAYER)
{
event.setIsError(true);
serverRMI.notifyAll(event);
serverTCP.notifyAll(event);
return false;
}else if(event.getEventType() != EventType.DISCONNECTED_PLAYER)
{
disconnectionTimer.cancel(true);
disconnectionTimer = null;
playerList.clear();
gameController.setModel(null);
System.out.println("\n!!! Player list is now empty, ready for a new game init !!!\n");
return true;
}
}
//Cancel the timer if another player is reconnected , so there are more than one player
if (event.getEventType() == EventType.RECONNECT_PLAYER && disconnectionTimer != null && !disconnectionTimer.isDone()) {
disconnectionTimer.cancel(false);
disconnectionTimer = null;
}
synchronized(gameController){
int roundPrev=gameController.getModel().getCurrentState().getRound();
//applies the event and set if is an error
@@ -132,19 +136,29 @@ public class ServerLauncher {
//if the event wasn't an error , it will be sent to players
if(!event.getIsError())
{
//Cancel the timer if another player is reconnected , so there are more than one player
if (event.getEventType() == EventType.RECONNECT_PLAYER && disconnectionTimer != null && !disconnectionTimer.isDone()) {
disconnectionTimer.cancel(false);
disconnectionTimer = null;
}
if(!this.gameSave() ){
System.out.println("\n!!! Save failed !!!\n");
}
if(event.getEventType().equals(EventType.DISCONNECTED_PLAYER)&& game.getCurrentState().getGameStage().equals(GameStages.WAITING))
{
playerList.remove(event.getUsername());
return true;
}else {
event.setData(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers());
if (event.getEventType().equals(EventType.TOTEM_CHOICE)) {
((TotemChoice) event).setAvailableTotems(gameController.getModel().getAvailableTotems());
} else if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && game.getCurrentState().getGameStage().equals(GameStages.WAITING)) {
playerList.remove(event.getUsername());
}
}
if (event.getEventType().equals(EventType.TOTEM_CHOICE)) {
((TotemChoice) event).setAvailableTotems(gameController.getModel().getAvailableTotems());
}else if (event.getEventType().equals(EventType.RECONNECT_PLAYER))
{
((ReconnectPlayer) event).setDisconnected(game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new)));
}else if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER))
{
((DisconnectedPlayer) event).setDisconnected(game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new)));
}
//if there is only one player the game will be suspended and starts the forfeit timer
if (event.getEventType().equals(EventType.DISCONNECTED_PLAYER) && playerList.values().stream().filter(x -> x).count() == 1&& game.getCurrentState().getGameStage() != GameStages.ENDED) {