Improved stability and other related fixes:

* server: added limit to max chat message (related to #11285);
* gui: fixed possible error after auto-submit deck;
* gui: fixed possible error after end game dialog;
* refactor: other code improves;
This commit is contained in:
Oleg Agafonov 2023-11-25 12:29:54 +04:00
parent 81f97c3b0e
commit d1f9e9cc90
15 changed files with 86 additions and 48 deletions

View file

@ -5,6 +5,7 @@ import mage.client.SessionHandler;
import mage.client.cards.BigCard;
import mage.client.dialog.PreferencesDialog;
import mage.client.util.GUISizeHelper;
import mage.constants.Constants;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import org.mage.card.arcane.ManaSymbols;
@ -103,7 +104,6 @@ public class ChatPanelBasic extends javax.swing.JPanel {
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, CHAT_ALPHA));
jScrollPaneTxt.setViewportBorder(null);
}
}
public void cleanUp() {
@ -398,6 +398,12 @@ public class ChatPanelBasic extends javax.swing.JPanel {
public void handleKeyTyped(java.awt.event.KeyEvent evt) {
if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
if (this.txtMessage.getText().length() > Constants.MAX_CHAT_MESSAGE_SIZE) {
JOptionPane.showMessageDialog(null, "Can't send too long message", "Chat", JOptionPane.WARNING_MESSAGE);
return;
}
if (parentChatRef != null) {
SessionHandler.sendChatMessage(parentChatRef.chatId, this.txtMessage.getText());
} else {

View file

@ -1497,13 +1497,13 @@ public class DeckEditorPanel extends javax.swing.JPanel {
timeToSubmit = 60;
this.btnSubmitTimer.setEnabled(false);
ScheduledFuture scheduledFuture = scheduledExecutorService.schedule((Callable) () -> {
scheduledExecutorService.schedule(() -> {
if (updateDeckTask != null) {
updateDeckTask.cancel(true);
}
if (SessionHandler.submitDeck(mode, tableId, deck.getDeckCardLists())) {
removeDeckEditor();
SwingUtilities.invokeLater(this::removeDeckEditor);
}
return null;
}, 60, TimeUnit.SECONDS);

View file

@ -11,6 +11,7 @@ import mage.constants.PlayerAction;
import mage.constants.TurnPhase;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.Serializable;
@ -40,6 +41,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
private ChatPanelBasic connectedChatPanel;
private Map<String, Serializable> lastOptions = new HashMap<>();
private static final int AUTO_CLOSE_END_DIALOG_TIMEOUT_SECS = 8;
private static final ScheduledExecutorService WORKER = Executors.newSingleThreadScheduledExecutor();
/**
@ -153,16 +155,18 @@ public class FeedbackPanel extends javax.swing.JPanel {
*/
private void endWithTimeout() {
Runnable task = () -> {
LOGGER.info("Ending game...");
Component c = MageFrame.getGame(gameId);
while (c != null && !(c instanceof GamePane)) {
c = c.getParent();
}
if (c != null && c.isVisible()) { // check if GamePanel still visible
FeedbackPanel.this.btnRight.doClick();
}
SwingUtilities.invokeLater(() -> {
LOGGER.info("Ending game...");
Component c = MageFrame.getGame(gameId);
while (c != null && !(c instanceof GamePane)) {
c = c.getParent();
}
if (c != null && c.isVisible()) { // check if GamePanel still visible
FeedbackPanel.this.btnRight.doClick();
}
});
};
WORKER.schedule(task, 8, TimeUnit.SECONDS);
WORKER.schedule(task, AUTO_CLOSE_END_DIALOG_TIMEOUT_SECS, TimeUnit.SECONDS);
}
public void updateOptions(Map<String, Serializable> options) {

View file

@ -87,12 +87,12 @@ public class MageActionCallback implements ActionCallback {
private Date enlargeredViewOpened;
private volatile EnlargedWindowState enlargedWindowState = EnlargedWindowState.CLOSED;
//private volatile boolean enlargedImageWindowOpen = false;
// shows the alternative card the normal card or the alternative card (copy source, other flip side, other transformed side)
private volatile EnlargeMode enlargeMode;
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(1);
private ScheduledFuture<?> hideTimeout;
private static final ScheduledExecutorService hideEnlargedCardWorker = Executors.newScheduledThreadPool(1);
private ScheduledFuture<?> hideEnlagedCardTask;
private static final int HIDE_ENLARGED_CARD_TIMEOUT_MS = 700;
private MageCard prevCardPanel;
private boolean startedDragging;
@ -472,7 +472,7 @@ public class MageActionCallback implements ActionCallback {
}
hideTooltipPopup();
cancelTimeout();
cancelHidingEnlagedCard();
Component parentComponent = SwingUtilities.getRoot(cardPanel);
if (parentComponent == null) {
// virtual card (example: show card popup in non cards panel like PickChoiceDialog)
@ -514,7 +514,7 @@ public class MageActionCallback implements ActionCallback {
popupTextWindowOpen = true;
}
if (enlargedWindowState != EnlargedWindowState.CLOSED) {
cancelTimeout();
cancelHidingEnlagedCard();
displayEnlargedCard(cardPanel.getOriginal(), data);
}
}
@ -552,7 +552,7 @@ public class MageActionCallback implements ActionCallback {
public void hideAll(UUID gameId) {
hideTooltipPopup();
startHideTimeout();
startHidingEnlagedCard();
this.popupTextWindowOpen = false;
if (gameId != null) {
ArrowBuilder.getBuilder().removeArrowsByType(gameId, ArrowBuilder.Type.TARGET);
@ -740,14 +740,16 @@ public class MageActionCallback implements ActionCallback {
return PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_ABILITY_TEXT_OVERLAY, "true").equals("true");
}
private synchronized void startHideTimeout() {
cancelTimeout();
hideTimeout = timeoutExecutor.schedule(this::hideEnlargedCard, 700, TimeUnit.MILLISECONDS);
private synchronized void startHidingEnlagedCard() {
cancelHidingEnlagedCard();
hideEnlagedCardTask = hideEnlargedCardWorker.schedule(
() -> SwingUtilities.invokeLater(this::hideEnlargedCard), HIDE_ENLARGED_CARD_TIMEOUT_MS, TimeUnit.MILLISECONDS
);
}
private synchronized void cancelTimeout() {
if (hideTimeout != null) {
hideTimeout.cancel(false);
private synchronized void cancelHidingEnlagedCard() {
if (hideEnlagedCardTask != null) {
hideEnlagedCardTask.cancel(false);
}
}

View file

@ -647,7 +647,7 @@ public class DownloadPicturesService extends DefaultBoundedRangeModel implements
while (!executor.isTerminated()) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException ie) {
} catch (InterruptedException ignore) {
}
}
}