Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #151 from Programmer245/Testing-New-Network-Stack
Browse files Browse the repository at this point in the history
Testing-New-Network-Stack
  • Loading branch information
lorenzo-cmyk authored Jun 27, 2024
2 parents 7c2a848 + 9f9ec9a commit 4c565c7
Show file tree
Hide file tree
Showing 80 changed files with 2,724 additions and 313 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,10 @@ The group members are:
| Complete Rules + TUI + GUI + RMI or Socket + 1 FA (Chat) | 24 | ☑️ |
| Complete Rules + TUI + GUI + RMI + Socket + 1 FA (Chat) | 27 | ☑️ |
| Complete Rules + TUI + GUI + RMI + Socket + 2 FA (Chat & Multiple match) | 30 | ☑️ |
| Complete Rules + TUI + GUI + RMI + Socket + 3 FA (Chat & Multiple match & Disconnection resilience) | 30L | |
| Complete Rules + TUI + GUI + RMI + Socket + 3 FA (Chat & Multiple match & Disconnection resilience) | 30L | |

### Currently Known Issues

- 🟨 The branch with the correct version of the network stack is not yet merged. Therefore, the network is not informing the View if the initial connection was successful or not.
- 🟥 The branch with the correct version of the network stack is not yet merged. Therefore, the network is not activating the PingTask that allows (in both Client & Server) the disconnection discovery in RMI.

## Code Coverage

The average code coverage, between Model and Controller, is 96% for methods and 85% for lines, all (known) edge cases are covered.
Expand Down
Binary file added deliverables/FinalUML/ChatFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/ClientFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/ControllerFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/MessageFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/ModelFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/ProjectFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/FinalUML/UtilitiesFinalUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deliverables/InitialUML/ModelInitialUML.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
171 changes: 163 additions & 8 deletions src/main/java/it/polimi/ingsw/am32/client/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,199 @@
* Enumeration of the possible events that can occur during the game.
*/
public enum Event {
LOBBY(0), // STATUS
PREPARATION(1), // STATUS
PLAYING(2), // STATUS
TERMINATING(3), // STATUS
LAST_TURN(4), // STATUS
TERMINATED(5), // STATUS
/**
* Identifiers for the Lobby phase: the phase in which the players are waiting for the game to start.
* Associated with the number 0.
*/
LOBBY(0),
/**
* Identifiers for the preparation phase: the phase in which the players are selecting their starting card side and
* secret objective card.
* Associated with the number 1.
*/
PREPARATION(1),
/**
* Identifiers for the playing phase: the phase in which the players place their cards on the field and draw new
* cards if it is their turn.
* Associated with the number 2.
*/
PLAYING(2),
/**
* Identifiers for the terminating phase: when one of the players has gained 20 points or more.
* Associated with the number 3.
*/
TERMINATING(3),
/**
* Identifiers for the last turn phase: in which phase each player has one last turn to place a card on the field
* without drawing a new card.
* Associated with the number 4.
*/
LAST_TURN(4),
/**
* Identifiers for the game terminated phase: when the game is over and the final scores are displayed.
* Associated with the number 5.
*/
TERMINATED(5),
/**
* Indicates that the player should choose a connection type.
* Associated with the number 6.
*/
CHOOSE_CONNECTION (6),
/**
* Indicates that the player should choose a game mode.
* Associated with the number 7.
*/
SELECT_GAME_MODE(7),
/**
* Indicates that the player selected to create a new game.
* Associated with the number 8.
*/
CREATE_GAME(8),
/**
* Indicates that the player selected to join an existing game.
* Associated with the number 9.
*/
JOIN_GAME(9),
/**
* Indicates that the player selected to reconnect to a game.
* Associated with the number 10.
*/
RECONNECT_GAME(10),
/**
* Indicates that the game has been created successfully.
* Associated with the number 11.
*/
GAME_CREATED (11),
/**
* Indicates that the player has joined the game successfully.
* Associated with the number 12.
*/
GAME_JOINED (12),
/**
* Indicates that the player has reconnected to the game successfully.
* Associated with the number 13.
*/
GAME_RECONNECTED (13),
/**
* Indicates that a new player has joined the game.
* Associated with the number 14.
*/
NEW_PLAYER_JOIN (14),
/**
* Indicates that a player has disconnected from the game.
* Associated with the number 15.
*/
PLAYER_DISCONNECTED (15),
/**
* Indicates that the game is waiting for the start of the game, waiting for all players to join.
* Associated with the number 16.
*/
WAITING_FOR_START (16),
/**
* Indicates that the game has started with all players joined.
* Associated with the number 17.
*/
GAME_START (17),
/**
* Indicates that the player should select the side of the starter card.
* Associated with the number 18.
*/
SELECT_STARTER_CARD_SIDE(18),
/**
* Indicates that the player has selected the side of the starter card not successfully.
* Associated with the number 19.
*/
SELECT_STARTER_CARD_SIDE_FAILURE (19),
/**
* Indicates that the player should select the secret objective card.
* Associated with the number 20.
*/
SELECT_SECRET_OBJ_CARD (20),
/**
* Indicates that the player has selected the secret objective card not successfully.
* Associated with the number 21.
*/
SELECT_SECRET_OBJ_CARD_FAILURE (21),
/**
* Indicates that the player should place a card on the field.
* Associated with the number 22.
*/
PLACE_CARD(22),
/**
* Indicates that the player has placed the card on the field not successfully.
* Associated with the number 23.
*/
PLACE_CARD_FAILURE (23),
/**
* Indicates that the player should draw a card.
* Associated with the number 24.
*/
DRAW_CARD(24),
/**
* Indicates that the player has reconnected to the game successfully.
* Associated with the number 25.
*/
PLAYER_RECONNECTED(25),
/**
* Indicates that the player has drawn a card not successfully.
* Associated with the number 26.
*/
DRAW_CARD_FAILURE(26),
WELCOME(27), // STATUS
/**
* Indicates phase in which the player is asked to select a game mode.
* Associated with the number 27.
*/
WELCOME(27),
/**
* Indicates that the player has completed the selection of the starter card side.
* Associated with the number 28.
*/
SELECTED_STARTER_CARD_SIDE(28),
/**
* Indicates that the player has completed the selection of the secret objective card.
* Associated with the number 29.
*/
SELECTED_SECRET_OBJ_CARD(29),
/**
* Indicates that the player has completed the selection of the card he wants to place on the field and the
* coordinates where he wants to place it.
* Associated with the number 30.
*/
CARD_PLACED(30),
/**
* Indicates that the player has completed the selection of the card he wants to draw.
* Associated with the number 31.
*/
CARD_DRAWN(31),
/**
* Indicates that the player is waiting for his turn to place a card on the field or the player is waiting for the
* start of playing phase.
* Associated with the number 32.
*/
WAITING_FOR_TURN(32),
/**
* Indicates there was an error in the chat message.
* Associated with the number 33.
*/
CHAT_ERROR(33),
/**
* Indicates that the game creation failed.
* Associated with the number 34.
*/
CREATE_GAME_FAILURE(34),
/**
* Indicates that the player failed to join the game.
* Associated with the number 35.
*/
JOIN_GAME_FAILURE(35),
/**
* Indicates that the player failed to reconnect to the game.
* Associated with the number 36.
*/
RECONNECT_GAME_FAILURE(36);

/**
* The integer value associated with the event.
*/
private final int value;

/**
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/it/polimi/ingsw/am32/client/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,16 @@ public abstract void updateRollback(String playerNickname, int removedCard, int
*/
public abstract void handleEvent(Event event, String nickname);

/**
* Method called when the node disconnects from the game.
* Called from the Network to notify the View that the connection to the server is lost.
*/
public abstract void nodeDisconnected();

/**
* Method called when the node reconnects to the game.
* Called from the Network to notify the View that the connection to the server is restored.
*/
public abstract void nodeReconnected();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ private void processLobbyMessages() {
}
// If we successfully sent the message, remove it from the queue.
synchronized (queuesLock) {
lobbyMessageQueue.removeFirst();
if(!lobbyMessageQueue.isEmpty()) {
lobbyMessageQueue.removeFirst();
}
}
logger.debug("LobbyMessage sent to the server: {}", currentLobbyMessage.getClass());
} catch (UploadFailureException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,26 @@
import it.polimi.ingsw.am32.message.ClientToServer.CtoSLobbyMessage;
import it.polimi.ingsw.am32.message.ClientToServer.CtoSMessage;

/**
* Interface for the AskListener class: used to manage the messages that clients want to send to the server.
* Listens for messages to be added to the queues (according to their type).
* There are two queues: one for CtoSMessage and one for CtoSLobbyMessage.
*/
public interface AskListenerInterface {
/**
* Adds a CtoSMessage to the queue to be sent to the server.
* @param message The message to be added to the queue and which will be sent to the server.
*/
void addMessage(CtoSMessage message);

/**
* Adds a CtoSLobbyMessage to the queue of messages to be sent to the server.
* @param message The message to be added to the queue and which will be sent to the server.
*/
void addMessage(CtoSLobbyMessage message);

/**
* Flushes both the message and lobbyMessage queues.
*/
void flushMessages();
}
Loading

0 comments on commit 4c565c7

Please sign in to comment.