From b5959a4c77d1cb800c5e19720aa806a8b745af85 Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Wed, 14 Feb 2024 11:33:33 +0800 Subject: [PATCH 1/8] fix typo --- src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ISU.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ISU.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ISU.kt index d53a9b8..e7edce6 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ISU.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ISU.kt @@ -29,7 +29,7 @@ class ISU : NfApp(), IFshApp { override fun getAppDescription() = "我的世界玩家状态监控" - override fun getCommands() = arrayOf("-玩家状态", "-有妖怪在线吗", "-桃呢", "-有无妖怪", "-有妖怪在线吗") + override fun getCommands() = arrayOf("-玩家状态", "-有妖怪在线吗", "-桃呢", "-有无妖怪", "-有妖怪在吗") override fun getOptions() = NfOptions().apply { addOption("m", "more", false, "获取更多信息") From 9a53316c52f8e6afce91f76a41f5d6863f51f3f1 Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Sun, 24 Mar 2024 12:29:43 +0800 Subject: [PATCH 2/8] change minecraft player api respond body --- .../webAPI/router/mincreaftServer/player.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/player.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/player.kt index 2e1490b..4de1e4c 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/player.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/player.kt @@ -16,14 +16,31 @@ fun Route.player() { val data = MinecraftServerPlayer { this.id = id }.findById() ?: error(WebApi.requestError) - call.respond(NfResult.success(data)) + val apiModel = data.let { + MinecraftPlayerApiModel( + it.name, + it.id, + it.lastLoginTime.toString(), + it.lastLoginServer, + it.permissions + ) + } + call.respond(NfResult.success(apiModel)) } get("/players/search") { val name = call.request.queryParameters["name"] ?: error(WebApi.requestError) val data = MinecraftServerPlayer { this.name = name - }.findByName() + }.findByName().map { + MinecraftPlayerApiModel( + it.name, + it.id, + it.lastLoginTime.toString(), + it.lastLoginServer, + it.permissions + ) + } call.respond(NfResult.success(data)) } get("/players/online") { From 36f88765bdcb6c073b5e2952dc46ca0b9d161cbe Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Sun, 12 May 2024 15:24:57 +0800 Subject: [PATCH 3/8] change help url --- .../com/xiaoyv404/mirai/app/SomeThing.kt | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/SomeThing.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/SomeThing.kt index ae43903..efcdac0 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/SomeThing.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/SomeThing.kt @@ -1,15 +1,21 @@ package com.xiaoyv404.mirai.app -import com.xiaoyv404.mirai.* -import com.xiaoyv404.mirai.app.fsh.* -import com.xiaoyv404.mirai.core.* +import com.xiaoyv404.mirai.PluginData +import com.xiaoyv404.mirai.app.fsh.IFshApp +import com.xiaoyv404.mirai.core.App import com.xiaoyv404.mirai.core.MessageProcessor.reply -import com.xiaoyv404.mirai.extension.* -import net.mamoe.mirai.event.* -import net.mamoe.mirai.event.events.* -import net.mamoe.mirai.message.code.* -import net.mamoe.mirai.message.data.* -import kotlin.coroutines.* +import com.xiaoyv404.mirai.core.NfApp +import com.xiaoyv404.mirai.extension.getFriend +import net.mamoe.mirai.event.GlobalEventChannel +import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent +import net.mamoe.mirai.event.events.MessageEvent +import net.mamoe.mirai.event.events.NewFriendRequestEvent +import net.mamoe.mirai.event.subscribeGroupMessages +import net.mamoe.mirai.message.code.MiraiCode +import net.mamoe.mirai.message.data.PlainText +import net.mamoe.mirai.message.data.buildMessageChain +import kotlin.collections.set +import kotlin.coroutines.EmptyCoroutineContext @App class SomeThing : NfApp(), IFshApp { @@ -38,7 +44,7 @@ class SomeThing : NfApp(), IFshApp { } private suspend fun help(msg: MessageEvent) { - msg.reply("https://www.xiaoyv404.top/archives/404.html") + msg.reply("https://www.xiaoyv404.top/404/") } override fun init() { From 0ee31097be4c72608e7ee17e2a947649a274532f Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Sun, 12 May 2024 15:27:40 +0800 Subject: [PATCH 4/8] change web api parameter name --- .../app/webAPI/router/mincreaftServer/server.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/server.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/server.kt index b1527ab..c0cb9c1 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/server.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/router/mincreaftServer/server.kt @@ -15,14 +15,14 @@ import io.ktor.server.response.* import io.ktor.server.routing.* fun Route.server() { - get("/server/{n}") { - val n = call.parameters["n"] ?: error(WebApi.requestError) - if (n == "all") { + get("/server/{id}") { + val id = call.parameters["id"] ?: error(WebApi.requestError) + if (id == "all") { val map = getAll().map { it.apiModel() } call.respond(NfResult.success(map)) return@get } - val serverID = n.toIntOrNull() ?: error(WebApi.requestError) + val serverID = id.toIntOrNull() ?: error(WebApi.requestError) val data = MinecraftServer { this.id = serverID @@ -30,13 +30,13 @@ fun Route.server() { call.respond(NfResult.success(data)) } - patch("/server/{n}") { + patch("/server/{id}") { val principal = call.principal() ?: error(WebApi.noPrincipal) - val n = call.parameters["n"]?.toIntOrNull() ?: error(WebApi.requestError) + val id = call.parameters["id"]?.toIntOrNull() ?: error(WebApi.requestError) principal.name.permissionRequiredAdmin() val data = call.receive() - data.id = n + data.id = id val changeLine = data.update() if (changeLine == 0) WebApi.requestError From 3da531601fd20d3005433c9a03b4c0375252f302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=AE=87?= <63290381+xiaoyv404@users.noreply.github.com> Date: Wed, 19 Jun 2024 18:46:41 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20UserAlert.kt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/com/xiaoyv404/mirai/app/UserAlert.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/UserAlert.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/UserAlert.kt index f39a830..cd8f4f3 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/UserAlert.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/UserAlert.kt @@ -77,7 +77,7 @@ class UserAlert : NfAppMessageHandler(), IFshApp { val reply = buildMessageChain { +"${user.id}共收到${user.warningTimes}次警告" logs.forEach { - +"\n${it.executor} ${it.type.name}" + +"\n${it.executor} ${it.type.name} ${it.time}" } } println(reply) From 882c62ae93d30adbe25341b03d7f2d02bd900c4e Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Sun, 23 Jun 2024 00:31:28 +0800 Subject: [PATCH 6/8] fix UserAlerTest --- src/test/kotlin/com/xiaoyv404/mirai/app/UserAlertTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/xiaoyv404/mirai/app/UserAlertTest.kt b/src/test/kotlin/com/xiaoyv404/mirai/app/UserAlertTest.kt index 2191de7..12ae1f5 100644 --- a/src/test/kotlin/com/xiaoyv404/mirai/app/UserAlertTest.kt +++ b/src/test/kotlin/com/xiaoyv404/mirai/app/UserAlertTest.kt @@ -25,8 +25,8 @@ internal class UserAlertTest : BaseTest() { assertEquals( """ 1共收到2次警告 - 2 Increase - 2 Increase + 2 Increase 2006-04-16T06:58:39.810 + 2 Increase 2006-04-16T06:58:39.810 """.trimIndent(), msg[0].message.contentToString() ) From 93989d513ca74b5c733f240c1ee06555ced069d8 Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Fri, 19 Jul 2024 15:11:34 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mock=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=92=8Childe=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../minecraftServer/MinecraftServerList.kt | 38 +------- .../MinecraftServerListGenerator.kt | 87 +++++++++++++------ .../minecraftServer/MinecraftServerStats.kt | 50 ++++++----- .../ServerInformationFormatAndStatus.kt | 5 +- .../webAPI/model/MinecraftServerApiModel.kt | 7 +- .../mincraftServer/MinecraftServer.dao.kt | 18 ++-- src/test/resources/init-data.sql | 8 +- 7 files changed, 121 insertions(+), 92 deletions(-) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerList.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerList.kt index c01e8c5..f4e418d 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerList.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerList.kt @@ -1,7 +1,5 @@ package com.xiaoyv404.mirai.app.minecraftServer -import com.google.gson.Gson -import com.xiaoyv404.mirai.PluginConfig import com.xiaoyv404.mirai.app.fsh.IFshApp import com.xiaoyv404.mirai.core.App import com.xiaoyv404.mirai.core.MessageProcessor.reply @@ -10,7 +8,6 @@ import com.xiaoyv404.mirai.dao.send import com.xiaoyv404.mirai.dao.toList import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServer import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerPlayer -import com.xiaoyv404.mirai.tool.ClientUtils import net.mamoe.mirai.contact.Contact.Companion.uploadImage import net.mamoe.mirai.event.events.MessageEvent import net.mamoe.mirai.message.data.toMessageChain @@ -34,40 +31,11 @@ class MinecraftServerList : NfApp(), IFshApp { override suspend fun executeRsh(args: Array, msg: MessageEvent): Boolean { val cmdLine = IFshApp.cmdLine(options, args) - val tps = try { - Gson().fromJson( - ClientUtils.get( - "${PluginConfig.etc.planApiUrl}/v1/graph?server=Minecraft幻想乡&type=performance" - ), Performance::class.java - ).tps.takeLast(720) - } catch (e: Exception) { - null - } - - val low = mutableListOf() - val average = mutableListOf() - - var lowi: Long = 20 - var averagei: Long = 0 - var k = 1 - tps?.forEach { - if (k == 60) { - low.add(lowi) - average.add(averagei / 60) - lowi = 20 - averagei = 0 - k = 0 - } - if (lowi > it[1]) - lowi = it[1].toLong() - k++ - averagei += it[1].toLong() - } - - val list = MinecraftServer().toList() - val img = MinecraftServerListGenerator().drawList(list, low, average) + val list = MinecraftServer().toList().filter { !it.hilde } + val img = MinecraftServerListGenerator().drawList(list) msg.reply(msg.subject.uploadImage(img).toMessageChain()) + if (!cmdLine.hasOption("player")) return true MinecraftServerPlayer().getAllOnlinePlayers().send(msg) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerListGenerator.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerListGenerator.kt index 3e8479e..e78d328 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerListGenerator.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerListGenerator.kt @@ -1,7 +1,11 @@ package com.xiaoyv404.mirai.app.minecraftServer +import com.google.gson.Gson +import com.xiaoyv404.mirai.PluginConfig import com.xiaoyv404.mirai.PluginMain import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServer +import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerStatus +import com.xiaoyv404.mirai.tool.ClientUtils import java.awt.Color import java.awt.Font import java.awt.Graphics2D @@ -12,7 +16,7 @@ import java.io.ByteArrayOutputStream import java.util.* import javax.imageio.ImageIO -class MinecraftServerListGenerator() { +class MinecraftServerListGenerator { private val roundX = 10 private val red = Color.decode("#FF3D38") private val green = Color.decode("#76FFA1") @@ -27,7 +31,7 @@ class MinecraftServerListGenerator() { PluginMain.resolveDataFile("resources/Minecraft/Minecraft AE.ttf"), ).deriveFont(Font.PLAIN, 22f) - fun drawList(list: List, low: List, average: List): ByteArrayInputStream { + suspend fun drawList(list: List): ByteArrayInputStream { val imgWidth = 800 val imgHeight = 150 * list.size + 10 val img = BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB) @@ -57,7 +61,7 @@ class MinecraftServerListGenerator() { val status = v.status val roundY = 10 + k * 150 drawInfo(g2d, status, roundY, name, "%03d".format(v.playerNum), "%03d".format(v.playerMaxNum)) - drawBar(g2d, roundY, status, name, average, low) + drawBar(g2d, roundY, status, name) } g2d.dispose() @@ -68,13 +72,13 @@ class MinecraftServerListGenerator() { private fun drawInfo( g2d: Graphics2D, - status: Int, + status: MinecraftServerStatus, roundY: Int, name: String, playerNum: String, playerMaxNum: String ) { - g2d.color = if (status == 1) + g2d.color = if (status == MinecraftServerStatus.Online) green else red @@ -98,35 +102,34 @@ class MinecraftServerListGenerator() { } - private fun drawBar( + private suspend fun drawBar( g2d: Graphics2D, roundY: Int, - status: Int, + status: MinecraftServerStatus, name: String, - averages: List, - lows: List ) { - if (name != "MCG") { - g2d.color = if (status == 1) - green - else - red - - for (i in 0..11) + if (name == "MCG" && status == MinecraftServerStatus.Online) { + getMCGTps() + for (i in 0..11) { + (average.getOrNull(i) ?: 0).let { + g2d.color = setColorByTPS(it) + } drawBarPart(g2d, roundY, i) - return + (low.getOrNull(i) ?: 0).let { + g2d.color = setColorByTPS(it) + } + drawBarLowTpsPart(g2d, roundY, i) + } } - for (i in 0..11) { - (averages.getOrNull(i) ?: 0).let { - g2d.color = setColorByTPS(it) - } + g2d.color = if (status == MinecraftServerStatus.Online) + green + else + red + + for (i in 0..11) drawBarPart(g2d, roundY, i) - (lows.getOrNull(i) ?: 0).let { - g2d.color = setColorByTPS(it) - } - drawBarLowTpsPart(g2d, roundY, i) - } + return } private fun drawBarPart(g2d: Graphics2D, roundY: Int, i: Int) { @@ -163,4 +166,36 @@ class MinecraftServerListGenerator() { else -> red } } + + private val low = mutableListOf() + private val average = mutableListOf() + + private suspend fun getMCGTps(){ + val tps = try { + Gson().fromJson( + ClientUtils.get( + "${PluginConfig.etc.planApiUrl}/v1/graph?server=Minecraft幻想乡&type=performance" + ), Performance::class.java + ).tps.takeLast(720) + } catch (e: Exception) { + null + } + + var lowi: Long = 20 + var averagei: Long = 0 + var k = 1 + tps?.forEach { + if (k == 60) { + low.add(lowi) + average.add(averagei / 60) + lowi = 20 + averagei = 0 + k = 0 + } + if (lowi > it[1]) + lowi = it[1].toLong() + k++ + averagei += it[1].toLong() + } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerStats.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerStats.kt index 889350c..f4b04e8 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerStats.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/MinecraftServerStats.kt @@ -11,10 +11,10 @@ import com.xiaoyv404.mirai.core.gid import com.xiaoyv404.mirai.dao.* import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServer import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerMap +import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerStatus import com.xiaoyv404.mirai.tool.ClientUtils import kotlinx.coroutines.launch import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import net.mamoe.mirai.Bot import net.mamoe.mirai.contact.Contact @@ -52,14 +52,14 @@ class MinecraftServerStats : NfApp(), IFshApp { override suspend fun executeRsh(args: Array, msg: MessageEvent): Boolean { val cmdLine = IFshApp.cmdLine(getOptions(), args) - val severName = when { + val server = when { cmdLine.hasOption("server") -> cmdLine.getOptionValue("server") msg.gid() == 113594190L -> "gtnh" else -> "MCG" }.findByName() ?: return false sendInfo( - msg, severName, + msg, server, cmdLine.hasOption("player") ) return true @@ -92,17 +92,19 @@ class MinecraftServerStats : NfApp(), IFshApp { val players = info.serverInformationFormat?.players //判断当前服务器状态 - val statusT = if (info.status != 1) - -1 + val statusT = if (info.status != MinecraftServerStatus.Online) + MinecraftServerStatus.Offline else - 1 + MinecraftServerStatus.Online //通过状态生成提示语 - val data = server.msgMaker(statusT, players, msg.subject) - + val data = if (server.mock) + server.msgMaker(MinecraftServerStatus.Offline, players, msg.subject) + else + server.msgMaker(statusT, players, msg.subject) //获取服务器关联群,并发送提示 - if (statusT != server.status) { + if (statusT != server.status && !server.mock) { MinecraftServerMap { serverID = server.id }.findByServerId().forEach { @@ -120,7 +122,7 @@ class MinecraftServerStats : NfApp(), IFshApp { //如果有需求并且服务器在线,发送玩家列表 //并更新在线玩家列表 - if (statusT == 1 && playerList) + if (statusT == MinecraftServerStatus.Online && playerList && !server.mock) getPlayerList(server.host, server.port, players!!).let { it.save(server.name) server.getOnlinePlayers().send(msg) @@ -136,13 +138,13 @@ class MinecraftServerStats : NfApp(), IFshApp { val players = information.serverInformationFormat?.players //判断服务器现在是什么状态 - val statusT = if (statusD != 1) - if (info.status == 1) - 0 + val statusT = if (statusD != MinecraftServerStatus.Online) + if (info.status == MinecraftServerStatus.Online) + MinecraftServerStatus.Uncertain else - -1 + MinecraftServerStatus.Offline else - 1 + MinecraftServerStatus.Online //更新在线玩家列表 players?.players?.save(info.name) @@ -156,15 +158,19 @@ class MinecraftServerStats : NfApp(), IFshApp { }.update() //发送log并获取服务器的关联群 - if (!((statusT == -1 && info.status != -1) || (statusT == 1 && info.status == -1))) + if (!((statusT == MinecraftServerStatus.Offline && info.status != MinecraftServerStatus.Offline) || (statusT == MinecraftServerStatus.Online && info.status == MinecraftServerStatus.Offline))) return - if (statusT == 1) + if (statusT == MinecraftServerStatus.Online) log.info("服务器 ${info.name} 上线") else log.info("服务器 ${info.name} 离线") + // 如果在隐藏状态就不发送消息 + if (info.mock) + return + MinecraftServerMap { serverID = info.id }.findByServerId().forEach { groups.add(bot.getGroup(it.groupID) ?: return@forEach) } @@ -176,8 +182,12 @@ class MinecraftServerStats : NfApp(), IFshApp { } } - private suspend fun MinecraftServer.msgMaker(status: Int, playerList: Players?, subject: Contact): CodableMessage { - return if (status == 1) + private suspend fun MinecraftServer.msgMaker( + status: MinecraftServerStatus, + playerList: Players?, + subject: Contact + ): CodableMessage { + return if (status == MinecraftServerStatus.Online) subject.uploadImage( MinecraftDataImgGenerator.getImg( playerList!!.players, @@ -210,7 +220,7 @@ class MinecraftServerStats : NfApp(), IFshApp { pJ } catch (e: Exception) { PluginMain.logger.debug(e.message) - pJ.status = 0 + pJ.status = MinecraftServerStatus.Offline pJ } } diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ServerInformationFormatAndStatus.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ServerInformationFormatAndStatus.kt index fea0439..44b762c 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ServerInformationFormatAndStatus.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/minecraftServer/ServerInformationFormatAndStatus.kt @@ -1,10 +1,11 @@ package com.xiaoyv404.mirai.app.minecraftServer -import kotlinx.serialization.* +import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerStatus +import kotlinx.serialization.Serializable data class ServerInformationFormatAndStatus( var serverInformationFormat: ServerInformationFormat? = null, - var status: Int = 1 + var status: MinecraftServerStatus = MinecraftServerStatus.Online ) @Serializable diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/model/MinecraftServerApiModel.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/model/MinecraftServerApiModel.kt index 4fb8d4a..b355dc5 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/model/MinecraftServerApiModel.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/webAPI/model/MinecraftServerApiModel.kt @@ -1,6 +1,7 @@ package com.xiaoyv404.mirai.app.webAPI.model import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServer +import com.xiaoyv404.mirai.model.mincraftServer.MinecraftServerStatus import kotlinx.serialization.Serializable @Serializable @@ -18,7 +19,11 @@ fun MinecraftServer.apiModel(): MinecraftServerApiModel { this.name, this.host, this.port, - this.status, + when (this.status) { + MinecraftServerStatus.Online -> 1 + MinecraftServerStatus.Offline -> -1 + MinecraftServerStatus.Uncertain -> 1 + }, this.playerNum, this.playerMaxNum ) diff --git a/src/main/kotlin/com/xiaoyv404/mirai/model/mincraftServer/MinecraftServer.dao.kt b/src/main/kotlin/com/xiaoyv404/mirai/model/mincraftServer/MinecraftServer.dao.kt index 05df351..06812cd 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/model/mincraftServer/MinecraftServer.dao.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/model/mincraftServer/MinecraftServer.dao.kt @@ -1,6 +1,6 @@ package com.xiaoyv404.mirai.model.mincraftServer -import org.ktorm.entity.* +import org.ktorm.entity.Entity import org.ktorm.schema.* @@ -9,20 +9,28 @@ interface MinecraftServer : Entity { var id: Int val host: String val port: Int - var status: Int + var status: MinecraftServerStatus val name: String var playerNum: Int var playerMaxNum: Int + val mock: Boolean + val hilde: Boolean } - - object MinecraftServers : Table("MinecraftServer") { val id = int("id").primaryKey().bindTo { it.id } val host = varchar("host").bindTo { it.host } val port = int("port").bindTo { it.port } - val status = int("status").bindTo { it.status } + val status = enum("status").bindTo { it.status } val name = varchar("name").bindTo { it.name } val playerNum = int("playerNum").bindTo { it.playerNum } val playerMaxNum = int("playerMaxNum").bindTo { it.playerMaxNum } + val mock = boolean("mock").bindTo { it.mock } + val hilde = boolean("hilde").bindTo { it.hilde } +} + +enum class MinecraftServerStatus { + Online, + Offline, + Uncertain, } \ No newline at end of file diff --git a/src/test/resources/init-data.sql b/src/test/resources/init-data.sql index f9385b3..fec64c5 100644 --- a/src/test/resources/init-data.sql +++ b/src/test/resources/init-data.sql @@ -57,7 +57,9 @@ create table "MinecraftServer" "status" int8, "name" varchar(255), "playerNum" int8, - "playerMaxNum" int8 + "playerMaxNum" int8, + "hilde" boolean, + "mock" boolean ); insert into "Groups" ("id", "notice", "permission", "salutatory", "type") @@ -156,5 +158,5 @@ INSERT INTO "UserAlertLogs"("target", "executor", "time", "type") values (1, 2, '2006-04-16 06:58:39.810', 'Increase'), (1, 2, '2006-04-16 06:58:39.810', 'Increase'); -INSERT INTO "MinecraftServer"("id", "host", "port", "status", "name", "playerNum", "playerMaxNum") -values (1, 'test', 1, 1, 'mcg', 10, 80); +INSERT INTO "MinecraftServer"("id", "host", "port", "status", "name", "playerNum", "playerMaxNum", "hilde", "mock") +values (1, 'test', 1, 1, 'mcg', 10, 80, false, false); From 13173a4e54dfe67c2b91cd87f0fc1a33fe70d9a8 Mon Sep 17 00:00:00 2001 From: xiaoyv404 Date: Fri, 19 Jul 2024 15:35:08 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/resources/init-data.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/resources/init-data.sql b/src/test/resources/init-data.sql index fec64c5..9de1587 100644 --- a/src/test/resources/init-data.sql +++ b/src/test/resources/init-data.sql @@ -54,7 +54,7 @@ create table "MinecraftServer" "id" int8 not null, "host" varchar(255), "port" int8, - "status" int8, + "status" varchar(9), "name" varchar(255), "playerNum" int8, "playerMaxNum" int8, @@ -159,4 +159,4 @@ values (1, 2, '2006-04-16 06:58:39.810', 'Increase'), (1, 2, '2006-04-16 06:58:39.810', 'Increase'); INSERT INTO "MinecraftServer"("id", "host", "port", "status", "name", "playerNum", "playerMaxNum", "hilde", "mock") -values (1, 'test', 1, 1, 'mcg', 10, 80, false, false); +values (1, 'test', 1, 'Online', 'mcg', 10, 80, false, false);