2 Commits

Author SHA1 Message Date
1ed0f88702 Fix SteamwarConnectionListener
Some checks failed
SteamWarCI Build failed
2025-06-11 11:42:42 +02:00
affad49bf5 Fix for Bungee 1.21.R0.3
Some checks failed
SteamWarCI Build failed
2025-05-30 16:01:24 +02:00
4 changed files with 37 additions and 35 deletions

View File

@ -5,8 +5,8 @@ plugins {
group = 'de.steamwar' group = 'de.steamwar'
version = '' version = ''
sourceCompatibility = 11 sourceCompatibility = 8
targetCompatibility = 11 targetCompatibility = 8
sourceSets { sourceSets {
main { main {
@ -36,7 +36,8 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.22' annotationProcessor 'org.projectlombok:lombok:1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22' testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT' compileOnly 'net.md-5:bungeecord-api:1.21-R0.1-SNAPSHOT'
compileOnly 'net.md-5:bungeecord-proxy:1.20-R0.3-SNAPSHOT' compileOnly 'net.md-5:bungeecord-proxy:1.21-R0.1-SNAPSHOT'
implementation 'codecrafter47.bungeetablistplus:bungeetablistplus-api-bungee:3.5.2' // compileOnly 'codecrafter47.bungeetablistplus:bungeetablistplus-api-bungee:3.5.2'
implementation 'it.unimi.dsi:fastutil-core:8.5.15'
} }

View File

@ -1,6 +1,3 @@
name: SteamWarTeamserverIntegration name: SteamWarTeamserverIntegration
version: 1.0.0 version: '1.0.0'
main: de.steamwar.SteamWarBungeeTeamserver main: de.steamwar.SteamWarBungeeTeamserver
softDepends:
- BungeeTabListPlus

View File

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