Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
32d050c
[-] Drop maimai finale since literally 0 accounts was created since 2024
hykilpikonna Oct 24, 2025
c4182fb
[O] CM Java > kt
hykilpikonna Oct 24, 2025
1ca1e3e
[-] Drop maimai finale database
hykilpikonna Oct 24, 2025
6d99bea
[F]
hykilpikonna Oct 24, 2025
567ed05
[-] ByteBufUtil
hykilpikonna Oct 24, 2025
9fe9450
[-] Drop chuni paradise
hykilpikonna Oct 24, 2025
7cd750b
[O] Java > kt
hykilpikonna Oct 24, 2025
7553c6a
[O] Assume non-null
hykilpikonna Oct 24, 2025
45e14e2
[F] Fix compile
hykilpikonna Oct 24, 2025
69f4f75
[M] Move files
hykilpikonna Oct 24, 2025
a61f602
[-] Remove unused
hykilpikonna Oct 24, 2025
00d74e6
[O] Optimize imports
hykilpikonna Oct 24, 2025
01d4262
[-] Drop chuni database
hykilpikonna Oct 24, 2025
ccd6367
[+] Firendly note
hykilpikonna Oct 24, 2025
f3cf673
[F] SQL order
hykilpikonna Oct 24, 2025
b87ff18
[-] Remove old start.bat
hykilpikonna Oct 24, 2025
e7b96d4
[-] Remove old files
hykilpikonna Oct 24, 2025
b2aef08
[O] Optional should not exist in kt
hykilpikonna Oct 24, 2025
458146a
[O] Optimize
hykilpikonna Oct 24, 2025
6767b62
Update CardMakerController.kt
hykilpikonna Oct 24, 2025
38b8831
[-] No advice
hykilpikonna Oct 24, 2025
664365b
[O] DIVA java > kt
hykilpikonna Oct 24, 2025
acf76bd
[O] DIVA kt > better kt
hykilpikonna Oct 24, 2025
32c3226
[O] DIVA repos > kt
hykilpikonna Oct 24, 2025
8d48ab0
[O] DIVA utils > kt
hykilpikonna Oct 24, 2025
419e22c
[-] BaseHandler
hykilpikonna Oct 24, 2025
c7a5458
[-] Remove unused imports
hykilpikonna Oct 24, 2025
619caec
[O] Use global db
hykilpikonna Oct 24, 2025
b7cb3cb
[-] Drop ng words and unused repo functinos
hykilpikonna Oct 25, 2025
e901233
[O] Capsule
hykilpikonna Oct 25, 2025
7e90aec
[O] Auto optimize
hykilpikonna Oct 25, 2025
8fc2a74
[O] Baseless
hykilpikonna Oct 25, 2025
55869f9
[O] Modelless
hykilpikonna Oct 25, 2025
3a54798
[O] Pojoless
hykilpikonna Oct 25, 2025
8e5827e
[O] DB > kt
hykilpikonna Oct 25, 2025
4cdf324
[O] Request > kt
hykilpikonna Oct 25, 2025
1827c8d
[-] Remove unused
hykilpikonna Oct 25, 2025
7fd71e3
[O] Abstract pd_id
hykilpikonna Oct 25, 2025
20b6af1
[M] Move
hykilpikonna Oct 25, 2025
4583676
[O] Other models > kt
hykilpikonna Oct 25, 2025
b5e27e8
[O] Optimize imports
hykilpikonna Oct 25, 2025
c6175b3
[-] Completely remove lombok
hykilpikonna Oct 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 0 additions & 25 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ plugins {
val ktVer = "2.1.10"

java
kotlin("plugin.lombok") version ktVer
kotlin("jvm") version ktVer
kotlin("plugin.spring") version ktVer
kotlin("plugin.jpa") version ktVer
kotlin("plugin.serialization") version ktVer
kotlin("plugin.allopen") version ktVer
kotlin("kapt") version ktVer
id("io.freefair.lombok") version "8.6"
id("org.springframework.boot") version "3.2.3"
id("com.github.ben-manes.versions") version "0.51.0"
id("org.hibernate.orm") version "6.4.4.Final"
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ext/Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ val <K, V> Map<K, V>.mut get() = toMutableMap()
val <T> Set<T>.mut get() = toMutableSet()

fun <T> List<T>.unique(fn: (T) -> Any) = distinctBy(fn).ifEmpty { null }
val <T> Collection<T>.csv get() = joinToString(",")
val IntArray.csv get() = joinToString(",")

// Optionals
operator fun <T> Optional<T>.invoke(): T? = orElse(null)
Expand All @@ -228,6 +230,7 @@ fun Str.fromChusanUsername() = String(this.toByteArray(StandardCharsets.ISO_8859
fun Str.truncate(len: Int) = if (this.length > len) this.take(len) + "..." else this
val Str.some get() = ifBlank { null }
val ByteArray.hexStr get() = toHexString()
operator fun StringBuilder.plusAssign(other: String) { this.append(other) }

// Coroutine
suspend fun <T> async(block: suspend kotlinx.coroutines.CoroutineScope.() -> T): T = withContext(Dispatchers.IO) { block() }
Expand Down Expand Up @@ -256,6 +259,7 @@ operator fun <E> List<E>.component13(): E = get(12)

inline operator fun <reified E> List<Any?>.invoke(i: Int) = get(i) as E
val empty = emptyList<Any>()
val emptyMap = emptyMap<Any, Any>()

val <F> Pair<F, *>.l get() = component1()
val <S> Pair<*, S>.r get() = component2()
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/icu/samnyan/aqua/net/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ext.*
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.chusan.model.Chu3Repos
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.general.model.CardStatus
import icu.samnyan.aqua.sega.general.model.sensitiveInfo
import icu.samnyan.aqua.sega.maimai2.model.Mai2Repos
Expand Down Expand Up @@ -52,7 +53,7 @@ class BotController(
secret.checkSecret()

// 1. Find user card
val oc = (us.cardRepo.findByLuid(card)() ?: (404 - "Card not found")).maybeGhost()
val oc = (us.cardRepo.findByLuid(card) ?: (404 - "Card not found")).maybeGhost()

// 2. Change the status to migrated
us.cardRepo.save(oc.apply {
Expand All @@ -66,7 +67,7 @@ class BotController(
fun clearMigrateFlag(@RP secret: Str, @RP card: Str): Any {
secret.checkSecret()

val oc = (us.cardRepo.findByLuid(card)() ?: (404 - "Card not found")).maybeGhost()
val oc = (us.cardRepo.findByLuid(card) ?: (404 - "Card not found")).maybeGhost()

us.cardRepo.save(oc.apply {
status = CardStatus.NORMAL
Expand All @@ -82,14 +83,14 @@ class BotController(
secret.checkSecret()

// 1. Check if the card exist
var cards = listOfNotNull(
us.cardRepo.findByLuid(cardId)(),
var cards: MutableList<Card> = listOfNotNull(
us.cardRepo.findByLuid(cardId),
).mut

cardId.toLongOrNull()?.let {
cards += listOfNotNull(
us.cardRepo.findById(it)(),
us.cardRepo.findByExtId(it)(),
us.cardRepo.findByExtId(it),
)

cards += listOfNotNull(
Expand All @@ -110,8 +111,8 @@ class BotController(

return cards.map { card ->
// Find all games played by this card
val chu3 = chu3Db.userData.findByCard_ExtId(card.extId)()
val mai2 = mai2Db.userData.findByCard_ExtId(card.extId)()
val chu3 = chu3Db.userData.findByCard_ExtId(card.extId)
val mai2 = mai2Db.userData.findByCard_ExtId(card.extId)
val gamesDict = listOfNotNull(chu3, mai2).map {
// Find the keychip owner
val keychip = it.lastClientId
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/icu/samnyan/aqua/net/CardController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import icu.samnyan.aqua.net.games.IUserData
import icu.samnyan.aqua.net.utils.AquaNetProps
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.chusan.model.Chu3UserDataRepo
import icu.samnyan.aqua.sega.diva.PlayerProfileRepository
import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.general.service.CardService
Expand All @@ -19,7 +20,6 @@ import org.springframework.scheduling.annotation.Scheduled
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.RestController
import java.time.LocalDateTime
import kotlin.jvm.optionals.getOrNull
import kotlin.random.Random

@RestController
Expand Down Expand Up @@ -204,7 +204,7 @@ class CardGameService(
val chusan: Chu3UserDataRepo,
val wacca: WcUserRepo,
val ongeki: OgkUserDataRepo,
val diva: icu.samnyan.aqua.sega.diva.dao.userdata.PlayerProfileRepository,
val diva: PlayerProfileRepository,
val safety: AquaNetSafetyService,
val cardRepo: CardRepository,
val em: EntityManager
Expand Down Expand Up @@ -238,7 +238,7 @@ class CardGameService(
"chu3" to getSummaryFor(chusan, card),
"ongeki" to getSummaryFor(ongeki, card),
"wacca" to getSummaryFor(wacca, card),
"diva" to diva.findByPdId(card.extId).getOrNull()?.let {
"diva" to diva.findByPdId(card.extId)()?.let {
mapOf(
"name" to it.playerName,
"rating" to it.level,
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/icu/samnyan/aqua/net/Fedy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ package icu.samnyan.aqua.net

import ext.*
import icu.samnyan.aqua.net.components.EmailProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.web.bind.annotation.RestController
import java.security.MessageDigest
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.net.components.JWT
import icu.samnyan.aqua.net.db.AquaNetUser
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.games.mai2.Mai2Import
import icu.samnyan.aqua.net.games.ExportOptions
import icu.samnyan.aqua.sega.maimai2.handler.UploadUserPlaylogHandler as Mai2UploadUserPlaylogHandler
import icu.samnyan.aqua.sega.maimai2.handler.UpsertUserAllHandler as Mai2UpsertUserAllHandler
import icu.samnyan.aqua.net.utils.ApiException
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserDataRepo
import icu.samnyan.aqua.net.games.GenericUserDataRepo
import icu.samnyan.aqua.net.games.IUserData
import icu.samnyan.aqua.net.games.mai2.Mai2Import
import icu.samnyan.aqua.net.utils.ApiException
import icu.samnyan.aqua.net.utils.PathProps
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.chusan.model.Chu3UserDataRepo
import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.general.service.CardService
import icu.samnyan.aqua.sega.maimai2.model.Mai2UserDataRepo
import icu.samnyan.aqua.sega.ongeki.OgkUserDataRepo
import icu.samnyan.aqua.sega.wacca.model.db.WcUserRepo
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.context.annotation.Configuration
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.security.MessageDigest
import java.util.concurrent.CompletableFuture
import kotlin.io.path.getLastModifiedTime
import kotlin.io.path.isRegularFile
import kotlin.io.path.writeBytes
import icu.samnyan.aqua.sega.maimai2.handler.UploadUserPlaylogHandler as Mai2UploadUserPlaylogHandler
import icu.samnyan.aqua.sega.maimai2.handler.UpsertUserAllHandler as Mai2UpsertUserAllHandler

@Configuration
@ConfigurationProperties(prefix = "aqua-net.fedy")
Expand Down Expand Up @@ -165,7 +165,7 @@ class Fedy(
data class DataPullRes(val error: FedyErr? = null, val result: Any? = null)
@API("/data/pull")
fun handleDataPull(@RH(KEY_HEADER) key: Str, @RT(REQ_PART) req: DataPullReq): DataPullRes = handleFedy(key) {
val card = cardRepo.findByExtId(req.extId).orElse(null)
val card = cardRepo.findByExtId(req.extId)
?: (404 - "Card with extId ${req.extId} not found")
{
DataPullRes(result = when (req.game) {
Expand All @@ -181,10 +181,9 @@ class Fedy(
fun handleDataPush(@RH(KEY_HEADER) key: Str, @RT(REQ_PART) req: DataPushReq): Any = handleFedy(key) {
val extId = req.extId
fun<UserData : IUserData, UserRepo : GenericUserDataRepo<UserData>> removeOldData(repo: UserRepo) {
val oldData = repo.findByCard_ExtId(extId)
if (oldData.isPresent) {
repo.findByCard_ExtId(extId)?.let { oldData ->
log.info("Fedy: Deleting old data for $extId (${req.game})")
repo.delete(oldData.get());
repo.delete(oldData);
repo.flush()
}
}
Expand Down Expand Up @@ -281,7 +280,7 @@ class Fedy(
fun onCardLinked(luid: Str, oldExtId: Long?, ghostExtId: Long, migratedGames: List<Str>) = maybeNotifyAsync(FedyEvent(cardLinked = CardLinkedEvent(luid, oldExtId, ghostExtId, migratedGames)))
fun onCardUnlinked(luid: Str) = maybeNotifyAsync(FedyEvent(cardUnlinked = CardUnlinkedEvent(luid)))
fun onDataUpdated(extId: Long, game: Str, removeOldData: Bool) = maybeNotifyAsync({
val card = cardRepo.findByExtId(extId).orElse(null) ?: return@maybeNotifyAsync null // Card not found, nothing to do
val card = cardRepo.findByExtId(extId) ?: return@maybeNotifyAsync null // Card not found, nothing to do
FedyEvent(dataUpdated = DataUpdatedEvent(extId, card.isGhost, game, removeOldData))
})

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/icu/samnyan/aqua/net/Frontier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Frontier(

if (accessCode.length != 20) 400 - "Invalid access code"
// if (!accessCode.startsWith("9900")) 400 - "Frontier access code must start with 9900"
if (async { cardService.cardRepo.findByLuid(accessCode) }.isPresent) 400 - "Card already registered"
if (async { cardService.cardRepo.findByLuid(accessCode) } != null) 400 - "Card already registered"

val card = async { cardService.registerByAccessCode(accessCode) }

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/icu/samnyan/aqua/net/Migrations.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package icu.samnyan.aqua.net

import ext.JACKSON
import ext.invoke
import ext.logger
import ext.parse
import icu.samnyan.aqua.net.db.AquaNetUserRepo
Expand All @@ -24,7 +23,7 @@ class Migrations(

@PostConstruct
fun migrate() {
val db = props.findByPropertyKey("migrations")() ?: PropertyEntry("migrations", "[]")
val db = props.findByPropertyKey("migrations") ?: PropertyEntry("migrations", "[]")
val p = JACKSON.parse<ArrayList<String>>(db.propertyValue)
val old = p.size

Expand All @@ -47,7 +46,7 @@ class Migrations(
if (c.extId > max) {
var new = c.extId and max
log.info("Removing signed bit: {${c.extId} -> $new} for ${c.luid}")
while (cardRepo.findByExtId(new).isPresent) {
while (cardRepo.findByExtId(new) != null) {
log.error("> Conflicting card found for ${c.luid}: $new")
new++
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/icu/samnyan/aqua/net/UserRegistrar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package icu.samnyan.aqua.net

import ext.*
import icu.samnyan.aqua.net.components.*
import icu.samnyan.aqua.net.db.*
import icu.samnyan.aqua.net.db.AquaUserServices.Companion.SETTING_FIELDS
import icu.samnyan.aqua.net.db.AquaNetUserRepo
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.db.EmailConfirmationRepo
import icu.samnyan.aqua.net.db.ResetPasswordRepo
import icu.samnyan.aqua.net.utils.PathProps
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.general.dao.CardRepository
import icu.samnyan.aqua.sega.general.model.Card
import icu.samnyan.aqua.sega.general.model.CardStatus
import icu.samnyan.aqua.sega.general.service.CardService
import jakarta.servlet.http.HttpServletRequest
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -18,7 +18,6 @@ import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.time.Instant
import java.time.LocalDateTime
import kotlin.io.path.writeBytes

@RestController
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/icu/samnyan/aqua/net/components/Email.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ package icu.samnyan.aqua.net.components
import ext.Bool
import ext.Str
import ext.logger
import icu.samnyan.aqua.net.db.AquaNetUser
import icu.samnyan.aqua.net.db.EmailConfirmation
import icu.samnyan.aqua.net.db.EmailConfirmationRepo
import icu.samnyan.aqua.net.db.ResetPassword
import icu.samnyan.aqua.net.db.ResetPasswordRepo
import icu.samnyan.aqua.net.db.*
import org.simplejavamail.api.mailer.Mailer
import org.simplejavamail.email.EmailBuilder
import org.simplejavamail.springsupport.SimpleJavaMailSpringSupport
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/icu/samnyan/aqua/net/components/JWT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ package icu.samnyan.aqua.net.components

import ext.Str
import ext.minus
import icu.samnyan.aqua.net.db.AquaNetUser
import icu.samnyan.aqua.net.db.AquaNetUserRepo
import icu.samnyan.aqua.net.db.SessionToken
import icu.samnyan.aqua.net.db.SessionTokenRepo
import icu.samnyan.aqua.net.db.getTokenExpiry
import icu.samnyan.aqua.net.db.*
import io.jsonwebtoken.JwtParser
import io.jsonwebtoken.Jwts
import io.jsonwebtoken.security.Keys
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/icu/samnyan/aqua/net/db/AquaNetSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.stereotype.Repository
import java.io.Serializable
import java.time.Instant
import java.util.UUID
import java.util.*

fun getTokenExpiry() = Instant.now().plusSeconds(7 * 86400)

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/icu/samnyan/aqua/net/db/AquaNetUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class AquaUserServices(

suspend fun cardByName(username: Str) =
if (username.startsWith("user")) username.substring(4).toLongOrNull()
?.let { cardRepo.findById(it).getOrNull() } ?: (404 - "Card not found")
?.let { cardRepo.findById(it)() } ?: (404 - "Card not found")
else byName(username) { it.ghostCard }

suspend fun <T> cardByName(username: Str, callback: suspend (Card) -> T) = callback(cardByName(username))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ abstract class GameApiController<T : IUserData>(val name: String, userDataClass:
}

@API("playlog")
fun playlog(@RP id: Long): IGenericGamePlaylog = playlogRepo.findById(id).getOrNull() ?: (404 - "Playlog not found")
fun playlog(@RP id: Long): IGenericGamePlaylog = playlogRepo.findById(id)() ?: (404 - "Playlog not found")

val userDetailFields by lazy { userDataClass.gettersMap().let { vm ->
(settableFields.keys.toSet() + gettableFields)
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/icu/samnyan/aqua/net/games/ImportController.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package icu.samnyan.aqua.net.games

import ext.*
import icu.samnyan.aqua.net.Fedy
import icu.samnyan.aqua.net.db.AquaNetUser
import icu.samnyan.aqua.net.db.AquaUserServices
import icu.samnyan.aqua.net.Fedy
import icu.samnyan.aqua.net.utils.AquaNetProps
import icu.samnyan.aqua.net.utils.SUCCESS
import icu.samnyan.aqua.sega.general.model.Card
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Lazy
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.repository.NoRepositoryBean
import org.springframework.transaction.PlatformTransactionManager
import org.springframework.transaction.support.TransactionTemplate
import java.time.LocalDateTime
import java.util.*
import kotlin.io.path.Path
import kotlin.io.path.writeText
import kotlin.reflect.KClass
import org.springframework.context.annotation.Lazy

data class ExportOptions(
val playlogAfter: String? = null
Expand All @@ -43,7 +42,7 @@ interface IExportClass<UserModel: IUserData> {
@NoRepositoryBean
interface IUserRepo<UserModel, ThisModel>: JpaRepository<ThisModel, Long> {
fun findByUser(user: UserModel): List<ThisModel>
fun findSingleByUser(user: UserModel): Optional<ThisModel>
fun findSingleByUser(user: UserModel): ThisModel?
}

/**
Expand Down Expand Up @@ -89,7 +88,7 @@ abstract class ImportController<ExportModel: IExportClass<UserModel>, UserModel:
userData = userDataRepo.findByCard(c) ?: (404 - "User not found")
exportRepos.forEach { (f, u) ->
if (f returns List::class) f.set(this, u.findByUser(userData))
else u.findSingleByUser(userData)()?.let { f.set(this, it) }
else u.findSingleByUser(userData)?.let { f.set(this, it) }
}
customExporters.forEach { (f, exporter) ->
exporter(userData, options)?.let { f.set(this, it) }
Expand Down
Loading