mirror of https://github.com/hykilpikonna/AquaDX
[+] Wacca user/status/create
parent
13f3cf1e90
commit
c5d6f6f5b9
|
@ -122,6 +122,7 @@ fun Any.long() = when (this) {
|
|||
}
|
||||
|
||||
// Collections
|
||||
fun <T> ls(vararg args: T) = args.toList()
|
||||
operator fun <K, V> Map<K, V>.plus(map: Map<K, V>) =
|
||||
(if (this is MutableMap) this else toMutableMap()).apply { putAll(map) }
|
||||
operator fun <K, V> MutableMap<K, V>.plusAssign(map: Map<K, V>) { putAll(map) }
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package icu.samnyan.aqua.sega.wacca
|
||||
|
||||
import icu.samnyan.aqua.sega.wacca.model.db.WaccaUser
|
||||
import icu.samnyan.aqua.sega.wacca.model.db.WcUserItem
|
||||
|
||||
enum class WaccaGrades(val value: Int) {
|
||||
D(1),
|
||||
C(2),
|
||||
|
@ -23,25 +26,28 @@ enum class WaccaDifficulty(val value: Int) {
|
|||
INFERNO(4),
|
||||
}
|
||||
|
||||
val WACCA_ITEM_TYPES = mapOf(
|
||||
"xp" to 1,
|
||||
"wp" to 2,
|
||||
"music_unlock" to 3,
|
||||
"music_difficulty_unlock" to 4,
|
||||
"title" to 5,
|
||||
"icon" to 6,
|
||||
"trophy" to 7,
|
||||
"skill" to 8,
|
||||
"ticket" to 9,
|
||||
"note_color" to 10,
|
||||
"note_sound" to 11,
|
||||
"baht_do_not_send" to 12,
|
||||
"boost_badge" to 13,
|
||||
"gate_point" to 14,
|
||||
"navigator" to 15,
|
||||
"user_plate" to 16,
|
||||
"touch_effect" to 17,
|
||||
)
|
||||
enum class WaccaItemType(val type: Int) {
|
||||
XP(1),
|
||||
WP(2),
|
||||
MUSIC_UNLOCK(3),
|
||||
MUSIC_DIFFICULTY_UNLOCK(4),
|
||||
TITLE(5),
|
||||
ICON(6),
|
||||
TROPHY(7),
|
||||
SKILL(8),
|
||||
TICKET(9),
|
||||
NOTE_COLOR(10),
|
||||
NOTE_SOUND(11),
|
||||
BAHT_DO_NOT_SEND(12),
|
||||
BOOST_BADGE(13),
|
||||
GATE_POINT(14),
|
||||
NAVIGATOR(15),
|
||||
USER_PLATE(16),
|
||||
TOUCH_EFFECT(17);
|
||||
|
||||
operator fun invoke() = type
|
||||
operator fun invoke(u: WaccaUser, id: Int) = WcUserItem(u, id, this)
|
||||
}
|
||||
|
||||
enum class WaccaOptionType(val id: Int, val default: Int) {
|
||||
NOTE_SPEED(1, 5), // 1.0 - 6.0
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package icu.samnyan.aqua.sega.wacca
|
||||
|
||||
import ext.*
|
||||
import icu.samnyan.aqua.sega.general.dao.CardRepository
|
||||
import icu.samnyan.aqua.sega.wacca.WaccaItemType.*
|
||||
import icu.samnyan.aqua.sega.wacca.WaccaOptionType.SET_ICON_ID
|
||||
import icu.samnyan.aqua.sega.wacca.WaccaOptionType.SET_TITLE_ID
|
||||
import icu.samnyan.aqua.sega.wacca.model.BaseRequest
|
||||
|
@ -15,7 +17,7 @@ val empty = emptyList<Any>()
|
|||
|
||||
@RestController
|
||||
@API("/g/wacca/")
|
||||
class WaccaServer(val rp: WaccaRepos) {
|
||||
class WaccaServer(val rp: WaccaRepos, val cardRepo: CardRepository) {
|
||||
val handlerMap = mutableMapOf<String, (BaseRequest, List<Any>) -> List<Any>>()
|
||||
val cacheMap = mutableMapOf<String, String>()
|
||||
|
||||
|
@ -26,10 +28,7 @@ class WaccaServer(val rp: WaccaRepos) {
|
|||
// DSL Functions
|
||||
fun options(u: WaccaUser?) = u?.let { rp.option.findByUser(u).associate { it.optId to it.value } } ?: emptyMap()
|
||||
operator fun Map<Int, Int>.get(type: WaccaOptionType) = getOrDefault(type.id, type.default)
|
||||
|
||||
fun ls(vararg args: Any) = args.toList()
|
||||
operator fun String.minus(value: Any) = value
|
||||
|
||||
operator fun String.invoke(block: (BaseRequest, List<Any>) -> List<Any>) { handlerMap[this.lowercase()] = block }
|
||||
infix fun String.cached(block: () -> Any) { cacheMap[this.lowercase()] = block().toJson() }
|
||||
|
||||
|
@ -79,14 +78,33 @@ fun WaccaServer.api() {
|
|||
val ru = rp.user.findById(uid.long())()
|
||||
val u = ru ?: WaccaUser()
|
||||
val o = options(ru)
|
||||
u.run { ls(
|
||||
ls(u.id, username, "userType" - 1, xp, danLevel, danType, wp, "titlePartIds" - ls(0, 0, 0),
|
||||
loginCount, loginCountDays, loginCountConsec, loginCountDaysConsec, vipExpireTime, loginCountToday, rating),
|
||||
u.run { ls(u.lStatus(),
|
||||
o[SET_TITLE_ID], o[SET_ICON_ID],
|
||||
"status" - if (ru == null) 1 else 0, // 0 = GOOD, 1 = Register
|
||||
// 0 = Version GOOD, 1 = Game is newer, 2 = Game is older
|
||||
"version" - ls(req.appVersion.shortVer().compareTo(lastGameVer.shortVer()), lastGameVer.shortVer()),
|
||||
"version" - ls(req.appVersion.shortVer().compareTo(lastGameVer.shortVer())
|
||||
.let { if (it < 0) 1 else if (it > 0) 2 else 0 }, // 0 = Version GOOD, 1 = Game is newer, 2 = Game is older
|
||||
lastGameVer.shortVer()),
|
||||
o.map { (k, v) -> ls(k, v) }
|
||||
) }
|
||||
}
|
||||
|
||||
"user/status/create" { _, (uid, name) ->
|
||||
val u = rp.user.save(WaccaUser().apply {
|
||||
card = cardRepo.findByExtId(uid.long())() ?: (400 - "Card not found")
|
||||
username = name.toString()
|
||||
})
|
||||
|
||||
// Starter items
|
||||
rp.item.saveAll(
|
||||
ls(104001, 104002, 104003, 104005).map { TITLE(u, it) } +
|
||||
ls(102001, 102002).map { ICON(u, it) } +
|
||||
ls(103001, 203001).map { NOTE_COLOR(u, it) } +
|
||||
ls(105001, 205005).map { NOTE_SOUND(u, it) } +
|
||||
(ls(210001, 210002, 310001, 310002) + (210054..210061)).map { NAVIGATOR(u, it) } +
|
||||
ls(211001).map { USER_PLATE(u, it) } +
|
||||
ls(312000, 312001).map { TOUCH_EFFECT(u, it) }
|
||||
)
|
||||
|
||||
ls(u.lStatus())
|
||||
}
|
||||
}
|
|
@ -1,9 +1,10 @@
|
|||
package icu.samnyan.aqua.sega.wacca.model.db
|
||||
|
||||
import ext.ls
|
||||
import icu.samnyan.aqua.net.games.BaseEntity
|
||||
import icu.samnyan.aqua.sega.general.model.Card
|
||||
import jakarta.persistence.*
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* General user information
|
||||
|
@ -12,7 +13,7 @@ import java.util.Date
|
|||
class WaccaUser : BaseEntity() {
|
||||
@OneToOne
|
||||
@JoinColumn(name = "aime_card_id", unique = true)
|
||||
var card: Card? = null
|
||||
var card: Card = Card()
|
||||
|
||||
@Column(length = 8)
|
||||
var username = ""
|
||||
|
@ -52,4 +53,7 @@ class WaccaUser : BaseEntity() {
|
|||
var lastSongOrder = 0
|
||||
var lastLoginDate: String? = null
|
||||
var gateTutorialFlags: String? = null
|
||||
|
||||
fun lStatus() = ls(card.id, username, 1, xp, danLevel, danType, wp, ls(0, 0, 0), loginCount, loginCountDays,
|
||||
loginCountConsec, loginCountDaysConsec, vipExpireTime, loginCountToday, rating)
|
||||
}
|
|
@ -2,6 +2,7 @@ package icu.samnyan.aqua.sega.wacca.model.db
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import icu.samnyan.aqua.net.games.BaseEntity
|
||||
import icu.samnyan.aqua.sega.wacca.WaccaItemType
|
||||
import jakarta.persistence.*
|
||||
|
||||
typealias UC = UniqueConstraint
|
||||
|
@ -59,11 +60,13 @@ class WcUserGate : WaccaUserEntity() {
|
|||
}
|
||||
|
||||
@Entity @Table(name = "wacca_user_item", uniqueConstraints = [UC("", ["user_id", "item_id", "type"])])
|
||||
class WcUserItem : WaccaUserEntity() {
|
||||
class WcUserItem() : WaccaUserEntity() {
|
||||
var itemId = 0
|
||||
var type = 0
|
||||
var acquireDate = ""
|
||||
var useCount = 0
|
||||
|
||||
constructor(u: WaccaUser, id: Int, typ: WaccaItemType) : this() { user = u; itemId = id; type = typ() }
|
||||
}
|
||||
|
||||
@Entity @Table(name = "wacca_user_ticket", uniqueConstraints = [UC("", ["user_id", "ticket_id"])])
|
||||
|
|
|
@ -50,4 +50,9 @@ class WaccaTest : StringSpec({
|
|||
post("user/status/get", """["$uid"]""").res shouldBe
|
||||
"""[[0, "", 1, 0, 0, 0, 0, [0, 0, 0], 0, 0, 0, 0, 0, 0, 0], 104001, 102001, 1, [2, "1.0.0"], []]""".jsonArray()
|
||||
}
|
||||
|
||||
"user/status/create #1" {
|
||||
post("user/status/create", """["$uid", "AZA"]""").res shouldBe
|
||||
"""[[$uid, "AZA", 1, 0, 0, 0, 0, [0, 0, 0], 0, 0, 0, 0, 0, 0, 0]]""".jsonArray()
|
||||
}
|
||||
})
|
Loading…
Reference in New Issue