Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit 2026bb5

Browse files
committed
Merge branch 'SpigotMC-master'
2 parents 31d9e3c + dbbab41 commit 2026bb5

File tree

26 files changed

+90
-40
lines changed

26 files changed

+90
-40
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "native/mbedtls"]
2+
path = native/mbedtls
3+
url = https://github.com/ARMmbed/mbedtls.git
4+
[submodule "native/zlib"]
5+
path = native/zlib
6+
url = https://github.com/cloudflare/zlib.git

log/src/main/java/net/md_5/bungee/log/BungeeLogger.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ public class BungeeLogger extends Logger
1313

1414
private final LogDispatcher dispatcher = new LogDispatcher( this );
1515

16+
// CHECKSTYLE:OFF
1617
@SuppressWarnings(
1718
{
1819
"CallToPrintStackTrace", "CallToThreadStartDuringObjectConstruction"
1920
})
21+
// CHECKSTYLE:ON
2022
@SuppressFBWarnings("SC_START_IN_CTOR")
2123
public BungeeLogger(String loggerName, String filePattern, ConsoleReader reader)
2224
{

native/compile-native.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/bin/sh
22

3-
CXX="g++ -shared -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/"
3+
set -eu
44

5-
$CXX src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so -lcrypto
6-
$CXX src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so -lz
5+
echo "Compiling mbedtls"
6+
(cd mbedtls && make no_test)
7+
8+
echo "Compiling zlib"
9+
(cd zlib && CFLAGS=-fPIC ./configure --static && make)
10+
11+
CXX="g++ -shared -fPIC -Wl,--wrap=memcpy -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/"
12+
13+
$CXX -Imbedtls/include src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so mbedtls/library/libmbedcrypto.a
14+
$CXX -Izlib src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so zlib/libz.a

native/mbedtls

Submodule mbedtls added at e483a77

native/src/main/c/NativeCipherImpl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
// Support for CentOS 6
2-
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
3-
41
#include <stdlib.h>
52
#include <string.h>
63

74
#include <mbedtls/aes.h>
85
#include "net_md_5_bungee_jni_cipher_NativeCipherImpl.h"
96

7+
// Support for CentOS 6
8+
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
9+
extern "C" void *__wrap_memcpy(void *dest, const void *src, size_t n) {
10+
return memcpy(dest, src, n);
11+
}
12+
1013
typedef unsigned char byte;
1114

1215
struct crypto_context {

native/src/main/c/NativeCompressImpl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
#include <stdlib.h>
2+
#include <string.h>
3+
24
#include <zlib.h>
35
#include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h"
46

7+
// Support for CentOS 6
8+
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
9+
extern "C" void *__wrap_memcpy(void *dest, const void *src, size_t n) {
10+
return memcpy(dest, src, n);
11+
}
12+
513
typedef unsigned char byte;
614

715
static jfieldID consumedID;

native/src/main/java/net/md_5/bungee/jni/NativeCode.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
import java.io.IOException;
77
import java.io.InputStream;
88
import java.io.OutputStream;
9+
import java.util.function.Supplier;
910
import net.md_5.bungee.jni.cipher.BungeeCipher;
1011

1112
public final class NativeCode<T>
1213
{
1314

1415
private final String name;
15-
private final Class<? extends T> javaImpl;
16-
private final Class<? extends T> nativeImpl;
16+
private final Supplier<? extends T> javaImpl;
17+
private final Supplier<? extends T> nativeImpl;
1718
//
1819
private boolean loaded;
1920

20-
public NativeCode(String name, Class<? extends T> javaImpl, Class<? extends T> nativeImpl)
21+
public NativeCode(String name, Supplier<? extends T> javaImpl, Supplier<? extends T> nativeImpl)
2122
{
2223
this.name = name;
2324
this.javaImpl = javaImpl;
@@ -26,13 +27,7 @@ public NativeCode(String name, Class<? extends T> javaImpl, Class<? extends T> n
2627

2728
public T newInstance()
2829
{
29-
try
30-
{
31-
return ( loaded ) ? nativeImpl.getDeclaredConstructor().newInstance() : javaImpl.getDeclaredConstructor().newInstance();
32-
} catch ( ReflectiveOperationException ex )
33-
{
34-
throw new RuntimeException( "Error getting instance", ex );
35-
}
30+
return ( loaded ) ? nativeImpl.get() : javaImpl.get();
3631
}
3732

3833
public boolean load()

native/src/main/java/net/md_5/bungee/jni/cipher/JavaCipher.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ protected byte[] initialValue()
2525
}
2626
}
2727

28-
public JavaCipher() throws GeneralSecurityException
28+
public JavaCipher()
2929
{
30-
this.cipher = Cipher.getInstance( "AES/CFB8/NoPadding" );
30+
try
31+
{
32+
this.cipher = Cipher.getInstance( "AES/CFB8/NoPadding" );
33+
} catch ( GeneralSecurityException ex )
34+
{
35+
throw new RuntimeException( ex );
36+
}
3137
}
3238

3339
@Override
8.16 KB
Binary file not shown.
32.6 KB
Binary file not shown.

native/src/test/java/net/md_5/bungee/NativeCipherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class NativeCipherTest
2626
private final SecretKey secret = new SecretKeySpec( new byte[ 16 ], "AES" );
2727
private static final int BENCHMARK_COUNT = 4096;
2828
//
29-
private static final NativeCode<BungeeCipher> factory = new NativeCode<>( "native-cipher", JavaCipher.class, NativeCipher.class );
29+
private static final NativeCode<BungeeCipher> factory = new NativeCode<>( "native-cipher", JavaCipher::new, NativeCipher::new );
3030

3131
@Test
3232
public void testNative() throws Exception

native/src/test/java/net/md_5/bungee/NativeZlibTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class NativeZlibTest
1616
{
1717

18-
private final NativeCode<BungeeZlib> factory = new NativeCode<>( "native-compress", JavaZlib.class, NativeZlib.class );
18+
private final NativeCode<BungeeZlib> factory = new NativeCode<>( "native-compress", JavaZlib::new, NativeZlib::new );
1919

2020
@Test
2121
public void doTest() throws DataFormatException

native/zlib

Submodule zlib added at 959b4ea

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
<plugin>
139139
<groupId>org.apache.maven.plugins</groupId>
140140
<artifactId>maven-checkstyle-plugin</artifactId>
141-
<version>3.1.1</version>
141+
<version>3.1.2</version>
142142
<executions>
143143
<execution>
144144
<phase>process-classes</phase>
@@ -156,14 +156,14 @@
156156
<dependency>
157157
<groupId>com.puppycrawl.tools</groupId>
158158
<artifactId>checkstyle</artifactId>
159-
<version>8.36.2</version>
159+
<version>8.44</version>
160160
</dependency>
161161
</dependencies>
162162
</plugin>
163163
<plugin>
164164
<groupId>org.codehaus.mojo</groupId>
165165
<artifactId>animal-sniffer-maven-plugin</artifactId>
166-
<version>1.19</version>
166+
<version>1.20</version>
167167
<executions>
168168
<execution>
169169
<phase>process-classes</phase>

protocol/src/main/java/net/md_5/bungee/protocol/ProtocolConstants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ProtocolConstants
3737
public static final int MINECRAFT_1_16_3 = 753;
3838
public static final int MINECRAFT_1_16_4 = 754;
3939
public static final int MINECRAFT_1_17 = 755;
40+
public static final int MINECRAFT_1_17_1 = 756;
4041
public static final List<String> SUPPORTED_VERSIONS;
4142
public static final List<Integer> SUPPORTED_VERSION_IDS;
4243

@@ -85,7 +86,8 @@ public class ProtocolConstants
8586
ProtocolConstants.MINECRAFT_1_16_2,
8687
ProtocolConstants.MINECRAFT_1_16_3,
8788
ProtocolConstants.MINECRAFT_1_16_4,
88-
ProtocolConstants.MINECRAFT_1_17
89+
ProtocolConstants.MINECRAFT_1_17,
90+
ProtocolConstants.MINECRAFT_1_17_1
8991
);
9092

9193
if ( SNAPSHOT_SUPPORT )

protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public Chat(String message, byte position, UUID sender)
4040
@Override
4141
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
4242
{
43-
message = readString( buf, ( direction == ProtocolConstants.Direction.TO_CLIENT ) ? 262144 : 256 );
43+
message = readString( buf, ( direction == ProtocolConstants.Direction.TO_CLIENT ) ? 262144 : ( protocolVersion >= ProtocolConstants.MINECRAFT_1_11 ? 256 : 100 ) );
4444
if ( direction == ProtocolConstants.Direction.TO_CLIENT && protocolVersion >= ProtocolConstants.MINECRAFT_1_8 )
4545
{
4646
position = buf.readByte();

protocol/src/main/java/net/md_5/bungee/protocol/packet/TabCompleteRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protoco
4141
{
4242
transactionId = readVarInt( buf );
4343
}
44-
cursor = readString( buf, 32500 );
44+
cursor = readString( buf, ( protocolVersion > ProtocolConstants.MINECRAFT_1_13 ? 32500 : ( protocolVersion == ProtocolConstants.MINECRAFT_1_13 ? 256 : 32767 ) ) );
4545

4646
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_8 && protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
4747
{

proxy/src/main/java/net/md_5/bungee/BungeeCord.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public BungeeCord() throws IOException
265265
public void start() throws Exception
266266
{
267267
System.setProperty( "io.netty.selectorAutoRebuildThreshold", "0" ); // Seems to cause Bungee to stop accepting connections
268-
if ( System.getProperty( "io.netty.leakDetectionLevel" ) == null )
268+
if ( System.getProperty( "io.netty.leakDetectionLevel" ) == null && System.getProperty( "io.netty.leakDetection.level" ) == null )
269269
{
270270
ResourceLeakDetector.setLevel( ResourceLeakDetector.Level.DISABLED ); // Eats performance
271271
}

proxy/src/main/java/net/md_5/bungee/EncryptionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class EncryptionUtil
3131
public static final KeyPair keys;
3232
@Getter
3333
private static final SecretKey secret = new SecretKeySpec( new byte[ 16 ], "AES" );
34-
public static final NativeCode<BungeeCipher> nativeFactory = new NativeCode<>( "native-cipher", JavaCipher.class, NativeCipher.class );
34+
public static final NativeCode<BungeeCipher> nativeFactory = new NativeCode<>( "native-cipher", JavaCipher::new, NativeCipher::new );
3535

3636
static
3737
{

proxy/src/main/java/net/md_5/bungee/UserConnection.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.netty.channel.ChannelFutureListener;
99
import io.netty.channel.ChannelInitializer;
1010
import io.netty.channel.ChannelOption;
11+
import io.netty.channel.ConnectTimeoutException;
1112
import io.netty.util.internal.PlatformDependent;
1213
import java.net.InetSocketAddress;
1314
import java.net.SocketAddress;
@@ -359,10 +360,10 @@ public void operationComplete(ChannelFuture future) throws Exception
359360
connect( def, null, true, ServerConnectEvent.Reason.LOBBY_FALLBACK );
360361
} else if ( dimensionChange )
361362
{
362-
disconnect( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
363+
disconnect( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) );
363364
} else
364365
{
365-
sendMessage( bungee.getTranslation( "fallback_kick", future.cause().getClass().getName() ) );
366+
sendMessage( bungee.getTranslation( "fallback_kick", connectionFailMessage( future.cause() ) ) );
366367
}
367368
}
368369
}
@@ -381,6 +382,17 @@ public void operationComplete(ChannelFuture future) throws Exception
381382
b.connect().addListener( listener );
382383
}
383384

385+
private String connectionFailMessage(Throwable cause)
386+
{
387+
if ( cause instanceof ConnectTimeoutException )
388+
{
389+
return bungee.getTranslation( "timeout" );
390+
} else
391+
{
392+
return cause.getClass().getName();
393+
}
394+
}
395+
384396
@Override
385397
public void disconnect(String reason)
386398
{

proxy/src/main/java/net/md_5/bungee/compress/CompressFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
public class CompressFactory
99
{
1010

11-
public static final NativeCode<BungeeZlib> zlib = new NativeCode<>( "native-compress", JavaZlib.class, NativeZlib.class );
11+
public static final NativeCode<BungeeZlib> zlib = new NativeCode<>( "native-compress", JavaZlib::new, NativeZlib::new );
1212
}

proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,6 @@ public void handle(LoginRequest loginRequest) throws Exception
360360
return;
361361
}
362362

363-
if ( getName().length() > 16 )
364-
{
365-
disconnect( bungee.getTranslation( "name_too_long" ) );
366-
return;
367-
}
368-
369363
int limit = BungeeCord.getInstance().config.getPlayerLimit();
370364
if ( limit > 0 && bungee.getOnlineCount() >= limit )
371365
{

proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,16 @@ public void handle(KeepAlive alive) throws Exception
147147
@Override
148148
public void handle(Chat chat) throws Exception
149149
{
150-
int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100;
151-
Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates
150+
for ( int index = 0, length = chat.getMessage().length(); index < length; index++ )
151+
{
152+
char c = chat.getMessage().charAt( index );
153+
// Section symbol, control sequences, and delete
154+
if ( c == '\u00A7' || c < ' ' || c == 127 )
155+
{
156+
con.disconnect( bungee.getTranslation( "illegal_chat_characters", String.format( "\\u%04x", (int) c ) ) );
157+
throw CancelSendSignal.INSTANCE;
158+
}
159+
}
152160

153161
ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() );
154162
if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )

proxy/src/main/java/net/md_5/bungee/entitymap/EntityMap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public static EntityMap getEntityMap(int version)
7373
case ProtocolConstants.MINECRAFT_1_16_4:
7474
return EntityMap_1_16_2.INSTANCE_1_16_2;
7575
case ProtocolConstants.MINECRAFT_1_17:
76+
case ProtocolConstants.MINECRAFT_1_17_1:
7677
return EntityMap_1_16_2.INSTANCE_1_17;
7778
}
7879
throw new RuntimeException( "Version " + version + " has no entity map" );

proxy/src/main/java/net/md_5/bungee/module/ModuleManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ public ModuleManager()
3232
knownSources.put( "travis-ci", new TravisCiModuleSource() );
3333
}
3434

35+
// CHECKSTYLE:OFF
3536
@SuppressFBWarnings(
3637
{
3738
"SF_SWITCH_FALLTHROUGH", "SF_SWITCH_NO_DEFAULT"
3839
})
40+
// CHECKSTYLE:ON
3941
public void load(ProxyServer proxy, File moduleDirectory) throws Exception
4042
{
4143
moduleDirectory.mkdir();

proxy/src/main/resources/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ connect_kick=\u00a7cKicked whilst connecting to {0}: {1}
77
current_server=\u00a76You are currently connected to {0}.
88
fallback_kick=\u00a7cCould not connect to a default or fallback server, please try again later: {0}
99
fallback_lobby=\u00a7cCould not connect to target server, you have been moved to a fallback server.
10+
timeout=Server not reachable (timeout). Offline? Incorrectly configured address/port/firewall?
1011
lost_connection=[Proxy] Lost connection to server.
1112
mojang_fail=Error occurred while contacting login servers, are they down?
1213
no_permission=\u00a7cYou do not have permission to execute this command!
@@ -20,7 +21,6 @@ server_kick=[Kicked]
2021
server_list=\u00a76You may connect to the following servers at this time:
2122
server_went_down=\u00a7cThe server you were previously on went down, you have been connected to a fallback server
2223
total_players=Total players online: {0}
23-
name_too_long=Cannot have username longer than 16 characters
2424
name_invalid=Username contains invalid characters.
2525
ping_cannot_connect=\u00a7c[Bungee] Can''t connect to server.
2626
offline_mode_player=Not authenticated with Minecraft.net
@@ -38,3 +38,4 @@ you_got_summoned=\u00a76Summoned to {0} by {1}
3838
command_perms_groups=\u00a76You have the following groups: {0}
3939
command_perms_permission=\u00a79- {0}
4040
command_ip=\u00a79IP of {0} is {1}
41+
illegal_chat_characters=\u00a7cillegal characters in chat ({0})

0 commit comments

Comments
 (0)