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.
41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
package net.netty;
|
|
|
|
import io.netty.bootstrap.ServerBootstrap;
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.EventLoopGroup;
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
|
|
|
public class ChannelServer extends AbstractServer {
|
|
private final int world;
|
|
private final int channel;
|
|
private Channel nettyChannel;
|
|
|
|
public ChannelServer(int port, int world, int channel) {
|
|
super(port);
|
|
this.world = world;
|
|
this.channel = channel;
|
|
}
|
|
|
|
@Override
|
|
public void start() {
|
|
EventLoopGroup parentGroup = new NioEventLoopGroup();
|
|
EventLoopGroup childGroup = new NioEventLoopGroup();
|
|
ServerBootstrap bootstrap = new ServerBootstrap()
|
|
.group(parentGroup, childGroup)
|
|
.channel(NioServerSocketChannel.class)
|
|
.childHandler(new ChannelServerInitializer(world, channel));
|
|
|
|
this.nettyChannel = bootstrap.bind(port).syncUninterruptibly().channel();
|
|
}
|
|
|
|
@Override
|
|
public void stop() {
|
|
if (nettyChannel == null) {
|
|
throw new IllegalStateException("Must start ChannelServer before stopping it");
|
|
}
|
|
|
|
nettyChannel.close().syncUninterruptibly();
|
|
}
|
|
}
|