server: improved logs for some use cases (related to #11572)

This commit is contained in:
Oleg Agafonov 2023-12-28 00:30:07 +04:00
parent fac5f8c752
commit e79f562f4a
4 changed files with 20 additions and 8 deletions

View file

@ -19,6 +19,7 @@ import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackType; import mage.interfaces.callback.ClientCallbackType;
import mage.remote.ActionData; import mage.remote.ActionData;
import mage.remote.Session; import mage.remote.Session;
import mage.util.DebugUtil;
import mage.view.*; import mage.view.*;
import mage.view.ChatMessage.MessageType; import mage.view.ChatMessage.MessageType;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -34,8 +35,6 @@ public class CallbackClientImpl implements CallbackClient {
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class); private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
private static final boolean DEBUG_CALLBACK_MESSAGES_LOG = false; // show all callback messages (server commands)
private final MageFrame frame; private final MageFrame frame;
private final Map<ClientCallbackType, Integer> lastMessages; private final Map<ClientCallbackType, Integer> lastMessages;
private final Map<UUID, GameClientMessage> firstGameData; private final Map<UUID, GameClientMessage> firstGameData;
@ -71,7 +70,7 @@ public class CallbackClientImpl implements CallbackClient {
// all GUI related code must be executed in swing thread // all GUI related code must be executed in swing thread
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
try { try {
if (DEBUG_CALLBACK_MESSAGES_LOG) { if (DebugUtil.NETWORK_SHOW_CLIENT_CALLBACK_MESSAGES_LOG) {
logger.info("message " + callback.getMessageId() + " - " + callback.getMethod().getType() + " - " + callback.getMethod()); logger.info("message " + callback.getMessageId() + " - " + callback.getMethod().getType() + " - " + callback.getMethod());
} }

View file

@ -211,16 +211,18 @@ public class HumanPlayer extends PlayerImpl {
// game frozen, possible reasons: // game frozen, possible reasons:
// * ANOTHER player lost connection and GAME thread trying to send data to him // * ANOTHER player lost connection and GAME thread trying to send data to him
// * current player send answer, but lost connect after it // * current player send answer, but lost connect after it
// * game thread stops and lost
String possibleReason; String possibleReason;
if (response.getActiveAction() == null) { if (response.getActiveAction() == null) {
possibleReason = "maybe connection problem with another player/watcher"; possibleReason = "maybe connection problem with another player/watcher";
} else { } else {
possibleReason = "something wrong with your priority on " + response.getActiveAction(); possibleReason = "something wrong with your priority on " + response.getActiveAction();
} }
logger.warn(String.format("Game frozen in waitResponseOpen for %d secs: current user %s, %s", logger.warn(String.format("Game frozen in waitResponseOpen for %d secs. User: %s; reason: %s; game: %s",
RESPONSE_WAITING_CHECK_MS * currentTimesWaiting / 1000, RESPONSE_WAITING_CHECK_MS * currentTimesWaiting / 1000,
this.getName(), this.getName(),
possibleReason possibleReason,
response.getActiveGameInfo()
)); ));
return false; return false;
} }
@ -308,7 +310,7 @@ public class HumanPlayer extends PlayerImpl {
while (loop) { while (loop) {
// start waiting for next answer // start waiting for next answer
response.clear(); response.clear();
response.setActiveAction(DebugUtil.getMethodNameWithSource(2)); response.setActiveAction(game, DebugUtil.getMethodNameWithSource(2));
game.resumeTimer(getTurnControlledBy()); game.resumeTimer(getTurnControlledBy());
responseOpenedForAnswer = true; responseOpenedForAnswer = true;

View file

@ -1,6 +1,7 @@
package mage.player.human; package mage.player.human;
import mage.constants.ManaType; import mage.constants.ManaType;
import mage.game.Game;
import mage.util.Copyable; import mage.util.Copyable;
import java.io.Serializable; import java.io.Serializable;
@ -20,7 +21,8 @@ import java.util.UUID;
*/ */
public class PlayerResponse implements Serializable, Copyable<PlayerResponse> { public class PlayerResponse implements Serializable, Copyable<PlayerResponse> {
private String activeAction; // for debug information private String activeAction; // for logs/debug information
private String activeGameInfo; // for logs/debug info
private String responseString; private String responseString;
private UUID responseUUID; private UUID responseUUID;
@ -64,6 +66,7 @@ public class PlayerResponse implements Serializable, Copyable<PlayerResponse> {
public void copyFrom(final PlayerResponse response) { public void copyFrom(final PlayerResponse response) {
this.activeAction = response.activeAction; this.activeAction = response.activeAction;
this.activeGameInfo = response.activeGameInfo;
this.responseString = response.responseString; this.responseString = response.responseString;
this.responseUUID = response.responseUUID; this.responseUUID = response.responseUUID;
this.responseBoolean = response.responseBoolean; this.responseBoolean = response.responseBoolean;
@ -76,6 +79,7 @@ public class PlayerResponse implements Serializable, Copyable<PlayerResponse> {
public void clear() { public void clear() {
this.activeAction = null; this.activeAction = null;
this.activeGameInfo = null;
this.responseString = null; this.responseString = null;
this.responseUUID = null; this.responseUUID = null;
this.responseBoolean = null; this.responseBoolean = null;
@ -90,8 +94,13 @@ public class PlayerResponse implements Serializable, Copyable<PlayerResponse> {
return this.activeAction; return this.activeAction;
} }
public void setActiveAction(String activeAction) { public String getActiveGameInfo() {
return this.activeGameInfo;
}
public void setActiveAction(Game game, String activeAction) {
this.activeAction = activeAction; this.activeAction = activeAction;
this.activeGameInfo = game.getId() + ", " + game;
} }
public String getString() { public String getString() {

View file

@ -11,6 +11,8 @@ import java.lang.reflect.Method;
*/ */
public class DebugUtil { public class DebugUtil {
public static boolean NETWORK_SHOW_CLIENT_CALLBACK_MESSAGES_LOG = false; // show all callback messages (server commands)
// cards basic (card panels) // cards basic (card panels)
public static boolean GUI_CARD_DRAW_OUTER_BORDER = false; public static boolean GUI_CARD_DRAW_OUTER_BORDER = false;
public static boolean GUI_CARD_DRAW_INNER_BORDER = false; public static boolean GUI_CARD_DRAW_INNER_BORDER = false;