mirror of
https://github.com/correl/mage.git
synced 2025-04-11 09:11:12 -09:00
* Some chnages to chat, user and player handling.
This commit is contained in:
parent
58627bfcf6
commit
52897094b3
9 changed files with 258 additions and 88 deletions
Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human
Mage.Server/src/main/java/mage/server
ChatManager.javaChatSession.javaSession.javaTableController.javaTableManager.javaUserManager.java
game
Mage/src/main/java/mage/players
|
@ -705,7 +705,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
// it's a main phase
|
// it's a main phase
|
||||||
if (!skippedAtLeastOnce
|
if (!skippedAtLeastOnce
|
||||||
|| (!playerId.equals(game.getActivePlayerId())
|
|| (!playerId.equals(game.getActivePlayerId())
|
||||||
&& !this.getUserData().getUserSkipPrioritySteps().isStopOnAllMainPhases())) {
|
&& !controllingPlayer.getUserData().getUserSkipPrioritySteps().isStopOnAllMainPhases())) {
|
||||||
skippedAtLeastOnce = true;
|
skippedAtLeastOnce = true;
|
||||||
if (passWithManaPoolCheck(game)) {
|
if (passWithManaPoolCheck(game)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -726,7 +726,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
// It's end of turn phase
|
// It's end of turn phase
|
||||||
if (!skippedAtLeastOnce
|
if (!skippedAtLeastOnce
|
||||||
|| (playerId.equals(game.getActivePlayerId())
|
|| (playerId.equals(game.getActivePlayerId())
|
||||||
&& !this.getUserData().getUserSkipPrioritySteps().isStopOnAllEndPhases())) {
|
&& !controllingPlayer.getUserData().getUserSkipPrioritySteps().isStopOnAllEndPhases())) {
|
||||||
skippedAtLeastOnce = true;
|
skippedAtLeastOnce = true;
|
||||||
if (passWithManaPoolCheck(game)) {
|
if (passWithManaPoolCheck(game)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -834,7 +834,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType());
|
return !controllingPlayer.getUserData().getUserSkipPrioritySteps().getOpponentTurn().isPhaseStepSet(game.getStep().getType());
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ex) {
|
} catch (NullPointerException ex) {
|
||||||
String isNull = userData == null ? "null" : "not null";
|
String isNull = controllingPlayer.getUserData() == null ? "null" : "not null";
|
||||||
logger.error("null pointer exception UserData = " + isNull);
|
logger.error("null pointer exception UserData = " + isNull);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -843,7 +843,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
@Override
|
@Override
|
||||||
public TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game) {
|
public TriggeredAbility chooseTriggeredAbility(List<TriggeredAbility> abilities, Game game) {
|
||||||
String autoOrderRuleText = null;
|
String autoOrderRuleText = null;
|
||||||
boolean autoOrderUse = getUserData().isAutoOrderTrigger();
|
boolean autoOrderUse = getControllingPlayersUserData(game).isAutoOrderTrigger();
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
// try to set trigger auto order
|
// try to set trigger auto order
|
||||||
List<TriggeredAbility> abilitiesWithNoOrderSet = new ArrayList<>();
|
List<TriggeredAbility> abilitiesWithNoOrderSet = new ArrayList<>();
|
||||||
|
@ -1045,7 +1045,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
if (passedAllTurns
|
if (passedAllTurns
|
||||||
|| passedUntilEndStepBeforeMyTurn
|
|| passedUntilEndStepBeforeMyTurn
|
||||||
|| (!getUserData().getUserSkipPrioritySteps().isStopOnDeclareAttackersDuringSkipAction()
|
|| (!getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareAttackersDuringSkipAction()
|
||||||
&& (passedTurn
|
&& (passedTurn
|
||||||
|| passedTurnSkipStack
|
|| passedTurnSkipStack
|
||||||
|| passedUntilEndOfTurn
|
|| passedUntilEndOfTurn
|
||||||
|
@ -1223,7 +1223,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy();
|
FilterCreatureForCombatBlock filter = filterCreatureForCombatBlock.copy();
|
||||||
filter.add(new ControllerIdPredicate(defendingPlayerId));
|
filter.add(new ControllerIdPredicate(defendingPlayerId));
|
||||||
if (game.getBattlefield().count(filter, null, playerId, game) == 0
|
if (game.getBattlefield().count(filter, null, playerId, game) == 0
|
||||||
&& !getUserData().getUserSkipPrioritySteps().isStopOnDeclareBlockerIfNoneAvailable()) {
|
&& !getControllingPlayersUserData(game).getUserSkipPrioritySteps().isStopOnDeclareBlockerIfNoneAvailable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
@ -1420,7 +1420,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
protected void activateAbility(LinkedHashMap<UUID, ? extends ActivatedAbility> abilities, MageObject object, Game game) {
|
protected void activateAbility(LinkedHashMap<UUID, ? extends ActivatedAbility> abilities, MageObject object, Game game) {
|
||||||
updateGameStatePriority("activateAbility", game);
|
updateGameStatePriority("activateAbility", game);
|
||||||
if (abilities.size() == 1
|
if (abilities.size() == 1
|
||||||
&& suppressAbilityPicker(abilities.values().iterator().next())) {
|
&& suppressAbilityPicker(abilities.values().iterator().next(), game)) {
|
||||||
ActivatedAbility ability = abilities.values().iterator().next();
|
ActivatedAbility ability = abilities.values().iterator().next();
|
||||||
if (!ability.getTargets().isEmpty()
|
if (!ability.getTargets().isEmpty()
|
||||||
|| !(ability.getCosts().size() == 1
|
|| !(ability.getCosts().size() == 1
|
||||||
|
@ -1452,8 +1452,8 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean suppressAbilityPicker(ActivatedAbility ability) {
|
private boolean suppressAbilityPicker(ActivatedAbility ability, Game game) {
|
||||||
if (this.getUserData().isShowAbilityPickerForced()) {
|
if (getControllingPlayersUserData(game).isShowAbilityPickerForced()) {
|
||||||
if (ability instanceof PlayLandAbility) {
|
if (ability instanceof PlayLandAbility) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,13 @@
|
||||||
*/
|
*/
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import mage.cards.repository.CardInfo;
|
import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.CardRepository;
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.server.exceptions.UserNotFoundException;
|
import mage.server.exceptions.UserNotFoundException;
|
||||||
|
@ -36,11 +43,6 @@ import mage.view.ChatMessage.MessageType;
|
||||||
import mage.view.ChatMessage.SoundToPlay;
|
import mage.view.ChatMessage.SoundToPlay;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
|
@ -51,6 +53,7 @@ public enum ChatManager {
|
||||||
private static final HashMap<String, String> userMessages = new HashMap<>();
|
private static final HashMap<String, String> userMessages = new HashMap<>();
|
||||||
|
|
||||||
private final ConcurrentHashMap<UUID, ChatSession> chatSessions = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<UUID, ChatSession> chatSessions = new ConcurrentHashMap<>();
|
||||||
|
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
public UUID createChatSession(String info) {
|
public UUID createChatSession(String info) {
|
||||||
ChatSession chatSession = new ChatSession(info);
|
ChatSession chatSession = new ChatSession(info);
|
||||||
|
@ -68,6 +71,10 @@ public enum ChatManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearUserMessageStorage() {
|
||||||
|
userMessages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void leaveChat(UUID chatId, UUID userId) {
|
public void leaveChat(UUID chatId, UUID userId) {
|
||||||
ChatSession chatSession = chatSessions.get(chatId);
|
ChatSession chatSession = chatSessions.get(chatId);
|
||||||
if (chatSession != null && chatSession.hasUser(userId)) {
|
if (chatSession != null && chatSession.hasUser(userId)) {
|
||||||
|
@ -81,7 +88,13 @@ public enum ChatManager {
|
||||||
if (chatSession != null) {
|
if (chatSession != null) {
|
||||||
synchronized (chatSession) {
|
synchronized (chatSession) {
|
||||||
if (chatSessions.containsKey(chatId)) {
|
if (chatSessions.containsKey(chatId)) {
|
||||||
|
final Lock w = lock.writeLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
chatSessions.remove(chatId);
|
chatSessions.remove(chatId);
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
logger.trace("Chat removed - chatId: " + chatId);
|
logger.trace("Chat removed - chatId: " + chatId);
|
||||||
} else {
|
} else {
|
||||||
logger.trace("Chat to destroy does not exist - chatId: " + chatId);
|
logger.trace("Chat to destroy does not exist - chatId: " + chatId);
|
||||||
|
@ -263,10 +276,11 @@ public enum ChatManager {
|
||||||
* @param userId
|
* @param userId
|
||||||
* @param message
|
* @param message
|
||||||
* @param color
|
* @param color
|
||||||
|
* @throws mage.server.exceptions.UserNotFoundException
|
||||||
*/
|
*/
|
||||||
public void broadcast(UUID userId, String message, MessageColor color) throws UserNotFoundException {
|
public void broadcast(UUID userId, String message, MessageColor color) throws UserNotFoundException {
|
||||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||||
chatSessions.values()
|
getChatSessions()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(chat -> chat.hasUser(userId))
|
.filter(chat -> chat.hasUser(userId))
|
||||||
.forEach(session -> session.broadcast(user.getName(), message, color, true, MessageType.TALK, null));
|
.forEach(session -> session.broadcast(user.getName(), message, color, true, MessageType.TALK, null));
|
||||||
|
@ -276,7 +290,7 @@ public enum ChatManager {
|
||||||
|
|
||||||
public void sendReconnectMessage(UUID userId) {
|
public void sendReconnectMessage(UUID userId) {
|
||||||
UserManager.instance.getUser(userId).ifPresent(user
|
UserManager.instance.getUser(userId).ifPresent(user
|
||||||
-> chatSessions.values()
|
-> getChatSessions()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(chat -> chat.hasUser(userId))
|
.filter(chat -> chat.hasUser(userId))
|
||||||
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, MessageType.STATUS, null)));
|
.forEach(chatSession -> chatSession.broadcast(null, user.getName() + " has reconnected", MessageColor.BLUE, true, MessageType.STATUS, null)));
|
||||||
|
@ -284,7 +298,7 @@ public enum ChatManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(UUID userId, DisconnectReason reason) {
|
public void removeUser(UUID userId, DisconnectReason reason) {
|
||||||
for (ChatSession chatSession : chatSessions.values()) {
|
for (ChatSession chatSession : getChatSessions()) {
|
||||||
if (chatSession.hasUser(userId)) {
|
if (chatSession.hasUser(userId)) {
|
||||||
chatSession.kill(userId, reason);
|
chatSession.kill(userId, reason);
|
||||||
}
|
}
|
||||||
|
@ -292,7 +306,13 @@ public enum ChatManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ChatSession> getChatSessions() {
|
public List<ChatSession> getChatSessions() {
|
||||||
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
|
try {
|
||||||
return new ArrayList<>(chatSessions.values());
|
return new ArrayList<>(chatSessions.values());
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,9 @@ package mage.server;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.interfaces.callback.ClientCallbackMethod;
|
import mage.interfaces.callback.ClientCallbackMethod;
|
||||||
import mage.view.ChatMessage;
|
import mage.view.ChatMessage;
|
||||||
|
@ -46,6 +49,8 @@ public class ChatSession {
|
||||||
private static final Logger logger = Logger.getLogger(ChatSession.class);
|
private static final Logger logger = Logger.getLogger(ChatSession.class);
|
||||||
private static final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
private static final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||||
|
|
||||||
|
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
private final ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<>();
|
||||||
private final UUID chatId;
|
private final UUID chatId;
|
||||||
private final Date createTime;
|
private final Date createTime;
|
||||||
|
@ -61,7 +66,13 @@ public class ChatSession {
|
||||||
UserManager.instance.getUser(userId).ifPresent(user -> {
|
UserManager.instance.getUser(userId).ifPresent(user -> {
|
||||||
if (!clients.containsKey(userId)) {
|
if (!clients.containsKey(userId)) {
|
||||||
String userName = user.getName();
|
String userName = user.getName();
|
||||||
|
final Lock w = lock.writeLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
clients.put(userId, userName);
|
clients.put(userId, userName);
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
broadcast(null, userName + " has joined (" + user.getClientVersion() + ')', MessageColor.BLUE, true, MessageType.STATUS, null);
|
broadcast(null, userName + " has joined (" + user.getClientVersion() + ')', MessageColor.BLUE, true, MessageType.STATUS, null);
|
||||||
logger.trace(userName + " joined chat " + chatId);
|
logger.trace(userName + " joined chat " + chatId);
|
||||||
}
|
}
|
||||||
|
@ -77,8 +88,14 @@ public class ChatSession {
|
||||||
}
|
}
|
||||||
if (userId != null && clients.containsKey(userId)) {
|
if (userId != null && clients.containsKey(userId)) {
|
||||||
String userName = clients.get(userId);
|
String userName = clients.get(userId);
|
||||||
if (reason != DisconnectReason.LostConnection) { // for lost connection the user will be reconnected or session expire so no removeUserFromAllTables of chat yet
|
if (reason != DisconnectReason.LostConnection) { // for lost connection the user will be reconnected or session expire so no removeUserFromAllTablesAndChat of chat yet
|
||||||
|
final Lock w = lock.writeLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
clients.remove(userId);
|
clients.remove(userId);
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
logger.debug(userName + '(' + reason.toString() + ')' + " removed from chatId " + chatId);
|
logger.debug(userName + '(' + reason.toString() + ')' + " removed from chatId " + chatId);
|
||||||
}
|
}
|
||||||
String message = reason.getMessage();
|
String message = reason.getMessage();
|
||||||
|
@ -117,7 +134,15 @@ public class ChatSession {
|
||||||
if (!message.isEmpty()) {
|
if (!message.isEmpty()) {
|
||||||
Set<UUID> clientsToRemove = new HashSet<>();
|
Set<UUID> clientsToRemove = new HashSet<>();
|
||||||
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
ClientCallback clientCallback = new ClientCallback(ClientCallbackMethod.CHATMESSAGE, chatId, new ChatMessage(userName, message, (withTime ? timeFormatter.format(new Date()) : ""), color, messageType, soundToPlay));
|
||||||
for (UUID userId : clients.keySet()) {
|
List<UUID> chatUserIds = new ArrayList<>();
|
||||||
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
|
try {
|
||||||
|
chatUserIds.addAll(clients.keySet());
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
|
for (UUID userId : chatUserIds) {
|
||||||
Optional<User> user = UserManager.instance.getUser(userId);
|
Optional<User> user = UserManager.instance.getUser(userId);
|
||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
user.get().fireCallback(clientCallback);
|
user.get().fireCallback(clientCallback);
|
||||||
|
@ -125,7 +150,15 @@ public class ChatSession {
|
||||||
clientsToRemove.add(userId);
|
clientsToRemove.add(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!clientsToRemove.isEmpty()) {
|
||||||
|
final Lock w = lock.readLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
clients.keySet().removeAll(clientsToRemove);
|
clients.keySet().removeAll(clientsToRemove);
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,7 @@ public class Session {
|
||||||
} else {
|
} else {
|
||||||
logger.error("SESSION LOCK - kill: userId " + userId);
|
logger.error("SESSION LOCK - kill: userId " + userId);
|
||||||
}
|
}
|
||||||
UserManager.instance.removeUserFromAllTables(userId, reason);
|
UserManager.instance.removeUserFromAllTablesAndChat(userId, reason);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
logger.error("SESSION LOCK - kill: userId " + userId, ex);
|
logger.error("SESSION LOCK - kill: userId " + userId, ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -511,7 +511,7 @@ public class TableController {
|
||||||
if (this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user
|
if (this.userId != null && this.userId.equals(userId) // tourn. sub tables have no creator user
|
||||||
&& (table.getState() == TableState.WAITING
|
&& (table.getState() == TableState.WAITING
|
||||||
|| table.getState() == TableState.READY_TO_START)) {
|
|| table.getState() == TableState.READY_TO_START)) {
|
||||||
// table not started yet and user is the owner, removeUserFromAllTables the table
|
// table not started yet and user is the owner, removeUserFromAllTablesAndChat the table
|
||||||
TableManager.instance.removeTable(table.getId());
|
TableManager.instance.removeTable(table.getId());
|
||||||
} else {
|
} else {
|
||||||
UUID playerId = userPlayerMap.get(userId);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
|
@ -826,7 +826,7 @@ public class TableController {
|
||||||
}
|
}
|
||||||
user.showUserMessage("Match info", sb.toString());
|
user.showUserMessage("Match info", sb.toString());
|
||||||
}
|
}
|
||||||
// removeUserFromAllTables table from user - table manager holds table for display of finished matches
|
// removeUserFromAllTablesAndChat table from user - table manager holds table for display of finished matches
|
||||||
if (!table.isTournamentSubTable()) {
|
if (!table.isTournamentSubTable()) {
|
||||||
user.removeTable(entry.getValue());
|
user.removeTable(entry.getValue());
|
||||||
}
|
}
|
||||||
|
@ -913,7 +913,7 @@ public class TableController {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// check if table creator is still a valid user, if not removeUserFromAllTables table
|
// check if table creator is still a valid user, if not removeUserFromAllTablesAndChat table
|
||||||
return UserManager.instance.getUser(userId).isPresent();
|
return UserManager.instance.getUser(userId).isPresent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ public enum TableManager {
|
||||||
TableManager() {
|
TableManager() {
|
||||||
expireExecutor.scheduleAtFixedRate(() -> {
|
expireExecutor.scheduleAtFixedRate(() -> {
|
||||||
try {
|
try {
|
||||||
|
ChatManager.instance.clearUserMessageStorage();
|
||||||
checkTableHealthState();
|
checkTableHealthState();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Check table health state job error:", ex);
|
logger.fatal("Check table health state job error:", ex);
|
||||||
|
@ -161,7 +162,7 @@ public enum TableManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeUserFromAllTables user from all tournament sub tables
|
// removeUserFromAllTablesAndChat user from all tournament sub tables
|
||||||
public void userQuitTournamentSubTables(UUID userId) {
|
public void userQuitTournamentSubTables(UUID userId) {
|
||||||
for (TableController controller : controllers.values()) {
|
for (TableController controller : controllers.values()) {
|
||||||
if (controller.getTable() != null) {
|
if (controller.getTable() != null) {
|
||||||
|
@ -174,7 +175,7 @@ public enum TableManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeUserFromAllTables user from all sub tables of a tournament
|
// removeUserFromAllTablesAndChat user from all sub tables of a tournament
|
||||||
public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
|
public void userQuitTournamentSubTables(UUID tournamentId, UUID userId) {
|
||||||
for (TableController controller : controllers.values()) {
|
for (TableController controller : controllers.values()) {
|
||||||
if (controller.getTable().isTournamentSubTable() && controller.getTable().getTournament().getId().equals(tournamentId)) {
|
if (controller.getTable().isTournamentSubTable() && controller.getTable().getTournament().getId().equals(tournamentId)) {
|
||||||
|
@ -386,8 +387,8 @@ public enum TableManager {
|
||||||
for (Table table : tableCopy) {
|
for (Table table : tableCopy) {
|
||||||
try {
|
try {
|
||||||
if (table.getState() != TableState.FINISHED
|
if (table.getState() != TableState.FINISHED
|
||||||
&& ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // removeUserFromAllTables only if table started longer than 30 seconds ago
|
&& ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // removeUserFromAllTablesAndChat only if table started longer than 30 seconds ago
|
||||||
// removeUserFromAllTables tables and games not valid anymore
|
// removeUserFromAllTablesAndChat tables and games not valid anymore
|
||||||
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
|
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
|
||||||
getController(table.getId()).ifPresent(tableController -> {
|
getController(table.getId()).ifPresent(tableController -> {
|
||||||
if ((table.isTournament() && !tableController.isTournamentStillValid())
|
if ((table.isTournament() && !tableController.isTournamentStillValid())
|
||||||
|
|
|
@ -29,6 +29,9 @@ package mage.server;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
import mage.server.User.UserState;
|
import mage.server.User.UserState;
|
||||||
import mage.server.record.UserStats;
|
import mage.server.record.UserStats;
|
||||||
import mage.server.record.UserStatsRepository;
|
import mage.server.record.UserStatsRepository;
|
||||||
|
@ -54,6 +57,7 @@ public enum UserManager {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(UserManager.class);
|
private static final Logger LOGGER = Logger.getLogger(UserManager.class);
|
||||||
|
|
||||||
|
private final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
private final ConcurrentHashMap<UUID, User> users = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<UUID, User> users = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static final ExecutorService USER_EXECUTOR = ThreadExecutor.instance.getCallExecutor();
|
private static final ExecutorService USER_EXECUTOR = ThreadExecutor.instance.getCallExecutor();
|
||||||
|
@ -69,7 +73,13 @@ public enum UserManager {
|
||||||
return Optional.empty(); //user already exists
|
return Optional.empty(); //user already exists
|
||||||
}
|
}
|
||||||
User user = new User(userName, host, authorizedUser);
|
User user = new User(userName, host, authorizedUser);
|
||||||
|
final Lock w = lock.writeLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
users.put(user.getId(), user);
|
users.put(user.getId(), user);
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
return Optional.of(user);
|
return Optional.of(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +93,9 @@ public enum UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<User> getUserByName(String userName) {
|
public Optional<User> getUserByName(String userName) {
|
||||||
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
|
try {
|
||||||
Optional<User> u = users.values().stream().filter(user -> user.getName().equals(userName))
|
Optional<User> u = users.values().stream().filter(user -> user.getName().equals(userName))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (u.isPresent()) {
|
if (u.isPresent()) {
|
||||||
|
@ -90,10 +103,22 @@ public enum UserManager {
|
||||||
} else {
|
} else {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<User> getUsers() {
|
public Collection<User> getUsers() {
|
||||||
return users.values();
|
ArrayList<User> userList = new ArrayList<>();
|
||||||
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
|
try {
|
||||||
|
userList.addAll(users.values());
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
|
return userList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean connectToSession(String sessionId, UUID userId) {
|
public boolean connectToSession(String sessionId, UUID userId) {
|
||||||
|
@ -112,13 +137,10 @@ public enum UserManager {
|
||||||
if (user.isPresent()) {
|
if (user.isPresent()) {
|
||||||
user.get().setSessionId("");
|
user.get().setSessionId("");
|
||||||
if (reason == DisconnectReason.Disconnected) {
|
if (reason == DisconnectReason.Disconnected) {
|
||||||
removeUserFromAllTables(userId, reason);
|
removeUserFromAllTablesAndChat(userId, reason);
|
||||||
user.get().setUserState(UserState.Offline);
|
user.get().setUserState(UserState.Offline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (userId != null) {
|
|
||||||
ChatManager.instance.removeUser(userId, reason);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin(UUID userId) {
|
public boolean isAdmin(UUID userId) {
|
||||||
|
@ -131,7 +153,7 @@ public enum UserManager {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUserFromAllTables(final UUID userId, final DisconnectReason reason) {
|
public void removeUserFromAllTablesAndChat(final UUID userId, final DisconnectReason reason) {
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
getUser(userId).ifPresent(user
|
getUser(userId).ifPresent(user
|
||||||
-> USER_EXECUTOR.execute(
|
-> USER_EXECUTOR.execute(
|
||||||
|
@ -139,6 +161,7 @@ public enum UserManager {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId + " [" + user.getGameInfo() + ']');
|
LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId + " [" + user.getGameInfo() + ']');
|
||||||
user.removeUserFromAllTables(reason);
|
user.removeUserFromAllTables(reason);
|
||||||
|
ChatManager.instance.removeUser(user.getId(), reason);
|
||||||
LOGGER.debug("USER REMOVE END - " + user.getName());
|
LOGGER.debug("USER REMOVE END - " + user.getName());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
@ -173,7 +196,16 @@ public enum UserManager {
|
||||||
Calendar calendarRemove = Calendar.getInstance();
|
Calendar calendarRemove = Calendar.getInstance();
|
||||||
calendarRemove.add(Calendar.MINUTE, -8);
|
calendarRemove.add(Calendar.MINUTE, -8);
|
||||||
List<User> toRemove = new ArrayList<>();
|
List<User> toRemove = new ArrayList<>();
|
||||||
for (User user : users.values()) {
|
logger.info("Start Check Expired");
|
||||||
|
ArrayList<User> userList = new ArrayList<>();
|
||||||
|
final Lock r = lock.readLock();
|
||||||
|
r.lock();
|
||||||
|
try {
|
||||||
|
userList.addAll(users.values());
|
||||||
|
} finally {
|
||||||
|
r.unlock();
|
||||||
|
}
|
||||||
|
for (User user : userList) {
|
||||||
try {
|
try {
|
||||||
if (user.getUserState() == UserState.Offline) {
|
if (user.getUserState() == UserState.Offline) {
|
||||||
if (user.isExpired(calendarRemove.getTime())) {
|
if (user.isExpired(calendarRemove.getTime())) {
|
||||||
|
@ -185,7 +217,7 @@ public enum UserManager {
|
||||||
user.lostConnection();
|
user.lostConnection();
|
||||||
disconnect(user.getId(), DisconnectReason.BecameInactive);
|
disconnect(user.getId(), DisconnectReason.BecameInactive);
|
||||||
}
|
}
|
||||||
removeUserFromAllTables(user.getId(), DisconnectReason.SessionExpired);
|
removeUserFromAllTablesAndChat(user.getId(), DisconnectReason.SessionExpired);
|
||||||
user.setUserState(UserState.Offline);
|
user.setUserState(UserState.Offline);
|
||||||
// Remove the user from all tournaments
|
// Remove the user from all tournaments
|
||||||
|
|
||||||
|
@ -195,9 +227,17 @@ public enum UserManager {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.info("Users to remove " + toRemove.size());
|
||||||
|
final Lock w = lock.readLock();
|
||||||
|
w.lock();
|
||||||
|
try {
|
||||||
for (User user : toRemove) {
|
for (User user : toRemove) {
|
||||||
users.remove(user.getId());
|
users.remove(user.getId());
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
w.unlock();
|
||||||
|
}
|
||||||
|
logger.info("End Check Expired");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
} else if (matchList.size() < 50) {
|
} else if (matchList.size() < 50) {
|
||||||
matchList.add(new MatchView(table));
|
matchList.add(new MatchView(table));
|
||||||
} else {
|
} else {
|
||||||
// more since 50 matches finished since this match so removeUserFromAllTables it
|
// more since 50 matches finished since this match so removeUserFromAllTablesAndChat it
|
||||||
if (table.isTournament()) {
|
if (table.isTournament()) {
|
||||||
TournamentManager.instance.removeTournament(table.getTournament().getId());
|
TournamentManager.instance.removeTournament(table.getTournament().getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,11 @@ import mage.cards.CardsImpl;
|
||||||
import mage.cards.SplitCard;
|
import mage.cards.SplitCard;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
|
import static mage.constants.Zone.BATTLEFIELD;
|
||||||
|
import static mage.constants.Zone.EXILED;
|
||||||
|
import static mage.constants.Zone.GRAVEYARD;
|
||||||
|
import static mage.constants.Zone.HAND;
|
||||||
|
import static mage.constants.Zone.LIBRARY;
|
||||||
import mage.counters.Counter;
|
import mage.counters.Counter;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.counters.Counters;
|
import mage.counters.Counters;
|
||||||
|
@ -965,6 +970,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
ability = chooseSpellAbilityForCast(ability, game, noMana);
|
ability = chooseSpellAbilityForCast(ability, game, noMana);
|
||||||
}
|
}
|
||||||
//20091005 - 601.2a
|
//20091005 - 601.2a
|
||||||
|
if (ability.getSourceId() == null) {
|
||||||
|
logger.error("Ability without sourceId turn " + game.getTurnNum() + ". Ability: " + ability.getRule());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Card card = game.getCard(ability.getSourceId());
|
Card card = game.getCard(ability.getSourceId());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId), ability)) {
|
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId), ability)) {
|
||||||
|
@ -2931,15 +2940,27 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
return this.userData;
|
return this.userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserData getControllingPlayersUserData(Game game) {
|
||||||
|
if (isGameUnderControl()) {
|
||||||
|
Player player = game.getPlayer(getTurnControlledBy());
|
||||||
|
if (player.isHuman()) {
|
||||||
|
return player.getUserData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.userData;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUserData(UserData userData) {
|
public void setUserData(UserData userData
|
||||||
|
) {
|
||||||
this.userData = userData;
|
this.userData = userData;
|
||||||
getManaPool().setAutoPayment(userData.isManaPoolAutomatic());
|
getManaPool().setAutoPayment(userData.isManaPoolAutomatic());
|
||||||
getManaPool().setAutoPaymentRestricted(userData.isManaPoolAutomaticRestricted());
|
getManaPool().setAutoPaymentRestricted(userData.isManaPoolAutomaticRestricted());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAction(String action) {
|
public void addAction(String action
|
||||||
|
) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2949,7 +2970,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAllowBadMoves(boolean allowBadMoves) {
|
public void setAllowBadMoves(boolean allowBadMoves
|
||||||
|
) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2959,17 +2981,21 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCanPayLifeCost(boolean canPayLifeCost) {
|
public void setCanPayLifeCost(boolean canPayLifeCost
|
||||||
|
) {
|
||||||
this.canPayLifeCost = canPayLifeCost;
|
this.canPayLifeCost = canPayLifeCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPaySacrificeCost(Permanent permanent, UUID sourceId, UUID controllerId, Game game) {
|
public boolean canPaySacrificeCost(Permanent permanent, UUID sourceId,
|
||||||
|
UUID controllerId, Game game
|
||||||
|
) {
|
||||||
return sacrificeCostFilter == null || !sacrificeCostFilter.match(permanent, sourceId, controllerId, game);
|
return sacrificeCostFilter == null || !sacrificeCostFilter.match(permanent, sourceId, controllerId, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCanPaySacrificeCostFilter(FilterPermanent filter) {
|
public void setCanPaySacrificeCostFilter(FilterPermanent filter
|
||||||
|
) {
|
||||||
this.sacrificeCostFilter = filter;
|
this.sacrificeCostFilter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2984,7 +3010,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLoseByZeroOrLessLife(boolean loseByZeroOrLessLife) {
|
public void setLoseByZeroOrLessLife(boolean loseByZeroOrLessLife
|
||||||
|
) {
|
||||||
this.loseByZeroOrLessLife = loseByZeroOrLessLife;
|
this.loseByZeroOrLessLife = loseByZeroOrLessLife;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2994,7 +3021,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPlayCardsFromGraveyard(boolean playCardsFromGraveyard) {
|
public void setPlayCardsFromGraveyard(boolean playCardsFromGraveyard
|
||||||
|
) {
|
||||||
this.canPlayCardsFromGraveyard = playCardsFromGraveyard;
|
this.canPlayCardsFromGraveyard = playCardsFromGraveyard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3021,12 +3049,14 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStoredBookmark(int storedBookmark) {
|
public void setStoredBookmark(int storedBookmark
|
||||||
|
) {
|
||||||
this.storedBookmark = storedBookmark;
|
this.storedBookmark = storedBookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void resetStoredBookmark(Game game) {
|
public synchronized void resetStoredBookmark(Game game
|
||||||
|
) {
|
||||||
if (this.storedBookmark != -1) {
|
if (this.storedBookmark != -1) {
|
||||||
game.removeBookmark(this.storedBookmark);
|
game.removeBookmark(this.storedBookmark);
|
||||||
}
|
}
|
||||||
|
@ -3034,7 +3064,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean lookAtFaceDownCard(Card card, Game game) {
|
public boolean lookAtFaceDownCard(Card card, Game game
|
||||||
|
) {
|
||||||
if (game.getContinuousEffects().asThough(card.getId(), AsThoughEffectType.LOOK_AT_FACE_DOWN, this.getId(), game)) {
|
if (game.getContinuousEffects().asThough(card.getId(), AsThoughEffectType.LOOK_AT_FACE_DOWN, this.getId(), game)) {
|
||||||
if (chooseUse(Outcome.Benefit, "Look at that card?", null, game)) {
|
if (chooseUse(Outcome.Benefit, "Look at that card?", null, game)) {
|
||||||
Cards cards = new CardsImpl(card);
|
Cards cards = new CardsImpl(card);
|
||||||
|
@ -3046,7 +3077,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPriorityTimeLeft(int timeLeft) {
|
public void setPriorityTimeLeft(int timeLeft
|
||||||
|
) {
|
||||||
priorityTimeLeft = timeLeft;
|
priorityTimeLeft = timeLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3071,7 +3103,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReachedNextTurnAfterLeaving(boolean reachedNextTurnAfterLeaving) {
|
public void setReachedNextTurnAfterLeaving(boolean reachedNextTurnAfterLeaving
|
||||||
|
) {
|
||||||
this.reachedNextTurnAfterLeaving = reachedNextTurnAfterLeaving;
|
this.reachedNextTurnAfterLeaving = reachedNextTurnAfterLeaving;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3081,12 +3114,14 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canJoinTable(Table table) {
|
public boolean canJoinTable(Table table
|
||||||
|
) {
|
||||||
return !table.userIsBanned(name);
|
return !table.userIsBanned(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addCommanderId(UUID commanderId) {
|
public void addCommanderId(UUID commanderId
|
||||||
|
) {
|
||||||
this.commandersIds.add(commanderId);
|
this.commandersIds.add(commanderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3096,12 +3131,17 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCards(Card card, Zone toZone, Ability source, Game game) {
|
public boolean moveCards(Card card, Zone toZone,
|
||||||
|
Ability source, Game game
|
||||||
|
) {
|
||||||
return moveCards(card, toZone, source, game, false, false, false, null);
|
return moveCards(card, toZone, source, game, false, false, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCards(Card card, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects) {
|
public boolean moveCards(Card card, Zone toZone,
|
||||||
|
Ability source, Game game,
|
||||||
|
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
|
||||||
|
) {
|
||||||
Set<Card> cardList = new HashSet<>();
|
Set<Card> cardList = new HashSet<>();
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
cardList.add(card);
|
cardList.add(card);
|
||||||
|
@ -3110,17 +3150,24 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCards(Cards cards, Zone toZone, Ability source, Game game) {
|
public boolean moveCards(Cards cards, Zone toZone,
|
||||||
|
Ability source, Game game
|
||||||
|
) {
|
||||||
return moveCards(cards.getCards(game), toZone, source, game);
|
return moveCards(cards.getCards(game), toZone, source, game);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCards(Set<Card> cards, Zone toZone, Ability source, Game game) {
|
public boolean moveCards(Set<Card> cards, Zone toZone,
|
||||||
|
Ability source, Game game
|
||||||
|
) {
|
||||||
return moveCards(cards, toZone, source, game, false, false, false, null);
|
return moveCards(cards, toZone, source, game, false, false, false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCards(Set<Card> cards, Zone toZone, Ability source, Game game, boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects) {
|
public boolean moveCards(Set<Card> cards, Zone toZone,
|
||||||
|
Ability source, Game game,
|
||||||
|
boolean tapped, boolean faceDown, boolean byOwner, List<UUID> appliedEffects
|
||||||
|
) {
|
||||||
if (cards.isEmpty()) {
|
if (cards.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3194,14 +3241,20 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardsToExile(Card card, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName) {
|
public boolean moveCardsToExile(Card card, Ability source,
|
||||||
|
Game game, boolean withName, UUID exileId,
|
||||||
|
String exileZoneName
|
||||||
|
) {
|
||||||
Set<Card> cards = new HashSet<>();
|
Set<Card> cards = new HashSet<>();
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
return moveCardsToExile(cards, source, game, withName, exileId, exileZoneName);
|
return moveCardsToExile(cards, source, game, withName, exileId, exileZoneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardsToExile(Set<Card> cards, Ability source, Game game, boolean withName, UUID exileId, String exileZoneName) {
|
public boolean moveCardsToExile(Set<Card> cards, Ability source,
|
||||||
|
Game game, boolean withName, UUID exileId,
|
||||||
|
String exileZoneName
|
||||||
|
) {
|
||||||
if (cards.isEmpty()) {
|
if (cards.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -3214,12 +3267,16 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game) {
|
public boolean moveCardToHandWithInfo(Card card, UUID sourceId,
|
||||||
|
Game game
|
||||||
|
) {
|
||||||
return this.moveCardToHandWithInfo(card, sourceId, game, true);
|
return this.moveCardToHandWithInfo(card, sourceId, game, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardToHandWithInfo(Card card, UUID sourceId, Game game, boolean withName) {
|
public boolean moveCardToHandWithInfo(Card card, UUID sourceId,
|
||||||
|
Game game, boolean withName
|
||||||
|
) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
Zone fromZone = game.getState().getZone(card.getId());
|
Zone fromZone = game.getState().getZone(card.getId());
|
||||||
if (fromZone == Zone.BATTLEFIELD && !(card instanceof Permanent)) {
|
if (fromZone == Zone.BATTLEFIELD && !(card instanceof Permanent)) {
|
||||||
|
@ -3242,7 +3299,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<Card> moveCardsToGraveyardWithInfo(Set<Card> allCards, Ability source, Game game, Zone fromZone) {
|
public Set<Card> moveCardsToGraveyardWithInfo(Set<Card> allCards, Ability source,
|
||||||
|
Game game, Zone fromZone
|
||||||
|
) {
|
||||||
UUID sourceId = source == null ? null : source.getSourceId();
|
UUID sourceId = source == null ? null : source.getSourceId();
|
||||||
Set<Card> movedCards = new LinkedHashSet<>();
|
Set<Card> movedCards = new LinkedHashSet<>();
|
||||||
while (!allCards.isEmpty()) {
|
while (!allCards.isEmpty()) {
|
||||||
|
@ -3309,7 +3368,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId, Game game, Zone fromZone) {
|
public boolean moveCardToGraveyardWithInfo(Card card, UUID sourceId,
|
||||||
|
Game game, Zone fromZone
|
||||||
|
) {
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3336,7 +3397,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardToLibraryWithInfo(Card card, UUID sourceId, Game game, Zone fromZone, boolean toTop, boolean withName) {
|
public boolean moveCardToLibraryWithInfo(Card card, UUID sourceId,
|
||||||
|
Game game, Zone fromZone,
|
||||||
|
boolean toTop, boolean withName
|
||||||
|
) {
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3368,7 +3432,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean moveCardToExileWithInfo(Card card, UUID exileId, String exileName, UUID sourceId, Game game, Zone fromZone, boolean withName) {
|
public boolean moveCardToExileWithInfo(Card card, UUID exileId,
|
||||||
|
String exileName, UUID sourceId,
|
||||||
|
Game game, Zone fromZone,
|
||||||
|
boolean withName
|
||||||
|
) {
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3398,7 +3466,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasOpponent(UUID playerToCheckId, Game game) {
|
public boolean hasOpponent(UUID playerToCheckId, Game game
|
||||||
|
) {
|
||||||
return !this.getId().equals(playerToCheckId) && game.isOpponent(this, playerToCheckId);
|
return !this.getId().equals(playerToCheckId) && game.isOpponent(this, playerToCheckId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3443,7 +3512,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setJustActivatedType(AbilityType justActivatedType) {
|
public void setJustActivatedType(AbilityType justActivatedType
|
||||||
|
) {
|
||||||
this.justActivatedType = justActivatedType;
|
this.justActivatedType = justActivatedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3453,7 +3523,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPermissionToShowHandCards(UUID watcherUserId) {
|
public void addPermissionToShowHandCards(UUID watcherUserId
|
||||||
|
) {
|
||||||
usersAllowedToSeeHandCards.add(watcherUserId);
|
usersAllowedToSeeHandCards.add(watcherUserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3463,7 +3534,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasUserPermissionToSeeHand(UUID userId) {
|
public boolean hasUserPermissionToSeeHand(UUID userId
|
||||||
|
) {
|
||||||
return usersAllowedToSeeHandCards.contains(userId);
|
return usersAllowedToSeeHandCards.contains(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3473,7 +3545,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setMatchPlayer(MatchPlayer matchPlayer) {
|
public void setMatchPlayer(MatchPlayer matchPlayer
|
||||||
|
) {
|
||||||
this.matchPlayer = matchPlayer;
|
this.matchPlayer = matchPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3488,7 +3561,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean scry(int value, Ability source, Game game) {
|
public boolean scry(int value, Ability source,
|
||||||
|
Game game
|
||||||
|
) {
|
||||||
game.informPlayers(getLogName() + " scries " + value);
|
game.informPlayers(getLogName() + " scries " + value);
|
||||||
Cards cards = new CardsImpl();
|
Cards cards = new CardsImpl();
|
||||||
cards.addAll(getLibrary().getTopCards(game, value));
|
cards.addAll(getLibrary().getTopCards(game, value));
|
||||||
|
@ -3510,7 +3585,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addTargets(Ability ability, Game game) {
|
public boolean addTargets(Ability ability, Game game
|
||||||
|
) {
|
||||||
// only used for TestPlayer to preSet Targets
|
// only used for TestPlayer to preSet Targets
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue