mirror of
https://github.com/correl/mage.git
synced 2025-01-13 19:11:33 +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
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
|
if (user != null) {
|
||||||
GameManager.getInstance().stopWatching(gameId, userId);
|
GameManager.getInstance().stopWatching(gameId, userId);
|
||||||
|
user.removeGameWatchInfo(gameId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,7 +402,7 @@ public class TableController {
|
||||||
if (table.isTournament()) {
|
if (table.isTournament()) {
|
||||||
tournament.removePlayer(playerId);
|
tournament.removePlayer(playerId);
|
||||||
} else {
|
} else {
|
||||||
match.leave(playerId);
|
match.quitMatch(playerId);
|
||||||
}
|
}
|
||||||
User user = UserManager.getInstance().getUser(userId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
@ -434,7 +434,7 @@ public class TableController {
|
||||||
matchPlayer.submitDeck(matchPlayer.getDeck());
|
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());
|
user.removeConstructing(match.getPlayer(entry.getValue()).getPlayer().getId());
|
||||||
GameManager.getInstance().joinGame(match.getGame().getId(), user.getId());
|
GameManager.getInstance().joinGame(match.getGame().getId(), user.getId());
|
||||||
logger.debug("Joined currently not connected user " + user.getName() + " matchId: " + match.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) {
|
if (creator == null) {
|
||||||
creator = user.getName();
|
creator = user.getName();
|
||||||
|
@ -663,17 +662,18 @@ 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) {
|
Game game = match.getGame();
|
||||||
|
if (game == null) {
|
||||||
return true;
|
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() && !game.isSimulation()) {
|
||||||
if (GameManager.getInstance().saveGame(match.getGame().getId())) {
|
if (GameManager.getInstance().saveGame(game.getId())) {
|
||||||
match.setReplayAvailable(true);
|
match.setReplayAvailable(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GameManager.getInstance().removeGame(match.getGame().getId());
|
GameManager.getInstance().removeGame(game.getId());
|
||||||
try {
|
try {
|
||||||
if (!match.hasEnded()) {
|
if (!match.hasEnded()) {
|
||||||
table.sideboard();
|
table.sideboard();
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class TableManager {
|
||||||
*
|
*
|
||||||
* In minutes.
|
* In minutes.
|
||||||
*/
|
*/
|
||||||
private static final int EXPIRE_CHECK_PERIOD = 1;
|
private static final int EXPIRE_CHECK_PERIOD = 10;
|
||||||
|
|
||||||
public static TableManager getInstance() {
|
public static TableManager getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
|
|
|
@ -352,6 +352,10 @@ public class User {
|
||||||
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
||||||
TableManager.getInstance().leaveTable(userId, 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 ");
|
logger.debug("REMOVE " + getName() + " Chats ");
|
||||||
ChatManager.getInstance().removeUser(userId, reason);
|
ChatManager.getInstance().removeUser(userId, reason);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,18 +141,19 @@ public class UserManager {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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);
|
user.remove(reason);
|
||||||
users.remove(userId);
|
logger.debug("USER REMOVE END - " + user.getName());
|
||||||
logger.debug("User " + user.getName() + " removed");
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
} finally {
|
||||||
|
users.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} 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);
|
watchers.remove(userId);
|
||||||
User user = UserManager.getInstance().getUser(userId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
user.removeGameWatchInfo(game.getId());
|
|
||||||
ChatManager.getInstance().broadcast(chatId, user.getName(), " has stopped watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
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);
|
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));
|
game.quit(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,9 +405,6 @@ public class GameController implements GameCallback {
|
||||||
game.restorePriority(getPlayerId(userId));
|
game.restorePriority(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leave(UUID userId) {
|
|
||||||
game.quit(getPlayerId(userId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||||
Deck deck;
|
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) {
|
public void timeout(UUID userId) {
|
||||||
if (userPlayerMap.containsKey(userId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
String sb = game.getPlayer(userPlayerMap.get(userId)).getName() +
|
String sb = game.getPlayer(userPlayerMap.get(userId)).getName() +
|
||||||
|
|
|
@ -123,7 +123,7 @@ public class GameManager {
|
||||||
public void quitMatch(UUID gameId, UUID userId) {
|
public void quitMatch(UUID gameId, UUID userId) {
|
||||||
GameController gameController = gameControllers.get(gameId);
|
GameController gameController = gameControllers.get(gameId);
|
||||||
if (gameController != null) {
|
if (gameController != null) {
|
||||||
gameController.quit(userId);
|
gameController.quitMatch(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +175,12 @@ public class GameManager {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void kill(UUID gameId, UUID userId) {
|
// public void kill(UUID gameId, UUID userId) {
|
||||||
GameController gameController = gameControllers.get(gameId);
|
// GameController gameController = gameControllers.get(gameId);
|
||||||
if (gameController != null) {
|
// if (gameController != null) {
|
||||||
gameController.kill(userId);
|
// gameController.kill(userId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
|
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||||
GameController gameController = gameControllers.get(gameId);
|
GameController gameController = gameControllers.get(gameId);
|
||||||
|
|
|
@ -31,7 +31,6 @@ package mage.server.game;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.constants.ManaType;
|
import mage.constants.ManaType;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.match.Match;
|
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.players.net.UserData;
|
import mage.players.net.UserData;
|
||||||
|
|
|
@ -56,7 +56,7 @@ public interface Match {
|
||||||
MatchPlayer getPlayer(UUID playerId);
|
MatchPlayer getPlayer(UUID playerId);
|
||||||
|
|
||||||
void addPlayer(Player player, Deck deck);
|
void addPlayer(Player player, Deck deck);
|
||||||
boolean leave(UUID playerId);
|
boolean quitMatch(UUID playerId);
|
||||||
|
|
||||||
void submitDeck(UUID playerId, Deck deck);
|
void submitDeck(UUID playerId, Deck deck);
|
||||||
void updateDeck(UUID playerId, Deck deck);
|
void updateDeck(UUID playerId, Deck deck);
|
||||||
|
|
|
@ -93,7 +93,7 @@ public abstract class MatchImpl implements Match {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean leave(UUID playerId) {
|
public boolean quitMatch(UUID playerId) {
|
||||||
MatchPlayer mPlayer = getPlayer(playerId);
|
MatchPlayer mPlayer = getPlayer(playerId);
|
||||||
if (mPlayer != null) {
|
if (mPlayer != null) {
|
||||||
if (!hasStarted()) {
|
if (!hasStarted()) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class TournamentPairing {
|
||||||
* Called by eliminate tournaments after each match
|
* Called by eliminate tournaments after each match
|
||||||
*/
|
*/
|
||||||
public void eliminatePlayers() {
|
public void eliminatePlayers() {
|
||||||
if (match.hasEnded()) {
|
if (match != null && match.hasEnded()) {
|
||||||
MatchPlayer mPlayer1 = match.getPlayer(player1.getPlayer().getId());
|
MatchPlayer mPlayer1 = match.getPlayer(player1.getPlayer().getId());
|
||||||
MatchPlayer mPlayer2 = match.getPlayer(player2.getPlayer().getId());
|
MatchPlayer mPlayer2 = match.getPlayer(player2.getPlayer().getId());
|
||||||
if (mPlayer1.hasQuit() || !mPlayer1.isMatchWinner()) {
|
if (mPlayer1.hasQuit() || !mPlayer1.isMatchWinner()) {
|
||||||
|
@ -88,7 +88,7 @@ public class TournamentPairing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void finishPlayersThatPlayedLastRound() {
|
public void finishPlayersThatPlayedLastRound() {
|
||||||
if (match.hasEnded()) {
|
if (match != null && match.hasEnded()) {
|
||||||
if (!player1.isEliminated()) {
|
if (!player1.isEliminated()) {
|
||||||
player1.setEliminated();
|
player1.setEliminated();
|
||||||
player1.setState(TournamentPlayerState.FINISHED);
|
player1.setState(TournamentPlayerState.FINISHED);
|
||||||
|
|
Loading…
Reference in a new issue