Search in sources :

Example 1 with TableState

use of mage.constants.TableState in project mage by magefree.

the class MageServerImpl method leaveTable.

@Override
public boolean leaveTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
    Optional<TableController> tableController = managerFactory.tableManager().getController(tableId);
    if (tableController.isPresent()) {
        TableState tableState = tableController.get().getTableState();
        if (tableState != TableState.WAITING && tableState != TableState.READY_TO_START) {
            // table was already started, so player can't leave anymore now
            return false;
        }
        execute("leaveTable", sessionId, () -> {
            managerFactory.sessionManager().getSession(sessionId).ifPresent(session -> {
                UUID userId = session.getUserId();
                managerFactory.gamesRoomManager().getRoom(roomId).ifPresent(room -> room.leaveTable(userId, tableId));
            });
        });
    } else {
        // this can happen if a game ends and a player quits XMage or a match nearly at the same time as the game ends
        logger.trace("table not found : " + tableId);
    }
    return true;
}
Also used : TableState(mage.constants.TableState)

Aggregations

TableState (mage.constants.TableState)1