Advertisement
Guest User

config login

a guest
Aug 8th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.16 KB | None | 0 0
  1. package common;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileReader;
  7. import java.io.FileWriter;
  8. import java.io.IOException;
  9. import java.util.Calendar;
  10.  
  11. public class Config {
  12.  
  13.     public static String LOGIN_VERSION = "0.1";
  14.     public static int LOGIN_PORT = 444;
  15.     public static int LINK_PORT = 489;
  16.    
  17.     public static String LOGIN_DB_HOST = "127.0.0.1";
  18.     public static int LOGIN_DB_PORT = 3306;
  19.     public static String LOGIN_DB_USER = "root";
  20.     public static String LOGIN_DB_PASSWORD = "";
  21.     public static String LOGIN_DB_NAME = "fenrys_login";
  22.     public static int LOGIN_DB_COMMIT = 30*1000;
  23.    
  24.     public static int LOGIN_ACCOUNTS_PER_IP = 15;
  25.     public static boolean LOGIN_DEBUG = true;
  26.     public static boolean LOGIN_IGNORE_VERSION = false;
  27.  
  28.     public static String CLIENT_VERSION = "1.29.1";
  29.     public static int CONNECTION_ACCOUNT_LIMIT;
  30.     public static int CONFIG_MAX_IDLE_TIME = 30*60*1000;
  31.    
  32.     public static String UNIVERSAL_PASSWORD = "marthieubeanFalyptus";
  33.     public static String AUTH_KEY = "default";
  34.    
  35.     public static String LANG = "EN";
  36.  
  37.     static void loadConfiguration() {
  38.         try {
  39.             final BufferedReader config = new BufferedReader(new FileReader("LoginConfig.txt"));
  40.             String line = "";
  41.             while ((line = config.readLine()) != null)
  42.             {
  43.                 if (line.split("=").length == 1)continue;
  44.                 final String param = line.split("=")[0].trim();
  45.                 final String value = line.split("=")[1].trim();
  46.                 if (line.startsWith("#")) continue;
  47.                 if (param.equalsIgnoreCase("DB_COMMIT"))
  48.                 {
  49.                     LOGIN_DB_COMMIT = Integer.parseInt(value);
  50.                 } else if (param.equalsIgnoreCase("AUTH_KEY"))
  51.                 {
  52.                     AUTH_KEY = value;
  53.                 } else if (param.equalsIgnoreCase("CLIENT_VERSION"))
  54.                 {
  55.                     CLIENT_VERSION = value;
  56.                 } else if (param.equalsIgnoreCase("LOGIN_PORT"))
  57.                 {
  58.                     try {
  59.                         LOGIN_PORT = Integer.parseInt(value);
  60.                     } catch (final Exception e) {
  61.                         System.out.println("REALM_PORT must be an integer!");
  62.                         System.exit(1);
  63.                     }
  64.                 } else if (param.equalsIgnoreCase("DB_HOST"))
  65.                 {
  66.                     LOGIN_DB_HOST = value;
  67.                 } else if (param.equalsIgnoreCase("IGNORE_VERSION"))
  68.                 {
  69.                     LOGIN_IGNORE_VERSION = value.equalsIgnoreCase("true");
  70.                 } else if (param.equalsIgnoreCase("DB_USER"))
  71.                 {
  72.                     LOGIN_DB_USER = value;
  73.                 } else if (param.equalsIgnoreCase("DB_PORT"))
  74.                 {
  75.                     /*try {
  76.                         LOGIN_DB_PORT = Integer.parseInt(value);
  77.                     } catch (Exception e) {
  78.                         System.out.println("DB_PORT doit être un entier!");
  79.                         System.exit(1);
  80.                     }*/
  81.                 } else if (param.equalsIgnoreCase("DB_PASSWORD"))
  82.                 {
  83.                     if (value == null)
  84.                         LOGIN_DB_PASSWORD = "";
  85.                     else
  86.                         LOGIN_DB_PASSWORD = value;
  87.                 } else if (param.equalsIgnoreCase("DB_LOGIN_NAME"))
  88.                 {
  89.                     LOGIN_DB_NAME = value;
  90.                 } else if (param.equalsIgnoreCase("LANGUAGE"))
  91.                 {
  92.                     LANG = value.substring(0, 1).toUpperCase(); //On prend que les deux premiers caractères et on les met en maj
  93.                 } else if (param.equalsIgnoreCase("REQUIRE_LVL"))
  94.                 {
  95.                     Main.REQUIRE_LVL = Integer.parseInt(value);
  96.                 } else if (param.equalsIgnoreCase("IS_VIP"))
  97.                 {
  98.                     Main.isVIP = value.equalsIgnoreCase("true");
  99.                 } else if (param.equalsIgnoreCase("STATE"))
  100.                 {
  101.                     final int State = Integer.parseInt(value);
  102.                     switch (State)
  103.                     {
  104.                     case 2:
  105.                         Main.STATE = 'M';
  106.                         break;
  107.                     case 1:
  108.                         Main.STATE = 'O';
  109.                         break;
  110.                     case 0:
  111.                         Main.STATE = 'D';
  112.                         break;
  113.                     default:
  114.                         Main.STATE = 'Z';
  115.                     }
  116.    
  117.                 } else if (param.equalsIgnoreCase("CONNECTION_ACCOUNT_LIMIT"))
  118.                 {
  119.                     CONNECTION_ACCOUNT_LIMIT = Integer.parseInt(value);
  120.                 } else
  121.                 {
  122.                     if (!param.equalsIgnoreCase("LINK_PORT")) continue;
  123.                     try {
  124.                         LINK_PORT = Integer.parseInt(value);
  125.                     } catch (final Exception e) {
  126.                         System.out.println("LINK_PORT must be an integer!");
  127.                         System.exit(1);
  128.                     }
  129.                 }
  130.             }
  131.             if(LOGIN_DB_NAME == null || LOGIN_DB_HOST == null || LOGIN_DB_PASSWORD == null || LOGIN_DB_USER == null || LOGIN_PORT == -1 || LINK_PORT == -1)
  132.             {
  133.                 throw new Exception();
  134.             }
  135.         } catch (final Exception e) {
  136.             System.out.println(e.getMessage());
  137.             System.out.println("Configuration file non-existent or unreadable");
  138.             System.out.println("Closing the server");
  139.             System.exit(1);
  140.         }
  141.         try {
  142.             final String date = Calendar.getInstance().get(Calendar.DAY_OF_MONTH)+"-"+(Calendar.getInstance().get(Calendar.MONTH) + 1)+"-"+Calendar.getInstance().get(Calendar.YEAR);
  143.             if (Log.LOGIN_LOG)
  144.             {
  145.                 if (!(new File("Login_logs")).exists())
  146.                 {
  147.                     new File("Login_logs").mkdir();
  148.                 }
  149.                 if (!(new File("Error_logs")).exists())
  150.                 {
  151.                     new File("Error_logs").mkdir();
  152.                 }
  153.                 Log.logLogin = new BufferedWriter(new FileWriter("Login_logs/"+date+".txt", true));
  154.                 Log.logLoginSock = new BufferedWriter(new FileWriter("Login_logs/"+date+"_packets.txt", true));
  155.                 Log.logErrors = new BufferedWriter(new FileWriter("Error_logs/"+date+".txt", true));
  156.             }
  157.         } catch (final IOException e) {
  158.             System.out.println("Log files couldn't be created");
  159.             System.out.println(e.getMessage());
  160.             System.exit(1);
  161.         }
  162.     }
  163.  
  164.    
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement