/*
* This program 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. This program 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 <http://www.gnu.org/licenses/>.
*/
package silentium.authserver;
import silentium.authserver.network.serverpackets.Init;
import silentium.commons.network.mmocore.*;
import silentium.commons.utils.IPv4Filter;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author KenM
*/
public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFactory<L2LoginClient>, IAcceptFilter {
private final ThreadPoolExecutor _generalPacketsThreadPool;
private final IPv4Filter _ipv4filter;
public SelectorHelper() {
_generalPacketsThreadPool = new ThreadPoolExecutor(4, 6, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
_ipv4filter = new IPv4Filter();
}
@Override
public void execute(final ReceivablePacket<L2LoginClient> packet) {
_generalPacketsThreadPool.execute(packet);
}
@Override
public L2LoginClient create(final MMOConnection<L2LoginClient> con) {
final L2LoginClient client = new L2LoginClient(con);
client.sendPacket(new Init(client));
return client;
}
@Override
public boolean accept(final SocketChannel sc) {
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}
}