From 312f5b96b73d125ca4f2db14671f50c269528fc5 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Dec 2019 10:56:11 +0100 Subject: [PATCH] Fixing 1.13+ support for forge modblocker --- .../bungeecore/listeners/mods/Forge.java | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Forge.java b/src/de/steamwar/bungeecore/listeners/mods/Forge.java index 0f366e6d..c4f54f82 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Forge.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Forge.java @@ -20,7 +20,9 @@ import java.util.concurrent.TimeUnit; public class Forge extends BasicListener { private static final String FMLHS = "FML|HS"; + private static final String FMLHS13 = "fml:handshake"; private static final byte[] REGISTER; + private static final byte[] REGISTER13; private static final byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0}; private static final Set unlocked = new HashSet<>(); @@ -30,6 +32,12 @@ public class Forge extends BasicListener { buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8); REGISTER = new byte[buf.readableBytes()]; buf.readBytes(REGISTER); + + buf.clear(); + buf.writeByte(13); + buf.writeCharSequence(FMLHS13, StandardCharsets.UTF_8); + REGISTER13 = new byte[buf.readableBytes()]; + buf.readBytes(REGISTER13); } @EventHandler @@ -43,17 +51,18 @@ public class Forge extends BasicListener { } } - if(player.getPendingConnection().getVersion() > 340) - player.sendData("minecraft:register", REGISTER); //1.13+ - else + if(player.getPendingConnection().getVersion() > 340) { + player.sendData("minecraft:register", REGISTER13); //1.13+ + player.sendData(FMLHS13, Forge.HELLO); + }else{ player.sendData("REGISTER", REGISTER); //1.12- - - player.sendData(FMLHS, HELLO); + player.sendData(FMLHS, Forge.HELLO); + } } @EventHandler public void onPluginMessageEvent(PluginMessageEvent e){ - if(!e.getTag().equals(FMLHS)) + if(!e.getTag().equals(FMLHS) && !e.getTag().equals(FMLHS13)) return; e.setCancelled(true); @@ -64,37 +73,33 @@ public class Forge extends BasicListener { return; ProxiedPlayer p = (ProxiedPlayer) sender; - switch(data[0]){ - case 2: - Pair numMods = Utils.readVarInt(data, 1); - List mods = new LinkedList<>(); + if (data[0] == 2) { + Pair numMods = Utils.readVarInt(data, 1); + List mods = new LinkedList<>(); - int bytePos = 1 + numMods.getKey(); - for(int i = 0; i < numMods.getValue(); i++){ - byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); - bytePos += 1 + data[bytePos]; - byte[] version = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); - bytePos += 1 + data[bytePos]; + int bytePos = 1 + numMods.getKey(); + for (int i = 0; i < numMods.getValue(); i++) { + byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); + bytePos += 1 + data[bytePos]; + //Version information is unused + bytePos += 1 + data[bytePos]; - mods.add(Mod.get(new String(name), Mod.Platform.FORGE)); + mods.add(Mod.get(new String(name), Mod.Platform.FORGE)); + } + + if (Utils.handleMods(p, mods)) { + synchronized (unlocked) { + unlocked.add(p.getUniqueId()); } - - if(Utils.handleMods(p, mods)){ - synchronized (unlocked){ - unlocked.add(p.getUniqueId()); + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), + () -> p.disconnect(BungeeCore.stringToText("§7Deine installierten Mods wurden überprüft\n§aDu kannst nun §eSteam§8War §abetreten")), + 2, TimeUnit.SECONDS); + ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { + synchronized (unlocked) { + unlocked.remove(p.getUniqueId()); } - ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), - () -> p.disconnect(BungeeCore.stringToText("§7Deine installierten Mods wurden überprüft\n§aDu kannst nun §eSteam§8War §abetreten")), - 2, TimeUnit.SECONDS); - ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> { - synchronized (unlocked) { - unlocked.remove(p.getUniqueId()); - } - }, 30, TimeUnit.SECONDS); - } - break; - default: - break; + }, 30, TimeUnit.SECONDS); + } } } }