/* * Copyright (C) 2004-2015 L2J Server * * This file is part of L2J Server. * * L2J Server is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * L2J Server is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.l2jserver.loginserver; import java.nio.channels.SocketChannel; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import commons.mmocore.IAcceptFilter; import commons.mmocore.IClientFactory; import commons.mmocore.IMMOExecutor; import commons.mmocore.MMOConnection; import commons.mmocore.ReceivablePacket; import com.l2jserver.loginserver.network.L2LoginClient; import com.l2jserver.loginserver.network.serverpackets.Init; import com.l2jserver.util.IPv4Filter; /** * @author KenM */ public class SelectorHelper implements IMMOExecutor, IClientFactory, IAcceptFilter { private final ThreadPoolExecutor _generalPacketsThreadPool; private final IPv4Filter _ipv4filter; public SelectorHelper() { _generalPacketsThreadPool = new ThreadPoolExecutor(4, 6, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue()); _ipv4filter = new IPv4Filter(); } @Override public void execute(ReceivablePacket packet) { _generalPacketsThreadPool.execute(packet); } @Override public L2LoginClient create(MMOConnection con) { L2LoginClient client = new L2LoginClient(con); client.sendPacket(new Init(client)); return client; } @Override public boolean accept(SocketChannel sc) { return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress()); } }