diff --git a/api/pom.xml b/api/pom.xml
index 1828ce78..cf923879 100644
--- a/api/pom.xml
+++ b/api/pom.xml
@@ -6,25 +6,19 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-api
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-API
API implemented by the Elastic Portal Suite
-
- com.google.guava
- guava
- 14.0.1
- compile
-
net.md-5
bungeecord-config
diff --git a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java
index 474391e1..b4894ab4 100644
--- a/api/src/main/java/net/md_5/bungee/api/ProxyServer.java
+++ b/api/src/main/java/net/md_5/bungee/api/ProxyServer.java
@@ -180,7 +180,7 @@ public abstract class ProxyServer
*
* @return the Minecraft protocol version
*/
- public abstract byte getProtocolVersion();
+ public abstract int getProtocolVersion();
/**
* Factory method to construct an implementation specific server info
diff --git a/api/src/main/java/net/md_5/bungee/api/ServerPing.java b/api/src/main/java/net/md_5/bungee/api/ServerPing.java
index e37f9aee..2458d133 100644
--- a/api/src/main/java/net/md_5/bungee/api/ServerPing.java
+++ b/api/src/main/java/net/md_5/bungee/api/ServerPing.java
@@ -1,33 +1,38 @@
package net.md_5.bungee.api;
+import lombok.AllArgsConstructor;
import lombok.Data;
+import lombok.NoArgsConstructor;
/**
* Represents the standard list data returned by opening a server in the
* Minecraft client server list, or hitting it with a packet 0xFE.
*/
@Data
+@NoArgsConstructor
+@AllArgsConstructor
public class ServerPing
{
- /**
- * Numeric protocol version supported by the server.
- */
- private final byte protocolVersion;
- /**
- * Human readable game version.
- */
- private final String gameVersion;
- /**
- * Server MOTD.
- */
- private final String motd;
- /**
- * Current amount of players on the server.
- */
- private final int currentPlayers;
- /**
- * Max amount of players the server will allow.
- */
- private final int maxPlayers;
+ private Protocol version;
+
+ @Data
+ @AllArgsConstructor
+ public static class Protocol
+ {
+
+ private String name;
+ private int protocol;
+ }
+ private Players players;
+
+ @Data
+ @AllArgsConstructor
+ public static class Players
+ {
+
+ private int max;
+ private int online;
+ }
+ private String description;
}
diff --git a/api/src/main/java/net/md_5/bungee/api/connection/Connection.java b/api/src/main/java/net/md_5/bungee/api/connection/Connection.java
index f0a3f504..2c9cae14 100644
--- a/api/src/main/java/net/md_5/bungee/api/connection/Connection.java
+++ b/api/src/main/java/net/md_5/bungee/api/connection/Connection.java
@@ -1,7 +1,7 @@
package net.md_5.bungee.api.connection;
import java.net.InetSocketAddress;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
+import net.md_5.bungee.protocol.DefinedPacket;
/**
* A proxy connection is defined as a connection directly connected to a socket.
diff --git a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java
index fba6e4f7..8513e8e3 100644
--- a/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java
+++ b/api/src/main/java/net/md_5/bungee/api/connection/PendingConnection.java
@@ -21,7 +21,7 @@ public interface PendingConnection extends Connection
*
* @return the protocol version of the remote client
*/
- byte getVersion();
+ int getVersion();
/**
* Get the requested virtual host that the client tried to connect to.
@@ -36,4 +36,11 @@ public interface PendingConnection extends Connection
* @return the accepting listener
*/
ListenerInfo getListener();
+
+ /**
+ * Get this connection's UUID, if set.
+ *
+ * @return the UUID
+ */
+ String getUUID();
}
diff --git a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
index 6ef00b28..bc5f6ee5 100644
--- a/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
+++ b/api/src/main/java/net/md_5/bungee/api/connection/ProxiedPlayer.java
@@ -99,4 +99,11 @@ public interface ProxiedPlayer extends Connection, CommandSender
* @param server the server to set
*/
void setReconnectServer(ServerInfo server);
+
+ /**
+ * Get this connection's UUID, if set.
+ *
+ * @return the UUID
+ */
+ String getUUID();
}
diff --git a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java
index de927325..2f7b38d9 100644
--- a/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java
+++ b/api/src/main/java/net/md_5/bungee/api/event/PlayerHandshakeEvent.java
@@ -4,8 +4,8 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import net.md_5.bungee.api.connection.PendingConnection;
-import net.md_5.bungee.protocol.packet.Packet2Handshake;
import net.md_5.bungee.api.plugin.Event;
+import net.md_5.bungee.protocol.packet.Handshake;
/**
* Event called to represent a player first making their presence and username
@@ -24,9 +24,9 @@ public class PlayerHandshakeEvent extends Event
/**
* The handshake.
*/
- private final Packet2Handshake handshake;
+ private final Handshake handshake;
- public PlayerHandshakeEvent(PendingConnection connection, Packet2Handshake handshake)
+ public PlayerHandshakeEvent(PendingConnection connection, Handshake handshake)
{
this.connection = connection;
this.handshake = handshake;
diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml
index f2107213..c81de384 100644
--- a/bootstrap/pom.xml
+++ b/bootstrap/pom.xml
@@ -6,13 +6,13 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-bootstrap
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-Bootstrap
diff --git a/config/pom.xml b/config/pom.xml
index 8c7e4cff..b96e3420 100644
--- a/config/pom.xml
+++ b/config/pom.xml
@@ -6,13 +6,13 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-config
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-Config
diff --git a/event/pom.xml b/event/pom.xml
index 51f10759..bb4a8313 100644
--- a/event/pom.xml
+++ b/event/pom.xml
@@ -6,13 +6,13 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-event
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-Event
diff --git a/pom.xml b/pom.xml
index 768bda2f..cf3da354 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
pom
BungeeCord
@@ -73,6 +73,18 @@
4.11
test
+
+ com.google.guava
+ guava
+ 14.0.1
+ compile
+
+
+ net.sf.trove4j
+ trove4j
+ 3.0.3
+ compile
+
org.projectlombok
lombok
diff --git a/protocol/pom.xml b/protocol/pom.xml
index e13e8062..545508d5 100644
--- a/protocol/pom.xml
+++ b/protocol/pom.xml
@@ -6,13 +6,13 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-protocol
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-Protocol
@@ -21,7 +21,7 @@
io.netty
- netty-buffer
+ netty-codec
${netty.version}
compile
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
new file mode 100644
index 00000000..08b12630
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/AbstractPacketHandler.java
@@ -0,0 +1,126 @@
+package net.md_5.bungee.protocol;
+
+import net.md_5.bungee.protocol.packet.KeepAlive;
+import net.md_5.bungee.protocol.packet.ClientSettings;
+import net.md_5.bungee.protocol.packet.ClientStatus;
+import net.md_5.bungee.protocol.packet.Login;
+import net.md_5.bungee.protocol.packet.Chat;
+import net.md_5.bungee.protocol.packet.EncryptionRequest;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
+import net.md_5.bungee.protocol.packet.TabCompleteRequest;
+import net.md_5.bungee.protocol.packet.ScoreboardObjective;
+import net.md_5.bungee.protocol.packet.ScoreboardScore;
+import net.md_5.bungee.protocol.packet.ScoreboardDisplay;
+import net.md_5.bungee.protocol.packet.Team;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.Kick;
+import net.md_5.bungee.protocol.packet.Respawn;
+import net.md_5.bungee.protocol.packet.Handshake;
+import net.md_5.bungee.protocol.packet.EncryptionResponse;
+import net.md_5.bungee.protocol.packet.LegacyPing;
+import net.md_5.bungee.protocol.packet.LoginRequest;
+import net.md_5.bungee.protocol.packet.LoginSuccess;
+import net.md_5.bungee.protocol.packet.PingPacket;
+import net.md_5.bungee.protocol.packet.StatusRequest;
+import net.md_5.bungee.protocol.packet.StatusResponse;
+import net.md_5.bungee.protocol.packet.TabCompleteResponse;
+
+public abstract class AbstractPacketHandler
+{
+
+ public void handle(LegacyPing ping) throws Exception
+ {
+ }
+
+ public void handle(TabCompleteResponse tabResponse) throws Exception
+ {
+ }
+
+ public void handle(PingPacket ping) throws Exception
+ {
+ }
+
+ public void handle(StatusRequest statusRequest) throws Exception
+ {
+ }
+
+ public void handle(StatusResponse statusResponse) throws Exception
+ {
+ }
+
+ public void handle(Handshake handshake) throws Exception
+ {
+ }
+
+ public void handle(KeepAlive keepAlive) throws Exception
+ {
+ }
+
+ public void handle(Login login) throws Exception
+ {
+ }
+
+ public void handle(Chat chat) throws Exception
+ {
+ }
+
+ public void handle(Respawn respawn) throws Exception
+ {
+ }
+
+ public void handle(LoginRequest loginRequest) throws Exception
+ {
+ }
+
+ public void handle(ClientSettings settings) throws Exception
+ {
+ }
+
+ public void handle(ClientStatus clientStatus) throws Exception
+ {
+ }
+
+ public void handle(PlayerListItem playerListItem) throws Exception
+ {
+ }
+
+ public void handle(TabCompleteRequest tabComplete) throws Exception
+ {
+ }
+
+ public void handle(ScoreboardObjective scoreboardObjective) throws Exception
+ {
+ }
+
+ public void handle(ScoreboardScore scoreboardScore) throws Exception
+ {
+ }
+
+ public void handle(EncryptionRequest encryptionRequest) throws Exception
+ {
+ }
+
+ public void handle(ScoreboardDisplay displayScoreboard) throws Exception
+ {
+ }
+
+ public void handle(Team team) throws Exception
+ {
+ }
+
+ public void handle(PluginMessage pluginMessage) throws Exception
+ {
+ }
+
+ public void handle(Kick kick) throws Exception
+ {
+ }
+
+ public void handle(EncryptionResponse encryptionResponse) throws Exception
+ {
+ }
+
+ public void handle(LoginSuccess loginSuccess) throws Exception
+ {
+ }
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java b/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java
index 523aeafc..6c0ef4df 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/BadPacketException.java
@@ -7,4 +7,9 @@ public class BadPacketException extends RuntimeException
{
super( message );
}
+
+ public BadPacketException(String message, Throwable cause)
+ {
+ super( message, cause );
+ }
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
new file mode 100644
index 00000000..3cc2a54a
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
@@ -0,0 +1,125 @@
+package net.md_5.bungee.protocol;
+
+import com.google.common.base.Charsets;
+import io.netty.buffer.ByteBuf;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
+public abstract class DefinedPacket
+{
+
+ public static void writeString(String s, ByteBuf buf)
+ {
+ // TODO: Check len - use Guava?
+ byte[] b = s.getBytes( Charsets.UTF_8 );
+ writeVarInt( b.length, buf );
+ buf.writeBytes( b );
+ }
+
+ public static String readString(ByteBuf buf)
+ {
+ int len = readVarInt( buf );
+ byte[] b = new byte[ len ];
+ buf.readBytes( b );
+
+ return new String( b, Charsets.UTF_8 );
+ }
+
+ public static void writeArray(byte[] b, ByteBuf buf)
+ {
+ // TODO: Check len - use Guava?
+ buf.writeShort( b.length );
+ buf.writeBytes( b );
+ }
+
+ public static byte[] readArray(ByteBuf buf)
+ {
+ // TODO: Check len - use Guava?
+ short len = buf.readShort();
+ byte[] ret = new byte[ len ];
+ buf.readBytes( ret );
+ return ret;
+ }
+
+ public static void writeStringArray(String[] s, ByteBuf buf)
+ {
+ writeVarInt( s.length, buf );
+ for ( String str : s )
+ {
+ writeString( str, buf );
+ }
+ }
+
+ public static String[] readStringArray(ByteBuf buf)
+ {
+ int len = readVarInt( buf );
+ String[] ret = new String[ len ];
+ for ( int i = 0; i < ret.length; i++ )
+ {
+ ret[i] = readString( buf );
+ }
+ return ret;
+ }
+
+ public static int readVarInt(ByteBuf input)
+ {
+ int out = 0;
+ int bytes = 0;
+ byte in;
+ while ( true )
+ {
+ in = input.readByte();
+
+ out |= ( in & 0x7F ) << ( bytes++ * 7 );
+
+ if ( bytes > 32 )
+ {
+ throw new RuntimeException( "VarInt too big" );
+ }
+
+ if ( ( in & 0x80 ) != 0x80 )
+ {
+ break;
+ }
+ }
+
+ return out;
+ }
+
+ public static void writeVarInt(int value, ByteBuf output)
+ {
+ int part;
+ while ( true )
+ {
+ part = value & 0x7F;
+
+ value >>>= 7;
+ if ( value != 0 )
+ {
+ part |= 0x80;
+ }
+
+ output.writeByte( part );
+
+ if ( value == 0 )
+ {
+ break;
+ }
+ }
+ }
+
+ public abstract void read(ByteBuf buf);
+
+ public abstract void write(ByteBuf buf);
+
+ public abstract void handle(AbstractPacketHandler handler) throws Exception;
+
+ @Override
+ public abstract boolean equals(Object obj);
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract String toString();
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java b/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
deleted file mode 100644
index a5707e84..00000000
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Forge.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package net.md_5.bungee.protocol;
-
-import io.netty.buffer.ByteBuf;
-import lombok.Getter;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.forge.Forge1Login;
-import net.md_5.bungee.protocol.skip.PacketReader;
-
-public class Forge extends Vanilla
-{
-
- @Getter
- private static final Forge instance = new Forge();
-
- public Forge()
- {
- classes[0x01] = Forge1Login.class;
- skipper = new PacketReader( this ); // TODO: :(
- }
-
- @Override
- public DefinedPacket read(short packetId, ByteBuf buf)
- {
- int start = buf.readerIndex();
- DefinedPacket packet = read( packetId, buf, this );
- if ( buf.readerIndex() == start )
- {
- packet = super.read( packetId, buf );
- }
-
- return packet;
- }
-}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java b/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java
new file mode 100644
index 00000000..eda9571e
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/KickStringWriter.java
@@ -0,0 +1,20 @@
+package net.md_5.bungee.protocol;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToByteEncoder;
+
+public class KickStringWriter extends MessageToByteEncoder
+{
+
+ @Override
+ protected void encode(ChannelHandlerContext ctx, String msg, ByteBuf out) throws Exception
+ {
+ out.writeByte( 0xFF );
+ out.writeShort( msg.length() );
+ for ( char c : msg.toCharArray() )
+ {
+ out.writeChar( c );
+ }
+ }
+}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java
new file mode 100644
index 00000000..7cc06d9b
--- /dev/null
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/LegacyDecoder.java
@@ -0,0 +1,31 @@
+package net.md_5.bungee.protocol;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.ByteToMessageDecoder;
+import java.util.List;
+import net.md_5.bungee.protocol.packet.LegacyPing;
+
+public class LegacyDecoder extends ByteToMessageDecoder
+{
+
+ @Override
+ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List
-
- net.sf.trove4j
- trove4j
- 3.0.3
- compile
-
mysql
mysql-connector-java
diff --git a/proxy/src/main/java/Test.java b/proxy/src/main/java/Test.java
new file mode 100644
index 00000000..cc08bad4
--- /dev/null
+++ b/proxy/src/main/java/Test.java
@@ -0,0 +1,40 @@
+
+import net.md_5.bungee.BungeeCord;
+import net.md_5.bungee.api.ChatColor;
+import net.md_5.bungee.api.ProxyServer;
+import net.md_5.bungee.command.ConsoleCommandSender;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+/**
+ *
+ * @author michael
+ */
+public class Test
+{
+
+ public static void main(String[] args) throws Exception
+ {
+
+ System.setProperty( "java.net.preferIPv4Stack", "true" );
+
+ BungeeCord bungee = new BungeeCord();
+ ProxyServer.setInstance( bungee );
+ bungee.getLogger().info( "Enabled BungeeCord version " + bungee.getVersion() );
+ bungee.start();
+
+ while ( bungee.isRunning )
+ {
+ String line = bungee.getConsoleReader().readLine( ">" );
+ if ( line != null )
+ {
+ if ( !bungee.getPluginManager().dispatchCommand( ConsoleCommandSender.getInstance(), line ) )
+ {
+ bungee.getConsole().sendMessage( ChatColor.RED + "Command not found" );
+ }
+ }
+ }
+ }
+}
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
index f6bf1e0c..badcac32 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java
@@ -57,10 +57,10 @@ import net.md_5.bungee.command.*;
import net.md_5.bungee.config.YamlConfig;
import net.md_5.bungee.log.LoggingOutputStream;
import net.md_5.bungee.netty.PipelineUtils;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.Packet3Chat;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.Vanilla;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.Protocol;
+import net.md_5.bungee.protocol.packet.Chat;
+import net.md_5.bungee.protocol.packet.PluginMessage;
import net.md_5.bungee.query.RemoteQuery;
import net.md_5.bungee.tab.Custom;
import net.md_5.bungee.util.CaseInsensitiveMap;
@@ -448,21 +448,21 @@ public class BungeeCord extends ProxyServer
return Collections.unmodifiableCollection( pluginChannels );
}
- public PacketFAPluginMessage registerChannels()
+ public PluginMessage registerChannels()
{
- return new PacketFAPluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() );
+ return new PluginMessage( "REGISTER", Util.format( pluginChannels, "\00" ).getBytes() );
}
@Override
- public byte getProtocolVersion()
+ public int getProtocolVersion()
{
- return Vanilla.PROTOCOL_VERSION;
+ return Protocol.PROTOCOL_VERSION;
}
@Override
public String getGameVersion()
{
- return Vanilla.GAME_VERSION;
+ return Protocol.MINECRAFT_VERSION;
}
@Override
@@ -483,7 +483,7 @@ public class BungeeCord extends ProxyServer
getConsole().sendMessage( message );
// TODO: Here too
String encoded = BungeeCord.getInstance().gson.toJson( message );
- broadcast( new Packet3Chat( "{\"text\":" + encoded + "}" ) );
+ broadcast( new Chat( "{\"text\":" + encoded + "}" ) );
}
public void addConnection(UserConnection con)
diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
index 489b2082..48e46ed1 100644
--- a/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
+++ b/proxy/src/main/java/net/md_5/bungee/BungeeServerInfo.java
@@ -25,8 +25,8 @@ import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.connection.PingHandler;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.PipelineUtils;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.packet.PluginMessage;
@RequiredArgsConstructor
public class BungeeServerInfo implements ServerInfo
@@ -97,7 +97,7 @@ public class BungeeServerInfo implements ServerInfo
server.sendData( channel, data );
} else
{
- packetQueue.add( new PacketFAPluginMessage( channel, data ) );
+ packetQueue.add( new PluginMessage( channel, data ) );
}
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java
index 046a84d2..eb7fe4f1 100644
--- a/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java
+++ b/proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java
@@ -15,8 +15,8 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
-import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
-import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
+import net.md_5.bungee.protocol.packet.EncryptionResponse;
+import net.md_5.bungee.protocol.packet.EncryptionRequest;
/**
* Class containing all encryption related methods for the proxy.
@@ -40,16 +40,16 @@ public class EncryptionUtil
}
}
- public static PacketFDEncryptionRequest encryptRequest(boolean onlinemode)
+ public static EncryptionRequest encryptRequest()
{
- String hash = ( onlinemode ) ? Long.toString( random.nextLong(), 16 ) : "-";
+ String hash = Long.toString( random.nextLong(), 16 );
byte[] pubKey = keys.getPublic().getEncoded();
byte[] verify = new byte[ 4 ];
random.nextBytes( verify );
- return new PacketFDEncryptionRequest( hash, pubKey, verify );
+ return new EncryptionRequest( hash, pubKey, verify );
}
- public static SecretKey getSecret(PacketFCEncryptionResponse resp, PacketFDEncryptionRequest request) throws GeneralSecurityException
+ public static SecretKey getSecret(EncryptionResponse resp, EncryptionRequest request) throws GeneralSecurityException
{
Cipher cipher = Cipher.getInstance( "RSA" );
cipher.init( Cipher.DECRYPT_MODE, keys.getPrivate() );
@@ -71,7 +71,7 @@ public class EncryptionUtil
return cip;
}
- public static PublicKey getPubkey(PacketFDEncryptionRequest request) throws GeneralSecurityException
+ public static PublicKey getPubkey(EncryptionRequest request) throws GeneralSecurityException
{
return KeyFactory.getInstance( "RSA" ).generatePublic( new X509EncodedKeySpec( request.getPublicKey() ) );
}
diff --git a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java
index e63212da..82814b07 100644
--- a/proxy/src/main/java/net/md_5/bungee/PacketConstants.java
+++ b/proxy/src/main/java/net/md_5/bungee/PacketConstants.java
@@ -1,18 +1,18 @@
package net.md_5.bungee;
-import net.md_5.bungee.protocol.packet.Packet9Respawn;
-import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
+import net.md_5.bungee.protocol.packet.Respawn;
+import net.md_5.bungee.protocol.packet.ClientStatus;
+import net.md_5.bungee.protocol.packet.PluginMessage;
public class PacketConstants
{
- public static final Packet9Respawn DIM1_SWITCH = new Packet9Respawn( (byte) 1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
- public static final Packet9Respawn DIM2_SWITCH = new Packet9Respawn( (byte) -1, (byte) 0, (byte) 0, (short) 256, "DEFAULT" );
- public static final PacketCDClientStatus CLIENT_LOGIN = new PacketCDClientStatus( (byte) 0 );
- public static final PacketFAPluginMessage FORGE_MOD_REQUEST = new PacketFAPluginMessage( "FML", new byte[]
+ public static final Respawn DIM1_SWITCH = new Respawn( (byte) 1, (byte) 0, (byte) 0, "default" );
+ public static final Respawn DIM2_SWITCH = new Respawn( (byte) -1, (byte) 0, (byte) 0, "default" );
+ public static final ClientStatus CLIENT_LOGIN = new ClientStatus( (byte) 0 );
+ public static final PluginMessage FORGE_MOD_REQUEST = new PluginMessage( "FML", new byte[]
{
0, 0, 0, 0, 0, 2
} );
- public static final PacketFAPluginMessage I_AM_BUNGEE = new PacketFAPluginMessage( "BungeeCord", new byte[ 0 ] );
+ public static final PluginMessage I_AM_BUNGEE = new PluginMessage( "BungeeCord", new byte[ 0 ] );
}
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java
index 555b0ff4..b5c5af50 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnection.java
@@ -7,9 +7,9 @@ import lombok.RequiredArgsConstructor;
import lombok.Setter;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.netty.ChannelWrapper;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.Kick;
@RequiredArgsConstructor
public class ServerConnection implements Server
@@ -34,7 +34,7 @@ public class ServerConnection implements Server
@Override
public void sendData(String channel, byte[] data)
{
- unsafe().sendPacket( new PacketFAPluginMessage( channel, data ) );
+ unsafe().sendPacket( new PluginMessage( channel, data ) );
}
@Override
@@ -43,7 +43,7 @@ public class ServerConnection implements Server
if ( !ch.isClosed() )
{
// TODO: Can we just use a future here?
- unsafe().sendPacket( new PacketFFKick( reason ) );
+ unsafe().sendPacket( new Kick( reason ) );
ch.getHandle().eventLoop().schedule( new Runnable()
{
@Override
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
index a410ff5f..d56e0f5e 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -3,12 +3,8 @@ package net.md_5.bungee;
import com.google.common.base.Preconditions;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
-import java.io.DataInput;
-import java.security.PublicKey;
import java.util.Objects;
import java.util.Queue;
-import javax.crypto.Cipher;
-import javax.crypto.SecretKey;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
@@ -23,23 +19,16 @@ import net.md_5.bungee.connection.CancelSendSignal;
import net.md_5.bungee.connection.DownstreamBridge;
import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.ChannelWrapper;
-import net.md_5.bungee.netty.CipherDecoder;
-import net.md_5.bungee.netty.CipherEncoder;
-import net.md_5.bungee.netty.PacketDecoder;
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.MinecraftOutput;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.Packet1Login;
-import net.md_5.bungee.protocol.packet.Packet9Respawn;
-import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
-import net.md_5.bungee.protocol.packet.PacketD1Team;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
-import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
-import net.md_5.bungee.protocol.packet.forge.Forge1Login;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.Protocol;
+import net.md_5.bungee.protocol.packet.Login;
+import net.md_5.bungee.protocol.packet.Respawn;
+import net.md_5.bungee.protocol.packet.ScoreboardObjective;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.Kick;
+import net.md_5.bungee.protocol.packet.LoginSuccess;
@RequiredArgsConstructor
public class ServerConnector extends PacketHandler
@@ -49,14 +38,12 @@ public class ServerConnector extends PacketHandler
private ChannelWrapper ch;
private final UserConnection user;
private final BungeeServerInfo target;
- private State thisState = State.ENCRYPT_REQUEST;
- private SecretKey secretkey;
- private boolean sentMessages;
+ private State thisState = State.LOGIN_SUCCESS;
private enum State
{
- ENCRYPT_REQUEST, ENCRYPT_RESPONSE, LOGIN, FINISHED;
+ LOGIN_SUCCESS, ENCRYPT_RESPONSE, LOGIN, FINISHED;
}
@Override
@@ -81,15 +68,12 @@ public class ServerConnector extends PacketHandler
out.writeUTF( "Login" );
out.writeUTF( user.getAddress().getHostString() );
out.writeInt( user.getAddress().getPort() );
- channel.write( new PacketFAPluginMessage( "BungeeCord", out.toByteArray() ) );
+ // channel.write( new PluginMessage( "BungeeCord", out.toByteArray() ) ); MOJANG
channel.write( user.getPendingConnection().getHandshake() );
- // Skip encryption if we are not using Forge
- if ( user.getPendingConnection().getForgeLogin() == null )
- {
- channel.write( PacketConstants.CLIENT_LOGIN );
- }
+ channel.setProtocol( Protocol.LOGIN );
+ channel.write( user.getPendingConnection().getLoginRequest() );
}
@Override
@@ -99,7 +83,17 @@ public class ServerConnector extends PacketHandler
}
@Override
- public void handle(Packet1Login login) throws Exception
+ public void handle(LoginSuccess loginSuccess) throws Exception
+ {
+ Preconditions.checkState( thisState == State.LOGIN_SUCCESS, "Not exepcting LOGIN_SUCCESS" );
+ ch.setProtocol( Protocol.GAME );
+ thisState = State.LOGIN;
+
+ throw new CancelSendSignal();
+ }
+
+ @Override
+ public void handle(Login login) throws Exception
{
Preconditions.checkState( thisState == State.LOGIN, "Not exepcting LOGIN" );
@@ -117,17 +111,10 @@ public class ServerConnector extends PacketHandler
}
}
- for ( PacketFAPluginMessage message : user.getPendingConnection().getRegisterMessages() )
+ for ( PluginMessage message : user.getPendingConnection().getRegisterMessages() )
{
ch.write( message );
}
- if ( !sentMessages )
- {
- for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() )
- {
- ch.write( message );
- }
- }
if ( user.getSettings() != null )
{
@@ -143,21 +130,14 @@ public class ServerConnector extends PacketHandler
user.setServerEntityId( login.getEntityId() );
// Set tab list size, this sucks balls, TODO: what shall we do about packet mutability
- Packet1Login modLogin;
- if ( ch.getHandle().pipeline().get( PacketDecoder.class ).getProtocol() == Forge.getInstance() )
- {
- modLogin = new Forge1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), login.getDimension(), login.getDifficulty(), login.getUnused(),
- (byte) user.getPendingConnection().getListener().getTabListSize() );
- } else
- {
- modLogin = new Packet1Login( login.getEntityId(), login.getLevelType(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(), login.getUnused(),
- (byte) user.getPendingConnection().getListener().getTabListSize() );
- }
+ Login modLogin = new Login( login.getEntityId(), login.getGameMode(), (byte) login.getDimension(), login.getDifficulty(),
+ (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType() );
+
user.unsafe().sendPacket( modLogin );
MinecraftOutput out = new MinecraftOutput();
out.writeStringUTF8WithoutLengthHeaderBecauseDinnerboneStuffedUpTheMCBrandPacket( ProxyServer.getInstance().getName() + " (" + ProxyServer.getInstance().getVersion() + ")" );
- user.unsafe().sendPacket( new PacketFAPluginMessage( "MC|Brand", out.toArray() ) );
+ user.unsafe().sendPacket( new PluginMessage( "MC|Brand", out.toArray() ) );
} else
{
user.getTabList().onServerChange();
@@ -165,18 +145,18 @@ public class ServerConnector extends PacketHandler
Scoreboard serverScoreboard = user.getServerSentScoreboard();
for ( Objective objective : serverScoreboard.getObjectives() )
{
- user.unsafe().sendPacket( new PacketCEScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) );
+ user.unsafe().sendPacket( new ScoreboardObjective( objective.getName(), objective.getValue(), (byte) 1 ) );
}
for ( Team team : serverScoreboard.getTeams() )
{
- user.unsafe().sendPacket( new PacketD1Team( team.getName() ) );
+ user.unsafe().sendPacket( new net.md_5.bungee.protocol.packet.Team( team.getName() ) );
}
serverScoreboard.clear();
user.sendDimensionSwitch();
user.setServerEntityId( login.getEntityId() );
- user.unsafe().sendPacket( new Packet9Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), (short) 256, login.getLevelType() ) );
+ user.unsafe().sendPacket( new Respawn( login.getDimension(), login.getDifficulty(), login.getGameMode(), login.getLevelType() ) );
// Remove from old servers
user.getServer().setObsolete( true );
@@ -209,47 +189,7 @@ public class ServerConnector extends PacketHandler
}
@Override
- public void handle(PacketFDEncryptionRequest encryptRequest) throws Exception
- {
- Preconditions.checkState( thisState == State.ENCRYPT_REQUEST, "Not expecting ENCRYPT_REQUEST" );
-
- // Only need to handle this if we want to use encryption
- if ( user.getPendingConnection().getForgeLogin() != null )
- {
- PublicKey publickey = EncryptionUtil.getPubkey( encryptRequest );
- this.secretkey = EncryptionUtil.getSecret();
-
- byte[] shared = EncryptionUtil.encrypt( publickey, secretkey.getEncoded() );
- byte[] token = EncryptionUtil.encrypt( publickey, encryptRequest.getVerifyToken() );
-
- ch.write( new PacketFCEncryptionResponse( shared, token ) );
-
- Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, secretkey );
- ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
-
- thisState = State.ENCRYPT_RESPONSE;
- } else
- {
- thisState = State.LOGIN;
- }
- }
-
- @Override
- public void handle(PacketFCEncryptionResponse encryptResponse) throws Exception
- {
- Preconditions.checkState( thisState == State.ENCRYPT_RESPONSE, "Not expecting ENCRYPT_RESPONSE" );
-
- Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, secretkey );
- ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) );
-
- ch.write( user.getPendingConnection().getForgeLogin() );
-
- ch.write( PacketConstants.CLIENT_LOGIN );
- thisState = State.LOGIN;
- }
-
- @Override
- public void handle(PacketFFKick kick) throws Exception
+ public void handle(Kick kick) throws Exception
{
ServerInfo def = bungee.getServerInfo( user.getPendingConnection().getListener().getFallbackServer() );
if ( Objects.equals( target, def ) )
@@ -273,40 +213,6 @@ public class ServerConnector extends PacketHandler
}
}
- @Override
- public void handle(PacketFAPluginMessage pluginMessage) throws Exception
- {
- if ( pluginMessage.equals( PacketConstants.I_AM_BUNGEE ) )
- {
- throw new IllegalStateException( "May not connect to another BungeCord!" );
- }
-
- DataInput in = pluginMessage.getStream();
- if ( pluginMessage.getTag().equals( "FML" ) && in.readUnsignedByte() == 0 )
- {
- int count = in.readInt();
- for ( int i = 0; i < count; i++ )
- {
- in.readUTF();
- }
- if ( in.readByte() != 0 )
- {
- // TODO: Using forge flag
- ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Forge.getInstance() );
- }
- }
-
- user.unsafe().sendPacket( pluginMessage ); // We have to forward these to the user, especially with Forge as stuff might break
- if ( !sentMessages && user.getPendingConnection().getForgeLogin() != null )
- {
- for ( PacketFAPluginMessage message : user.getPendingConnection().getLoginMessages() )
- {
- ch.write( message );
- }
- sentMessages = true;
- }
- }
-
@Override
public String toString()
{
diff --git a/proxy/src/main/java/net/md_5/bungee/UserConnection.java b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
index 9dec6c59..fa19f25b 100644
--- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java
+++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java
@@ -19,7 +19,6 @@ import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
-import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -30,13 +29,16 @@ import net.md_5.bungee.api.tab.TabListHandler;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.HandlerBoss;
-import net.md_5.bungee.netty.PacketWrapper;
+import net.md_5.bungee.protocol.PacketWrapper;
import net.md_5.bungee.netty.PipelineUtils;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.Packet3Chat;
-import net.md_5.bungee.protocol.packet.PacketCCSettings;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.MinecraftDecoder;
+import net.md_5.bungee.protocol.MinecraftEncoder;
+import net.md_5.bungee.protocol.Protocol;
+import net.md_5.bungee.protocol.packet.Chat;
+import net.md_5.bungee.protocol.packet.ClientSettings;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.Kick;
import net.md_5.bungee.util.CaseInsensitiveSet;
@RequiredArgsConstructor
@@ -88,7 +90,7 @@ public final class UserConnection implements ProxiedPlayer
private int serverEntityId;
@Getter
@Setter
- private PacketCCSettings settings;
+ private ClientSettings settings;
@Getter
private final Scoreboard serverSentScoreboard = new Scoreboard();
/*========================================================================*/
@@ -200,6 +202,8 @@ public final class UserConnection implements ProxiedPlayer
protected void initChannel(Channel ch) throws Exception
{
PipelineUtils.BASE.initChannel( ch );
+ ch.pipeline().addAfter( PipelineUtils.FRAME_DECODER, PipelineUtils.PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, false ) );
+ ch.pipeline().addAfter( PipelineUtils.FRAME_PREPENDER, PipelineUtils.PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, false ) );
ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( bungee, UserConnection.this, target ) );
}
};
@@ -251,7 +255,7 @@ public final class UserConnection implements ProxiedPlayer
if ( ch.getHandle().isActive() )
{
bungee.getLogger().log( Level.INFO, "[" + getName() + "] disconnected with: " + reason );
- unsafe().sendPacket( new PacketFFKick( reason ) );
+ unsafe().sendPacket( new Kick( reason ) );
ch.close();
if ( server != null )
{
@@ -264,7 +268,7 @@ public final class UserConnection implements ProxiedPlayer
public void chat(String message)
{
Preconditions.checkState( server != null, "Not connected to server" );
- server.getCh().write( new Packet3Chat( message ) );
+ server.getCh().write( new Chat( message ) );
}
@Override
@@ -272,7 +276,7 @@ public final class UserConnection implements ProxiedPlayer
{
// TODO: Fix this
String encoded = BungeeCord.getInstance().gson.toJson( message );
- unsafe().sendPacket( new Packet3Chat( "{\"text\":" + encoded + "}" ) );
+ unsafe().sendPacket( new Chat( "{\"text\":" + encoded + "}" ) );
}
@Override
@@ -287,7 +291,7 @@ public final class UserConnection implements ProxiedPlayer
@Override
public void sendData(String channel, byte[] data)
{
- unsafe().sendPacket( new PacketFAPluginMessage( channel, data ) );
+ unsafe().sendPacket( new PluginMessage( channel, data ) );
}
@Override
@@ -357,4 +361,10 @@ public final class UserConnection implements ProxiedPlayer
{
return unsafe;
}
+
+ @Override
+ public String getUUID()
+ {
+ return getPendingConnection().getUUID();
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
index 2e9286d8..d39410c9 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -21,15 +21,14 @@ import net.md_5.bungee.api.score.Scoreboard;
import net.md_5.bungee.api.score.Team;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
-import net.md_5.bungee.netty.PacketWrapper;
-import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
-import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
-import net.md_5.bungee.protocol.packet.PacketCEScoreboardObjective;
-import net.md_5.bungee.protocol.packet.PacketCFScoreboardScore;
-import net.md_5.bungee.protocol.packet.PacketD0DisplayScoreboard;
-import net.md_5.bungee.protocol.packet.PacketD1Team;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
+import net.md_5.bungee.protocol.PacketWrapper;
+import net.md_5.bungee.protocol.packet.KeepAlive;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
+import net.md_5.bungee.protocol.packet.ScoreboardObjective;
+import net.md_5.bungee.protocol.packet.ScoreboardScore;
+import net.md_5.bungee.protocol.packet.ScoreboardDisplay;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.Kick;
@RequiredArgsConstructor
public class DownstreamBridge extends PacketHandler
@@ -75,20 +74,20 @@ public class DownstreamBridge extends PacketHandler
{
if ( !server.isObsolete() )
{
- EntityMap.rewrite( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
+ // EntityMap.rewrite( packet.buf, con.getServerEntityId(), con.getClientEntityId() );
con.sendPacket( packet );
}
}
@Override
- public void handle(Packet0KeepAlive alive) throws Exception
+ public void handle(KeepAlive alive) throws Exception
{
con.setSentPingId( alive.getRandomId() );
con.setSentPingTime( System.currentTimeMillis() );
}
@Override
- public void handle(PacketC9PlayerListItem playerList) throws Exception
+ public void handle(PlayerListItem playerList) throws Exception
{
if ( !con.getTabList().onListUpdate( playerList.getUsername(), playerList.isOnline(), playerList.getPing() ) )
@@ -98,7 +97,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketCEScoreboardObjective objective) throws Exception
+ public void handle(ScoreboardObjective objective) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( objective.getAction() )
@@ -113,7 +112,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketCFScoreboardScore score) throws Exception
+ public void handle(ScoreboardScore score) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
switch ( score.getAction() )
@@ -130,7 +129,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketD0DisplayScoreboard displayScoreboard) throws Exception
+ public void handle(ScoreboardDisplay displayScoreboard) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
serverScoreboard.setName( displayScoreboard.getName() );
@@ -138,7 +137,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketD1Team team) throws Exception
+ public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception
{
Scoreboard serverScoreboard = con.getServerSentScoreboard();
// Remove team and move on
@@ -185,7 +184,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketFAPluginMessage pluginMessage) throws Exception
+ public void handle(PluginMessage pluginMessage) throws Exception
{
DataInput in = pluginMessage.getStream();
PluginMessageEvent event = new PluginMessageEvent( con.getServer(), con, pluginMessage.getTag(), pluginMessage.getData().clone() );
@@ -330,7 +329,7 @@ public class DownstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketFFKick kick) throws Exception
+ public void handle(Kick kick) throws Exception
{
ServerInfo def = bungee.getServerInfo( con.getPendingConnection().getListener().getFallbackServer() );
if ( Objects.equals( server.getInfo(), def ) )
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
index 77683b0b..89f9d299 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
@@ -1,7 +1,6 @@
package net.md_5.bungee.connection;
import com.google.common.base.Preconditions;
-import io.netty.util.concurrent.ScheduledFuture;
import java.math.BigInteger;
import java.net.InetSocketAddress;
import java.net.URLEncoder;
@@ -9,7 +8,6 @@ import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
@@ -17,7 +15,6 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.EncryptionUtil;
-import net.md_5.bungee.PacketConstants;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.Util;
import net.md_5.bungee.api.Callback;
@@ -36,23 +33,24 @@ import net.md_5.bungee.netty.HandlerBoss;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.CipherDecoder;
import net.md_5.bungee.netty.CipherEncoder;
-import net.md_5.bungee.netty.PacketDecoder;
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.MinecraftInput;
-import net.md_5.bungee.protocol.Vanilla;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.packet.Packet1Login;
-import net.md_5.bungee.protocol.packet.Packet2Handshake;
-import net.md_5.bungee.protocol.packet.PacketCDClientStatus;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
-import net.md_5.bungee.protocol.packet.PacketFCEncryptionResponse;
-import net.md_5.bungee.protocol.packet.PacketFDEncryptionRequest;
-import net.md_5.bungee.protocol.packet.PacketFEPing;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
+import net.md_5.bungee.protocol.DefinedPacket;
+import net.md_5.bungee.protocol.packet.Login;
+import net.md_5.bungee.protocol.packet.Handshake;
+import net.md_5.bungee.protocol.packet.PluginMessage;
+import net.md_5.bungee.protocol.packet.EncryptionResponse;
+import net.md_5.bungee.protocol.packet.EncryptionRequest;
+import net.md_5.bungee.protocol.packet.Kick;
import net.md_5.bungee.api.AbstractReconnectHandler;
import net.md_5.bungee.api.event.PlayerHandshakeEvent;
+import net.md_5.bungee.protocol.Protocol;
+import net.md_5.bungee.protocol.packet.LegacyPing;
+import net.md_5.bungee.protocol.packet.LoginRequest;
+import net.md_5.bungee.protocol.packet.LoginSuccess;
+import net.md_5.bungee.protocol.packet.PingPacket;
+import net.md_5.bungee.protocol.packet.StatusRequest;
+import net.md_5.bungee.protocol.packet.StatusResponse;
@RequiredArgsConstructor
public class InitialHandler extends PacketHandler implements PendingConnection
@@ -63,14 +61,16 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Getter
private final ListenerInfo listener;
@Getter
- private Packet1Login forgeLogin;
+ private Login forgeLogin;
@Getter
- private Packet2Handshake handshake;
- private PacketFDEncryptionRequest request;
+ private Handshake handshake;
@Getter
- private List loginMessages = new ArrayList<>();
+ private LoginRequest loginRequest;
+ private EncryptionRequest request;
@Getter
- private List registerMessages = new ArrayList<>();
+ private List loginMessages = new ArrayList<>();
+ @Getter
+ private List registerMessages = new ArrayList<>();
private State thisState = State.HANDSHAKE;
private SecretKey sharedKey;
private final Unsafe unsafe = new Unsafe()
@@ -83,14 +83,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection
};
@Getter
private boolean onlineMode = BungeeCord.getInstance().config.isOnlineMode();
- private ScheduledFuture> pingFuture;
private InetSocketAddress vHost;
private byte version = -1;
+ @Getter
+ private String UUID;
private enum State
{
- HANDSHAKE, ENCRYPT, LOGIN, FINISHED;
+ HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHED;
}
@Override
@@ -106,24 +107,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
@Override
- public void handle(PacketFAPluginMessage pluginMessage) throws Exception
+ public void handle(PluginMessage pluginMessage) throws Exception
{
- if ( pluginMessage.getTag().equals( "MC|PingHost" ) )
- {
- if ( pingFuture.cancel( false ) )
- {
- MinecraftInput in = pluginMessage.getMCStream();
- version = in.readByte();
- String connectHost = in.readString();
- int connectPort = in.readInt();
- this.vHost = new InetSocketAddress( connectHost, connectPort );
-
- respondToPing();
- }
-
- return;
- }
-
// TODO: Unregister?
if ( pluginMessage.getTag().equals( "REGISTER" ) )
{
@@ -134,8 +119,25 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
}
- private void respondToPing()
+ @Override
+ public void handle(LegacyPing ping) throws Exception
{
+ String kickMessage = ChatColor.DARK_BLUE
+ + "\00" + bungee.getProtocolVersion()
+ + "\00" + bungee.getGameVersion()
+ + "\00" + listener.getMotd()
+ + "\00" + bungee.getOnlineCount()
+ + "\00" + listener.getMaxPlayers();
+
+ ch.getHandle().writeAndFlush( kickMessage );
+ ch.close();
+ }
+
+ @Override
+ public void handle(StatusRequest statusRequest) throws Exception
+ {
+ Preconditions.checkState( thisState == State.STATUS, "Not expecting STATUS" );
+
ServerInfo forced = AbstractReconnectHandler.getForcedHost( this );
final String motd = ( forced != null ) ? forced.getMotd() : listener.getMotd();
@@ -146,18 +148,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
if ( error != null )
{
- result = new ServerPing( (byte) -1, "-1", "Error pinging remote server: " + Util.exception( error ), -1, -1 );
+ result = new ServerPing();
+ result.setDescription( "Error pinging remote server: " + Util.exception( error ) );
}
result = bungee.getPluginManager().callEvent( new ProxyPingEvent( InitialHandler.this, result ) ).getResponse();
- String kickMessage = ChatColor.DARK_BLUE
- + "\00" + result.getProtocolVersion()
- + "\00" + result.getGameVersion()
- + "\00" + result.getMotd()
- + "\00" + result.getCurrentPlayers()
- + "\00" + result.getMaxPlayers();
BungeeCord.getInstance().getConnectionThrottle().unthrottle( getAddress().getAddress() );
- disconnect( kickMessage );
+ unsafe.sendPacket( new StatusResponse( BungeeCord.getInstance().gson.toJson( result ) ) );
}
};
@@ -166,35 +163,26 @@ public class InitialHandler extends PacketHandler implements PendingConnection
forced.ping( pingBack );
} else
{
- pingBack.done( new ServerPing( bungee.getProtocolVersion(), bungee.getGameVersion(), motd, bungee.getOnlineCount(), listener.getMaxPlayers() ), null );
+ pingBack.done( new ServerPing(
+ new ServerPing.Protocol( bungee.getGameVersion(), bungee.getProtocolVersion() ),
+ new ServerPing.Players( listener.getMaxPlayers(), bungee.getOnlineCount() ),
+ motd ),
+ null );
}
+
+ thisState = State.PING;
}
@Override
- public void handle(PacketFEPing ping) throws Exception
+ public void handle(PingPacket ping) throws Exception
{
- pingFuture = ch.getHandle().eventLoop().schedule( new Runnable()
- {
- @Override
- public void run()
- {
- respondToPing();
- }
- }, 200, TimeUnit.MILLISECONDS );
+ Preconditions.checkState( thisState == State.PING, "Not expecting PING" );
+ unsafe.sendPacket( ping );
+ disconnect( "" );
}
@Override
- public void handle(Packet1Login login) throws Exception
- {
- Preconditions.checkState( thisState == State.LOGIN, "Not expecting FORGE LOGIN" );
- Preconditions.checkState( forgeLogin == null, "Already received FORGE LOGIN" );
- forgeLogin = login;
-
- ch.getHandle().pipeline().get( PacketDecoder.class ).setProtocol( Forge.getInstance() );
- }
-
- @Override
- public void handle(Packet2Handshake handshake) throws Exception
+ public void handle(Handshake handshake) throws Exception
{
Preconditions.checkState( thisState == State.HANDSHAKE, "Not expecting HANDSHAKE" );
this.handshake = handshake;
@@ -203,15 +191,40 @@ public class InitialHandler extends PacketHandler implements PendingConnection
bungee.getPluginManager().callEvent( new PlayerHandshakeEvent( InitialHandler.this, handshake ) );
- if ( handshake.getProtocolVersion() > Vanilla.PROTOCOL_VERSION )
+ switch ( handshake.getRequestedProtocol() )
+ {
+ case 1:
+ // Ping
+ thisState = State.STATUS;
+ ch.setProtocol( Protocol.STATUS );
+ break;
+ case 2:
+ thisState = State.USERNAME;
+ ch.setProtocol( Protocol.LOGIN );
+ // Login
+ break;
+ default:
+ throw new IllegalArgumentException( "Cannot request protocol " + handshake.getRequestedProtocol() );
+ }
+ }
+
+ @Override
+ public void handle(LoginRequest loginRequest) throws Exception
+ {
+ Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" );
+ this.loginRequest = loginRequest;
+
+ if ( handshake.getProtocolVersion() > bungee.getProtocolVersion() )
{
disconnect( bungee.getTranslation( "outdated_server" ) );
- } else if ( handshake.getProtocolVersion() < Vanilla.PROTOCOL_VERSION )
+ return;
+ } else if ( handshake.getProtocolVersion() < bungee.getProtocolVersion() )
{
disconnect( bungee.getTranslation( "outdated_client" ) );
+ return;
}
- if ( handshake.getUsername().length() > 16 )
+ if ( getName().length() > 16 )
{
disconnect( "Cannot have username longer than 16 characters" );
return;
@@ -225,27 +238,33 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
// If offline mode and they are already on, don't allow connect
- if ( !isOnlineMode() && bungee.getPlayer( handshake.getUsername() ) != null )
+ if ( !isOnlineMode() && bungee.getPlayer( getName() ) != null )
{
disconnect( bungee.getTranslation( "already_connected" ) );
return;
}
- unsafe().sendPacket( PacketConstants.I_AM_BUNGEE );
- unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST );
-
- unsafe().sendPacket( request = EncryptionUtil.encryptRequest( this.onlineMode ) );
+ // TODO: Nuuuu Mojang why u do this
+ // unsafe().sendPacket( PacketConstants.I_AM_BUNGEE );
+ // unsafe().sendPacket( PacketConstants.FORGE_MOD_REQUEST );
+ if ( this.onlineMode )
+ {
+ unsafe().sendPacket( request = EncryptionUtil.encryptRequest() );
+ } else
+ {
+ finish();
+ }
thisState = State.ENCRYPT;
}
@Override
- public void handle(final PacketFCEncryptionResponse encryptResponse) throws Exception
+ public void handle(final EncryptionResponse encryptResponse) throws Exception
{
Preconditions.checkState( thisState == State.ENCRYPT, "Not expecting ENCRYPT" );
sharedKey = EncryptionUtil.getSecret( encryptResponse, request );
Cipher decrypt = EncryptionUtil.getCipher( Cipher.DECRYPT_MODE, sharedKey );
- ch.addBefore( PipelineUtils.PACKET_DECODE_HANDLER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) );
+ ch.addBefore( PipelineUtils.FRAME_DECODER, PipelineUtils.DECRYPT_HANDLER, new CipherDecoder( decrypt ) );
if ( this.onlineMode )
{
@@ -259,9 +278,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
sha.update( bit );
}
-
String encodedHash = URLEncoder.encode( new BigInteger( sha.digest() ).toString( 16 ), "UTF-8" );
- String authURL = "http://session.minecraft.net/game/checkserver.jsp?user=" + encName + "&serverId=" + encodedHash;
+
+ String authURL = "https://sessionserver.mojang.com/session/minecraft/hasJoined?username=" + encName + "&serverId=" + encodedHash;
Callback handler = new Callback()
{
@@ -270,13 +289,14 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
if ( error == null )
{
- if ( "YES".equals( result ) )
+ LoginResult obj = BungeeCord.getInstance().gson.fromJson( result, LoginResult.class );
+ if ( obj != null )
{
+ UUID = obj.getId();
finish();
- } else
- {
- disconnect( "Not authenticated with Minecraft.net" );
+ return;
}
+ disconnect( "Not authenticated with Minecraft.net" );
} else
{
disconnect( bungee.getTranslation( "mojang_fail" ) );
@@ -295,7 +315,7 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void finish()
{
// Check for multiple connections
- ProxiedPlayer old = bungee.getPlayer( handshake.getUsername() );
+ ProxiedPlayer old = bungee.getPlayer( getName() );
if ( old != null )
{
old.disconnect( bungee.getTranslation( "already_connected" ) );
@@ -314,7 +334,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
return;
}
- thisState = InitialHandler.State.LOGIN;
ch.getHandle().eventLoop().execute( new Runnable()
{
@@ -323,15 +342,45 @@ public class InitialHandler extends PacketHandler implements PendingConnection
{
if ( ch.getHandle().isActive() )
{
- unsafe().sendPacket( new PacketFCEncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) );
- try
+
+ if ( onlineMode )
{
- Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey );
- ch.addBefore( PipelineUtils.DECRYPT_HANDLER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
- } catch ( GeneralSecurityException ex )
- {
- disconnect( "Cipher error: " + Util.exception( ex ) );
+ // unsafe().sendPacket( new EncryptionResponse( new byte[ 0 ], new byte[ 0 ] ) );
+ try
+ {
+ Cipher encrypt = EncryptionUtil.getCipher( Cipher.ENCRYPT_MODE, sharedKey );
+ ch.addBefore( PipelineUtils.FRAME_PREPENDER, PipelineUtils.ENCRYPT_HANDLER, new CipherEncoder( encrypt ) );
+ } catch ( GeneralSecurityException ex )
+ {
+ disconnect( "Cipher error: " + Util.exception( ex ) );
+ }
}
+
+ if ( UUID == null )
+ {
+ UUID = java.util.UUID.randomUUID().toString();
+ }
+ unsafe.sendPacket( new LoginSuccess( UUID, getName() ) );
+ ch.setProtocol( Protocol.GAME );
+
+ UserConnection userCon = new UserConnection( bungee, ch, getName(), InitialHandler.this );
+ userCon.init();
+
+ bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) );
+
+ ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
+
+ ServerInfo server;
+ if ( bungee.getReconnectHandler() != null )
+ {
+ server = bungee.getReconnectHandler().getServer( userCon );
+ } else
+ {
+ server = AbstractReconnectHandler.getForcedHost( InitialHandler.this );
+ }
+ userCon.connect( server, true );
+
+ thisState = State.FINISHED;
}
}
} );
@@ -342,38 +391,12 @@ public class InitialHandler extends PacketHandler implements PendingConnection
bungee.getPluginManager().callEvent( new LoginEvent( InitialHandler.this, complete ) );
}
- @Override
- public void handle(PacketCDClientStatus clientStatus) throws Exception
- {
- Preconditions.checkState( thisState == State.LOGIN, "Not expecting LOGIN" );
-
- UserConnection userCon = new UserConnection( bungee, ch, getName(), this );
- userCon.init();
-
- bungee.getPluginManager().callEvent( new PostLoginEvent( userCon ) );
-
- ch.getHandle().pipeline().get( HandlerBoss.class ).setHandler( new UpstreamBridge( bungee, userCon ) );
-
- ServerInfo server;
- if ( bungee.getReconnectHandler() != null )
- {
- server = bungee.getReconnectHandler().getServer( userCon );
- } else
- {
- server = AbstractReconnectHandler.getForcedHost( this );
- }
- userCon.connect( server, true );
-
- thisState = State.FINISHED;
- throw new CancelSendSignal();
- }
-
@Override
public synchronized void disconnect(String reason)
{
if ( !ch.isClosed() )
{
- unsafe().sendPacket( new PacketFFKick( reason ) );
+ unsafe().sendPacket( new Kick( BungeeCord.getInstance().gson.toJson( reason ) ) );
ch.close();
}
}
@@ -381,11 +404,11 @@ public class InitialHandler extends PacketHandler implements PendingConnection
@Override
public String getName()
{
- return ( handshake == null ) ? null : handshake.getUsername();
+ return ( loginRequest == null ) ? null : loginRequest.getData();
}
@Override
- public byte getVersion()
+ public int getVersion()
{
return ( handshake == null ) ? version : handshake.getProtocolVersion();
}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java b/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java
new file mode 100644
index 00000000..e0b4060c
--- /dev/null
+++ b/proxy/src/main/java/net/md_5/bungee/connection/LoginResult.java
@@ -0,0 +1,12 @@
+package net.md_5.bungee.connection;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+
+@Data
+@AllArgsConstructor
+public class LoginResult
+{
+
+ private String id;
+}
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
index 20b5abef..8629f055 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/PingHandler.java
@@ -8,7 +8,7 @@ import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
-import net.md_5.bungee.protocol.packet.PacketFFKick;
+import net.md_5.bungee.protocol.packet.Kick;
@RequiredArgsConstructor
public class PingHandler extends PacketHandler
@@ -20,7 +20,7 @@ public class PingHandler extends PacketHandler
@Override
public void connected(ChannelWrapper channel) throws Exception
{
- // TODO: Update this to 1.6.4 style!
+ // TODO: Update this to 1.7 style!
channel.write( Unpooled.wrappedBuffer( new byte[]
{
(byte) 0xFE, (byte) 0x01
@@ -34,11 +34,11 @@ public class PingHandler extends PacketHandler
}
@Override
- public void handle(PacketFFKick kick) throws Exception
+ public void handle(Kick kick) throws Exception
{
String[] split = kick.getMessage().split( "\00" );
- ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
- callback.done( ping, null );
+ // ServerPing ping = new ServerPing( Byte.parseByte( split[1] ), split[2], split[3], Integer.parseInt( split[4] ), Integer.parseInt( split[5] ) );
+ // callback.done( ping, null );
}
@Override
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
index d2e5afef..411003cb 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
@@ -1,7 +1,6 @@
package net.md_5.bungee.connection;
import net.md_5.bungee.BungeeCord;
-import net.md_5.bungee.EntityMap;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.Util;
import net.md_5.bungee.api.ProxyServer;
@@ -10,14 +9,15 @@ import net.md_5.bungee.api.event.PlayerDisconnectEvent;
import net.md_5.bungee.api.event.PluginMessageEvent;
import net.md_5.bungee.netty.ChannelWrapper;
import net.md_5.bungee.netty.PacketHandler;
-import net.md_5.bungee.netty.PacketWrapper;
-import net.md_5.bungee.protocol.packet.Packet0KeepAlive;
-import net.md_5.bungee.protocol.packet.Packet3Chat;
-import net.md_5.bungee.protocol.packet.PacketCBTabComplete;
-import net.md_5.bungee.protocol.packet.PacketCCSettings;
-import net.md_5.bungee.protocol.packet.PacketFAPluginMessage;
+import net.md_5.bungee.protocol.PacketWrapper;
+import net.md_5.bungee.protocol.packet.KeepAlive;
+import net.md_5.bungee.protocol.packet.Chat;
+import net.md_5.bungee.protocol.packet.TabCompleteRequest;
+import net.md_5.bungee.protocol.packet.ClientSettings;
+import net.md_5.bungee.protocol.packet.PluginMessage;
import java.util.ArrayList;
import java.util.List;
+import net.md_5.bungee.protocol.packet.TabCompleteResponse;
public class UpstreamBridge extends PacketHandler
{
@@ -59,7 +59,7 @@ public class UpstreamBridge extends PacketHandler
@Override
public void handle(PacketWrapper packet) throws Exception
{
- EntityMap.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() );
+ // EntityMap.rewrite( packet.buf, con.getClientEntityId(), con.getServerEntityId() );
if ( con.getServer() != null )
{
con.getServer().getCh().write( packet );
@@ -67,7 +67,7 @@ public class UpstreamBridge extends PacketHandler
}
@Override
- public void handle(Packet0KeepAlive alive) throws Exception
+ public void handle(KeepAlive alive) throws Exception
{
if ( alive.getRandomId() == con.getSentPingId() )
{
@@ -78,7 +78,7 @@ public class UpstreamBridge extends PacketHandler
}
@Override
- public void handle(Packet3Chat chat) throws Exception
+ public void handle(Chat chat) throws Exception
{
ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() );
if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )
@@ -93,7 +93,7 @@ public class UpstreamBridge extends PacketHandler
}
@Override
- public void handle(PacketCBTabComplete tabComplete) throws Exception
+ public void handle(TabCompleteRequest tabComplete) throws Exception
{
if ( tabComplete.getCursor().startsWith( "/" ) )
{
@@ -102,20 +102,20 @@ public class UpstreamBridge extends PacketHandler
if ( !results.isEmpty() )
{
- con.unsafe().sendPacket( new PacketCBTabComplete( results.toArray( new String[ results.size() ] ) ) );
+ con.unsafe().sendPacket( new TabCompleteResponse( results.toArray( new String[ results.size() ] ) ) );
throw new CancelSendSignal();
}
}
}
@Override
- public void handle(PacketCCSettings settings) throws Exception
+ public void handle(ClientSettings settings) throws Exception
{
con.setSettings( settings );
}
@Override
- public void handle(PacketFAPluginMessage pluginMessage) throws Exception
+ public void handle(PluginMessage pluginMessage) throws Exception
{
if ( pluginMessage.getTag().equals( "BungeeCord" ) )
{
diff --git a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java
index fd486e04..96d0a71d 100644
--- a/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/http/HttpHandler.java
@@ -36,7 +36,15 @@ public class HttpHandler extends SimpleChannelInboundHandler
if ( msg instanceof HttpResponse )
{
HttpResponse response = (HttpResponse) msg;
- if ( response.getStatus().code() != 200 )
+ int responseCode = response.getStatus().code();
+
+ if ( responseCode == HttpResponseStatus.NO_CONTENT.code() )
+ {
+ done( ctx );
+ return;
+ }
+
+ if ( responseCode != HttpResponseStatus.OK.code() )
{
throw new IllegalStateException( "Expected HTTP response 200 OK, got " + response.getStatus() );
}
@@ -48,14 +56,19 @@ public class HttpHandler extends SimpleChannelInboundHandler
if ( msg instanceof LastHttpContent )
{
- try
- {
- callback.done( buffer.toString(), null );
- } finally
- {
- ctx.channel().close();
- }
+ done( ctx );
}
}
}
+
+ private void done(ChannelHandlerContext ctx)
+ {
+ try
+ {
+ callback.done( buffer.toString(), null );
+ } finally
+ {
+ ctx.channel().close();
+ }
+ }
}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
index e16ae233..77ecd687 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
@@ -1,10 +1,14 @@
package net.md_5.bungee.netty;
+import net.md_5.bungee.protocol.PacketWrapper;
import com.google.common.base.Preconditions;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
+import net.md_5.bungee.protocol.MinecraftDecoder;
+import net.md_5.bungee.protocol.MinecraftEncoder;
+import net.md_5.bungee.protocol.Protocol;
public class ChannelWrapper
{
@@ -18,6 +22,12 @@ public class ChannelWrapper
this.ch = ctx.channel();
}
+ public void setProtocol(Protocol protocol)
+ {
+ ch.pipeline().get( MinecraftDecoder.class ).setProtocol( protocol );
+ ch.pipeline().get( MinecraftEncoder.class ).setProtocol( protocol );
+ }
+
public synchronized void write(Object packet)
{
if ( !closed )
@@ -25,10 +35,10 @@ public class ChannelWrapper
if ( packet instanceof PacketWrapper )
{
( (PacketWrapper) packet ).setReleased( true );
- ch.write( ( (PacketWrapper) packet ).buf );
+ ch.write( ( (PacketWrapper) packet ).buf, ch.voidPromise() );
} else
{
- ch.write( packet );
+ ch.write( packet, ch.voidPromise() );
}
ch.flush();
}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java b/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java
deleted file mode 100644
index cfa34503..00000000
--- a/proxy/src/main/java/net/md_5/bungee/netty/DefinedPacketEncoder.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package net.md_5.bungee.netty;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.MessageToByteEncoder;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-
-@ChannelHandler.Sharable
-public class DefinedPacketEncoder extends MessageToByteEncoder
-{
-
- @Override
- protected void encode(ChannelHandlerContext ctx, DefinedPacket msg, ByteBuf out) throws Exception
- {
- out.writeByte( msg.getId() );
- msg.write( out );
- }
-}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
index d3a59eef..fc80d169 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/HandlerBoss.java
@@ -1,5 +1,6 @@
package net.md_5.bungee.netty;
+import net.md_5.bungee.protocol.PacketWrapper;
import com.google.common.base.Preconditions;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java
deleted file mode 100644
index 47043da4..00000000
--- a/proxy/src/main/java/net/md_5/bungee/netty/PacketDecoder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package net.md_5.bungee.netty;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.handler.codec.ReplayingDecoder;
-import java.util.List;
-import lombok.AllArgsConstructor;
-import lombok.Getter;
-import lombok.Setter;
-import net.md_5.bungee.protocol.Protocol;
-import net.md_5.bungee.protocol.packet.DefinedPacket;
-import net.md_5.bungee.protocol.skip.PacketReader;
-
-/**
- * This class will attempt to read a packet from {@link PacketReader}, with the
- * specified {@link #protocol} before returning a new {@link ByteBuf} with the
- * copied contents of all bytes read in this frame.
- *
- * It is based on {@link ReplayingDecoder} so that packets will only be returned
- * when all needed data is present.
- */
-@AllArgsConstructor
-public class PacketDecoder extends ReplayingDecoder
-{
-
- @Getter
- @Setter
- private Protocol protocol;
-
- @Override
- protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception
- {
- // While we have enough data
- while ( true )
- {
- // Store our start index
- int startIndex = in.readerIndex();
- // Run packet through framer
- DefinedPacket packet = protocol.read( in.readUnsignedByte(), in );
- // If we got this far, it means we have formed a packet, so lets grab the end index
- int endIndex = in.readerIndex();
- // Allocate a buffer big enough for all bytes we have read
- ByteBuf buf = in.copy( startIndex, endIndex - startIndex );
- // Checkpoint our state incase we don't have enough data for another packet
- checkpoint();
- // Store our decoded message
- out.add( new PacketWrapper( packet, buf ) );
- }
- }
-}
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java
index ca4684ff..08ab8152 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PacketHandler.java
@@ -1,6 +1,8 @@
package net.md_5.bungee.netty;
-public abstract class PacketHandler extends net.md_5.bungee.protocol.packet.AbstractPacketHandler
+import net.md_5.bungee.protocol.PacketWrapper;
+
+public abstract class PacketHandler extends net.md_5.bungee.protocol.AbstractPacketHandler
{
@Override
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
index f37d9951..fd22e5c0 100644
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
@@ -10,12 +10,17 @@ import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.BungeeServerInfo;
-import net.md_5.bungee.ServerConnector;
import net.md_5.bungee.UserConnection;
import net.md_5.bungee.connection.InitialHandler;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ListenerInfo;
-import net.md_5.bungee.protocol.Vanilla;
+import net.md_5.bungee.protocol.KickStringWriter;
+import net.md_5.bungee.protocol.LegacyDecoder;
+import net.md_5.bungee.protocol.MinecraftDecoder;
+import net.md_5.bungee.protocol.MinecraftEncoder;
+import net.md_5.bungee.protocol.Protocol;
+import net.md_5.bungee.protocol.Varint21FrameDecoder;
+import net.md_5.bungee.protocol.Varint21LengthFieldPrepender;
public class PipelineUtils
{
@@ -36,26 +41,25 @@ public class PipelineUtils
}
BASE.initChannel( ch );
+ ch.pipeline().addBefore( FRAME_DECODER, LEGACY_DECODER, new LegacyDecoder() );
+ ch.pipeline().addAfter( FRAME_DECODER, PACKET_DECODER, new MinecraftDecoder( Protocol.HANDSHAKE, true ) );
+ ch.pipeline().addAfter( FRAME_PREPENDER, PACKET_ENCODER, new MinecraftEncoder( Protocol.HANDSHAKE, true ) );
+ ch.pipeline().addBefore( FRAME_PREPENDER, LEGACY_KICKER, new KickStringWriter() );
ch.pipeline().get( HandlerBoss.class ).setHandler( new InitialHandler( ProxyServer.getInstance(), ch.attr( LISTENER ).get() ) );
}
};
- public static final ChannelInitializer CLIENT = new ChannelInitializer()
- {
- @Override
- protected void initChannel(Channel ch) throws Exception
- {
- BASE.initChannel( ch );
- ch.pipeline().get( HandlerBoss.class ).setHandler( new ServerConnector( ProxyServer.getInstance(), ch.attr( USER ).get(), ch.attr( TARGET ).get() ) );
- }
- };
public static final Base BASE = new Base();
- private static final DefinedPacketEncoder packetEncoder = new DefinedPacketEncoder();
+ private static final Varint21LengthFieldPrepender framePrepender = new Varint21LengthFieldPrepender();
public static String TIMEOUT_HANDLER = "timeout";
- public static String PACKET_DECODE_HANDLER = "packet-decoder";
- public static String PACKET_ENCODE_HANDLER = "packet-encoder";
+ public static String PACKET_DECODER = "packet-decoder";
+ public static String PACKET_ENCODER = "packet-encoder";
public static String BOSS_HANDLER = "inbound-boss";
public static String ENCRYPT_HANDLER = "encrypt";
public static String DECRYPT_HANDLER = "decrypt";
+ public static String FRAME_DECODER = "frame-decoder";
+ public static String FRAME_PREPENDER = "frame-prepender";
+ public static String LEGACY_DECODER = "legacy-decoder";
+ public static String LEGACY_KICKER = "legacy-kick";
public final static class Base extends ChannelInitializer
{
@@ -72,8 +76,9 @@ public class PipelineUtils
}
ch.pipeline().addLast( TIMEOUT_HANDLER, new ReadTimeoutHandler( BungeeCord.getInstance().config.getTimeout(), TimeUnit.MILLISECONDS ) );
- ch.pipeline().addLast( PACKET_DECODE_HANDLER, new PacketDecoder( Vanilla.getInstance() ) );
- ch.pipeline().addLast( PACKET_ENCODE_HANDLER, packetEncoder );
+ ch.pipeline().addLast( FRAME_DECODER, new Varint21FrameDecoder() );
+ ch.pipeline().addLast( FRAME_PREPENDER, framePrepender );
+
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
}
};
diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java
index b38ae4b1..902d2cf6 100644
--- a/proxy/src/main/java/net/md_5/bungee/tab/Custom.java
+++ b/proxy/src/main/java/net/md_5/bungee/tab/Custom.java
@@ -7,7 +7,7 @@ import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.tab.CustomTabList;
import net.md_5.bungee.api.tab.TabListAdapter;
-import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
public class Custom extends TabListAdapter implements CustomTabList
{
@@ -96,7 +96,7 @@ public class Custom extends TabListAdapter implements CustomTabList
{
String text = ( slots[i][j] != null ) ? slots[i][j] : new StringBuilder().append( base( i ) ).append( base( j ) ).toString();
sent[i][j] = text;
- getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( text, true, (short) 0 ) );
+ getPlayer().unsafe().sendPacket( new PlayerListItem( text, true, (short) 0 ) );
}
}
}
@@ -112,7 +112,7 @@ public class Custom extends TabListAdapter implements CustomTabList
{
String text = sent[i][j];
sent[i][j] = null;
- getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( text, false, (short) 9999 ) );
+ getPlayer().unsafe().sendPacket( new PlayerListItem( text, false, (short) 9999 ) );
}
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/tab/Global.java b/proxy/src/main/java/net/md_5/bungee/tab/Global.java
index ccc4f014..608513e4 100644
--- a/proxy/src/main/java/net/md_5/bungee/tab/Global.java
+++ b/proxy/src/main/java/net/md_5/bungee/tab/Global.java
@@ -4,7 +4,7 @@ import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.tab.TabListAdapter;
-import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
public class Global extends TabListAdapter
{
@@ -16,9 +16,9 @@ public class Global extends TabListAdapter
{
for ( ProxiedPlayer p : ProxyServer.getInstance().getPlayers() )
{
- getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) );
+ getPlayer().unsafe().sendPacket( new PlayerListItem( p.getDisplayName(), true, (short) p.getPing() ) );
}
- BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) );
+ BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) );
}
@Override
@@ -27,14 +27,14 @@ public class Global extends TabListAdapter
if ( !sentPing )
{
sentPing = true;
- BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) );
+ BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) getPlayer().getPing() ) );
}
}
@Override
public void onDisconnect()
{
- BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) );
+ BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), false, (short) 9999 ) );
}
@Override
diff --git a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java
index c7233a2a..0c6a1169 100644
--- a/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java
+++ b/proxy/src/main/java/net/md_5/bungee/tab/GlobalPing.java
@@ -2,7 +2,7 @@ package net.md_5.bungee.tab;
import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer;
-import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
public class GlobalPing extends Global
{
@@ -17,7 +17,7 @@ public class GlobalPing extends Global
if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing )
{
lastPing = ping;
- BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) );
+ BungeeCord.getInstance().broadcast( new PlayerListItem( getPlayer().getDisplayName(), true, (short) ping ) );
}
}
}
diff --git a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java
index 722987b1..00dc2074 100644
--- a/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java
+++ b/proxy/src/main/java/net/md_5/bungee/tab/ServerUnique.java
@@ -3,7 +3,7 @@ package net.md_5.bungee.tab;
import java.util.Collection;
import java.util.HashSet;
import net.md_5.bungee.api.tab.TabListAdapter;
-import net.md_5.bungee.protocol.packet.PacketC9PlayerListItem;
+import net.md_5.bungee.protocol.packet.PlayerListItem;
public class ServerUnique extends TabListAdapter
{
@@ -17,7 +17,7 @@ public class ServerUnique extends TabListAdapter
{
for ( String username : usernames )
{
- getPlayer().unsafe().sendPacket( new PacketC9PlayerListItem( username, false, (short) 9999 ) );
+ getPlayer().unsafe().sendPacket( new PlayerListItem( username, false, (short) 9999 ) );
}
usernames.clear();
}
diff --git a/query/pom.xml b/query/pom.xml
index f86726ce..bcf3dc50 100644
--- a/query/pom.xml
+++ b/query/pom.xml
@@ -6,13 +6,13 @@
net.md-5
bungeecord-parent
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
../pom.xml
net.md-5
bungeecord-query
- 1.6.4-SNAPSHOT
+ 1.7-SNAPSHOT
jar
BungeeCord-Query