123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528 |
- /*
- * 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 net.sf.l2j.gameserver;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import java.util.Calendar;
- import java.util.logging.Level;
- import java.util.logging.LogManager;
- import java.util.logging.Logger;
- import net.sf.l2j.Config;
- import net.sf.l2j.L2DatabaseFactory;
- import net.sf.l2j.Server;
- import net.sf.l2j.gameserver.cache.CrestCache;
- import net.sf.l2j.gameserver.cache.HtmCache;
- import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
- import net.sf.l2j.gameserver.datatables.AccessLevels;
- import net.sf.l2j.gameserver.datatables.ArmorSetsTable;
- import net.sf.l2j.gameserver.datatables.AugmentationData;
- import net.sf.l2j.gameserver.datatables.CharNameTable;
- import net.sf.l2j.gameserver.datatables.CharTemplateTable;
- import net.sf.l2j.gameserver.datatables.ClanTable;
- import net.sf.l2j.gameserver.datatables.DoorTable;
- import net.sf.l2j.gameserver.datatables.EventDroplist;
- import net.sf.l2j.gameserver.datatables.ExtractableItemsData;
- import net.sf.l2j.gameserver.datatables.FishTable;
- import net.sf.l2j.gameserver.datatables.HelperBuffTable;
- import net.sf.l2j.gameserver.datatables.HennaTable;
- import net.sf.l2j.gameserver.datatables.HennaTreeTable;
- import net.sf.l2j.gameserver.datatables.HeroSkillTable;
- import net.sf.l2j.gameserver.datatables.ItemTable;
- import net.sf.l2j.gameserver.datatables.LevelUpData;
- import net.sf.l2j.gameserver.datatables.MapRegionTable;
- import net.sf.l2j.gameserver.datatables.MerchantPriceConfigTable;
- import net.sf.l2j.gameserver.datatables.NobleSkillTable;
- import net.sf.l2j.gameserver.datatables.NpcBufferTable;
- import net.sf.l2j.gameserver.datatables.NpcTable;
- import net.sf.l2j.gameserver.datatables.NpcWalkerRoutesTable;
- import net.sf.l2j.gameserver.datatables.SkillSpellbookTable;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.datatables.SkillTreeTable;
- import net.sf.l2j.gameserver.datatables.SpawnTable;
- import net.sf.l2j.gameserver.datatables.StaticObjects;
- import net.sf.l2j.gameserver.datatables.SummonItemsData;
- import net.sf.l2j.gameserver.datatables.TeleportLocationTable;
- import net.sf.l2j.gameserver.geoeditorcon.GeoEditorListener;
- import net.sf.l2j.gameserver.handler.AdminCommandHandler;
- import net.sf.l2j.gameserver.handler.ChatHandler;
- import net.sf.l2j.gameserver.handler.ItemHandler;
- import net.sf.l2j.gameserver.handler.SkillHandler;
- import net.sf.l2j.gameserver.handler.UserCommandHandler;
- import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
- import net.sf.l2j.gameserver.idfactory.IdFactory;
- import net.sf.l2j.gameserver.instancemanager.AuctionManager;
- import net.sf.l2j.gameserver.instancemanager.BoatManager;
- import net.sf.l2j.gameserver.instancemanager.CastleManager;
- import net.sf.l2j.gameserver.instancemanager.CastleManorManager;
- import net.sf.l2j.gameserver.instancemanager.ClanHallManager;
- import net.sf.l2j.gameserver.instancemanager.CoupleManager;
- import net.sf.l2j.gameserver.instancemanager.CursedWeaponsManager;
- import net.sf.l2j.gameserver.instancemanager.DayNightSpawnManager;
- import net.sf.l2j.gameserver.instancemanager.DimensionalRiftManager;
- import net.sf.l2j.gameserver.instancemanager.FortManager;
- import net.sf.l2j.gameserver.instancemanager.FortSiegeManager;
- import net.sf.l2j.gameserver.instancemanager.FourSepulchersManager;
- import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
- import net.sf.l2j.gameserver.instancemanager.ItemsOnGroundManager;
- import net.sf.l2j.gameserver.instancemanager.MercTicketManager;
- import net.sf.l2j.gameserver.instancemanager.PetitionManager;
- import net.sf.l2j.gameserver.instancemanager.QuestManager;
- import net.sf.l2j.gameserver.instancemanager.RaidBossPointsManager;
- import net.sf.l2j.gameserver.instancemanager.RaidBossSpawnManager;
- import net.sf.l2j.gameserver.instancemanager.SiegeManager;
- import net.sf.l2j.gameserver.instancemanager.TransformationManager;
- import net.sf.l2j.gameserver.instancemanager.ZoneManager;
- import net.sf.l2j.gameserver.model.AutoChatHandler;
- import net.sf.l2j.gameserver.model.AutoSpawnHandler;
- import net.sf.l2j.gameserver.model.L2AdminCommandAccessRights;
- import net.sf.l2j.gameserver.model.L2Manor;
- import net.sf.l2j.gameserver.model.L2PetDataTable;
- import net.sf.l2j.gameserver.model.L2World;
- import net.sf.l2j.gameserver.model.entity.Hero;
- import net.sf.l2j.gameserver.model.entity.TvTManager;
- import net.sf.l2j.gameserver.network.L2GameClient;
- import net.sf.l2j.gameserver.network.L2GamePacketHandler;
- import net.sf.l2j.gameserver.pathfinding.geonodes.GeoPathFinding;
- import net.sf.l2j.gameserver.script.faenor.FaenorScriptEngine;
- import net.sf.l2j.gameserver.scripting.CompiledScriptCache;
- import net.sf.l2j.gameserver.scripting.L2ScriptEngineManager;
- import net.sf.l2j.gameserver.taskmanager.KnownListUpdateTaskManager;
- import net.sf.l2j.gameserver.taskmanager.TaskManager;
- import net.sf.l2j.gameserver.util.DynamicExtension;
- import net.sf.l2j.gameserver.util.FloodProtector;
- import net.sf.l2j.status.Status;
- import org.mmocore.network.SelectorConfig;
- import org.mmocore.network.SelectorThread;
- /**
- * This class ...
- *
- * @version $Revision: 1.29.2.15.2.19 $ $Date: 2005/04/05 19:41:23 $
- */
- public class GameServer
- {
- private static final Logger _log = Logger.getLogger(GameServer.class.getName());
- private final SelectorThread<L2GameClient> _selectorThread;
- private final SkillTable _skillTable;
- private final ItemTable _itemTable;
- private final NpcTable _npcTable;
- private final HennaTable _hennaTable;
- private final IdFactory _idFactory;
- public static GameServer gameServer;
- private static ClanHallManager _cHManager;
- private final Shutdown _shutdownHandler;
- private final DoorTable _doorTable;
- private final SevenSigns _sevenSignsEngine;
- private final AutoChatHandler _autoChatHandler;
- private final AutoSpawnHandler _autoSpawnHandler;
- private LoginServerThread _loginThread;
- private final HelperBuffTable _helperBuffTable;
- private static Status _statusServer;
- @SuppressWarnings("unused")
- private final ThreadPoolManager _threadpools;
- public static final Calendar dateTimeServerStarted = Calendar.getInstance();
- public long getUsedMemoryMB()
- {
- return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/1048576; // 1024 * 1024 = 1048576;
- }
- public SelectorThread<L2GameClient> getSelectorThread()
- {
- return _selectorThread;
- }
- public ClanHallManager getCHManager(){
- return _cHManager;
- }
- public GameServer() throws Exception
- {
- long serverLoadStart = System.currentTimeMillis();
-
- gameServer = this;
- _log.finest("used mem:" + getUsedMemoryMB()+"MB" );
- if (Config.SERVER_VERSION != null)
- {
- _log.info("L2J Server Version: "+Config.SERVER_VERSION);
- }
- if (Config.DATAPACK_VERSION != null)
- {
- _log.info("L2J Datapack Version: "+Config.DATAPACK_VERSION);
- }
- _idFactory = IdFactory.getInstance();
- if (!_idFactory.isInitialized())
- {
- _log.severe("Could not read object IDs from DB. Please Check Your Data.");
- throw new Exception("Could not initialize the ID factory");
- }
- _threadpools = ThreadPoolManager.getInstance();
- new File(Config.DATAPACK_ROOT, "data/clans").mkdirs();
- new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
-
-
- // load script engines
- L2ScriptEngineManager.getInstance();
-
- // start game time control early
- GameTimeController.getInstance();
- // keep the references of Singletons to prevent garbage collection
- CharNameTable.getInstance();
- _skillTable = SkillTable.getInstance();
- if (!_skillTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the skill table");
- }
-
- _itemTable = ItemTable.getInstance();
- if (!_itemTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the item table");
- }
-
- // Load clan hall data before zone data and doors table
- _cHManager = ClanHallManager.getInstance();
-
- _doorTable = DoorTable.getInstance();
- _doorTable.parseData();
- StaticObjects.getInstance();
- ExtractableItemsData.getInstance();
- SummonItemsData.getInstance();
- MerchantPriceConfigTable.getInstance();
- TradeController.getInstance();
-
- if(Config.ALLOW_NPC_WALKERS)
- {
- NpcWalkerRoutesTable.getInstance().load();
- }
-
- NpcBufferTable.getInstance();
-
- RecipeController.getInstance();
- SkillTreeTable.getInstance();
- ArmorSetsTable.getInstance();
- FishTable.getInstance();
- SkillSpellbookTable.getInstance();
- CharTemplateTable.getInstance();
- NobleSkillTable.getInstance();
- HeroSkillTable.getInstance();
- //Call to load caches
- HtmCache.getInstance();
- CrestCache.getInstance();
- ClanTable.getInstance();
- _npcTable = NpcTable.getInstance();
- if (!_npcTable.isInitialized())
- {
- _log.severe("Could not find the extraced files. Please Check Your Data.");
- throw new Exception("Could not initialize the npc table");
- }
- _hennaTable = HennaTable.getInstance();
- if (!_hennaTable.isInitialized())
- {
- throw new Exception("Could not initialize the Henna Table");
- }
- HennaTreeTable.getInstance();
- if (!_hennaTable.isInitialized())
- {
- throw new Exception("Could not initialize the Henna Tree Table");
- }
- _helperBuffTable = HelperBuffTable.getInstance();
- if (!_helperBuffTable.isInitialized())
- {
- throw new Exception("Could not initialize the Helper Buff Table");
- }
- GeoData.getInstance();
- if (Config.GEODATA == 2)
- GeoPathFinding.getInstance();
-
- CastleManager.getInstance();
- SiegeManager.getInstance();
- FortManager.getInstance();
- FortSiegeManager.getInstance();
- TeleportLocationTable.getInstance();
- LevelUpData.getInstance();
- L2World.getInstance();
- SpawnTable.getInstance();
- ZoneManager.getInstance();
- RaidBossSpawnManager.getInstance();
- DayNightSpawnManager.getInstance().notifyChangeMode();
- GrandBossManager.getInstance();
- RaidBossPointsManager.init();
- FourSepulchersManager.getInstance().init();
- DimensionalRiftManager.getInstance();
- Announcements.getInstance();
- MapRegionTable.getInstance();
- EventDroplist.getInstance();
- /** Load Manor data */
- L2Manor.getInstance();
- /** Load Manager */
- AuctionManager.getInstance();
- BoatManager.getInstance();
- CastleManorManager.getInstance();
- MercTicketManager.getInstance();
- //PartyCommandManager.getInstance();
- PetitionManager.getInstance();
- QuestManager.getInstance();
- TransformationManager.getInstance();
-
- try
- {
- _log.info("Loading Server Scripts");
- File scripts = new File(Config.DATAPACK_ROOT + "/data/scripts.cfg");
- L2ScriptEngineManager.getInstance().executeScriptList(scripts);
- }
- catch (IOException ioe)
- {
- _log.severe("Failed loading scripts.cfg, no script going to be loaded");
- }
- try
- {
- CompiledScriptCache compiledScriptCache = L2ScriptEngineManager.getInstance().getCompiledScriptCache();
- if (compiledScriptCache == null)
- {
- _log.info("Compiled Scripts Cache is disabled.");
- }
- else
- {
- compiledScriptCache.purge();
-
- if (compiledScriptCache.isModified())
- {
- compiledScriptCache.save();
- _log.info("Compiled Scripts Cache was saved.");
- }
- else
- {
- _log.info("Compiled Scripts Cache is up-to-date.");
- }
- }
-
- }
- catch (IOException e)
- {
- _log.log(Level.SEVERE, "Failed to store Compiled Scripts Cache.", e);
- }
- QuestManager.getInstance().report();
- TransformationManager.getInstance().report();
-
- AugmentationData.getInstance();
- if (Config.SAVE_DROPPED_ITEM)
- ItemsOnGroundManager.getInstance();
- if (Config.AUTODESTROY_ITEM_AFTER > 0 || Config.HERB_AUTO_DESTROY_TIME > 0)
- ItemsAutoDestroy.getInstance();
- MonsterRace.getInstance();
- _sevenSignsEngine = SevenSigns.getInstance();
- SevenSignsFestival.getInstance();
- _autoSpawnHandler = AutoSpawnHandler.getInstance();
- _autoChatHandler = AutoChatHandler.getInstance();
- // Spawn the Orators/Preachers if in the Seal Validation period.
- _sevenSignsEngine.spawnSevenSignsNPC();
- Olympiad.getInstance();
- Hero.getInstance();
- FaenorScriptEngine.getInstance();
- // Init of a cursed weapon manager
- CursedWeaponsManager.getInstance();
- _log.config("AutoChatHandler: Loaded " + _autoChatHandler.size() + " handlers in total.");
- _log.config("AutoSpawnHandler: Loaded " + _autoSpawnHandler.size() + " handlers in total.");
-
- AdminCommandHandler.getInstance();
- ChatHandler.getInstance();
- ItemHandler.getInstance();
- SkillHandler.getInstance();
- UserCommandHandler.getInstance();
- VoicedCommandHandler.getInstance();
- AccessLevels.getInstance();
- L2AdminCommandAccessRights.getInstance();
-
- if(Config.L2JMOD_ALLOW_WEDDING)
- CoupleManager.getInstance();
- TaskManager.getInstance();
- GmListTable.getInstance();
- // read pet stats from db
- L2PetDataTable.getInstance().loadPetsData();
- Universe.getInstance();
- if (Config.ACCEPT_GEOEDITOR_CONN)
- GeoEditorListener.getInstance();
- _shutdownHandler = Shutdown.getInstance();
- Runtime.getRuntime().addShutdownHook(_shutdownHandler);
- try
- {
- _doorTable.getDoor(24190001).openMe();
- _doorTable.getDoor(24190002).openMe();
- _doorTable.getDoor(24190003).openMe();
- _doorTable.getDoor(24190004).openMe();
- _doorTable.getDoor(23180001).openMe();
- _doorTable.getDoor(23180002).openMe();
- _doorTable.getDoor(23180003).openMe();
- _doorTable.getDoor(23180004).openMe();
- _doorTable.getDoor(23180005).openMe();
- _doorTable.getDoor(23180006).openMe();
- _doorTable.checkAutoOpen();
- }
- catch (NullPointerException e)
- {
- _log.warning("There is errors in your Door.csv file. Update door.csv");
- if (Config.DEBUG)
- e.printStackTrace();
- }
-
- ForumsBBSManager.getInstance();
-
- _log.config("IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size());
- // initialize the dynamic extension loader
- try
- {
- DynamicExtension.getInstance();
- }
- catch (Exception ex)
- {
- _log.log(Level.WARNING, "DynamicExtension could not be loaded and initialized", ex);
- }
- FloodProtector.getInstance();
- TvTManager.getInstance();
- KnownListUpdateTaskManager.getInstance();
- System.gc();
- // maxMemory is the upper limit the jvm can use, totalMemory the size of the current allocation pool, freeMemory the unused memory in the allocation pool
- long freeMem = (Runtime.getRuntime().maxMemory()-Runtime.getRuntime().totalMemory()+Runtime.getRuntime().freeMemory()) / 1048576; // 1024 * 1024 = 1048576;
- long totalMem = Runtime.getRuntime().maxMemory() / 1048576;
- _log.info("GameServer Started, free memory "+freeMem+" Mb of "+totalMem+" Mb");
- _loginThread = LoginServerThread.getInstance();
- _loginThread.start();
-
- L2GamePacketHandler gph = new L2GamePacketHandler();
- SelectorConfig<L2GameClient> sc = new SelectorConfig<L2GameClient>(null, null, gph, gph);
- sc.setMaxSendPerPass(12);
- sc.setSelectorSleepTime(20);
-
- _selectorThread = new SelectorThread<L2GameClient>(sc, gph, gph, null);
-
- InetAddress bindAddress = null;
- if (!Config.GAMESERVER_HOSTNAME.equals("*"))
- {
- try
- {
- bindAddress = InetAddress.getByName(Config.GAMESERVER_HOSTNAME);
- }
- catch (UnknownHostException e1)
- {
- _log.severe("WARNING: The GameServer bind address is invalid, using all avaliable IPs. Reason: "+e1.getMessage());
- if (Config.DEVELOPER)
- {
- e1.printStackTrace();
- }
- }
- }
-
- try
- {
- _selectorThread.openServerSocket(bindAddress, Config.PORT_GAME);
- }
- catch (IOException e)
- {
- _log.severe("FATAL: Failed to open server socket. Reason: "+e.getMessage());
- if (Config.DEVELOPER)
- {
- e.printStackTrace();
- }
- System.exit(1);
- }
- _selectorThread.start();
- _log.config("Maximum Numbers of Connected Players: " + Config.MAXIMUM_ONLINE_USERS);
- long serverLoadEnd = System.currentTimeMillis();
- _log.info("Server Loaded in "+((serverLoadEnd - serverLoadStart) / 1000)+" seconds");
- }
- public static void main(String[] args) throws Exception
- {
- Server.serverMode = Server.MODE_GAMESERVER;
- // Local Constants
- final String LOG_FOLDER = "log"; // Name of folder for log file
- final String LOG_NAME = "./log.cfg"; // Name of log file
- /*** Main ***/
- // Create log folder
- File logFolder = new File(Config.DATAPACK_ROOT, LOG_FOLDER);
- logFolder.mkdir();
- // Create input stream for log file -- or store file data into memory
- InputStream is = new FileInputStream(new File(LOG_NAME));
- LogManager.getLogManager().readConfiguration(is);
- is.close();
- // Initialize config
- Config.load();
- L2DatabaseFactory.getInstance();
- gameServer = new GameServer();
- if ( Config.IS_TELNET_ENABLED ) {
- _statusServer = new Status(Server.serverMode);
- _statusServer.start();
- }
- else {
- _log.info("Telnet server is currently disabled.");
- }
- }
- }
|