diff --git a/config/application.properties b/config/application.properties index a6f80edb..6141b757 100644 --- a/config/application.properties +++ b/config/application.properties @@ -87,6 +87,9 @@ spring.datasource.url=jdbc:sqlite:data/db.sqlite ## AquaNet Settings ################################ +## Link card limit +aqua-net.link-card-limit=10 + ## CloudFlare Turnstile Captcha ## This enables captcha for user registration. aqua-net.turnstile.enable=false diff --git a/src/main/java/icu/samnyan/aqua/net/CardController.kt b/src/main/java/icu/samnyan/aqua/net/CardController.kt index 413f2de4..9124270f 100644 --- a/src/main/java/icu/samnyan/aqua/net/CardController.kt +++ b/src/main/java/icu/samnyan/aqua/net/CardController.kt @@ -2,6 +2,7 @@ package icu.samnyan.aqua.net import ext.* import icu.samnyan.aqua.net.components.JWT +import icu.samnyan.aqua.net.utils.AquaNetProps import icu.samnyan.aqua.net.utils.SUCCESS import icu.samnyan.aqua.sega.general.dao.CardRepository import icu.samnyan.aqua.sega.general.model.Card @@ -17,10 +18,12 @@ class CardController( val cardService: CardService, val cardGameService: CardGameService, val cardRepository: CardRepository, + val props: AquaNetProps ) { @API("/summary") suspend fun summary(@RP cardId: Str): Any { + // DO NOT CHANGE THIS ERROR MESSAGE - The frontend uses it to detect if the card is not found val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") // Lookup data for each game @@ -41,6 +44,9 @@ class CardController( */ @API("/bind") suspend fun bind(@RP token: Str, @RP cardId: Str, @RP migrate: Str) = jwt.auth(token) { u -> + // Check if the user's card limit is reached + if (u.cards.size >= props.linkCardLimit) 400 - "Card limit reached" + // Check if the card is already bound val card = cardService.tryLookup(cardId) ?: (404 - "Card not found") if (card.aquaUser != null) 400 - "Card already bound to another user (@${card.aquaUser?.username})" diff --git a/src/main/java/icu/samnyan/aqua/net/utils/AquaNetProps.kt b/src/main/java/icu/samnyan/aqua/net/utils/AquaNetProps.kt new file mode 100644 index 00000000..b2fcd328 --- /dev/null +++ b/src/main/java/icu/samnyan/aqua/net/utils/AquaNetProps.kt @@ -0,0 +1,10 @@ +package icu.samnyan.aqua.net.utils + +import org.springframework.boot.context.properties.ConfigurationProperties +import org.springframework.context.annotation.Configuration + +@Configuration +@ConfigurationProperties(prefix = "aqua-net") +class AquaNetProps { + var linkCardLimit: Int = 10 +} \ No newline at end of file