Compare commits
10 Commits
18eae8a1a6
...
8b195d1d21
Author | SHA1 | Date | |
---|---|---|---|
|
8b195d1d21 | ||
|
cda4537fba | ||
|
df413f62db | ||
|
8a88ce464e | ||
|
006a14a75c | ||
|
07df657f3c | ||
|
b8b373a53e | ||
|
e7e0b97cff | ||
|
52ab21b1ff | ||
|
8e8a635361 |
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-api</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-API</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-bootstrap</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Bootstrap</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-chat</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Chat</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-config</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Config</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-event</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Event</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-log</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Log</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-alert</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_alert</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-find</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_find</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-kick</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_kick</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-list</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_list</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-send</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_send</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-cmd-server</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>cmd_server</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>BungeeCord Modules</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-module-reconnect-yaml</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>reconnect_yaml</name>
|
||||
|
@ -8,7 +8,20 @@ echo "Compiling mbedtls"
|
||||
echo "Compiling zlib"
|
||||
(cd zlib && CFLAGS=-fPIC ./configure --static && make)
|
||||
|
||||
CXX="g++ -shared -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/"
|
||||
CC="gcc"
|
||||
CFLAGS="-c -fPIC -O3 -Wall -Werror -I$JAVA_HOME/include/ -I$JAVA_HOME/include/linux/"
|
||||
LDFLAGS="-shared"
|
||||
|
||||
$CXX -Imbedtls/include src/main/c/NativeCipherImpl.cpp -o src/main/resources/native-cipher.so mbedtls/library/libmbedcrypto.a
|
||||
$CXX -Izlib src/main/c/NativeCompressImpl.cpp -o src/main/resources/native-compress.so zlib/libz.a
|
||||
echo "Compiling bungee"
|
||||
$CC $CFLAGS -o shared.o src/main/c/shared.c
|
||||
$CC $CFLAGS -Imbedtls/include -o NativeCipherImpl.o src/main/c/NativeCipherImpl.c
|
||||
$CC $CFLAGS -Izlib -o NativeCompressImpl.o src/main/c/NativeCompressImpl.c
|
||||
|
||||
echo "Linking native-cipher.so"
|
||||
$CC $LDFLAGS -o src/main/resources/native-cipher.so shared.o NativeCipherImpl.o mbedtls/library/libmbedcrypto.a
|
||||
|
||||
echo "Linking native-compress.so"
|
||||
$CC $LDFLAGS -o src/main/resources/native-compress.so shared.o NativeCompressImpl.o zlib/libz.a
|
||||
|
||||
echo "Cleaning up"
|
||||
rm shared.o NativeCipherImpl.o NativeCompressImpl.o
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-native</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Native</name>
|
||||
|
@ -2,31 +2,33 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <mbedtls/aes.h>
|
||||
#include "shared.h"
|
||||
#include "net_md_5_bungee_jni_cipher_NativeCipherImpl.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
struct crypto_context {
|
||||
typedef struct crypto_context {
|
||||
int mode;
|
||||
mbedtls_aes_context cipher;
|
||||
byte *key;
|
||||
};
|
||||
byte key[];
|
||||
} crypto_context;
|
||||
|
||||
jlong JNICALL Java_net_md_15_bungee_jni_cipher_NativeCipherImpl_init(JNIEnv* env, jobject obj, jboolean forEncryption, jbyteArray key) {
|
||||
jsize keyLen = env->GetArrayLength(key);
|
||||
jbyte *keyBytes = env->GetByteArrayElements(key, NULL);
|
||||
jsize keyLen = (*env)->GetArrayLength(env, key);
|
||||
|
||||
crypto_context *crypto = (crypto_context*) malloc(sizeof (crypto_context) + (size_t) keyLen);
|
||||
if (!crypto) {
|
||||
throwOutOfMemoryError(env, "Failed to malloc new crypto_context");
|
||||
return 0;
|
||||
}
|
||||
|
||||
(*env)->GetByteArrayRegion(env, key, 0, keyLen, (jbyte*) &crypto->key);
|
||||
|
||||
crypto_context *crypto = (crypto_context*) malloc(sizeof (crypto_context));
|
||||
mbedtls_aes_init(&crypto->cipher);
|
||||
|
||||
mbedtls_aes_setkey_enc(&crypto->cipher, (byte*) keyBytes, keyLen * 8);
|
||||
|
||||
crypto->key = (byte*) malloc(keyLen);
|
||||
memcpy(crypto->key, keyBytes, keyLen);
|
||||
mbedtls_aes_setkey_enc(&crypto->cipher, (byte*) &crypto->key, keyLen * 8);
|
||||
|
||||
crypto->mode = (forEncryption) ? MBEDTLS_AES_ENCRYPT : MBEDTLS_AES_DECRYPT;
|
||||
|
||||
env->ReleaseByteArrayElements(key, keyBytes, JNI_ABORT);
|
||||
return (jlong) crypto;
|
||||
}
|
||||
|
||||
@ -34,7 +36,6 @@ void Java_net_md_15_bungee_jni_cipher_NativeCipherImpl_free(JNIEnv* env, jobject
|
||||
crypto_context *crypto = (crypto_context*) ctx;
|
||||
|
||||
mbedtls_aes_free(&crypto->cipher);
|
||||
free(crypto->key);
|
||||
free(crypto);
|
||||
}
|
||||
|
@ -2,28 +2,28 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <zlib.h>
|
||||
#include "shared.h"
|
||||
#include "net_md_5_bungee_jni_zlib_NativeCompressImpl.h"
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
static jclass classID;
|
||||
static jfieldID consumedID;
|
||||
static jfieldID finishedID;
|
||||
static jmethodID makeExceptionID;
|
||||
|
||||
void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_initFields(JNIEnv* env, jclass clazz) {
|
||||
// We trust that these fields will be there
|
||||
consumedID = env->GetFieldID(clazz, "consumed", "I");
|
||||
finishedID = env->GetFieldID(clazz, "finished", "Z");
|
||||
classID = clazz;
|
||||
// We trust that these will be there
|
||||
consumedID = (*env)->GetFieldID(env, clazz, "consumed", "I");
|
||||
finishedID = (*env)->GetFieldID(env, clazz, "finished", "Z");
|
||||
makeExceptionID = (*env)->GetMethodID(env, clazz, "makeException", "(Ljava/lang/String;I)Lnet/md_5/bungee/jni/NativeCodeException;");
|
||||
}
|
||||
|
||||
jint throwException(JNIEnv *env, const char* message, int err) {
|
||||
// These can't be static for some unknown reason
|
||||
jclass exceptionClass = env->FindClass("net/md_5/bungee/jni/NativeCodeException");
|
||||
jmethodID exceptionInitID = env->GetMethodID(exceptionClass, "<init>", "(Ljava/lang/String;I)V");
|
||||
|
||||
jstring jMessage = env->NewStringUTF(message);
|
||||
|
||||
jthrowable throwable = (jthrowable) env->NewObject(exceptionClass, exceptionInitID, jMessage, err);
|
||||
return env->Throw(throwable);
|
||||
jstring jMessage = (*env)->NewStringUTF(env, message);
|
||||
jthrowable throwable = (jthrowable) (*env)->CallStaticObjectMethod(env, classID, makeExceptionID, jMessage, err);
|
||||
return (*env)->Throw(env, throwable);
|
||||
}
|
||||
|
||||
void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_reset(JNIEnv* env, jobject obj, jlong ctx, jboolean compress) {
|
||||
@ -48,10 +48,17 @@ void JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_end(JNIEnv* env,
|
||||
|
||||
jlong JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_init(JNIEnv* env, jobject obj, jboolean compress, jint level) {
|
||||
z_stream* stream = (z_stream*) calloc(1, sizeof (z_stream));
|
||||
if (!stream) {
|
||||
throwOutOfMemoryError(env, "Failed to calloc new z_stream");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = (compress) ? deflateInit(stream, level) : inflateInit(stream);
|
||||
|
||||
if (ret != Z_OK) {
|
||||
free(stream);
|
||||
throwException(env, "Could not init z_stream", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (jlong) stream;
|
||||
@ -70,15 +77,16 @@ jint JNICALL Java_net_md_15_bungee_jni_zlib_NativeCompressImpl_process(JNIEnv* e
|
||||
|
||||
switch (ret) {
|
||||
case Z_STREAM_END:
|
||||
env->SetBooleanField(obj, finishedID, true);
|
||||
(*env)->SetBooleanField(env, obj, finishedID, JNI_TRUE);
|
||||
break;
|
||||
case Z_OK:
|
||||
break;
|
||||
default:
|
||||
throwException(env, "Unknown z_stream return code", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
env->SetIntField(obj, consumedID, inLength - stream->avail_in);
|
||||
(*env)->SetIntField(env, obj, consumedID, inLength - stream->avail_in);
|
||||
|
||||
return outLength - stream->avail_out;
|
||||
}
|
15
native/src/main/c/shared.c
Normal file
15
native/src/main/c/shared.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include "shared.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void throwOutOfMemoryError(JNIEnv* env, const char* msg) {
|
||||
jclass exceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
|
||||
if (!exceptionClass) {
|
||||
// If the proxy ran out of memory, loading this class may fail
|
||||
fprintf(stderr, "OUT OF MEMORY: %s\n", msg);
|
||||
fprintf(stderr, "Could not load class java.lang.OutOfMemoryError!\n");
|
||||
exit(-1);
|
||||
return;
|
||||
}
|
||||
(*env)->ThrowNew(env, exceptionClass, msg);
|
||||
}
|
10
native/src/main/c/shared.h
Normal file
10
native/src/main/c/shared.h
Normal file
@ -0,0 +1,10 @@
|
||||
// This header contains functions to be shared between both native libraries
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#ifndef _INCLUDE_SHARED_H
|
||||
#define _INCLUDE_SHARED_H
|
||||
|
||||
void throwOutOfMemoryError(JNIEnv* env, const char* msg);
|
||||
|
||||
#endif
|
@ -1,6 +1,6 @@
|
||||
package net.md_5.bungee.jni;
|
||||
|
||||
public class NativeCodeException extends Exception
|
||||
public class NativeCodeException extends RuntimeException
|
||||
{
|
||||
|
||||
public NativeCodeException(String message, int reason)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.md_5.bungee.jni.zlib;
|
||||
|
||||
import net.md_5.bungee.jni.NativeCodeException;
|
||||
|
||||
public class NativeCompressImpl
|
||||
{
|
||||
|
||||
@ -20,4 +22,9 @@ public class NativeCompressImpl
|
||||
native long init(boolean compress, int compressionLevel);
|
||||
|
||||
native int process(long ctx, long in, int inLength, long out, int outLength, boolean compress);
|
||||
|
||||
NativeCodeException makeException(String message, int err)
|
||||
{
|
||||
return new NativeCodeException( message, err );
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.zip.DataFormatException;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.jni.NativeCodeException;
|
||||
|
||||
public class NativeZlib implements BungeeZlib
|
||||
{
|
||||
@ -48,7 +49,14 @@ public class NativeZlib implements BungeeZlib
|
||||
{
|
||||
out.ensureWritable( 8192 );
|
||||
|
||||
int processed = nativeCompress.process( ctx, in.memoryAddress() + in.readerIndex(), in.readableBytes(), out.memoryAddress() + out.writerIndex(), out.writableBytes(), compress );
|
||||
int processed;
|
||||
try
|
||||
{
|
||||
processed = nativeCompress.process( ctx, in.memoryAddress() + in.readerIndex(), in.readableBytes(), out.memoryAddress() + out.writerIndex(), out.writableBytes(), compress );
|
||||
} catch ( NativeCodeException exception )
|
||||
{
|
||||
throw (DataFormatException) new DataFormatException( "Failed to decompress via Zlib!" ).initCause( exception );
|
||||
}
|
||||
|
||||
in.readerIndex( in.readerIndex() + nativeCompress.consumed );
|
||||
out.writerIndex( out.writerIndex() + processed );
|
||||
|
Binary file not shown.
Binary file not shown.
@ -28,6 +28,17 @@ public class NativeZlibTest
|
||||
test( new JavaZlib() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testException() throws DataFormatException
|
||||
{
|
||||
if ( NativeCode.isSupported() )
|
||||
{
|
||||
assertTrue( factory.load(), "Native code failed to load!" );
|
||||
testExceptionImpl( factory.newInstance() );
|
||||
}
|
||||
testExceptionImpl( new JavaZlib() );
|
||||
}
|
||||
|
||||
private void test(BungeeZlib zlib) throws DataFormatException
|
||||
{
|
||||
System.out.println( "Testing: " + zlib );
|
||||
@ -66,4 +77,22 @@ public class NativeZlibTest
|
||||
|
||||
assertTrue( Arrays.equals( dataBuf, check ), "Results do not match" );
|
||||
}
|
||||
|
||||
private void testExceptionImpl(BungeeZlib zlib) throws DataFormatException
|
||||
{
|
||||
System.out.println( "Testing Exception: " + zlib );
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
byte[] dataBuf = new byte[ 1 << 12 ]; // 4096 random bytes
|
||||
new Random().nextBytes( dataBuf );
|
||||
|
||||
zlib.init( false, 0 );
|
||||
|
||||
ByteBuf originalBuf = Unpooled.directBuffer();
|
||||
originalBuf.writeBytes( dataBuf );
|
||||
|
||||
ByteBuf decompressed = Unpooled.directBuffer();
|
||||
|
||||
assertThrows( DataFormatException.class, () -> zlib.process( originalBuf, decompressed ), "Decompressing random bytes did not result in a DataFormatException!" );
|
||||
}
|
||||
}
|
||||
|
4
pom.xml
4
pom.xml
@ -5,7 +5,7 @@
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>BungeeCord-Parent</name>
|
||||
@ -83,7 +83,7 @@
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-bom</artifactId>
|
||||
<version>4.1.109.Final</version>
|
||||
<version>4.1.110.Final</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-protocol</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Protocol</name>
|
||||
|
@ -10,6 +10,7 @@ import net.md_5.bungee.protocol.packet.ClientStatus;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import net.md_5.bungee.protocol.packet.CookieRequest;
|
||||
import net.md_5.bungee.protocol.packet.CookieResponse;
|
||||
import net.md_5.bungee.protocol.packet.DisconnectReportDetails;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
||||
import net.md_5.bungee.protocol.packet.EntityStatus;
|
||||
@ -38,6 +39,7 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScoreReset;
|
||||
import net.md_5.bungee.protocol.packet.ServerData;
|
||||
import net.md_5.bungee.protocol.packet.ServerLinks;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
import net.md_5.bungee.protocol.packet.StartConfiguration;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
@ -268,4 +270,12 @@ public abstract class AbstractPacketHandler
|
||||
public void handle(CookieResponse cookieResponse) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(DisconnectReportDetails disconnectReportDetails) throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void handle(ServerLinks serverLinks) throws Exception
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import net.md_5.bungee.protocol.packet.ClientSettings;
|
||||
import net.md_5.bungee.protocol.packet.Commands;
|
||||
import net.md_5.bungee.protocol.packet.CookieRequest;
|
||||
import net.md_5.bungee.protocol.packet.CookieResponse;
|
||||
import net.md_5.bungee.protocol.packet.DisconnectReportDetails;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionRequest;
|
||||
import net.md_5.bungee.protocol.packet.EncryptionResponse;
|
||||
import net.md_5.bungee.protocol.packet.EntityStatus;
|
||||
@ -44,6 +45,7 @@ import net.md_5.bungee.protocol.packet.ScoreboardObjective;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScore;
|
||||
import net.md_5.bungee.protocol.packet.ScoreboardScoreReset;
|
||||
import net.md_5.bungee.protocol.packet.ServerData;
|
||||
import net.md_5.bungee.protocol.packet.ServerLinks;
|
||||
import net.md_5.bungee.protocol.packet.SetCompression;
|
||||
import net.md_5.bungee.protocol.packet.StartConfiguration;
|
||||
import net.md_5.bungee.protocol.packet.StatusRequest;
|
||||
@ -496,6 +498,16 @@ public enum Protocol
|
||||
Transfer::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x73 )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
DisconnectReportDetails.class,
|
||||
DisconnectReportDetails::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_21, 0x7A )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ServerLinks.class,
|
||||
ServerLinks::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_21, 0x7B )
|
||||
);
|
||||
|
||||
TO_SERVER.registerPacket(
|
||||
KeepAlive.class,
|
||||
@ -742,6 +754,16 @@ public enum Protocol
|
||||
Transfer::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_20_5, 0x0B )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
DisconnectReportDetails.class,
|
||||
DisconnectReportDetails::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_21, 0x0F )
|
||||
);
|
||||
TO_CLIENT.registerPacket(
|
||||
ServerLinks.class,
|
||||
ServerLinks::new,
|
||||
map( ProtocolConstants.MINECRAFT_1_21, 0x10 )
|
||||
);
|
||||
|
||||
TO_SERVER.registerPacket(
|
||||
ClientSettings.class,
|
||||
|
@ -46,6 +46,7 @@ public class ProtocolConstants
|
||||
public static final int MINECRAFT_1_20_2 = 764;
|
||||
public static final int MINECRAFT_1_20_3 = 765;
|
||||
public static final int MINECRAFT_1_20_5 = 766;
|
||||
public static final int MINECRAFT_1_21 = 767;
|
||||
public static final List<String> SUPPORTED_VERSIONS;
|
||||
public static final List<Integer> SUPPORTED_VERSION_IDS;
|
||||
|
||||
@ -64,7 +65,8 @@ public class ProtocolConstants
|
||||
"1.17.x",
|
||||
"1.18.x",
|
||||
"1.19.x",
|
||||
"1.20.x"
|
||||
"1.20.x",
|
||||
"1.21.x"
|
||||
);
|
||||
ImmutableList.Builder<Integer> supportedVersionIds = ImmutableList.<Integer>builder().add(
|
||||
ProtocolConstants.MINECRAFT_1_8,
|
||||
@ -105,13 +107,14 @@ public class ProtocolConstants
|
||||
ProtocolConstants.MINECRAFT_1_20,
|
||||
ProtocolConstants.MINECRAFT_1_20_2,
|
||||
ProtocolConstants.MINECRAFT_1_20_3,
|
||||
ProtocolConstants.MINECRAFT_1_20_5
|
||||
ProtocolConstants.MINECRAFT_1_20_5,
|
||||
ProtocolConstants.MINECRAFT_1_21
|
||||
);
|
||||
|
||||
if ( SNAPSHOT_SUPPORT )
|
||||
{
|
||||
// supportedVersions.add( "1.20.x" );
|
||||
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_20_5 );
|
||||
// supportedVersions.add( "1.21.x" );
|
||||
// supportedVersionIds.add( ProtocolConstants.MINECRAFT_1_21 );
|
||||
}
|
||||
|
||||
SUPPORTED_VERSIONS = supportedVersions.build();
|
||||
|
@ -0,0 +1,55 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class DisconnectReportDetails extends DefinedPacket
|
||||
{
|
||||
|
||||
private Map<String, String> details;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
int len = readVarInt( buf );
|
||||
Preconditions.checkArgument( len <= 32, "Too many details" );
|
||||
|
||||
details = new HashMap<>();
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
details.put( readString( buf, 128 ), readString( buf, 4096 ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
Preconditions.checkArgument( details.size() <= 32, "Too many details" );
|
||||
writeVarInt( details.size(), buf );
|
||||
|
||||
for ( Map.Entry<String, String> detail : details.entrySet() )
|
||||
{
|
||||
writeString( detail.getKey(), buf, 128 );
|
||||
writeString( detail.getValue(), buf, 4096 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package net.md_5.bungee.protocol.packet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.protocol.AbstractPacketHandler;
|
||||
import net.md_5.bungee.protocol.DefinedPacket;
|
||||
import net.md_5.bungee.protocol.Either;
|
||||
import net.md_5.bungee.protocol.ProtocolConstants;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ServerLinks extends DefinedPacket
|
||||
{
|
||||
|
||||
private Link[] links;
|
||||
|
||||
@Override
|
||||
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
int len = readVarInt( buf );
|
||||
links = new Link[ len ];
|
||||
for ( int i = 0; i < len; i++ )
|
||||
{
|
||||
Either<LinkType, BaseComponent> type;
|
||||
if ( buf.readBoolean() )
|
||||
{
|
||||
type = Either.left( LinkType.values()[readVarInt( buf )] );
|
||||
} else
|
||||
{
|
||||
type = Either.right( readBaseComponent( buf, protocolVersion ) );
|
||||
}
|
||||
String url = readString( buf );
|
||||
|
||||
links[i] = new Link( type, url );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
||||
{
|
||||
writeVarInt( links.length, buf );
|
||||
for ( Link link : links )
|
||||
{
|
||||
Either<LinkType, BaseComponent> type = link.getType();
|
||||
if ( type.isLeft() )
|
||||
{
|
||||
buf.writeBoolean( true );
|
||||
writeVarInt( type.getLeft().ordinal(), buf );
|
||||
} else
|
||||
{
|
||||
buf.writeBoolean( false );
|
||||
writeBaseComponent( type.getRight(), buf, protocolVersion );
|
||||
}
|
||||
writeString( link.getUrl(), buf );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(AbstractPacketHandler handler) throws Exception
|
||||
{
|
||||
handler.handle( this );
|
||||
}
|
||||
|
||||
public enum LinkType
|
||||
{
|
||||
|
||||
REPORT_BUG,
|
||||
COMMUNITY_GUIDELINES,
|
||||
SUPPORT,
|
||||
STATUS,
|
||||
FEEDBACK,
|
||||
COMMUNITY,
|
||||
WEBSITE,
|
||||
FORUMS,
|
||||
NEWS,
|
||||
ANNOUNCEMENTS;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Link
|
||||
{
|
||||
|
||||
private final Either<LinkType, BaseComponent> type;
|
||||
private final String url;
|
||||
}
|
||||
}
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-proxy</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Proxy</name>
|
||||
@ -108,7 +108,7 @@
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>8.3.0</version>
|
||||
<version>8.4.0</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- add these back in as they are not exposed by the API -->
|
||||
|
@ -103,7 +103,7 @@ public class DownstreamBridge extends PacketHandler
|
||||
{
|
||||
server.setObsolete( true );
|
||||
con.connectNow( def, ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT );
|
||||
con.sendMessage( bungee.getTranslation( "server_went_down" ) );
|
||||
con.sendMessage( bungee.getTranslation( "server_went_down", def.getName() ) );
|
||||
} else
|
||||
{
|
||||
con.disconnect( Util.exception( t ) );
|
||||
@ -120,13 +120,25 @@ public class DownstreamBridge extends PacketHandler
|
||||
bungee.getReconnectHandler().setServer( con );
|
||||
}
|
||||
|
||||
if ( !server.isObsolete() )
|
||||
ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent( con, server.getInfo() );
|
||||
bungee.getPluginManager().callEvent( serverDisconnectEvent );
|
||||
|
||||
if ( server.isObsolete() )
|
||||
{
|
||||
// do not perform any actions if the user has already moved
|
||||
return;
|
||||
}
|
||||
|
||||
ServerInfo def = con.updateAndGetNextServer( server.getInfo() );
|
||||
if ( def != null )
|
||||
{
|
||||
server.setObsolete( true );
|
||||
con.connectNow( def, ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT );
|
||||
con.sendMessage( bungee.getTranslation( "server_went_down", def.getName() ) );
|
||||
} else
|
||||
{
|
||||
con.disconnect( bungee.getTranslation( "lost_connection" ) );
|
||||
}
|
||||
|
||||
ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent( con, server.getInfo() );
|
||||
bungee.getPluginManager().callEvent( serverDisconnectEvent );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,6 +87,7 @@ public abstract class EntityMap
|
||||
case ProtocolConstants.MINECRAFT_1_20_3:
|
||||
return EntityMap_1_16_2.INSTANCE_1_20_3;
|
||||
case ProtocolConstants.MINECRAFT_1_20_5:
|
||||
case ProtocolConstants.MINECRAFT_1_21:
|
||||
return EntityMap_1_16_2.INSTANCE_1_20_5;
|
||||
}
|
||||
throw new RuntimeException( "Version " + version + " has no entity map" );
|
||||
|
@ -30,6 +30,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
|
||||
private ChannelWrapper channel;
|
||||
private PacketHandler handler;
|
||||
private boolean healthCheck;
|
||||
|
||||
public void setHandler(PacketHandler handler)
|
||||
{
|
||||
@ -96,7 +97,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
channel.setRemoteAddress( newAddress );
|
||||
} else
|
||||
{
|
||||
channel.close();
|
||||
healthCheck = true;
|
||||
}
|
||||
} finally
|
||||
{
|
||||
@ -146,7 +147,7 @@ public class HandlerBoss extends ChannelInboundHandlerAdapter
|
||||
{
|
||||
if ( ctx.channel().isActive() )
|
||||
{
|
||||
boolean logExceptions = !( handler instanceof PingHandler );
|
||||
boolean logExceptions = !( handler instanceof PingHandler ) && !healthCheck;
|
||||
|
||||
if ( logExceptions )
|
||||
{
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-query</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-Query</name>
|
||||
|
@ -6,13 +6,13 @@
|
||||
<parent>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-parent</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>bungeecord-slf4j</artifactId>
|
||||
<version>1.20-R0.3-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>BungeeCord-SLF4J</name>
|
||||
|
Loading…
Reference in New Issue
Block a user