Server: fixed NPE error on wrong AI usage in new game dialogs (fixes #7556);

This commit is contained in:
Oleg Agafonov 2021-02-13 14:54:13 +04:00
parent 82f40f04ae
commit 42364f7e27
5 changed files with 34 additions and 24 deletions

View file

@ -30,7 +30,7 @@ public interface ICardGrid {
// only for debug, return inner cards list
Object getCardsStore();
// specil memory optimization to clean inner cards list before new cards load, so you don't need 2x memory
// WARNING, you must call it in same code as new cards list prepare
// special memory optimization to clean inner cards list before new cards load, so you don't need 2x memory
// WARNING, you must call it in the same code as new cards list prepare
void clearCardsStoreBeforeUpdate();
}

View file

@ -471,7 +471,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
private void debugObjectMemorySize(String name, Object object) {
// just debug code, don't use it in production
// need 2x memory for find a size
// need 2x memory to find a size
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);

View file

@ -522,6 +522,19 @@ public class NewTableDialog extends MageDialog {
return;
}
try {
// join AI
for (TablePlayerPanel player : players) {
if (player.getPlayerType() != PlayerType.HUMAN) {
if (!player.joinTable(roomId, table.getTableId())) {
// error message must be send by the server
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
// join itself
if (SessionHandler.joinTable(
roomId,
table.getTableId(),
@ -529,16 +542,7 @@ public class NewTableDialog extends MageDialog {
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
this.txtPassword.getText())) {
for (TablePlayerPanel player : players) {
if (player.getPlayerType() != PlayerType.HUMAN) {
if (!player.joinTable(roomId, table.getTableId())) {
// error message must be send by the server
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
// all fine, can close create dialog (join dialog will be opened after feedback from server)
this.hideDialog();
return;
}

View file

@ -692,6 +692,20 @@ public class NewTournamentDialog extends MageDialog {
// message must be send by server!
return;
}
// join AI
for (TournamentPlayerPanel player : players) {
if (player.getPlayerType().getSelectedItem() != PlayerType.HUMAN) {
if (!player.joinTournamentTable(roomId, table.getTableId(), DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true))) {
// error message must be send by sever
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
// join itself
if (SessionHandler.joinTournamentTable(
roomId,
table.getTableId(),
@ -699,19 +713,11 @@ public class NewTournamentDialog extends MageDialog {
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
tOptions.getPassword())) {
for (TournamentPlayerPanel player : players) {
if (player.getPlayerType().getSelectedItem() != PlayerType.HUMAN) {
if (!player.joinTournamentTable(roomId, table.getTableId(), DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true))) {
// error message must be send by sever
SessionHandler.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
// all fine, can close create dialog (join dialog will be opened after feedback from server)
this.hideDialog();
return;
}
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
SessionHandler.removeTable(roomId, table.getTableId());
table = null;

View file

@ -608,7 +608,7 @@ public class CallbackClientImpl implements CallbackClient {
logger.fatal("Client error\n", ex);
String errorMessage = ex.getMessage();
if (errorMessage == null || errorMessage.isEmpty() || errorMessage.equals("Null")) {
errorMessage = ex.getClass().getSimpleName() + " - look server logs for more details";
errorMessage = ex.getClass().getSimpleName() + " - look server or client logs for more details";
}
frame.showError("Server's error: " + errorMessage);
}