Addition of ServerMode enum.

This commit is contained in:
MobiusDevelopment
2019-08-22 10:27:06 +00:00
parent 764855464a
commit ca21735a9d
163 changed files with 761 additions and 781 deletions
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -94,7 +95,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -80,7 +81,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -143,6 +144,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean PLAYER_DELEVEL; public static boolean PLAYER_DELEVEL;
public static int DELEVEL_MINIMUM; public static int DELEVEL_MINIMUM;
public static boolean DECREASE_SKILL_LEVEL; public static boolean DECREASE_SKILL_LEVEL;
@@ -1275,10 +1278,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3337,7 +3342,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -1,30 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius;
/**
* This class used to be the starter class, since LS/GS split, it only retains server mode
*/
public class Server
{
// constants for the server mode
private static final int MODE_NONE = 0;
public static final int MODE_GAMESERVER = 1;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
}
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -14,17 +14,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius; package org.l2jmobius.commons.enums;
/** /**
* This class used to be the starter class, since LS/GS split, it only retains server mode * @author Mobius
*/ */
public class Server public enum ServerMode
{ {
// constants for the server mode NONE,
public static final int MODE_NONE = 0; GAME,
public static final int MODE_GAMESERVER = 1; LOGIN;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
} }
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -176,7 +176,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -185,6 +184,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -195,8 +197,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -95,7 +96,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -80,7 +81,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -144,6 +145,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1282,10 +1285,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3354,7 +3359,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -14,17 +14,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius; package org.l2jmobius.commons.enums;
/** /**
* This class used to be the starter class, since LS/GS split, it only retains server mode * @author Mobius
*/ */
public class Server public enum ServerMode
{ {
// constants for the server mode NONE,
private static final int MODE_NONE = 0; GAME,
public static final int MODE_GAMESERVER = 1; LOGIN;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
} }
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -180,7 +180,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -189,6 +188,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -199,8 +201,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -95,7 +96,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData; import org.l2jmobius.gameserver.data.xml.impl.AbilityPointsData;
@@ -80,7 +81,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -144,6 +145,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1290,10 +1293,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3369,7 +3374,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -14,17 +14,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius; package org.l2jmobius.commons.enums;
/** /**
* This class used to be the starter class, since LS/GS split, it only retains server mode * @author Mobius
*/ */
public class Server public enum ServerMode
{ {
// constants for the server mode NONE,
private static final int MODE_NONE = 0; GAME,
public static final int MODE_GAMESERVER = 1; LOGIN;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
} }
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -180,7 +180,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -189,6 +188,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -199,8 +201,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -94,7 +95,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -79,7 +80,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -144,6 +145,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1277,10 +1280,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3343,7 +3348,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -14,17 +14,14 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius; package org.l2jmobius.commons.enums;
/** /**
* This class used to be the starter class, since LS/GS split, it only retains server mode * @author Mobius
*/ */
public class Server public enum ServerMode
{ {
// constants for the server mode NONE,
private static final int MODE_NONE = 0; GAME,
public static final int MODE_GAMESERVER = 1; LOGIN;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
} }
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -180,7 +180,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -189,6 +188,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -199,8 +201,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -95,7 +96,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -79,7 +80,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -146,6 +147,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1273,10 +1276,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3419,7 +3424,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -1,30 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius;
/**
* This class used to be the starter class, since LS/GS split, it only retains server mode
*/
public class Server
{
// constants for the server mode
private static final int MODE_NONE = 0;
public static final int MODE_GAMESERVER = 1;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
}
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.commons.enums;
/**
* @author Mobius
*/
public enum ServerMode
{
NONE,
GAME,
LOGIN;
}
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -182,7 +182,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -191,6 +190,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -201,8 +203,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -95,7 +96,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -79,7 +80,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -146,6 +147,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1273,10 +1276,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3419,7 +3424,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -1,30 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius;
/**
* This class used to be the starter class, since LS/GS split, it only retains server mode
*/
public class Server
{
// constants for the server mode
private static final int MODE_NONE = 0;
public static final int MODE_GAMESERVER = 1;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
}
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.commons.enums;
/**
* @author Mobius
*/
public enum ServerMode
{
NONE,
GAME,
LOGIN;
}
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -182,7 +182,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -191,6 +190,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -201,8 +203,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -95,7 +96,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -79,7 +80,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -146,6 +147,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1290,10 +1293,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3454,7 +3459,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -1,30 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius;
/**
* This class used to be the starter class, since LS/GS split, it only retains server mode
*/
public class Server
{
// constants for the server mode
private static final int MODE_NONE = 0;
public static final int MODE_GAMESERVER = 1;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
}
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.commons.enums;
/**
* @author Mobius
*/
public enum ServerMode
{
NONE,
GAME,
LOGIN;
}
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -183,7 +183,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -192,6 +191,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -202,8 +204,6 @@ public class GameServer
LogManager.getLogManager().readConfiguration(is); LogManager.getLogManager().readConfiguration(is);
} }
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -184,9 +184,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -37,6 +37,7 @@ import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.ClassMasterSettings; import org.l2jmobius.commons.util.ClassMasterSettings;
import org.l2jmobius.commons.util.L2Properties; import org.l2jmobius.commons.util.L2Properties;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -108,6 +109,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
public static final String EOL = System.lineSeparator(); public static final String EOL = System.lineSeparator();
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean EVERYBODY_HAS_ADMIN_RIGHTS; public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
public static int MASTERACCESS_LEVEL; public static int MASTERACCESS_LEVEL;
public static int USERACCESS_LEVEL; public static int USERACCESS_LEVEL;
@@ -3787,9 +3790,10 @@ public class Config
loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_POTION, "Potion", "4"); loadFloodProtectorConfig(properties, FLOOD_PROTECTOR_POTION, "Potion", "4");
} }
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
loadHexed(); loadHexed();
@@ -3850,7 +3854,7 @@ public class Config
loadTelnetConfig(); loadTelnetConfig();
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
loadLoginStartConfig(); loadLoginStartConfig();
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.commons.enums;
/**
* @author Mobius
*/
public enum ServerMode
{
NONE,
GAME,
LOGIN;
}
@@ -28,10 +28,10 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.crypt.nProtect; import org.l2jmobius.commons.crypt.nProtect;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.mmocore.NetcoreConfig; import org.l2jmobius.commons.mmocore.NetcoreConfig;
import org.l2jmobius.commons.mmocore.SelectorConfig; import org.l2jmobius.commons.mmocore.SelectorConfig;
import org.l2jmobius.commons.mmocore.SelectorThread; import org.l2jmobius.commons.mmocore.SelectorThread;
@@ -140,7 +140,7 @@ import org.l2jmobius.gameserver.thread.daemons.DeadlockDetector;
import org.l2jmobius.gameserver.thread.daemons.ItemsAutoDestroy; import org.l2jmobius.gameserver.thread.daemons.ItemsAutoDestroy;
import org.l2jmobius.gameserver.thread.daemons.PcPoint; import org.l2jmobius.gameserver.thread.daemons.PcPoint;
import org.l2jmobius.gameserver.ui.Gui; import org.l2jmobius.gameserver.ui.Gui;
import org.l2jmobius.status.Status; import org.l2jmobius.telnet.TelnetStatusThread;
public class GameServer public class GameServer
{ {
@@ -149,14 +149,12 @@ public class GameServer
private static SelectorThread<GameClient> _selectorThread; private static SelectorThread<GameClient> _selectorThread;
private static LoginServerThread _loginThread; private static LoginServerThread _loginThread;
private static GamePacketHandler _gamePacketHandler; private static GamePacketHandler _gamePacketHandler;
private static Status _statusServer; private static TelnetStatusThread _statusServer;
public static final Calendar dateTimeServerStarted = Calendar.getInstance(); public static final Calendar dateTimeServerStarted = Calendar.getInstance();
public static void main(String[] args) throws Exception public static void main(String[] args) throws Exception
{ {
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -164,6 +162,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Load GameServer Configs
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -176,9 +177,6 @@ public class GameServer
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
// Load GameServer Configs
Config.load();
Util.printSection("Database"); Util.printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -565,7 +563,7 @@ public class GameServer
Util.printSection("Telnet"); Util.printSection("Telnet");
if (Config.IS_TELNET_ENABLED) if (Config.IS_TELNET_ENABLED)
{ {
_statusServer = new Status(Server.serverMode); _statusServer = new TelnetStatusThread();
_statusServer.start(); _statusServer.start();
} }
else else
@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.TradeController; import org.l2jmobius.gameserver.TradeController;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.datatables.SkillTable; import org.l2jmobius.gameserver.datatables.SkillTable;
@@ -126,7 +127,7 @@ public class AdminReload implements IAdminCommandHandler
} }
else if (type.equals("configs")) else if (type.equals("configs"))
{ {
Config.load(); Config.load(ServerMode.GAME);
sendReloadPage(activeChar); sendReloadPage(activeChar);
BuilderUtil.sendSysMessage(activeChar, "Server Config Reloaded."); BuilderUtil.sendSysMessage(activeChar, "Server Config Reloaded.");
} }
@@ -168,7 +168,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -28,15 +28,15 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.mmocore.NetcoreConfig; import org.l2jmobius.commons.mmocore.NetcoreConfig;
import org.l2jmobius.commons.mmocore.SelectorConfig; import org.l2jmobius.commons.mmocore.SelectorConfig;
import org.l2jmobius.commons.mmocore.SelectorThread; import org.l2jmobius.commons.mmocore.SelectorThread;
import org.l2jmobius.loginserver.network.gameserverpackets.ServerStatus; import org.l2jmobius.loginserver.network.gameserverpackets.ServerStatus;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
import org.l2jmobius.status.Status; import org.l2jmobius.telnet.TelnetStatusThread;
public class LoginServer public class LoginServer
{ {
@@ -46,7 +46,7 @@ public class LoginServer
private static LoginServer INSTANCE; private static LoginServer INSTANCE;
private GameServerListener _gameServerListener; private GameServerListener _gameServerListener;
private SelectorThread<LoginClient> _selectorThread; private SelectorThread<LoginClient> _selectorThread;
private Status _statusServer; private TelnetStatusThread _statusServer;
private static int _loginStatus = ServerStatus.STATUS_NORMAL; private static int _loginStatus = ServerStatus.STATUS_NORMAL;
public static void main(String[] args) public static void main(String[] args)
@@ -61,8 +61,6 @@ public class LoginServer
public LoginServer() public LoginServer()
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -70,6 +68,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load LoginServer Configs
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -85,9 +86,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load LoginServer Configs
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -133,7 +131,7 @@ public class LoginServer
{ {
try try
{ {
_statusServer = new Status(Server.serverMode); _statusServer = new TelnetStatusThread();
_statusServer.start(); _statusServer.start();
} }
catch (IOException e) catch (IOException e)
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius.status; package org.l2jmobius.telnet;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius.status; package org.l2jmobius.telnet;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.l2jmobius.status; package org.l2jmobius.telnet;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@@ -28,20 +28,19 @@ import java.util.Properties;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.Rnd; import org.l2jmobius.commons.util.Rnd;
public class Status extends Thread public class TelnetStatusThread extends Thread
{ {
protected static final Logger LOGGER = Logger.getLogger(Status.class.getName()); protected static final Logger LOGGER = Logger.getLogger(TelnetStatusThread.class.getName());
private final ServerSocket statusServerSocket; private final ServerSocket statusServerSocket;
private final int _uptime; private final int _uptime;
private final int _statusPort; private final int _statusPort;
private String _statusPw; private String _statusPw;
private final int _mode;
private final List<LoginStatusThread> _loginStatus; private final List<LoginStatusThread> _loginStatus;
@Override @Override
@@ -55,7 +54,7 @@ public class Status extends Thread
{ {
final Socket connection = statusServerSocket.accept(); final Socket connection = statusServerSocket.accept();
if (_mode == Server.MODE_GAMESERVER) if (Config.SERVER_MODE == ServerMode.GAME)
{ {
final GameStatusThread gst = new GameStatusThread(connection, _uptime, _statusPw); final GameStatusThread gst = new GameStatusThread(connection, _uptime, _statusPw);
if (!connection.isClosed()) if (!connection.isClosed())
@@ -63,7 +62,7 @@ public class Status extends Thread
ThreadPool.execute(gst); ThreadPool.execute(gst);
} }
} }
else if (_mode == Server.MODE_LOGINSERVER) else if (Config.SERVER_MODE == ServerMode.LOGIN)
{ {
final LoginStatusThread lst = new LoginStatusThread(connection, _uptime, _statusPw); final LoginStatusThread lst = new LoginStatusThread(connection, _uptime, _statusPw);
if (!connection.isClosed()) if (!connection.isClosed())
@@ -103,10 +102,9 @@ public class Status extends Thread
} }
} }
public Status(int mode) throws IOException public TelnetStatusThread() throws IOException
{ {
super("Status"); super("Status");
_mode = mode;
final Properties telnetSettings = new Properties(); final Properties telnetSettings = new Properties();
final InputStream is = new FileInputStream(new File(Config.TELNET_CONFIG_FILE)); final InputStream is = new FileInputStream(new File(Config.TELNET_CONFIG_FILE));
telnetSettings.load(is); telnetSettings.load(is);
@@ -115,7 +113,7 @@ public class Status extends Thread
_statusPort = Integer.parseInt(telnetSettings.getProperty("StatusPort", "12345")); _statusPort = Integer.parseInt(telnetSettings.getProperty("StatusPort", "12345"));
_statusPw = telnetSettings.getProperty("StatusPW"); _statusPw = telnetSettings.getProperty("StatusPW");
if ((_mode == Server.MODE_GAMESERVER) || (_mode == Server.MODE_LOGINSERVER)) if ((Config.SERVER_MODE == ServerMode.GAME) || (Config.SERVER_MODE == ServerMode.LOGIN))
{ {
if (_statusPw == null) if (_statusPw == null)
{ {
@@ -126,6 +124,7 @@ public class Status extends Thread
} }
LOGGER.info("Telnet StatusServer started successfully, listening on Port: " + _statusPort); LOGGER.info("Telnet StatusServer started successfully, listening on Port: " + _statusPort);
} }
statusServerSocket = new ServerSocket(_statusPort); statusServerSocket = new ServerSocket(_statusPort);
_uptime = (int) System.currentTimeMillis(); _uptime = (int) System.currentTimeMillis();
_loginStatus = new ArrayList<>(); _loginStatus = new ArrayList<>();
@@ -30,8 +30,8 @@ import java.util.Base64;
import java.util.List; import java.util.List;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -47,8 +47,7 @@ public class SQLAccountManager
public static void main(String[] args) throws SQLException, IOException, NoSuchAlgorithmException public static void main(String[] args) throws SQLException, IOException, NoSuchAlgorithmException
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
while (true) while (true)
@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.Util; import org.l2jmobius.commons.util.Util;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -66,9 +66,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.sql.impl.TeleportLocationTable; import org.l2jmobius.gameserver.data.sql.impl.TeleportLocationTable;
@@ -87,7 +88,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -74,7 +75,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return "Telnet Admin: Reloaded Configs."; return "Telnet Admin: Reloaded Configs.";
} }
case "access": case "access":
@@ -55,6 +55,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.gameserver.enums.ChatType; import org.l2jmobius.gameserver.enums.ChatType;
@@ -143,6 +144,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean PLAYER_DELEVEL; public static boolean PLAYER_DELEVEL;
public static boolean DECREASE_SKILL_LEVEL; public static boolean DECREASE_SKILL_LEVEL;
public static double ALT_WEIGHT_LIMIT; public static double ALT_WEIGHT_LIMIT;
@@ -1340,10 +1343,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in config file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (config file) for configuring your server. * If the key doesn't appear in config file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (config file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3329,7 +3334,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);
@@ -1,30 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius;
/**
* This class used to be the starter class, since LS/GS split, it only retains server mode
*/
public class Server
{
// constants for the server mode
private static final int MODE_NONE = 0;
public static final int MODE_GAMESERVER = 1;
public static final int MODE_LOGINSERVER = 2;
public static int serverMode = MODE_NONE;
}
@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server; import org.l2jmobius.commons.enums.ServerMode;
/** /**
* @author Mobius * @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : ""; final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
try try
{ {
final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Server.serverMode == Server.MODE_GAMESERVER ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date())); final Process process = Runtime.getRuntime().exec(mysqldumpPath + "mysqldump -u " + Config.DATABASE_LOGIN + (Config.DATABASE_PASSWORD.trim().isEmpty() ? "" : " -p" + Config.DATABASE_PASSWORD) + " " + Config.DATABASE_URL.replace("jdbc:mariadb://", "").replaceAll(".*\\/|\\?.*", "") + " -r " + Config.BACKUP_PATH + (Config.SERVER_MODE == ServerMode.GAME ? "game" : "login") + new SimpleDateFormat("_yyyy_MM_dd_HH_mm'.sql'").format(new Date()));
process.waitFor(); process.waitFor();
} }
catch (Exception e) catch (Exception e)
@@ -0,0 +1,27 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.commons.enums;
/**
* @author Mobius
*/
public enum ServerMode
{
NONE,
GAME,
LOGIN;
}
@@ -29,9 +29,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool; import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.DeadLockDetector; import org.l2jmobius.commons.util.DeadLockDetector;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable; import org.l2jmobius.gameserver.data.sql.impl.AnnouncementsTable;
@@ -174,7 +174,6 @@ public class GameServer
public GameServer() throws Exception public GameServer() throws Exception
{ {
final long serverLoadStart = System.currentTimeMillis(); final long serverLoadStart = System.currentTimeMillis();
Server.serverMode = Server.MODE_GAMESERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
@@ -183,6 +182,9 @@ public class GameServer
new Gui(); new Gui();
} }
// Initialize config
Config.load(ServerMode.GAME);
// Create log folder // Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log"); final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -195,8 +197,6 @@ public class GameServer
new File("log/game").mkdirs(); new File("log/game").mkdirs();
// Initialize config
Config.load();
printSection("Database"); printSection("Database");
DatabaseFactory.init(); DatabaseFactory.init();
@@ -169,7 +169,7 @@ public class Gui
{ {
if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0) if (JOptionPane.showOptionDialog(null, "Reload configs?", "Select an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, confirmOptions, confirmOptions[1]) == 0)
{ {
Config.load(); Config.load(Config.SERVER_MODE);
} }
}); });
mnReload.add(mntmConfigs); mnReload.add(mntmConfigs);
@@ -30,9 +30,9 @@ import java.util.logging.LogManager;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup; import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus; import org.l2jmobius.gameserver.network.loginserverpackets.game.ServerStatus;
import org.l2jmobius.loginserver.network.ClientNetworkManager; import org.l2jmobius.loginserver.network.ClientNetworkManager;
import org.l2jmobius.loginserver.ui.Gui; import org.l2jmobius.loginserver.ui.Gui;
@@ -62,8 +62,6 @@ public class LoginServer
private LoginServer() throws Exception private LoginServer() throws Exception
{ {
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI // GUI
if (!GraphicsEnvironment.isHeadless()) if (!GraphicsEnvironment.isHeadless())
{ {
@@ -71,6 +69,9 @@ public class LoginServer
new Gui(); new Gui();
} }
// Load Config
Config.load(ServerMode.LOGIN);
// Create log folder // Create log folder
final File logFolder = new File(".", "log"); final File logFolder = new File(".", "log");
logFolder.mkdir(); logFolder.mkdir();
@@ -86,9 +87,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage()); LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
} }
// Load Config
Config.load();
// Prepare Database // Prepare Database
DatabaseFactory.init(); DatabaseFactory.init();
@@ -25,8 +25,8 @@ import java.util.Base64;
import java.util.Scanner; import java.util.Scanner;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/** /**
* This class SQL Account Manager * This class SQL Account Manager
@@ -41,8 +41,7 @@ public class SQLAccountManager
public static void main(String[] args) public static void main(String[] args)
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
try (Scanner _scn = new Scanner(System.in)) try (Scanner _scn = new Scanner(System.in))
@@ -30,8 +30,8 @@ import java.util.Properties;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory; import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.CommonUtil; import org.l2jmobius.commons.util.CommonUtil;
import org.l2jmobius.loginserver.GameServerTable; import org.l2jmobius.loginserver.GameServerTable;
@@ -65,9 +65,7 @@ public abstract class BaseGameServerRegister
*/ */
public void load() public void load()
{ {
Server.serverMode = Server.MODE_LOGINSERVER; Config.load(ServerMode.LOGIN);
Config.load();
DatabaseFactory.init(); DatabaseFactory.init();
GameServerTable.getInstance(); GameServerTable.getInstance();
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -94,7 +95,7 @@ public class AdminReload implements IAdminCommandHandler
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs."); AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Configs.");
break; break;
} }
@@ -22,6 +22,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.l2jmobius.Config; import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.cache.HtmCache; import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.data.sql.impl.CrestTable; import org.l2jmobius.gameserver.data.sql.impl.CrestTable;
import org.l2jmobius.gameserver.data.xml.impl.AdminData; import org.l2jmobius.gameserver.data.xml.impl.AdminData;
@@ -79,7 +80,7 @@ public class Reload implements ITelnetCommand
{ {
case "config": case "config":
{ {
Config.load(); Config.load(ServerMode.GAME);
return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs."); return AdminData.getInstance().broadcastMessageToGMs("Telnet Admin: Reloaded Configs.");
} }
case "access": case "access":
@@ -56,6 +56,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.l2jmobius.commons.enums.IdFactoryType; import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.IXmlReader; import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.commons.util.PropertiesParser; import org.l2jmobius.commons.util.PropertiesParser;
import org.l2jmobius.commons.util.StringUtil; import org.l2jmobius.commons.util.StringUtil;
@@ -145,6 +146,8 @@ public class Config
// -------------------------------------------------- // --------------------------------------------------
// Variable Definitions // Variable Definitions
// -------------------------------------------------- // --------------------------------------------------
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean ENABLE_ATTENDANCE_REWARDS; public static boolean ENABLE_ATTENDANCE_REWARDS;
public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS; public static boolean PREMIUM_ONLY_ATTENDANCE_REWARDS;
public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT; public static boolean ATTENDANCE_REWARDS_SHARE_ACCOUNT;
@@ -1215,10 +1218,12 @@ public class Config
/** /**
* This class initializes all global variables for configuration.<br> * This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server. * If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
* @param serverMode
*/ */
public static void load() public static void load(ServerMode serverMode)
{ {
if (Server.serverMode == Server.MODE_GAMESERVER) SERVER_MODE = serverMode;
if (SERVER_MODE == ServerMode.GAME)
{ {
FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector"); FLOOD_PROTECTOR_USE_ITEM = new FloodProtectorConfig("UseItemFloodProtector");
FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector"); FLOOD_PROTECTOR_ROLL_DICE = new FloodProtectorConfig("RollDiceFloodProtector");
@@ -3216,7 +3221,7 @@ public class Config
L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false); L2WALKER_PROTECTION = WalkerBotProtection.getBoolean("L2WalkerProtection", false);
} }
else if (Server.serverMode == Server.MODE_LOGINSERVER) else if (SERVER_MODE == ServerMode.LOGIN)
{ {
final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE); final PropertiesParser ServerSettings = new PropertiesParser(LOGIN_CONFIG_FILE);

Some files were not shown because too many files have changed in this diff Show More