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 f16b0bee0e..758758e7ae 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -31,11 +31,7 @@ import java.awt.event.KeyEvent; import java.util.List; import java.util.UUID; import javax.swing.*; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import mage.cards.decks.Deck; -import mage.client.remote.S3Uploader; import mage.client.MageFrame; import mage.client.SessionHandler; import mage.client.chat.ChatPanelBasic; @@ -53,7 +49,6 @@ import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.ClientCallback; import mage.remote.ActionData; import mage.remote.Session; -import mage.remote.SessionImpl; import mage.utils.CompressUtil; import mage.view.*; import mage.view.ChatMessage.MessageType; @@ -410,6 +405,7 @@ public class CallbackClientImpl implements CallbackClient { } }); } + private ActionData appendJsonEvent(String name, UUID gameId, Object value) { Session session = SessionHandler.getSession(); ActionData actionData = new ActionData(name, gameId); @@ -417,6 +413,7 @@ public class CallbackClientImpl implements CallbackClient { session.appendJsonLog(actionData); return actionData; } + private void createChatStartMessage(ChatPanelBasic chatPanel) { chatPanel.setStartMessageDone(true); ChatPanelBasic usedPanel = chatPanel; diff --git a/Mage.Client/src/main/java/mage/client/remote/S3Uploader.java b/Mage.Client/src/main/java/mage/client/remote/S3Uploader.java index 21e9504f41..35a1b538ce 100644 --- a/Mage.Client/src/main/java/mage/client/remote/S3Uploader.java +++ b/Mage.Client/src/main/java/mage/client/remote/S3Uploader.java @@ -1,27 +1,26 @@ package mage.client.remote; -import java.io.File; - import com.amazonaws.AmazonClientException; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.transfer.TransferManager; import com.amazonaws.services.s3.transfer.Upload; +import java.io.File; import org.apache.log4j.Logger; -import javax.xml.crypto.Data; - - public class S3Uploader { + private static final Logger logger = Logger.getLogger(S3Uploader.class); public static Boolean upload(String filePath, String keyName) throws Exception { String existingBucketName = System.getenv("S3_BUCKET") != null ? System.getenv("S3_BUCKET") - : "xmage-game-logs-dev"; + : "xmage-game-logs-dev"; String accessKeyId = System.getenv("AWS_ACCESS_ID"); String secretKeyId = System.getenv("AWS_SECRET_KEY"); - if(accessKeyId == "" || secretKeyId == "" || existingBucketName == "") { + if (accessKeyId == null || "".equals(accessKeyId) + || secretKeyId == null || "".equals(secretKeyId) + || existingBucketName == null || "".equals(existingBucketName)) { logger.info("Aborting json log sync."); return false; } @@ -39,8 +38,7 @@ public class S3Uploader { new File(path); return true; } catch (AmazonClientException amazonClientException) { - System.out.println("Unable to upload file, upload was aborted."); - amazonClientException.printStackTrace(); + logger.fatal("Unable to upload file, upload was aborted.", amazonClientException); return false; } } diff --git a/Mage.Common/src/main/java/mage/remote/ActionData.java b/Mage.Common/src/main/java/mage/remote/ActionData.java index d173535b14..51d079a0ac 100644 --- a/Mage.Common/src/main/java/mage/remote/ActionData.java +++ b/Mage.Common/src/main/java/mage/remote/ActionData.java @@ -25,20 +25,17 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.remote; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import mage.remote.interfaces.*; - -import java.util.UUID; - -import com.google.gson.annotations.Expose; import com.google.gson.ExclusionStrategy; import com.google.gson.FieldAttributes; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.annotations.Expose; +import java.util.UUID; public class ActionData { + @Expose public UUID gameId; @Expose @@ -69,57 +66,59 @@ public class ActionData { } public class CustomExclusionStrategy implements ExclusionStrategy { + // FIXME: Very crude way of whitelisting, as it applies to all levels of the JSON tree. - private final java.util.Set KEEP = new java.util.HashSet( + private final java.util.Set KEEP = new java.util.HashSet<>( java.util.Arrays.asList( new String[]{ - "id", - "choice", - "damage", - "abilityType", - "ability", - "abilities", - "method", - "data", - "options", - "life", - "players", - "zone", - "step", - "phase", - "attackers", - "blockers", - "tapped", - "damage", - "combat", - "paid", - "hand", - "stack", - "convertedManaCost", - "gameId", - "canPlayInHand", - "gameView", - "sessionId", - "power", - "choices", - "targets", - "loyalty", - "toughness", - "power", - "type", - "priorityTime", - "manaCost", - "value", - "message", - "cardsView", - "name", - "count", - "counters", - "battlefield", - "parentId" + "id", + "choice", + "damage", + "abilityType", + "ability", + "abilities", + "method", + "data", + "options", + "life", + "players", + "zone", + "step", + "phase", + "attackers", + "blockers", + "tapped", + "damage", + "combat", + "paid", + "hand", + "stack", + "convertedManaCost", + "gameId", + "canPlayInHand", + "gameView", + "sessionId", + "power", + "choices", + "targets", + "loyalty", + "toughness", + "power", + "type", + "priorityTime", + "manaCost", + "value", + "message", + "cardsView", + "name", + "count", + "counters", + "battlefield", + "parentId" })); - public CustomExclusionStrategy() {} + public CustomExclusionStrategy() { + } // This method is called for all fields. if the method returns true the // field is excluded from serialization diff --git a/Mage.Common/src/main/java/mage/remote/Session.java b/Mage.Common/src/main/java/mage/remote/Session.java index 67022d59e8..e7f04049ca 100644 --- a/Mage.Common/src/main/java/mage/remote/Session.java +++ b/Mage.Common/src/main/java/mage/remote/Session.java @@ -24,8 +24,7 @@ * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. -*/ - + */ package mage.remote; import mage.remote.interfaces.ChatSession; @@ -38,7 +37,6 @@ import mage.remote.interfaces.PlayerActions; import mage.remote.interfaces.Replays; import mage.remote.interfaces.ServerState; import mage.remote.interfaces.Testable; -import mage.remote.ActionData; /** * Extracted interface for SessionImpl class. @@ -46,5 +44,6 @@ import mage.remote.ActionData; * @author noxx */ public interface Session extends ClientData, Connect, GamePlay, GameTypes, ServerState, ChatSession, Feedback, PlayerActions, Replays, Testable { + public void appendJsonLog(ActionData actionData); } diff --git a/Mage.Common/src/main/java/mage/remote/SessionImpl.java b/Mage.Common/src/main/java/mage/remote/SessionImpl.java index 907de603b0..318e628f38 100644 --- a/Mage.Common/src/main/java/mage/remote/SessionImpl.java +++ b/Mage.Common/src/main/java/mage/remote/SessionImpl.java @@ -27,16 +27,14 @@ */ package mage.remote; +import java.io.BufferedWriter; +import java.io.FileWriter; import java.io.IOException; +import java.io.PrintWriter; import java.lang.reflect.UndeclaredThrowableException; import java.net.*; import java.util.*; import java.util.concurrent.TimeUnit; -import java.io.BufferedWriter; -import java.io.PrintWriter; -import java.io.FileWriter; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import mage.MageException; import mage.cards.decks.DeckCardLists; import mage.cards.repository.CardInfo; @@ -55,7 +53,6 @@ import mage.interfaces.callback.ClientCallback; import mage.players.PlayerType; import mage.players.net.UserData; import mage.utils.CompressUtil; -import mage.remote.ActionData; import mage.view.*; import org.apache.log4j.Logger; import org.jboss.remoting.*; @@ -896,10 +893,8 @@ public class SessionImpl implements Session { @Override public void appendJsonLog(ActionData actionData) { actionData.sessionId = getSessionId(); - String logFileName = "game-" + actionData.gameId + ".json"; - System.out.println("Logging to " + logFileName); - try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFileName, true)))) { + try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFileName, true)))) { out.println(actionData.toJson()); } catch (IOException e) { System.err.println(e);