diff --git a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java index 2f1c1bb..3119452 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/Fabric.java +++ b/src/de/steamwar/bungeecore/listeners/mods/Fabric.java @@ -19,10 +19,9 @@ package de.steamwar.bungeecore.listeners.mods; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; +import com.google.gson.*; import de.steamwar.bungeecore.BungeeCore; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Storage; import de.steamwar.bungeecore.listeners.BasicListener; import de.steamwar.bungeecore.sql.Mod; @@ -34,6 +33,7 @@ import net.md_5.bungee.api.event.PluginMessageEvent; import net.md_5.bungee.event.EventHandler; import java.nio.charset.StandardCharsets; +import java.nio.charset.UnsupportedCharsetException; import java.sql.Timestamp; import java.time.Instant; import java.util.*; @@ -41,8 +41,7 @@ import java.util.logging.Level; public class Fabric extends BasicListener { - private final List neededMods = new LinkedList<>(); - public static final Set checkedPlayers = new HashSet(); + private final Set neededMods = new HashSet<>(); { neededMods.add("java"); @@ -61,6 +60,7 @@ public class Fabric extends BasicListener { } ProxiedPlayer player = (ProxiedPlayer) e.getSender(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); List mods = new LinkedList<>(); @@ -69,41 +69,46 @@ public class Fabric extends BasicListener { data = Arrays.copyOfRange(data,varInt.length, data.length); - String dataString = new String(data, StandardCharsets.UTF_8); + if(data.length != varInt.length + varInt.value) { + banPlayer(user,player); + } + + String dataString = ""; + + try{ + dataString = new String(data, StandardCharsets.UTF_8); + }catch (UnsupportedCharsetException exception) { + banPlayer(user, player); + } + + JsonArray array = new JsonArray(); try { - JsonArray array = new JsonParser().parse(dataString).getAsJsonArray(); - - for(int i = 0; i < array.size(); i++) { - mods.add(Mod.get(array.get(i).getAsString(), Mod.Platform.FABRIC)); - } - - boolean isSorted = isSortedAlphabetically(mods); - - 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."); - 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; - } - - if(Utils.handleMods(player,mods)) checkedPlayers.add(player); - }catch (Exception ex) { - ex.printStackTrace(); - player.disconnect("§7Mod Verification failed! Contact a Developer"); + array = new JsonParser().parse(dataString).getAsJsonArray(); + }catch (JsonSyntaxException exception) { + banPlayer(user, player); } - } - @EventHandler - public void onDisconnect(PlayerDisconnectEvent e){ - checkedPlayers.remove(e.getPlayer()); + for(JsonElement mod : array) { + mods.add(Mod.get(mod.getAsString(), Mod.Platform.FABRIC)); + } + + boolean isSorted = isSortedAlphabetically(mods); + + if(!isSorted) { + banPlayer(user, player); + return; + } + + if(!modsAreAbsent(mods)) { + banPlayer(user, player); + return; + } + + if(Utils.handleMods(player,mods)) { + Storage.fabricPlayers.remove(player); + Message.send("MODIFICATION_CHECK_SUCCESS", player); + } } private boolean isSortedAlphabetically(List mods) { @@ -124,4 +129,13 @@ public class Fabric extends BasicListener { .distinct() .count() == neededMods.size(); } + + public void banPlayer(SteamwarUser user, ProxiedPlayer player) { + user.punish(Punishment.PunishmentType.Ban, + Timestamp.from(Instant.now()), + Message.parse("MODIFICATION_BAN_MESSAGE", player), + 0, + true); + BungeeCore.log(Level.SEVERE, user.getUserName() + " " + user.getId() + Message.parse("MODIFICATION_BAN_LOG", player)); + } } diff --git a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java index d347d42..a4d54e6 100644 --- a/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java +++ b/src/de/steamwar/bungeecore/listeners/mods/ModLoaderBlocker.java @@ -73,7 +73,7 @@ public class ModLoaderBlocker extends BasicListener { } public static boolean isFabric(ProxiedPlayer player) { - return Storage.fabricPlayers.contains(player) && !Fabric.checkedPlayers.contains(player); + return Storage.fabricPlayers.contains(player); } public static void addServer(String server) { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 19226ef..00c88de 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -583,3 +583,8 @@ RANK_UNPLACED=§eunplatziert RANK_PLACED=§e{0}§8. §7mit §e{1} §7Elo§8. RANK_EMBLEM=§eEmblem§8: {0} RANK_NEEDED_FIGHTS_LEFT={0} §8(§7noch §e{1}§7 Kämpfe nötig§8) + +#Fabric Mod Sender +MODIFICATION_BAN_MESSAGE = "Du hast probiert den FabricModSender zu umgehen / zu modifizieren!" +MODIFICATION_BAN_LOG = " hat probiert den Fabric Mod Sender zu editieren / umzugehen!" +MODIFICATION_CHECK_SUCCESS = "§eDeine Mods wurden geprüft und du darfst nun auf Arenen joinen!"