From 6d648b9a719ded0a0c14c4476595f6d28c97224e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 18 Aug 2024 13:03:24 +0200 Subject: [PATCH] Fixes --- .../SQL/src/de/steamwar/sql/SteamwarUser.java | 2 +- .../SQL/src/de/steamwar/sql/UserPerm.java | 2 +- WebsiteBackend/build.gradle.kts | 9 -- WebsiteBackend/src/de/steamwar/Application.kt | 1 - .../src/de/steamwar/bungee/Bungee.kt | 56 ------------ .../src/de/steamwar/data/SkinCache.kt | 4 +- .../src/de/steamwar/plugins/Auth.kt | 1 + .../src/de/steamwar/plugins/SteamWar.kt | 4 +- WebsiteBackend/src/de/steamwar/routes/Data.kt | 86 ++++++++++--------- .../src/de/steamwar/routes/Schematic.kt | 12 +-- steamwarci.yml | 2 +- 11 files changed, 61 insertions(+), 118 deletions(-) delete mode 100644 WebsiteBackend/src/de/steamwar/bungee/Bungee.kt diff --git a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java index 8aefbd49..96974c61 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java +++ b/CommonCore/SQL/src/de/steamwar/sql/SteamwarUser.java @@ -373,6 +373,6 @@ public class SteamwarUser { } public static List getAll() { - return null; + return getAll.listSelect(); } } diff --git a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java index a05fe2ad..ed842d54 100644 --- a/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java +++ b/CommonCore/SQL/src/de/steamwar/sql/UserPerm.java @@ -65,7 +65,7 @@ public enum UserPerm { private static final Table table = new Table<>(UserPermTable.class, "UserPerm"); private static final SelectStatement getPerms = table.selectFields("user"); - private static final Statement addPerm = table.insertFields("user", "perm"); + private static final Statement addPerm = table.insertAll(); private static final Statement removePerm = table.delete(Table.PRIMARY); public static Set getPerms(int user) { diff --git a/WebsiteBackend/build.gradle.kts b/WebsiteBackend/build.gradle.kts index 321dc310..2cf527a7 100644 --- a/WebsiteBackend/build.gradle.kts +++ b/WebsiteBackend/build.gradle.kts @@ -26,15 +26,6 @@ plugins { application { mainClass.set("de.steamwar.ApplicationKt") - - val isDevelopment: Boolean = project.ext.has("development") - applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment") -} - -ktor { - fatJar { - archiveFileName.set("api.jar") - } } tasks.build { diff --git a/WebsiteBackend/src/de/steamwar/Application.kt b/WebsiteBackend/src/de/steamwar/Application.kt index 1b653a60..23fc3066 100644 --- a/WebsiteBackend/src/de/steamwar/Application.kt +++ b/WebsiteBackend/src/de/steamwar/Application.kt @@ -44,7 +44,6 @@ data class Config(val giteaToken: String) val config = Json.decodeFromStream(File("config.json").inputStream()) fun main() { - SchematicType.Normal.name().length Thread { while (true) { Thread.sleep(1000 * 10) diff --git a/WebsiteBackend/src/de/steamwar/bungee/Bungee.kt b/WebsiteBackend/src/de/steamwar/bungee/Bungee.kt deleted file mode 100644 index 547aa2cf..00000000 --- a/WebsiteBackend/src/de/steamwar/bungee/Bungee.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2024 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 . - */ - -package de.steamwar.bungee - -import java.io.ObjectInputStream -import java.io.ObjectOutputStream -import java.net.Socket - -object Bungee { - var socket: Socket? = null - var output: ObjectOutputStream? = null - var thread: Thread? = null - - fun run() { - val input = ObjectInputStream(socket!!.getInputStream()) - - while (socket != null && !socket!!.isClosed) { - if (input.available() <= 0) { - Thread.sleep(50) - continue - } - } - - socket = null - thread = null - output = null - } - - inline fun connect(func: (Socket) -> Unit) { - if(socket == null || socket!!.isClosed) { - socket = Socket("localhost", 7546) - output = ObjectOutputStream(socket!!.getOutputStream()) - thread = Thread(Bungee::run) - thread!!.start() - } - - func(socket!!) - } -} \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/data/SkinCache.kt b/WebsiteBackend/src/de/steamwar/data/SkinCache.kt index 6a6ff935..a8b056eb 100644 --- a/WebsiteBackend/src/de/steamwar/data/SkinCache.kt +++ b/WebsiteBackend/src/de/steamwar/data/SkinCache.kt @@ -91,7 +91,7 @@ suspend fun getCachedSkin(uuid: String): Pair { val file = File(kCacheFolderFile, "$uuid.webp") if (file.exists()) { if (CacheConfig.isOutdated(uuid)) { - val skin = client.get("https://visage.surgeplay.com/bust/150/$uuid") + val skin = client.get("https://vzge.me/bust/150/$uuid") skin.bodyAsChannel().copyTo(file.outputStream()) CacheConfig.update(uuid) @@ -103,7 +103,7 @@ suspend fun getCachedSkin(uuid: String): Pair { withContext(Dispatchers.IO) { file.createNewFile() } - val skin = client.get("https://visage.surgeplay.com/bust/150/$uuid") + val skin = client.get("https://vzge.me/bust/150/$uuid") skin.bodyAsChannel().copyTo(file.outputStream()) CacheConfig.update(uuid) return file to false diff --git a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt index 40006aa5..bf26f6f4 100644 --- a/WebsiteBackend/src/de/steamwar/plugins/Auth.kt +++ b/WebsiteBackend/src/de/steamwar/plugins/Auth.kt @@ -99,6 +99,7 @@ Message: ${cause.message} } """ + SWException.log(msg, cause.stackTraceToString()) call.response.headers.append("X-Caught", "1") } } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/plugins/SteamWar.kt b/WebsiteBackend/src/de/steamwar/plugins/SteamWar.kt index bcac22bc..db96a700 100644 --- a/WebsiteBackend/src/de/steamwar/plugins/SteamWar.kt +++ b/WebsiteBackend/src/de/steamwar/plugins/SteamWar.kt @@ -19,9 +19,11 @@ package de.steamwar.plugins +import de.steamwar.routes.catchException import de.steamwar.sql.SteamwarUser import io.ktor.server.request.* +import java.util.UUID fun ApplicationRequest.getUser(key: String = "id"): SteamwarUser? { - return SteamwarUser.get(call.parameters[key]?.toIntOrNull() ?: return null) + return SteamwarUser.get(call.parameters[key]?.let { catchException { UUID.fromString(it) } } ?: return null) } \ No newline at end of file diff --git a/WebsiteBackend/src/de/steamwar/routes/Data.kt b/WebsiteBackend/src/de/steamwar/routes/Data.kt index d05ffc90..2e055d40 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Data.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Data.kt @@ -44,10 +44,10 @@ import java.util.UUID data class ResponseSchematicType(val name: String, val db: String) @Serializable -data class ResponseUser(val id: Int, val name: String, val uuid: String, val prefix: String, val perms: List) { - constructor(user: SteamwarUser) : this(user.id, user.userName, user.uuid.toString(), user.prefix().chatPrefix, user.perms().map { it.name }) { +data class ResponseUser(val name: String, val uuid: String, val prefix: String, val perms: List) { + constructor(user: SteamwarUser) : this(user.userName, user.uuid.toString(), user.prefix().chatPrefix, user.perms().map { it.name }) { synchronized(cache) { - cache[id] = this + cache[user.id] = this } } @@ -73,32 +73,51 @@ fun Route.configureDataRoutes() { get { call.respondText("Hello World!") } - get("/schematicTypes") { - val types = mutableListOf() - loadSchematicTypes(types, mutableMapOf()) - 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 }) - } - get("/gamemodes/{gamemode}/maps") { - val gamemode = call.parameters["gamemode"] - if (gamemode == null) { - call.respond(HttpStatusCode.BadRequest, ResponseError("Invalid gamemode")) - return@get + route("/admin") { + install(SWPermissionCheck) { + mustAuth = true + permission = UserPerm.PREFIX_MODERATOR } - val file = File("/configs/GameModes/$gamemode.yml") - if (!file.exists()) { - call.respond(HttpStatusCode.NotFound, ResponseError("Gamemode not found")) - return@get + get("/users") { + call.respond(SteamwarUser.getAll().map { ResponseUser(it) }) + } + get("/schematicTypes") { + val types = mutableListOf() + loadSchematicTypes(types, mutableMapOf()) + 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 }) + } + get("/gamemodes/{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")) + } + get("/groups") { + call.respond(Groups.getAllGroups()) + } + get("/server") { + try { + val server = fetchData(InetSocketAddress("steamwar.de", 25565), 100) + call.respond(server) + } catch (e: Exception) { + e.printStackTrace() + call.respond(HttpStatusCode.InternalServerError, ResponseError(e.message ?: "Unknown error")) + return@get + } } - call.respond(YamlConfiguration.loadConfiguration(file).getStringList("Server.Maps")) - } - get("/users") { - call.respond(SteamwarUser.getAll().map { ResponseUser(it) }) } get("/team") { call.respond( @@ -108,19 +127,6 @@ fun Route.configureDataRoutes() { .mapValues { it.value.map { ResponseUser(it) } } ) } - get("/groups") { - call.respond(Groups.getAllGroups()) - } - get("/server") { - try { - val server = fetchData(InetSocketAddress("steamwar.de", 25565), 100) - call.respond(server) - } catch (e: Exception) { - e.printStackTrace() - call.respond(HttpStatusCode.InternalServerError, ResponseError(e.message ?: "Unknown error")) - return@get - } - } get("/skin/{uuid}") { val uuid = call.parameters["uuid"] if (uuid == null || catchException { UUID.fromString(uuid) } == null) { diff --git a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt index ef2900f5..3e21d374 100644 --- a/WebsiteBackend/src/de/steamwar/routes/Schematic.kt +++ b/WebsiteBackend/src/de/steamwar/routes/Schematic.kt @@ -50,8 +50,8 @@ data class ResponseSchematicLong(val members: List, val path: Stri } @Serializable -data class ResponseSchematicList(val breadcrumbs: List, val schematics: List, val players: Map) { - constructor(schematics: List, breadcrumbs: List) : this(breadcrumbs, schematics, schematics.map { it.owner }.distinct().map { ResponseUser.get(it) }.associateBy { it.id }) +data class ResponseSchematicList(val breadcrumbs: List, val schematics: List, val players: Map) { + constructor(schematics: List, breadcrumbs: List) : this(breadcrumbs, schematics, schematics.map { it.owner }.distinct().map { ResponseUser.get(it) }.associateBy { it.uuid }) } @Serializable @@ -132,7 +132,7 @@ fun Route.configureSchematic() { } route("/schem") { install(SWPermissionCheck) - get { + /*get { val user = call.principal()!!.user call.respond(ResponseSchematicList(SchematicNode.list(user, null).filter { it.name != "//copy" }.sortedWith { o1, o2 -> if (o1.isDir || o2.isDir) { @@ -141,7 +141,7 @@ fun Route.configureSchematic() { o1.name.compareTo(o2.name) } }.map { ResponseSchematic(it) }, listOf())) - } + }*/ post { val file = call.receive() @@ -166,7 +166,7 @@ fun Route.configureSchematic() { call.respond(ResponseSchematic(node)) } - + /* route("/{id}") { get { val user = call.principal()!!.user @@ -224,6 +224,6 @@ fun Route.configureSchematic() { } }.map { ResponseSchematic(it) }, parent.generateBreadcrumbsMap(user).map { ResponseBreadcrumb(it.key, it.value) })) } - } + }*/ } } diff --git a/steamwarci.yml b/steamwarci.yml index 8fbd084b..19b1643c 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -29,4 +29,4 @@ artifacts: "/binarys/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar" "/binarys/deployarena.py": "VelocityCore/deployarena.py" - "/binarys/website-api.jar": "WebsiteBackend/build/libs/api.jar" \ No newline at end of file + "/binarys/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar" \ No newline at end of file