Java Socket垃圾邮件导致打开文件太多

时间:2016-01-08 16:44:41

标签: java sockets spam

我正在为游戏服务器运行套接字服务器而有人正在垃圾邮件我的服务器端口导致太多打开文件错误。发生这种情况时,我的应用程序无法打开新连接。

    //Opens a new connection
    @Override
        public void sessionOpened(IoSession session) {
        FilePrinter.print(FilePrinter.SESSION, "IoSession with " + session.getRemoteAddress() + " opened on " + sdf.format(Calendar.getInstance().getTime()), false);

        byte key[] = {BLLABLALBALBALBLALBALBLABLALBALBLALBALBLA};
        byte ivRecv[] = {BLA BLA BLA};
        byte ivSend[] = {BLA BLA BLA};
        ivRecv[3] = (byte) (Math.random() * 255);
        ivSend[3] = (byte) (Math.random() * 255);
        MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - ServerConstants.VERSION));
        MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, (short) ServerConstants.VERSION);
        MapleClient client = new MapleClient(sendCypher, recvCypher, session);
        client.setWorld(world);
        client.setChannel(channel);
        session.write(MaplePacketCreator.getHello(ServerConstants.VERSION, ivSend, ivRecv));
        session.setAttribute(MapleClient.CLIENT_KEY, client);
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
        if (client != null) {
            try {
                boolean inCashShop = false;
                if (client.getPlayer() != null) {
                    inCashShop = client.getPlayer().getCashShop().isOpened();                  
                }
                client.disconnect(false, inCashShop);
            } catch (Throwable t) {
                FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, t);
            } finally {
                session.close();
                session.removeAttribute(MapleClient.CLIENT_KEY);
                //client.empty();
            }
        }
        super.sessionClosed(session);
    }

我已经尝试使用iptables阻止超过5个连接,但它不起作用。当一个ip打开一千个假连接时,我的服务器无法创建新的连接。

此服务器是一个开源游戏服务器。您可以在此处查看完整代码:http://trac.assembla.com/MoopleDEV/browser 我发布的这个文件的路径是:src / net / MapleServerHandler.java

任何帮助解决此问题的人都将不胜感激

0 个答案:

没有答案