mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Some minor changes to JSON game log (#4587).
This commit is contained in:
parent
15602cdfb3
commit
51c68842aa
5 changed files with 68 additions and 80 deletions
|
|
@ -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<String> KEEP = new java.util.HashSet<String>(
|
||||
private final java.util.Set<String> 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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue