use of org.lanternpowered.server.network.message.codec.CodecContext in project LanternServer by LanternPowered.
the class NetworkManager method init0.
@Override
protected ChannelFuture init0(SocketAddress address, boolean epoll) {
this.bootstrap = new ServerBootstrap();
// Take advantage of the fast thread local threads,
// this is also provided by the default thread factory
final ThreadFactory threadFactory = ThreadHelper.newFastThreadLocalThreadFactory(() -> "netty-" + threadCounter.getAndIncrement());
this.bossGroup = createEventLoopGroup(epoll, threadFactory);
this.workerGroup = createEventLoopGroup(epoll, threadFactory);
this.socketAddress = address;
return this.bootstrap.group(this.bossGroup, this.workerGroup).channel(getServerSocketChannelClass(epoll)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
final ChannelPipeline pipeline = ch.pipeline();
final NetworkSession networkSession = new NetworkSession(ch, server, NetworkManager.this);
final CodecContext codecContext = new SimpleCodecContext(new LanternByteBufferAllocator(ch.alloc()), ch, networkSession);
pipeline.addLast(new ReadTimeoutHandler(NetworkSession.READ_TIMEOUT_SECONDS)).addLast(NetworkSession.LEGACY_PING, new LegacyProtocolHandler(networkSession)).addLast(NetworkSession.ENCRYPTION, NoopHandler.INSTANCE).addLast(NetworkSession.FRAMING, new MessageFramingHandler()).addLast(NetworkSession.COMPRESSION, NoopHandler.INSTANCE).addLast(NetworkSession.CODECS, new MessageCodecHandler(codecContext)).addLast(NetworkSession.PROCESSOR, new MessageProcessorHandler(codecContext)).addLast(NetworkSession.HANDLER, networkSession);
}
}).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true).bind(address);
}
use of org.lanternpowered.server.network.message.codec.CodecContext in project LanternServer by LanternPowered.
the class CodecPlayOutEffect method encode.
@Override
public ByteBuffer encode(CodecContext context, Message message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
if (message instanceof MessagePlayOutEffect) {
final MessagePlayOutEffect message1 = (MessagePlayOutEffect) message;
buf.writeInteger(message1.getType());
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getData());
buf.writeBoolean(message1.isBroadcast());
} else if (message instanceof MessagePlayOutRecord) {
final MessagePlayOutRecord message1 = (MessagePlayOutRecord) message;
buf.writeInteger(1010);
buf.write(Types.VECTOR_3_I, message1.getPosition());
buf.writeInteger(message1.getRecord().map(type -> 2256 + ((LanternRecordType) type).getInternalId()).orElse(0));
buf.writeBoolean(false);
} else {
throw new EncoderException("Unsupported message type: " + message.getClass().getName());
}
return buf;
}
Aggregations