示例#1
0
  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);
      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.getState().equals(TableState.FINISHED)) {
        GamesRoomManager.getInstance().removeTable(tableId);
      }
      if (table.getMatch() != null && table.getMatch().getGame() != null) {
        table.getMatch().getGame().end();
      }
    }
  }
示例#2
0
 public String registerUserHandling(String userName) throws MageException {
   this.isAdmin = false;
   if (userName.equals("Admin")) {
     return "User name Admin already in use";
   }
   if (userName.length() > ConfigSettings.getInstance().getMaxUserNameLength()) {
     return new StringBuilder("User name may not be longer than ")
         .append(ConfigSettings.getInstance().getMaxUserNameLength())
         .append(" characters")
         .toString();
   }
   if (userName.length() < ConfigSettings.getInstance().getMinUserNameLength()) {
     return new StringBuilder("User name may not be shorter than ")
         .append(ConfigSettings.getInstance().getMinUserNameLength())
         .append(" characters")
         .toString();
   }
   Pattern p =
       Pattern.compile(
           ConfigSettings.getInstance().getUserNamePattern(), Pattern.CASE_INSENSITIVE);
   Matcher m = p.matcher(userName);
   if (m.find()) {
     return new StringBuilder("User name '")
         .append(userName)
         .append("' includes not allowed characters: use a-z, A-Z and 0-9")
         .toString();
   }
   User user = UserManager.getInstance().createUser(userName, host);
   boolean reconnect = false;
   if (user == null) { // user already exists
     user = UserManager.getInstance().findUser(userName);
     if (user.getHost().equals(host)) {
       user.updateLastActivity(null); // minimizes possible expiration
       this.userId = user.getId();
       if (user.getSessionId().isEmpty()) {
         logger.info("Reconnecting session for " + userName);
         reconnect = true;
       } else {
         // disconnect previous session
         logger.info("Disconnecting another user instance: " + userName);
         SessionManager.getInstance()
             .disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
       }
     } else {
       return new StringBuilder("User name ")
           .append(userName)
           .append(" already in use (or your IP address changed)")
           .toString();
     }
   }
   if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
     return new StringBuilder("Error connecting ").append(userName).toString();
   }
   this.userId = user.getId();
   if (reconnect) { // must be connected to receive the message
     UUID chatId =
         GamesRoomManager.getInstance()
             .getRoom(GamesRoomManager.getInstance().getMainRoomId())
             .getChatId();
     if (chatId != null) {
       ChatManager.getInstance().joinChat(chatId, userId);
     }
     ChatManager.getInstance().sendReconnectMessage(userId);
   }
   return null;
 }