package net.taehui.twilight.etc import io.netty.bootstrap.ServerBootstrap import io.netty.channel.Channel import io.netty.channel.ChannelInitializer import io.netty.channel.EventLoopGroup import io.netty.channel.socket.SocketChannel import io.netty.channel.socket.nio.NioServerSocketChannel import io.netty.handler.codec.http.HttpClientCodec import io.netty.handler.codec.http.HttpObjectAggregator import io.netty.handler.codec.http.HttpServerCodec import net.taehui.twilight.Logger class EtcBoot(eventLoopGroup: EventLoopGroup) : Logger, AutoCloseable { private val mainBootstrap: ServerBootstrap = ServerBootstrap().group(eventLoopGroup).channel(NioServerSocketChannel::class.java) .childHandler(object : ChannelInitializer<SocketChannel>() { public override fun initChannel(ch: SocketChannel) { ch.pipeline() .addLast(HttpServerCodec()) .addLast(HttpObjectAggregator(Int.MAX_VALUE)) .addLast(HttpClientCodec()) .addLast(EtcAvatar()) } }) private val mainChannel: Channel init { logInfo("Loading Etc") mainChannel = mainBootstrap.bind(4003).channel().closeFuture() .addListener { logInfo("Closed Etc") }.channel() } override fun close() { mainChannel.close() } }