Alejandro Acuña
2024-10-22 9214c4e5cec380dc263034f9a0e5a10f0dc1ebac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
    }
    
    
    
}