mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 19:41:59 -08:00
Some changes to logging and NPE handling.
This commit is contained in:
parent
3e789ccb1f
commit
ddb9c786b4
7 changed files with 44 additions and 17 deletions
|
|
@ -72,10 +72,14 @@ public class ChatSession {
|
||||||
public void kill(UUID userId, DisconnectReason reason) {
|
public void kill(UUID userId, DisconnectReason reason) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (userId != null && clients.containsKey(userId)) {
|
if (reason == null) {
|
||||||
|
logger.fatal("User kill without disconnect reason userId: " + userId) ;
|
||||||
|
reason = DisconnectReason.Undefined;
|
||||||
|
}
|
||||||
|
if (reason != null && userId != null && clients.containsKey(userId)) {
|
||||||
String userName = clients.get(userId);
|
String userName = clients.get(userId);
|
||||||
clients.remove(userId);
|
clients.remove(userId);
|
||||||
logger.debug(userName + (reason == null?"null":"(" + reason.toString() +")") + " removed from chatId " + chatId) ;
|
logger.debug(userName + "(" + reason.toString() +")" + " removed from chatId " + chatId) ;
|
||||||
String message;
|
String message;
|
||||||
switch (reason) {
|
switch (reason) {
|
||||||
case Disconnected:
|
case Disconnected:
|
||||||
|
|
@ -85,7 +89,7 @@ public class ChatSession {
|
||||||
message = " has lost connection";
|
message = " has lost connection";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message = reason == null ? " left (unknown reason) ": " left (" + reason.toString() +")";
|
message = " left (" + reason.toString() +")";
|
||||||
}
|
}
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
broadcast(null, new StringBuilder(userName).append(message).toString(), MessageColor.BLUE, true, MessageType.STATUS);
|
broadcast(null, new StringBuilder(userName).append(message).toString(), MessageColor.BLUE, true, MessageType.STATUS);
|
||||||
|
|
|
||||||
|
|
@ -510,8 +510,11 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logger.error("Unable to find player " + entry.getKey());
|
logger.error("Unable to find user: " + entry.getKey() + " playerId: " + entry.getValue());
|
||||||
match.getPlayer(entry.getValue()).setQuit(true);
|
MatchPlayer matchPlayer = match.getPlayer(entry.getValue());
|
||||||
|
if (matchPlayer != null && !matchPlayer.hasQuit()) {
|
||||||
|
matchPlayer.setQuit(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -526,11 +529,16 @@ public class TableController {
|
||||||
}
|
}
|
||||||
ServerMessagesUtil.getInstance().incGamesStarted();
|
ServerMessagesUtil.getInstance().incGamesStarted();
|
||||||
|
|
||||||
|
|
||||||
// log about game started
|
// log about game started
|
||||||
logger.info("GAME started [" + match.getName() +"] "+ creator + " - " + opponent.toString());
|
logger.info("GAME started [" + match.getName() +"] "+ creator + " - " + opponent.toString());
|
||||||
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
|
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
|
||||||
|
if (match.getGame() != null) {
|
||||||
logger.debug("- gameId: " + match.getGame().getId());
|
logger.debug("- gameId: " + match.getGame().getId());
|
||||||
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
||||||
|
} else {
|
||||||
|
logger.debug("- no valid game object");
|
||||||
|
}
|
||||||
LogServiceImpl.instance.log(LogKeys.KEY_GAME_STARTED, String.valueOf(userPlayerMap.size()), creator, opponent.toString());
|
LogServiceImpl.instance.log(LogKeys.KEY_GAME_STARTED, String.valueOf(userPlayerMap.size()), creator, opponent.toString());
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
|
@ -622,6 +630,9 @@ public class TableController {
|
||||||
*/
|
*/
|
||||||
public boolean endGameAndStartNextGame() {
|
public boolean endGameAndStartNextGame() {
|
||||||
// get player that chooses who goes first
|
// get player that chooses who goes first
|
||||||
|
if (match.getGame() == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
UUID choosingPlayerId = match.getChooser();
|
UUID choosingPlayerId = match.getChooser();
|
||||||
match.endGame();
|
match.endGame();
|
||||||
if (ConfigSettings.getInstance().isSaveGameActivated() && !match.getGame().isSimulation()) {
|
if (ConfigSettings.getInstance().isSaveGameActivated() && !match.getGame().isSimulation()) {
|
||||||
|
|
|
||||||
|
|
@ -81,8 +81,11 @@ public class UserManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(UUID userId) {
|
public User getUser(UUID userId) {
|
||||||
|
if (userId != null) {
|
||||||
return users.get(userId);
|
return users.get(userId);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public User findUser(String userName) {
|
public User findUser(String userName) {
|
||||||
for (User user: users.values()) {
|
for (User user: users.values()) {
|
||||||
|
|
|
||||||
|
|
@ -117,26 +117,32 @@ class XenagosManaEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(source.getControllerId());
|
Player player = game.getPlayer(source.getControllerId());
|
||||||
if(player != null){
|
if (player != null){
|
||||||
int x = game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), source.getControllerId(), game);
|
int x = game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getSourceId(), source.getControllerId(), game);
|
||||||
Choice manaChoice = new ChoiceImpl();
|
Choice manaChoice = new ChoiceImpl();
|
||||||
Set<String> choices = new LinkedHashSet<String>();
|
Set<String> choices = new LinkedHashSet<>();
|
||||||
choices.add("Red");
|
choices.add("Red");
|
||||||
choices.add("Green");
|
choices.add("Green");
|
||||||
manaChoice.setChoices(choices);
|
manaChoice.setChoices(choices);
|
||||||
manaChoice.setMessage("Select color of mana to add");
|
manaChoice.setMessage("Select color of mana to add");
|
||||||
|
|
||||||
for(int i = 0; i < x; i++){
|
for (int i = 0; i < x; i++){
|
||||||
Mana mana = new Mana();
|
Mana mana = new Mana();
|
||||||
while (!player.choose(Outcome.Benefit, manaChoice, game)) {
|
while (!player.choose(Outcome.Benefit, manaChoice, game)) {
|
||||||
if (!player.isInGame()) {
|
if (!player.isInGame()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (manaChoice.getChoice().equals("Green")) {
|
if (manaChoice.getChoice() == null) { // can happen if player leaves game
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (manaChoice.getChoice()) {
|
||||||
|
case "Green":
|
||||||
mana.addGreen();
|
mana.addGreen();
|
||||||
} else if (manaChoice.getChoice().equals("Red")) {
|
break;
|
||||||
|
case "Red":
|
||||||
mana.addRed();
|
mana.addRed();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
player.getManaPool().addMana(mana, game, source);
|
player.getManaPool().addMana(mana, game, source);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -158,7 +158,7 @@ public class PersistTest extends CardTestPlayerBase {
|
||||||
assertPowerToughness(playerA, "Kitchen Finks", 3,2, Filter.ComparisonScope.Any);
|
assertPowerToughness(playerA, "Kitchen Finks", 3,2, Filter.ComparisonScope.Any);
|
||||||
|
|
||||||
assertLife(playerA, 20); // No life from Kitchen Finks ETB becaus of Torpor Orb
|
assertLife(playerA, 20); // No life from Kitchen Finks ETB becaus of Torpor Orb
|
||||||
assertLife(playerB, 22); // AI assigns damage only 2 damage to one blocker so only 2 life link (It's a kind of bug (or bad play) of AI)
|
assertLife(playerB, 22); // AI assigns only 2 damage to one blocker so only 2 life link (It's a kind of bug (or bad play) of AI)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -865,6 +865,9 @@ public class ContinuousEffects implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEffect(ContinuousEffect effect, Ability source) {
|
public void addEffect(ContinuousEffect effect, Ability source) {
|
||||||
|
if (source == null && effect != null) {
|
||||||
|
logger.warn("Adding effect without ability : " +effect.toString());
|
||||||
|
}
|
||||||
switch (effect.getEffectType()) {
|
switch (effect.getEffectType()) {
|
||||||
case REPLACEMENT:
|
case REPLACEMENT:
|
||||||
case REDIRECTION:
|
case REDIRECTION:
|
||||||
|
|
|
||||||
|
|
@ -934,7 +934,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
public void quit(UUID playerId) {
|
public void quit(UUID playerId) {
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
Player player = state.getPlayer(playerId);
|
Player player = state.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null && player.isInGame()) {
|
||||||
player.quit(this);
|
player.quit(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue