Archiviert
1
0

Fixing 1.13+ support for forge modblocker

Dieser Commit ist enthalten in:
Lixfel 2019-12-31 10:56:11 +01:00
Ursprung 8f553a663b
Commit 312f5b96b7

Datei anzeigen

@ -20,7 +20,9 @@ import java.util.concurrent.TimeUnit;
public class Forge extends BasicListener { public class Forge extends BasicListener {
private static final String FMLHS = "FML|HS"; private static final String FMLHS = "FML|HS";
private static final String FMLHS13 = "fml:handshake";
private static final byte[] REGISTER; 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 byte[] HELLO = new byte[]{0, 2, 0, 0, 0, 0};
private static final Set<UUID> unlocked = new HashSet<>(); private static final Set<UUID> unlocked = new HashSet<>();
@ -30,6 +32,12 @@ public class Forge extends BasicListener {
buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8); buf.writeCharSequence(FMLHS, StandardCharsets.UTF_8);
REGISTER = new byte[buf.readableBytes()]; REGISTER = new byte[buf.readableBytes()];
buf.readBytes(REGISTER); buf.readBytes(REGISTER);
buf.clear();
buf.writeByte(13);
buf.writeCharSequence(FMLHS13, StandardCharsets.UTF_8);
REGISTER13 = new byte[buf.readableBytes()];
buf.readBytes(REGISTER13);
} }
@EventHandler @EventHandler
@ -43,17 +51,18 @@ public class Forge extends BasicListener {
} }
} }
if(player.getPendingConnection().getVersion() > 340) if(player.getPendingConnection().getVersion() > 340) {
player.sendData("minecraft:register", REGISTER); //1.13+ player.sendData("minecraft:register", REGISTER13); //1.13+
else player.sendData(FMLHS13, Forge.HELLO);
}else{
player.sendData("REGISTER", REGISTER); //1.12- player.sendData("REGISTER", REGISTER); //1.12-
player.sendData(FMLHS, Forge.HELLO);
player.sendData(FMLHS, HELLO); }
} }
@EventHandler @EventHandler
public void onPluginMessageEvent(PluginMessageEvent e){ public void onPluginMessageEvent(PluginMessageEvent e){
if(!e.getTag().equals(FMLHS)) if(!e.getTag().equals(FMLHS) && !e.getTag().equals(FMLHS13))
return; return;
e.setCancelled(true); e.setCancelled(true);
@ -64,23 +73,22 @@ public class Forge extends BasicListener {
return; return;
ProxiedPlayer p = (ProxiedPlayer) sender; ProxiedPlayer p = (ProxiedPlayer) sender;
switch(data[0]){ if (data[0] == 2) {
case 2:
Pair<Integer, Integer> numMods = Utils.readVarInt(data, 1); Pair<Integer, Integer> numMods = Utils.readVarInt(data, 1);
List<Mod> mods = new LinkedList<>(); List<Mod> mods = new LinkedList<>();
int bytePos = 1 + numMods.getKey(); int bytePos = 1 + numMods.getKey();
for(int i = 0; i < numMods.getValue(); i++){ for (int i = 0; i < numMods.getValue(); i++) {
byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); byte[] name = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1);
bytePos += 1 + data[bytePos]; bytePos += 1 + data[bytePos];
byte[] version = Arrays.copyOfRange(data, bytePos + 1, bytePos + data[bytePos] + 1); //Version information is unused
bytePos += 1 + data[bytePos]; 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)){ if (Utils.handleMods(p, mods)) {
synchronized (unlocked){ synchronized (unlocked) {
unlocked.add(p.getUniqueId()); unlocked.add(p.getUniqueId());
} }
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(),
@ -92,9 +100,6 @@ public class Forge extends BasicListener {
} }
}, 30, TimeUnit.SECONDS); }, 30, TimeUnit.SECONDS);
} }
break;
default:
break;
} }
} }
} }