|
|
|
|
@ -20,8 +20,9 @@
|
|
|
|
|
package de.steamwar.listener;
|
|
|
|
|
|
|
|
|
|
import de.steamwar.ConfigSystem;
|
|
|
|
|
import de.steamwar.utils.BungeeTabListPlusFixer;
|
|
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
|
|
|
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
|
|
|
|
import net.md_5.bungee.BungeeCord;
|
|
|
|
|
import net.md_5.bungee.api.chat.TextComponent;
|
|
|
|
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
|
|
|
|
@ -31,15 +32,14 @@ import net.md_5.bungee.connection.InitialHandler;
|
|
|
|
|
import net.md_5.bungee.connection.LoginResult;
|
|
|
|
|
import net.md_5.bungee.event.EventHandler;
|
|
|
|
|
import net.md_5.bungee.netty.ChannelWrapper;
|
|
|
|
|
import net.md_5.bungee.protocol.DefinedPacket;
|
|
|
|
|
import net.md_5.bungee.protocol.Protocol;
|
|
|
|
|
import net.md_5.bungee.protocol.ProtocolConstants;
|
|
|
|
|
import net.md_5.bungee.protocol.packet.Handshake;
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Array;
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.net.InetSocketAddress;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
@ -61,31 +61,33 @@ public class SteamwarConnectionListener implements Listener {
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
Protocol.DirectionData directionData = Protocol.HANDSHAKE.TO_SERVER;
|
|
|
|
|
Field directionDataProtocols = Protocol.DirectionData.class.getDeclaredField("protocols");
|
|
|
|
|
directionDataProtocols.setAccessible(true);
|
|
|
|
|
Int2ObjectMap protocols = (Int2ObjectMap) directionDataProtocols.get(directionData);
|
|
|
|
|
|
|
|
|
|
Class<?> protocolDataClass = Class.forName("net.md_5.bungee.protocol.Protocol$ProtocolData");
|
|
|
|
|
Field protocolDataPacketMap = protocolDataClass.getDeclaredField("packetMap");
|
|
|
|
|
protocolDataPacketMap.setAccessible(true);
|
|
|
|
|
Field protocolDataPacketConstructors = protocolDataClass.getDeclaredField("packetConstructors");
|
|
|
|
|
protocolDataPacketConstructors.setAccessible(true);
|
|
|
|
|
|
|
|
|
|
Method mapMethod = Protocol.class.getDeclaredMethod("map", int.class, int.class);
|
|
|
|
|
mapMethod.setAccessible(true);
|
|
|
|
|
Object protocolMapping = mapMethod.invoke(null, ProtocolConstants.MINECRAFT_1_8, 0x00);
|
|
|
|
|
Class<?> directionDataClazz = Class.forName("net.md_5.bungee.protocol.Protocol$DirectionData");
|
|
|
|
|
Class<?> protocolMappingClazz = Class.forName("net.md_5.bungee.protocol.Protocol$ProtocolMapping");
|
|
|
|
|
Field field = Protocol.class.getDeclaredField("TO_SERVER");
|
|
|
|
|
field.setAccessible(true);
|
|
|
|
|
Object o = field.get(Protocol.HANDSHAKE);
|
|
|
|
|
Method method = Arrays.stream(directionDataClazz.getDeclaredMethods())
|
|
|
|
|
.filter(m -> m.getName().equals("registerPacket"))
|
|
|
|
|
.filter(m -> m.getParameterCount() == 3)
|
|
|
|
|
.filter(m -> m.getParameterTypes()[0] == Class.class)
|
|
|
|
|
.filter(m -> m.getParameterTypes()[1] == Supplier.class)
|
|
|
|
|
.filter(m -> m.getParameterTypes()[2].isArray())
|
|
|
|
|
.findFirst()
|
|
|
|
|
.orElseThrow(() -> new RuntimeException("Could not find registerPacket method"));
|
|
|
|
|
method.setAccessible(true);
|
|
|
|
|
Object protocolMappingArray = Array.newInstance(protocolMappingClazz, 1);
|
|
|
|
|
Array.set(protocolMappingArray, 0, protocolMapping);
|
|
|
|
|
method.invoke(o, Handshake.class, new Supplier<Handshake>() {
|
|
|
|
|
@Override
|
|
|
|
|
public Handshake get() {
|
|
|
|
|
return new SteamwarHandshake();
|
|
|
|
|
}
|
|
|
|
|
}, protocolMappingArray);
|
|
|
|
|
Field protocolMappingPacketId = protocolMapping.getClass().getDeclaredField("packetID");
|
|
|
|
|
protocolMappingPacketId.setAccessible(true);
|
|
|
|
|
int packetID = protocolMappingPacketId.getInt(protocolMapping);
|
|
|
|
|
|
|
|
|
|
for (int version : ProtocolConstants.SUPPORTED_VERSION_IDS) {
|
|
|
|
|
Object protocolData = protocols.get(version);
|
|
|
|
|
|
|
|
|
|
Object2IntMap<Class<? extends DefinedPacket>> packetMap = (Object2IntMap<Class<? extends DefinedPacket>>) protocolDataPacketMap.get(protocolData);
|
|
|
|
|
Supplier<? extends DefinedPacket>[] packetConstructors = (Supplier<? extends DefinedPacket>[]) protocolDataPacketConstructors.get(protocolData);
|
|
|
|
|
|
|
|
|
|
packetMap.put(Handshake.class, packetID);
|
|
|
|
|
packetConstructors[packetID] = SteamwarHandshake::new;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chField = InitialHandler.class.getDeclaredField("ch");
|
|
|
|
|
chField.setAccessible(true);
|
|
|
|
|
@ -102,7 +104,7 @@ public class SteamwarConnectionListener implements Listener {
|
|
|
|
|
if (!ConfigSystem.isEnabled()) return;
|
|
|
|
|
|
|
|
|
|
String address = preLoginEvent.getConnection().getSocketAddress().toString();
|
|
|
|
|
if (address.startsWith("/78.31.71.136:")) {
|
|
|
|
|
if (address.startsWith("/178.63.72.88:")) {
|
|
|
|
|
InitialHandler initialHandler = (InitialHandler) preLoginEvent.getConnection();
|
|
|
|
|
String extraData = initialHandler.getExtraDataInHandshake();
|
|
|
|
|
String[] split = extraData.split("\0");
|
|
|
|
|
@ -158,8 +160,10 @@ public class SteamwarConnectionListener implements Listener {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (BungeeCord.getInstance().getPluginManager().getPlugin("BungeeTabListPlus") != null) {
|
|
|
|
|
BungeeTabListPlusFixer.remove(postLoginEvent.getPlayer());
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|