From 4a383521d775e091436b724a8f0878904f7a2759 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 29 Feb 2024 18:30:20 -0500 Subject: [PATCH] [+] Properly update last access time for card --- src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDB.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDB.kt b/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDB.kt index c7e9059c..eadae568 100644 --- a/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDB.kt +++ b/src/main/java/icu/samnyan/aqua/sega/aimedb/AimeDB.kt @@ -13,6 +13,7 @@ import org.slf4j.Logger import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import java.nio.charset.StandardCharsets +import java.time.LocalDateTime import kotlin.jvm.optionals.getOrNull /** @@ -99,6 +100,11 @@ class AimeDB( } } + fun getCard(accessCode: String) = cardService.getCardByAccessCode(accessCode).getOrNull()?.let { + // Update card access time + cardService.cardRepo.save(it.apply { accessTime = LocalDateTime.now() }).extId + } ?: -1 + /** * Felica Lookup v2: Look up the card in the card repository, return the External ID */ @@ -109,7 +115,7 @@ class AimeDB( // Get the decimal represent of the hex value, same from minime val accessCode = idm.toString().replace("-", "").padStart(20, '0') - val aimeId = cardService.getCardByAccessCode(accessCode).getOrNull()?.extId ?: -1 + val aimeId = getCard(accessCode) logger.info("> Response: $accessCode, $aimeId") return Unpooled.copiedBuffer(ByteArray(0x0140)).apply { @@ -130,7 +136,7 @@ class AimeDB( val luid = ByteBufUtil.hexDump(msg.slice(0x20, 0x2a - 0x20)) logger.info("> Lookup v1 (luid $luid)") - val aimeId = cardService.getCardByAccessCode(luid).getOrNull()?.extId ?: -1 + val aimeId = getCard(luid) logger.info("> Response: $aimeId") return Unpooled.copiedBuffer(ByteArray(0x0130)).apply { @@ -145,7 +151,7 @@ class AimeDB( val luid = ByteBufUtil.hexDump(msg.slice(0x20, 0x2a - 0x20)) logger.info("> Lookup v2 (luid $luid)") - val aimeId = cardService.getCardByAccessCode(luid).getOrNull()?.extId ?: -1 + val aimeId = getCard(luid) logger.info("> Response: $aimeId") return Unpooled.copiedBuffer(ByteArray(0x0130)).apply {