mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
server: fixed non-started tourney freeze in some use cases (related to #11285);
This commit is contained in:
parent
33346fa118
commit
ce8ae6ff4c
1 changed files with 18 additions and 16 deletions
|
|
@ -21,8 +21,8 @@ import mage.game.tournament.TournamentPlayer;
|
||||||
import mage.players.PlayerType;
|
import mage.players.PlayerType;
|
||||||
import mage.server.User;
|
import mage.server.User;
|
||||||
import mage.server.draft.DraftController;
|
import mage.server.draft.DraftController;
|
||||||
import mage.server.managers.TableManager;
|
|
||||||
import mage.server.managers.ManagerFactory;
|
import mage.server.managers.ManagerFactory;
|
||||||
|
import mage.server.managers.TableManager;
|
||||||
import mage.util.ThreadUtils;
|
import mage.util.ThreadUtils;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import mage.view.ChatMessage.MessageType;
|
import mage.view.ChatMessage.MessageType;
|
||||||
|
|
@ -129,7 +129,7 @@ public class TournamentController {
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void join(UUID userId) {
|
public void join(UUID userId) {
|
||||||
UUID playerId = userPlayerMap.get(userId);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
if (playerId == null) {
|
if (playerId == null) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
|
|
@ -143,21 +143,23 @@ public class TournamentController {
|
||||||
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
|
logger.debug("player reopened tournament panel userId: " + userId + " tournamentId: " + tournament.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// first join of player
|
// first join of player
|
||||||
|
User user = managerFactory.userManager().getUser(userId).orElse(null);
|
||||||
|
if (user == null) {
|
||||||
|
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TournamentSession tournamentSession = new TournamentSession(managerFactory, tournament, userId, tableId, playerId);
|
TournamentSession tournamentSession = new TournamentSession(managerFactory, tournament, userId, tableId, playerId);
|
||||||
tournamentSessions.put(playerId, tournamentSession);
|
tournamentSessions.put(playerId, tournamentSession);
|
||||||
Optional<User> _user = managerFactory.userManager().getUser(userId);
|
|
||||||
if (_user.isPresent()) {
|
|
||||||
User user = _user.get();
|
|
||||||
user.addTournament(playerId, tournament.getId());
|
user.addTournament(playerId, tournament.getId());
|
||||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||||
player.setJoined();
|
player.setJoined();
|
||||||
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
|
logger.debug("player " + player.getPlayer().getName() + " - client has joined tournament " + tournament.getId());
|
||||||
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
|
managerFactory.chatManager().broadcast(chatId, "", player.getPlayer().getLogName() + " has joined the tournament", MessageColor.BLACK, true, null, MessageType.STATUS, null);
|
||||||
|
|
||||||
checkStart();
|
checkStart();
|
||||||
} else {
|
|
||||||
logger.error("User not found userId: " + userId + " tournamentId: " + tournament.getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rejoin(UUID playerId) {
|
public void rejoin(UUID playerId) {
|
||||||
|
|
@ -173,7 +175,7 @@ public class TournamentController {
|
||||||
tournamentSession.update();
|
tournamentSession.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkStart() {
|
private synchronized void checkStart() {
|
||||||
if (!started && allJoined()) {
|
if (!started && allJoined()) {
|
||||||
managerFactory.threadExecutor().getTourneyExecutor().execute(this::startTournament);
|
managerFactory.threadExecutor().getTourneyExecutor().execute(this::startTournament);
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +193,7 @@ public class TournamentController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void startTournament() {
|
private void startTournament() {
|
||||||
Thread.currentThread().setName(ThreadUtils.THREAD_PREFIX_TOURNEY + " " + tableId);
|
Thread.currentThread().setName(ThreadUtils.THREAD_PREFIX_TOURNEY + " " + tableId);
|
||||||
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
for (final TournamentSession tournamentSession : tournamentSessions.values()) {
|
||||||
if (!tournamentSession.init()) {
|
if (!tournamentSession.init()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue