Merge pull request #243 from simoleo89/fix/wired-user-action-inputs

fix(wired): bound user action inputs
This commit is contained in:
DuckieTM
2026-06-18 12:35:35 +02:00
committed by GitHub
3 changed files with 44 additions and 2 deletions
@@ -87,7 +87,13 @@ public class WiredConditionUserPerformsAction extends InteractionWiredCondition
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) {
return;
@@ -253,7 +259,7 @@ public class WiredConditionUserPerformsAction extends InteractionWiredCondition
}
long timestamp = (Long) timestampValue;
if ((System.currentTimeMillis() - timestamp) > TRANSIENT_ACTION_WINDOW_MS) {
if (!WiredUserActionInputGuard.isRecentTimestamp(timestamp, System.currentTimeMillis(), TRANSIENT_ACTION_WINDOW_MS)) {
return false;
}
@@ -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;
}
}
@@ -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));
}
}