[F] Fix server return type

pull/110/head
Azalea 2025-01-17 13:02:55 -05:00
parent 93518aa1f4
commit 202df27f88
4 changed files with 65 additions and 52 deletions

View File

@ -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()
}
}

View File

@ -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) {
// <IP Address, RecruitInfo>
val recruits = mutableMapOf<UInt, RecruitRecord>()
// 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<RecruitRecord>(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<String>) {

View File

@ -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<Bool>,
var UserIDs: List<Long>,
val UserNames: List<String>,
val IconIDs: List<Int>,
val FumenDifs: List<Int>,
val Rateing: List<Int>,
val ClassValue: List<Int>,
val MaxClassValue: List<Int>,
val UserType: List<Int>
)
@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
)

View File

@ -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(
}
}
}
}
}
@Serializable
data class MechaInfo(
val IsJoin: Bool,
val IpAddress: UInt,
val MusicID: Int,
val Entrys: List<Bool>,
var UserIDs: List<Long>,
val UserNames: List<String>,
val IconIDs: List<Int>,
val FumenDifs: List<Int>,
val Rateing: List<Int>,
val ClassValue: List<Int>,
val MaxClassValue: List<Int>,
val UserType: List<Int>
)
@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
)