package art.servers.configuration;
|
|
import art.servers.types.IPv4;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
|
public class ConfigurationListenerDEBUG
|
{
|
@JsonProperty("Port")
|
public int port = 0;
|
|
@JsonProperty("Maximum connections")
|
public int maximumConnections = 0;
|
|
@JsonProperty("Allowed connections")
|
public List<String> allowedConnections = new ArrayList<String>();
|
|
|
|
@JsonIgnore
|
public boolean allowed(String address)
|
{
|
try
|
{
|
if (allowedConnections.isEmpty() == true) return true;
|
|
long address1 = IPv4.toLong(address);
|
|
for (String connection : allowedConnections)
|
{
|
long address2 = IPv4.toLong(connection.substring(0, connection.indexOf("/")));
|
long mask = IPv4.toLong(Integer.parseInt(connection.substring(connection.indexOf("/") + 1, connection.length())));
|
if ((address1 & mask) == (address2 & mask)) return true;
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
|
return false;
|
}
|
|
|
|
}
|