This commit is contained in:
2024-08-18 13:03:24 +02:00
parent f69f7ae294
commit 6d648b9a71
11 changed files with 61 additions and 118 deletions
@@ -373,6 +373,6 @@ public class SteamwarUser {
}
public static List<SteamwarUser> getAll() {
return null;
return getAll.listSelect();
}
}
@@ -65,7 +65,7 @@ public enum UserPerm {
private static final Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
private static final SelectStatement<UserPermTable> 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<UserPerm> getPerms(int user) {
-9
View File
@@ -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 {
@@ -44,7 +44,6 @@ data class Config(val giteaToken: String)
val config = Json.decodeFromStream<Config>(File("config.json").inputStream())
fun main() {
SchematicType.Normal.name().length
Thread {
while (true) {
Thread.sleep(1000 * 10)
@@ -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 <https://www.gnu.org/licenses/>.
*/
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!!)
}
}
@@ -91,7 +91,7 @@ suspend fun getCachedSkin(uuid: String): Pair<File, Boolean> {
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<File, Boolean> {
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
@@ -99,6 +99,7 @@ Message: ${cause.message}
}
"""
SWException.log(msg, cause.stackTraceToString())
call.response.headers.append("X-Caught", "1")
}
}
@@ -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)
}
+46 -40
View File
@@ -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<String>) {
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<String>) {
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<SchematicType>()
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<SchematicType>()
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) {
@@ -50,8 +50,8 @@ data class ResponseSchematicLong(val members: List<ResponseUser>, val path: Stri
}
@Serializable
data class ResponseSchematicList(val breadcrumbs: List<ResponseBreadcrumb>, val schematics: List<ResponseSchematic>, val players: Map<Int, ResponseUser>) {
constructor(schematics: List<ResponseSchematic>, breadcrumbs: List<ResponseBreadcrumb>) : this(breadcrumbs, schematics, schematics.map { it.owner }.distinct().map { ResponseUser.get(it) }.associateBy { it.id })
data class ResponseSchematicList(val breadcrumbs: List<ResponseBreadcrumb>, val schematics: List<ResponseSchematic>, val players: Map<String, ResponseUser>) {
constructor(schematics: List<ResponseSchematic>, breadcrumbs: List<ResponseBreadcrumb>) : 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<SWAuthPrincipal>()!!.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<UploadSchematic>()
@@ -166,7 +166,7 @@ fun Route.configureSchematic() {
call.respond(ResponseSchematic(node))
}
/*
route("/{id}") {
get {
val user = call.principal<SWAuthPrincipal>()!!.user
@@ -224,6 +224,6 @@ fun Route.configureSchematic() {
}
}.map { ResponseSchematic(it) }, parent.generateBreadcrumbsMap(user).map { ResponseBreadcrumb(it.key, it.value) }))
}
}
}*/
}
}
+1 -1
View File
@@ -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"
"/binarys/website-api.jar": "WebsiteBackend/build/libs/WebsiteBackend-all.jar"