mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
tests: added runtime check for wrong usage of inform messages inside layer effects (disabled by default, related to #13259, #11285)
This commit is contained in:
parent
bbd0fa2ffb
commit
d75792312e
2 changed files with 20 additions and 3 deletions
|
|
@ -3169,6 +3169,7 @@ public abstract class GameImpl implements Game {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.INFO, message, this);
|
tableEventSource.fireTableEvent(EventType.INFO, message, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3177,6 +3178,7 @@ public abstract class GameImpl implements Game {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, withTurnInfo, this);
|
tableEventSource.fireTableEvent(EventType.STATUS, message, withTime, withTurnInfo, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3185,7 +3187,7 @@ public abstract class GameImpl implements Game {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.trace("fireUpdatePlayersEvent");
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
|
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
|
||||||
getState().clearLookedAt();
|
getState().clearLookedAt();
|
||||||
getState().clearRevealed();
|
getState().clearRevealed();
|
||||||
|
|
@ -3196,15 +3198,27 @@ public abstract class GameImpl implements Game {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.trace("fireGameEndIfo");
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.END_GAME_INFO, null, this);
|
tableEventSource.fireTableEvent(EventType.END_GAME_INFO, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fireErrorEvent(String message, Exception ex) {
|
public void fireErrorEvent(String message, Exception ex) {
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.ERROR, message, ex, this);
|
tableEventSource.fireTableEvent(EventType.ERROR, message, ex, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void makeSureCalledOutsideLayersEffects() {
|
||||||
|
// very slow, enable/comment it for debug or load/stability tests only
|
||||||
|
// TODO: enable check and remove/rework all wrong usages
|
||||||
|
if (true) return;
|
||||||
|
Arrays.stream(Thread.currentThread().getStackTrace()).forEach(e -> {
|
||||||
|
if (e.toString().contains("GameState.applyEffects")) {
|
||||||
|
throw new IllegalStateException("Wrong code usage: client side events can't be called from layers effects (wrong informPlayers usage?");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Players getPlayers() {
|
public Players getPlayers() {
|
||||||
return state.getPlayers();
|
return state.getPlayers();
|
||||||
|
|
@ -3871,6 +3885,7 @@ public abstract class GameImpl implements Game {
|
||||||
@Override
|
@Override
|
||||||
public void initTimer(UUID playerId) {
|
public void initTimer(UUID playerId) {
|
||||||
if (priorityTime > 0) {
|
if (priorityTime > 0) {
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.INIT_TIMER, playerId, null, this);
|
tableEventSource.fireTableEvent(EventType.INIT_TIMER, playerId, null, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3878,6 +3893,7 @@ public abstract class GameImpl implements Game {
|
||||||
@Override
|
@Override
|
||||||
public void resumeTimer(UUID playerId) {
|
public void resumeTimer(UUID playerId) {
|
||||||
if (priorityTime > 0) {
|
if (priorityTime > 0) {
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.RESUME_TIMER, playerId, null, this);
|
tableEventSource.fireTableEvent(EventType.RESUME_TIMER, playerId, null, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3885,6 +3901,7 @@ public abstract class GameImpl implements Game {
|
||||||
@Override
|
@Override
|
||||||
public void pauseTimer(UUID playerId) {
|
public void pauseTimer(UUID playerId) {
|
||||||
if (priorityTime > 0) {
|
if (priorityTime > 0) {
|
||||||
|
makeSureCalledOutsideLayersEffects();
|
||||||
tableEventSource.fireTableEvent(EventType.PAUSE_TIMER, playerId, null, this);
|
tableEventSource.fireTableEvent(EventType.PAUSE_TIMER, playerId, null, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
|
||||||
|
|
||||||
public TableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
|
public TableEvent(EventType eventType, String message, boolean withTime, boolean withTurnInfo, Game game) {
|
||||||
super(game);
|
super(game);
|
||||||
this.game = game;
|
this.game = game; // TODO: potentially bugged and need game copy? See related makeSureCalledOutsideLayersEffects
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.eventType = eventType;
|
this.eventType = eventType;
|
||||||
this.withTime = withTime;
|
this.withTime = withTime;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue