diff --git a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java index 1f9f271..099ff0b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java +++ b/src/main/java/it/polimi/ingsw/gc14/ClientLauncherTUI.java @@ -160,7 +160,14 @@ public class ClientLauncherTUI { view.setLineReader(gameReader); } } - //TODO + /** + * Reads login fields from the terminal and connects to the server. + * + * @param controller the client controller to connect. + * @param loginReader line reader used for username, player count, and network type. + * @param ipReader line reader with localhost auto-complete for the server IP. + * @return {@code true} on successful connection; {@code false} if input is invalid or connection fails. + */ private boolean doLoginInner(ClientController controller, LineReader loginReader, LineReader ipReader) { String username, networkStr, ip; int nPlayers; diff --git a/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java b/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java index b01e6ee..b136c2f 100644 --- a/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java +++ b/src/main/java/it/polimi/ingsw/gc14/GameEventProcessor.java @@ -33,15 +33,15 @@ import java.util.stream.Collectors; * thread via {@link #doFirstEvent()}. */ public class GameEventProcessor { - //TODO + /** Queue from which incoming client events are consumed one at a time. */ private final BlockingQueue actionQueue; - //TODO + /** Server-side game controller; all model mutations go through this. */ private final GameController gameController; - //TODO + /** Shared map tracking each player's online status ({@code true} = online). */ private final LimitedMap playerList; - //TODO + /** Broadcaster used to push events and model snapshots to all connected clients. */ private final CompositeClientBroadcaster broadcaster; - //TODO + /** Persists and deletes game save files. */ private final SaveManager saveManager; /** Single-thread executor used exclusively for the forfeit timer. Daemon so it does not block JVM shutdown. */ @@ -340,7 +340,6 @@ public class GameEventProcessor { } } - // ── Utilities ───────────────────────────────────────────────────────────── /** * Returns the number of players currently marked as online in the player list. diff --git a/src/main/java/it/polimi/ingsw/gc14/LimitedMap.java b/src/main/java/it/polimi/ingsw/gc14/LimitedMap.java index 4064109..203e68e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/LimitedMap.java +++ b/src/main/java/it/polimi/ingsw/gc14/LimitedMap.java @@ -14,7 +14,7 @@ import java.util.concurrent.ConcurrentHashMap; * @param the type of mapped values. */ public class LimitedMap implements Map { - //TODO + /** The underlying thread-safe hash map storing all key-value pairs. */ private final ConcurrentHashMap map = new ConcurrentHashMap<>(); /** diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java index a3ccde9..ee8fe8d 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Cards/BuildingCard.java @@ -165,7 +165,13 @@ public class BuildingCard extends PlayableCard implements Cloneable , BuildingEf this.effectType = effectTypeFromId(effectId); this.effectId = effectId; } - //TODO JV + /** + * Maps a building effect identifier to its corresponding {@link EffectType}. + * + * @param effectId the effect identifier to resolve. + * @return the {@link EffectType} for the given identifier. + * @throws IllegalArgumentException if {@code effectId} does not correspond to any known effect type. + */ private static EffectType effectTypeFromId(int effectId) { switch (effectId) { case 2, 9, 7, 6, 5: return EffectType.ON_EVENT; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java b/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java index fbfa271..0966f4b 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/CompositeClientBroadcaster.java @@ -11,9 +11,9 @@ import it.polimi.ingsw.gc14.Network.TCP.Server.TCPServer; * broadcaster without knowing which protocols are active underneath. */ public class CompositeClientBroadcaster { - //TODO + /** RMI transport used to reach RMI-connected clients. */ private final RMIServer rmiServer; - //TODO + /** TCP transport used to reach TCP-connected clients. */ private final TCPServer tcpServer; /** diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java index bd7f3d7..2292f71 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/EventType.java @@ -65,7 +65,7 @@ public enum EventType { * Event used to notify that the game has ended. */ ENDED_GAME("Ended Game"); - //TODO + /** Human-readable label for this event type, returned by {@link #toString()}. */ private final String description; EventType(String description) { this.description = description; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/InterfaceResolver.java b/src/main/java/it/polimi/ingsw/gc14/Network/InterfaceResolver.java index 0da622b..6258a86 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/InterfaceResolver.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/InterfaceResolver.java @@ -45,7 +45,14 @@ public class InterfaceResolver { return socket.getLocalAddress().getHostAddress(); } } - //TODO + /** + * Returns {@code true} if {@code a} and {@code b} share the same subnet given a CIDR {@code prefix} length. + * + * @param a first IPv4 address. + * @param b second IPv4 address. + * @param prefix CIDR prefix length (0–32). + * @return {@code true} if both addresses belong to the same subnet. + */ private static boolean sameSubnet(InetAddress a, InetAddress b, int prefix) { if (prefix < 0 || prefix > 32) return false; int maskBits = prefix == 0 ? 0 : (0xFFFFFFFF << (32 - prefix)); @@ -53,7 +60,12 @@ public class InterfaceResolver { int addrB = toInt(b.getAddress()) & maskBits; return addrA == addrB; } - //TODO + /** + * Converts a 4-byte big-endian IPv4 address array to a signed 32-bit integer. + * + * @param bytes the 4-byte address array. + * @return the corresponding signed integer. + */ private static int toInt(byte[] bytes) { return ((bytes[0] & 0xFF) << 24) | ((bytes[1] & 0xFF) << 16) | diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/ApplyNextRound.java b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/ApplyNextRound.java index 57b1d3d..685f938 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/ApplyNextRound.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/NetworkEvents/ApplyNextRound.java @@ -25,13 +25,13 @@ import java.util.Map; * always returns {@code false}. */ public class ApplyNextRound extends NetworkEvent { - //TODO + /** Tribe cards shown in the upper row of the board for the new round. */ private final ArrayList upperListTribeCards; - //TODO + /** Tribe cards shown in the lower row of the board for the new round. */ private final ArrayList lowerListTribeCards; - //TODO + /** Building cards shown in the upper row of the board for the new round. */ private final ArrayList upperListBuildingCards; - //TODO + /** Building cards shown in the lower row of the board for the new round. */ private final ArrayList lowerListBuildingCards; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java index 01ea3e2..309366e 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Client/RMIClient.java @@ -14,19 +14,19 @@ import it.polimi.ingsw.gc14.Network.RMI.Common.IGameServer; * Client RMI. Uses the methods exposed by the server RMI. */ public class RMIClient implements IClient { - //TODO + /** Hostname or IP address of the RMI server. */ private final String host; - //TODO + /** Port of the RMI registry. */ private final int port; - //TODO + /** Remote stub obtained from the RMI registry after a successful connection. */ private IGameServer stub; - //TODO + /** Client-side controller that receives and applies incoming game events. */ private final ClientController controller; - //TODO + /** Local IP address advertised to the RMI runtime so callbacks are routed correctly. */ private final String myIp; - //TODO + /** Username of the currently connected player; set during {@link #connect}. */ private String username; - //TODO + /** {@code true} while the heartbeat loop is active; set to {@code false} on disconnect. */ private volatile boolean running = false; /** Scheduler that fires ping() every {@value NetworkConfig#KEEPALIVE_INTERVAL_MS} ms. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIHeartbeat.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIHeartbeat.java index 78c7d56..40a7f50 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIHeartbeat.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIHeartbeat.java @@ -26,20 +26,20 @@ import java.util.concurrent.*; * */ public class RMIHeartbeat { - //TODO + /** Username of the client monitored by this watchdog. */ private String username; - //TODO + /** Shared map used to mark the player as offline on timeout. */ private final LimitedMap playerList; - //TODO + /** Registry of active RMI callbacks; the entry for this player is removed on disconnect. */ private final Map clients; - //TODO + /** Shared event queue; a {@link DisconnectedPlayer} event is posted here on timeout. */ private final BlockingQueue actionQueue; /** Last time a ping was received from this client. */ private volatile long lastPingTime = System.currentTimeMillis(); - //TODO + /** {@code true} while the watchdog is running; set to {@code false} on first disconnect. */ private volatile boolean running = true; - //TODO + /** Single-thread executor that periodically checks whether the silence threshold has been exceeded. */ private final ScheduledExecutorService watchdog = Executors.newSingleThreadScheduledExecutor(r -> { Thread t = new Thread(r, "rmi-watchdog-" + username); diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java index 8d3ffee..fe8b9fb 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/RMI/Server/RMIServer.java @@ -33,11 +33,11 @@ import java.util.stream.Collectors; * shared network event queue. */ public class RMIServer extends UnicastRemoteObject implements IGameServer { - //TODO + /** Hostname or IP address exposed by the RMI runtime ({@code java.rmi.server.hostname}). */ private final String host; - //TODO + /** Server-side game controller; all model access is synchronized on this object. */ private final GameController controller; - //TODO + /** Port on which the RMI registry is bound. */ private final int nPort; /** username → callback */ @@ -49,9 +49,9 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer { * HeartbeatHandler in the TCP stack. */ private final Map watchdogs = new ConcurrentHashMap<>(); - //TODO + /** Shared queue to which player actions are added for sequential processing. */ private final BlockingQueue actionQueue; - //TODO + /** Shared map tracking each player's connection status ({@code true} = online). */ private final LimitedMap playerList; diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java index b0783f3..bcdc7c8 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Client/TCPClient.java @@ -18,9 +18,9 @@ import java.util.concurrent.TimeUnit; * Client TCP. Sends and receives messages with the TCP server. */ public class TCPClient implements IClient { - //TODO + /** Byte value sent by the client to signal it is still alive. */ private static final int PING = 1; - //TODO + /** Byte value expected from the server in response to a {@link #PING}. */ private static final int PONG = 2; /** Socket TCP */ @@ -37,17 +37,17 @@ public class TCPClient implements IClient { /** IP address of the server to connect to */ private final String hostname; - //TODO + /** {@code true} while the connection is active; set to {@code false} on disconnect. */ private boolean running; /** TCP port */ private final int mainPort; - //TODO + /** TCP port dedicated to heartbeat communication. */ private final int heartbeatPort; - //TODO + /** Socket used exclusively for heartbeat ping/pong exchange. */ private Socket heartbeatSocket; - //TODO + /** Output stream of {@link #heartbeatSocket}, used to write {@link #PING} bytes. */ private OutputStream heartbeatOut; - //TODO + /** Input stream of {@link #heartbeatSocket}, used to read {@link #PONG} bytes. */ private InputStream heartbeatIn; @@ -113,7 +113,11 @@ public class TCPClient implements IClient { return ErrorType.SERVER_UNREACHABLE; } } - //TODO + /** + * Sends a {@link #PING} byte to the server every 3 seconds and waits for a {@link #PONG} reply. + * If no reply arrives within {@value NetworkConfig#SILENCE_THRESHOLD_MS} ms, the server is + * considered unreachable and {@link #disconnect()} is called. + */ private void heartbeatLoop() { ScheduledExecutorService sender = Executors.newSingleThreadScheduledExecutor(); sender.scheduleAtFixedRate(() -> { diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java index 2a2c4e2..a1252e0 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/ClientHandler.java @@ -21,7 +21,7 @@ public class ClientHandler implements Runnable { * The username of the connected client on this handler */ private final String username; - //TODO + /** {@code true} while the handler is actively reading from the socket; set to {@code false} on disconnect. */ private volatile boolean running; /** diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/HeartbeatHandler.java b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/HeartbeatHandler.java index 0d3e272..097f528 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/HeartbeatHandler.java +++ b/src/main/java/it/polimi/ingsw/gc14/Network/TCP/Server/HeartbeatHandler.java @@ -16,13 +16,13 @@ import it.polimi.ingsw.gc14.Network.NetworkConfig; * both the heartbeat connection and the main client connection are disconnected. */ public class HeartbeatHandler implements Runnable { - //TODO + /** Username of the client associated with this heartbeat connection. */ private final String username; - //TODO + /** Dedicated socket used solely for heartbeat ping/pong exchange. */ private final Socket socket; - //TODO + /** Input stream of {@link #socket} used to receive {@code PING} bytes from the client. */ private final InputStream in; - //TODO + /** Output stream of {@link #socket} used to send {@code PONG} bytes back to the client. */ private final OutputStream out; /** diff --git a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LeaderboardFXMLController.java b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LeaderboardFXMLController.java index 6d3f65f..d21b569 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/GUI/LeaderboardFXMLController.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/GUI/LeaderboardFXMLController.java @@ -34,11 +34,11 @@ import java.util.*; *

Displays the final player rankings and a winner/game-over banner. */ public class LeaderboardFXMLController { - //TODO + /** Root pane of the leaderboard scene; used to set the background and anchor the popup. */ @FXML private StackPane rootPane; - //TODO + /** Main vertical container holding the outcome label and ranking rows. */ @FXML private VBox mainVBox; - //TODO + /** Vertical list populated with one {@code HBox} row per ranked player. */ @FXML private VBox rankingList; /** Client controller for fetching game state and sending actions. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java b/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java index d7b26e1..952c188 100644 --- a/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java +++ b/src/main/java/it/polimi/ingsw/gc14/View/TUI/BorderStyle.java @@ -14,7 +14,7 @@ public enum BorderStyle { * Rounded Unicode border style. */ ROUNDED("╭","╮","╰","╯","─","│","├","┤","┬","┴","┼","├","┤","┼"); - //TODO + /** Corner (tl/tr/bl/br), line (h/v), outer junction (ml/mr/mt/mb/x), and separator junction (sl/sr/sx) characters. */ 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, diff --git a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java index 50693bb..03fabed 100644 --- a/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java +++ b/src/test/java/it/polimi/ingsw/gc14/Model/Orders/Order3Test.java @@ -229,7 +229,6 @@ class Order3Test { assertTrue(order.toString().contains("--")); assertTrue(order.toString().contains("-1🍖/-2🏅")); - //TODO testare IndexOutOfBoundsException } }