Ejemplo n.º 1
0
 public ArrayList<String> getUserList() {
   ArrayList<String> userList = new ArrayList<String>();
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       userList.add(clientThread.getUserName());
     }
   }
   return userList;
 }
Ejemplo n.º 2
0
 public boolean doesUserExist(String newUser) {
   boolean result = false;
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       result = clientThread.getUserName().compareTo(newUser) == 0;
     }
   }
   return result;
 }
Ejemplo n.º 3
0
 public boolean sendPrivateMessage(String message, String user) {
   for (Connection clientThread : list) {
     if (clientThread.getState() == Connection.STATE_REGISTERED) {
       if (clientThread.getUserName().compareTo(user) == 0) {
         clientThread.messageForConnection(message + System.lineSeparator());
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 4
0
  @RequestMapping(value = "/connect", method = RequestMethod.POST)
  public String connecting(
      @ModelAttribute("connection") Connection connection, HttpSession session, Model model) {

    try {
      DatabaseManager manager =
          service.connect(
              connection.getDbName(), connection.getUserName(), connection.getPassword());
      session.setAttribute("db_manager", manager);
      return "redirect:" + connection.getFromPage();
    } catch (Exception e) {
      e.printStackTrace();
      model.addAttribute("message", e.getMessage());
      return "error";
    }
  }