From c8ebe0cd876fc1b0a91444be99c150f32db059ab Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 27 Oct 2022 10:30:28 -0400 Subject: [PATCH] Packet rate limit --- core/src/mindustry/game/Team.java | 3 ++- core/src/mindustry/input/InputHandler.java | 5 +++++ core/src/mindustry/net/Administration.java | 2 +- core/src/mindustry/net/ArcNetProvider.java | 7 +++++++ core/src/mindustry/net/NetConnection.java | 2 ++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/mindustry/game/Team.java b/core/src/mindustry/game/Team.java index a855fea83c..5ca27e6efe 100644 --- a/core/src/mindustry/game/Team.java +++ b/core/src/mindustry/game/Team.java @@ -35,7 +35,8 @@ public class Team implements Comparable{ //TODO temporarily no palettes for these teams. green = new Team(4, "green", Color.valueOf("54d67d")),//Color.valueOf("96f58c"), Color.valueOf("54d67d"), Color.valueOf("28785c")), - blue = new Team(5, "blue", Color.valueOf("6c87fd")); //Color.valueOf("85caf9"), Color.valueOf("6c87fd"), Color.valueOf("3b3392") + blue = new Team(5, "blue", Color.valueOf("6c87fd")), //Color.valueOf("85caf9"), Color.valueOf("6c87fd"), Color.valueOf("3b3392") + neoplastic = new Team(6, "neoplastic", Color.valueOf("e05438")); //yes, it looks very similar to crux, you're not supposed to use this team for block regions anyway static{ Mathf.rand.setSeed(8); diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index e26751bf81..d2630c9593 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -556,6 +556,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ public static void unitClear(Player player){ if(player == null) return; + //make sure player is allowed to control the building + if(net.server() && !netServer.admins.allowAction(player, ActionType.respawn, action -> {})){ + throw new ValidateException(player, "Player cannot respawn."); + } + if(!player.dead() && !player.unit().spawnedByCore){ var docked = player.unit().dockedType; diff --git a/core/src/mindustry/net/Administration.java b/core/src/mindustry/net/Administration.java index 917be5a98b..820731fb20 100644 --- a/core/src/mindustry/net/Administration.java +++ b/core/src/mindustry/net/Administration.java @@ -676,7 +676,7 @@ public class Administration{ } public enum ActionType{ - breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem, control, buildSelect, command, removePlanned, commandUnits, commandBuilding + breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem, control, buildSelect, command, removePlanned, commandUnits, commandBuilding, respawn } } diff --git a/core/src/mindustry/net/ArcNetProvider.java b/core/src/mindustry/net/ArcNetProvider.java index 402c24b79c..7bab5c7154 100644 --- a/core/src/mindustry/net/ArcNetProvider.java +++ b/core/src/mindustry/net/ArcNetProvider.java @@ -137,6 +137,13 @@ public class ArcNetProvider implements NetProvider{ ArcConnection k = getByArcID(connection.getID()); if(!(object instanceof Packet pack) || k == null) return; + if(!k.packetRate.allow(3000, 270)){ + Log.warn("Blacklisting IP '@' as potential DOS attack - packet spam.", k.address); + connection.close(DcReason.closed); + netServer.admins.blacklistDos(k.address); + return; + } + Core.app.post(() -> { try{ net.handleServerReceived(k, pack); diff --git a/core/src/mindustry/net/NetConnection.java b/core/src/mindustry/net/NetConnection.java index 4d34e2702a..21f0eb64c0 100644 --- a/core/src/mindustry/net/NetConnection.java +++ b/core/src/mindustry/net/NetConnection.java @@ -30,6 +30,8 @@ public abstract class NetConnection{ public Seq rejectedRequests = new Seq<>(); /** Handles chat spam rate limits. */ public Ratekeeper chatRate = new Ratekeeper(); + /** Handles packet spam rate limits. */ + public Ratekeeper packetRate = new Ratekeeper(); public boolean hasConnected, hasBegunConnecting, hasDisconnected; public float viewWidth, viewHeight, viewX, viewY;