Fix: client verification username

This commit is contained in:
rubenpirreram
2026-05-05 13:23:03 +02:00
parent 5418d70cf8
commit 65e88dd9fc
@@ -5,6 +5,8 @@ import it.polimi.ingsw.gc14.Network.IClient;
import it.polimi.ingsw.gc14.Network.NetworkEvents.*; import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
import it.polimi.ingsw.gc14.View.IView; 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. * 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. * It provides methods to set the client components and to execute requested actions.
@@ -68,8 +70,16 @@ public class ClientController {
* @param pos the index of the card to draw * @param pos the index of the card to draw
*/ */
public void drawUpperTribeCard(String playerUsername, int pos) { public void drawUpperTribeCard(String playerUsername, int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
{
view.showError("It's not your turn!");
}
else
{
client.doEvent(new DrawUpperTribeCard(playerUsername,pos)); client.doEvent(new DrawUpperTribeCard(playerUsername,pos));
} }
}
/** /**
@@ -90,7 +100,11 @@ public class ClientController {
* @param pos the index of the card to draw * @param pos the index of the card to draw
*/ */
public void drawUpperBuildingCard(String playerUsername,int pos) { public void drawUpperBuildingCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new DrawUpperBuildingCard(playerUsername,pos)); client.doEvent(new DrawUpperBuildingCard(playerUsername,pos));
} }
@@ -101,6 +115,9 @@ public class ClientController {
* @param pos the index of the card to draw * @param pos the index of the card to draw
*/ */
public void drawLowerBuildingCard(String playerUsername,int pos) { public void drawLowerBuildingCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new DrawLowerBuildingCard(playerUsername,pos)); client.doEvent(new DrawLowerBuildingCard(playerUsername,pos));
} }
@@ -111,6 +128,9 @@ public class ClientController {
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
*/ */
public void skipUpper(String playerUsername) { public void skipUpper(String playerUsername) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new SkipUpper(playerUsername)); 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. * 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 * @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,6 +153,9 @@ public class ClientController {
* @param pos the index of the card to draw * @param pos the index of the card to draw
*/ */
public void pickOptionalTribeCard(String playerUsername,int pos) { public void pickOptionalTribeCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new PickOptionalTribeCard(playerUsername,pos)); client.doEvent(new PickOptionalTribeCard(playerUsername,pos));
} }
@@ -141,6 +167,9 @@ public class ClientController {
* @param pos the index of the card to draw * @param pos the index of the card to draw
*/ */
public void pickOptionalBuildingCard(String playerUsername,int pos) { public void pickOptionalBuildingCard(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new PickOptionalBuildingCard(playerUsername,pos)); client.doEvent(new PickOptionalBuildingCard(playerUsername,pos));
} }
@@ -151,6 +180,9 @@ public class ClientController {
* @param playerUsername the name of the player performing the action * @param playerUsername the name of the player performing the action
*/ */
public void noOptionalCard(String playerUsername) { public void noOptionalCard(String playerUsername) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new NoOptionalCard(playerUsername)); client.doEvent(new NoOptionalCard(playerUsername));
} }
@@ -161,6 +193,9 @@ public class ClientController {
* @param pos the index of the selected slot * @param pos the index of the selected slot
*/ */
public void slotChoice(String playerUsername,int pos) { public void slotChoice(String playerUsername,int pos) {
if(!Objects.equals(playerUsername, localController.getModel().getCurrentState().getCurrentPlayer().getUserName()))
view.showError("It's not your turn!");
else
client.doEvent(new SlotChoice(playerUsername,pos)); client.doEvent(new SlotChoice(playerUsername,pos));
} }