mirror of
https://github.com/correl/mage.git
synced 2025-04-12 17:00:08 -09:00
Changes to logging an chat session handling.
This commit is contained in:
parent
fc382740ce
commit
020daf94f5
12 changed files with 72 additions and 33 deletions
Mage.Server/src/main/java/mage/server
ChatManager.javaChatSession.javaRoomImpl.javaTableController.javaTableManager.javaUser.javaUserManager.java
game
tournament
Mage/src/mage/players
|
@ -55,8 +55,8 @@ public class ChatManager {
|
|||
|
||||
private final ConcurrentHashMap<UUID, ChatSession> chatSessions = new ConcurrentHashMap<>();
|
||||
|
||||
public UUID createChatSession() {
|
||||
ChatSession chatSession = new ChatSession();
|
||||
public UUID createChatSession(String info) {
|
||||
ChatSession chatSession = new ChatSession(info);
|
||||
chatSessions.put(chatSession.getChatId(), chatSession);
|
||||
return chatSession.getChatId();
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ public class ChatManager {
|
|||
chatSessions.get(chatId).broadcastInfoToUser(user,message);
|
||||
return true;
|
||||
}
|
||||
if (command.startsWith("\\W ") || command.startsWith("\\WHISPER ")) {
|
||||
String rest = message.substring(command.startsWith("\\W ") ? 3 : 9);
|
||||
if (command.startsWith("\\W ") || command.startsWith("\\WHISPER ") || command.startsWith("/W ") || command.startsWith("/WHISPER ")) {
|
||||
String rest = message.substring(command.startsWith("\\W ") || command.startsWith("/W ")? 3 : 9);
|
||||
int first = rest.indexOf(" ");
|
||||
if (first > 1) {
|
||||
String userToName = rest.substring(0,first);
|
||||
|
|
|
@ -49,10 +49,14 @@ public class ChatSession {
|
|||
private static final Logger logger = Logger.getLogger(ChatSession.class);
|
||||
private final ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<>();
|
||||
private final UUID chatId;
|
||||
private final Date createTime;
|
||||
private final String info;
|
||||
private final DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||
|
||||
public ChatSession() {
|
||||
public ChatSession(String info) {
|
||||
chatId = UUID.randomUUID();
|
||||
this.createTime = new Date();
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public void join(UUID userId) {
|
||||
|
@ -72,7 +76,7 @@ public class ChatSession {
|
|||
String userName = clients.get(userId);
|
||||
clients.remove(userId);
|
||||
logger.debug(userName + (reason == null?"null":"(" + reason.toString() +")") + " removed from chatId " + chatId) ;
|
||||
String message = null;
|
||||
String message;
|
||||
switch (reason) {
|
||||
case Disconnected:
|
||||
message = " has left XMage";
|
||||
|
@ -158,4 +162,13 @@ public class ChatSession {
|
|||
public ConcurrentHashMap<UUID, String> getClients() {
|
||||
return clients;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public String getInfo() {
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public abstract class RoomImpl implements Room {
|
|||
|
||||
public RoomImpl() {
|
||||
roomId = UUID.randomUUID();
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
chatId = ChatManager.getInstance().createChatSession("Room " + roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -96,7 +96,6 @@ public class TableController {
|
|||
|
||||
public TableController(UUID roomId, UUID userId, MatchOptions options) {
|
||||
this.userId = userId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
if (userId != null) {
|
||||
|
@ -108,12 +107,12 @@ public class TableController {
|
|||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||
chatId = ChatManager.getInstance().createChatSession("Match Table " + table.getId());
|
||||
init();
|
||||
}
|
||||
|
||||
public TableController(UUID roomId, UUID userId, TournamentOptions options) {
|
||||
this.userId = userId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
if (userId != null) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
|
@ -128,6 +127,7 @@ public class TableController {
|
|||
controllerName = "System";
|
||||
}
|
||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||
chatId = ChatManager.getInstance().createChatSession("Tourn. table " + table.getId());
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
@ -369,15 +369,15 @@ public class TableController {
|
|||
}
|
||||
|
||||
public synchronized void leaveTable(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (table == null) {
|
||||
logger.error("TableController.leaveTable table == null - userId: " + userId);
|
||||
logger.error("No table object - userId: " + userId);
|
||||
return;
|
||||
}
|
||||
if (table.isTournament() && tournament == null) {
|
||||
logger.error("TableController.leaveTable tournament == null - userId: " + userId + " table: " + table.getId());
|
||||
logger.error("No tournament object - userId: " + userId + " table: " + table.getId());
|
||||
return;
|
||||
}
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
if (playerId != null) {
|
||||
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING) {
|
||||
table.leaveNotStartedTable(playerId);
|
||||
|
@ -391,14 +391,14 @@ public class TableController {
|
|||
ChatManager.getInstance().broadcast(chatId, user.getName(), "has left the table", ChatMessage.MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, ChatMessage.SoundToPlay.PlayerLeft);
|
||||
user.removeTable(playerId);
|
||||
} else {
|
||||
logger.debug("TableController.leaveTable user with this userId not found userId: " + userId);
|
||||
logger.debug("User not found - userId: " + userId + " tableId:" + table.getId());
|
||||
}
|
||||
userPlayerMap.remove(userId);
|
||||
} else if (!table.getState().equals(TableState.FINISHED)) {
|
||||
if (table.isTournament()) {
|
||||
logger.debug("TableController.leaveTable before userQuitTournamentSubTables");
|
||||
logger.debug("Quit tournament sub tables for userId: " + userId);
|
||||
TableManager.getInstance().userQuitTournamentSubTables(userId);
|
||||
logger.debug("TableController.leaveTable before quit tournament ");
|
||||
logger.debug("Quit tournament Id: " + table.getTournament().getId());
|
||||
TournamentManager.getInstance().quit(tournament.getId(), userId);
|
||||
} else {
|
||||
MatchPlayer matchPlayer = match.getPlayer(playerId);
|
||||
|
@ -413,7 +413,7 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
logger.error("TableController.leaveTable no playerId found for userId: " + userId);
|
||||
logger.error("No playerId found for userId: " + userId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -658,7 +658,6 @@ public class TableController {
|
|||
private void closeTable() {
|
||||
this.matchEnd();
|
||||
table.closeTable();
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
private void matchEnd() {
|
||||
|
@ -790,4 +789,8 @@ public class TableController {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void cleanUp() {
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -343,10 +343,17 @@ public class TableManager {
|
|||
|
||||
public void removeTable(UUID tableId) {
|
||||
if (tables.containsKey(tableId)) {
|
||||
|
||||
TableController tableController = controllers.get(tableId);
|
||||
if (tableController != null) {
|
||||
controllers.remove(tableId);
|
||||
tableController.cleanUp();
|
||||
}
|
||||
|
||||
Table table = tables.get(tableId);
|
||||
controllers.remove(tableId);
|
||||
tables.remove(tableId);
|
||||
// If table is not finished, the table has to be removed completly (if finished it will be removed in GamesRoomImpl.Update())
|
||||
|
||||
// If table is not finished, the table has to be removed completly (if finished it will be removed in GamesRoomImpl.Update())
|
||||
if (!table.getState().equals(TableState.FINISHED)) {
|
||||
GamesRoomManager.getInstance().removeTable(tableId);
|
||||
}
|
||||
|
@ -366,7 +373,7 @@ public class TableManager {
|
|||
ArrayList<ChatSession> chatSessions = ChatManager.getInstance().getChatSessions();
|
||||
logger.debug("------- ChatSessions: " + chatSessions.size() + " ----------------------------------");
|
||||
for (ChatSession chatSession: chatSessions) {
|
||||
logger.debug(chatSession.getChatId() + " " + chatSession.getClients().values().toString());
|
||||
logger.debug(chatSession.getChatId() + " " +formatter.format(chatSession.getCreateTime()) +" " + chatSession.getInfo()+ " "+ chatSession.getClients().values().toString());
|
||||
}
|
||||
logger.debug("------- Tables: " + tables.size() + " --------------------------------------------");
|
||||
for (Table table: tables.values()) {
|
||||
|
|
|
@ -327,23 +327,25 @@ public class User {
|
|||
}
|
||||
|
||||
public void kill(DisconnectReason reason) {
|
||||
logger.debug("game sessions: " + gameSessions.size() );
|
||||
logger.debug("Game sessions: " + gameSessions.size() );
|
||||
for (GameSession gameSession: gameSessions.values()) {
|
||||
logger.debug("-- kill game session of gameId: " + gameSession.getGameId() );
|
||||
gameSession.kill();
|
||||
}
|
||||
logger.debug("draft sessions " + draftSessions.size());
|
||||
logger.debug("Draft sessions " + draftSessions.size());
|
||||
for (DraftSession draftSession: draftSessions.values()) {
|
||||
draftSession.setKilled();
|
||||
}
|
||||
logger.debug("tournament sessions " + tournamentSessions.size());
|
||||
logger.debug("Tournament sessions " + tournamentSessions.size());
|
||||
for (TournamentSession tournamentSession: tournamentSessions.values()) {
|
||||
tournamentSession.setKilled();
|
||||
}
|
||||
logger.debug("tables " + tables.size());
|
||||
logger.debug("Tables " + tables.size());
|
||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
||||
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
||||
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
||||
}
|
||||
logger.debug("chat remove user");
|
||||
logger.debug("Chat remove user");
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
}
|
||||
|
||||
|
|
|
@ -125,7 +125,7 @@ public class UserManager {
|
|||
public void removeUser(UUID userId, DisconnectReason reason) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
logger.debug(user.getName() + " " + reason.toString() + "userId: " + userId);
|
||||
logger.debug(user.getName() + " removed (" + reason.toString() + ") userId: " + userId);
|
||||
user.kill(reason);
|
||||
users.remove(userId);
|
||||
} else {
|
||||
|
|
|
@ -91,7 +91,7 @@ public class GameController implements GameCallback {
|
|||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
gameSessionId = UUID.randomUUID();
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
chatId = ChatManager.getInstance().createChatSession("Game " + game.getId());
|
||||
this.game = game;
|
||||
this.game.setSaveGame(ConfigSettings.getInstance().isSaveGameActivated());
|
||||
this.tableId = tableId;
|
||||
|
@ -106,7 +106,7 @@ public class GameController implements GameCallback {
|
|||
}
|
||||
|
||||
public void cleanUp() {
|
||||
// nothing now
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
|
|
@ -49,6 +49,7 @@ import mage.server.RoomImpl;
|
|||
import mage.server.TableManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.UsersView;
|
||||
|
@ -106,7 +107,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
} else {
|
||||
// more since 50 matches finished since this match so remove it
|
||||
if (table.isTournament()) {
|
||||
// Any special action needed?
|
||||
TournamentManager.getInstance().removeTournament(table.getTournament().getId());
|
||||
}
|
||||
this.removeTable(table.getId());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public class TournamentController {
|
|||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
chatId = ChatManager.getInstance().createChatSession("Tournament " + tournament.getId());
|
||||
this.tournament = tournament;
|
||||
this.tableId = tableId;
|
||||
init();
|
||||
|
@ -427,4 +427,8 @@ public class TournamentController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public void cleanUpOnRemoveTournament() {
|
||||
ChatManager.getInstance().destroyChatSession(chatId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,5 +94,14 @@ public class TournamentManager {
|
|||
public UUID getChatId(UUID tournamentId) {
|
||||
return controllers.get(tournamentId).getChatId();
|
||||
}
|
||||
|
||||
public void removeTournament(UUID tournamentId) {
|
||||
TournamentController tournamentController = controllers.get(tournamentId);
|
||||
if (tournamentController != null) {
|
||||
controllers.remove(tournamentId);
|
||||
tournamentController.cleanUpOnRemoveTournament();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1542,11 +1542,11 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
@Override
|
||||
public void concede(Game game) {
|
||||
log.debug("playerImpl.concede -> start " + this.getName());
|
||||
log.debug(this.getName() + (" concedes gameId:" +game.getId()));
|
||||
game.gameOver(playerId);
|
||||
log.debug("playerImpl.concede -> before lost " + this.getName());
|
||||
log.debug("Before lost " + this.getName());
|
||||
lost(game);
|
||||
log.debug("playerImpl.concede -> after lost " + this.getName());
|
||||
log.debug("After lost " + this.getName());
|
||||
this.left = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue