//TODO: JVD MISSING

This commit is contained in:
rubenpirreram
2026-06-19 22:19:34 +02:00
parent 0d2250b68f
commit 85205ec912
17 changed files with 58 additions and 24 deletions
@@ -160,7 +160,7 @@ public class ClientLauncherTUI {
view.setLineReader(gameReader); view.setLineReader(gameReader);
} }
} }
//TODO
private boolean doLoginInner(ClientController controller, LineReader loginReader, LineReader ipReader) { private boolean doLoginInner(ClientController controller, LineReader loginReader, LineReader ipReader) {
String username, networkStr, ip; String username, networkStr, ip;
int nPlayers; int nPlayers;
@@ -33,11 +33,15 @@ import java.util.stream.Collectors;
* thread via {@link #doFirstEvent()}. * thread via {@link #doFirstEvent()}.
*/ */
public class GameEventProcessor { public class GameEventProcessor {
//TODO
private final BlockingQueue<NetworkEvent> actionQueue; private final BlockingQueue<NetworkEvent> actionQueue;
//TODO
private final GameController gameController; private final GameController gameController;
//TODO
private final LimitedMap<String, Boolean> playerList; private final LimitedMap<String, Boolean> playerList;
//TODO
private final CompositeClientBroadcaster broadcaster; private final CompositeClientBroadcaster broadcaster;
//TODO
private final SaveManager saveManager; private final SaveManager saveManager;
/** Single-thread executor used exclusively for the forfeit timer. Daemon so it does not block JVM shutdown. */ /** Single-thread executor used exclusively for the forfeit timer. Daemon so it does not block JVM shutdown. */
@@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @param <V> the type of mapped values. * @param <V> the type of mapped values.
*/ */
public class LimitedMap<K, V> implements Map<K, V> { public class LimitedMap<K, V> implements Map<K, V> {
//TODO
private final ConcurrentHashMap<K, V> map = new ConcurrentHashMap<>(); private final ConcurrentHashMap<K, V> map = new ConcurrentHashMap<>();
/** /**
@@ -165,7 +165,7 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf
this.effectType = effectTypeFromId(effectId); this.effectType = effectTypeFromId(effectId);
this.effectId = effectId; this.effectId = effectId;
} }
//TODO JV
private static EffectType effectTypeFromId(int effectId) { private static EffectType effectTypeFromId(int effectId) {
switch (effectId) { switch (effectId) {
case 2, 9, 7, 6, 5: return EffectType.ON_EVENT; case 2, 9, 7, 6, 5: return EffectType.ON_EVENT;
@@ -21,7 +21,6 @@ import java.util.*;
*/ */
public class DecksCreator { public class DecksCreator {
private DecksCreator() {}
/** /**
* Loads the tribe card deck for the specified era from the corresponding JSON resource file. * Loads the tribe card deck for the specified era from the corresponding JSON resource file.
@@ -11,8 +11,9 @@ import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer;
* broadcaster without knowing which protocols are active underneath. * broadcaster without knowing which protocols are active underneath.
*/ */
public class CompositeClientBroadcaster { public class CompositeClientBroadcaster {
//TODO
private final RMIServer rmiServer; private final RMIServer rmiServer;
//TODO
private final TCPServer tcpServer; private final TCPServer tcpServer;
/** /**
@@ -65,7 +65,7 @@ public enum EventType {
* Event used to notify that the game has ended. * Event used to notify that the game has ended.
*/ */
ENDED_GAME("Ended Game"); ENDED_GAME("Ended Game");
//TODO
private final String description; private final String description;
EventType(String description) { EventType(String description) {
this.description = description; this.description = description;
@@ -45,6 +45,7 @@ public class InterfaceResolver {
return socket.getLocalAddress().getHostAddress(); return socket.getLocalAddress().getHostAddress();
} }
} }
//TODO
private static boolean sameSubnet(InetAddress a, InetAddress b, int prefix) { private static boolean sameSubnet(InetAddress a, InetAddress b, int prefix) {
if (prefix < 0 || prefix > 32) return false; if (prefix < 0 || prefix > 32) return false;
int maskBits = prefix == 0 ? 0 : (0xFFFFFFFF << (32 - prefix)); int maskBits = prefix == 0 ? 0 : (0xFFFFFFFF << (32 - prefix));
@@ -52,6 +53,7 @@ public class InterfaceResolver {
int addrB = toInt(b.getAddress()) & maskBits; int addrB = toInt(b.getAddress()) & maskBits;
return addrA == addrB; return addrA == addrB;
} }
//TODO
private static int toInt(byte[] bytes) { private static int toInt(byte[] bytes) {
return ((bytes[0] & 0xFF) << 24) | return ((bytes[0] & 0xFF) << 24) |
((bytes[1] & 0xFF) << 16) | ((bytes[1] & 0xFF) << 16) |
@@ -25,10 +25,13 @@ import java.util.Map;
* always returns {@code false}. * always returns {@code false}.
*/ */
public class ApplyNextRound extends NetworkEvent { public class ApplyNextRound extends NetworkEvent {
//TODO
private final ArrayList<TribeCard> upperListTribeCards; private final ArrayList<TribeCard> upperListTribeCards;
//TODO
private final ArrayList<TribeCard> lowerListTribeCards; private final ArrayList<TribeCard> lowerListTribeCards;
//TODO
private final ArrayList<BuildingCard> upperListBuildingCards; private final ArrayList<BuildingCard> upperListBuildingCards;
//TODO
private final ArrayList<BuildingCard> lowerListBuildingCards; private final ArrayList<BuildingCard> lowerListBuildingCards;
@@ -14,14 +14,19 @@ import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer;
* Client RMI. Uses the methods exposed by the server RMI. * Client RMI. Uses the methods exposed by the server RMI.
*/ */
public class RMIClient implements IClient { public class RMIClient implements IClient {
//TODO
private final String host; private final String host;
//TODO
private final int port; private final int port;
//TODO
private IGameServer stub; private IGameServer stub;
//TODO
private final ClientController controller; private final ClientController controller;
//TODO
private final String myIp; private final String myIp;
//TODO
private String username; private String username;
//TODO
private volatile boolean running = false; private volatile boolean running = false;
/** Scheduler that fires ping() every {@value NetworkConfig#KEEPALIVE_INTERVAL_MS} ms. */ /** Scheduler that fires ping() every {@value NetworkConfig#KEEPALIVE_INTERVAL_MS} ms. */
@@ -26,16 +26,20 @@ import java.util.concurrent.*;
* </ul> * </ul>
*/ */
public class RMIHeartbeat { public class RMIHeartbeat {
//TODO
private String username; private String username;
//TODO
private final LimitedMap<String, Boolean> playerList; private final LimitedMap<String, Boolean> playerList;
//TODO
private final Map<String, IClientCallback> clients; private final Map<String, IClientCallback> clients;
//TODO
private final BlockingQueue<NetworkEvent> actionQueue; private final BlockingQueue<NetworkEvent> actionQueue;
/** Last time a ping was received from this client. */ /** Last time a ping was received from this client. */
private volatile long lastPingTime = System.currentTimeMillis(); private volatile long lastPingTime = System.currentTimeMillis();
//TODO
private volatile boolean running = true; private volatile boolean running = true;
//TODO
private final ScheduledExecutorService watchdog = private final ScheduledExecutorService watchdog =
Executors.newSingleThreadScheduledExecutor(r -> { Executors.newSingleThreadScheduledExecutor(r -> {
Thread t = new Thread(r, "rmi-watchdog-" + username); Thread t = new Thread(r, "rmi-watchdog-" + username);
@@ -33,8 +33,11 @@ import java.util.stream.Collectors;
* shared network event queue. * shared network event queue.
*/ */
public class RMIServer extends UnicastRemoteObject implements IGameServer { public class RMIServer extends UnicastRemoteObject implements IGameServer {
//TODO
private final String host; private final String host;
//TODO
private final GameController controller; private final GameController controller;
//TODO
private final int nPort; private final int nPort;
/** username → callback */ /** username → callback */
@@ -46,8 +49,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
* HeartbeatHandler in the TCP stack. * HeartbeatHandler in the TCP stack.
*/ */
private final Map<String, RMIHeartbeat> watchdogs = new ConcurrentHashMap<>(); private final Map<String, RMIHeartbeat> watchdogs = new ConcurrentHashMap<>();
//TODO
private final BlockingQueue<NetworkEvent> actionQueue; private final BlockingQueue<NetworkEvent> actionQueue;
//TODO
private final LimitedMap<String, Boolean> playerList; private final LimitedMap<String, Boolean> playerList;
@@ -18,7 +18,9 @@ import java.util.concurrent.TimeUnit;
* Client TCP. Sends and receives messages with the TCP server. * Client TCP. Sends and receives messages with the TCP server.
*/ */
public class TCPClient implements IClient { public class TCPClient implements IClient {
//TODO
private static final int PING = 1; private static final int PING = 1;
//TODO
private static final int PONG = 2; private static final int PONG = 2;
/** Socket TCP */ /** Socket TCP */
@@ -35,14 +37,17 @@ public class TCPClient implements IClient {
/** IP address of the server to connect to */ /** IP address of the server to connect to */
private final String hostname; private final String hostname;
//TODO
private boolean running; private boolean running;
/** TCP port */ /** TCP port */
private final int mainPort; private final int mainPort;
//TODO
private final int heartbeatPort; private final int heartbeatPort;
//TODO
private Socket heartbeatSocket; private Socket heartbeatSocket;
//TODO
private OutputStream heartbeatOut; private OutputStream heartbeatOut;
//TODO
private InputStream heartbeatIn; private InputStream heartbeatIn;
@@ -108,7 +113,7 @@ public class TCPClient implements IClient {
return ErrorType.SERVER_UNREACHABLE; return ErrorType.SERVER_UNREACHABLE;
} }
} }
//TODO
private void heartbeatLoop() { private void heartbeatLoop() {
ScheduledExecutorService sender = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService sender = Executors.newSingleThreadScheduledExecutor();
sender.scheduleAtFixedRate(() -> { sender.scheduleAtFixedRate(() -> {
@@ -21,7 +21,7 @@ public class ClientHandler implements Runnable {
* The username of the connected client on this handler * The username of the connected client on this handler
*/ */
private final String username; private final String username;
//TODO
private volatile boolean running; private volatile boolean running;
/** /**
@@ -16,10 +16,13 @@ import it.polimi.ingsw.gc14.Network.NetworkConfig;
* both the heartbeat connection and the main client connection are disconnected. * both the heartbeat connection and the main client connection are disconnected.
*/ */
public class HeartbeatHandler implements Runnable { public class HeartbeatHandler implements Runnable {
//TODO
private final String username; private final String username;
//TODO
private final Socket socket; private final Socket socket;
//TODO
private final InputStream in; private final InputStream in;
//TODO
private final OutputStream out; private final OutputStream out;
/** /**
@@ -34,10 +34,13 @@ import java.util.*;
* <p>Displays the final player rankings and a winner/game-over banner. * <p>Displays the final player rankings and a winner/game-over banner.
*/ */
public class LeaderboardFXMLController { public class LeaderboardFXMLController {
//TODO
@FXML private StackPane rootPane; @FXML private StackPane rootPane;
//TODO
@FXML private VBox mainVBox; @FXML private VBox mainVBox;
//TODO
@FXML private VBox rankingList; @FXML private VBox rankingList;
/** Client controller for fetching game state and sending actions. */ /** Client controller for fetching game state and sending actions. */
private ClientController controller; private ClientController controller;
/** Auto-hiding popup that shows detailed player card information. */ /** Auto-hiding popup that shows detailed player card information. */
@@ -163,9 +166,9 @@ public class LeaderboardFXMLController {
Label posLabel = new Label(position + "°"); Label posLabel = new Label(position + "°");
posLabel.setMinWidth(55); posLabel.setMinWidth(55);
String medalColor = switch (position) { String medalColor = switch (position) {
case 1 -> "#FFD700"; case 1 -> "#FFD700"; // oro
case 2 -> "#C0C0C0"; case 2 -> "#C0C0C0"; // argento
case 3 -> "#CD7F32"; case 3 -> "#CD7F32"; // bronzo
default -> "#EEEEEE"; default -> "#EEEEEE";
}; };
posLabel.setStyle("-fx-font-size: 28px; -fx-font-weight: bold; -fx-text-fill: " + medalColor + ";"); posLabel.setStyle("-fx-font-size: 28px; -fx-font-weight: bold; -fx-text-fill: " + medalColor + ";");
@@ -324,7 +327,7 @@ public class LeaderboardFXMLController {
scrollPane.setStyle("-fx-background: transparent; -fx-background-color: transparent;"); scrollPane.setStyle("-fx-background: transparent; -fx-background-color: transparent;");
Window window = rootPane.getScene().getWindow(); Window window = rootPane.getScene().getWindow();
scrollPane.setMaxHeight(window.getHeight() * 0.8); scrollPane.setMaxHeight(window.getHeight() * 0.8); // cap scroll area to 80% of window height
popupContent.getChildren().add(scrollPane); popupContent.getChildren().add(scrollPane);
popup.show(window, 0, 0); popup.show(window, 0, 0);
popup.getScene().setFill(Color.TRANSPARENT); popup.getScene().setFill(Color.TRANSPARENT);
@@ -7,13 +7,14 @@ package it.polimi.ingsw.gc14.View.TUI;
* <p>Each style stores the characters needed to draw table corners, * <p>Each style stores the characters needed to draw table corners,
* horizontal and vertical lines, and junctions. * horizontal and vertical lines, and junctions.
*/ */
@SuppressWarnings("ALL")
public enum BorderStyle { public enum BorderStyle {
/** /**
* Rounded Unicode border style. * Rounded Unicode border style.
*/ */
ROUNDED("","","","","","","","","","","","","",""); ROUNDED("","","","","","","","","","","","","","");
//TODO
private final String tl,tr,bl,br,h,v,ml,mr,mt,mb,x,sl,sr,sx; private final String tl,tr,bl,br,h,v,ml,mr,mt,mb,x,sl,sr,sx;
BorderStyle(String tl,String tr,String bl,String br, BorderStyle(String tl,String tr,String bl,String br,