Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.dream.auth;
- import java.io.File;
- import java.io.IOException;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import org.apache.log4j.Logger;
- import org.apache.log4j.xml.DOMConfigurator;
- import com.dream.AuthConfig;
- import com.dream.L2AuthDatabaseFactory;
- import com.dream.auth.manager.AuthManager;
- import com.dream.auth.manager.BanManager;
- import com.dream.auth.manager.GameServerManager;
- import com.dream.auth.mmocore.SelectorConfig;
- import com.dream.auth.mmocore.SelectorThread;
- import com.dream.auth.thread.GameServerListener;
- import com.dream.tools.network.Util;
- public class L2AuthServer
- {
- public static final int PROTOCOL_REV = 0x102;
- public static Logger _log = Logger.getLogger(L2AuthServer.class);
- private static double _intialTime = 0;
- private GameServerListener _gameServerListener;
- private SelectorThread<L2AuthClient> _selectorThread;
- private static L2AuthServer _instance;
- public static L2AuthServer getInstance()
- {
- return _instance;
- }
- public static void main(String[] args) throws Throwable
- {
- _instance = new L2AuthServer();
- }
- public L2AuthServer() throws Throwable
- {
- new File("log").mkdirs();
- DOMConfigurator.configure("./config/log4j.xml");
- _intialTime = System.currentTimeMillis();
- AuthConfig.load();
- L2AuthDatabaseFactory.getInstance();
- GameServerManager.getInstance();
- ClientManager.getInstance();
- AuthManager.load();
- BanManager.getInstance();
- Runtime.getRuntime().addShutdownHook(new Thread()
- {
- @Override
- public void run()
- {
- _log.info("Auth server shutting down");
- }
- });
- initNetworkLayer();
- initGSListener();
- startServer();
- Util.printSection("Server Info");
- printInfo();
- }
- private static void printInfo()
- {
- long freeMem = ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory()) + Runtime.getRuntime().freeMemory()) / 1048576;
- long totalMem = Runtime.getRuntime().maxMemory() / 1048576;
- double finalTime = System.currentTimeMillis();
- if (AuthConfig.CRYPT_TOKEN)
- {
- _log.info("Token-based brut-proof enabled");
- }
- _log.info("Free memory: " + freeMem + " Mb of " + totalMem + " Mb");
- _log.info("Ready on IP: " + AuthConfig.LOGIN_SERVER_HOSTNAME + ":" + AuthConfig.LOGIN_SERVER_PORT + ".");
- _log.info("Load time: " + (int) ((finalTime - _intialTime) / 1000) + " Seconds.");
- Util.printSection("Server Info");
- _log.info("Auth Server successfully started.");
- }
- private void startServer()
- {
- InetAddress bindAddress = null;
- if (!AuthConfig.LOGIN_SERVER_HOSTNAME.equals("*"))
- {
- try
- {
- bindAddress = InetAddress.getByName(AuthConfig.LOGIN_SERVER_HOSTNAME);
- }
- catch (UnknownHostException e1)
- {
- _log.warn("WARNING: The LoginServer bind address is invalid, using all available IPs. Reason: " + e1.getMessage());
- }
- }
- try
- {
- _selectorThread.openServerSocket(bindAddress, AuthConfig.LOGIN_SERVER_PORT);
- }
- catch (IOException e)
- {
- _log.fatal("FATAL: Failed to open server socket. Reason: " + e.getMessage(), e);
- System.exit(1);
- }
- _selectorThread.start();
- }
- private void initGSListener()
- {
- _gameServerListener = new GameServerListener();
- _gameServerListener.start();
- _log.info("Listening for GameServers on " + AuthConfig.LOGIN_HOSTNAME + ":" + AuthConfig.LOGIN_PORT);
- }
- private void initNetworkLayer()
- {
- L2AuthPacketHandler loginPacketHandler = new L2AuthPacketHandler();
- SelectorHelper sh = new SelectorHelper();
- SelectorConfig<L2AuthClient> ssc = new SelectorConfig<>(null, null, sh, loginPacketHandler);
- try
- {
- _selectorThread = new SelectorThread<>(ssc, sh, sh, sh);
- }
- catch (IOException e)
- {
- _log.fatal("FATAL: Failed to open Selector. Reason: " + e.getMessage(), e);
- System.exit(1);
- }
- }
- public GameServerListener getGameServerListener()
- {
- return _gameServerListener;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment