mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 11:15:47 +01:00
Nearly ready to get a working connection, however few hacks due to own shortcomings and netty shortcomings.
This commit is contained in:
parent
e12bc1d92e
commit
4fb85721a9
@ -14,6 +14,7 @@ import net.md_5.bungee.packet.PacketFFKick;
|
||||
public class ServerConnection implements Server
|
||||
{
|
||||
|
||||
@Getter
|
||||
private final Channel ch;
|
||||
@Getter
|
||||
private final ServerInfo info;
|
||||
|
@ -7,8 +7,11 @@ import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||
import net.md_5.bungee.connection.DownstreamBridge;
|
||||
import net.md_5.bungee.netty.HandlerBoss;
|
||||
import net.md_5.bungee.packet.DefinedPacket;
|
||||
import net.md_5.bungee.packet.Packet1Login;
|
||||
import net.md_5.bungee.packet.Packet2Handshake;
|
||||
import net.md_5.bungee.packet.Packet9Respawn;
|
||||
import net.md_5.bungee.packet.PacketCDClientStatus;
|
||||
import net.md_5.bungee.packet.PacketFDEncryptionRequest;
|
||||
@ -35,7 +38,8 @@ public class ServerConnector extends PacketHandler
|
||||
public void connected(Channel channel) throws Exception
|
||||
{
|
||||
this.ch = channel;
|
||||
channel.write( user.handshake );
|
||||
// TODO: Fix this crap
|
||||
channel.write( new Packet2Handshake( user.handshake.procolVersion, user.handshake.username, user.handshake.host, user.handshake.port ) );
|
||||
channel.write( PacketCDClientStatus.CLIENT_LOGIN );
|
||||
}
|
||||
|
||||
@ -91,6 +95,8 @@ public class ServerConnector extends PacketHandler
|
||||
user.getServer().disconnect( "Quitting" );
|
||||
user.getServer().getInfo().removePlayer( user );
|
||||
}
|
||||
|
||||
ch.pipeline().get( HandlerBoss.class ).setHandler( new DownstreamBridge( bungee, user ) );
|
||||
}
|
||||
|
||||
thisState = State.FINISHED;
|
||||
|
@ -33,7 +33,7 @@ public final class UserConnection implements ProxiedPlayer
|
||||
|
||||
public final Packet2Handshake handshake;
|
||||
private final ProxyServer bungee;
|
||||
private final Channel ch;
|
||||
public final Channel ch;
|
||||
final Packet1Login forgeLogin;
|
||||
final List<PacketFAPluginMessage> loginMessages;
|
||||
public Queue<DefinedPacket> packetQueue = new ConcurrentLinkedQueue<>();
|
||||
@ -69,7 +69,8 @@ public final class UserConnection implements ProxiedPlayer
|
||||
this.pendingConnection = pendingConnection;
|
||||
this.forgeLogin = forgeLogin;
|
||||
this.loginMessages = loginMessages;
|
||||
|
||||
this.name = handshake.username;
|
||||
this.displayName = name;
|
||||
|
||||
Collection<String> g = bungee.getConfigurationAdapter().getGroups( name );
|
||||
for ( String s : g )
|
||||
|
@ -3,7 +3,9 @@ package net.md_5.bungee.connection;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.EntityMap;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
@ -24,6 +26,13 @@ public class DownstreamBridge extends PacketHandler
|
||||
private final ProxyServer bungee;
|
||||
private final UserConnection con;
|
||||
|
||||
@Override
|
||||
public void handle(ByteBuf buf) throws Exception
|
||||
{
|
||||
EntityMap.rewrite( buf, con.serverEntityId, con.clientEntityId );
|
||||
con.ch.write( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Packet0KeepAlive alive) throws Exception
|
||||
{
|
||||
|
@ -177,10 +177,10 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
||||
}
|
||||
}
|
||||
|
||||
ch.write( new PacketFCEncryptionResponse() );
|
||||
|
||||
Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, shared );
|
||||
Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, shared );
|
||||
ch.write( new PacketFCEncryptionResponse() );
|
||||
ch.config().setAutoRead( false );
|
||||
ch.pipeline().addBefore( "decoder", "cipher", new CipherCodec( encrypt, decrypt ) );
|
||||
|
||||
thisState = InitialHandler.State.LOGIN;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.md_5.bungee.connection;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.md_5.bungee.EntityMap;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
@ -17,6 +19,13 @@ public class UpstreamBridge extends PacketHandler
|
||||
private final ProxyServer bungee;
|
||||
private final UserConnection con;
|
||||
|
||||
@Override
|
||||
public void handle(ByteBuf buf) throws Exception
|
||||
{
|
||||
EntityMap.rewrite( buf, con.clientEntityId, con.serverEntityId );
|
||||
con.getServer().getCh().write( buf );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Packet0KeepAlive alive) throws Exception
|
||||
{
|
||||
|
@ -33,9 +33,6 @@ public class CipherCodec extends ByteToByteCodec
|
||||
{
|
||||
heapOut = ctx.alloc().heapBuffer();
|
||||
}
|
||||
System.out.println( "e) in: " + in );
|
||||
System.out.println( "e) heapOut: " + heapOut );
|
||||
System.out.println( "e) out: " + out );
|
||||
cipher( encrypt, in, heapOut );
|
||||
out.writeBytes( heapOut );
|
||||
heapOut.discardSomeReadBytes();
|
||||
@ -44,9 +41,6 @@ public class CipherCodec extends ByteToByteCodec
|
||||
@Override
|
||||
public void decode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception
|
||||
{
|
||||
System.out.println( "d) in: " + in );
|
||||
System.out.println( "d) heapOut: " + heapOut );
|
||||
System.out.println( "d) out: " + out );
|
||||
cipher( decrypt, in, out );
|
||||
}
|
||||
|
||||
|
@ -51,17 +51,15 @@ public class HandlerBoss extends ChannelInboundMessageHandlerAdapter<ByteBuf>
|
||||
if ( packet != null )
|
||||
{
|
||||
packet.handle( handler );
|
||||
} else
|
||||
{
|
||||
handler.handle( msg );
|
||||
}
|
||||
handler.handle( msg );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception
|
||||
{
|
||||
System.out.println( handler + " " + Util.exception( cause ) );
|
||||
cause.printStackTrace();
|
||||
if ( ctx.channel().isActive() )
|
||||
{
|
||||
ctx.close();
|
||||
|
@ -11,7 +11,7 @@ public class Packet0KeepAlive extends DefinedPacket
|
||||
|
||||
public int id;
|
||||
|
||||
public Packet0KeepAlive(ByteBuf buf)
|
||||
Packet0KeepAlive(ByteBuf buf)
|
||||
{
|
||||
super( 0x00, buf );
|
||||
id = readInt();
|
||||
|
@ -29,7 +29,7 @@ public class Packet1Login extends DefinedPacket
|
||||
writeByte( maxPlayers );
|
||||
}
|
||||
|
||||
public Packet1Login(ByteBuf buf)
|
||||
Packet1Login(ByteBuf buf)
|
||||
{
|
||||
super( 0x01, buf );
|
||||
this.entityId = readInt();
|
||||
|
@ -23,7 +23,7 @@ public class Packet2Handshake extends DefinedPacket
|
||||
writeInt( port );
|
||||
}
|
||||
|
||||
public Packet2Handshake(ByteBuf buf)
|
||||
Packet2Handshake(ByteBuf buf)
|
||||
{
|
||||
super( 0x02, buf );
|
||||
this.procolVersion = readByte();
|
||||
|
@ -17,7 +17,7 @@ public class Packet3Chat extends DefinedPacket
|
||||
writeString( message );
|
||||
}
|
||||
|
||||
public Packet3Chat(ByteBuf buf)
|
||||
Packet3Chat(ByteBuf buf)
|
||||
{
|
||||
super( 0x03, buf );
|
||||
this.message = readString();
|
||||
|
@ -27,7 +27,7 @@ public class Packet9Respawn extends DefinedPacket
|
||||
writeString( levelType );
|
||||
}
|
||||
|
||||
public Packet9Respawn(ByteBuf buf)
|
||||
Packet9Respawn(ByteBuf buf)
|
||||
{
|
||||
super( 0x09, buf );
|
||||
this.dimension = readInt();
|
||||
|
@ -13,7 +13,7 @@ public class PacketC9PlayerListItem extends DefinedPacket
|
||||
public boolean online;
|
||||
public int ping;
|
||||
|
||||
public PacketC9PlayerListItem(ByteBuf buf)
|
||||
PacketC9PlayerListItem(ByteBuf buf)
|
||||
{
|
||||
super( 0xC9, buf );
|
||||
username = readString();
|
||||
|
@ -22,7 +22,7 @@ public class PacketCDClientStatus extends DefinedPacket
|
||||
writeByte( payload );
|
||||
}
|
||||
|
||||
public PacketCDClientStatus(ByteBuf buf)
|
||||
PacketCDClientStatus(ByteBuf buf)
|
||||
{
|
||||
super( 0xCD, buf );
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class PacketFAPluginMessage extends DefinedPacket
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public PacketFAPluginMessage(ByteBuf buf)
|
||||
PacketFAPluginMessage(ByteBuf buf)
|
||||
{
|
||||
super( 0xFA, buf );
|
||||
this.tag = readString();
|
||||
|
@ -26,7 +26,7 @@ public class PacketFCEncryptionResponse extends DefinedPacket
|
||||
writeArray( verifyToken );
|
||||
}
|
||||
|
||||
public PacketFCEncryptionResponse(ByteBuf buf)
|
||||
PacketFCEncryptionResponse(ByteBuf buf)
|
||||
{
|
||||
super( 0xFC, buf );
|
||||
this.sharedSecret = readArray();
|
||||
|
@ -24,7 +24,7 @@ public class PacketFDEncryptionRequest extends DefinedPacket
|
||||
this.verifyToken = verifyToken;
|
||||
}
|
||||
|
||||
public PacketFDEncryptionRequest(ByteBuf buf)
|
||||
PacketFDEncryptionRequest(ByteBuf buf)
|
||||
{
|
||||
super( 0xFD, buf );
|
||||
serverId = readString();
|
||||
|
@ -11,7 +11,7 @@ public class PacketFEPing extends DefinedPacket
|
||||
|
||||
public byte version;
|
||||
|
||||
public PacketFEPing(ByteBuf buffer)
|
||||
PacketFEPing(ByteBuf buffer)
|
||||
{
|
||||
super( 0xFE, buffer );
|
||||
version = readByte();
|
||||
|
@ -17,7 +17,7 @@ public class PacketFFKick extends DefinedPacket
|
||||
writeString( message );
|
||||
}
|
||||
|
||||
public PacketFFKick(ByteBuf buf)
|
||||
PacketFFKick(ByteBuf buf)
|
||||
{
|
||||
super( 0xFF, buf );
|
||||
this.message = readString();
|
||||
|
@ -6,11 +6,6 @@ import io.netty.channel.Channel;
|
||||
public abstract class PacketHandler
|
||||
{
|
||||
|
||||
private void nop(Object msg)
|
||||
{
|
||||
throw new UnsupportedOperationException( "No handler defined for packet " + msg.getClass() );
|
||||
}
|
||||
|
||||
public void connected(Channel channel) throws Exception
|
||||
{
|
||||
}
|
||||
@ -25,66 +20,53 @@ public abstract class PacketHandler
|
||||
|
||||
public void handle(ByteBuf buf) throws Exception
|
||||
{
|
||||
nop( buf );
|
||||
}
|
||||
|
||||
public void handle(Packet0KeepAlive alive) throws Exception
|
||||
{
|
||||
nop( alive );
|
||||
}
|
||||
|
||||
public void handle(Packet1Login login) throws Exception
|
||||
{
|
||||
nop( login );
|
||||
}
|
||||
|
||||
public void handle(Packet2Handshake handshake) throws Exception
|
||||
{
|
||||
nop( handshake );
|
||||
}
|
||||
|
||||
public void handle(Packet3Chat chat) throws Exception
|
||||
{
|
||||
nop( chat );
|
||||
}
|
||||
|
||||
public void handle(Packet9Respawn respawn) throws Exception
|
||||
{
|
||||
nop( respawn );
|
||||
}
|
||||
|
||||
public void handle(PacketC9PlayerListItem playerList) throws Exception
|
||||
{
|
||||
nop( playerList );
|
||||
}
|
||||
|
||||
public void handle(PacketCDClientStatus clientStatus) throws Exception
|
||||
{
|
||||
nop( clientStatus );
|
||||
}
|
||||
|
||||
public void handle(PacketFAPluginMessage pluginMessage) throws Exception
|
||||
{
|
||||
nop( pluginMessage );
|
||||
}
|
||||
|
||||
public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception
|
||||
{
|
||||
nop( encryptResponse );
|
||||
}
|
||||
|
||||
public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception
|
||||
{
|
||||
nop( encryptRequest );
|
||||
}
|
||||
|
||||
public void handle(PacketFEPing ping) throws Exception
|
||||
{
|
||||
nop( ping );
|
||||
}
|
||||
|
||||
public void handle(PacketFFKick kick) throws Exception
|
||||
{
|
||||
nop( kick );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user