Fix: client verification username
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user