package io.luna.net;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import io.luna.net.session.Session;
import io.netty.channel.Channel;
import io.netty.util.AttributeKey;
import io.netty.util.ResourceLeakDetector.Level;

/**
 * A utility class that only contains Netty constants.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class LunaNetworkConstants {

    /**
     * The resource leak detection level, should be {@code PARANOID} in a development environment and {@code DISABLED} in a
     * production environment.
     */
    public static final Level RESOURCE_LEAK_DETECTION = Level.PARANOID;

    /**
     * The port that the server will be bound on.
     */
    public static final int PORT = 43594;

    /**
     * The amount of {@code SECONDS} that must elapse for a channel to be disconnected after no read operations.
     */
    public static final int READ_IDLE_SECONDS = 5;

    /**
     * The maximum amount of connections allowed per channel.
     */
    public static final int CONNECTION_LIMIT = 2;

    /**
     * The maximum amount of incoming messages per cycle.
     */
    public static final int MESSAGE_LIMIT = 15;

    /**
     * The preferred ports for the user to use, a log message will be printed if none of these ports are used.
     */
    public static final ImmutableSet<Integer> PREFERRED_PORTS = ImmutableSet.of(43594, 5555);

    /**
     * A list of exceptions that are ignored when received from Netty.
     */
    public static final ImmutableList<String> IGNORED_EXCEPTIONS = ImmutableList
        .of("An existing connection was forcibly closed by the remote host",
            "An established connection was aborted by the software in your host machine");

    /**
     * An {@link AttributeKey} that is used to retrieve the session instance from the attribute map of a {@link Channel}.
     */
    public static final AttributeKey<Session> SESSION_KEY = AttributeKey.valueOf("session.KEY");

    /**
     * A private constructor to discourage external instantiation.
     */
    private LunaNetworkConstants() {
    }
}

@@ -110,16 +110,86 @@
 bleSet;%0A
+import com.google.gson.JsonObject;%0Aimport com.moandjiezana.toml.Toml;%0A
 import i
@@ -334,16 +334,67 @@
 Level;%0A%0A
+import java.io.File;%0Aimport java.math.BigInteger;%0A%0A
 /**%0A * A
@@ -539,16 +539,676 @@
 ants %7B%0A%0A
+    static %7B%0A        try %7B%0A            JsonObject reader = new Toml().read(new File(%22./data/luna.toml%22)).getTable(%22settings%22).to(JsonObject.class);%0A%0A            PORT = reader.get(%22port%22).getAsInt();%0A            RSA_MODULUS = new BigInteger(reader.get(%22rsa_modulus%22).getAsString());%0A            RSA_EXPONENT = new BigInteger(reader.get(%22rsa_exponent%22).getAsString());%0A            RESOURCE_LEAK_DETECTION = Level.valueOf(reader.get(%22resource_leak_detection_level%22).getAsString());%0A            CONNECTION_LIMIT = reader.get(%22connection_threshold%22).getAsInt();%0A        %7D catch (Exception e) %7B%0A            throw new ExceptionInInitializerError(e);%0A        %7D%0A    %7D%0A%0A
     /**%0A
@@ -1427,25 +1427,8 @@
 TION
- = Level.PARANOID
 ;%0A%0A 
@@ -1528,16 +1528,8 @@
 PORT
- = 43594
 ;%0A%0A 
@@ -1550,108 +1550,137 @@
 The 
-amount of %7B@code SECONDS%7D that must elapse for a channel to be disconnected after no read operations
+public RSA exponent value.%0A     */%0A    public static final BigInteger RSA_MODULUS;%0A%0A    /**%0A     * The private RSA exponent value
 .%0A  
@@ -1713,33 +1713,31 @@
 nal 
-int READ_IDLE_SECONDS = 5
+BigInteger RSA_EXPONENT
 ;%0A%0A 
@@ -1861,12 +1861,189 @@
 IMIT
+;%0A%0A    /**%0A     * The amount of %7B@code SECONDS%7D that must elapse for a channel to be disconnected after no read operations.%0A     */%0A    public static final int READ_IDLE_SECONDS
  = 
-2
+5
 ;%0A%0A 

Load network constants from luna.toml