Search in sources :

Example 1 with MapleCodecFactory

use of net.mina.MapleCodecFactory 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;
}
Also used : MapleCodecFactory(net.mina.MapleCodecFactory) SQLException(java.sql.SQLException) InetSocketAddress(java.net.InetSocketAddress) SimpleBufferAllocator(org.apache.mina.core.buffer.SimpleBufferAllocator) Properties(java.util.Properties) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) World(net.server.world.World) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) RankingWorker(net.server.worker.RankingWorker) CouponWorker(net.server.worker.CouponWorker) Channel(net.server.channel.Channel) Connection(java.sql.Connection) DatabaseConnection(tools.DatabaseConnection) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) TimerManager(server.TimerManager) FileInputStream(java.io.FileInputStream) SQLException(java.sql.SQLException) IOException(java.io.IOException) MapleServerHandler(net.MapleServerHandler)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MapleServerHandler (net.MapleServerHandler)1 MapleCodecFactory (net.mina.MapleCodecFactory)1 Channel (net.server.channel.Channel)1 CouponWorker (net.server.worker.CouponWorker)1 RankingWorker (net.server.worker.RankingWorker)1 World (net.server.world.World)1 SimpleBufferAllocator (org.apache.mina.core.buffer.SimpleBufferAllocator)1 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)1 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)1 TimerManager (server.TimerManager)1 DatabaseConnection (tools.DatabaseConnection)1