Guest User

Untitled

a guest
Dec 10th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. package org.moparscape.msc.config;
  2.  
  3. /**
  4. * A class to handle loading configuration from XML
  5. */
  6.  
  7. import java.io.File;
  8. import java.io.FileInputStream;
  9. import java.io.IOException;
  10. import java.util.Properties;
  11.  
  12. public class Config {
  13. /**
  14. * User info for the database
  15. */
  16. public static String MYSQL_HOST = "localhost";
  17. public static String MYSQL_DB = "hypers";
  18. public static String MYSQL_USER = "root";
  19. public static String MYSQL_PASS = "justanotherpw";
  20.  
  21. public static String SERVER_IP, SERVER_NAME, RSCD_HOME, CONF_DIR,
  22. SERVER_LOCATION, LS_IP;
  23.  
  24. public static int SERVER_PORT, SERVER_VERSION, MAX_PLAYERS, LS_PORT,
  25. SERVER_NUM, CONENCTION_THROTTLE_THRESHOLD;
  26.  
  27. public static long START_TIME;
  28.  
  29. public static boolean members, f2pWildy, APPLICATION_LEVEL_BLOCKING;
  30.  
  31. public static double expRate, subExpRate, WILD_NON_COMBAT_BONUS,
  32. WILD_COMBAT_BONUS;
  33.  
  34. public static String[] pmods, mods, admins;
  35. public static int IP_BAN_REMOVAL_DELAY, GARBAGE_COLLECT_INTERVAL,
  36. SAVE_INTERVAL;
  37. public static String DATE_FORMAT, BLOCK_COMMAND, UNBLOCK_COMMAND,
  38. ALERT_CONFIG, COMMAND_CONFIG;
  39. public static int CONNECTION_THROTTLE_SIZE,
  40. WILD_LEVEL_FOR_NON_COMBAT_BONUS, WILD_STAND_STILL_TIME,
  41. DELAY_REMOVAL;
  42. public static boolean OS_LEVEL_BLOCKING, APPLICATION_LEVEL_THROTTLE_ALERT,
  43. OS_LEVEL_THROTTLE_ALERT, OS_LEVEL_UNBLOCK_FAILED_ALERT,
  44. CONGRATS_FOR_MAX_LEVEL;
  45.  
  46. static {
  47. loadEnv();
  48. }
  49.  
  50. /**
  51. * Called to load config settings from the given file
  52. *
  53. * @param file
  54. * the xml file to load settings from
  55. * @throws IOException
  56. * if an i/o error occurs
  57. */
  58. public static void initConfig(String file) throws IOException {
  59. START_TIME = System.currentTimeMillis();
  60.  
  61. Properties props = new Properties();
  62. props.loadFromXML(new FileInputStream(file));
  63.  
  64. SERVER_VERSION = Integer.parseInt(props.getProperty("25"));
  65. SERVER_NAME = props.getProperty("hypers");
  66. SERVER_IP = props.getProperty("localhost");
  67. SERVER_PORT = Integer.parseInt(props.getProperty("43594"));
  68. SERVER_LOCATION = props.getProperty("home");
  69.  
  70. MYSQL_USER = props.getProperty("root");
  71. MYSQL_PASS = props.getProperty("justanotherpw");
  72. MYSQL_HOST = props.getProperty("localhost");
  73. MYSQL_DB = props.getProperty("hypers");
  74.  
  75. MAX_PLAYERS = Integer.parseInt(props.getProperty("100000"));
  76.  
  77. LS_IP = props.getProperty("localhost");
  78. LS_PORT = Integer.parseInt(props.getProperty("34526"));
  79. SERVER_NUM = Integer.parseInt(props.getProperty("servernum"));
  80.  
  81. members = Boolean.parseBoolean(props.getProperty("members", "false"));
  82. f2pWildy = Boolean.parseBoolean(props.getProperty("f2pWildy", "true"));
  83. expRate = Double.parseDouble(props.getProperty("2"));
  84. subExpRate = Double.parseDouble(props.getProperty("4"));
  85.  
  86. pmods = props.getProperty("pmods").replaceAll(", +", ",").split(",");
  87. mods = props.getProperty("mods").replaceAll(", +", ",").split(",");
  88. admins = props.getProperty("admins").replaceAll(", +", ",").split(",");
  89.  
  90. IP_BAN_REMOVAL_DELAY = Integer.parseInt(props
  91. .getProperty("ip-ban-removal-delay"));
  92. BLOCK_COMMAND = props.getProperty("os-level-block-command");
  93. UNBLOCK_COMMAND = props.getProperty("os-level-unblock-command");
  94. CONNECTION_THROTTLE_SIZE = Integer.parseInt(props
  95. .getProperty("connection-throttle-size"));
  96. CONENCTION_THROTTLE_THRESHOLD = Integer.parseInt(props
  97. .getProperty("connection-throttle"));
  98. APPLICATION_LEVEL_BLOCKING = Boolean.parseBoolean(props
  99. .getProperty("application-level-blocking"));
  100. OS_LEVEL_BLOCKING = Boolean.parseBoolean(props
  101. .getProperty("os-level-blocking"));
  102. APPLICATION_LEVEL_THROTTLE_ALERT = Boolean.parseBoolean(props
  103. .getProperty("application-level-blocking-throttle-alert"));
  104. OS_LEVEL_THROTTLE_ALERT = Boolean.parseBoolean(props
  105. .getProperty("os-level-blocking-throttle-alert"));
  106. OS_LEVEL_UNBLOCK_FAILED_ALERT = Boolean.parseBoolean(props
  107. .getProperty("os-level-blocking-unblock-failed-alert"));
  108. DELAY_REMOVAL = Integer.parseInt(props
  109. .getProperty("connection-throttle-remove-delay"));
  110.  
  111. GARBAGE_COLLECT_INTERVAL = Integer.parseInt(props
  112. .getProperty("garbage-collect-interval"));
  113. SAVE_INTERVAL = Integer.parseInt(props.getProperty("save-interval"));
  114.  
  115. DATE_FORMAT = props.getProperty("date-format");
  116.  
  117. ALERT_CONFIG = props.getProperty("alert-config");
  118. COMMAND_CONFIG = props.getProperty("command-config");
  119.  
  120. WILD_STAND_STILL_TIME = Integer.parseInt(props
  121. .getProperty("wild-stand-still-time"));
  122. WILD_LEVEL_FOR_NON_COMBAT_BONUS = Integer.parseInt(props
  123. .getProperty("wild-non-combat-min-level"));
  124. WILD_NON_COMBAT_BONUS = Double.parseDouble(props
  125. .getProperty("wild-non-combat-bonus"));
  126. WILD_COMBAT_BONUS = Double.parseDouble(props
  127. .getProperty("wild-combat-bonus"));
  128. CONGRATS_FOR_MAX_LEVEL = Boolean.parseBoolean(props
  129. .getProperty("max-level-congrats"));
  130.  
  131. props.clear();
  132.  
  133. Constants.GameServer.MOTD = "@yel@Welcome to @whi@"
  134. + Config.SERVER_NAME + "@yel@ - World @whi@"
  135. + (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " ("
  136. + (Config.members ? "P2P" : "F2P") + ")";
  137. }
  138.  
  139. /**
  140. * Called to load RSCD_HOME and CONF_DIR Used to be situated in
  141. * PersistenceManager
  142. */
  143. private static void loadEnv() {
  144. String home = System.getenv("RSCD_HOME");
  145. if (home == null) { // the env var hasnt been set, fall back to .
  146. home = ".";
  147. }
  148. CONF_DIR = home + File.separator + "conf";
  149. RSCD_HOME = home;
  150. }
  151. }
Add Comment
Please, Sign In to add comment