Graphical disconnection

This commit is contained in:
2026-05-27 20:09:48 +02:00
parent eec85c5a3f
commit 06b6bc971f
6 changed files with 21 additions and 5 deletions
@@ -21,6 +21,7 @@ public class MiniModel implements Serializable {
public ArrayList<TribeCard> lowerListTribeCards;
public ArrayList<BuildingCard> upperListBuildingCards;
public ArrayList<BuildingCard> lowerListBuildingCards;
public ArrayList<String> disconnectedPlayers;
/**
* Map associating each occupied slot with the corresponding player.
@@ -64,6 +65,7 @@ public class MiniModel implements Serializable {
this.lowerListTribeCards = lowerListTribeCards;
this.upperListBuildingCards = upperListBuildingCards;
this.lowerListBuildingCards = lowerListBuildingCards;
this.disconnectedPlayers = new ArrayList<>();
}
/**
@@ -80,7 +82,7 @@ public class MiniModel implements Serializable {
OrderLogicCard orderLogicCard,
CurrentState currentState,
List<Player> players,
List<Totems> availableTotems,ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards) {
List<Totems> availableTotems,ArrayList<TribeCard> upperListTribeCards,ArrayList<TribeCard>lowerListTribeCards,ArrayList<BuildingCard> upperListBuildingCards,ArrayList<BuildingCard>lowerListBuildingCards, ArrayList<String> disconnectedPlayers) {
this.slotPlayerMap = slotPlayerMap;
this.orderLogicCard = orderLogicCard;
@@ -92,6 +94,7 @@ public class MiniModel implements Serializable {
this.lowerListTribeCards = lowerListTribeCards;
this.upperListBuildingCards = upperListBuildingCards;
this.lowerListBuildingCards = lowerListBuildingCards;
this.disconnectedPlayers = disconnectedPlayers;
setPlayers(players);
}
@@ -181,4 +184,9 @@ public class MiniModel implements Serializable {
}
return -1;
}
//TODO
public void setDisconnectedPlayers (ArrayList<String> disconnectedPlayers){
this.disconnectedPlayers=disconnectedPlayers;
}
}
@@ -15,11 +15,14 @@ import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.rmi.*;
import java.util.stream.Collectors;
/**
@@ -127,7 +130,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
System.out.println("Reconnected player: " + username);
startWatchdog(username);
Game game = controller.getModel();
callback.onGameInit(new MiniModel(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding()));
callback.onGameInit(new MiniModel(game.getSlotMap(), game.orderLogicCard, game.getCurrentState(), game.getPlayers(), game.getAvailableTotems(), game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))));
System.out.println("Model sent: " + username);
actionQueue.add(new ReconnectPlayer(username));
return null;
@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
/**
* TCP server responsible for accepting client connections,
@@ -265,7 +266,7 @@ public class TCPServer {
game.getCurrentState(),
game.getPlayers(),
game.getAvailableTotems(),
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding()
game.getUpperListTribeCards(), game.getLowerListTribeCards(), game.getUpperListBuilding(), game.getLowerListBuilding(), game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new))
));
Thread thread = new Thread(handler);
@@ -24,6 +24,7 @@ import java.rmi.RemoteException;
import java.util.*;
import java.util.concurrent.*;
import java.net.*;
import java.util.stream.Collectors;
/**
@@ -274,7 +275,7 @@ public class ServerLauncher {
MiniModel miniModel;
synchronized (gameController) {
Game game = gameController.getModel();
miniModel= new MiniModel(game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), game.getAvailableTotems(),game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding());
miniModel= new MiniModel(game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers(), game.getAvailableTotems(),game.getUpperListTribeCards(),game.getLowerListTribeCards(),game.getUpperListBuilding(),game.getLowerListBuilding(), game.disconnetedPlayers.entrySet().stream().filter(Map.Entry::getValue).map(x -> x.getKey().getUserName()).collect(Collectors.toCollection(ArrayList::new)));
}
serverRMI.notifyAll(miniModel);
serverTCP.notifyAll(miniModel);
@@ -324,6 +324,9 @@ public class MainFXMLController {
tt.play();
}
}
if (controller.miniModel.disconnectedPlayers.contains(player.getUserName())) {
usernameLabel.setText(usernameLabel.getText() + " (crash)");
}
headerRow.getChildren().addAll(totem, usernameLabel);
// Riga 2: cibo + prestigio + building
@@ -75,7 +75,7 @@ public class TotemFXMLController {
if (myTurn) {
turnBanner.setText("✦ It's your turn to choose ✦");
turnBanner.setStyle(
"-fx-font-family: 'Cinzel'; -fx-font-size: 13; -fx-letter-spacing: 3;" +
"-fx-font-family: 'Cinzel'; -fx-font-size: 13; -fx-font-weight: 'bold'; -fx-letter-spacing: 3;" +
"-fx-text-fill: #000000;" +
"-fx-background-color: linear-gradient(to right, #f4c05a, #c8791a, #f4c05a);" +
"-fx-border-color: #000000; -fx-border-width: 1;" +