Fixed login issues after latest eclipse corrections.

This commit is contained in:
MobiusDev 2017-09-30 14:46:18 +00:00
parent f85299668b
commit 291b59aa9e
14 changed files with 128 additions and 53 deletions

View File

@ -323,21 +323,39 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
public boolean isBannedAddress(InetAddress address)
{
final String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi != null)
{

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -60,7 +59,7 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
}
@Override
public boolean accept(SocketChannel sc) throws UnknownHostException
public boolean accept(SocketChannel sc)
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver.network.mmocore;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
/**
@ -24,5 +23,5 @@ import java.nio.channels.SocketChannel;
*/
public interface IAcceptFilter
{
boolean accept(SocketChannel sc) throws UnknownHostException;
boolean accept(SocketChannel sc);
}

View File

@ -323,21 +323,39 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
public boolean isBannedAddress(InetAddress address)
{
final String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi != null)
{

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -60,7 +59,7 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
}
@Override
public boolean accept(SocketChannel sc) throws UnknownHostException
public boolean accept(SocketChannel sc)
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver.network.mmocore;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
/**
@ -24,5 +23,5 @@ import java.nio.channels.SocketChannel;
*/
public interface IAcceptFilter
{
boolean accept(SocketChannel sc) throws UnknownHostException;
boolean accept(SocketChannel sc);
}

View File

@ -323,21 +323,39 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
public boolean isBannedAddress(InetAddress address)
{
final String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi != null)
{

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -60,7 +59,7 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
}
@Override
public boolean accept(SocketChannel sc) throws UnknownHostException
public boolean accept(SocketChannel sc)
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver.network.mmocore;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
/**
@ -24,5 +23,5 @@ import java.nio.channels.SocketChannel;
*/
public interface IAcceptFilter
{
boolean accept(SocketChannel sc) throws UnknownHostException;
boolean accept(SocketChannel sc);
}

View File

@ -321,28 +321,50 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
public boolean isBannedAddress(InetAddress address)
{
final String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address) == null ? _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0")) : _bannedIps.get(address);
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
return false;
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
catch (UnknownHostException e)
{
}
}
if ((bi <= 0) || (bi >= System.currentTimeMillis()))
if (bi != null)
{
if ((bi > 0) && (bi < System.currentTimeMillis()))
{
_bannedIps.remove(address);
_log.info("Removed expired ip address ban " + address.getHostAddress() + ".");
return false;
}
return true;
}
_bannedIps.remove(address);
_log.info("Removed expired ip address ban " + address.getHostAddress() + ".");
return false;
}

View File

@ -16,12 +16,10 @@
*/
package com.l2jmobius.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 com.l2jmobius.commons.mmocore.IAcceptFilter;
import com.l2jmobius.commons.mmocore.IClientFactory;
@ -37,13 +35,12 @@ import com.l2jmobius.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;
public SelectorHelper()
{
_generalPacketsThreadPool = new ThreadPoolExecutor(4, 6, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
_generalPacketsThreadPool = new ThreadPoolExecutor(4, 6, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
_ipv4filter = new IPv4Filter();
}
@ -64,14 +61,6 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
@Override
public boolean accept(SocketChannel sc)
{
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;
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}
}

View File

@ -323,21 +323,39 @@ public class LoginController
_bannedIps.putIfAbsent(address, System.currentTimeMillis() + duration);
}
public boolean isBannedAddress(InetAddress address) throws UnknownHostException
public boolean isBannedAddress(InetAddress address)
{
final String[] parts = address.getHostAddress().split("\\.");
Long bi = _bannedIps.get(address);
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + "." + parts[2] + ".0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + "." + parts[1] + ".0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi == null)
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
try
{
bi = _bannedIps.get(InetAddress.getByName(parts[0] + ".0.0.0"));
}
catch (UnknownHostException e)
{
}
}
if (bi != null)
{

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
@ -60,7 +59,7 @@ public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFacto
}
@Override
public boolean accept(SocketChannel sc) throws UnknownHostException
public boolean accept(SocketChannel sc)
{
return _ipv4filter.accept(sc) && !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
}

View File

@ -16,7 +16,6 @@
*/
package com.l2jmobius.loginserver.network.mmocore;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
/**
@ -24,5 +23,5 @@ import java.nio.channels.SocketChannel;
*/
public interface IAcceptFilter
{
boolean accept(SocketChannel sc) throws UnknownHostException;
boolean accept(SocketChannel sc);
}