[F] Try to fix wacca uint overflow

This commit is contained in:
Azalea 2024-04-20 09:37:34 +09:00
parent 8e882aafa1
commit 4215b39539
2 changed files with 3 additions and 3 deletions

View File

@ -134,6 +134,7 @@ fun Any.long() = when (this) {
is String -> toLong()
else -> 400 - "Invalid number: $this"
}
fun Any.uint32() = long() and 0xFFFFFFFF
fun Any.int() = long().toInt()
operator fun Bool.unaryPlus() = if (this) 1 else 0

View File

@ -5,7 +5,6 @@ import icu.samnyan.aqua.net.db.AquaGameOptions
import icu.samnyan.aqua.net.games.wacca.Wacca
import icu.samnyan.aqua.net.utils.ApiException
import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.wacca.WaccaDifficulty.INFERNO
import icu.samnyan.aqua.sega.wacca.WaccaItemType.*
import icu.samnyan.aqua.sega.wacca.WaccaItemType.NOTE_COLOR
import icu.samnyan.aqua.sega.wacca.WaccaItemType.NOTE_SOUND
@ -47,7 +46,7 @@ class WaccaServer {
init { init() }
// DSL Functions
fun user(uid: Any) = if (uid == 0) null else rp.user.findByCardExtId(uid.long())
fun user(uid: Any) = if (uid == 0) null else rp.user.findByCardExtId(uid.uint32())
fun options(u: WaccaUser?) = u?.let { rp.option.findByUser(u).associate { it.optId to it.value } } ?: emptyMap()
fun itmGrp(u: WaccaUser) = rp.item.findByUser(u).groupBy { it.type }.mapValues { it.value.associateBy { it.itemId } }
operator fun Map<Int, Int>.get(type: WaccaOptionType) = getOrDefault(type.id, type.default)
@ -137,7 +136,7 @@ fun WaccaServer.init() {
if (user(uid) != null) 404 - "User already exists"
val u = rp.user.save(WaccaUser().apply {
card = cardRepo.findByExtId(uid.long())() ?: (404 - "Card not found")
card = cardRepo.findByExtId(uid.uint32())() ?: (404 - "Card not found")
userName = name.toString()
})