Guest User

Untitled

a guest
Dec 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 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("serverversion"));
  65. SERVER_NAME = props.getProperty("name");
  66. SERVER_IP = props.getProperty("ip");
  67. SERVER_PORT = Integer.parseInt(props.getProperty("port"));
  68. SERVER_LOCATION = props.getProperty("location");
  69.  
  70. MYSQL_USER = props.getProperty("mysqluser");
  71. MYSQL_PASS = props.getProperty("mysqlpass");
  72. MYSQL_HOST = props.getProperty("mysqlhost");
  73. MYSQL_DB = props.getProperty("mysqldb");
  74.  
  75. MAX_PLAYERS = Integer.parseInt(props.getProperty("maxplayers"));
  76.  
  77. LS_IP = props.getProperty("lsip");
  78. LS_PORT = Integer.parseInt(props.getProperty("lsport"));
  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("expRate"));
  84. subExpRate = Double.parseDouble(props.getProperty("subExpRate"));
  85.  
  86.  
  87. pmods = props.getProperty("pmods").replaceAll(", +", ",").split(",");
  88. mods = props.getProperty("mods").replaceAll(", +", ",").split(",");
  89. admins = props.getProperty("admins").replaceAll(", +", ",").split(",");
  90.  
  91. IP_BAN_REMOVAL_DELAY = Integer.parseInt(props
  92. .getProperty("ip-ban-removal-delay"));
  93. BLOCK_COMMAND = props.getProperty("os-level-block-command");
  94. UNBLOCK_COMMAND = props.getProperty("os-level-unblock-command");
  95. CONNECTION_THROTTLE_SIZE = Integer.parseInt(props
  96. .getProperty("connection-throttle-size"));
  97. CONENCTION_THROTTLE_THRESHOLD = Integer.parseInt(props
  98. .getProperty("connection-throttle"));
  99. APPLICATION_LEVEL_BLOCKING = Boolean.parseBoolean(props
  100. .getProperty("application-level-blocking"));
  101. OS_LEVEL_BLOCKING = Boolean.parseBoolean(props
  102. .getProperty("os-level-blocking"));
  103. APPLICATION_LEVEL_THROTTLE_ALERT = Boolean.parseBoolean(props
  104. .getProperty("application-level-blocking-throttle-alert"));
  105. OS_LEVEL_THROTTLE_ALERT = Boolean.parseBoolean(props
  106. .getProperty("os-level-blocking-throttle-alert"));
  107. OS_LEVEL_UNBLOCK_FAILED_ALERT = Boolean.parseBoolean(props
  108. .getProperty("os-level-blocking-unblock-failed-alert"));
  109. DELAY_REMOVAL = Integer.parseInt(props
  110. .getProperty("connection-throttle-remove-delay"));
  111.  
  112. GARBAGE_COLLECT_INTERVAL = Integer.parseInt(props
  113. .getProperty("garbage-collect-interval"));
  114. SAVE_INTERVAL = Integer.parseInt(props.getProperty("save-interval"));
  115.  
  116. DATE_FORMAT = props.getProperty("date-format");
  117.  
  118. ALERT_CONFIG = props.getProperty("alert-config");
  119. COMMAND_CONFIG = props.getProperty("command-config");
  120.  
  121. WILD_STAND_STILL_TIME = Integer.parseInt(props
  122. .getProperty("wild-stand-still-time"));
  123. WILD_LEVEL_FOR_NON_COMBAT_BONUS = Integer.parseInt(props
  124. .getProperty("wild-non-combat-min-level"));
  125. WILD_NON_COMBAT_BONUS = Double.parseDouble(props
  126. .getProperty("wild-non-combat-bonus"));
  127. WILD_COMBAT_BONUS = Double.parseDouble(props
  128. .getProperty("wild-combat-bonus"));
  129. CONGRATS_FOR_MAX_LEVEL = Boolean.parseBoolean(props
  130. .getProperty("max-level-congrats"));
  131.  
  132. props.clear();
  133.  
  134. Constants.GameServer.MOTD = "@yel@Welcome to @whi@"
  135. + Config.SERVER_NAME + "@yel@ - World @whi@"
  136. + (Config.SERVER_NUM == 0 ? 2 : Config.SERVER_NUM) + " ("
  137. + (Config.members ? "P2P" : "F2P") + ")";
  138. }
  139.  
  140. /**
  141. * Called to load RSCD_HOME and CONF_DIR Used to be situated in
  142. * PersistenceManager
  143. */
  144. private static void loadEnv() {
  145. String home = System.getenv("RSCD_HOME");
  146. if (home == null) { // the env var hasnt been set, fall back to .
  147. home = ".";
  148. }
  149. CONF_DIR = home + File.separator + "conf";
  150. RSCD_HOME = home;
  151. }
  152. }
Add Comment
Please, Sign In to add comment