server: improved logs for can't create table errors (instead No message)

This commit is contained in:
Oleg Agafonov 2025-04-17 20:09:54 +04:00
parent b61bd22c85
commit 33fb660dc8

View file

@ -29,7 +29,6 @@ import mage.server.managers.ManagerFactory;
import mage.server.services.impl.FeedbackServiceImpl; import mage.server.services.impl.FeedbackServiceImpl;
import mage.server.tournament.TournamentFactory; import mage.server.tournament.TournamentFactory;
import mage.server.util.ServerMessagesUtil; import mage.server.util.ServerMessagesUtil;
import mage.utils.SystemUtil;
import mage.utils.*; import mage.utils.*;
import mage.view.*; import mage.view.*;
import mage.view.ChatMessage.MessageColor; import mage.view.ChatMessage.MessageColor;
@ -1300,29 +1299,30 @@ public class MageServerImpl implements MageServer {
@Override @Override
public TableView execute() throws MageException { public TableView execute() throws MageException {
Optional<Session> session = managerFactory.sessionManager().getSession(sessionId); Session session = managerFactory.sessionManager().getSession(sessionId).orElse(null);
if (!session.isPresent()) { if (session == null) {
return null; return null;
} }
UUID userId = session.get().getUserId(); UUID userId = session.getUserId();
Optional<User> _user = managerFactory.userManager().getUser(userId); User user = managerFactory.userManager().getUser(userId).orElse(null);
if (!_user.isPresent()) { if (user == null) {
logger.error("User for session not found. session = " + sessionId);
return null; return null;
} }
User user = _user.get();
// check if user can create another table // check if user can create another table
int notStartedTables = user.getNumberOfNotStartedTables(); int notStartedTables = user.getNumberOfNotStartedTables();
if (notStartedTables > 1) { if (notStartedTables > 1) {
user.showUserMessage("Create table", "You have already " + notStartedTables + " not started tables. You can't create another."); user.showUserMessage("Create table", "You have already " + notStartedTables + " not started tables. You can't create another.");
throw new MageException("No message"); throw new MageException("User " + user.getName() + " can't create table: too much started");
} }
// check if the user itself satisfies the quitRatio requirement. // check if the user itself satisfies the quitRatio requirement.
int quitRatio = options.getQuitRatio(); int quitRatio = options.getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) { if (quitRatio < user.getMatchQuitRatio()) {
user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + '%'); user.showUserMessage("Create table", "Your quit ratio " + user.getMatchQuitRatio() + "% is higher than the table requirement " + quitRatio + '%');
throw new MageException("No message"); throw new MageException("User " + user.getName() + " can't create table: incompatible quit ratio");
} }
// check if the user satisfies the minimumRating requirement. // check if the user satisfies the minimumRating requirement.
int minimumRating = options.getMinimumRating(); int minimumRating = options.getMinimumRating();
int userRating; int userRating;
@ -1334,20 +1334,15 @@ public class MageServerImpl implements MageServer {
if (userRating < minimumRating) { if (userRating < minimumRating) {
String message = new StringBuilder("Your rating ").append(userRating).append(" is lower than the table requirement ").append(minimumRating).toString(); String message = new StringBuilder("Your rating ").append(userRating).append(" is lower than the table requirement ").append(minimumRating).toString();
user.showUserMessage("Create table", message); user.showUserMessage("Create table", message);
throw new MageException("No message"); throw new MageException("User " + user.getName() + " can't create table: incompatible rating");
} }
Optional<GamesRoom> room = managerFactory.gamesRoomManager().getRoom(roomId);
if (room.isPresent()) { GamesRoom room = managerFactory.gamesRoomManager().getRoom(roomId).orElse(null);
TableView table = room.get().createTable(userId, options); if (room == null) {
if (logger.isDebugEnabled()) {
logger.debug("TABLE created - tableId: " + table.getTableId() + ' ' + table.getTableName());
logger.debug("- " + user.getName() + " userId: " + user.getId());
logger.debug("- chatId: " + managerFactory.tableManager().getChatId(table.getTableId()));
}
return table;
} else {
return null; return null;
} }
return room.createTable(userId, options);
} }
} }