Added: ErrorType.toString
This commit is contained in:
@@ -83,7 +83,7 @@ public class ClientLauncherTUI {
|
||||
System.out.println("Succesfully connected to RMI server\n\n");
|
||||
} else {
|
||||
System.out.println("RMI connection refused\n\n");
|
||||
controller.view.showError(serverResponse);
|
||||
controller.view.showError(serverResponse,serverResponse.toString());
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
@@ -99,7 +99,7 @@ public class ClientLauncherTUI {
|
||||
System.out.println("Succesfully connected to TCP server\n\n");
|
||||
} else {
|
||||
System.out.println("TCP connection refused\n\n");
|
||||
controller.view.showError(serverResponse);
|
||||
controller.view.showError(serverResponse,serverResponse.toString());
|
||||
return;
|
||||
}
|
||||
controller.setClient(client);
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
package it.polimi.ingsw.gc14;
|
||||
|
||||
public enum ErrorType {
|
||||
USER_NOT_FOUND, USERNAME_ALREADY_USED,USER_ALREADY_CONNECTED,WRONG_PLAYER_NUMBER,WRONG_GAME_ACTION,SERVER_CRASHED,GENERIC_ERROR, GAME_ALREADY_STARTED
|
||||
USER_NOT_FOUND("User not found"),
|
||||
USERNAME_ALREADY_USED("Username is already in use"),
|
||||
USER_ALREADY_CONNECTED("User is already connected"),
|
||||
WRONG_PLAYER_NUMBER("Wrong player number"),
|
||||
SERVER_CRASHED("Server crashed"),
|
||||
GENERIC_ERROR("Generic error"),
|
||||
GAME_ALREADY_STARTED("Game already started"),
|
||||
WRONG_ACTION("Wrong action");
|
||||
private String description;
|
||||
ErrorType(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ApplyNextRound extends NetworkEvent implements Serializable{
|
||||
* @param players the list of players in the game.
|
||||
*/
|
||||
public ApplyNextRound(Map<Slot, Player> slotPlayerMap, OrderLogicCard orderLogicCard, CurrentState currentState, List<Player> players, ArrayList<TribeCard> upperListTribeCards, ArrayList<TribeCard>lowerListTribeCards, ArrayList<BuildingCard> upperListBuildingCards, ArrayList<BuildingCard>lowerListBuildingCards) {
|
||||
super("SERVER",EventType.NEXT_ROUND,false, ErrorType.WRONG_GAME_ACTION);
|
||||
super("SERVER",EventType.NEXT_ROUND,false, ErrorType.WRONG_ACTION);
|
||||
this.upperListBuildingCards = upperListBuildingCards;
|
||||
this.lowerListBuildingCards = lowerListBuildingCards;
|
||||
this.upperListTribeCards = upperListTribeCards;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DrawLowerBuildingCard extends NetworkEvent implements Serializable
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawLowerBuildingCard(String username, int pos){
|
||||
super(username, EventType.DRAW_LOWER_BUILD, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.DRAW_LOWER_BUILD, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DrawLowerTribeCard extends NetworkEvent implements Serializable{
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawLowerTribeCard(String username, int pos){
|
||||
super(username, EventType.DRAW_LOWER_TRIBE, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.DRAW_LOWER_TRIBE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DrawUpperBuildingCard extends NetworkEvent implements Serializable
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawUpperBuildingCard(String username, int pos){
|
||||
super(username, EventType.DRAW_UPPER_BUILD, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.DRAW_UPPER_BUILD, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public class DrawUpperTribeCard extends NetworkEvent implements Serializable{
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public DrawUpperTribeCard(String username, int pos){
|
||||
super(username, EventType.DRAW_UPPER_TRIBE, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.DRAW_UPPER_TRIBE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SkipTurn extends NetworkEvent implements Serializable{
|
||||
* @param username the name of the player requesting the event
|
||||
*/
|
||||
public SkipTurn(String username){
|
||||
super(username, EventType.SKIP_TURN, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.SKIP_TURN, false, ErrorType.WRONG_ACTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ public class SlotChoice extends NetworkEvent implements Serializable {
|
||||
* @param pos the index of the card to draw
|
||||
*/
|
||||
public SlotChoice(String username, int pos) {
|
||||
super(username, EventType.SLOT_CHOICE, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.SLOT_CHOICE, false, ErrorType.WRONG_ACTION);
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TotemChoice extends NetworkEvent implements Serializable {
|
||||
* @param totem the name of the selected totem.
|
||||
*/
|
||||
public TotemChoice(String username, String totem) {
|
||||
super(username, EventType.TOTEM_CHOICE, false, ErrorType.WRONG_GAME_ACTION);
|
||||
super(username, EventType.TOTEM_CHOICE, false, ErrorType.WRONG_ACTION);
|
||||
this.totem = totem;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
@Override
|
||||
public void onAction(NetworkEvent event) throws RemoteException {
|
||||
if(event.getIsError()) {
|
||||
clientController.view.showError(event.getErrorType());
|
||||
clientController.view.showError(event.getErrorType(),event.toString());
|
||||
} else {
|
||||
event.apply(clientController.miniModel);
|
||||
clientController.view.render();
|
||||
|
||||
@@ -126,7 +126,7 @@ public class RMIClient implements IClient {
|
||||
if (!running) return;
|
||||
running = false;
|
||||
if (pingSender != null) pingSender.shutdownNow();
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED);
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ public class TCPClient implements IClient {
|
||||
running = false;
|
||||
try { communicationSocket.close(); } catch (IOException ignored) {}
|
||||
try { heartbeatSocket.close(); } catch (IOException ignored) {}
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED);
|
||||
controller.view.showError(ErrorType.SERVER_CRASHED,ErrorType.SERVER_CRASHED.toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,11 @@ public class TCPClient implements IClient {
|
||||
|
||||
if (read instanceof NetworkEvent event) {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.getErrorType());
|
||||
if(event.getErrorType() == ErrorType.WRONG_ACTION) {
|
||||
controller.view.showError(ErrorType.WRONG_ACTION,event.toString());
|
||||
}
|
||||
else
|
||||
controller.view.showError(event.getErrorType(),event.getErrorType().toString());
|
||||
} else {
|
||||
event.apply(controller.miniModel);
|
||||
controller.view.render();
|
||||
|
||||
@@ -135,7 +135,7 @@ public class GUI extends Application implements IView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(ErrorType error) {
|
||||
public void showError(ErrorType error,String message) {
|
||||
Platform.runLater(() -> {
|
||||
synchronized (miniModel) {
|
||||
controllerMain.isError = true;
|
||||
|
||||
@@ -11,6 +11,6 @@ public interface IView {
|
||||
|
||||
void showMessage(String message);
|
||||
|
||||
public void showError(ErrorType error);
|
||||
public void showError(ErrorType error,String message);
|
||||
|
||||
}
|
||||
|
||||
@@ -234,10 +234,10 @@ public class TUI implements IView {
|
||||
*
|
||||
* @param error the error message to display
|
||||
*/
|
||||
public void showError(ErrorType error) {
|
||||
public void showError(ErrorType error,String message) {
|
||||
clearTerminal();
|
||||
render();
|
||||
System.out.println(error);
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user