Merge pull request #4535 from spjspj/master

Add option to get debug information from game state in chat
This commit is contained in:
spjspj 2018-02-19 12:27:51 +11:00 committed by GitHub
commit f523c3c614
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 124 additions and 6 deletions

View file

@ -28,6 +28,7 @@
package mage.server;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
@ -37,6 +38,8 @@ import java.util.regex.Pattern;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.server.exceptions.UserNotFoundException;
import mage.server.game.GameController;
import mage.server.game.GameManager;
import mage.server.util.SystemUtil;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
@ -220,6 +223,27 @@ public enum ChatManager {
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
if (command.startsWith("GAME")) {
message += "<br/>" + GameManager.instance.getChatId(chatId);
ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) {
String gameId = session.getInfo();
if (gameId.startsWith("Game ")) {
UUID id = java.util.UUID.fromString(gameId.substring(5, gameId.length()));
for (Entry<UUID, GameController> entry : GameManager.instance.getGameController().entrySet()) {
if (entry.getKey().equals(id)) {
GameController controller = entry.getValue();
if (controller != null) {
message += controller.getGameStateDebugMessage();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
}
}
}
}
return true;
}
if (command.startsWith("CARD ")) {
Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase());
if (matchPattern.find()) {
@ -289,18 +313,18 @@ public enum ChatManager {
public void sendReconnectMessage(UUID userId) {
UserManager.instance.getUser(userId).ifPresent(user
-> getChatSessions()
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, MessageType.STATUS, null)));
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, MessageType.STATUS, null)));
}
public void sendLostConnectionMessage(UUID userId, DisconnectReason reason) {
UserManager.instance.getUser(userId).ifPresent(user
-> getChatSessions()
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + reason.getMessage(), MessageColor.BLUE, true, MessageType.STATUS, null)));
.stream()
.filter(chat -> chat.hasUser(userId))
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + reason.getMessage(), MessageColor.BLUE, true, MessageType.STATUS, null)));
}

View file

@ -50,6 +50,7 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.GameException;
import mage.game.GameOptions;
import mage.game.GameState;
import mage.game.Table;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
@ -1088,4 +1089,97 @@ public class GameController implements GameCallback {
return false;
}
public String getGameStateDebugMessage() {
if (game == null) {
return "";
}
GameState state = game.getState();
if (state == null) {
return "";
}
StringBuilder sb = new StringBuilder();
sb.append("<br/>Game State:<br/><font size=-2>");
sb.append(state);
sb.append("<br>Active player is: ");
sb.append(game.getPlayer(state.getActivePlayerId()).getName());
sb.append("<br>isGameOver: ");
sb.append(state.isGameOver());
sb.append("<br>Current phase is: ");
sb.append(state.getTurn().getPhase());
sb.append("<br>getBattlefield: ");
sb.append(state.getBattlefield());
sb.append("<br>getChoosingPlayerId: ");
if (state.getChoosingPlayerId() != null) {
sb.append(game.getPlayer(state.getChoosingPlayerId()).getName());
} else {
sb.append("noone!");
}
sb.append("<br>getCombat: ");
sb.append(state.getCombat());
sb.append("<br>getCommand: ");
sb.append(state.getCommand());
sb.append("<br>getContinuousEffects: ");
sb.append(state.getContinuousEffects());
sb.append("<br>getCopiedCards: ");
sb.append(state.getCopiedCards());
sb.append("<br>getDelayed: ");
sb.append(state.getDelayed());
sb.append("<br>getDesignations: ");
sb.append(state.getDesignations());
sb.append("<br>getExile: ");
sb.append(state.getExile());
sb.append("<br>getMonarchId: ");
sb.append(state.getMonarchId());
sb.append("<br>getNextPermanentOrderNumber: ");
sb.append(state.getNextPermanentOrderNumber());
sb.append("<br>getPlayerByOrderId: ");
if (state.getPlayerByOrderId() != null) {
sb.append(game.getPlayer(state.getPlayerByOrderId()).getName());
} else {
sb.append("noone!");
}
sb.append("<br>getPlayerList: ");
sb.append(state.getPlayerList());
sb.append("<br>getPlayers: ");
sb.append(state.getPlayers());
sb.append("<br>Player with Priority is: ");
if (state.getPriorityPlayerId() != null) {
sb.append(game.getPlayer(state.getPriorityPlayerId()).getName());
} else {
sb.append("noone!");
}
sb.append("<br>getRevealed: ");
sb.append(state.getRevealed());
sb.append("<br>getSpecialActions: ");
sb.append(state.getSpecialActions());
sb.append("<br>getStack: ");
sb.append(state.getStack());
sb.append("<br>getStepNum: ");
sb.append(state.getStepNum());
sb.append("<br>getTriggers: ");
sb.append(state.getTriggers());
sb.append("<br>getTurn: ");
sb.append(state.getTurn());
sb.append("<br>getTurnId: ");
sb.append(state.getTurnId());
sb.append("<br>getTurnMods: ");
sb.append(state.getTurnMods());
sb.append("<br>getTurnNum: ");
sb.append(state.getTurnNum());
sb.append("<br>Future Timeout:");
if (futureTimeout != null) {
sb.append("Cancelled?=");
sb.append(futureTimeout.isCancelled());
sb.append(",,,Done?=");
sb.append(futureTimeout.isDone());
sb.append(",,,GetDelay?=");
sb.append((int) futureTimeout.getDelay(TimeUnit.SECONDS));
} else {
sb.append("Not using future Timeout!");
}
sb.append("</font>");
return sb.toString();
}
}