diff --git a/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt b/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt index edc9e09e..69b2849e 100644 --- a/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt +++ b/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt @@ -8,6 +8,8 @@ import org.springframework.context.annotation.Configuration import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer import org.springframework.web.servlet.resource.PathResourceResolver +import kotlin.io.path.createFile +import kotlin.io.path.exists @Configuration @ConfigurationProperties(prefix = "paths") @@ -15,14 +17,18 @@ class PathProps { var mai2Plays: String = "data/upload/mai2/plays" var mai2Portrait: String = "data/upload/mai2/portrait" var aquaNetPortrait: String = "data/upload/net/portrait" - var recruitLog: String = "data/futari/recruit.log" + var futariRecruitLog: String = "data/futari/recruit.log" + var futariRelayInfo: String = "data/futari/relays.json" @PostConstruct fun init() { mai2Plays = mai2Plays.path().apply { toFile().mkdirs() }.toString() mai2Portrait = mai2Portrait.path().apply { toFile().mkdirs() }.toString() aquaNetPortrait = aquaNetPortrait.path().apply { toFile().mkdirs() }.toString() - recruitLog = recruitLog.path().apply { toFile().parentFile.mkdirs() }.toString() + futariRecruitLog = futariRecruitLog.path().apply { toFile().parentFile.mkdirs() }.toString() + futariRelayInfo = futariRelayInfo.path() + .apply { toFile().parentFile.mkdirs() } + .apply { if (!exists()) createFile() }.toString() } } diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariLobby.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariLobby.kt index 58a5823a..d9fb2b01 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariLobby.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariLobby.kt @@ -14,6 +14,7 @@ import java.io.FileOutputStream import java.time.LocalDateTime import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.withLock +import kotlin.io.path.readText // KotlinX Serialization @@ -30,7 +31,7 @@ const val MAX_TTL = 30 * 1000 @RestController @RequestMapping(path = ["/mai2-futari"]) -class FutariLobby(paths: PathProps) { +class FutariLobby(val paths: PathProps) { // val recruits = mutableMapOf() // Append writer @@ -40,7 +41,7 @@ class FutariLobby(paths: PathProps) { init { paths.init() - writer = FileOutputStream(File(paths.recruitLog), true).bufferedWriter() + writer = FileOutputStream(File(paths.futariRecruitLog), true).bufferedWriter() } fun log(data: String) = mutex.withLock { @@ -69,7 +70,7 @@ class FutariLobby(paths: PathProps) { fun finishRecruit(@RB data: String) { val d = parsing { KJson.decodeFromString(data) } if (d.ip !in recruits) 400 - "Recruit not found" - if (d.Keychip != recruits[d.ip]!!.Keychip) 400 - "Keychip mismatch" +// if (d.Keychip != recruits[d.ip]!!.Keychip) 400 - "Keychip mismatch" recruits.remove(d.ip) log(d, "EndRecruit") } @@ -78,8 +79,11 @@ class FutariLobby(paths: PathProps) { fun listRecruit(): String { val time = millis() recruits.filterValues { time - it.Time > MAX_TTL }.keys.forEach { recruits.remove(it) } - return recruits.values.toList().joinToString("\n") { KJson.encodeToString(it.RecruitInfo) } + return recruits.values.toList().joinToString("\n") { KJson.encodeToString(it) } } + + @API("server-list") + fun serverList() = paths.futariRelayInfo.path().readText().trim() } fun main(args: Array) { diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariModels.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariModels.kt deleted file mode 100644 index e8178c54..00000000 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariModels.kt +++ /dev/null @@ -1,41 +0,0 @@ -@file:Suppress("PropertyName") - -package icu.samnyan.aqua.sega.maimai2.worldslink - -import ext.Bool -import kotlinx.serialization.Serializable - -@Serializable -data class MechaInfo( - val IsJoin: Bool, - val IpAddress: UInt, - val MusicID: Int, - val Entrys: List, - var UserIDs: List, - val UserNames: List, - val IconIDs: List, - val FumenDifs: List, - val Rateing: List, - val ClassValue: List, - val MaxClassValue: List, - val UserType: List -) - -@Serializable -data class RecruitInfo( - val MechaInfo: MechaInfo, - val MusicID: Int, - val GroupID: Int, - val EventModeID: Boolean, - val JoinNumber: Int, - val PartyStance: Int, - val _startTimeTicks: Long, - val _recvTimeTicks: Long -) - -@Serializable -data class RecruitRecord( - val RecruitInfo: RecruitInfo, - val Keychip: String, - var Time: Long = 0 -) diff --git a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariTypes.kt b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariTypes.kt index c011af57..4544b412 100644 --- a/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariTypes.kt +++ b/src/main/java/icu/samnyan/aqua/sega/maimai2/worldslink/FutariTypes.kt @@ -1,9 +1,9 @@ +@file:Suppress("PropertyName") + package icu.samnyan.aqua.sega.maimai2.worldslink -import ext.arr -import ext.ls -import ext.some -import ext.str +import ext.* +import kotlinx.serialization.Serializable object Command { // Control plane @@ -53,4 +53,48 @@ data class Msg( } } } -} \ No newline at end of file +} + +@Serializable +data class MechaInfo( + val IsJoin: Bool, + val IpAddress: UInt, + val MusicID: Int, + val Entrys: List, + var UserIDs: List, + val UserNames: List, + val IconIDs: List, + val FumenDifs: List, + val Rateing: List, + val ClassValue: List, + val MaxClassValue: List, + val UserType: List +) + +@Serializable +data class RecruitInfo( + val MechaInfo: MechaInfo, + val MusicID: Int, + val GroupID: Int, + val EventModeID: Boolean, + val JoinNumber: Int, + val PartyStance: Int, + val _startTimeTicks: Long, + val _recvTimeTicks: Long +) + +@Serializable +data class RecruitRecord( + val RecruitInfo: RecruitInfo, + val Keychip: String, + var Server: RelayServerInfo? = null, + var Time: Long = 0, +) + +@Serializable +data class RelayServerInfo( + val name: String, + val addr: String, + val port: Int = 20101, + val official: Bool = true +)