From 65e88dd9fcc8f90696aafe61d14238215cede0c8 Mon Sep 17 00:00:00 2001 From: rubenpirreram Date: Tue, 5 May 2026 13:23:03 +0200 Subject: [PATCH] Fix: client verification username --- .../gc14/Controller/ClientController.java | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java index 5c2070b..4d04688 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java +++ b/src/main/java/it/polimi/ingsw/gc14/Controller/ClientController.java @@ -5,6 +5,8 @@ import it.polimi.ingsw.gc14.Network.IClient; import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.View.IView; +import java.util.Objects; + /** * Controller class that holds all the components of the client, such as view, network client and Game Controller. * It provides methods to set the client components and to execute requested actions. @@ -68,7 +70,15 @@ public class ClientController { * @param pos the index of the card to draw */ public void drawUpperTribeCard(String playerUsername, int pos) { - client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); + + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + { + view.showError("It's not your turn!"); + } + else + { + client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); + } } @@ -90,7 +100,11 @@ public class ClientController { * @param pos the index of the card to draw */ public void drawUpperBuildingCard(String playerUsername,int pos) { - client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); + } @@ -101,7 +115,10 @@ public class ClientController { * @param pos the index of the card to draw */ public void drawLowerBuildingCard(String playerUsername,int pos) { - client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); } @@ -111,7 +128,10 @@ public class ClientController { * @param playerUsername the name of the player performing the action */ public void skipUpper(String playerUsername) { - client.doEvent(new SkipUpper(playerUsername)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new SkipUpper(playerUsername)); } @@ -120,7 +140,10 @@ public class ClientController { * This action is available only when the lower list is empty or the player cannot draw any card. * @param playerUsername the name of the player performing the action */ - public void skipLower(String playerUsername) { client.doEvent(new SkipLower(playerUsername));} + public void skipLower(String playerUsername) { if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new SkipLower(playerUsername));} /** @@ -130,7 +153,10 @@ public class ClientController { * @param pos the index of the card to draw */ public void pickOptionalTribeCard(String playerUsername,int pos) { - client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); } @@ -141,7 +167,10 @@ public class ClientController { * @param pos the index of the card to draw */ public void pickOptionalBuildingCard(String playerUsername,int pos) { - client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); } @@ -151,7 +180,10 @@ public class ClientController { * @param playerUsername the name of the player performing the action */ public void noOptionalCard(String playerUsername) { - client.doEvent(new NoOptionalCard(playerUsername)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new NoOptionalCard(playerUsername)); } @@ -161,7 +193,10 @@ public class ClientController { * @param pos the index of the selected slot */ public void slotChoice(String playerUsername,int pos) { - client.doEvent(new SlotChoice(playerUsername,pos)); + if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName())) + view.showError("It's not your turn!"); + else + client.doEvent(new SlotChoice(playerUsername,pos)); } }