From 0faecb2fb67f71f628b54339bc49b7f2932c64ef Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 31 Dec 2019 04:11:23 +0400 Subject: [PATCH] Server: fixed missing data compress for some server's responses; --- .../client/remote/CallbackClientImpl.java | 3 +- .../interfaces/callback/ClientCallback.java | 31 ++++++++++++++----- .../main/java/mage/utils/CompressUtil.java | 2 +- .../mage/server/game/GameSessionWatcher.java | 3 -- .../mage/test/load/LoadCallbackClient.java | 1 + 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index 5f48cefadc..92cc8f2f8d 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -18,7 +18,6 @@ import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.ClientCallback; import mage.remote.ActionData; import mage.remote.Session; -import mage.utils.CompressUtil; import mage.view.*; import mage.view.ChatMessage.MessageType; import org.apache.log4j.Logger; @@ -44,8 +43,8 @@ public class CallbackClientImpl implements CallbackClient { @Override public synchronized void processCallback(final ClientCallback callback) { + callback.decompressData(); SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString()); - callback.setData(CompressUtil.decompress(callback.getData())); SwingUtilities.invokeLater(() -> { try { logger.debug(callback.getMessageId() + " -- " + callback.getMethod()); diff --git a/Mage.Common/src/main/java/mage/interfaces/callback/ClientCallback.java b/Mage.Common/src/main/java/mage/interfaces/callback/ClientCallback.java index ca69ff740d..f7582fc158 100644 --- a/Mage.Common/src/main/java/mage/interfaces/callback/ClientCallback.java +++ b/Mage.Common/src/main/java/mage/interfaces/callback/ClientCallback.java @@ -1,12 +1,12 @@ - - package mage.interfaces.callback; +import mage.remote.traffic.ZippedObject; +import mage.utils.CompressUtil; + import java.io.Serializable; import java.util.UUID; /** - * * @author BetaSteward_at_googlemail.com */ public class ClientCallback implements Serializable { @@ -16,12 +16,14 @@ public class ClientCallback implements Serializable { private ClientCallbackMethod method; private int messageId; - public ClientCallback() {} - public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data) { + this(method, objectId, data, true); + } + + public ClientCallback(ClientCallbackMethod method, UUID objectId, Object data, boolean useCompress) { this.method = method; this.objectId = objectId; - this.data = data; + this.setData(data, useCompress); } public ClientCallback(ClientCallbackMethod method, UUID objectId) { @@ -42,13 +44,28 @@ public class ClientCallback implements Serializable { } public Object getData() { + if (this.data instanceof ZippedObject) { + throw new IllegalStateException("Client data must be decompressed first"); + } return data; } - public void setData(Object data) { + public void setData(Object data, boolean useCompress) { + if (!useCompress || data == null || data instanceof ZippedObject) { + this.data = data; + } else { + this.data = CompressUtil.compress(data); + } + this.data = data; } + public void decompressData() { + if (this.data instanceof ZippedObject) { + this.data = CompressUtil.decompress(this.data); + } + } + public ClientCallbackMethod getMethod() { return method; } diff --git a/Mage.Common/src/main/java/mage/utils/CompressUtil.java b/Mage.Common/src/main/java/mage/utils/CompressUtil.java index eeef7533de..fdd45dd7d5 100644 --- a/Mage.Common/src/main/java/mage/utils/CompressUtil.java +++ b/Mage.Common/src/main/java/mage/utils/CompressUtil.java @@ -14,7 +14,7 @@ public final class CompressUtil { * Defines should data be compressed or not. True by default. Read from * system property: */ - private static boolean compressData = true; + private static boolean compressData; /** * Defines the system property name to disable any compressing. diff --git a/Mage.Server/src/main/java/mage/server/game/GameSessionWatcher.java b/Mage.Server/src/main/java/mage/server/game/GameSessionWatcher.java index 086a1cc04d..ebe711cfcf 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameSessionWatcher.java +++ b/Mage.Server/src/main/java/mage/server/game/GameSessionWatcher.java @@ -1,5 +1,3 @@ - - package mage.server.game; import mage.game.Game; @@ -101,7 +99,6 @@ public class GameSessionWatcher { GameView gameView = new GameView(game.getState(), game, null, userId); processWatchedHands(userId, gameView); return gameView; - } protected void processWatchedHands(UUID userId, GameView gameView) { diff --git a/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java b/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java index 9d85778f03..f74a0b360f 100644 --- a/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java +++ b/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java @@ -35,6 +35,7 @@ public class LoadCallbackClient implements CallbackClient { @Override public void processCallback(ClientCallback callback) { + callback.decompressData(); controlCount = 0; // ignore bloaded logs