Initial Netty implementation for networking
Split into 1 LoginServer and 1 ChannelServer per channel. There is still a lot of cleanup and refactoring to be done. Currently, the reliance on IoSession holding client state is the most pressing issue to be addressed.
This commit is contained in:
@@ -37,6 +37,7 @@ import constants.net.OpcodeConstants;
|
||||
import constants.net.ServerConstants;
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.netty.LoginServer;
|
||||
import net.server.audit.ThreadTracker;
|
||||
import net.server.audit.locks.MonitoredLockType;
|
||||
import net.server.audit.locks.MonitoredReadLock;
|
||||
@@ -106,6 +107,7 @@ public class Server {
|
||||
private static final List<Integer> activeCoupons = new LinkedList<>();
|
||||
|
||||
private IoAcceptor acceptor;
|
||||
private LoginServer loginServer;
|
||||
private List<Map<Integer, String>> channels = new LinkedList<>();
|
||||
private List<World> worlds = new ArrayList<>();
|
||||
private final Properties subnetInfo = new Properties();
|
||||
@@ -906,17 +908,8 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
IoBuffer.setUseDirectBuffer(false); // join IO operations performed by lxconan
|
||||
IoBuffer.setAllocator(new SimpleBufferAllocator());
|
||||
acceptor = new NioSocketAcceptor();
|
||||
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
|
||||
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
|
||||
acceptor.setHandler(new MapleServerHandler());
|
||||
try {
|
||||
acceptor.bind(new InetSocketAddress(8484));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// acceptor = initAcceptor(8484);
|
||||
loginServer = initLoginServer(8484);
|
||||
|
||||
log.info("Listening on port 8484");
|
||||
|
||||
@@ -932,6 +925,28 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
private LoginServer initLoginServer(int port) {
|
||||
LoginServer loginServer = new LoginServer(port);
|
||||
loginServer.start();
|
||||
return loginServer;
|
||||
}
|
||||
|
||||
private IoAcceptor initAcceptor(int port) {
|
||||
IoBuffer.setUseDirectBuffer(false); // join IO operations performed by lxconan
|
||||
IoBuffer.setAllocator(new SimpleBufferAllocator());
|
||||
acceptor = new NioSocketAcceptor();
|
||||
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
|
||||
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
|
||||
acceptor.setHandler(new MapleServerHandler());
|
||||
try {
|
||||
acceptor.bind(new InetSocketAddress(port));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
private static void setAllLoggedOut(Connection con) throws SQLException {
|
||||
try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = 0")) {
|
||||
ps.executeUpdate();
|
||||
|
||||
@@ -26,6 +26,7 @@ import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import net.MapleServerHandler;
|
||||
import net.mina.MapleCodecFactory;
|
||||
import net.netty.ChannelServer;
|
||||
import net.server.PlayerStorage;
|
||||
import net.server.Server;
|
||||
import net.server.audit.LockCollector;
|
||||
@@ -58,6 +59,7 @@ import tools.MaplePacketCreator;
|
||||
import tools.Pair;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
@@ -69,6 +71,7 @@ public final class Channel {
|
||||
private int port = 7575;
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
private int world, channel;
|
||||
private ChannelServer channelServer;
|
||||
private IoAcceptor acceptor;
|
||||
private String ip, serverMessage;
|
||||
private MapleMapManager mapManager;
|
||||
@@ -122,14 +125,8 @@ public final class Channel {
|
||||
port = 7575 + this.channel - 1;
|
||||
port += (world * 100);
|
||||
ip = YamlConfig.config.server.HOST + ":" + port;
|
||||
IoBuffer.setUseDirectBuffer(false);
|
||||
IoBuffer.setAllocator(new SimpleBufferAllocator());
|
||||
acceptor = new NioSocketAcceptor();
|
||||
acceptor.setHandler(new MapleServerHandler(world, channel));
|
||||
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
|
||||
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
|
||||
acceptor.bind(new InetSocketAddress(port));
|
||||
((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
|
||||
// acceptor = initAcceptor();
|
||||
channelServer = initServer(port, world, channel);
|
||||
expedType.addAll(Arrays.asList(MapleExpeditionType.values()));
|
||||
|
||||
if (Server.getInstance().isOnline()) { // postpone event loading to improve boot time... thanks Riizade, daronhudson for noticing slow startup times
|
||||
@@ -156,6 +153,24 @@ public final class Channel {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private IoAcceptor initAcceptor() throws IOException {
|
||||
IoBuffer.setUseDirectBuffer(false);
|
||||
IoBuffer.setAllocator(new SimpleBufferAllocator());
|
||||
IoAcceptor acceptor = new NioSocketAcceptor();
|
||||
acceptor.setHandler(new MapleServerHandler(world, channel));
|
||||
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 30);
|
||||
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
|
||||
acceptor.bind(new InetSocketAddress(port));
|
||||
((SocketSessionConfig) acceptor.getSessionConfig()).setTcpNoDelay(true);
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
private ChannelServer initServer(int port, int world, int channel) {
|
||||
this.channelServer = new ChannelServer(port, world, channel);
|
||||
channelServer.start();
|
||||
return channelServer;
|
||||
}
|
||||
|
||||
public synchronized void reloadEventScriptManager(){
|
||||
if (finishedShutdown) {
|
||||
|
||||
Reference in New Issue
Block a user