3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Merge pull request #1 from MylesIsCool/master

Update fork.
Dieser Commit ist enthalten in:
7kasper 2018-09-12 17:00:25 +02:00 committet von GitHub
Commit 048ae2fcd0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
8 geänderte Dateien mit 122 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -3,8 +3,18 @@ package us.myles.ViaVersion.bukkit.classgenerator;
import javassist.*; import javassist.*;
import javassist.expr.ConstructorCall; import javassist.expr.ConstructorCall;
import javassist.expr.ExprEditor; import javassist.expr.ExprEditor;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import us.myles.ViaVersion.ViaVersionPlugin;
import us.myles.ViaVersion.api.ViaVersion; import us.myles.ViaVersion.api.ViaVersion;
import us.myles.ViaVersion.bukkit.handlers.BukkitDecodeHandler; import us.myles.ViaVersion.bukkit.handlers.BukkitDecodeHandler;
import us.myles.ViaVersion.bukkit.handlers.BukkitEncodeHandler; import us.myles.ViaVersion.bukkit.handlers.BukkitEncodeHandler;
@ -13,6 +23,7 @@ import us.myles.ViaVersion.bukkit.util.NMSUtil;
public class ClassGenerator { public class ClassGenerator {
private static HandlerConstructor constructor = new BasicHandlerConstructor(); private static HandlerConstructor constructor = new BasicHandlerConstructor();
private static String psPackage = null; private static String psPackage = null;
private static Class psConnectListener;
public static HandlerConstructor getConstructor() { public static HandlerConstructor getConstructor() {
return constructor; return constructor;
@ -37,6 +48,7 @@ public class ClassGenerator {
Class encodeSuper; Class encodeSuper;
Class decodeSuper; Class decodeSuper;
if (isMultiplatformPS()) { if (isMultiplatformPS()) {
psConnectListener = makePSConnectListener(pool);
return; return;
} else { } else {
String psPackage = getOldPSPackage(); String psPackage = getOldPSPackage();
@ -166,6 +178,81 @@ public class ClassGenerator {
return null; return null;
} }
private static Class makePSConnectListener(ClassPool pool) {
try {
// Reference classes
CtClass toExtend = pool.get("protocolsupport.api.Connection$PacketListener");
CtClass connectListenerClazz = pool.makeClass("us.myles.ViaVersion.classgenerator.generated.ProtocolSupportConnectListener");
connectListenerClazz.setSuperclass(toExtend);
// Import packages
pool.importPackage("java.util.Arrays");
pool.importPackage("us.myles.ViaVersion.api.protocol.ProtocolRegistry");
pool.importPackage("protocolsupport.api.ProtocolVersion");
pool.importPackage("protocolsupport.api.ProtocolType");
pool.importPackage("protocolsupport.api.Connection");
pool.importPackage("protocolsupport.api.Connection.PacketListener");
pool.importPackage("protocolsupport.api.Connection.PacketListener.PacketEvent");
pool.importPackage("protocolsupport.protocol.ConnectionImpl");
pool.importPackage(NMSUtil.nms("PacketHandshakingInSetProtocol").getName());
// Add connection reference field
connectListenerClazz.addField(CtField.make("private ConnectionImpl connection;", connectListenerClazz));
// Bake constructor
connectListenerClazz.addConstructor(CtNewConstructor.make(
"public ProtocolSupportConnectListener (ConnectionImpl connection) {\n"
+ " this.connection = connection;\n"
+ "}", connectListenerClazz));
// Add the listening method
connectListenerClazz.addMethod(CtNewMethod.make(
// On packet receive
"public void onPacketReceiving(protocolsupport.api.Connection.PacketListener.PacketEvent event) {\n"
// Check if we are getting handshake packet.
+ " if (event.getPacket() instanceof PacketHandshakingInSetProtocol) {\n"
// Get protocol version.
+ " int protoVersion = ((PacketHandshakingInSetProtocol) event.getPacket()).getProtocolVersion();\n"
// ViaVersion has at this point already spoofed the connectionversion. (Since it is higher up the pipeline)
// If via has put the protoVersion to the server we can spoof ProtocolSupport's version.
+ " if (protoVersion == us.myles.ViaVersion.api.protocol.ProtocolRegistry.SERVER_PROTOCOL) {\n"
+ " connection.setVersion(ProtocolVersion.getLatest(ProtocolType.PC));\n"
+ " }\n"
+ " }\n"
// Id version is not serverversion viaversion will not spoof. ProtocolSupport will handle the rest.
// In any case, remove the packet listener and wrap up.
+ " connection.removePacketListener(this);\n"
+ "}", connectListenerClazz));
return connectListenerClazz.toClass(HandlerConstructor.class.getClassLoader());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void registerPSConnectListener(ViaVersionPlugin plugin) {
if (getPSConnectListener() != null) {
try {
Class<? extends Event> connectionOpenEvent = (Class<? extends Event>) Class.forName("protocolsupport.api.events.ConnectionOpenEvent");
Bukkit.getPluginManager().registerEvent(connectionOpenEvent, new Listener() { }, EventPriority.HIGH, new EventExecutor() {
@Override
public void execute(Listener listener, Event event) throws EventException {
try {
Object connection = event.getClass().getMethod("getConnection").invoke(event);
Object connectListener = getPSConnectListener().getConstructor(connection.getClass()).newInstance(connection);
Method addConnectListener = connection.getClass().getMethod("addPacketListener", Class.forName("protocolsupport.api.Connection$PacketListener"));
addConnectListener.invoke(connection, connectListener);
} catch (Exception e) {
e.printStackTrace();
}
}
}, plugin);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static Class getPSConnectListener() {
return psConnectListener;
}
public static String getOldPSPackage() { public static String getOldPSPackage() {
if (psPackage == null) { if (psPackage == null) {
try { try {

Datei anzeigen

@ -209,4 +209,9 @@ public class BukkitConfigAPI extends Config implements ViaVersionConfig {
public boolean isSuppress1_13ConversionErrors() { public boolean isSuppress1_13ConversionErrors() {
return getBoolean("suppress-1_13-conversion-errors", false); return getBoolean("suppress-1_13-conversion-errors", false);
} }
@Override
public boolean isDisable1_13AutoComplete() {
return getBoolean("disable-1_13-auto-complete", false);
}
} }

Datei anzeigen

@ -18,6 +18,7 @@ import us.myles.ViaVersion.bukkit.listeners.protocol1_9to1_8.*;
import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider; import us.myles.ViaVersion.bukkit.providers.BukkitInventoryQuickMoveProvider;
import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator; import us.myles.ViaVersion.bukkit.providers.BukkitViaBulkChunkTranslator;
import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter; import us.myles.ViaVersion.bukkit.providers.BukkitViaMovementTransmitter;
import us.myles.ViaVersion.bukkit.classgenerator.ClassGenerator;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider;
@ -57,6 +58,9 @@ public class BukkitViaLoader implements ViaPlatformLoader {
/* Base Protocol */ /* Base Protocol */
final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion"); final ViaVersionPlugin plugin = (ViaVersionPlugin) Bukkit.getPluginManager().getPlugin("ViaVersion");
// Add ProtocolSupport ConnectListener if necessary.
ClassGenerator.registerPSConnectListener(plugin);
registerListener(new Listener() { registerListener(new Listener() {
@EventHandler @EventHandler
public void onPlayerQuit(PlayerQuitEvent e) { public void onPlayerQuit(PlayerQuitEvent e) {
@ -128,4 +132,4 @@ public class BukkitViaLoader implements ViaPlatformLoader {
} }
tasks.clear(); tasks.clear();
} }
} }

Datei anzeigen

@ -262,4 +262,9 @@ public class BungeeConfigAPI extends Config implements ViaVersionConfig {
public boolean isSuppress1_13ConversionErrors() { public boolean isSuppress1_13ConversionErrors() {
return getBoolean("suppress-1_13-conversion-errors", false); return getBoolean("suppress-1_13-conversion-errors", false);
} }
@Override
public boolean isDisable1_13AutoComplete() {
return getBoolean("disable-1_13-auto-complete", false);
}
} }

Datei anzeigen

@ -216,14 +216,14 @@ public interface ViaVersionConfig {
* @return True if enabled * @return True if enabled
*/ */
boolean is1_13TeamColourFix(); boolean is1_13TeamColourFix();
/** /**
* Should we fix shift quick move action for 1.12 clients * Should we fix shift quick move action for 1.12 clients
* *
* @return True if enabled * @return True if enabled
*/ */
boolean is1_12QuickMoveActionFix(); boolean is1_12QuickMoveActionFix();
/** /**
* Get the blocked protocols * Get the blocked protocols
* *
@ -252,4 +252,11 @@ public interface ViaVersionConfig {
* @return True if enabled * @return True if enabled
*/ */
boolean isSuppress1_13ConversionErrors(); boolean isSuppress1_13ConversionErrors();
/**
* Should we disable the 1.13 auto-complete feature to stop spam kicks? (for any server lower than 1.13)
*
* @return True if enabled
*/
boolean isDisable1_13AutoComplete();
} }

Datei anzeigen

@ -536,6 +536,10 @@ public class Protocol1_13To1_12_2 extends Protocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
// Disable auto-complete if configured
if (Via.getConfig().isDisable1_13AutoComplete()) {
wrapper.cancel();
}
int tid = wrapper.read(Type.VAR_INT); int tid = wrapper.read(Type.VAR_INT);
// Save transaction id // Save transaction id
wrapper.user().get(TabCompleteTracker.class).setTransactionId(tid); wrapper.user().get(TabCompleteTracker.class).setTransactionId(tid);

Datei anzeigen

@ -90,6 +90,8 @@ quick-move-action-fix: false
team-colour-fix: true team-colour-fix: true
# We warn when there's a error converting from pre-1.13 to 1.13, should we suppress these? (Only suggested if spamming) # We warn when there's a error converting from pre-1.13 to 1.13, should we suppress these? (Only suggested if spamming)
suppress-1_13-conversion-errors: false suppress-1_13-conversion-errors: false
# 1.13 introduced new auto complete which can trigger "Kicked for spamming" for servers older than 1.13, the following option will disable it completely.
disable-1_13-auto-complete: false
# #
#----------------------------------------------------------# #----------------------------------------------------------#
# 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS # # 1.9 & 1.10 CLIENTS ON 1.8 SERVERS OPTIONS #

Datei anzeigen

@ -215,4 +215,9 @@ public class SpongeConfigAPI extends Config implements ViaVersionConfig {
public boolean isSuppress1_13ConversionErrors() { public boolean isSuppress1_13ConversionErrors() {
return getBoolean("suppress-1_13-conversion-errors", false); return getBoolean("suppress-1_13-conversion-errors", false);
} }
@Override
public boolean isDisable1_13AutoComplete() {
return getBoolean("disable-1_13-auto-complete", false);
}
} }