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

View File

@@ -37,6 +37,7 @@ import java.util.Properties;
import java.util.logging.Logger;
import org.l2jmobius.commons.enums.IdFactoryType;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.ClassMasterSettings;
import org.l2jmobius.commons.util.L2Properties;
import org.l2jmobius.commons.util.StringUtil;
@@ -108,6 +109,8 @@ public class Config
// --------------------------------------------------
public static final String EOL = System.lineSeparator();
public static ServerMode SERVER_MODE = ServerMode.NONE;
public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
public static int MASTERACCESS_LEVEL;
public static int USERACCESS_LEVEL;
@@ -3787,9 +3790,10 @@ public class Config
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();
@@ -3850,7 +3854,7 @@ public class Config
loadTelnetConfig();
}
else if (Server.serverMode == Server.MODE_LOGINSERVER)
else if (SERVER_MODE == ServerMode.LOGIN)
{
loadLoginStartConfig();

View File

@@ -26,7 +26,7 @@ import java.util.Date;
import java.util.concurrent.TimeUnit;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.enums.ServerMode;
/**
* @author Mobius
@@ -72,7 +72,7 @@ public class DatabaseBackup
final String mysqldumpPath = System.getProperty("os.name").toLowerCase().contains("win") ? Config.MYSQL_BIN_PATH : "";
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();
}
catch (Exception e)

View File

@@ -1,30 +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;
/**
* 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
public 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;
}
/*
* 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;
}

View File

@@ -28,10 +28,10 @@ import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.crypt.nProtect;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.mmocore.NetcoreConfig;
import org.l2jmobius.commons.mmocore.SelectorConfig;
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.PcPoint;
import org.l2jmobius.gameserver.ui.Gui;
import org.l2jmobius.status.Status;
import org.l2jmobius.telnet.TelnetStatusThread;
public class GameServer
{
@@ -149,14 +149,12 @@ public class GameServer
private static SelectorThread<GameClient> _selectorThread;
private static LoginServerThread _loginThread;
private static GamePacketHandler _gamePacketHandler;
private static Status _statusServer;
private static TelnetStatusThread _statusServer;
public static final Calendar dateTimeServerStarted = Calendar.getInstance();
public static void main(String[] args) throws Exception
{
Server.serverMode = Server.MODE_GAMESERVER;
// GUI
if (!GraphicsEnvironment.isHeadless())
{
@@ -164,6 +162,9 @@ public class GameServer
new Gui();
}
// Load GameServer Configs
Config.load(ServerMode.GAME);
// Create log folder
final File logFolder = new File(Config.DATAPACK_ROOT, "log");
logFolder.mkdir();
@@ -176,9 +177,6 @@ public class GameServer
final long serverLoadStart = System.currentTimeMillis();
// Load GameServer Configs
Config.load();
Util.printSection("Database");
DatabaseFactory.init();
@@ -565,7 +563,7 @@ public class GameServer
Util.printSection("Telnet");
if (Config.IS_TELNET_ENABLED)
{
_statusServer = new Status(Server.serverMode);
_statusServer = new TelnetStatusThread();
_statusServer.start();
}
else

View File

@@ -19,6 +19,7 @@ package org.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.StringTokenizer;
import org.l2jmobius.Config;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.gameserver.TradeController;
import org.l2jmobius.gameserver.cache.HtmCache;
import org.l2jmobius.gameserver.datatables.SkillTable;
@@ -126,7 +127,7 @@ public class AdminReload implements IAdminCommandHandler
}
else if (type.equals("configs"))
{
Config.load();
Config.load(ServerMode.GAME);
sendReloadPage(activeChar);
BuilderUtil.sendSysMessage(activeChar, "Server Config Reloaded.");
}

View File

@@ -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)
{
Config.load();
Config.load(Config.SERVER_MODE);
}
});
mnReload.add(mntmConfigs);

View File

@@ -28,15 +28,15 @@ import java.util.logging.LogManager;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseBackup;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.mmocore.NetcoreConfig;
import org.l2jmobius.commons.mmocore.SelectorConfig;
import org.l2jmobius.commons.mmocore.SelectorThread;
import org.l2jmobius.loginserver.network.gameserverpackets.ServerStatus;
import org.l2jmobius.loginserver.ui.Gui;
import org.l2jmobius.status.Status;
import org.l2jmobius.telnet.TelnetStatusThread;
public class LoginServer
{
@@ -46,7 +46,7 @@ public class LoginServer
private static LoginServer INSTANCE;
private GameServerListener _gameServerListener;
private SelectorThread<LoginClient> _selectorThread;
private Status _statusServer;
private TelnetStatusThread _statusServer;
private static int _loginStatus = ServerStatus.STATUS_NORMAL;
public static void main(String[] args)
@@ -61,8 +61,6 @@ public class LoginServer
public LoginServer()
{
Server.serverMode = Server.MODE_LOGINSERVER;
// GUI
if (!GraphicsEnvironment.isHeadless())
{
@@ -70,6 +68,9 @@ public class LoginServer
new Gui();
}
// Load LoginServer Configs
Config.load(ServerMode.LOGIN);
// Create log folder
final File logFolder = new File(".", "log");
logFolder.mkdir();
@@ -85,9 +86,6 @@ public class LoginServer
LOGGER.warning(getClass().getSimpleName() + ": " + e.getMessage());
}
// Load LoginServer Configs
Config.load();
// Prepare Database
DatabaseFactory.init();
@@ -133,7 +131,7 @@ public class LoginServer
{
try
{
_statusServer = new Status(Server.serverMode);
_statusServer = new TelnetStatusThread();
_statusServer.start();
}
catch (IOException e)

View File

@@ -14,7 +14,7 @@
* 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.status;
package org.l2jmobius.telnet;
import java.io.BufferedReader;
import java.io.File;

View File

@@ -14,7 +14,7 @@
* 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.status;
package org.l2jmobius.telnet;
import java.io.BufferedReader;
import java.io.File;

View File

@@ -14,7 +14,7 @@
* 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.status;
package org.l2jmobius.telnet;
import java.io.File;
import java.io.FileInputStream;
@@ -28,20 +28,19 @@ import java.util.Properties;
import java.util.logging.Logger;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.enums.ServerMode;
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 int _uptime;
private final int _statusPort;
private String _statusPw;
private final int _mode;
private final List<LoginStatusThread> _loginStatus;
@Override
@@ -55,7 +54,7 @@ public class Status extends Thread
{
final Socket connection = statusServerSocket.accept();
if (_mode == Server.MODE_GAMESERVER)
if (Config.SERVER_MODE == ServerMode.GAME)
{
final GameStatusThread gst = new GameStatusThread(connection, _uptime, _statusPw);
if (!connection.isClosed())
@@ -63,7 +62,7 @@ public class Status extends Thread
ThreadPool.execute(gst);
}
}
else if (_mode == Server.MODE_LOGINSERVER)
else if (Config.SERVER_MODE == ServerMode.LOGIN)
{
final LoginStatusThread lst = new LoginStatusThread(connection, _uptime, _statusPw);
if (!connection.isClosed())
@@ -103,10 +102,9 @@ public class Status extends Thread
}
}
public Status(int mode) throws IOException
public TelnetStatusThread() throws IOException
{
super("Status");
_mode = mode;
final Properties telnetSettings = new Properties();
final InputStream is = new FileInputStream(new File(Config.TELNET_CONFIG_FILE));
telnetSettings.load(is);
@@ -115,7 +113,7 @@ public class Status extends Thread
_statusPort = Integer.parseInt(telnetSettings.getProperty("StatusPort", "12345"));
_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)
{
@@ -126,6 +124,7 @@ public class Status extends Thread
}
LOGGER.info("Telnet StatusServer started successfully, listening on Port: " + _statusPort);
}
statusServerSocket = new ServerSocket(_statusPort);
_uptime = (int) System.currentTimeMillis();
_loginStatus = new ArrayList<>();

View File

@@ -30,8 +30,8 @@ import java.util.Base64;
import java.util.List;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
/**
* This class SQL Account Manager
@@ -47,8 +47,7 @@ public class SQLAccountManager
public static void main(String[] args) throws SQLException, IOException, NoSuchAlgorithmException
{
Server.serverMode = Server.MODE_LOGINSERVER;
Config.load();
Config.load(ServerMode.LOGIN);
DatabaseFactory.init();
while (true)

View File

@@ -31,8 +31,8 @@ import java.util.Properties;
import java.util.ResourceBundle;
import org.l2jmobius.Config;
import org.l2jmobius.Server;
import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.enums.ServerMode;
import org.l2jmobius.commons.util.Util;
import org.l2jmobius.loginserver.GameServerTable;
@@ -66,9 +66,7 @@ public abstract class BaseGameServerRegister
*/
public void load()
{
Server.serverMode = Server.MODE_LOGINSERVER;
Config.load();
Config.load(ServerMode.LOGIN);
DatabaseFactory.init();
GameServerTable.getInstance();