Implement targeted GWEN-based discrimination against certain ip addresses
This commit is contained in:
parent
888761d15e
commit
1148283dff
@ -1,6 +1,5 @@
|
||||
package mineplex.core.antihack;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -10,20 +9,12 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.minecraft.server.v1_8_R3.MinecraftServer;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
@ -37,7 +28,6 @@ import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mineplex.anticheat.MineplexAnticheat;
|
||||
import com.mineplex.anticheat.api.GameEndEvent;
|
||||
import com.mineplex.anticheat.api.GameStartEvent;
|
||||
import com.mineplex.anticheat.api.MineplexLink;
|
||||
@ -55,13 +45,13 @@ import com.mineplex.anticheat.checks.move.HeadRoll;
|
||||
import com.mineplex.anticheat.checks.move.Speed;
|
||||
import com.mineplex.anticheat.checks.player.BadPackets;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.ReflectivelyCreateMiniPlugin;
|
||||
import mineplex.core.account.CoreClient;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.antihack.actions.AntiHackAction;
|
||||
import mineplex.core.antihack.actions.BanwaveAction;
|
||||
import mineplex.core.antihack.actions.GEPBanAction;
|
||||
import mineplex.core.antihack.actions.ImmediateBanAction;
|
||||
import mineplex.core.antihack.actions.NoopAction;
|
||||
import mineplex.core.antihack.animations.BanwaveAnimationSpin;
|
||||
@ -72,25 +62,25 @@ import mineplex.core.antihack.commands.AnticheatOnCommand;
|
||||
import mineplex.core.antihack.commands.DetailedMessagesCommand;
|
||||
import mineplex.core.antihack.commands.GetVlsCommand;
|
||||
import mineplex.core.antihack.commands.TestBanCommand;
|
||||
import mineplex.core.antihack.gep.GwenExtremePrejudice;
|
||||
import mineplex.core.antihack.guardians.GuardianManager;
|
||||
import mineplex.core.antihack.logging.AntihackLogger;
|
||||
import mineplex.core.antihack.redisnotifications.GwenBanNotification;
|
||||
import mineplex.core.antihack.redisnotifications.GwenBanwaveNotification;
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
import mineplex.core.disguise.DisguiseManager;
|
||||
import mineplex.core.disguise.disguises.DisguiseBase;
|
||||
import mineplex.core.preferences.Preference;
|
||||
import mineplex.core.preferences.PreferencesManager;
|
||||
import mineplex.core.punish.Category;
|
||||
import mineplex.core.punish.Punish;
|
||||
import mineplex.core.punish.PunishmentResponse;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
|
||||
@ReflectivelyCreateMiniPlugin
|
||||
public class AntiHack extends MiniPlugin
|
||||
@ -140,6 +130,8 @@ public class AntiHack extends MiniPlugin
|
||||
private final Punish _punish = require(Punish.class);
|
||||
|
||||
private final Set<String> _detailedMessages = new HashSet<>();
|
||||
|
||||
private final GEPBanAction _gepAction = new GEPBanAction(10);
|
||||
|
||||
private Set<Player> _pendingBan = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
@ -174,6 +166,8 @@ public class AntiHack extends MiniPlugin
|
||||
player.spigot().sendMessage(minimal);
|
||||
}
|
||||
});
|
||||
|
||||
new GwenExtremePrejudice(UtilServer.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -201,7 +195,7 @@ public class AntiHack extends MiniPlugin
|
||||
runSync(() -> _banned.remove(uuid));
|
||||
}
|
||||
|
||||
public void doBan(Player player, Class<? extends Check> cause)
|
||||
public void doBan(Player player, Class<? extends Check> cause, boolean gep)
|
||||
{
|
||||
runSync(() ->
|
||||
{
|
||||
@ -213,6 +207,10 @@ public class AntiHack extends MiniPlugin
|
||||
String finalMessage = "[GWEN] " + id;
|
||||
JsonObject custom = new JsonObject();
|
||||
custom.addProperty("ban-reason", CheckManager.getCheckSimpleName(cause));
|
||||
if (gep)
|
||||
{
|
||||
custom.addProperty("extreme-prejudice", true);
|
||||
}
|
||||
|
||||
_logger.saveMetadata(player, id, () ->
|
||||
{
|
||||
@ -366,6 +364,11 @@ public class AntiHack extends MiniPlugin
|
||||
{
|
||||
if (_ignoredChecks.contains(event.getCheckClass()))
|
||||
return;
|
||||
|
||||
if (_gepAction.handleCustom(event))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ACTIONS.getOrDefault(event.getCheckClass(), NOOP_ACTION).handle(event);
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package mineplex.core.antihack.actions;
|
||||
|
||||
import com.mineplex.anticheat.api.PlayerViolationEvent;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.antihack.AntiHack;
|
||||
|
||||
public class GEPBanAction extends AntiHackAction
|
||||
{
|
||||
public GEPBanAction(int vl)
|
||||
{
|
||||
super(vl);
|
||||
}
|
||||
|
||||
public boolean handleCustom(PlayerViolationEvent event)
|
||||
{
|
||||
if (event.getViolations() >= this.getMinVl() && event.getPlayer().getMetadata("GWENEXTREMEPREJUDICE").get(0).asBoolean())
|
||||
{
|
||||
Managers.get(AntiHack.class).doBan(event.getPlayer(), event.getCheckClass(), true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PlayerViolationEvent event)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package mineplex.core.antihack.actions;
|
||||
|
||||
import com.mineplex.anticheat.api.PlayerViolationEvent;
|
||||
|
||||
import mineplex.core.Managers;
|
||||
import mineplex.core.antihack.AntiHack;
|
||||
import mineplex.core.common.util.UtilServer;
|
||||
|
||||
public class ImmediateBanAction extends AntiHackAction
|
||||
{
|
||||
@ -17,7 +17,7 @@ public class ImmediateBanAction extends AntiHackAction
|
||||
{
|
||||
if (event.getViolations() >= this.getMinVl())
|
||||
{
|
||||
Managers.get(AntiHack.class).doBan(event.getPlayer(), event.getCheckClass());
|
||||
Managers.get(AntiHack.class).doBan(event.getPlayer(), event.getCheckClass(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
package mineplex.core.antihack.gep;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.serverdata.database.DBPool;
|
||||
|
||||
public class GwenExtremePrejudice extends MiniPlugin
|
||||
{
|
||||
private final List<String> _addresses = new ArrayList<>();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public GwenExtremePrejudice(JavaPlugin plugin)
|
||||
{
|
||||
super("GEP", plugin);
|
||||
|
||||
int ticks = 20 * 5 * 60;
|
||||
int offset = 20 * (int)Math.floor(Math.random() * 10) * 60;
|
||||
ticks += offset;
|
||||
|
||||
Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, () ->
|
||||
{
|
||||
refreshIPList();
|
||||
}, 0, ticks);
|
||||
}
|
||||
|
||||
private void refreshIPList()
|
||||
{
|
||||
try (Connection c = DBPool.getAccount().getConnection())
|
||||
{
|
||||
List<String> addresses = new ArrayList<>();
|
||||
ResultSet rs = c.prepareStatement("SELECT ipAddress FROM gepAddresses;").executeQuery();
|
||||
while (rs.next())
|
||||
{
|
||||
addresses.add(rs.getString(1));
|
||||
}
|
||||
runSync(() ->
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
if (addresses.contains(player.getAddress().getAddress().getHostAddress()))
|
||||
{
|
||||
player.removeMetadata("GWENEXTREMEPREJUDICE", getPlugin());
|
||||
player.setMetadata("GWENEXTREMEPREJUDICE", new FixedMetadataValue(getPlugin(), true));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.removeMetadata("GWENEXTREMEPREJUDICE", getPlugin());
|
||||
player.setMetadata("GWENEXTREMEPREJUDICE", new FixedMetadataValue(getPlugin(), false));
|
||||
}
|
||||
}
|
||||
_addresses.clear();
|
||||
_addresses.addAll(addresses);
|
||||
});
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
if (!_addresses.isEmpty() && _addresses.contains(player.getAddress().getAddress().getHostAddress()))
|
||||
{
|
||||
player.removeMetadata("GWENEXTREMEPREJUDICE", getPlugin());
|
||||
player.setMetadata("GWENEXTREMEPREJUDICE", new FixedMetadataValue(getPlugin(), true));
|
||||
}
|
||||
else
|
||||
{
|
||||
player.setMetadata("GWENEXTREMEPREJUDICE", new FixedMetadataValue(getPlugin(), false));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user