Fix and complete JavaDoc comments

This commit is contained in:
MatteoPellegrino05
2026-05-06 16:59:18 +02:00
parent b40ed99bc1
commit 51718699a3
35 changed files with 390 additions and 54 deletions
@@ -1,5 +1,16 @@
package it.polimi.ingsw.gc14.Network;
/**
* Represents the possible actions requested by a client and handled by the
* server during the game.
*
* <p>Each value identifies a specific user action, such as adding a player,
* choosing a slot, drawing a card, picking an optional card, or skipping an
* optional action.
/**
* Represents the different types of network events that can be sent between
* client and server.
*/
public enum EventType {
ADD_PLAYER,
SLOT_CHOICE,
@@ -6,7 +6,28 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import java.io.Serializable;
import java.rmi.*;
/**
* Callback interface used by the server to notify an RMI client about
* game updates and incoming network actions.
*
* <p>Implementations of this interface are remotely accessible and
* serializable.
*/
public interface IClientCallback extends Remote, Serializable {
/**
* Notifies the client that the game model has been initialized or updated.
*
* @param model the current game model.
* @throws RemoteException if an RMI communication error occurs.
*/
void onGameInit(Game model) throws RemoteException;
/**
* Notifies the client about a network action to process.
*
* @param action the network event received from the server.
* @throws RemoteException if an RMI communication error occurs.
*/
void onAction(NetworkEvent action) throws RemoteException;
}
@@ -4,9 +4,31 @@ import it.polimi.ingsw.gc14.Network.NetworkEvent;
import java.rmi.*;
/**
* Remote interface used by RMI clients to interact with the game server.
*/
public interface IGameServer extends Remote {
/**
* Adds a player to the game through the remote server.
*
* @param username the username of the player joining the game.
* @param preferredInt the preferred player number or slot selected by the client.
* @param callback the client callback used by the server to send updates.
* @return {@code true} if the player successfully joins the game;
* {@code false} otherwise.
* @throws RemoteException if an RMI communication error occurs.
*/
boolean joinGame(String username,int preferredInt, IClientCallback callback) throws RemoteException;
/**
* Sends a network event to the game server.
*
* @param event the event to be processed by the server.
* @return {@code true} if the event is accepted and processed;
* {@code false} otherwise.
* @throws RemoteException if an RMI communication error occurs.
*/
boolean doEvent(NetworkEvent event) throws RemoteException;
}
@@ -37,9 +37,12 @@ public class ClientHandler implements Runnable {
/**
* Class constructor that initializes the attributes.
* @param clientSocket The socket representing the client's TCP connection
* @param clientHandlers The shared list of all active client handlers
* @param actionQueue The queue containing incoming events
*
* @param clientSocket the socket representing the client's TCP connection.
* @param out the output stream used to send data to the client.
* @param in the input stream used to receive data from the client.
* @param clientHandlers the shared list of all active client handlers.
* @param actionQueue the queue containing incoming events.
*/
public ClientHandler(Socket clientSocket, ObjectOutputStream out, ObjectInputStream in, List<ClientHandler> clientHandlers, BlockingQueue<NetworkEvent> actionQueue) {
this.clientSocket = clientSocket;
@@ -139,13 +139,21 @@ public class TCPServer {
}
/** Sends an action to all TCP clients */
/**
* Sends an action to all TCP clients.
*
* @param event the network event to send to all connected TCP clients.
*/
public void notifyAll(NetworkEvent event){
clientHandlers.forEach((x) -> x.notifyEvent(event));
}
/** Sends a game model to all TCP clients */
/**
* Sends a game model to all TCP clients.
*
* @param model the game model to send to all connected TCP clients.
*/
public void notifyAll(Game model){
clientHandlers.forEach((x) -> x.notifyModel(model));
}