Skip to content

Commit

Permalink
修复 BombAPI
Browse files Browse the repository at this point in the history
- 修复 BombAPI
- 当 refreshRankingListInHour 为负数是禁止排行榜
  • Loading branch information
Taskeren committed Sep 18, 2023
1 parent 1001e78 commit 382ee4a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
20 changes: 14 additions & 6 deletions booster/src/main/kotlin/explode2/booster/BoosterMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import explode2.booster.event.KtorInitEvent
import explode2.booster.event.KtorModuleEvent
import explode2.booster.util.forEachExceptional
import io.github.lxgaming.classloader.ClassLoaderUtils
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import org.koin.core.context.startKoin
Expand Down Expand Up @@ -76,12 +77,7 @@ fun main() {

logger.debug("Listening on ${addr}:${port}")

ktorServer = embeddedServer(Netty, port = port, host = addr) {
MainLogics.setupGraphQL(this)

// 启动服务器后发布注册事件
KtorModuleEvent(this).dispatchEvent()
}
ktorServer = embeddedServer(Netty, port = port, host = addr, module = Application::explodeModule)
try {
ktorServer.start(true)
} catch(e: BindException) {
Expand All @@ -92,6 +88,10 @@ fun main() {

koinApp

Runtime.getRuntime().addShutdownHook(thread(start = false, name = "Main Stopping Thread") {
Explode.saveAllConfig()
})

logger.info("Boosted!")
// 主线程退出
}
Expand Down Expand Up @@ -177,4 +177,12 @@ object ExplodeService {
logger.error(preludeMarker, "Exception occurred when post-initializing plugin ${plugin.id}", exception)
}

}

fun Application.explodeModule() {
MainLogics.setupGraphQL(this)
MainLogics.setupResource(this)

// 启动服务器后发布注册事件
KtorModuleEvent(this).dispatchEvent()
}
5 changes: 1 addition & 4 deletions booster/src/main/kotlin/explode2/booster/bomb/BombPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.ktor.server.routing.*
import io.ktor.util.pipeline.*
import org.greenrobot.eventbus.Subscribe
import org.koin.core.component.inject
import org.koin.ktor.plugin.Koin
import org.slf4j.LoggerFactory
import org.slf4j.MarkerFactory
import java.lang.reflect.Type
Expand All @@ -47,7 +46,7 @@ class BombPlugin : BoosterPlugin {
override val id: String = "bomb-api"
override val version: String = "1.0.0"

private val pathRaw = config.getString("route-path", "general", "explode2/booster/bomb/v{version}", "后端根地址")
private val pathRaw = config.getString("route-path", "general", "/bomb/v{version}", "后端根地址")
private val useSuperstar = config.getBoolean("superstar-admin", "general", true, "启用 Superstar 账号")

// 后门账号,用于创建初始账号
Expand Down Expand Up @@ -133,8 +132,6 @@ class BombPlugin : BoosterPlugin {
anyHost()
}

install(Koin)

routing {
route(path, bombModule)
}
Expand Down
2 changes: 2 additions & 0 deletions booster/src/main/kotlin/explode2/booster/graphql/BasicMaze.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ object BasicMaze : ExplodeQuery, ExplodeMutation, MazeProvider {
val l = limit.int.baah("invalid limit")
return if(refreshRankingListInHour > 0) {
RefreshingRankingList.getOrCreate(cid, refreshRankingListInHour, recRepo).get(l, s)
} else if(refreshRankingListInHour < 0) {
listOf()
} else {
recRepo
.getChartRecords(cid, l, s)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package explode2.booster.graphql.definition

import explode2.booster.graphql.BasicMaze
import explode2.booster.graphql.BasicMaze.getUser
import explode2.booster.graphql.BasicMaze.refreshRankingListInHour
import explode2.booster.graphql.GraphqlDataSource.assInfoRepo
import explode2.booster.graphql.GraphqlDataSource.assRecRepo
import explode2.booster.graphql.GraphqlDataSource.recRepo
Expand Down Expand Up @@ -33,8 +33,10 @@ object BasicSelfImpl : Self {
override suspend fun playRankSelf(env: DataFetchingEnvironment, chartId: String?): PlayRecordWithRankModel? {
val u = env.getUser().baah("invalid token")
val cid = chartId.baah("invalid chart id")
return if(BasicMaze.refreshRankingListInHour > 0) {
RefreshingRankingList.getOrCreate(cid, BasicMaze.refreshRankingListInHour, recRepo).get(u.id)
return if(refreshRankingListInHour > 0) {
RefreshingRankingList.getOrCreate(cid, refreshRankingListInHour, recRepo).get(u.id)
} else if(refreshRankingListInHour < 0) {
null
} else {
recRepo.getPlayerBestChartRecord(cid, u.id)?.tunerize()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
explode2.booster.bomb.BombPlugin
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

rootProject.name = "explode3"
rootProject.name = "explode2+"
include("gateau")
include("labyrinth")
include("labyrinth-mongodb")
Expand Down

0 comments on commit 382ee4a

Please sign in to comment.