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,13 +522,7 @@ public class NewTableDialog extends MageDialog {
return;
}
try {
if (SessionHandler.joinTable(
roomId,
table.getTableId(),
this.player1Panel.getPlayerName(),
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
this.txtPassword.getText())) {
// join AI
for (TablePlayerPanel player : players) {
if (player.getPlayerType() != PlayerType.HUMAN) {
if (!player.joinTable(roomId, table.getTableId())) {
@ -539,6 +533,16 @@ public class NewTableDialog extends MageDialog {
}
}
}
// join itself
if (SessionHandler.joinTable(
roomId,
table.getTableId(),
this.player1Panel.getPlayerName(),
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
this.txtPassword.getText())) {
// all fine, can close create dialog (join dialog will be opened after feedback from server)
this.hideDialog();
return;
}

View file

@ -692,13 +692,8 @@ public class NewTournamentDialog extends MageDialog {
// message must be send by server!
return;
}
if (SessionHandler.joinTournamentTable(
roomId,
table.getTableId(),
this.player1Panel.getPlayerName(),
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
tOptions.getPassword())) {
// join AI
for (TournamentPlayerPanel player : players) {
if (player.getPlayerType().getSelectedItem() != PlayerType.HUMAN) {
if (!player.joinTournamentTable(roomId, table.getTableId(), DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true))) {
@ -709,9 +704,20 @@ public class NewTournamentDialog extends MageDialog {
}
}
}
// join itself
if (SessionHandler.joinTournamentTable(
roomId,
table.getTableId(),
this.player1Panel.getPlayerName(),
PlayerType.HUMAN, 1,
DeckImporter.importDeckFromFile(this.player1Panel.getDeckFile(), true),
tOptions.getPassword())) {
// 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);
}