From 657c03dff17fce850d309f0e88c18ef6adcd09ad Mon Sep 17 00:00:00 2001 From: zOnlyKroks Date: Sat, 12 Mar 2022 13:35:59 +0100 Subject: [PATCH] Parsing funktioniert + notwendige mods check --- .../bungeecore/listeners/mods/Fabric.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 2ec76256..6a9c30ed 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -39,6 +39,15 @@ import java.util.logging.Level; public class Fabric extends BasicListener { + private final List neededMods = new LinkedList<>(); + + { + neededMods.add("java"); + neededMods.add("minecraft"); + neededMods.add("fabricloader"); + neededMods.add("steamwarmodsender"); + } + @EventHandler public void onPluginMessageEvent(PluginMessageEvent e){ if(!e.getTag().equals("fabricmodsender:mods")) @@ -52,9 +61,12 @@ public class Fabric extends BasicListener { List mods = new LinkedList<>(); - String dataString = new String(e.getData(), StandardCharsets.UTF_8).substring(1); + byte[] data = e.getData(); + Utils.VarInt varInt = Utils.readVarInt(data,0); - System.out.println(dataString); + data = Arrays.copyOfRange(data,varInt.length, data.length); + + String dataString = new String(data, StandardCharsets.UTF_8); try { JsonArray array = new JsonParser().parse(dataString).getAsJsonArray(); @@ -68,7 +80,14 @@ public class Fabric extends BasicListener { if(!isSorted) { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now()), "§7Du hast probiert den FabricModSender zu umgehen!", 0, true); - BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch gebannt, da er den FabricModSender editiert hatte"); + BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch gebannt, da er den FabricModSender editiert hatte."); + return; + } + + if(!modsAreAbsent(mods)) { + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + user.punish(Punishment.PunishmentType.Ban, Timestamp.from(Instant.now()), "§7Du hast probiert den FabricModSender zu umgehen!", 0, true); + BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + " wurde automatisch gebannt, da er den FabricModSender editiert hatte."); return; } @@ -89,4 +108,12 @@ public class Fabric extends BasicListener { } return isSorted; } + + private boolean modsAreAbsent(List mods) { + return mods.stream() + .map(Mod::getModName) + .filter(neededMods::contains) + .distinct() + .count() == neededMods.size(); + } }