Sync with L2jServer HighFive Apr 1st 2015.

This commit is contained in:
MobiusDev
2015-04-02 04:12:06 +00:00
parent 8300183361
commit 1abccfcae0
26 changed files with 283 additions and 248 deletions

View File

@@ -327,21 +327,21 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address)
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
{
String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(parts[0] + "." + parts[1] + "." + parts[2] + ".0");
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
if (bi == null)
{
bi = _bannedIps.get(parts[0] + "." + parts[1] + ".0.0");
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
if (bi == null)
{
bi = _bannedIps.get(parts[0] + ".0.0.0");
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
if (bi != null)
{
@@ -368,7 +368,7 @@ public class LoginController
*/
public boolean removeBanForAddress(InetAddress address)
{
return _bannedIps.remove(address.getHostAddress()) != null;
return _bannedIps.remove(address) != null;
}
/**

View File

@@ -18,10 +18,12 @@
*/
package com.l2jserver.loginserver;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
import commons.mmocore.IAcceptFilter;
import commons.mmocore.IClientFactory;
@@ -38,6 +40,7 @@ import com.l2jserver.util.IPv4Filter;
*/
public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFactory<L2LoginClient>, IAcceptFilter
{
private static final Logger LOG = Logger.getLogger(LoginController.class.getName());
private final ThreadPoolExecutor _generalPacketsThreadPool;
private final IPv4Filter _ipv4filter;
@@ -64,6 +67,14 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
@Override
public boolean accept(SocketChannel sc)
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
try
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}
catch (UnknownHostException e)
{
LOG.severe(SelectorHelper.class.getSimpleName() + ": Invalid address: " + sc.socket().getInetAddress() + "; " + e.getMessage());
}
return false;
}
}