Disconnect client if idle

Thanks SharpAceX for Guida,
which I used as a reference.
This commit is contained in:
P0nk
2021-06-24 22:07:22 +02:00
parent 5651bee2b5
commit 80cacd609a
4 changed files with 83 additions and 13 deletions

View File

@@ -5,6 +5,7 @@ import constants.net.ServerConstants;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;
import tools.MaplePacketCreator;
import java.util.concurrent.atomic.AtomicLong;
@@ -16,6 +17,7 @@ public abstract class ServerChannelInitializer extends ChannelInitializer<Socket
final InitializationVector sendIv = InitializationVector.generateSend();
final InitializationVector recvIv = InitializationVector.generateReceive();
socketChannel.writeAndFlush(Unpooled.wrappedBuffer(MaplePacketCreator.getHello(ServerConstants.VERSION, sendIv, recvIv)));
socketChannel.pipeline().addFirst("IdleStateHandler", new IdleStateHandler(30, 30, 0));
socketChannel.pipeline().addLast("PacketCodec", new PacketCodec(ClientCyphers.of(sendIv, recvIv)));
socketChannel.pipeline().addLast("MapleClient", client);
}