forked from SteamWar/SteamWar
55 lines
2.1 KiB
Kotlin
55 lines
2.1 KiB
Kotlin
/*
|
|
* This file is a part of the SteamWar software.
|
|
*
|
|
* Copyright (C) 2026 SteamWar.de-Serverteam
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package de.steamwar.routes.v2
|
|
|
|
import de.steamwar.ResponseError
|
|
import io.ktor.http.HttpStatusCode
|
|
import io.ktor.server.application.call
|
|
import io.ktor.server.response.respond
|
|
import io.ktor.server.routing.Route
|
|
import io.ktor.server.routing.get
|
|
import io.ktor.server.routing.route
|
|
import org.bspfsystems.yamlconfiguration.file.YamlConfiguration
|
|
import java.io.File
|
|
import kotlin.io.nameWithoutExtension
|
|
|
|
fun Route.configureGameModeRoutes() {
|
|
route("/gamemodes") {
|
|
get {
|
|
call.respond(
|
|
File("/configs/GameModes/").listFiles()!!
|
|
.filter { it.name.endsWith(".yml") && !it.name.endsWith(".kits.yml") }
|
|
.map { it.nameWithoutExtension })
|
|
}
|
|
get("/{gamemode}/maps") {
|
|
val gamemode = call.parameters["gamemode"]
|
|
if (gamemode == null) {
|
|
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid gamemode"))
|
|
return@get
|
|
}
|
|
val file = File("/configs/GameModes/$gamemode.yml")
|
|
if (!file.exists()) {
|
|
call.respond(HttpStatusCode.NotFound, ResponseError("Gamemode not found"))
|
|
return@get
|
|
}
|
|
call.respond(YamlConfiguration.loadConfiguration(file).getStringList("Server.Maps"))
|
|
}
|
|
}
|
|
} |