mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-28 05:05:21 +01:00
Back to CR1 we go. Deal with the issues.
This commit is contained in:
parent
22133bc8d2
commit
a6ba661a32
2
pom.xml
2
pom.xml
@ -59,7 +59,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<build.number>unknown</build.number>
|
<build.number>unknown</build.number>
|
||||||
<netty.version>4.0.0.CR5</netty.version>
|
<netty.version>4.0.0.CR1</netty.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ public class BungeeCord extends ProxyServer
|
|||||||
* Thread pools.
|
* Thread pools.
|
||||||
*/
|
*/
|
||||||
public final ScheduledThreadPoolExecutor executors = new BungeeThreadPool( new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() );
|
public final ScheduledThreadPoolExecutor executors = new BungeeThreadPool( new ThreadFactoryBuilder().setNameFormat( "Bungee Pool Thread #%1$d" ).build() );
|
||||||
public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
|
public final MultithreadEventLoopGroup eventLoops = new NioEventLoopGroup( 0, new ThreadFactoryBuilder().setNameFormat( "Netty IO Thread #%1$d" ).build() );
|
||||||
/**
|
/**
|
||||||
* locations.yml save thread.
|
* locations.yml save thread.
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,6 @@ import net.md_5.bungee.netty.CipherDecoder;
|
|||||||
import net.md_5.bungee.netty.CipherEncoder;
|
import net.md_5.bungee.netty.CipherEncoder;
|
||||||
import net.md_5.bungee.netty.PacketDecoder;
|
import net.md_5.bungee.netty.PacketDecoder;
|
||||||
import net.md_5.bungee.netty.PacketHandler;
|
import net.md_5.bungee.netty.PacketHandler;
|
||||||
import net.md_5.bungee.netty.PipelineUtils;
|
|
||||||
import net.md_5.bungee.protocol.Forge;
|
import net.md_5.bungee.protocol.Forge;
|
||||||
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
import net.md_5.bungee.protocol.packet.DefinedPacket;
|
||||||
import net.md_5.bungee.protocol.packet.Packet1Login;
|
import net.md_5.bungee.protocol.packet.Packet1Login;
|
||||||
@ -175,7 +174,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|||||||
|
|
||||||
sharedKey = EncryptionUtil.getSecret( encryptResponse, request );
|
sharedKey = EncryptionUtil.getSecret( encryptResponse, request );
|
||||||
Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, sharedKey );
|
Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, sharedKey );
|
||||||
ch.getHandle().pipeline().addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) );
|
ch.getHandle().pipeline().addBefore( "decoder", "decrypt", new CipherDecoder( decrypt ) );
|
||||||
|
|
||||||
if ( BungeeCord.getInstance().config.isOnlineMode() )
|
if ( BungeeCord.getInstance().config.isOnlineMode() )
|
||||||
{
|
{
|
||||||
@ -248,7 +247,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey );
|
Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey );
|
||||||
ch.getHandle().pipeline().addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
|
ch.getHandle().pipeline().addBefore( "decoder", "encrypt", new CipherEncoder( encrypt ) );
|
||||||
} catch ( GeneralSecurityException ex )
|
} catch ( GeneralSecurityException ex )
|
||||||
{
|
{
|
||||||
disconnect( "Cipher error: " + Util.exception( ex ) );
|
disconnect( "Cipher error: " + Util.exception( ex ) );
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.md_5.bungee.netty;
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.crypto.ShortBufferException;
|
import javax.crypto.ShortBufferException;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
@ -52,21 +51,4 @@ public class CipherBase
|
|||||||
}
|
}
|
||||||
out.writeBytes( heapOut, 0, cipher.update( heapIn, 0, readableBytes, heapOut ) );
|
out.writeBytes( heapOut, 0, cipher.update( heapIn, 0, readableBytes, heapOut ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException
|
|
||||||
{
|
|
||||||
byte[] heapIn = heapInLocal.get();
|
|
||||||
int readableBytes = in.readableBytes();
|
|
||||||
if ( heapIn.length < readableBytes )
|
|
||||||
{
|
|
||||||
heapIn = new byte[ readableBytes ];
|
|
||||||
heapInLocal.set( heapIn );
|
|
||||||
}
|
|
||||||
in.readBytes( heapIn, 0, readableBytes );
|
|
||||||
|
|
||||||
ByteBuf out = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) );
|
|
||||||
out.writerIndex( cipher.update( heapIn, 0, readableBytes, out.array(), out.arrayOffset() ) );
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,10 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.MessageList;
|
import io.netty.handler.codec.ByteToByteDecoder;
|
||||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
public class CipherDecoder extends ByteToMessageDecoder
|
public class CipherDecoder extends ByteToByteDecoder
|
||||||
{
|
{
|
||||||
|
|
||||||
private final CipherBase cipher;
|
private final CipherBase cipher;
|
||||||
@ -17,8 +16,8 @@ public class CipherDecoder extends ByteToMessageDecoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList<Object> out) throws Exception
|
protected void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
|
||||||
{
|
{
|
||||||
out.add( cipher.cipher( ctx, in ) );
|
cipher.cipher( in, out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.handler.codec.MessageToByteEncoder;
|
import io.netty.handler.codec.ByteToByteEncoder;
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
|
|
||||||
public class CipherEncoder extends MessageToByteEncoder<ByteBuf>
|
public class CipherEncoder extends ByteToByteEncoder
|
||||||
{
|
{
|
||||||
|
|
||||||
private final CipherBase cipher;
|
private final CipherBase cipher;
|
||||||
@ -16,8 +16,8 @@ public class CipherEncoder extends MessageToByteEncoder<ByteBuf>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception
|
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
|
||||||
{
|
{
|
||||||
cipher.cipher( msg, out );
|
cipher.cipher( in, out );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ package net.md_5.bungee.netty;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
import io.netty.channel.MessageList;
|
|
||||||
import io.netty.handler.timeout.ReadTimeoutException;
|
import io.netty.handler.timeout.ReadTimeoutException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -17,7 +16,7 @@ import net.md_5.bungee.connection.PingHandler;
|
|||||||
* channels to maintain simple states, and only call the required, adapted
|
* channels to maintain simple states, and only call the required, adapted
|
||||||
* methods when the channel is connected.
|
* methods when the channel is connected.
|
||||||
*/
|
*/
|
||||||
public class HandlerBoss extends ChannelInboundHandlerAdapter
|
public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<Object>
|
||||||
{
|
{
|
||||||
|
|
||||||
private ChannelWrapper channel;
|
private ChannelWrapper channel;
|
||||||
@ -59,30 +58,27 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, MessageList<Object> msgs) throws Exception
|
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception
|
||||||
{
|
{
|
||||||
for ( Object msg : msgs )
|
if ( handler != null && ctx.channel().isActive() )
|
||||||
{
|
{
|
||||||
if ( handler != null && ctx.channel().isActive() )
|
if ( msg instanceof PacketWrapper )
|
||||||
{
|
{
|
||||||
if ( msg instanceof PacketWrapper )
|
boolean sendPacket = true;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
boolean sendPacket = true;
|
( (PacketWrapper) msg ).packet.handle( handler );
|
||||||
try
|
} catch ( CancelSendSignal ex )
|
||||||
{
|
|
||||||
( (PacketWrapper) msg ).packet.handle( handler );
|
|
||||||
} catch ( CancelSendSignal ex )
|
|
||||||
{
|
|
||||||
sendPacket = false;
|
|
||||||
}
|
|
||||||
if ( sendPacket )
|
|
||||||
{
|
|
||||||
handler.handle( ( (PacketWrapper) msg ).buf );
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
handler.handle( (byte[]) msg );
|
sendPacket = false;
|
||||||
}
|
}
|
||||||
|
if ( sendPacket )
|
||||||
|
{
|
||||||
|
handler.handle( ( (PacketWrapper) msg ).buf );
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
handler.handle( (byte[]) msg );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
package net.md_5.bungee.netty;
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelOutboundHandlerAdapter;
|
import io.netty.channel.ChannelOperationHandlerAdapter;
|
||||||
|
import io.netty.channel.ChannelPromise;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
|
|
||||||
public class OutboundBoss extends ChannelOutboundHandlerAdapter
|
public class OutboundBoss extends ChannelOperationHandlerAdapter
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void flush(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
|
||||||
|
{
|
||||||
|
ctx.flush( promise );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.md_5.bungee.netty;
|
package net.md_5.bungee.netty;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.MessageBuf;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.MessageList;
|
|
||||||
import io.netty.handler.codec.ReplayingDecoder;
|
import io.netty.handler.codec.ReplayingDecoder;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -28,7 +28,7 @@ public class PacketDecoder extends ReplayingDecoder<Void>
|
|||||||
private Protocol protocol;
|
private Protocol protocol;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, MessageList<Object> out) throws Exception
|
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
|
||||||
{
|
{
|
||||||
// While we have enough data
|
// While we have enough data
|
||||||
while ( true )
|
while ( true )
|
||||||
@ -53,10 +53,10 @@ public class PacketDecoder extends ReplayingDecoder<Void>
|
|||||||
// Store our decoded message
|
// Store our decoded message
|
||||||
if ( packet != null )
|
if ( packet != null )
|
||||||
{
|
{
|
||||||
out.add( new PacketWrapper( packet, buf ) );
|
return( new PacketWrapper( packet, buf ) );
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
out.add( buf );
|
return( buf );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import io.netty.channel.Channel;
|
|||||||
import io.netty.channel.ChannelException;
|
import io.netty.channel.ChannelException;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.handler.codec.bytes.ByteArrayEncoder;
|
import io.netty.handler.codec.bytes.ByteArrayEncoder;
|
||||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
import io.netty.util.AttributeKey;
|
import io.netty.util.AttributeKey;
|
||||||
|
Loading…
Reference in New Issue
Block a user