L2CommunityServer.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.communityserver;
  16. import java.io.File;
  17. import java.io.FileInputStream;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. import java.sql.SQLException;
  21. import java.util.logging.LogManager;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.communityserver.cache.HtmCache;
  24. import com.l2jserver.communityserver.network.GameServerListener;
  25. import com.l2jserver.communityserver.network.netcon.NetConnectionConfig;
  26. import com.l2jserver.communityserver.threading.ThreadPoolManager;
  27. import com.l2jserver.communityserver.Shutdown;
  28. public final class L2CommunityServer
  29. {
  30. private static final Logger _log = Logger.getLogger(L2CommunityServer.class.getName());
  31. private static L2CommunityServer _instance;
  32. public static final L2CommunityServer getInstance()
  33. {
  34. return _instance;
  35. }
  36. public static final void main(final String[] args)
  37. {
  38. _instance = new L2CommunityServer();
  39. }
  40. private GameServerListener _listener;
  41. private final Shutdown _shutdownHandler;
  42. public L2CommunityServer()
  43. {
  44. final String LOG_FOLDER = "log";
  45. final String LOG_NAME = "./log.cfg";
  46. File logFolder = new File(Config.DATAPACK_ROOT, LOG_FOLDER);
  47. logFolder.mkdir();
  48. InputStream is = null;
  49. try
  50. {
  51. is = new FileInputStream(new File(LOG_NAME));
  52. LogManager.getLogManager().readConfiguration(is);
  53. is.close();
  54. }
  55. catch (IOException e)
  56. {
  57. e.printStackTrace();
  58. }
  59. finally
  60. {
  61. try
  62. {
  63. if (is != null)
  64. {
  65. is.close();
  66. }
  67. }
  68. catch (IOException e)
  69. {
  70. e.printStackTrace();
  71. }
  72. }
  73. Config.load();
  74. _shutdownHandler = Shutdown.getInstance();
  75. Runtime.getRuntime().addShutdownHook(_shutdownHandler);
  76. ThreadPoolManager.init();
  77. GameServerRegistrationTable.getInstance();
  78. try
  79. {
  80. L2DatabaseFactory.getInstance();
  81. }
  82. catch (SQLException e)
  83. {
  84. _log.severe("FATAL: Failed initializing database. Reason: "+e.getMessage());
  85. System.exit(1);
  86. }
  87. // load htm cache
  88. HtmCache.getInstance();
  89. try
  90. {
  91. _listener = new GameServerListener(new NetConnectionConfig(Config.CONFIGURATION_FILE));
  92. _listener.start();
  93. _log.info("Listening for GameServers on " + Config.GAME_SERVER_LOGIN_HOST + ":" + Config.GAME_SERVER_LOGIN_PORT);
  94. }
  95. catch (Exception e)
  96. {
  97. _log.severe("FATAL: Failed to start the Game Server Listener. Reason: " + e.getMessage());
  98. e.printStackTrace();
  99. System.exit(1);
  100. }
  101. }
  102. }