Riizade/config file (#520)
* added POJO + yaml file * made config members public * switched to yaml * modified files to use YamlConfig over ServerConstants * removed constants from ServerConstants * removed unused imports * removed unused import * removed world ini * removed now unused .ini files * fixed docker-launch.sh * added jackson dependency JARs * fixed errors * removed unused server config values, added world defaults * don't use env variables for docker * fixed package imports/specifiers for js files
This commit is contained in:
committed by
Ronan Lana
parent
e169971384
commit
181573dc74
@@ -46,6 +46,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
|
||||
|
||||
import config.YamlConfig;
|
||||
import net.server.audit.ThreadTracker;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReentrantReadWriteLock;
|
||||
@@ -170,7 +171,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public void updateCurrentTime() {
|
||||
serverCurrentTime = currentTime.addAndGet(ServerConstants.UPDATE_INTERVAL);
|
||||
serverCurrentTime = currentTime.addAndGet(YamlConfig.config.server.UPDATE_INTERVAL);
|
||||
}
|
||||
|
||||
public long forceUpdateCurrentTime() {
|
||||
@@ -342,18 +343,13 @@ public class Server {
|
||||
if(worldChannels == null) return -3;
|
||||
|
||||
int channelid = worldChannels.size();
|
||||
if(channelid >= ServerConstants.CHANNEL_SIZE) return -2;
|
||||
|
||||
Properties p = loadWorldINI();
|
||||
if(p == null) {
|
||||
return -1;
|
||||
}
|
||||
if(channelid >= YamlConfig.config.server.CHANNEL_SIZE) return -2;
|
||||
|
||||
channelid++;
|
||||
World world = this.getWorld(worldid);
|
||||
Channel channel = new Channel(worldid, channelid, getCurrentTime());
|
||||
|
||||
channel.setServerMessage(p.getProperty("whyamirecommended" + worldid));
|
||||
|
||||
channel.setServerMessage(YamlConfig.config.worlds.get(worldid).why_am_i_recommended);
|
||||
|
||||
world.addChannel(channel);
|
||||
worldChannels.put(channelid, channel.getIP());
|
||||
@@ -365,10 +361,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public int addWorld() {
|
||||
Properties p = loadWorldINI();
|
||||
if(p == null) return -2;
|
||||
|
||||
int newWorld = initWorld(p);
|
||||
int newWorld = initWorld();
|
||||
if(newWorld > -1) {
|
||||
installWorldPlayerRanking(newWorld);
|
||||
|
||||
@@ -388,40 +381,40 @@ public class Server {
|
||||
return newWorld;
|
||||
}
|
||||
|
||||
private static int getWorldProperty(Properties p, String property, int wid, int defaultValue) {
|
||||
String content = p.getProperty(property + wid);
|
||||
return content != null ? Integer.parseInt(content) : defaultValue;
|
||||
}
|
||||
|
||||
private int initWorld(Properties p) {
|
||||
private int initWorld() {
|
||||
wldWLock.lock();
|
||||
try {
|
||||
int i = worlds.size();
|
||||
|
||||
if(i >= ServerConstants.WLDLIST_SIZE) {
|
||||
if(i >= YamlConfig.config.server.WLDLIST_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
System.out.println("Starting world " + i);
|
||||
int exprate = getWorldProperty(p, "exprate", i, ServerConstants.EXP_RATE);
|
||||
int mesorate = getWorldProperty(p, "mesorate", i, ServerConstants.MESO_RATE);
|
||||
int droprate = getWorldProperty(p, "droprate", i, ServerConstants.DROP_RATE);
|
||||
int bossdroprate = getWorldProperty(p, "bossdroprate", i, ServerConstants.BOSS_DROP_RATE);
|
||||
int questrate = getWorldProperty(p, "questrate", i, ServerConstants.QUEST_RATE);
|
||||
int travelrate = getWorldProperty(p, "travelrate", i, ServerConstants.TRAVEL_RATE);
|
||||
int fishingrate = getWorldProperty(p, "fishrate", i, ServerConstants.FISHING_RATE);
|
||||
|
||||
int exprate = YamlConfig.config.worlds.get(i).exp_rate;
|
||||
int mesorate = YamlConfig.config.worlds.get(i).meso_rate;
|
||||
int droprate = YamlConfig.config.worlds.get(i).drop_rate;
|
||||
int bossdroprate = YamlConfig.config.worlds.get(i).boss_drop_rate;
|
||||
int questrate = YamlConfig.config.worlds.get(i).quest_rate;
|
||||
int travelrate = YamlConfig.config.worlds.get(i).travel_rate;
|
||||
int fishingrate = YamlConfig.config.worlds.get(i).fishing_rate;
|
||||
|
||||
int flag = YamlConfig.config.worlds.get(i).flag;
|
||||
String event_message = YamlConfig.config.worlds.get(i).event_message;
|
||||
String why_am_i_recommended = YamlConfig.config.worlds.get(i).why_am_i_recommended;
|
||||
|
||||
World world = new World(i,
|
||||
Integer.parseInt(p.getProperty("flag" + i)),
|
||||
p.getProperty("eventmessage" + i),
|
||||
flag,
|
||||
event_message,
|
||||
exprate, droprate, bossdroprate, mesorate, questrate, travelrate, fishingrate);
|
||||
|
||||
worldRecommendedList.add(new Pair<>(i, p.getProperty("whyamirecommended" + i)));
|
||||
worldRecommendedList.add(new Pair<>(i, why_am_i_recommended));
|
||||
worlds.add(world);
|
||||
|
||||
Map<Integer, String> channelInfo = new HashMap<>();
|
||||
long bootTime = getCurrentTime();
|
||||
for (int j = 1; j <= Integer.parseInt(p.getProperty("channels" + i)); j++) {
|
||||
for (int j = 1; j <= YamlConfig.config.worlds.get(i).channels; j++) {
|
||||
int channelid = j;
|
||||
Channel channel = new Channel(i, channelid, bootTime);
|
||||
|
||||
@@ -431,7 +424,7 @@ public class Server {
|
||||
|
||||
channels.add(i, channelInfo);
|
||||
|
||||
world.setServerMessage(p.getProperty("servermessage" + i));
|
||||
world.setServerMessage(YamlConfig.config.worlds.get(i).server_message);
|
||||
System.out.println("Finished loading world " + i + "\r\n");
|
||||
|
||||
return i;
|
||||
@@ -511,18 +504,6 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
public static Properties loadWorldINI() {
|
||||
Properties p = new Properties();
|
||||
try {
|
||||
p.load(new FileInputStream("world.ini"));
|
||||
return p;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("[SEVERE] Could not find/open 'world.ini'.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static long getTimeLeftForNextHour() {
|
||||
Calendar nextHour = Calendar.getInstance();
|
||||
nextHour.add(Calendar.HOUR, 1);
|
||||
@@ -547,7 +528,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public static void cleanNxcodeCoupons(Connection con) throws SQLException {
|
||||
if (!ServerConstants.USE_CLEAR_OUTDATED_COUPONS) return;
|
||||
if (!YamlConfig.config.server.USE_CLEAR_OUTDATED_COUPONS) return;
|
||||
|
||||
long timeClear = System.currentTimeMillis() - 14 * 24 * 60 * 60 * 1000;
|
||||
|
||||
@@ -705,7 +686,7 @@ public class Server {
|
||||
public List<Pair<String, Integer>> getWorldPlayerRanking(int worldid) {
|
||||
wldRLock.lock();
|
||||
try {
|
||||
return new ArrayList<>(playerRanking.get(!ServerConstants.USE_WHOLE_SERVER_RANKING ? worldid : 0));
|
||||
return new ArrayList<>(playerRanking.get(!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? worldid : 0));
|
||||
} finally {
|
||||
wldRLock.unlock();
|
||||
}
|
||||
@@ -716,7 +697,7 @@ public class Server {
|
||||
if(!ranking.isEmpty()) {
|
||||
wldWLock.lock();
|
||||
try {
|
||||
if (!ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
for(int i = playerRanking.size(); i <= worldid; i++) {
|
||||
playerRanking.add(new ArrayList<Pair<String, Integer>>(0));
|
||||
}
|
||||
@@ -732,7 +713,7 @@ public class Server {
|
||||
}
|
||||
|
||||
private void removeWorldPlayerRanking() {
|
||||
if (!ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
wldWLock.lock();
|
||||
try {
|
||||
if(playerRanking.size() < this.getWorldsSize()) {
|
||||
@@ -760,7 +741,7 @@ public class Server {
|
||||
if(!rankUpdates.isEmpty()) {
|
||||
wldWLock.lock();
|
||||
try {
|
||||
if (!ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
for(int i = playerRanking.size(); i <= rankUpdates.get(rankUpdates.size() - 1).getLeft(); i++) {
|
||||
playerRanking.add(new ArrayList<Pair<String, Integer>>(0));
|
||||
}
|
||||
@@ -778,7 +759,7 @@ public class Server {
|
||||
}
|
||||
|
||||
private void initWorldPlayerRanking() {
|
||||
if (ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
playerRanking.add(new ArrayList<Pair<String, Integer>>(0));
|
||||
}
|
||||
updateWorldPlayerRanking();
|
||||
@@ -795,7 +776,7 @@ public class Server {
|
||||
con = DatabaseConnection.getConnection();
|
||||
|
||||
String worldQuery;
|
||||
if (!ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
if(worldid >= 0) {
|
||||
worldQuery = (" AND `characters`.`world` = " + worldid);
|
||||
} else {
|
||||
@@ -805,10 +786,10 @@ public class Server {
|
||||
worldQuery = (" AND `characters`.`world` >= 0 AND `characters`.`world` <= " + Math.abs(worldid));
|
||||
}
|
||||
|
||||
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!ServerConstants.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
||||
ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
||||
rs = ps.executeQuery();
|
||||
|
||||
if (!ServerConstants.USE_WHOLE_SERVER_RANKING) {
|
||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||
int currentWorld = -1;
|
||||
while(rs.next()) {
|
||||
int rsWorld = rs.getInt("world");
|
||||
@@ -854,17 +835,12 @@ public class Server {
|
||||
}
|
||||
|
||||
public void init() {
|
||||
Properties p = loadWorldINI();
|
||||
if(p == null) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
System.out.println("HeavenMS v" + ServerConstants.VERSION + " starting up.\r\n");
|
||||
|
||||
if(ServerConstants.SHUTDOWNHOOK)
|
||||
if(YamlConfig.config.server.SHUTDOWNHOOK)
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
|
||||
|
||||
TimeZone.setDefault(TimeZone.getTimeZone(ServerConstants.TIMEZONE));
|
||||
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
||||
|
||||
Connection c = null;
|
||||
try {
|
||||
@@ -897,21 +873,21 @@ public class Server {
|
||||
ThreadManager.getInstance().start();
|
||||
TimerManager tMan = TimerManager.getInstance();
|
||||
tMan.start();
|
||||
tMan.register(tMan.purge(), ServerConstants.PURGING_INTERVAL);//Purging ftw...
|
||||
tMan.register(tMan.purge(), YamlConfig.config.server.PURGING_INTERVAL);//Purging ftw...
|
||||
disconnectIdlesOnLoginTask();
|
||||
|
||||
long timeLeft = getTimeLeftForNextHour();
|
||||
tMan.register(new CharacterDiseaseWorker(), ServerConstants.UPDATE_INTERVAL, ServerConstants.UPDATE_INTERVAL);
|
||||
tMan.register(new CharacterDiseaseWorker(), YamlConfig.config.server.UPDATE_INTERVAL, YamlConfig.config.server.UPDATE_INTERVAL);
|
||||
tMan.register(new ReleaseLockWorker(), 2 * 60 * 1000, 2 * 60 * 1000);
|
||||
tMan.register(new CouponWorker(), ServerConstants.COUPON_INTERVAL, timeLeft);
|
||||
tMan.register(new CouponWorker(), YamlConfig.config.server.COUPON_INTERVAL, timeLeft);
|
||||
tMan.register(new RankingCommandWorker(), 5 * 60 * 1000, 5 * 60 * 1000);
|
||||
tMan.register(new RankingLoginWorker(), ServerConstants.RANKING_INTERVAL, timeLeft);
|
||||
tMan.register(new RankingLoginWorker(), YamlConfig.config.server.RANKING_INTERVAL, timeLeft);
|
||||
tMan.register(new LoginCoordinatorWorker(), 60 * 60 * 1000, timeLeft);
|
||||
tMan.register(new EventRecallCoordinatorWorker(), 60 * 60 * 1000, timeLeft);
|
||||
tMan.register(new LoginStorageWorker(), 2 * 60 * 1000, 2 * 60 * 1000);
|
||||
tMan.register(new DueyFredrickWorker(), 60 * 60 * 1000, timeLeft);
|
||||
tMan.register(new InvitationWorker(), 30 * 1000, 30 * 1000);
|
||||
tMan.register(new RespawnWorker(), ServerConstants.RESPAWN_INTERVAL, ServerConstants.RESPAWN_INTERVAL);
|
||||
tMan.register(new RespawnWorker(), YamlConfig.config.server.RESPAWN_INTERVAL, YamlConfig.config.server.RESPAWN_INTERVAL);
|
||||
|
||||
timeLeft = getTimeLeftForNextDay();
|
||||
MapleExpeditionBossLog.resetBossLogTable();
|
||||
@@ -932,13 +908,13 @@ public class Server {
|
||||
|
||||
NewYearCardRecord.startPendingNewYearCardRequests();
|
||||
|
||||
if(ServerConstants.USE_THREAD_TRACKER) ThreadTracker.getInstance().registerThreadTrackerTask();
|
||||
if(YamlConfig.config.server.USE_THREAD_TRACKER) ThreadTracker.getInstance().registerThreadTrackerTask();
|
||||
|
||||
try {
|
||||
Integer worldCount = Math.min(GameConstants.WORLD_NAMES.length, Integer.parseInt(p.getProperty("worlds")));
|
||||
Integer worldCount = Math.min(GameConstants.WORLD_NAMES.length, YamlConfig.config.worlds.size());
|
||||
|
||||
for (int i = 0; i < worldCount; i++) {
|
||||
initWorld(p);
|
||||
initWorld();
|
||||
}
|
||||
initWorldPlayerRanking();
|
||||
|
||||
@@ -952,7 +928,7 @@ public class Server {
|
||||
|
||||
System.out.println();
|
||||
|
||||
if(ServerConstants.USE_FAMILY_SYSTEM) {
|
||||
if(YamlConfig.config.server.USE_FAMILY_SYSTEM) {
|
||||
timeToTake = System.currentTimeMillis();
|
||||
MapleFamily.loadAllFamilies();
|
||||
System.out.println("Families loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
|
||||
@@ -1767,7 +1743,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public boolean validateCharacteridInTransition(IoSession session, int charId) {
|
||||
if (!ServerConstants.USE_IP_VALIDATION) {
|
||||
if (!YamlConfig.config.server.USE_IP_VALIDATION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1783,7 +1759,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public Integer freeCharacteridInTransition(IoSession session) {
|
||||
if (!ServerConstants.USE_IP_VALIDATION) {
|
||||
if (!YamlConfig.config.server.USE_IP_VALIDATION) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1798,7 +1774,7 @@ public class Server {
|
||||
}
|
||||
|
||||
public boolean hasCharacteridInTransition(IoSession session) {
|
||||
if (!ServerConstants.USE_IP_VALIDATION) {
|
||||
if (!YamlConfig.config.server.USE_IP_VALIDATION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1905,7 +1881,7 @@ public class Server {
|
||||
|
||||
List<Channel> allChannels = getAllChannels();
|
||||
|
||||
if(ServerConstants.USE_THREAD_TRACKER) ThreadTracker.getInstance().cancelThreadTrackerTask();
|
||||
if(YamlConfig.config.server.USE_THREAD_TRACKER) ThreadTracker.getInstance().cancelThreadTrackerTask();
|
||||
|
||||
for (Channel ch : allChannels) {
|
||||
while (!ch.finishedShutdown()) {
|
||||
|
||||
Reference in New Issue
Block a user