From 96a5287e5bacbdb9481829a2dd3098dc1b67da96 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 12 Nov 2012 17:21:09 +1100 Subject: [PATCH] Stab in dark at forge + more client mod support. --- src/main/java/net/md_5/bungee/InitialHandler.java | 12 +++++++----- src/main/java/net/md_5/bungee/ServerConnection.java | 9 +++++++-- src/main/java/net/md_5/bungee/UserConnection.java | 8 ++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/md_5/bungee/InitialHandler.java b/src/main/java/net/md_5/bungee/InitialHandler.java index 68f9f285c..b2f54ace0 100644 --- a/src/main/java/net/md_5/bungee/InitialHandler.java +++ b/src/main/java/net/md_5/bungee/InitialHandler.java @@ -3,6 +3,8 @@ package net.md_5.bungee; import java.io.IOException; import java.io.OutputStream; import java.net.Socket; +import java.util.ArrayList; +import java.util.List; import javax.crypto.SecretKey; import net.md_5.bungee.packet.Packet2Handshake; import net.md_5.bungee.packet.PacketFCEncryptionResponse; @@ -66,14 +68,14 @@ public class InitialHandler implements Runnable out.write(new PacketFCEncryptionResponse().getPacket()); in = new PacketInputStream(new CipherInputStream(socket.getInputStream(), EncryptionUtil.getCipher(false, shared))); out = new CipherOutputStream(socket.getOutputStream(), EncryptionUtil.getCipher(true, shared)); - - int ciphId = Util.getId(in.readPacket()); - if (ciphId != 0xCD) + List customPackets = new ArrayList<>(); + byte[] custom; + while (Util.getId((custom = in.readPacket())) != 0xCD) { - throw new KickException("Unable to receive encrypted client status"); + customPackets.add(custom); } - UserConnection userCon = new UserConnection(socket, in, out, handshake); + UserConnection userCon = new UserConnection(socket, in, out, handshake, customPackets); userCon.connect(BungeeCord.instance.config.getServer(handshake.username, handshake.host)); break; case 0xFE: diff --git a/src/main/java/net/md_5/bungee/ServerConnection.java b/src/main/java/net/md_5/bungee/ServerConnection.java index bccf87e39..5fd3fadfd 100644 --- a/src/main/java/net/md_5/bungee/ServerConnection.java +++ b/src/main/java/net/md_5/bungee/ServerConnection.java @@ -32,7 +32,7 @@ public class ServerConnection extends GenericConnection this.loginPacket = loginPacket; } - public static ServerConnection connect(String name, InetSocketAddress address, Packet2Handshake handshake, boolean retry) + public static ServerConnection connect(UserConnection user, String name, InetSocketAddress address, Packet2Handshake handshake, boolean retry) { try { @@ -61,6 +61,11 @@ public class ServerConnection extends GenericConnection in = new PacketInputStream(new CipherInputStream(socket.getInputStream(), EncryptionUtil.getCipher(false, myKey))); out = new CipherOutputStream(out, EncryptionUtil.getCipher(true, myKey)); + for (byte[] custom : user.loginPackets) + { + out.write(custom); + } + out.write(new PacketCDClientStatus((byte) 0).getPacket()); byte[] loginResponse = in.readPacket(); if (Util.getId(loginResponse) == 0xFF) @@ -79,7 +84,7 @@ public class ServerConnection extends GenericConnection InetSocketAddress def = BungeeCord.instance.config.getServer(null); if (retry && !address.equals(def)) { - return connect(name, def, handshake, false); + return connect(user, name, def, handshake, false); } else { throw new RuntimeException("Could not connect to target server"); diff --git a/src/main/java/net/md_5/bungee/UserConnection.java b/src/main/java/net/md_5/bungee/UserConnection.java index ab610a5ba..e9d3a2d5e 100644 --- a/src/main/java/net/md_5/bungee/UserConnection.java +++ b/src/main/java/net/md_5/bungee/UserConnection.java @@ -5,6 +5,8 @@ import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketAddress; +import java.util.ArrayList; +import java.util.List; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import net.md_5.bungee.command.CommandSender; @@ -24,6 +26,7 @@ public class UserConnection extends GenericConnection implements CommandSender public final Packet2Handshake handshake; public Queue packetQueue = new ConcurrentLinkedQueue<>(); + public List loginPackets = new ArrayList<>(); private ServerConnection server; private UpstreamBridge upBridge; private DownstreamBridge downBridge; @@ -36,11 +39,12 @@ public class UserConnection extends GenericConnection implements CommandSender private long pingTime; private int ping; - public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake) + public UserConnection(Socket socket, PacketInputStream in, OutputStream out, Packet2Handshake handshake, List loginPackets) { super(socket, in, out); this.handshake = handshake; username = handshake.username; + this.loginPackets = loginPackets; BungeeCord.instance.connections.put(username, this); BungeeCord.instance.tabListHandler.onJoin(this); } @@ -81,7 +85,7 @@ public class UserConnection extends GenericConnection implements CommandSender out.write(new Packet9Respawn((byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT").getPacket()); } - ServerConnection newServer = ServerConnection.connect(name, serverAddr, handshake, server == null); + ServerConnection newServer = ServerConnection.connect(this, name, serverAddr, handshake, server == null); if (server == null) { clientEntityId = newServer.loginPacket.entityId;