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; }
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; }
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; }
@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"; } }