diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/api/pom.xml b/api/pom.xml index e64231f560..f291fb2eed 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-api - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-API @@ -73,7 +73,7 @@ org.yaml snakeyaml - 1.28 + 1.30-SNAPSHOT compile diff --git a/api/src/main/java/net/md_5/bungee/Util.java b/api/src/main/java/net/md_5/bungee/Util.java index 31101f6b2f..e565c836bc 100644 --- a/api/src/main/java/net/md_5/bungee/Util.java +++ b/api/src/main/java/net/md_5/bungee/Util.java @@ -7,6 +7,7 @@ import java.net.SocketAddress; import java.net.URI; import java.net.URISyntaxException; +import java.util.Locale; import java.util.UUID; /** @@ -68,6 +69,17 @@ public static String hex(int i) return String.format( "0x%02X", i ); } + /** + * Formats an char as a unicode value. + * + * @param c the character to format + * @return the unicode representation of the character + */ + public static String unicode(char c) + { + return "\\u" + String.format( "%04x", (int) c ).toUpperCase( Locale.ROOT ); + } + /** * Constructs a pretty one line version of a {@link Throwable}. Useful for * debugging. 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 29a4716fec..e7ab62e58a 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 @@ -57,7 +57,7 @@ public enum MainHand String getDisplayName(); /** - * Sets this players display name to be used by bungeecord commands and plugins. + * Sets this player's display name to be used by proxy commands and plugins. * * @param name the name to set */ diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java index 75cf6e3339..68157dd4b9 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginClassloader.java @@ -63,7 +63,13 @@ private Class loadClass0(String name, boolean resolve, boolean checkOther, bo { try { - return super.loadClass( name, resolve ); + Class result = super.loadClass( name, resolve ); + + // SPIGOT-6749: Library classes will appear in the above, but we don't want to return them to other plugins + if ( checkOther || result.getClassLoader() == this ) + { + return result; + } } catch ( ClassNotFoundException ex ) { } diff --git a/bootstrap/pom.xml b/bootstrap/pom.xml index a35a8318be..5eab55bd96 100644 --- a/bootstrap/pom.xml +++ b/bootstrap/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-bootstrap - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Bootstrap diff --git a/chat/pom.xml b/chat/pom.xml index fb797b1eb6..0c244852c7 100644 --- a/chat/pom.xml +++ b/chat/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-chat - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Chat @@ -22,7 +22,7 @@ com.google.code.gson gson - 2.8.0 + 2.8.8 compile diff --git a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java index 1598dcc562..8601793a18 100644 --- a/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ b/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java @@ -230,6 +230,6 @@ protected void toLegacyText(StringBuilder builder) @Override public String toString() { - return String.format( "TextComponent{text=%s, %s}", text, super.toString() ); + return "TextComponent{text=" + text + ", " + super.toString() + '}'; } } diff --git a/chat/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java b/chat/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java index fc9739a80a..515e158587 100644 --- a/chat/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java +++ b/chat/src/main/java/net/md_5/bungee/chat/BaseComponentSerializer.java @@ -85,7 +85,7 @@ protected void deserialize(JsonObject object, BaseComponent component, JsonDeser { components = new BaseComponent[] { - context.deserialize( contents, BaseComponent.class ) + context.deserialize( contents, BaseComponent.class ) }; } hoverEvent = new HoverEvent( action, components ); diff --git a/checkstyle.xml b/checkstyle.xml index 9ac4e93186..cde9c2101f 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -33,6 +33,7 @@ + @@ -84,4 +85,6 @@ + + diff --git a/config/pom.xml b/config/pom.xml index 88c71b99c5..318ea6ef28 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-config - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Config @@ -22,14 +22,14 @@ com.google.code.gson gson - 2.8.0 + 2.8.8 compile true org.yaml snakeyaml - 1.28 + 1.30-SNAPSHOT compile true diff --git a/event/pom.xml b/event/pom.xml index 3a9c76345b..37320a3b26 100644 --- a/event/pom.xml +++ b/event/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-event - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Event diff --git a/log/pom.xml b/log/pom.xml index 6d6242e1d7..28545b9286 100644 --- a/log/pom.xml +++ b/log/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-log - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Log diff --git a/module/cmd-alert/pom.xml b/module/cmd-alert/pom.xml index 4b3a82ea9c..dcf9388869 100644 --- a/module/cmd-alert/pom.xml +++ b/module/cmd-alert/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-alert - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar cmd_alert diff --git a/module/cmd-find/pom.xml b/module/cmd-find/pom.xml index 1c7f2515c4..59163873f7 100644 --- a/module/cmd-find/pom.xml +++ b/module/cmd-find/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-find - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar cmd_find diff --git a/module/cmd-list/pom.xml b/module/cmd-list/pom.xml index 91fadc2b96..23f6974756 100644 --- a/module/cmd-list/pom.xml +++ b/module/cmd-list/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-list - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar cmd_list diff --git a/module/cmd-send/pom.xml b/module/cmd-send/pom.xml index 30097fc3ca..db9e47628a 100644 --- a/module/cmd-send/pom.xml +++ b/module/cmd-send/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-send - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar cmd_send diff --git a/module/cmd-server/pom.xml b/module/cmd-server/pom.xml index d69f1e612e..06f55aa849 100644 --- a/module/cmd-server/pom.xml +++ b/module/cmd-server/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-cmd-server - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar cmd_server diff --git a/module/pom.xml b/module/pom.xml index dbc316dd05..32d966a054 100644 --- a/module/pom.xml +++ b/module/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT pom BungeeCord Modules diff --git a/module/reconnect-yaml/pom.xml b/module/reconnect-yaml/pom.xml index 8d1df1fd91..4bb408fe58 100644 --- a/module/reconnect-yaml/pom.xml +++ b/module/reconnect-yaml/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-module - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-module-reconnect-yaml - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar reconnect_yaml diff --git a/native/pom.xml b/native/pom.xml index f8bacabd63..aa62ce2a55 100644 --- a/native/pom.xml +++ b/native/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-native - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Native diff --git a/pom.xml b/pom.xml index f44f6c2b40..3169ca7897 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT pom BungeeCord-Parent @@ -76,10 +76,25 @@ + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + false + + + true + + + + unknown 1.18.20 - 4.1.65.Final + 4.1.70.Final 1.8 1.8 UTF-8 @@ -95,7 +110,7 @@ com.google.guava guava - 21.0 + 31.0.1-jre compile @@ -156,7 +171,7 @@ com.puppycrawl.tools checkstyle - 8.44 + 8.45.1 diff --git a/protocol/pom.xml b/protocol/pom.xml index f66ca6ca9d..6e23170f15 100644 --- a/protocol/pom.xml +++ b/protocol/pom.xml @@ -6,33 +6,18 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-protocol - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Protocol Minimal implementation of the Minecraft protocol for use in BungeeCord - - - - sonatype-nexus-snapshots - Sonatype Nexus Snapshots - https://oss.sonatype.org/content/repositories/snapshots - - false - - - true - - - - net.md-5 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 index dd210d3ed8..e6128f8111 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java @@ -23,7 +23,7 @@ public static void writeString(String s, ByteBuf buf) { if ( s.length() > Short.MAX_VALUE ) { - throw new OverflowPacketException( String.format( "Cannot send string longer than Short.MAX_VALUE (got %s characters)", s.length() ) ); + throw new OverflowPacketException( "Cannot send string longer than Short.MAX_VALUE (got " + s.length() + " characters)" ); } byte[] b = s.getBytes( Charsets.UTF_8 ); @@ -41,7 +41,7 @@ public static String readString(ByteBuf buf, int maxLen) int len = readVarInt( buf ); if ( len > maxLen * 4 ) { - throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d bytes)", maxLen * 4, len ) ); + throw new OverflowPacketException( "Cannot receive string longer than " + maxLen * 4 + " (got " + len + " bytes)" ); } byte[] b = new byte[ len ]; @@ -50,7 +50,7 @@ public static String readString(ByteBuf buf, int maxLen) String s = new String( b, Charsets.UTF_8 ); if ( s.length() > maxLen ) { - throw new OverflowPacketException( String.format( "Cannot receive string longer than %d (got %d characters)", maxLen, s.length() ) ); + throw new OverflowPacketException( "Cannot receive string longer than " + maxLen + " (got " + s.length() + " characters)" ); } return s; @@ -60,7 +60,7 @@ public static void writeArray(byte[] b, ByteBuf buf) { if ( b.length > Short.MAX_VALUE ) { - throw new OverflowPacketException( String.format( "Cannot send byte array longer than Short.MAX_VALUE (got %s bytes)", b.length ) ); + throw new OverflowPacketException( "Cannot send byte array longer than Short.MAX_VALUE (got " + b.length + " bytes)" ); } writeVarInt( b.length, buf ); buf.writeBytes( b ); @@ -84,7 +84,7 @@ public static byte[] readArray(ByteBuf buf, int limit) int len = readVarInt( buf ); if ( len > limit ) { - throw new OverflowPacketException( String.format( "Cannot receive byte array longer than %s (got %s bytes)", limit, len ) ); + throw new OverflowPacketException( "Cannot receive byte array longer than " + limit + " (got " + len + " bytes)" ); } byte[] ret = new byte[ len ]; buf.readBytes( ret ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java index 9f1b0a990a..6078790227 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/Protocol.java @@ -226,7 +226,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_14, 0x4F ), map( ProtocolConstants.MINECRAFT_1_15, 0x50 ), map( ProtocolConstants.MINECRAFT_1_16, 0x4F ), - map( ProtocolConstants.MINECRAFT_1_17, 0x59 ) + map( ProtocolConstants.MINECRAFT_1_17, 0x59 ), + map( ProtocolConstants.MINECRAFT_1_18, 0x5A ) ); TO_CLIENT.registerPacket( ClearTitles.class, @@ -236,12 +237,14 @@ public enum Protocol TO_CLIENT.registerPacket( Subtitle.class, Subtitle::new, - map( ProtocolConstants.MINECRAFT_1_17, 0x57 ) + map( ProtocolConstants.MINECRAFT_1_17, 0x57 ), + map( ProtocolConstants.MINECRAFT_1_18, 0x58 ) ); TO_CLIENT.registerPacket( TitleTimes.class, TitleTimes::new, - map( ProtocolConstants.MINECRAFT_1_17, 0x5A ) + map( ProtocolConstants.MINECRAFT_1_17, 0x5A ), + map( ProtocolConstants.MINECRAFT_1_18, 0x5B ) ); TO_CLIENT.registerPacket( PlayerListHeaderFooter.class, @@ -255,7 +258,8 @@ public enum Protocol map( ProtocolConstants.MINECRAFT_1_14, 0x53 ), map( ProtocolConstants.MINECRAFT_1_15, 0x54 ), map( ProtocolConstants.MINECRAFT_1_16, 0x53 ), - map( ProtocolConstants.MINECRAFT_1_17, 0x5E ) + map( ProtocolConstants.MINECRAFT_1_17, 0x5E ), + map( ProtocolConstants.MINECRAFT_1_18, 0x5F ) ); TO_CLIENT.registerPacket( EntityStatus.class, diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java index ed70052719..15a5242265 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java @@ -38,6 +38,7 @@ public class ProtocolConstants public static final int MINECRAFT_1_16_4 = 754; public static final int MINECRAFT_1_17 = 755; public static final int MINECRAFT_1_17_1 = 756; + public static final int MINECRAFT_1_18 = 757; public static final List SUPPORTED_VERSIONS; public static final List SUPPORTED_VERSION_IDS; @@ -54,7 +55,8 @@ public class ProtocolConstants "1.14.x", "1.15.x", "1.16.x", - "1.17.x" + "1.17.x", + "1.18.x" ); ImmutableList.Builder supportedVersionIds = ImmutableList.builder().add( ProtocolConstants.MINECRAFT_1_7_2, @@ -87,13 +89,14 @@ public class ProtocolConstants ProtocolConstants.MINECRAFT_1_16_3, ProtocolConstants.MINECRAFT_1_16_4, ProtocolConstants.MINECRAFT_1_17, - ProtocolConstants.MINECRAFT_1_17_1 + ProtocolConstants.MINECRAFT_1_17_1, + ProtocolConstants.MINECRAFT_1_18 ); if ( SNAPSHOT_SUPPORT ) { - // supportedVersions.add( "1.17.x" ); - // supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_17 ); + // supportedVersions.add( "1.18.x" ); + // supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_18 ); } SUPPORTED_VERSIONS = supportedVersions.build(); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java index bc491b363d..ec719e2ce0 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ClientSettings.java @@ -24,6 +24,7 @@ public class ClientSettings extends DefinedPacket private byte skinParts; private int mainHand; private boolean disableTextFiltering; + private boolean allowServerListing; @Override public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) @@ -45,6 +46,10 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { disableTextFiltering = buf.readBoolean(); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_18 ) + { + allowServerListing = buf.readBoolean(); + } } @Override @@ -73,6 +78,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { buf.writeBoolean( disableTextFiltering ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_18 ) + { + buf.writeBoolean( allowServerListing ); + } } @Override diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java index a240ccbbff..3cab0d3d1a 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Login.java @@ -32,6 +32,7 @@ public class Login extends DefinedPacket private int maxPlayers; private String levelType; private int viewDistance; + private int simulationDistance; private boolean reducedDebugInfo; private boolean normalRespawn; private boolean debug; @@ -100,6 +101,10 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco { viewDistance = readVarInt( buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_18 ) + { + simulationDistance = readVarInt( buf ); + } if ( protocolVersion >= 29 ) { reducedDebugInfo = buf.readBoolean(); @@ -177,6 +182,10 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc { writeVarInt( viewDistance, buf ); } + if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_18 ) + { + writeVarInt( simulationDistance, buf ); + } if ( protocolVersion >= 29 ) { buf.writeBoolean( reducedDebugInfo ); diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java index 1b80112ce6..2196310d15 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/PluginMessage.java @@ -2,7 +2,6 @@ import com.google.common.base.Function; import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.io.ByteArrayInputStream; @@ -50,14 +49,6 @@ public String apply(String tag) return "legacy:" + tag.toLowerCase( Locale.ROOT ); } }; - public static final Predicate SHOULD_RELAY = new Predicate() - { - @Override - public boolean apply(PluginMessage input) - { - return ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "minecraft:register" ) || input.getTag().equals( "MC|Brand" ) || input.getTag().equals( "minecraft:brand" ) ) && input.getData().length < Byte.MAX_VALUE; - } - }; // private String tag; private byte[] data; @@ -76,7 +67,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco data = readArrayLegacy( buf ); } else { - tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf ); + tag = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? MODERNISE.apply( readString( buf ) ) : readString( buf, 20 ); int maxSize = direction == ProtocolConstants.Direction.TO_SERVER ? Short.MAX_VALUE : 0x100000; Preconditions.checkArgument( buf.readableBytes() < maxSize ); data = new byte[ buf.readableBytes() ]; diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java index ca7c6342bb..21aa967508 100644 --- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java +++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteResponse.java @@ -57,9 +57,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco } suggestions = new Suggestions( range, matches ); - } - - if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 ) + } else { commands = readStringArray( buf ); } @@ -84,9 +82,7 @@ public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protoc writeString( suggestion.getTooltip().getString(), buf ); } } - } - - if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 ) + } else { writeStringArray( commands, buf ); } diff --git a/proxy/pom.xml b/proxy/pom.xml index 0f0af3dc2f..84ace403e6 100644 --- a/proxy/pom.xml +++ b/proxy/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-proxy - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Proxy @@ -94,7 +94,7 @@ mysql mysql-connector-java - 5.1.49 + 8.0.27 runtime 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 95e1534033..e895d1646f 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeCord.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeCord.java @@ -198,8 +198,6 @@ public BungeeCord() throws IOException // Java uses ! to indicate a resource inside of a jar/zip/other container. Running Bungee from within a directory that has a ! will cause this to muck up. Preconditions.checkState( new File( "." ).getAbsolutePath().indexOf( '!' ) == -1, "Cannot use BungeeCord in directory with ! in path." ); - System.setSecurityManager( new BungeeSecurityManager() ); - try { baseBundle = ResourceBundle.getBundle( "messages" ); diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java b/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java deleted file mode 100644 index 53c81923c8..0000000000 --- a/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java +++ /dev/null @@ -1,78 +0,0 @@ -package net.md_5.bungee; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.security.AccessControlException; -import java.security.Permission; -import java.util.HashSet; -import java.util.Set; -import java.util.logging.Level; -import net.md_5.bungee.api.ProxyServer; -import net.md_5.bungee.api.scheduler.GroupedThreadFactory; - -public class BungeeSecurityManager extends SecurityManager -{ - - private static final boolean ENFORCE = false; - private final Set seen = new HashSet<>(); - - private void checkRestricted(String text) - { - Class[] context = getClassContext(); - for ( int i = 2; i < context.length; i++ ) - { - ClassLoader loader = context[i].getClassLoader(); - - // Bungee / system can do everything - if ( loader == ClassLoader.getSystemClassLoader() || loader == null ) - { - break; - } - - AccessControlException ex = new AccessControlException( "Plugin violation: " + text ); - if ( ENFORCE ) - { - throw ex; - } - - StringWriter stack = new StringWriter(); - ex.printStackTrace( new PrintWriter( stack ) ); - if ( seen.add( stack.toString() ) ) - { - ProxyServer.getInstance().getLogger().log( Level.WARNING, "Plugin performed restricted action, please inform them to use proper API methods: " + text, ex ); - } - break; - } - } - - @Override - public void checkExit(int status) - { - checkRestricted( "Exit: Cannot close VM" ); - } - - @Override - public void checkAccess(ThreadGroup g) - { - if ( !( g instanceof GroupedThreadFactory.BungeeGroup ) ) - { - checkRestricted( "Illegal thread group access" ); - } - } - - @Override - public void checkPermission(Permission perm, Object context) - { - checkPermission( perm ); - } - - @Override - public void checkPermission(Permission perm) - { - switch ( perm.getName() ) - { - case "setSecurityManager": - throw new AccessControlException( "Restricted Action", perm ); - } - } -} 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 97b8c29922..31a811cbdb 100644 --- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java +++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java @@ -1,10 +1,12 @@ package net.md_5.bungee; +import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import java.net.InetSocketAddress; import java.util.Arrays; +import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.Queue; import java.util.Set; @@ -136,7 +138,8 @@ public void connected(ChannelWrapper channel) throws Exception copiedHandshake.setHost( newHost ); } else if ( !user.getExtraDataInHandshake().isEmpty() ) { - // Restore the extra data + // Only restore the extra data if IP forwarding is off. + // TODO: Add support for this data with IP forwarding. copiedHandshake.setHost( copiedHandshake.getHost() + user.getExtraDataInHandshake() ); } @@ -215,9 +218,16 @@ public void handle(Login login) throws Exception } } - for ( PluginMessage message : user.getPendingConnection().getRelayMessages() ) + PluginMessage brandMessage = user.getPendingConnection().getBrandMessage(); + if ( brandMessage != null ) { - ch.write( message ); + ch.write( brandMessage ); + } + + Set registeredChannels = user.getPendingConnection().getRegisteredChannels(); + if ( !registeredChannels.isEmpty() ) + { + ch.write( new PluginMessage( user.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:register" : "REGISTER", Joiner.on( "\0" ).join( registeredChannels ).getBytes( StandardCharsets.UTF_8 ), false ) ); } if ( user.getSettings() != null ) @@ -247,7 +257,7 @@ public void handle(Login login) throws Exception } else { modLogin = new Login( login.getEntityId(), login.isHardcore(), login.getGameMode(), login.getPreviousGameMode(), login.getWorldNames(), login.getDimensions(), login.getDimension(), login.getWorldName(), login.getSeed(), login.getDifficulty(), - (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() ); + (byte) user.getPendingConnection().getListener().getTabListSize(), login.getLevelType(), login.getViewDistance(), login.getSimulationDistance(), login.isReducedDebugInfo(), login.isNormalRespawn(), login.isDebug(), login.isFlat() ); } user.unsafe().sendPacket( modLogin ); 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 b62f2c61db..f8181cbb88 100644 --- a/proxy/src/main/java/net/md_5/bungee/UserConnection.java +++ b/proxy/src/main/java/net/md_5/bungee/UserConnection.java @@ -149,10 +149,7 @@ public void sendPacket(DefinedPacket packet) public void init() { - if ( getPendingConnection().getVersion() < ProtocolConstants.MINECRAFT_1_16_2 || !bungee.getConfig().isIpForward() ) - { - this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() ); - } + this.entityRewrite = EntityMap.getEntityMap( getPendingConnection().getVersion() ); this.displayName = name; diff --git a/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java b/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java index d87d0b95f3..03feeb3902 100644 --- a/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java +++ b/proxy/src/main/java/net/md_5/bungee/command/CommandEnd.java @@ -2,6 +2,7 @@ import com.google.common.base.Joiner; import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.plugin.Command; @@ -25,7 +26,7 @@ public void execute(CommandSender sender, String[] args) BungeeCord.getInstance().stop(); } else { - BungeeCord.getInstance().stop( Joiner.on( ' ' ).join( args ) ); + BungeeCord.getInstance().stop( ChatColor.translateAlternateColorCodes( '&', Joiner.on( ' ' ).join( args ) ) ); } } } 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 ff58734c1b..2437b6f064 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 @@ -63,7 +63,6 @@ import net.md_5.bungee.protocol.packet.TabCompleteResponse; import net.md_5.bungee.tab.TabList; - @RequiredArgsConstructor public class DownstreamBridge extends PacketHandler { @@ -76,8 +75,10 @@ public class DownstreamBridge extends PacketHandler public void exception(Throwable t) throws Exception { if ( server.isObsolete() ) + { // do not perform any actions if the user has already moved return; + } ServerInfo def = con.updateAndGetNextServer( server.getInfo() ); if ( def != null ) @@ -97,10 +98,14 @@ public void disconnected(ChannelWrapper channel) throws Exception // We lost connection to the server server.getInfo().removePlayer( con ); if ( bungee.getReconnectHandler() != null ) + { bungee.getReconnectHandler().setServer( con ); + } if ( !server.isObsolete() ) + { con.disconnect( bungee.getTranslation( "lost_connection" ) ); + } ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent( con, server.getInfo() ); bungee.getPluginManager().callEvent( serverDisconnectEvent ); @@ -212,7 +217,9 @@ public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception t = new Team( team.getName() ); serverScoreboard.addTeam( t ); } else + { t = serverScoreboard.getTeam( team.getName() ); + } if ( t != null ) { @@ -243,6 +250,7 @@ public void handle(net.md_5.bungee.protocol.packet.Team team) throws Exception } @Override + @SuppressWarnings("checkstyle:avoidnestedblocks") public void handle(PluginMessage pluginMessage) throws Exception { DataInput in = pluginMessage.getStream(); @@ -285,15 +293,39 @@ public void handle(PluginMessage pluginMessage) throws Exception ByteArrayDataOutput out = ByteStreams.newDataOutput(); String subChannel = in.readUTF(); - if ( subChannel.equals( "ForwardToPlayer" ) ) + switch ( subChannel ) { - ProxiedPlayer target = bungee.getPlayer( in.readUTF() ); - if ( target != null ) + case "ForwardToPlayer": + { + ProxiedPlayer target = bungee.getPlayer( in.readUTF() ); + if ( target != null ) + { + // Read data from server + String channel = in.readUTF(); + short len = in.readShort(); + byte[] data = new byte[ len ]; + in.readFully( data ); + + // Prepare new data to send + out.writeUTF( channel ); + out.writeShort( data.length ); + out.write( data ); + byte[] payload = out.toByteArray(); + + target.getServer().sendData( "BungeeCord", payload ); + } + + // Null out stream, important as we don't want to send to ourselves + out = null; + break; + } + case "Forward": { // Read data from server + String target = in.readUTF(); String channel = in.readUTF(); short len = in.readShort(); - byte[] data = new byte[len]; + byte[] data = new byte[ len ]; in.readFully( data ); // Prepare new data to send @@ -302,222 +334,221 @@ public void handle(PluginMessage pluginMessage) throws Exception out.write( data ); byte[] payload = out.toByteArray(); - target.getServer().sendData( "BungeeCord", payload ); - } + // Null out stream, important as we don't want to send to ourselves + out = null; - // Null out stream, important as we don't want to send to ourselves - out = null; - } - if ( subChannel.equals( "Forward" ) ) - { - // Read data from server - String target = in.readUTF(); - String channel = in.readUTF(); - short len = in.readShort(); - byte[] data = new byte[len]; - in.readFully( data ); - - // Prepare new data to send - out.writeUTF( channel ); - out.writeShort( data.length ); - out.write( data ); - byte[] payload = out.toByteArray(); - - // Null out stream, important as we don't want to send to ourselves - out = null; - - if ( target.equals( "ALL" ) ) + switch ( target ) + { + case "ALL": + for ( ServerInfo server : bungee.getServers().values() ) + { + if ( server != this.server.getInfo() ) + { + server.sendData( "BungeeCord", payload ); + } + } + break; + case "ONLINE": + for ( ServerInfo server : bungee.getServers().values() ) + { + if ( server != this.server.getInfo() ) + { + server.sendData( "BungeeCord", payload, false ); + } + } + break; + default: + ServerInfo server = bungee.getServerInfo( target ); + if ( server != null ) + { + server.sendData( "BungeeCord", payload ); + } + break; + } + break; + } + case "Connect": + { + ServerInfo server = bungee.getServerInfo( in.readUTF() ); + if ( server != null ) + { + con.connect( server, ServerConnectEvent.Reason.PLUGIN_MESSAGE ); + } + break; + } + case "ConnectOther": { - for ( ServerInfo server : bungee.getServers().values() ) + ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); + if ( player != null ) { - if ( server != this.server.getInfo() ) + ServerInfo server = bungee.getServerInfo( in.readUTF() ); + if ( server != null ) { - server.sendData( "BungeeCord", payload ); + player.connect( server ); } } - } else if ( target.equals( "ONLINE" ) ) + break; + } + case "IP": + out.writeUTF( "IP" ); + if ( con.getSocketAddress() instanceof InetSocketAddress ) + { + out.writeUTF( con.getAddress().getHostString() ); + out.writeInt( con.getAddress().getPort() ); + } else + { + out.writeUTF( "unix://" + ( (DomainSocketAddress) con.getSocketAddress() ).path() ); + out.writeInt( 0 ); + } + break; + case "IPOther": { - for ( ServerInfo server : bungee.getServers().values() ) + ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); + if ( player != null ) { - if ( server != this.server.getInfo() ) + out.writeUTF( "IPOther" ); + out.writeUTF( player.getName() ); + if ( player.getSocketAddress() instanceof InetSocketAddress ) + { + InetSocketAddress address = (InetSocketAddress) player.getSocketAddress(); + out.writeUTF( address.getHostString() ); + out.writeInt( address.getPort() ); + } else { - server.sendData( "BungeeCord", payload, false ); + out.writeUTF( "unix://" + ( (DomainSocketAddress) player.getSocketAddress() ).path() ); + out.writeInt( 0 ); } } - } else - { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) - server.sendData( "BungeeCord", payload ); + break; } - } - if ( subChannel.equals( "Connect" ) ) - { - ServerInfo server = bungee.getServerInfo( in.readUTF() ); - if ( server != null ) + case "PlayerCount": { - con.connect( server, ServerConnectEvent.Reason.PLUGIN_MESSAGE ); + String target = in.readUTF(); + out.writeUTF( "PlayerCount" ); + if ( target.equals( "ALL" ) ) + { + out.writeUTF( "ALL" ); + out.writeInt( bungee.getOnlineCount() ); + } else + { + ServerInfo server = bungee.getServerInfo( target ); + if ( server != null ) + { + out.writeUTF( server.getName() ); + out.writeInt( server.getPlayers().size() ); + } + } + break; } - } - if ( subChannel.equals( "ConnectOther" ) ) - { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) + case "PlayerList": { - ServerInfo server = bungee.getServerInfo( in.readUTF() ); - if ( server != null ) - player.connect( server ); + String target = in.readUTF(); + out.writeUTF( "PlayerList" ); + if ( target.equals( "ALL" ) ) + { + out.writeUTF( "ALL" ); + out.writeUTF( Util.csv( bungee.getPlayers() ) ); + } else + { + ServerInfo server = bungee.getServerInfo( target ); + if ( server != null ) + { + out.writeUTF( server.getName() ); + out.writeUTF( Util.csv( server.getPlayers() ) ); + } + } + break; } - } - if ( subChannel.equals( "IP" ) ) - { - out.writeUTF( "IP" ); - if ( con.getSocketAddress() instanceof InetSocketAddress ) - { - out.writeUTF( con.getAddress().getHostString() ); - out.writeInt( con.getAddress().getPort() ); - } else + case "GetServers": { - out.writeUTF( "unix://" + ( (DomainSocketAddress) con.getSocketAddress() ).path() ); - out.writeInt( 0 ); + out.writeUTF( "GetServers" ); + out.writeUTF( Util.csv( bungee.getServers().keySet() ) ); + break; } - } - if ( subChannel.equals( "IPOther" ) ) - { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) + case "Message": { - out.writeUTF( "IPOther" ); - out.writeUTF( player.getName() ); - if ( player.getSocketAddress() instanceof InetSocketAddress ) + String target = in.readUTF(); + String message = in.readUTF(); + if ( target.equals( "ALL" ) ) { - InetSocketAddress address = (InetSocketAddress) player.getSocketAddress(); - out.writeUTF( address.getHostString() ); - out.writeInt( address.getPort() ); + for ( ProxiedPlayer player : bungee.getPlayers() ) + { + player.sendMessage( message ); + } } else { - out.writeUTF( "unix://" + ( (DomainSocketAddress) player.getSocketAddress() ).path() ); - out.writeInt( 0 ); + ProxiedPlayer player = bungee.getPlayer( target ); + if ( player != null ) + { + player.sendMessage( message ); + } } + break; } - } - if ( subChannel.equals( "PlayerCount" ) ) - { - String target = in.readUTF(); - out.writeUTF( "PlayerCount" ); - if ( target.equals( "ALL" ) ) - { - out.writeUTF( "ALL" ); - out.writeInt( bungee.getOnlineCount() ); - } else + case "MessageRaw": { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) + String target = in.readUTF(); + BaseComponent[] message = ComponentSerializer.parse( in.readUTF() ); + if ( target.equals( "ALL" ) ) { - out.writeUTF( server.getName() ); - out.writeInt( server.getPlayers().size() ); + for ( ProxiedPlayer player : bungee.getPlayers() ) + { + player.sendMessage( message ); + } + } else + { + ProxiedPlayer player = bungee.getPlayer( target ); + if ( player != null ) + { + player.sendMessage( message ); + } } + break; } - } - if ( subChannel.equals( "PlayerList" ) ) - { - String target = in.readUTF(); - out.writeUTF( "PlayerList" ); - if ( target.equals( "ALL" ) ) - { - out.writeUTF( "ALL" ); - out.writeUTF( Util.csv( bungee.getPlayers() ) ); - } else + case "GetServer": { - ServerInfo server = bungee.getServerInfo( target ); - if ( server != null ) - { - out.writeUTF( server.getName() ); - out.writeUTF( Util.csv( server.getPlayers() ) ); - } + out.writeUTF( "GetServer" ); + out.writeUTF( server.getInfo().getName() ); + break; } - } - if ( subChannel.equals( "GetServers" ) ) - { - out.writeUTF( "GetServers" ); - out.writeUTF( Util.csv( bungee.getServers().keySet() ) ); - } - if ( subChannel.equals( "Message" ) ) - { - String target = in.readUTF(); - String message = in.readUTF(); - if ( target.equals( "ALL" ) ) + case "UUID": { - for ( ProxiedPlayer player : bungee.getPlayers() ) - { - player.sendMessage( message ); - } - } else + out.writeUTF( "UUID" ); + out.writeUTF( con.getUUID() ); + break; + } + case "UUIDOther": { - ProxiedPlayer player = bungee.getPlayer( target ); + ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); if ( player != null ) { - player.sendMessage( message ); + out.writeUTF( "UUIDOther" ); + out.writeUTF( player.getName() ); + out.writeUTF( player.getUUID() ); } + break; } - } - if ( subChannel.equals( "MessageRaw" ) ) - { - String target = in.readUTF(); - BaseComponent[] message = ComponentSerializer.parse( in.readUTF() ); - if ( target.equals( "ALL" ) ) + case "ServerIP": { - for ( ProxiedPlayer player : bungee.getPlayers() ) + ServerInfo info = bungee.getServerInfo( in.readUTF() ); + if ( info != null && !info.getAddress().isUnresolved() ) { - player.sendMessage( message ); + out.writeUTF( "ServerIP" ); + out.writeUTF( info.getName() ); + out.writeUTF( info.getAddress().getAddress().getHostAddress() ); + out.writeShort( info.getAddress().getPort() ); } - } else + break; + } + case "KickPlayer": { - ProxiedPlayer player = bungee.getPlayer( target ); + ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); if ( player != null ) { - player.sendMessage( message ); + String kickReason = in.readUTF(); + player.disconnect( new TextComponent( kickReason ) ); } - } - } - if ( subChannel.equals( "GetServer" ) ) - { - out.writeUTF( "GetServer" ); - out.writeUTF( server.getInfo().getName() ); - } - if ( subChannel.equals( "UUID" ) ) - { - out.writeUTF( "UUID" ); - out.writeUTF( con.getUUID() ); - } - if ( subChannel.equals( "UUIDOther" ) ) - { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) - { - out.writeUTF( "UUIDOther" ); - out.writeUTF( player.getName() ); - out.writeUTF( player.getUUID() ); - } - } - if ( subChannel.equals( "ServerIP" ) ) - { - ServerInfo info = bungee.getServerInfo( in.readUTF() ); - if ( info != null && !info.getAddress().isUnresolved() ) - { - out.writeUTF( "ServerIP" ); - out.writeUTF( info.getName() ); - out.writeUTF( info.getAddress().getAddress().getHostAddress() ); - out.writeShort( info.getAddress().getPort() ); - } - } - if ( subChannel.equals( "KickPlayer" ) ) - { - ProxiedPlayer player = bungee.getPlayer( in.readUTF() ); - if ( player != null ) - { - String kickReason = in.readUTF(); - player.disconnect( new TextComponent( kickReason ) ); + break; } } 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 8b0417e5cb..693b0c596e 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 @@ -7,8 +7,10 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import java.util.UUID; import java.util.logging.Level; import javax.crypto.SecretKey; @@ -62,7 +64,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.StatusRequest; import net.md_5.bungee.protocol.packet.StatusResponse; -import net.md_5.bungee.util.BoundedArrayList; +import net.md_5.bungee.util.AllowedCharacters; import net.md_5.bungee.util.BufUtil; import net.md_5.bungee.util.QuietException; @@ -80,7 +82,9 @@ public class InitialHandler extends PacketHandler implements PendingConnection private LoginRequest loginRequest; private EncryptionRequest request; @Getter - private final List relayMessages = new BoundedArrayList<>( 128 ); + private PluginMessage brandMessage; + @Getter + private final Set registeredChannels = new HashSet<>(); private State thisState = State.HANDSHAKE; private final Unsafe unsafe = new Unsafe() { @@ -115,12 +119,12 @@ public boolean shouldHandle(PacketWrapper packet) throws Exception private enum State { - HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHED; + HANDSHAKE, STATUS, PING, USERNAME, ENCRYPT, FINISHING; } private boolean canSendKickMessage() { - return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHED; + return thisState == State.USERNAME || thisState == State.ENCRYPT || thisState == State.FINISHING; } @Override @@ -153,11 +157,7 @@ public void handle(PacketWrapper packet) throws Exception @Override public void handle(PluginMessage pluginMessage) throws Exception { - // TODO: Unregister? - if ( PluginMessage.SHOULD_RELAY.apply( pluginMessage ) ) - { - relayMessages.add( pluginMessage ); - } + this.relayMessage( pluginMessage ); } @Override @@ -352,13 +352,13 @@ public void handle(Handshake handshake) throws Exception public void handle(LoginRequest loginRequest) throws Exception { Preconditions.checkState( thisState == State.USERNAME, "Not expecting USERNAME" ); - this.loginRequest = loginRequest; - if ( getName().contains( " " ) ) + if ( !AllowedCharacters.isValidName( loginRequest.getData(), onlineMode ) ) { disconnect( bungee.getTranslation( "name_invalid" ) ); return; } + this.loginRequest = loginRequest; int limit = BungeeCord.getInstance().config.getPlayerLimit(); if ( limit > 0 && bungee.getOnlineCount() >= limit ) @@ -392,12 +392,13 @@ public void done(PreLoginEvent result, Throwable error) } if ( onlineMode ) { + thisState = State.ENCRYPT; unsafe().sendPacket( request = EncryptionUtil.encryptRequest() ); } else { + thisState = State.FINISHING; finish(); } - thisState = State.ENCRYPT; } }; @@ -455,7 +456,7 @@ public void done(String result, Throwable error) } } }; - + thisState = State.FINISHING; HttpClient.get( authURL, ch.getHandle().eventLoop(), handler ); } @@ -543,8 +544,6 @@ public void run() } userCon.connect( server, null, true, ServerConnectEvent.Reason.JOIN_PROXY ); - - thisState = State.FINISHED; } } } ); @@ -669,4 +668,31 @@ public boolean isConnected() { return !ch.isClosed(); } + + public void relayMessage(PluginMessage input) throws Exception + { + if ( input.getTag().equals( "REGISTER" ) || input.getTag().equals( "minecraft:register" ) ) + { + String content = new String( input.getData(), StandardCharsets.UTF_8 ); + + for ( String id : content.split( "\0" ) ) + { + Preconditions.checkState( registeredChannels.size() < 128, "Too many registered channels" ); + Preconditions.checkArgument( id.length() < 128, "Channel name too long" ); + + registeredChannels.add( id ); + } + } else if ( input.getTag().equals( "UNREGISTER" ) || input.getTag().equals( "minecraft:unregister" ) ) + { + String content = new String( input.getData(), StandardCharsets.UTF_8 ); + + for ( String id : content.split( "\0" ) ) + { + registeredChannels.remove( id ); + } + } else if ( input.getTag().equals( "MC|Brand" ) || input.getTag().equals( "minecraft:brand" ) ) + { + brandMessage = input; + } + } } 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 ead2024b5e..7d125cf44f 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 @@ -32,6 +32,7 @@ import net.md_5.bungee.protocol.packet.PluginMessage; import net.md_5.bungee.protocol.packet.TabCompleteRequest; import net.md_5.bungee.protocol.packet.TabCompleteResponse; +import net.md_5.bungee.util.AllowedCharacters; public class UpstreamBridge extends PacketHandler { @@ -150,10 +151,9 @@ public void handle(Chat chat) throws Exception for ( int index = 0, length = chat.getMessage().length(); index < length; index++ ) { char c = chat.getMessage().charAt( index ); - // Section symbol, control sequences, and delete - if ( c == '\u00A7' || c < ' ' || c == 127 ) + if ( !AllowedCharacters.isChatAllowedCharacter( c ) ) { - con.disconnect( bungee.getTranslation( "illegal_chat_characters", String.format( "\\u%04x", (int) c ) ) ); + con.disconnect( bungee.getTranslation( "illegal_chat_characters", Util.unicode( c ) ) ); throw CancelSendSignal.INSTANCE; } } @@ -174,10 +174,11 @@ public void handle(Chat chat) throws Exception public void handle(TabCompleteRequest tabComplete) throws Exception { List suggestions = new ArrayList<>(); + boolean isRegisteredCommand = false; if ( tabComplete.getCursor().startsWith( "/" ) ) { - bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions ); + isRegisteredCommand = bungee.getPluginManager().dispatchCommand( con, tabComplete.getCursor().substring( 1 ), suggestions ); } TabCompleteEvent tabCompleteEvent = new TabCompleteEvent( con, con.getServer(), tabComplete.getCursor(), suggestions ); @@ -212,6 +213,12 @@ public void handle(TabCompleteRequest tabComplete) throws Exception } throw CancelSendSignal.INSTANCE; } + + // Don't forward tab completions if the command is a registered bungee command + if ( isRegisteredCommand ) + { + throw CancelSendSignal.INSTANCE; + } } @Override @@ -261,11 +268,7 @@ public void handle(PluginMessage pluginMessage) throws Exception throw CancelSendSignal.INSTANCE; } - // TODO: Unregister as well? - if ( PluginMessage.SHOULD_RELAY.apply( pluginMessage ) ) - { - con.getPendingConnection().getRelayMessages().add( pluginMessage ); - } + con.getPendingConnection().relayMessage( pluginMessage ); } @Override diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java index aae6ae5f50..deb75d6ffb 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java @@ -75,6 +75,8 @@ public static EntityMap getEntityMap(int version) case ProtocolConstants.MINECRAFT_1_17: case ProtocolConstants.MINECRAFT_1_17_1: return EntityMap_1_16_2.INSTANCE_1_17; + case ProtocolConstants.MINECRAFT_1_18: + return EntityMap_1_16_2.INSTANCE_1_18; } throw new RuntimeException( "Version " + version + " has no entity map" ); } diff --git a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java index df5516cacc..66586c8ca0 100644 --- a/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java +++ b/proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap_1_16_2.java @@ -16,6 +16,7 @@ class EntityMap_1_16_2 extends EntityMap static final EntityMap_1_16_2 INSTANCE_1_16_2 = new EntityMap_1_16_2( 0x04, 0x2D ); static final EntityMap_1_16_2 INSTANCE_1_17 = new EntityMap_1_16_2( 0x04, 0x2D ); + static final EntityMap_1_16_2 INSTANCE_1_18 = new EntityMap_1_16_2( 0x04, 0x2D ); // private final int spawnPlayerId; private final int spectateId; 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 270545f28e..f8d6becd69 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 @@ -83,14 +83,17 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception HAProxyMessage proxy = (HAProxyMessage) msg; try { - InetSocketAddress newAddress = new InetSocketAddress( proxy.sourceAddress(), proxy.sourcePort() ); - - ProxyServer.getInstance().getLogger().log( Level.FINE, "Set remote address via PROXY {0} -> {1}", new Object[] + if ( proxy.sourceAddress() != null ) { - channel.getRemoteAddress(), newAddress - } ); + InetSocketAddress newAddress = new InetSocketAddress( proxy.sourceAddress(), proxy.sourcePort() ); - channel.setRemoteAddress( newAddress ); + ProxyServer.getInstance().getLogger().log( Level.FINE, "Set remote address via PROXY {0} -> {1}", new Object[] + { + channel.getRemoteAddress(), newAddress + } ); + + channel.setRemoteAddress( newAddress ); + } } finally { proxy.release(); diff --git a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java index 67db0cc4e5..38b75b51b9 100644 --- a/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java +++ b/proxy/src/main/java/net/md_5/bungee/scheduler/BungeeTask.java @@ -63,7 +63,7 @@ public void run() task.run(); } catch ( Throwable t ) { - ProxyServer.getInstance().getLogger().log( Level.SEVERE, String.format( "Task %s encountered an exception", this ), t ); + ProxyServer.getInstance().getLogger().log( Level.SEVERE, "Task " + this + " encountered an exception", t ); } // If we have a period of 0 or less, only run once diff --git a/proxy/src/main/java/net/md_5/bungee/util/AllowedCharacters.java b/proxy/src/main/java/net/md_5/bungee/util/AllowedCharacters.java new file mode 100644 index 0000000000..d1cd109055 --- /dev/null +++ b/proxy/src/main/java/net/md_5/bungee/util/AllowedCharacters.java @@ -0,0 +1,39 @@ +package net.md_5.bungee.util; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class AllowedCharacters +{ + + public static boolean isChatAllowedCharacter(char character) + { + // Section symbols, control sequences, and deletes are not allowed + return character != '\u00A7' && character >= ' ' && character != 127; + } + + private static boolean isNameAllowedCharacter(char c, boolean onlineMode) + { + if ( onlineMode ) + { + return ( c >= 'a' && c <= 'z' ) || ( c >= '0' && c <= '9' ) || ( c >= 'A' && c <= 'Z' ) || c == '_'; + } else + { + // Don't allow spaces, Yaml config doesn't support them + return isChatAllowedCharacter( c ) && c != ' '; + } + } + + public static boolean isValidName(String name, boolean onlineMode) + { + for ( int index = 0, len = name.length(); index < len; index++ ) + { + if ( !isNameAllowedCharacter( name.charAt( index ), onlineMode ) ) + { + return false; + } + } + return true; + } +} diff --git a/proxy/src/main/java/net/md_5/bungee/util/BoundedArrayList.java b/proxy/src/main/java/net/md_5/bungee/util/BoundedArrayList.java deleted file mode 100644 index dad5121a26..0000000000 --- a/proxy/src/main/java/net/md_5/bungee/util/BoundedArrayList.java +++ /dev/null @@ -1,49 +0,0 @@ -package net.md_5.bungee.util; - -import com.google.common.base.Preconditions; -import java.util.ArrayList; -import java.util.Collection; - -public class BoundedArrayList extends ArrayList -{ - - private final int maxSize; - - public BoundedArrayList(int maxSize) - { - this.maxSize = maxSize; - } - - private void checkSize(int increment) - { - Preconditions.checkState( size() + increment <= maxSize, "Adding %s elements would exceed capacity of %s", increment, maxSize ); - } - - @Override - public boolean add(E e) - { - checkSize( 1 ); - return super.add( e ); - } - - @Override - public void add(int index, E element) - { - checkSize( 1 ); - super.add( index, element ); - } - - @Override - public boolean addAll(Collection c) - { - checkSize( c.size() ); - return super.addAll( c ); - } - - @Override - public boolean addAll(int index, Collection c) - { - checkSize( c.size() ); - return super.addAll( index, c ); - } -} diff --git a/proxy/src/main/resources/messages.properties b/proxy/src/main/resources/messages.properties index 0b7e74c967..5890e8c909 100644 --- a/proxy/src/main/resources/messages.properties +++ b/proxy/src/main/resources/messages.properties @@ -17,7 +17,6 @@ outdated_client=Outdated client! Please use {0} outdated_server=Outdated server! I''m still on {0} proxy_full=Server is full! restart=[Proxy] Proxy restarting. -server_kick=[Kicked] server_list=\u00a76You may connect to the following servers at this time: server_went_down=\u00a7cThe server you were previously on went down, you have been connected to a fallback server total_players=Total players online: {0} @@ -33,7 +32,6 @@ user_not_online=\u00a7cThat user is not online. user_online_at=\u00a7a{0} \u00a7ris online at {1} send_cmd_usage=\u00a7cNot enough arguments, usage: /send player_only=\u00a7cOnly in game players can use this command -successfully_summoned=\u00a7aSuccessfully summoned player(s) you_got_summoned=\u00a76Summoned to {0} by {1} command_perms_groups=\u00a76You have the following groups: {0} command_perms_permission=\u00a79- {0} diff --git a/proxy/src/test/java/net/md_5/bungee/util/BoundedArrayListTest.java b/proxy/src/test/java/net/md_5/bungee/util/BoundedArrayListTest.java deleted file mode 100644 index d66305d9e0..0000000000 --- a/proxy/src/test/java/net/md_5/bungee/util/BoundedArrayListTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.md_5.bungee.util; - -import com.google.common.collect.ImmutableList; -import org.junit.Test; - -public class BoundedArrayListTest -{ - - @Test - public void testGoodAdd() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 2 ); - list.add( new Object() ); - list.add( new Object() ); - } - - @Test - public void testSizeOneAdd() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 1 ); - list.add( new Object() ); - } - - @Test(expected = IllegalStateException.class) - public void testBadAdd() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 0 ); - list.add( new Object() ); - } - - @Test - public void testGoodAdd1() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 2 ); - list.add( new Object() ); - list.add( 0, new Object() ); - } - - @Test(expected = IllegalStateException.class) - public void testBadAdd1() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 1 ); - list.add( new Object() ); - list.add( 0, new Object() ); - } - - @Test - public void testGoodAddAll() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 1 ); - list.addAll( ImmutableList.of( new Object() ) ); - } - - @Test - public void testGoodAddAll1() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 2 ); - list.add( new Object() ); - list.addAll( 0, ImmutableList.of( new Object() ) ); - } - - @Test(expected = IllegalStateException.class) - public void testBadAddAll() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 0 ); - list.addAll( ImmutableList.of( new Object() ) ); - } - - @Test(expected = IllegalStateException.class) - public void testBadAddAll1() throws Exception - { - BoundedArrayList list = new BoundedArrayList<>( 1 ); - list.add( new Object() ); - list.addAll( ImmutableList.of( new Object() ) ); - } -} diff --git a/query/pom.xml b/query/pom.xml index 4212899e72..9e0c453989 100644 --- a/query/pom.xml +++ b/query/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-query - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-Query diff --git a/slf4j/pom.xml b/slf4j/pom.xml index fd365ed0b0..d9495ea752 100644 --- a/slf4j/pom.xml +++ b/slf4j/pom.xml @@ -6,13 +6,13 @@ net.md-5 bungeecord-parent - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT ../pom.xml net.md-5 bungeecord-slf4j - 1.17-R0.1-SNAPSHOT + 1.18-R0.1-SNAPSHOT jar BungeeCord-SLF4J