From 9218544349c7b62857c07b20cef7a8912ceda68d Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Fri, 7 Jan 2022 11:50:26 +0100 Subject: [PATCH] Primitive Version --- .../listeners/mods/CustomPacketHandler.java | 44 +++++++++++++++++ .../bungeecore/listeners/mods/FMLPing.java | 48 +++++++++++++++++++ .../bungeecore/listeners/mods/Forge.java | 38 +++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 src/de/steamwar/bungeecore/listeners/mods/CustomPacketHandler.java create mode 100644 src/de/steamwar/bungeecore/listeners/mods/FMLPing.java diff --git a/src/de/steamwar/bungeecore/listeners/mods/CustomPacketHandler.java b/src/de/steamwar/bungeecore/listeners/mods/CustomPacketHandler.java new file mode 100644 index 00000000..c210912f --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/CustomPacketHandler.java @@ -0,0 +1,44 @@ +package de.steamwar.bungeecore.listeners.mods; + +import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.sql.Mod; +import net.md_5.bungee.BungeeCord; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.LoginEvent; +import net.md_5.bungee.api.event.PreLoginEvent; +import net.md_5.bungee.api.plugin.Event; +import net.md_5.bungee.netty.ChannelWrapper; +import net.md_5.bungee.netty.PacketHandler; +import net.md_5.bungee.protocol.packet.LoginPayloadResponse; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +public class CustomPacketHandler extends PacketHandler { + + private LoginEvent event; + private ChannelWrapper wrapper; + + public CustomPacketHandler(LoginEvent event, ChannelWrapper wrapper) { + this.event = event; + this.wrapper = wrapper; + } + + @Override public String toString() { + return null; + } + + public void handle(LoginPayloadResponse response){ + if(response.getData() == null) { + System.out.println("Data is null with id: " + response.getId() + " , which means Client has no installed mods!"); + event.completeIntent(BungeeCore.get()); + return; + } + + + event.completeIntent(BungeeCore.get()); + } +} diff --git a/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java b/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java new file mode 100644 index 00000000..73dba3d8 --- /dev/null +++ b/src/de/steamwar/bungeecore/listeners/mods/FMLPing.java @@ -0,0 +1,48 @@ +package de.steamwar.bungeecore.listeners.mods; + +import net.md_5.bungee.api.ServerPing; + +import java.util.ArrayList; +import java.util.List; + +public class FMLPing extends ServerPing { + private final ForgeData forgeData = new ForgeData(); + + public FMLPing(ServerPing existing) { + super(existing.getVersion(), existing.getPlayers(), existing.getDescriptionComponent(), existing.getFaviconObject()); + } + + private static class ForgeData { + private final List channels = new ArrayList<>(); + private final List mods = new ArrayList<>(); + private final int fmlNetworkVersion = 2; + + public ForgeData() { + channels.add(new ForgeChannel("minecraft:unregister")); + channels.add(new ForgeChannel("minecraft:register")); + channels.add(new ForgeChannel("fml:handshake")); + mods.add(new ForgeMod("minecraft", "1.15.2")); + mods.add(new ForgeMod("forge", "ANY")); + } + + private static class ForgeChannel { + private final String res; + private final String version = "FML2"; + private final boolean required = true; + + private ForgeChannel(String res) { + this.res = res; + } + } + + private static class ForgeMod { + private final String modId; + private final String modmarker; + + private ForgeMod(String modId, String modmarker) { + this.modId = modId; + this.modmarker = modmarker; + } + } + } +} diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index 905eecb8..881e4d7c 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -27,10 +27,17 @@ import io.netty.buffer.UnpooledByteBufAllocator; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.connection.Connection; import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.LoginEvent; import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.api.event.PostLoginEvent; +import net.md_5.bungee.api.event.ProxyPingEvent; +import net.md_5.bungee.connection.InitialHandler; import net.md_5.bungee.event.EventHandler; +import net.md_5.bungee.netty.ChannelWrapper; +import net.md_5.bungee.netty.HandlerBoss; +import net.md_5.bungee.protocol.packet.LoginPayloadRequest; +import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.TimeUnit; @@ -39,6 +46,7 @@ public class Forge extends BasicListener { private static final String FMLHS = "FML|HS"; private static final String FMLHS13 = "fml:handshake"; + private static final String WRAPPER = "fml:loginwrapper"; private static final byte[] REGISTER; private static final byte[] REGISTER13; private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0}; @@ -58,6 +66,36 @@ public class Forge extends BasicListener { buf.readBytes(REGISTER13); } + @EventHandler + public void onServerConnected(LoginEvent event){ + //Wir senden Packet ID 1 + //Wir wollen empfangen Packet ID 2 + //(FMLHS13, new byte[]{4, 1, 0, 0, 0}); + //13,102,109,108,58,104,97,110,100,115,104,97,107,101 = 13 + "fml:handshake" + event.getConnection().unsafe().sendPacket(new LoginPayloadRequest(1,WRAPPER, new byte[]{13,102,109,108,58,104,97,110,100,115,104,97,107,101,4,1,0,0,0})); + event.registerIntent(BungeeCore.get()); + + + InitialHandler handler = (InitialHandler) event.getConnection(); + + Field ch; + ChannelWrapper wrapper = null; + + try{ + ch = handler.getClass().getDeclaredField("ch"); + ch.setAccessible(true); + wrapper = (ChannelWrapper) ch.get(handler); + } catch (NoSuchFieldException | IllegalAccessException e) { + e.printStackTrace(); + } + wrapper.getHandle().pipeline().get(HandlerBoss.class).setHandler(new CustomPacketHandler(event, wrapper)); + } + + @EventHandler + public void onServerPing(ProxyPingEvent event) { + event.setResponse(new FMLPing(event.getResponse())); + } + @EventHandler public void onPostLogin(PostLoginEvent event) { ProxiedPlayer player = event.getPlayer();