DatabaseFactory.getInstance().initPool("GameServer");
LOGGER.info("Checking database: ........");
SqlTableOptimizer.repairTables(DatabaseFactory.getInstance().getConnection());
SqlTableOptimizer.optimizeTables(DatabaseFactory.getInstance().getConnection());
final IdFactory _idFactory = IdFactory.getInstance();
if (!_idFactory.isInitialized()) {
LOGGER.error("Could not read object IDs from DB. Please Check Your Data.");
throw new Exception("Could not initialize the ID factory");
}
ThreadPoolManager.getInstance();
Scripts.getInstance();
GeoEngine.load();
Strings.reload();
GameTimeController.getInstance();
World.init();
Parsers.parseAll();
ItemsDAO.getInstance();
CrestCache.getInstance();
CharacterDAO.getInstance();
ClanTable.getInstance();
SkillTreeTable.getInstance();
CharTemplateTable.getInstance();
LevelUpTable.getInstance();
PetSkillsTable.getInstance();
if(Config.NPC_SERVER_DELAY > 0)
{
ThreadPoolManager.getInstance().schedule(new NpcTaskSpawn(), Config.NPC_SERVER_DELAY * 1000);
}
SpawnManager.getInstance().spawnAll();
BoatHolder.getInstance().spawnAll();
StaticObjectHolder.getInstance().spawnAll();
RaidBossSpawnManager.getInstance();
Scripts.getInstance().init();
DimensionalRiftManager.getInstance();
Announcements.getInstance();
LotteryManager.getInstance();
PlayerMessageStack.getInstance();
if (Config.AUTODESTROY_ITEM_AFTER > 0) {
ItemsAutoDestroy.getInstance();
}
MonsterRace.getInstance();
SevenSigns.getInstance();
SevenSignsFestival.getInstance();
SevenSigns.getInstance().updateFestivalScore();
NoblessManager.getInstance();
if (Config.OLY_ENABLED) {
OlympiadSystemManager.getInstance();
HeroManager.getInstance();
}
PetitionManager.getInstance();
if (!Config.ALLOW_WEDDING) {
CoupleManager.getInstance();
LOGGER.info("CoupleManager initialized");
}
LOGGER.info("=[Handlers]=======================================");
ItemHandler.getInstance().log();
AdminCommandHandler.getInstance().log();
UserCommandHandler.getInstance().log();
VoicedCommandHandler.getInstance().log();
BypassHolder.getInstance().log();
NpcDialogAppenderHolder.getInstance().log();
OnShiftActionHolder.getInstance().log();
LOGGER.info("==================================================");
TaskManager.getInstance();
ClanTable.getInstance().checkClans();
LOGGER.info("=[Events]=========================================");
ResidenceHolder.getInstance().callInit();
EventHolder.getInstance().callInit();
LOGGER.info("==================================================");
CastleManorManager.getInstance();
Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
LOGGER.info("IdFactory: Free ObjectID's remaining: " + IdFactory.getInstance().size());
CoupleManager.getInstance();
CursedWeaponsManager.getInstance();
if (Config.ALT_FISH_CHAMPIONSHIP_ENABLED) {
FishingChampionShipManager.getInstance();
}
PhantomLoader.getInstance().loadPhantomSystem();
L2TopRuManager.getInstance();
Shutdown.getInstance().schedule(Config.RESTART_AT_TIME, 2);
LOGGER.info("GameServer Started");
LOGGER.info("Maximum Numbers of Connected Players: " + Config.MAXIMUM_ONLINE_USERS);
final GamePacketHandler gph = new GamePacketHandler();
InetAddress serverAddr = "*".equalsIgnoreCase(Config.GAMESERVER_HOSTNAME) ? null : InetAddress.getByName(Config.GAMESERVER_HOSTNAME);
_selectorThreads = new SelectorThread[Config.PORTS_GAME.length];
for (int i = 0; i < Config.PORTS_GAME.length; i++) {
_selectorThreads = new SelectorThread<>(Config.SELECTOR_CONFIG, gph, gph, gph, null);
_selectorThreads.openServerSocket(serverAddr, Config.PORTS_GAME);
_selectorThreads.start();
}
AuthServerCommunication.getInstance().start();
if (Config.SERVICES_OFFLINE_TRADE_RESTORE_AFTER_RESTART) {
ThreadPoolManager.getInstance().schedule(new RestoreOfflineTraders(), 30000L);
}
getListeners().onStart();
if (Config.IS_TELNET_ENABLED) {
statusServer = new TelnetServer();
} else {
LOGGER.info("Telnet server is currently disabled.");
}
CGMHelper.getInstance();
LOGGER.info("=================================================");
System.gc();
System.runFinalization();
StatsUtils.printMemoryInfo();
LOGGER.info("=================================================");
final long serverLoadEnd = System.currentTimeMillis();
LOGGER.info("Server Loaded in {} seconds", (serverLoadEnd - serverLoadStart) / 1000);
if (Config.CUSTOM_SHOP_TRADER_MANAGER) {
CustomTradeManagers.getInstance();
}
//TwitchRewardManager.getInstance();
Toolkit.getDefaultToolkit().beep();
}
public static GameServer getInstance() {
return _instance;
}
private static void checkFreePorts() {
boolean binded = false;
while (!binded) {
for (final int PORT_GAME : Config.PORTS_GAME) {
try {
ServerSocket ss;
if ("*".equalsIgnoreCase(Config.GAMESERVER_HOSTNAME)) {
ss = new ServerSocket(PORT_GAME);
} else {
ss = new ServerSocket(PORT_GAME, 50, InetAddress.getByName(Config.GAMESERVER_HOSTNAME));
}
ss.close();
binded = true;
} catch (Exception e) {
LOGGER.warn("Port " + PORT_GAME + " is allready binded. Please free it and restart server.");
binded = false;
try {
Thread.sleep(1000L);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
}
@HideAccess
public static void cancelCheckSelector() {
if (selectorTask != null) {
selectorTask.cancel(true);
selectorTask = null;
}
}
public static void main(final String[] args) throws Exception {
new GameServer();
}
@HideAccess
private void copyLog(final String name) {
final File copyLog = new File("log/" + name + ".log");
if (copyLog.exists()) {
final Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(copyLog.lastModified());
final SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy_HH-mm-ss");
copyLog.renameTo(new File(String.format("log/%s/%s-%s.log", name, name, df.format(calendar.getTime()))));
}
}
public SelectorThread<GameClient>[] getSelectorThreads() {
return _selectorThreads;
}
public long getServerStartTime() {
return _serverStartTimeMillis;
}
public GameServerListenerList getListeners() {
return _listeners;
}
public <T extends GameListener> boolean addListener(final T listener) {
return _listeners.add(listener);
}
public <T extends GameListener> boolean removeListener(final T listener) {
return _listeners.remove(listener);
}
public Version getVersion() {
return version;
}
public TelnetServer getStatusServer() {
return statusServer;
}
public class GameServerListenerList extends ListenerList<GameServer> {
public void onStart() {
getListeners().stream().filter(OnStartListener.class::isInstance).forEach(listener -> ((OnStartListener) listener).onStart());
}
public void onShutdown() {
getListeners().stream().filter(OnShutdownListener.class::isInstance).forEach(listener -> ((OnShutdownListener) listener).onShutdown());
}
}
public class NpcTaskSpawn extends RunnableImpl {
@Override
public void runImpl() {
SpawnManager.getInstance().spawnAll();
}
}
}
достался по наследству