Add Fight Delete
Dieser Commit ist enthalten in:
Ursprung
84a1ce87c6
Commit
0b670cd016
@ -23,17 +23,13 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.ktor:ktor-server-auto-head-response-jvm:$ktor_version")
|
|
||||||
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
|
implementation("io.ktor:ktor-server-core-jvm:$ktor_version")
|
||||||
implementation("io.ktor:ktor-server-caching-headers-jvm:$ktor_version")
|
|
||||||
implementation("io.ktor:ktor-server-compression-jvm:$ktor_version")
|
|
||||||
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
|
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktor_version")
|
||||||
implementation("io.ktor:ktor-server-cors-jvm:$ktor_version")
|
implementation("io.ktor:ktor-server-cors-jvm:$ktor_version")
|
||||||
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
|
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktor_version")
|
||||||
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
|
implementation("io.ktor:ktor-server-netty-jvm:$ktor_version")
|
||||||
implementation("ch.qos.logback:logback-classic:$logback_version")
|
implementation("ch.qos.logback:logback-classic:$logback_version")
|
||||||
implementation("io.ktor:ktor-server-host-common-jvm:2.2.1")
|
implementation("io.ktor:ktor-server-host-common-jvm:2.2.1")
|
||||||
implementation("io.ktor:ktor-server-status-pages-jvm:2.2.1")
|
|
||||||
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
|
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
|
||||||
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||||
implementation("io.ktor:ktor-server-request-validation:$ktor_version")
|
implementation("io.ktor:ktor-server-request-validation:$ktor_version")
|
||||||
|
@ -1,46 +1,15 @@
|
|||||||
package de.steamwar.plugins
|
package de.steamwar.plugins
|
||||||
|
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.http.content.*
|
|
||||||
import io.ktor.serialization.kotlinx.json.*
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.plugins.autohead.*
|
|
||||||
import io.ktor.server.plugins.cachingheaders.*
|
|
||||||
import io.ktor.server.plugins.compression.*
|
|
||||||
import io.ktor.server.plugins.contentnegotiation.*
|
import io.ktor.server.plugins.contentnegotiation.*
|
||||||
import io.ktor.server.plugins.cors.routing.*
|
import io.ktor.server.plugins.cors.routing.*
|
||||||
import io.ktor.server.plugins.statuspages.*
|
|
||||||
import io.ktor.server.response.*
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
data class Session(val name: String)
|
data class Session(val name: String)
|
||||||
|
|
||||||
fun Application.configurePlugins() {
|
fun Application.configurePlugins() {
|
||||||
install(AutoHeadResponse)
|
|
||||||
|
|
||||||
install(CachingHeaders) {
|
|
||||||
options { call, outgoingContent ->
|
|
||||||
when (outgoingContent.contentType?.withoutParameters()) {
|
|
||||||
ContentType.Text.CSS -> CachingOptions(CacheControl.MaxAge(maxAgeSeconds = 24 * 60 * 60))
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
install(Compression) {
|
|
||||||
gzip {
|
|
||||||
priority = 1.0
|
|
||||||
}
|
|
||||||
deflate {
|
|
||||||
priority = 10.0
|
|
||||||
minimumSize(1024) // condition
|
|
||||||
}
|
|
||||||
}
|
|
||||||
install(StatusPages) {
|
|
||||||
exception<Throwable> { call, cause ->
|
|
||||||
call.respondText(text = "500: $cause\n${cause.stackTraceToString()}", status = HttpStatusCode.InternalServerError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
install(CORS) {
|
install(CORS) {
|
||||||
allowMethod(HttpMethod.Options)
|
allowMethod(HttpMethod.Options)
|
||||||
allowMethod(HttpMethod.Get)
|
allowMethod(HttpMethod.Get)
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
package de.steamwar.routes
|
package de.steamwar.routes
|
||||||
|
|
||||||
import de.steamwar.ResponseError
|
import de.steamwar.ResponseError
|
||||||
|
import de.steamwar.sql.SQLWrapperImpl
|
||||||
import de.steamwar.sql.SchematicType
|
import de.steamwar.sql.SchematicType
|
||||||
import de.steamwar.sql.SteamwarUser
|
import de.steamwar.sql.SteamwarUser
|
||||||
|
import de.steamwar.sql.loadSchematicTypes
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
import io.ktor.server.application.*
|
import io.ktor.server.application.*
|
||||||
import io.ktor.server.response.*
|
import io.ktor.server.response.*
|
||||||
@ -20,7 +22,9 @@ data class ResponseUser(val id: Int, val name: String, val uuid: String)
|
|||||||
fun Routing.configureDataRoutes() {
|
fun Routing.configureDataRoutes() {
|
||||||
route("/data") {
|
route("/data") {
|
||||||
get("/schematicTypes") {
|
get("/schematicTypes") {
|
||||||
call.respond(SchematicType.values().filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
|
val types = mutableListOf<SchematicType>()
|
||||||
|
loadSchematicTypes(types, mutableMapOf())
|
||||||
|
call.respond(types.filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
|
||||||
}
|
}
|
||||||
get("/gamemodes") {
|
get("/gamemodes") {
|
||||||
call.respond(File("/configs/GameModes/").listFiles().filter { it.name.endsWith(".yml") && !it.name.endsWith(".kits.yml") }.map { it.nameWithoutExtension })
|
call.respond(File("/configs/GameModes/").listFiles().filter { it.name.endsWith(".yml") && !it.name.endsWith(".kits.yml") }.map { it.nameWithoutExtension })
|
||||||
|
@ -42,42 +42,59 @@ fun Routing.configureEventFightRoutes() {
|
|||||||
val eventFight = EventFight.create(fight.event, Timestamp.from(Instant.ofEpochMilli(fight.start)), fight.spielmodus, fight.map, fight.blueTeam, fight.redTeam)
|
val eventFight = EventFight.create(fight.event, Timestamp.from(Instant.ofEpochMilli(fight.start)), fight.spielmodus, fight.map, fight.blueTeam, fight.redTeam)
|
||||||
call.respond(HttpStatusCode.Created, ResponseEventFight(eventFight))
|
call.respond(HttpStatusCode.Created, ResponseEventFight(eventFight))
|
||||||
}
|
}
|
||||||
put("/{fight}") {
|
route("/{fight}") {
|
||||||
val fightId = call.parameters["fight"]?.toIntOrNull()
|
put {
|
||||||
if (fightId == null) {
|
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
if (fightId == null) {
|
||||||
return@put
|
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||||
|
return@put
|
||||||
|
}
|
||||||
|
val fight = EventFight.get(fightId)
|
||||||
|
if (fight == null) {
|
||||||
|
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||||
|
return@put
|
||||||
|
}
|
||||||
|
val updateFight = call.receiveNullable<UpdateEventFight>()
|
||||||
|
if (updateFight == null) {
|
||||||
|
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body"))
|
||||||
|
return@put
|
||||||
|
}
|
||||||
|
if(updateFight.blueTeam != null && Team.get(updateFight.blueTeam) != null) {
|
||||||
|
fight.teamBlue = updateFight.blueTeam
|
||||||
|
}
|
||||||
|
if(updateFight.redTeam != null && Team.get(updateFight.redTeam) != null) {
|
||||||
|
fight.teamRed = updateFight.redTeam
|
||||||
|
}
|
||||||
|
if(updateFight.kampfleiter != null && SteamwarUser.get(updateFight.kampfleiter) != null) {
|
||||||
|
fight.kampfleiter = updateFight.kampfleiter
|
||||||
|
}
|
||||||
|
if(updateFight.start != null) {
|
||||||
|
fight.startTime = Timestamp.from(Instant.ofEpochMilli(updateFight.start))
|
||||||
|
}
|
||||||
|
if(updateFight.map != null) {
|
||||||
|
fight.map = updateFight.map
|
||||||
|
}
|
||||||
|
if(updateFight.spielmodus != null) {
|
||||||
|
fight.spielModus = updateFight.spielmodus
|
||||||
|
}
|
||||||
|
fight.update()
|
||||||
|
call.respond(HttpStatusCode.OK, ResponseEventFight(fight))
|
||||||
}
|
}
|
||||||
val fight = EventFight.get(fightId)
|
delete {
|
||||||
if (fight == null) {
|
val fightId = call.parameters["fight"]?.toIntOrNull()
|
||||||
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
if (fightId == null) {
|
||||||
return@put
|
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid fight ID"))
|
||||||
|
return@delete
|
||||||
|
}
|
||||||
|
val fight = EventFight.get(fightId)
|
||||||
|
if (fight == null) {
|
||||||
|
call.respond(HttpStatusCode.NotFound, ResponseError("Fight not found"))
|
||||||
|
return@delete
|
||||||
|
}
|
||||||
|
fight.delete()
|
||||||
|
call.respond(HttpStatusCode.OK)
|
||||||
}
|
}
|
||||||
val updateFight = call.receiveNullable<UpdateEventFight>()
|
|
||||||
if (updateFight == null) {
|
|
||||||
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body"))
|
|
||||||
return@put
|
|
||||||
}
|
|
||||||
if(updateFight.blueTeam != null && Team.get(updateFight.blueTeam) != null) {
|
|
||||||
fight.teamBlue = updateFight.blueTeam
|
|
||||||
}
|
|
||||||
if(updateFight.redTeam != null && Team.get(updateFight.redTeam) != null) {
|
|
||||||
fight.teamRed = updateFight.redTeam
|
|
||||||
}
|
|
||||||
if(updateFight.kampfleiter != null && SteamwarUser.get(updateFight.kampfleiter) != null) {
|
|
||||||
fight.kampfleiter = updateFight.kampfleiter
|
|
||||||
}
|
|
||||||
if(updateFight.start != null) {
|
|
||||||
fight.startTime = Timestamp.from(Instant.ofEpochMilli(updateFight.start))
|
|
||||||
}
|
|
||||||
if(updateFight.map != null) {
|
|
||||||
fight.map = updateFight.map
|
|
||||||
}
|
|
||||||
if(updateFight.spielmodus != null) {
|
|
||||||
fight.spielModus = updateFight.spielmodus
|
|
||||||
}
|
|
||||||
fight.update()
|
|
||||||
call.respond(HttpStatusCode.OK, ResponseEventFight(fight))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,37 +5,38 @@ import java.io.File
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
class SQLWrapperImpl: SQLWrapper {
|
fun loadSchematicTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
|
||||||
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) {
|
val folder = File("/configs/GameModes")
|
||||||
val folder = File("/configs/GameModes")
|
if (folder.exists()) {
|
||||||
if (folder.exists()) {
|
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
||||||
for (configFile in Arrays.stream(folder.listFiles { _, name -> name.endsWith(".yml") && !name.endsWith(".kits.yml") })
|
.sorted().collect(Collectors.toList())) {
|
||||||
.sorted().collect(Collectors.toList())) {
|
val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile)
|
||||||
val config: YamlConfiguration = YamlConfiguration.loadConfiguration(configFile)
|
if (!config.isConfigurationSection("Schematic")) continue
|
||||||
if (!config.isConfigurationSection("Schematic")) continue
|
val type: String = config.getString("Schematic.Type")!!
|
||||||
val type: String = config.getString("Schematic.Type")!!
|
val shortcut: String = config.getString("Schematic.Shortcut")!!
|
||||||
val shortcut: String = config.getString("Schematic.Shortcut")!!
|
if (tmpFromDB!!.containsKey(type.lowercase(Locale.getDefault()))) continue
|
||||||
if (tmpFromDB!!.containsKey(type.lowercase(Locale.getDefault()))) continue
|
var checktype: SchematicType? = null
|
||||||
var checktype: SchematicType? = null
|
val material: String = config.getString("Schematic.Material", "STONE_BUTTON")!!
|
||||||
val material: String = config.getString("Schematic.Material", "STONE_BUTTON")!!
|
if (!config.getStringList("CheckQuestions").isEmpty()) {
|
||||||
if (!config.getStringList("CheckQuestions").isEmpty()) {
|
checktype = SchematicType("C$type", "C$shortcut", SchematicType.Type.CHECK_TYPE, null, material)
|
||||||
checktype = SchematicType("C$type", "C$shortcut", SchematicType.Type.CHECK_TYPE, null, material)
|
tmpTypes!!.add(checktype)
|
||||||
tmpTypes!!.add(checktype)
|
tmpFromDB[checktype.toDB()] = checktype
|
||||||
tmpFromDB[checktype.toDB()] = checktype
|
|
||||||
}
|
|
||||||
val current = SchematicType(
|
|
||||||
type,
|
|
||||||
shortcut,
|
|
||||||
if (config.isConfigurationSection("Server")) SchematicType.Type.FIGHT_TYPE else SchematicType.Type.NORMAL,
|
|
||||||
checktype,
|
|
||||||
material
|
|
||||||
)
|
|
||||||
tmpTypes!!.add(current)
|
|
||||||
tmpFromDB[type.lowercase(Locale.getDefault())] = current
|
|
||||||
}
|
}
|
||||||
|
val current = SchematicType(
|
||||||
|
type,
|
||||||
|
shortcut,
|
||||||
|
if (config.isConfigurationSection("Server")) SchematicType.Type.FIGHT_TYPE else SchematicType.Type.NORMAL,
|
||||||
|
checktype,
|
||||||
|
material
|
||||||
|
)
|
||||||
|
tmpTypes!!.add(current)
|
||||||
|
tmpFromDB[type.lowercase(Locale.getDefault())] = current
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SQLWrapperImpl: SQLWrapper {
|
||||||
|
override fun loadSchemTypes(tmpTypes: MutableList<SchematicType>?, tmpFromDB: MutableMap<String, SchematicType>?) = loadSchematicTypes(tmpTypes, tmpFromDB)
|
||||||
|
|
||||||
override fun additionalExceptionMetadata(builder: StringBuilder) {
|
override fun additionalExceptionMetadata(builder: StringBuilder) {
|
||||||
builder.append("EventAPI")
|
builder.append("EventAPI")
|
||||||
|
Laden…
x
In neuem Issue referenzieren
Einen Benutzer sperren