Added shaded netty 4.0.23

Added support for SSL encryption.
This commit is contained in:
ProfMobius committed 2014-10-03 22:46:52 +02:00
1 parent 70b4e8d5fa
commit 7c693ab480
2 files changed
+35 -2

No files matched your search

@@ -2,10 +2,13 @@ package mcp.mobius.opis.network.rconserver;
import static cpw.mods.fml.relauncher.Side.SERVER;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Timer;
import javax.net.ssl.SSLException;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.io.ByteArrayDataOutput;
@@ -34,6 +37,13 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.compression.JdkZlibDecoder;
import io.netty.handler.codec.compression.JdkZlibEncoder;
import io.netty.handler.codec.compression.ZlibCodecFactory;
import io.netty.handler.codec.compression.ZlibDecoder;
import io.netty.handler.codec.compression.ZlibWrapper;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.handler.timeout.IdleStateHandler;
import io.netty.handler.timeout.ReadTimeoutHandler;
import io.netty.util.ReferenceCountUtil;
@@ -41,9 +51,22 @@ import io.netty.util.ReferenceCountUtil;
public class RConServer implements Runnable {
class ChannelInit extends ChannelInitializer<SocketChannel>{
private final SslContext sslCtx;
public ChannelInit(SslContext sslCtx) {
this.sslCtx = sslCtx;
}
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ReadTimeoutHandler(10), new RconMsgDecoder(), new RConInboundHandler());
ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()));
ch.pipeline().addLast(new ReadTimeoutHandler(10));
ch.pipeline().addLast(new JdkZlibDecoder());
ch.pipeline().addLast(new JdkZlibEncoder());
ch.pipeline().addLast(new RconMsgDecoder());
ch.pipeline().addLast(new RConInboundHandler());
}
}
@@ -68,6 +91,15 @@ public class RConServer implements Runnable {
public void run(){
modOpis.log.info("Starting Opis remote control server.");
SelfSignedCertificate ssc = null;
SslContext sslCtx = null;
try {
ssc = new SelfSignedCertificate();
sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
} catch (CertificateException e1) { e1.printStackTrace();
} catch (SSLException e1) { e1.printStackTrace(); }
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
@@ -75,7 +107,7 @@ public class RConServer implements Runnable {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInit())
.childHandler(new ChannelInit(sslCtx))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);