You've already forked Arcturus-Morningstar-Extended
mirror of
https://github.com/duckietm/Arcturus-Morningstar-Extended.git
synced 2026-06-19 15:06:19 +00:00
fix(wired): bound user action inputs
This commit is contained in:
+8
-2
@@ -87,7 +87,13 @@ public class WiredConditionUserPerformsAction extends InteractionWiredCondition
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
JsonData data;
|
||||||
|
try {
|
||||||
|
data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||||
|
} catch (RuntimeException ignored) {
|
||||||
|
this.resetSettings();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
return;
|
return;
|
||||||
@@ -253,7 +259,7 @@ public class WiredConditionUserPerformsAction extends InteractionWiredCondition
|
|||||||
}
|
}
|
||||||
|
|
||||||
long timestamp = (Long) timestampValue;
|
long timestamp = (Long) timestampValue;
|
||||||
if ((System.currentTimeMillis() - timestamp) > TRANSIENT_ACTION_WINDOW_MS) {
|
if (!WiredUserActionInputGuard.isRecentTimestamp(timestamp, System.currentTimeMillis(), TRANSIENT_ACTION_WINDOW_MS)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
|
||||||
|
|
||||||
|
public final class WiredUserActionInputGuard {
|
||||||
|
private WiredUserActionInputGuard() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRecentTimestamp(long timestamp, long now, long windowMs) {
|
||||||
|
if (timestamp < 1 || timestamp > now || windowMs < 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (now - timestamp) <= windowMs;
|
||||||
|
}
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
class WiredUserActionInputGuardTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejectsInvalidOrFutureTimestamps() {
|
||||||
|
assertFalse(WiredUserActionInputGuard.isRecentTimestamp(0, 1000, 5000));
|
||||||
|
assertFalse(WiredUserActionInputGuard.isRecentTimestamp(1500, 1000, 5000));
|
||||||
|
assertFalse(WiredUserActionInputGuard.isRecentTimestamp(900, 1000, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void acceptsTimestampsInsideWindowOnly() {
|
||||||
|
assertTrue(WiredUserActionInputGuard.isRecentTimestamp(900, 1000, 5000));
|
||||||
|
assertFalse(WiredUserActionInputGuard.isRecentTimestamp(100, 1000, 500));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user