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
Merge pull request #254 from simoleo89/fix/wired-date-payloads
fix(wired): bound date payloads
This commit is contained in:
+1
@@ -79,6 +79,7 @@ public class WiredConditionDateRangeActive extends InteractionWiredCondition {
|
||||
|
||||
@Override
|
||||
public void loadWiredData(ResultSet set, Room room) throws SQLException {
|
||||
this.onPickUp();
|
||||
String wiredData = set.getString("wired_data");
|
||||
if (wiredData == null || wiredData.isEmpty()) {
|
||||
this.applyRange(0, 0);
|
||||
|
||||
+13
-6
@@ -125,7 +125,14 @@ public class WiredConditionMatchDate extends InteractionWiredCondition {
|
||||
}
|
||||
|
||||
if (wiredData.startsWith("{")) {
|
||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||
JsonData data;
|
||||
try {
|
||||
data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||
} catch (RuntimeException exception) {
|
||||
this.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +200,7 @@ public class WiredConditionMatchDate extends InteractionWiredCondition {
|
||||
}
|
||||
}
|
||||
|
||||
private int normalizeMode(int value) {
|
||||
int normalizeMode(int value) {
|
||||
if (value < MODE_SKIP || value > MODE_RANGE) {
|
||||
return MODE_SKIP;
|
||||
}
|
||||
@@ -201,20 +208,20 @@ public class WiredConditionMatchDate extends InteractionWiredCondition {
|
||||
return value;
|
||||
}
|
||||
|
||||
private int normalizeDay(int value) {
|
||||
int normalizeDay(int value) {
|
||||
return Math.max(1, Math.min(31, value));
|
||||
}
|
||||
|
||||
private int normalizeYear(int value) {
|
||||
int normalizeYear(int value) {
|
||||
return Math.max(1, Math.min(9999, value));
|
||||
}
|
||||
|
||||
private int normalizeWeekdayMask(int value) {
|
||||
int normalizeWeekdayMask(int value) {
|
||||
int normalized = value & ALL_WEEKDAYS_MASK;
|
||||
return (normalized == 0) ? ALL_WEEKDAYS_MASK : normalized;
|
||||
}
|
||||
|
||||
private int normalizeMonthMask(int value) {
|
||||
int normalizeMonthMask(int value) {
|
||||
int normalized = value & ALL_MONTHS_MASK;
|
||||
return (normalized == 0) ? ALL_MONTHS_MASK : normalized;
|
||||
}
|
||||
|
||||
+11
-4
@@ -126,7 +126,14 @@ public class WiredConditionMatchTime extends InteractionWiredCondition {
|
||||
}
|
||||
|
||||
if (wiredData.startsWith("{")) {
|
||||
JsonData data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||
JsonData data;
|
||||
try {
|
||||
data = WiredManager.getGson().fromJson(wiredData, JsonData.class);
|
||||
} catch (RuntimeException exception) {
|
||||
this.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
@@ -195,7 +202,7 @@ public class WiredConditionMatchTime extends InteractionWiredCondition {
|
||||
}
|
||||
}
|
||||
|
||||
private int normalizeMode(int value) {
|
||||
int normalizeMode(int value) {
|
||||
if (value < MODE_SKIP || value > MODE_RANGE) {
|
||||
return MODE_SKIP;
|
||||
}
|
||||
@@ -203,11 +210,11 @@ public class WiredConditionMatchTime extends InteractionWiredCondition {
|
||||
return value;
|
||||
}
|
||||
|
||||
private int normalizeHour(int value) {
|
||||
int normalizeHour(int value) {
|
||||
return Math.max(0, Math.min(23, value));
|
||||
}
|
||||
|
||||
private int normalizeMinuteOrSecond(int value) {
|
||||
int normalizeMinuteOrSecond(int value) {
|
||||
return Math.max(0, Math.min(59, value));
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ public final class HotelDateTimeUtil {
|
||||
}
|
||||
|
||||
public static ZoneId getZoneId() {
|
||||
String configuredZoneId = Emulator.getConfig().getValue(CONFIG_KEY, ZoneId.systemDefault().getId());
|
||||
String configuredZoneId = Emulator.getConfig() != null
|
||||
? Emulator.getConfig().getValue(CONFIG_KEY, ZoneId.systemDefault().getId())
|
||||
: ZoneId.systemDefault().getId();
|
||||
|
||||
try {
|
||||
lastInvalidTimezoneId = null;
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.eu.habbo.habbohotel.items.interactions.wired.conditions;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class WiredConditionDatePayloadGuardTest {
|
||||
@Test
|
||||
void matchDateBoundsMasksAndParts() {
|
||||
WiredConditionMatchDate condition = new WiredConditionMatchDate(1, 1, null, "", 0, 0);
|
||||
|
||||
assertEquals(0, condition.normalizeMode(99));
|
||||
assertEquals(2, condition.normalizeMode(2));
|
||||
assertEquals(1, condition.normalizeDay(-1));
|
||||
assertEquals(31, condition.normalizeDay(99));
|
||||
assertEquals(1, condition.normalizeYear(-1));
|
||||
assertEquals(9999, condition.normalizeYear(50_000));
|
||||
assertEquals(254, condition.normalizeWeekdayMask(0));
|
||||
assertEquals(8190, condition.normalizeMonthMask(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchTimeBoundsParts() {
|
||||
WiredConditionMatchTime condition = new WiredConditionMatchTime(1, 1, null, "", 0, 0);
|
||||
|
||||
assertEquals(0, condition.normalizeMode(99));
|
||||
assertEquals(2, condition.normalizeMode(2));
|
||||
assertEquals(0, condition.normalizeHour(-1));
|
||||
assertEquals(23, condition.normalizeHour(99));
|
||||
assertEquals(0, condition.normalizeMinuteOrSecond(-1));
|
||||
assertEquals(59, condition.normalizeMinuteOrSecond(99));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dateRangeBoundsAndSortsUnixTimestamps() {
|
||||
WiredConditionDateRangeActive condition = new WiredConditionDateRangeActive(1, 1, null, "", 0, 0);
|
||||
|
||||
assertEquals(0, condition.normalizeTimestamp(-1));
|
||||
assertEquals(123, condition.normalizeTimestamp(123));
|
||||
|
||||
condition.setRange(200, 100);
|
||||
|
||||
assertEquals("{\"startDate\":100,\"endDate\":200}", condition.getWiredData());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user