public void process(Client client) throws ClientValidationException { if (client instanceof QueryClient) { return; } // adjust the read timeout for the client if (client instanceof TetrinetClient) { TetrinetClient c = (TetrinetClient) client; try { c.getSocket().setSoTimeout(2 * getTimeout() * 1000); } catch (SocketException e) { e.printStackTrace(); } } // start listening the messages sent by the client MessageReader messageReader = new MessageReader(client); messageReader.start(); // initiates the dialogue client.send(new PlayerNumMessage(1)); prologue(client); // wait until the client is processed try { Boolean accepted = queue.poll(getTimeout(), TimeUnit.SECONDS); if ((accepted == null || accepted == Boolean.FALSE) && isValidating()) { log.info("Rejecting " + client); client.disconnect(); throw new ClientValidationException(); } else { log.info("Accepting: " + client); } } catch (InterruptedException e) { e.printStackTrace(); } }
public void run() { running = true; try { log.finer("Message reader started (" + this + ")"); Message message; while (running && (message = client.receive()) != null) { send(message); } } catch (IOException e) { log.log(Level.WARNING, "Error reading client message during the interception", e); } finally { log.finer("Message reader stopped (" + this + ")"); } }
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); String name = request.getParameter("name"); String redirect = "/user.jsp?name=" + name; Client client = ClientRepository.getInstance().getClient(name); if ("kick".equals(action)) { logger.info( client.getUser().getName() + " (" + client.getInetAddress() + ") has been kicked by " + request.getRemoteUser() + " (" + request.getRemoteHost() + ")"); } else if ("ban".equals(action)) { Banlist banlist = Banlist.getInstance(); banlist.ban(client.getInetAddress().getHostAddress()); logger.info( client.getUser().getName() + " (" + client.getInetAddress() + ") has been banned by " + request.getRemoteUser() + " (" + request.getRemoteHost() + ")"); // save the server configuration Server.getInstance().getConfig().save(); } client.disconnect(); response.sendRedirect("/channel.jsp?name=" + client.getChannel().getConfig().getName()); }