use of net.server.worker.RankingWorker in project HeavenMS by ronancpl.
the class Server method run.
@Override
public void run() {
Properties p = new Properties();
try {
p.load(new FileInputStream("world.ini"));
} catch (Exception e) {
e.printStackTrace();
System.out.println("Please start create_server.bat");
System.exit(0);
}
System.out.println("HeavenMS v" + ServerConstants.VERSION + " starting up.\r\n");
if (ServerConstants.SHUTDOWNHOOK)
Runtime.getRuntime().addShutdownHook(new Thread(shutdown(false)));
Connection c = null;
try {
c = DatabaseConnection.getConnection();
PreparedStatement ps = c.prepareStatement("UPDATE accounts SET loggedin = 0");
ps.executeUpdate();
ps.close();
ps = c.prepareStatement("UPDATE characters SET HasMerchant = 0");
ps.executeUpdate();
ps.close();
loadCouponRates(c);
updateActiveCoupons();
c.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
}
IoBuffer.setUseDirectBuffer(false);
IoBuffer.setAllocator(new SimpleBufferAllocator());
acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast("codec", (IoFilter) new ProtocolCodecFilter(new MapleCodecFactory()));
TimerManager tMan = TimerManager.getInstance();
tMan.start();
// Purging ftw...
tMan.register(tMan.purge(), ServerConstants.PURGING_INTERVAL);
disconnectIdlesOnLoginTask();
long timeLeft = getTimeLeftForNextHour();
tMan.register(new CouponWorker(), ServerConstants.COUPON_INTERVAL, timeLeft);
tMan.register(new RankingWorker(), ServerConstants.RANKING_INTERVAL, timeLeft);
long timeToTake = System.currentTimeMillis();
SkillFactory.loadAllSkills();
System.out.println("Skills loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
timeToTake = System.currentTimeMillis();
// MapleItemInformationProvider.getInstance().getAllItems(); //unused, rofl
CashItemFactory.getSpecialCashItems();
System.out.println("Items loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds");
timeToTake = System.currentTimeMillis();
MapleQuest.loadAllQuest();
System.out.println("Quest loaded in " + ((System.currentTimeMillis() - timeToTake) / 1000.0) + " seconds\r\n");
NewYearCardRecord.startPendingNewYearCardRequests();
if (ServerConstants.USE_THREAD_TRACKER)
ThreadTracker.getInstance().registerThreadTrackerTask();
try {
Integer worldCount = Math.min(ServerConstants.WORLD_NAMES.length, Integer.parseInt(p.getProperty("worlds")));
for (int i = 0; i < worldCount; i++) {
System.out.println("Starting world " + i);
World world = new World(i, Integer.parseInt(p.getProperty("flag" + i)), p.getProperty("eventmessage" + i), ServerConstants.EXP_RATE, ServerConstants.DROP_RATE, ServerConstants.MESO_RATE, ServerConstants.QUEST_RATE);
worldRecommendedList.add(new Pair<>(i, p.getProperty("whyamirecommended" + i)));
worlds.add(world);
channels.add(new HashMap<Integer, String>());
for (int j = 0; j < Integer.parseInt(p.getProperty("channels" + i)); j++) {
int channelid = j + 1;
Channel channel = new Channel(i, channelid);
world.addChannel(channel);
channels.get(i).put(channelid, channel.getIP());
}
world.setServerMessage(p.getProperty("servermessage" + i));
System.out.println("Finished loading world " + i + "\r\n");
}
} catch (Exception e) {
// For those who get errors
e.printStackTrace();
System.out.println("Error in moople.ini, start CreateINI.bat to re-make the file.");
System.exit(0);
}
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
acceptor.setHandler(new MapleServerHandler());
try {
acceptor.bind(new InetSocketAddress(8484));
} catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("Listening on port 8484\r\n\r\n");
System.out.println("HeavenMS is now online.\r\n");
online = true;
}
Aggregations