mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Changes to user / tournament / match handling.
This commit is contained in:
parent
ffa959d536
commit
eeb22c05ee
11 changed files with 55 additions and 50 deletions
|
@ -839,7 +839,12 @@ public class MageServerImpl implements MageServer {
|
|||
@Override
|
||||
public void execute() {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ public class TableController {
|
|||
if (table.isTournament()) {
|
||||
tournament.removePlayer(playerId);
|
||||
} else {
|
||||
match.leave(playerId);
|
||||
match.quitMatch(playerId);
|
||||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
|
@ -434,7 +434,7 @@ public class TableController {
|
|||
matchPlayer.submitDeck(matchPlayer.getDeck());
|
||||
}
|
||||
}
|
||||
match.leave(playerId);
|
||||
match.quitMatch(playerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -526,9 +526,8 @@ public class TableController {
|
|||
user.removeConstructing(match.getPlayer(entry.getValue()).getPlayer().getId());
|
||||
GameManager.getInstance().joinGame(match.getGame().getId(), user.getId());
|
||||
logger.debug("Joined currently not connected user " + user.getName() + " matchId: " + match.getId());
|
||||
} else {
|
||||
user.gameStarted(match.getGame().getId(), entry.getValue());
|
||||
}
|
||||
user.gameStarted(match.getGame().getId(), entry.getValue());
|
||||
|
||||
if (creator == null) {
|
||||
creator = user.getName();
|
||||
|
@ -663,17 +662,18 @@ public class TableController {
|
|||
*/
|
||||
public boolean endGameAndStartNextGame() {
|
||||
// get player that chooses who goes first
|
||||
if (match.getGame() == null) {
|
||||
Game game = match.getGame();
|
||||
if (game == null) {
|
||||
return true;
|
||||
}
|
||||
UUID choosingPlayerId = match.getChooser();
|
||||
match.endGame();
|
||||
if (ConfigSettings.getInstance().isSaveGameActivated() && !match.getGame().isSimulation()) {
|
||||
if (GameManager.getInstance().saveGame(match.getGame().getId())) {
|
||||
if (ConfigSettings.getInstance().isSaveGameActivated() && !game.isSimulation()) {
|
||||
if (GameManager.getInstance().saveGame(game.getId())) {
|
||||
match.setReplayAvailable(true);
|
||||
}
|
||||
}
|
||||
GameManager.getInstance().removeGame(match.getGame().getId());
|
||||
GameManager.getInstance().removeGame(game.getId());
|
||||
try {
|
||||
if (!match.hasEnded()) {
|
||||
table.sideboard();
|
||||
|
|
|
@ -81,7 +81,7 @@ public class TableManager {
|
|||
*
|
||||
* In minutes.
|
||||
*/
|
||||
private static final int EXPIRE_CHECK_PERIOD = 1;
|
||||
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||
|
||||
public static TableManager getInstance() {
|
||||
return INSTANCE;
|
||||
|
|
|
@ -352,6 +352,10 @@ public class User {
|
|||
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
||||
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
||||
}
|
||||
logger.debug("REMOVE " + getName() + " watched Games " + watchedGames.size());
|
||||
for (UUID gameId: watchedGames) {
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
}
|
||||
logger.debug("REMOVE " + getName() + " Chats ");
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
}
|
||||
|
|
|
@ -141,18 +141,19 @@ public class UserManager {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
logger.debug("User " + user.getName() + " will be removed (" + reason.toString() + ") userId: " + userId);
|
||||
logger.debug("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId);
|
||||
user.remove(reason);
|
||||
users.remove(userId);
|
||||
logger.debug("User " + user.getName() + " removed");
|
||||
logger.debug("USER REMOVE END - " + user.getName());
|
||||
} catch (Exception ex) {
|
||||
handleException(ex);
|
||||
} finally {
|
||||
users.remove(userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
} else {
|
||||
logger.warn(new StringBuilder("Trying to remove userId: ").append(userId).append(" but it does not exist."));
|
||||
logger.warn("Trying to remove userId: " + userId + " - but it does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -355,7 +355,6 @@ public class GameController implements GameCallback {
|
|||
watchers.remove(userId);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.removeGameWatchInfo(game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
}
|
||||
}
|
||||
|
@ -368,7 +367,25 @@ public class GameController implements GameCallback {
|
|||
game.setManaPoolMode(getPlayerId(userId), autoPayment);
|
||||
}
|
||||
|
||||
public void quit(UUID userId) {
|
||||
// public void removeUser(UUID userId) {
|
||||
// UUID playerId = userPlayerMap.get(userId);
|
||||
// if (playerId != null) {
|
||||
// GameSession gameSession = gameSessions.get(playerId);
|
||||
// if (gameSession != null) {
|
||||
// gameSession.setKilled();
|
||||
// gameSessions.remove(playerId);
|
||||
// quitMatch(userId);
|
||||
// userPlayerMap.remove(userId);
|
||||
// }
|
||||
// }
|
||||
// GameWatcher gameWatcher = watchers.get(userId);
|
||||
// if (gameWatcher != null) {
|
||||
// gameWatcher.setKilled();
|
||||
// watchers.remove(userId);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void quitMatch(UUID userId) {
|
||||
game.quit(getPlayerId(userId));
|
||||
}
|
||||
|
||||
|
@ -388,9 +405,6 @@ public class GameController implements GameCallback {
|
|||
game.restorePriority(getPlayerId(userId));
|
||||
}
|
||||
|
||||
private void leave(UUID userId) {
|
||||
game.quit(getPlayerId(userId));
|
||||
}
|
||||
|
||||
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||
Deck deck;
|
||||
|
@ -421,24 +435,6 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
}
|
||||
|
||||
public void kill(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId != null) {
|
||||
GameSession gameSession = gameSessions.get(playerId);
|
||||
if (gameSession != null) {
|
||||
gameSession.setKilled();
|
||||
gameSessions.remove(playerId);
|
||||
leave(userId);
|
||||
userPlayerMap.remove(userId);
|
||||
}
|
||||
}
|
||||
GameWatcher gameWatcher = watchers.get(userId);
|
||||
if (gameWatcher != null) {
|
||||
gameWatcher.setKilled();
|
||||
watchers.remove(userId);
|
||||
}
|
||||
}
|
||||
|
||||
public void timeout(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
String sb = game.getPlayer(userPlayerMap.get(userId)).getName() +
|
||||
|
|
|
@ -123,7 +123,7 @@ public class GameManager {
|
|||
public void quitMatch(UUID gameId, UUID userId) {
|
||||
GameController gameController = gameControllers.get(gameId);
|
||||
if (gameController != null) {
|
||||
gameController.quit(userId);
|
||||
gameController.quitMatch(userId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,12 +175,12 @@ public class GameManager {
|
|||
// }
|
||||
// }
|
||||
|
||||
public void kill(UUID gameId, UUID userId) {
|
||||
GameController gameController = gameControllers.get(gameId);
|
||||
if (gameController != null) {
|
||||
gameController.kill(userId);
|
||||
}
|
||||
}
|
||||
// public void kill(UUID gameId, UUID userId) {
|
||||
// GameController gameController = gameControllers.get(gameId);
|
||||
// if (gameController != null) {
|
||||
// gameController.kill(userId);
|
||||
// }
|
||||
// }
|
||||
|
||||
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||
GameController gameController = gameControllers.get(gameId);
|
||||
|
|
|
@ -31,7 +31,6 @@ package mage.server.game;
|
|||
import mage.cards.Cards;
|
||||
import mage.constants.ManaType;
|
||||
import mage.game.Game;
|
||||
import mage.game.match.Match;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.Player;
|
||||
import mage.players.net.UserData;
|
||||
|
|
|
@ -56,7 +56,7 @@ public interface Match {
|
|||
MatchPlayer getPlayer(UUID playerId);
|
||||
|
||||
void addPlayer(Player player, Deck deck);
|
||||
boolean leave(UUID playerId);
|
||||
boolean quitMatch(UUID playerId);
|
||||
|
||||
void submitDeck(UUID playerId, Deck deck);
|
||||
void updateDeck(UUID playerId, Deck deck);
|
||||
|
|
|
@ -93,7 +93,7 @@ public abstract class MatchImpl implements Match {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean leave(UUID playerId) {
|
||||
public boolean quitMatch(UUID playerId) {
|
||||
MatchPlayer mPlayer = getPlayer(playerId);
|
||||
if (mPlayer != null) {
|
||||
if (!hasStarted()) {
|
||||
|
|
|
@ -76,7 +76,7 @@ public class TournamentPairing {
|
|||
* Called by eliminate tournaments after each match
|
||||
*/
|
||||
public void eliminatePlayers() {
|
||||
if (match.hasEnded()) {
|
||||
if (match != null && match.hasEnded()) {
|
||||
MatchPlayer mPlayer1 = match.getPlayer(player1.getPlayer().getId());
|
||||
MatchPlayer mPlayer2 = match.getPlayer(player2.getPlayer().getId());
|
||||
if (mPlayer1.hasQuit() || !mPlayer1.isMatchWinner()) {
|
||||
|
@ -88,7 +88,7 @@ public class TournamentPairing {
|
|||
}
|
||||
}
|
||||
public void finishPlayersThatPlayedLastRound() {
|
||||
if (match.hasEnded()) {
|
||||
if (match != null && match.hasEnded()) {
|
||||
if (!player1.isEliminated()) {
|
||||
player1.setEliminated();
|
||||
player1.setState(TournamentPlayerState.FINISHED);
|
||||
|
|
Loading…
Reference in a new issue