Example #1
0
 public void endGame(UUID tableId) {
   if (controllers.containsKey(tableId)) {
     if (controllers.get(tableId).endGameAndStartNextGame()) {
       removeTable(tableId);
     }
   }
 }
Example #2
0
 public boolean removeTable(UUID userId, UUID tableId) {
   if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) {
     leaveTable(userId, tableId);
     TableController tableController = controllers.get(tableId);
     if (tableController != null) {
       ChatManager.getInstance().destroyChatSession(tableController.getChatId());
       removeTable(tableId);
     }
     return true;
   }
   return false;
 }
Example #3
0
  public void leaveTable(UUID userId, UUID tableId) {
    TableController tableController = controllers.get(tableId);
    if (tableController != null) {
      // table not started yet and user is the owner, remove the table
      Table table = getTable(tableId);
      if (table != null
          && isTableOwner(tableId, userId)
          && (table.getState().equals(TableState.WAITING)
              || table.getState().equals(TableState.STARTING))) {
        removeTable(tableId);

      } else {
        logger.debug("TABLE leave - userId: " + userId + "  tableId: " + tableId);
        tableController.leaveTable(userId);
      }
    }
  }
Example #4
0
 private void checkExpired() {
   debugServerState();
   Date now = new Date();
   List<UUID> toRemove = new ArrayList<>();
   for (Table table : tables.values()) {
     if (!table.getState().equals(TableState.FINISHED)) {
       // remove all not finished tables created more than expire_time ago
       long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
       if (diff >= EXPIRE_TIME) {
         logger.warn(
             "Table expired: id = "
                 + table.getId()
                 + ", created_by="
                 + table.getControllerName()
                 + ". Removing...");
         toRemove.add(table.getId());
       }
       // remove tables not valid anymore
       else if (!table.isTournament()) {
         TableController tableController = getController(table.getId());
         if (!tableController.isMatchTableStillValid()) {
           logger.warn(
               "Table with no active human player: id = "
                   + table.getId()
                   + ", created_by="
                   + table.getControllerName()
                   + ". Removing...");
           toRemove.add(table.getId());
         }
       }
     }
   }
   for (UUID tableId : toRemove) {
     try {
       removeTable(tableId);
     } catch (Exception e) {
       logger.error(e);
     }
   }
 }