Remove Punishments and Update

Dieser Commit ist enthalten in:
Chaoscaot 2023-06-04 09:22:02 +02:00
Ursprung e643908d44
Commit c179dac718
6 geänderte Dateien mit 83 neuen und 28 gelöschten Zeilen

Datei anzeigen

@ -23,19 +23,19 @@ repositories {
}
dependencies {
implementation("io.ktor:ktor-server-core-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-serialization-kotlinx-json-jvm:$ktor_version")
implementation("io.ktor:ktor-server-jetty-jvm:$ktor_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-call-logging-jvm:2.2.1")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktor_version")
implementation("io.ktor:ktor-server-core-jvm:2.3.0")
implementation("io.ktor:ktor-server-content-negotiation-jvm:2.3.0")
implementation("io.ktor:ktor-server-cors-jvm:2.3.0")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:2.3.0")
implementation("io.ktor:ktor-server-jetty-jvm:2.3.0")
implementation("io.ktor:ktor-server-host-common-jvm:2.3.0")
implementation("io.ktor:ktor-server-call-logging-jvm:2.3.0")
implementation("io.ktor:ktor-server-request-validation:2.3.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
implementation("io.ktor:ktor-server-request-validation:$ktor_version")
implementation("com.mysql:mysql-connector-j:8.0.31")
implementation(project(":CommonCore"))
implementation("org.bspfsystems:yamlconfiguration:1.3.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1")
testImplementation("io.ktor:ktor-server-tests-jvm:2.3.0")
}

Datei anzeigen

@ -30,7 +30,7 @@ import java.util.Properties
val validCodes by lazy {
val file = File(System.getProperty("user.home"), "api-codes.txt")
if(!file.exists()) {
if (!file.exists()) {
file.createNewFile()
}
Properties().apply {
@ -47,7 +47,7 @@ fun isValidCode(code: String): Pair<Boolean, String> {
val SWAuth = createApplicationPlugin("SWAuth") {
onCall { call ->
if(call.request.httpMethod == HttpMethod.Options) {
if (call.request.httpMethod == HttpMethod.Options) {
return@onCall
}
val auth = call.request.headers["X-SW-Auth"] ?: call.request.queryParameters["auth"]

Datei anzeigen

@ -28,7 +28,6 @@ import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.request.*
import kotlinx.serialization.json.Json
import org.slf4j.event.*
import java.security.MessageDigest
data class Session(val name: String)
@ -53,7 +52,7 @@ fun Application.configurePlugins() {
level = Level.INFO
format {
val auth = it.request.headers["X-SW-Auth"]
if(auth != null) {
if (auth != null) {
val verfied = isValidCode(auth)
return@format "Auth: ${verfied.second}, Valid: ${verfied.first}, ${it.request.httpMethod.value} ${it.request.uri}"
} else {

Datei anzeigen

@ -37,7 +37,7 @@ data class ResponseSchematicType(val name: String, val db: String)
@Serializable
data class ResponseUser(val id: Int, val name: String, val uuid: String) {
constructor(user: SteamwarUser): this(user.id, user.userName, user.uuid.toString())
constructor(user: SteamwarUser) : this(user.id, user.userName, user.uuid.toString())
}
fun Routing.configureDataRoutes() {
@ -48,7 +48,10 @@ fun Routing.configureDataRoutes() {
call.respond(types.filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
}
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 })
}
get("/gamemodes/{gamemode}/maps") {
val gamemode = call.parameters["gamemode"]

Datei anzeigen

@ -38,22 +38,55 @@ import java.time.Instant
@Serializable
data class ShortEvent(val id: Int, val name: String, val start: Long, val end: Long) {
constructor(event: Event): this(event.eventID, event.eventName, event.start.time, event.end.time)
constructor(event: Event) : this(event.eventID, event.eventName, event.start.time, event.end.time)
}
@Serializable
data class ResponseEvent(val id: Int, val name: String, val deadline: Long, val start: Long, val end: Long, val maxTeamMembers: Int, val schemType: String?, val publicSchemsOnly: Boolean, val spectateSystem: Boolean) {
constructor(event: Event): this(event.eventID, event.eventName, event.deadline.time, event.start.time, event.end.time, event.maximumTeamMembers, event.schematicType?.toDB(), event.publicSchemsOnly(), event.spectateSystem())
data class ResponseEvent(
val id: Int,
val name: String,
val deadline: Long,
val start: Long,
val end: Long,
val maxTeamMembers: Int,
val schemType: String?,
val publicSchemsOnly: Boolean,
val spectateSystem: Boolean
) {
constructor(event: Event) : this(
event.eventID,
event.eventName,
event.deadline.time,
event.start.time,
event.end.time,
event.maximumTeamMembers,
event.schematicType?.toDB(),
event.publicSchemsOnly(),
event.spectateSystem()
)
}
@Serializable
data class ExtendedResponseEvent(val event: ResponseEvent, val teams: List<ResponseTeam>, val fights: List<ResponseEventFight>)
data class ExtendedResponseEvent(
val event: ResponseEvent,
val teams: List<ResponseTeam>,
val fights: List<ResponseEventFight>
)
@Serializable
data class CreateEvent(val name: String, val start: Long, val end: Long)
@Serializable
data class UpdateEvent(val name: String?, val deadline: Long?, val start: Long?, val end: Long?, val maxTeamMembers: Int?, val schemType: String?, val publicSchemsOnly: Boolean?, val spectateSystem: Boolean?)
data class UpdateEvent(
val name: String?,
val deadline: Long?,
val start: Long?,
val end: Long?,
val maxTeamMembers: Int?,
val schemType: String?,
val publicSchemsOnly: Boolean?,
val spectateSystem: Boolean?
)
fun Routing.configureEventsRoute() {
route("/events") {
@ -66,7 +99,11 @@ fun Routing.configureEventsRoute() {
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid body"))
return@post
}
val event = Event.create(createEvent.name, Timestamp.from(Instant.ofEpochMilli(createEvent.start)), Timestamp.from(Instant.ofEpochMilli(createEvent.end)))
val event = Event.create(
createEvent.name,
Timestamp.from(Instant.ofEpochMilli(createEvent.start)),
Timestamp.from(Instant.ofEpochMilli(createEvent.end))
)
call.respond(HttpStatusCode.Created, ResponseEvent(event))
}
route("/{id}") {
@ -81,7 +118,12 @@ fun Routing.configureEventsRoute() {
call.respond(HttpStatusCode.NotFound, ResponseError("Event not found"))
return@get
}
call.respond(ExtendedResponseEvent(ResponseEvent(event), TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) }, EventFight.getFromEvent(event.eventID).map { ResponseEventFight(it) }))
call.respond(
ExtendedResponseEvent(
ResponseEvent(event),
TeamTeilnahme.getTeams(event.eventID).map { ResponseTeam(it) },
EventFight.getFromEvent(event.eventID).map { ResponseEventFight(it) })
)
}
get("/teams") {
val id = call.parameters["id"]?.toIntOrNull()
@ -128,8 +170,17 @@ fun Routing.configureEventsRoute() {
csv.appendLine()
val blue = Team.get(it.teamBlue)
val red = Team.get(it.teamRed)
val winner = if (it.ergebnis == 1) blue.teamName else if(it.ergebnis == 2) red.teamName else if(it.ergebnis == 3) "Tie" else "Unknown"
csv.append(arrayOf(it.startTime.toString(), Team.get(it.teamBlue).teamName, Team.get(it.teamRed).teamName, winner, Groups.getGroup(it.fightID)?.name ?: "Ungrouped").joinToString(","))
val winner =
if (it.ergebnis == 1) blue.teamName else if (it.ergebnis == 2) red.teamName else if (it.ergebnis == 3) "Tie" else "Unknown"
csv.append(
arrayOf(
it.startTime.toString(),
Team.get(it.teamBlue).teamName,
Team.get(it.teamRed).teamName,
winner,
Groups.getGroup(it.fightID)?.name ?: "Ungrouped"
).joinToString(",")
)
}
call.response.header("Content-Disposition", "attachment; filename=\"${event.eventName}.csv\"")
call.response.header("Content-Type", "text/csv")
@ -169,10 +220,10 @@ fun Routing.configureEventsRoute() {
event.maximumTeamMembers = updateEvent.maxTeamMembers
}
if (updateEvent.schemType != null) {
if(updateEvent.schemType == "null") {
if (updateEvent.schemType == "null") {
event.setSchemType(null)
} else {
if(SchematicType.fromDB(updateEvent.schemType) != null) {
if (SchematicType.fromDB(updateEvent.schemType) != null) {
event.setSchemType(SchematicType.fromDB(updateEvent.schemType))
}
}

Datei anzeigen

@ -30,7 +30,7 @@ import kotlinx.serialization.Serializable
@Serializable
data class ResponseMod(val platform: Int, val modName: String, val modType: Int) {
constructor(mod: Mod): this(mod.platform.ordinal, mod.modName, mod.modType.ordinal)
constructor(mod: Mod) : this(mod.platform.ordinal, mod.modName, mod.modType.ordinal)
}
@Serializable
@ -48,7 +48,9 @@ fun Routing.configureModRoutes() {
val platform = call.parameters["platform"]
val modName = call.parameters["mod"]
val update = call.receiveNullable<UpdateMod>()
if (platform == null || !Mod.Platform.values().map { it.name }.contains(platform) || modName == null || update == null || !Mod.ModType.values().map { it.name }.contains(update.modType)) {
if (platform == null || !Mod.Platform.values().map { it.name }
.contains(platform) || modName == null || update == null || !Mod.ModType.values().map { it.name }
.contains(update.modType)) {
call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid something"))
return@put
}