2011-05-13 04:24:42 -04:00
package org.moparscape.msc.config ;
2011-04-27 01:44:26 -04:00
/ * *
* A class to handle loading configuration from XML
* /
import java.io.File ;
import java.io.FileInputStream ;
import java.io.IOException ;
import java.util.Properties ;
public class Config {
/ * *
* User info for the database
* /
public static String MYSQL_HOST ;
public static String MYSQL_DB ;
public static String MYSQL_USER ;
public static String MYSQL_PASS ;
public static String SERVER_IP , SERVER_NAME , RSCD_HOME , CONF_DIR , SERVER_LOCATION , LS_IP ;
public static int SERVER_PORT , SERVER_VERSION , MAX_PLAYERS , LS_PORT , SERVER_NUM ;
public static long START_TIME ;
2011-05-16 20:15:24 -04:00
public static boolean members , f2pWildy ;
public static double expRate , subExpRate ;
public static String [ ] pmods , mods , admins ;
2011-06-21 19:22:37 -04:00
public static String UNUSED_IP ;
2011-06-21 19:36:48 -04:00
public static int IP_BAN_REMOVAL_DELAY ;
2011-06-21 19:43:31 -04:00
public static int GARBAGE_COLLECT_INTERVAL ;
public static int SAVE_INTERVAL ;
2011-06-21 20:06:34 -04:00
public static String DATE_FORMAT ;
2011-05-16 20:15:24 -04:00
2011-04-27 01:44:26 -04:00
static {
loadEnv ( ) ;
}
/ * *
* Called to load config settings from the given file
*
* @param file
* the xml file to load settings from
* @throws IOException
* if an i / o error occurs
* /
public static void initConfig ( String file ) throws IOException {
START_TIME = System . currentTimeMillis ( ) ;
Properties props = new Properties ( ) ;
props . loadFromXML ( new FileInputStream ( file ) ) ;
SERVER_VERSION = Integer . parseInt ( props . getProperty ( " version " ) ) ;
SERVER_NAME = props . getProperty ( " name " ) ;
SERVER_IP = props . getProperty ( " ip " ) ;
SERVER_PORT = Integer . parseInt ( props . getProperty ( " port " ) ) ;
SERVER_LOCATION = props . getProperty ( " location " ) ;
MYSQL_USER = props . getProperty ( " mysqluser " ) ;
MYSQL_PASS = props . getProperty ( " mysqlpass " ) ;
MYSQL_HOST = props . getProperty ( " mysqlhost " ) ;
MYSQL_DB = props . getProperty ( " mysqldb " ) ;
MAX_PLAYERS = Integer . parseInt ( props . getProperty ( " maxplayers " ) ) ;
LS_IP = props . getProperty ( " lsip " ) ;
LS_PORT = Integer . parseInt ( props . getProperty ( " lsport " ) ) ;
SERVER_NUM = Integer . parseInt ( props . getProperty ( " servernum " ) ) ;
2011-05-16 20:15:24 -04:00
members = Boolean . parseBoolean ( props . getProperty ( " members " , " false " ) ) ;
f2pWildy = Boolean . parseBoolean ( props . getProperty ( " f2pWildy " , " true " ) ) ;
expRate = Double . parseDouble ( props . getProperty ( " expRate " ) ) ;
subExpRate = Double . parseDouble ( props . getProperty ( " subExpRate " ) ) ;
pmods = props . getProperty ( " pmods " ) . replaceAll ( " , + " , " , " ) . split ( " , " ) ;
mods = props . getProperty ( " mods " ) . replaceAll ( " , + " , " , " ) . split ( " , " ) ;
admins = props . getProperty ( " admins " ) . replaceAll ( " , + " , " , " ) . split ( " , " ) ;
2011-05-16 20:31:12 -04:00
2011-06-21 19:22:37 -04:00
UNUSED_IP = props . getProperty ( " unused-ip " ) ;
2011-06-21 19:36:48 -04:00
IP_BAN_REMOVAL_DELAY = Integer . parseInt ( props . getProperty ( " ip-ban-removal-delay " ) ) ;
2011-06-21 19:22:37 -04:00
2011-06-21 19:43:31 -04:00
GARBAGE_COLLECT_INTERVAL = Integer . parseInt ( props . getProperty ( " garbage-collect-interval " ) ) ;
SAVE_INTERVAL = Integer . parseInt ( props . getProperty ( " save-interval " ) ) ;
2011-06-21 20:06:34 -04:00
DATE_FORMAT = props . getProperty ( " date-format " ) ;
2011-04-27 01:44:26 -04:00
props . clear ( ) ;
2011-05-16 20:15:24 -04:00
Constants . GameServer . MOTD = " @yel@Welcome to @whi@ " + Config . SERVER_NAME + " @yel@ - World @whi@ " + ( Config . SERVER_NUM = = 0 ? 2 : Config . SERVER_NUM ) + " ( " + ( Config . members ? " P2P " : " F2P " ) + " ) " ;
2011-04-27 01:44:26 -04:00
}
/ * *
* Called to load RSCD_HOME and CONF_DIR Used to be situated in
* PersistenceManager
* /
private static void loadEnv ( ) {
String home = System . getenv ( " RSCD_HOME " ) ;
if ( home = = null ) { // the env var hasnt been set, fall back to .
home = " . " ;
}
CONF_DIR = home + File . separator + " conf " + File . separator + " server " ;
RSCD_HOME = home ;
}
}