You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-20 07:26:18 +00:00
🆙 Redone the userwalk flood detection
This commit is contained in:
+45
-3
@@ -26,9 +26,16 @@ public class RoomUserWalkEvent extends MessageHandler {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RoomUserWalkEvent.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RoomUserWalkEvent.class);
|
||||||
public static final String CONTROL_KEY = "control";
|
public static final String CONTROL_KEY = "control";
|
||||||
|
|
||||||
|
private static final String WALK_FLOOD_COUNT_KEY = "__walkFloodCount";
|
||||||
|
private static final String WALK_FLOOD_WINDOW_KEY = "__walkFloodWindow";
|
||||||
|
private static final String WALK_LAST_X_KEY = "__walkLastX";
|
||||||
|
private static final String WALK_LAST_Y_KEY = "__walkLastY";
|
||||||
|
|
||||||
|
private static final int MAX_WALKS_PER_SECOND = 15;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRatelimit() {
|
public int getRatelimit() {
|
||||||
return Emulator.getConfig().getInt("pathfinder.click.delay", 0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,8 +44,43 @@ public class RoomUserWalkEvent extends MessageHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x = this.packet.readInt(); // Position X
|
int x = this.packet.readInt();
|
||||||
int y = this.packet.readInt(); // Position Y
|
int y = this.packet.readInt();
|
||||||
|
|
||||||
|
RoomUnit unit = this.client.getHabbo().getRoomUnit();
|
||||||
|
if (unit != null) {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
Object windowObj = unit.getCacheable().get(WALK_FLOOD_WINDOW_KEY);
|
||||||
|
Object countObj = unit.getCacheable().get(WALK_FLOOD_COUNT_KEY);
|
||||||
|
|
||||||
|
long windowStart = (windowObj instanceof Long) ? (Long) windowObj : 0L;
|
||||||
|
int count = (countObj instanceof Integer) ? (Integer) countObj : 0;
|
||||||
|
|
||||||
|
if (now - windowStart > 1000) {
|
||||||
|
// New 1-second window
|
||||||
|
windowStart = now;
|
||||||
|
count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
count++;
|
||||||
|
unit.getCacheable().put(WALK_FLOOD_WINDOW_KEY, windowStart);
|
||||||
|
unit.getCacheable().put(WALK_FLOOD_COUNT_KEY, count);
|
||||||
|
|
||||||
|
if (count > MAX_WALKS_PER_SECOND) {
|
||||||
|
unit.getCacheable().put(WALK_LAST_X_KEY, x);
|
||||||
|
unit.getCacheable().put(WALK_LAST_Y_KEY, y);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object lastX = unit.getCacheable().get(WALK_LAST_X_KEY);
|
||||||
|
Object lastY = unit.getCacheable().get(WALK_LAST_Y_KEY);
|
||||||
|
if (lastX != null && lastY != null) {
|
||||||
|
x = (Integer) lastX;
|
||||||
|
y = (Integer) lastY;
|
||||||
|
unit.getCacheable().remove(WALK_LAST_X_KEY);
|
||||||
|
unit.getCacheable().remove(WALK_LAST_Y_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Habbo habbo = getControlledHabbo();
|
Habbo habbo = getControlledHabbo();
|
||||||
if (habbo == null) {
|
if (habbo == null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user