[chuni] Use dynamic reboot time instead of fixed one

pull/1/head
Dom Eori 2021-10-19 21:12:31 +09:00
parent 5d32d269d1
commit 46fc8921c0
1 changed files with 12 additions and 12 deletions

View File

@ -4,14 +4,14 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import icu.samnyan.aqua.sega.chunithm.handler.BaseHandler;
import icu.samnyan.aqua.sega.chunithm.model.response.GetGameSettingResp;
import icu.samnyan.aqua.sega.chunithm.model.response.data.GameSetting;
import icu.samnyan.aqua.sega.general.dao.PropertyEntryRepository;
import icu.samnyan.aqua.sega.general.model.PropertyEntry;
import icu.samnyan.aqua.sega.util.jackson.StringMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;
/**
@ -24,29 +24,29 @@ public class GetGameSettingHandler implements BaseHandler {
private final StringMapper mapper;
private final PropertyEntryRepository propertyEntryRepository;
@Autowired
public GetGameSettingHandler(StringMapper mapper, PropertyEntryRepository propertyEntryRepository) {
public GetGameSettingHandler(StringMapper mapper) {
this.mapper = mapper;
this.propertyEntryRepository = propertyEntryRepository;
}
@Override
public String handle(Map<String, Object> request) throws JsonProcessingException {
PropertyEntry start = propertyEntryRepository.findByPropertyKey("reboot_start_time")
.orElseGet(() -> new PropertyEntry("reboot_start_time", "2020-01-01 23:59:00.0"));
PropertyEntry end = propertyEntryRepository.findByPropertyKey("reboot_end_time")
.orElseGet(() -> new PropertyEntry("reboot_end_time", "2020-01-01 23:59:00.0"));
// Fixed reboot time triggers chunithm maintenance lockout, so let's try minime method which sets it dynamically
// Special thanks to skogaby
// Hardcode so that the reboot time always started 3 hours ago and ended 2 hours ago
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
LocalDateTime rebootStartTime = LocalDateTime.now().minusHours(3);
LocalDateTime rebootEndTime = LocalDateTime.now().minusHours(2);
GameSetting gameSetting = new GameSetting(
1,
false,
10,
start.getPropertyValue(),
end.getPropertyValue(),
rebootStartTime.format(formatter),
rebootEndTime.format(formatter),
false,
300,
300,