Added option to activate/deactivate JSON game log. Added logic to write the logs to subdirectory. Some changes to SEND_PLAYER_ACTION type logging.

This commit is contained in:
LevelX2 2018-03-10 00:04:56 +01:00
parent dc5220df4f
commit b60522f9e4
7 changed files with 138 additions and 70 deletions

1
.gitignore vendored
View file

@ -4,6 +4,7 @@ syntax: glob
Mage.Client/*.dck Mage.Client/*.dck
Mage.Client/db Mage.Client/db
Mage.Client/gamelogs Mage.Client/gamelogs
Mage.Client/gamelogsJson
Mage.Client/*.log Mage.Client/*.log
Mage.Client/plugins/images Mage.Client/plugins/images
Mage.Client/plugins/plugin.data Mage.Client/plugins/plugin.data

View file

@ -1,7 +1,9 @@
package mage.client; package mage.client;
import java.util.*;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.client.chat.LocalCommands; import mage.client.chat.LocalCommands;
import mage.client.dialog.PreferencesDialog;
import mage.constants.ManaType; import mage.constants.ManaType;
import mage.constants.PlayerAction; import mage.constants.PlayerAction;
import mage.game.match.MatchOptions; import mage.game.match.MatchOptions;
@ -14,8 +16,6 @@ import mage.remote.Session;
import mage.remote.SessionImpl; import mage.remote.SessionImpl;
import mage.view.*; import mage.view.*;
import java.util.*;
/** /**
* Created by IGOUDT on 15-9-2016. * Created by IGOUDT on 15-9-2016.
*/ */
@ -26,6 +26,7 @@ public final class SessionHandler {
public static void startSession(MageFrame mageFrame) { public static void startSession(MageFrame mageFrame) {
session = new SessionImpl(mageFrame); session = new SessionImpl(mageFrame);
session.setJsonLogActive("true".equals(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_LOG_AUTO_SAVE, "true")));
} }
public static void ping() { public static void ping() {
@ -322,7 +323,7 @@ public final class SessionHandler {
} }
public static void updateDeck(UUID tableId, DeckCardLists deckCardLists) { public static void updateDeck(UUID tableId, DeckCardLists deckCardLists) {
session.updateDeck(tableId, deckCardLists); session.updateDeck(tableId, deckCardLists);
} }
public static boolean emailAuthToken(Connection connection) { public static boolean emailAuthToken(Connection connection) {
@ -330,10 +331,10 @@ public final class SessionHandler {
} }
public static boolean resetPassword(Connection connection) { public static boolean resetPassword(Connection connection) {
return session.resetPassword(connection); return session.resetPassword(connection);
} }
public static boolean register(Connection connection) { public static boolean register(Connection connection) {
return session.register(connection); return session.register(connection);
} }
} }

View file

@ -25,17 +25,18 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="saveButton" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="exitButton" min="-2" pref="100" max="-2" attributes="0"/> <Group type="103" groupAlignment="1" attributes="0">
<Component id="tabsPanel" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="saveButton" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="exitButton" min="-2" pref="100" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/> <EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="tabsPanel" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
@ -94,10 +95,10 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="main_game" min="-2" max="-2" attributes="0"/> <Component id="main_game" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="main_gamelog" min="-2" max="-2" attributes="0"/> <Component id="main_gamelog" min="-2" pref="107" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="main_battlefield" min="-2" max="-2" attributes="0"/> <Component id="main_battlefield" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="154" max="32767" attributes="0"/> <EmptySpace pref="121" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -121,9 +122,10 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="cbDraftLogAutoSave" max="32767" attributes="0"/> <Component id="cbDraftLogAutoSave" min="-2" max="-2" attributes="0"/>
<Component id="cbGameLogAutoSave" max="32767" attributes="0"/> <Component id="cbGameJsonLogAutoSave" min="-2" max="-2" attributes="0"/>
<Component id="cbGameLogAutoSave" alignment="0" min="-2" pref="505" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
</Group> </Group>
@ -134,7 +136,10 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="cbGameLogAutoSave" alignment="1" min="-2" max="-2" attributes="0"/> <Component id="cbGameLogAutoSave" alignment="1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="cbDraftLogAutoSave" alignment="1" min="-2" max="-2" attributes="0"/> <Component id="cbDraftLogAutoSave" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbGameJsonLogAutoSave" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -143,7 +148,7 @@
<Component class="javax.swing.JCheckBox" name="cbGameLogAutoSave"> <Component class="javax.swing.JCheckBox" name="cbGameLogAutoSave">
<Properties> <Properties>
<Property name="selected" type="boolean" value="true"/> <Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Auto save game logs (to &quot;../Mage.Client/gamelogs/&quot; directory)"/> <Property name="text" type="java.lang.String" value="Save game logs (to &quot;../Mage.Client/gamelogs/&quot; directory)"/>
<Property name="toolTipText" type="java.lang.String" value="The logs of all your games will be saved to the mentioned folder if this option is switched on."/> <Property name="toolTipText" type="java.lang.String" value="The logs of all your games will be saved to the mentioned folder if this option is switched on."/>
</Properties> </Properties>
<Events> <Events>
@ -153,13 +158,23 @@
<Component class="javax.swing.JCheckBox" name="cbDraftLogAutoSave"> <Component class="javax.swing.JCheckBox" name="cbDraftLogAutoSave">
<Properties> <Properties>
<Property name="selected" type="boolean" value="true"/> <Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Auto save draft logs (to &quot;../Mage.Client/gamelogs/&quot; directory)"/> <Property name="text" type="java.lang.String" value="Save draft logs (to &quot;../Mage.Client/gamelogs/&quot; directory)"/>
<Property name="toolTipText" type="java.lang.String" value="The logs of all your games will be saved to the mentioned folder if this option is switched on."/> <Property name="toolTipText" type="java.lang.String" value="The logs of all your games will be saved to the mentioned folder if this option is switched on."/>
</Properties> </Properties>
<Events> <Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbDraftLogAutoSaveActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbDraftLogAutoSaveActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JCheckBox" name="cbGameJsonLogAutoSave">
<Properties>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Save JSON game logs (to &quot;../Mage.Client/gamelogsJson/&quot; directory)"/>
<Property name="toolTipText" type="java.lang.String" value="The JSON logs of all your games will be saved to the mentioned folder if this option is switched on."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbGameJsonLogAutoSaveActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Container> </Container>
<Container class="javax.swing.JPanel" name="main_card"> <Container class="javax.swing.JPanel" name="main_card">
@ -221,7 +236,7 @@
<Property name="toolTipText" type="java.lang.String" value="Write the card&apos;s name on the card to make the card name more recognizable."/> <Property name="toolTipText" type="java.lang.String" value="Write the card&apos;s name on the card to make the card name more recognizable."/>
<Property name="actionCommand" type="java.lang.String" value=""/> <Property name="actionCommand" type="java.lang.String" value=""/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/> <Color id="Standardcursor"/>
</Property> </Property>
</Properties> </Properties>
<Events> <Events>
@ -252,7 +267,7 @@
<Property name="selected" type="boolean" value="true"/> <Property name="selected" type="boolean" value="true"/>
<Property name="toolTipText" type="java.lang.String" value="Show the path Xmage is expecting for this card&apos;s image (only displays if missing)"/> <Property name="toolTipText" type="java.lang.String" value="Show the path Xmage is expecting for this card&apos;s image (only displays if missing)"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor"> <Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/> <Color id="Standardcursor"/>
</Property> </Property>
<Property name="label" type="java.lang.String" value="Display image path for missing images"/> <Property name="label" type="java.lang.String" value="Display image path for missing images"/>
</Properties> </Properties>
@ -289,7 +304,7 @@
<Component id="cbAskMoveToGraveOrder" alignment="0" max="32767" attributes="0"/> <Component id="cbAskMoveToGraveOrder" alignment="0" max="32767" attributes="0"/>
<Component id="showAbilityPickerForced" alignment="0" max="32767" attributes="0"/> <Component id="showAbilityPickerForced" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace pref="255" max="32767" attributes="0"/> <EmptySpace pref="177" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -4318,7 +4333,7 @@
</Group> </Group>
<Component id="cbUseDefaultImageFolder" min="-2" max="-2" attributes="0"/> <Component id="cbUseDefaultImageFolder" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="0" pref="270" max="32767" attributes="0"/> <EmptySpace min="0" pref="308" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -5743,7 +5758,7 @@
<Component id="jLabel17" min="-2" max="-2" attributes="0"/> <Component id="jLabel17" min="-2" max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace pref="198" max="32767" attributes="0"/> <EmptySpace pref="201" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -6008,7 +6023,7 @@
<Component id="keyToggleRecordMacro" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="keyToggleRecordMacro" alignment="0" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="controlsDescriptionLabel" pref="441" max="32767" attributes="0"/> <Component id="controlsDescriptionLabel" pref="478" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>

View file

@ -65,12 +65,11 @@ import javax.swing.filechooser.FileFilter;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.SessionHandler; import mage.client.SessionHandler;
import mage.client.components.KeyBindButton; import mage.client.components.KeyBindButton;
import static mage.client.constants.Constants.BATTLEFIELD_FEEDBACK_COLORIZING_MODE_ENABLE_BY_MULTICOLOR;
import mage.client.util.Config; import mage.client.util.Config;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper; import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder; import mage.client.util.gui.BufferedImageBuilder;
import static mage.client.constants.Constants.BATTLEFIELD_FEEDBACK_COLORIZING_MODE_ENABLE_BY_MULTICOLOR;
import static mage.constants.Constants.DEFAULT_AVATAR_ID; import static mage.constants.Constants.DEFAULT_AVATAR_ID;
import static mage.constants.Constants.MAX_AVATAR_ID; import static mage.constants.Constants.MAX_AVATAR_ID;
import static mage.constants.Constants.MIN_AVATAR_ID; import static mage.constants.Constants.MIN_AVATAR_ID;
@ -79,6 +78,7 @@ import mage.players.net.UserGroup;
import mage.players.net.UserSkipPrioritySteps; import mage.players.net.UserSkipPrioritySteps;
import mage.remote.Connection; import mage.remote.Connection;
import mage.remote.Connection.ProxyType; import mage.remote.Connection.ProxyType;
import mage.remote.Session;
import mage.view.UserRequestMessage; import mage.view.UserRequestMessage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -122,6 +122,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave"; public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave";
public static final String KEY_DRAFT_LOG_AUTO_SAVE = "draftLogAutoSave"; public static final String KEY_DRAFT_LOG_AUTO_SAVE = "draftLogAutoSave";
public static final String KEY_JSON_GAME_LOG_AUTO_SAVE = "gameLogJsonAutoSave";
public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault"; public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault";
public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath"; public static final String KEY_CARD_IMAGES_PATH = "cardImagesPath";
@ -406,6 +407,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
main_gamelog = new javax.swing.JPanel(); main_gamelog = new javax.swing.JPanel();
cbGameLogAutoSave = new javax.swing.JCheckBox(); cbGameLogAutoSave = new javax.swing.JCheckBox();
cbDraftLogAutoSave = new javax.swing.JCheckBox(); cbDraftLogAutoSave = new javax.swing.JCheckBox();
cbGameJsonLogAutoSave = new javax.swing.JCheckBox();
main_card = new javax.swing.JPanel(); main_card = new javax.swing.JPanel();
showCardName = new javax.swing.JCheckBox(); showCardName = new javax.swing.JCheckBox();
tooltipDelayLabel = new javax.swing.JLabel(); tooltipDelayLabel = new javax.swing.JLabel();
@ -600,7 +602,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
main_gamelog.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Game log")); main_gamelog.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Game log"));
cbGameLogAutoSave.setSelected(true); cbGameLogAutoSave.setSelected(true);
cbGameLogAutoSave.setText("Auto save game logs (to \"../Mage.Client/gamelogs/\" directory)"); cbGameLogAutoSave.setText("Save game logs (to \"../Mage.Client/gamelogs/\" directory)");
cbGameLogAutoSave.setToolTipText("The logs of all your games will be saved to the mentioned folder if this option is switched on."); cbGameLogAutoSave.setToolTipText("The logs of all your games will be saved to the mentioned folder if this option is switched on.");
cbGameLogAutoSave.addActionListener(new java.awt.event.ActionListener() { cbGameLogAutoSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -609,7 +611,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
}); });
cbDraftLogAutoSave.setSelected(true); cbDraftLogAutoSave.setSelected(true);
cbDraftLogAutoSave.setText("Auto save draft logs (to \"../Mage.Client/gamelogs/\" directory)"); cbDraftLogAutoSave.setText("Save draft logs (to \"../Mage.Client/gamelogs/\" directory)");
cbDraftLogAutoSave.setToolTipText("The logs of all your games will be saved to the mentioned folder if this option is switched on."); cbDraftLogAutoSave.setToolTipText("The logs of all your games will be saved to the mentioned folder if this option is switched on.");
cbDraftLogAutoSave.addActionListener(new java.awt.event.ActionListener() { cbDraftLogAutoSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) { public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -617,15 +619,25 @@ public class PreferencesDialog extends javax.swing.JDialog {
} }
}); });
cbGameJsonLogAutoSave.setSelected(true);
cbGameJsonLogAutoSave.setText("Save JSON game logs (to \"../Mage.Client/gamelogsJson/\" directory)");
cbGameJsonLogAutoSave.setToolTipText("The JSON logs of all your games will be saved to the mentioned folder if this option is switched on.");
cbGameJsonLogAutoSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbGameJsonLogAutoSaveActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout main_gamelogLayout = new org.jdesktop.layout.GroupLayout(main_gamelog); org.jdesktop.layout.GroupLayout main_gamelogLayout = new org.jdesktop.layout.GroupLayout(main_gamelog);
main_gamelog.setLayout(main_gamelogLayout); main_gamelog.setLayout(main_gamelogLayout);
main_gamelogLayout.setHorizontalGroup( main_gamelogLayout.setHorizontalGroup(
main_gamelogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) main_gamelogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(main_gamelogLayout.createSequentialGroup() .add(main_gamelogLayout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.add(main_gamelogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) .add(main_gamelogLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(cbDraftLogAutoSave, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(cbDraftLogAutoSave)
.add(cbGameLogAutoSave, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .add(cbGameJsonLogAutoSave)
.add(cbGameLogAutoSave, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 505, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
main_gamelogLayout.setVerticalGroup( main_gamelogLayout.setVerticalGroup(
@ -633,7 +645,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
.add(main_gamelogLayout.createSequentialGroup() .add(main_gamelogLayout.createSequentialGroup()
.add(cbGameLogAutoSave) .add(cbGameLogAutoSave)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cbDraftLogAutoSave)) .add(cbDraftLogAutoSave)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cbGameJsonLogAutoSave)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
main_card.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Card")); main_card.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Card"));
@ -785,7 +800,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.add(cbShowStormCounter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(cbShowStormCounter, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(cbAskMoveToGraveOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(cbAskMoveToGraveOrder, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(showAbilityPickerForced, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .add(showAbilityPickerForced, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(255, Short.MAX_VALUE)) .addContainerGap(177, Short.MAX_VALUE))
); );
main_gameLayout.setVerticalGroup( main_gameLayout.setVerticalGroup(
main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) main_gameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
@ -860,10 +875,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(main_game, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(main_game, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(main_gamelog, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(main_gamelog, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(main_battlefield, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(main_battlefield, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(154, Short.MAX_VALUE)) .addContainerGap(121, Short.MAX_VALUE))
); );
main_card.getAccessibleContext().setAccessibleName("Game panel"); main_card.getAccessibleContext().setAccessibleName("Game panel");
@ -1582,7 +1597,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(cbNumberOfDownloadThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) .add(cbNumberOfDownloadThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.add(cbUseDefaultImageFolder)) .add(cbUseDefaultImageFolder))
.add(0, 270, Short.MAX_VALUE))) .add(0, 308, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
panelCardImagesLayout.setVerticalGroup( panelCardImagesLayout.setVerticalGroup(
@ -2387,7 +2402,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.add(connection_serversLayout.createSequentialGroup() .add(connection_serversLayout.createSequentialGroup()
.add(141, 141, 141) .add(141, 141, 141)
.add(jLabel17))) .add(jLabel17)))
.addContainerGap(198, Short.MAX_VALUE)) .addContainerGap(201, Short.MAX_VALUE))
); );
connection_serversLayout.setVerticalGroup( connection_serversLayout.setVerticalGroup(
connection_serversLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) connection_serversLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
@ -2626,7 +2641,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
.add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE))) .add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
tabControlsLayout.setVerticalGroup( tabControlsLayout.setVerticalGroup(
@ -2708,16 +2723,16 @@ public class PreferencesDialog extends javax.swing.JDialog {
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(saveButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(exitButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(6, 6, 6))
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.add(tabsPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.addContainerGap()) .add(org.jdesktop.layout.GroupLayout.LEADING, tabsPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.add(0, 0, Short.MAX_VALUE)
.add(saveButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(exitButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(6, 6, 6))
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
@ -2749,6 +2764,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.cbAskMoveToGraveOrder, KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY); save(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbGameJsonLogAutoSave, KEY_JSON_GAME_LOG_AUTO_SAVE, "true", "false", UPDATE_CACHE_POLICY);
String paramName = KEY_BATTLEFIELD_FEEDBACK_COLORIZING_MODE; String paramName = KEY_BATTLEFIELD_FEEDBACK_COLORIZING_MODE;
int paramValue = dialog.cbBattlefieldFeedbackColorizingMode.getSelectedIndex(); int paramValue = dialog.cbBattlefieldFeedbackColorizingMode.getSelectedIndex();
@ -3197,6 +3213,13 @@ public class PreferencesDialog extends javax.swing.JDialog {
}//GEN-LAST:event_cbBattlefieldFeedbackColorizingModeActionPerformed }//GEN-LAST:event_cbBattlefieldFeedbackColorizingModeActionPerformed
private void cbGameJsonLogAutoSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbGameJsonLogAutoSaveActionPerformed
Session session = SessionHandler.getSession();
if (session != null) {
session.setJsonLogActive(cbGameJsonLogAutoSave.isSelected());
}
}//GEN-LAST:event_cbGameJsonLogAutoSaveActionPerformed
private void showProxySettings() { private void showProxySettings() {
Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem(); Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem();
switch (proxyType) { switch (proxyType) {
@ -3311,6 +3334,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true"); load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true");
load(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true"); load(prefs, dialog.cbDraftLogAutoSave, KEY_DRAFT_LOG_AUTO_SAVE, "true");
load(prefs, dialog.cbGameJsonLogAutoSave, KEY_JSON_GAME_LOG_AUTO_SAVE, "true", "false");
String feedbackParam = ""; String feedbackParam = "";
try { try {
@ -3865,6 +3889,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
private javax.swing.JCheckBox cbEnableGameSounds; private javax.swing.JCheckBox cbEnableGameSounds;
private javax.swing.JCheckBox cbEnableOtherSounds; private javax.swing.JCheckBox cbEnableOtherSounds;
private javax.swing.JCheckBox cbEnableSkipButtonsSounds; private javax.swing.JCheckBox cbEnableSkipButtonsSounds;
private javax.swing.JCheckBox cbGameJsonLogAutoSave;
private javax.swing.JCheckBox cbGameLogAutoSave; private javax.swing.JCheckBox cbGameLogAutoSave;
private javax.swing.JComboBox cbNumberOfDownloadThreads; private javax.swing.JComboBox cbNumberOfDownloadThreads;
private javax.swing.JCheckBox cbPassPriorityActivation; private javax.swing.JCheckBox cbPassPriorityActivation;

View file

@ -190,16 +190,15 @@ public class CallbackClientImpl implements CallbackClient {
break; break;
} }
case GAME_OVER: { case GAME_OVER: {
GamePanel panel = MageFrame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) { if (panel != null) {
appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData()); Session session = SessionHandler.getSession();
ActionData actionData = appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData()); if (session.isJsonLogActive()) {
String logFileName = "game-" + actionData.gameId + ".json"; appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData());
ActionData actionData = appendJsonEvent("GAME_OVER", callback.getObjectId(), callback.getData());
S3Uploader.upload(logFileName, actionData.gameId.toString()); String logFileName = "game-" + actionData.gameId + ".json";
S3Uploader.upload(logFileName, actionData.gameId.toString());
}
panel.endMessage((String) callback.getData(), callback.getMessageId()); panel.endMessage((String) callback.getData(), callback.getMessageId());
} }
break; break;
@ -408,10 +407,13 @@ public class CallbackClientImpl implements CallbackClient {
private ActionData appendJsonEvent(String name, UUID gameId, Object value) { private ActionData appendJsonEvent(String name, UUID gameId, Object value) {
Session session = SessionHandler.getSession(); Session session = SessionHandler.getSession();
ActionData actionData = new ActionData(name, gameId); if (session.isJsonLogActive()) {
actionData.value = value; ActionData actionData = new ActionData(name, gameId);
session.appendJsonLog(actionData); actionData.value = value;
return actionData; session.appendJsonLog(actionData);
return actionData;
}
return null;
} }
private void createChatStartMessage(ChatPanelBasic chatPanel) { private void createChatStartMessage(ChatPanelBasic chatPanel) {

View file

@ -28,6 +28,7 @@
package mage.remote; package mage.remote;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -89,6 +90,7 @@ public class SessionImpl implements Session {
private static boolean debugMode = false; private static boolean debugMode = false;
private boolean canceled = false; private boolean canceled = false;
private boolean jsonLogActive = false;
static { static {
debugMode = System.getProperty("debug.mage") != null; debugMode = System.getProperty("debug.mage") != null;
@ -892,12 +894,20 @@ public class SessionImpl implements Session {
@Override @Override
public void appendJsonLog(ActionData actionData) { public void appendJsonLog(ActionData actionData) {
actionData.sessionId = getSessionId(); if (isJsonLogActive()) {
String logFileName = "game-" + actionData.gameId + ".json"; String dir = "gamelogsJson";
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFileName, true)))) { File saveDir = new File(dir);
out.println(actionData.toJson()); //Existence check
} catch (IOException e) { if (!saveDir.exists()) {
System.err.println(e); saveDir.mkdirs();
}
actionData.sessionId = getSessionId();
String logFileName = dir + File.separator + "game-" + actionData.gameId + ".json";
try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFileName, true)))) {
out.println(actionData.toJson());
} catch (IOException e) {
logger.error("Cant write JSON game log file - " + logFileName, e);
}
} }
} }
@ -1308,7 +1318,7 @@ public class SessionImpl implements Session {
if (isConnected()) { if (isConnected()) {
ActionData actionData = new ActionData("SEND_PLAYER_ACTION", gameId, getSessionId()); ActionData actionData = new ActionData("SEND_PLAYER_ACTION", gameId, getSessionId());
actionData.value = data; actionData.value = passPriorityAction + (data != null ? " " + data.toString() : "");
appendJsonLog(actionData); appendJsonLog(actionData);
server.sendPlayerAction(passPriorityAction, gameId, sessionId, data); server.sendPlayerAction(passPriorityAction, gameId, sessionId, data);
@ -1634,6 +1644,16 @@ public class SessionImpl implements Session {
} }
} }
@Override
public boolean isJsonLogActive() {
return jsonLogActive;
}
@Override
public void setJsonLogActive(boolean jsonLogActive) {
this.jsonLogActive = jsonLogActive;
}
} }
class MageAuthenticator extends Authenticator { class MageAuthenticator extends Authenticator {

View file

@ -37,4 +37,8 @@ public interface ClientData {
String getUserName(); String getUserName();
boolean updatePreferencesForServer(UserData userData); boolean updatePreferencesForServer(UserData userData);
void setJsonLogActive(boolean active);
boolean isJsonLogActive();
} }