forked from SteamWar/SteamWar
Fixes
This commit is contained in:
@@ -373,6 +373,6 @@ public class SteamwarUser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<SteamwarUser> getAll() {
|
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 Table<UserPermTable> table = new Table<>(UserPermTable.class, "UserPerm");
|
||||||
private static final SelectStatement<UserPermTable> getPerms = table.selectFields("user");
|
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);
|
private static final Statement removePerm = table.delete(Table.PRIMARY);
|
||||||
|
|
||||||
public static Set<UserPerm> getPerms(int user) {
|
public static Set<UserPerm> getPerms(int user) {
|
||||||
|
|||||||
@@ -26,15 +26,6 @@ plugins {
|
|||||||
|
|
||||||
application {
|
application {
|
||||||
mainClass.set("de.steamwar.ApplicationKt")
|
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 {
|
tasks.build {
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ data class Config(val giteaToken: String)
|
|||||||
val config = Json.decodeFromStream<Config>(File("config.json").inputStream())
|
val config = Json.decodeFromStream<Config>(File("config.json").inputStream())
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
SchematicType.Normal.name().length
|
|
||||||
Thread {
|
Thread {
|
||||||
while (true) {
|
while (true) {
|
||||||
Thread.sleep(1000 * 10)
|
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")
|
val file = File(kCacheFolderFile, "$uuid.webp")
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
if (CacheConfig.isOutdated(uuid)) {
|
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())
|
skin.bodyAsChannel().copyTo(file.outputStream())
|
||||||
|
|
||||||
CacheConfig.update(uuid)
|
CacheConfig.update(uuid)
|
||||||
@@ -103,7 +103,7 @@ suspend fun getCachedSkin(uuid: String): Pair<File, Boolean> {
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
file.createNewFile()
|
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())
|
skin.bodyAsChannel().copyTo(file.outputStream())
|
||||||
CacheConfig.update(uuid)
|
CacheConfig.update(uuid)
|
||||||
return file to false
|
return file to false
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ Message: ${cause.message}
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
SWException.log(msg, cause.stackTraceToString())
|
||||||
call.response.headers.append("X-Caught", "1")
|
call.response.headers.append("X-Caught", "1")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,9 +19,11 @@
|
|||||||
|
|
||||||
package de.steamwar.plugins
|
package de.steamwar.plugins
|
||||||
|
|
||||||
|
import de.steamwar.routes.catchException
|
||||||
import de.steamwar.sql.SteamwarUser
|
import de.steamwar.sql.SteamwarUser
|
||||||
import io.ktor.server.request.*
|
import io.ktor.server.request.*
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
fun ApplicationRequest.getUser(key: String = "id"): SteamwarUser? {
|
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)
|
||||||
}
|
}
|
||||||
@@ -44,10 +44,10 @@ import java.util.UUID
|
|||||||
data class ResponseSchematicType(val name: String, val db: String)
|
data class ResponseSchematicType(val name: String, val db: String)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ResponseUser(val id: Int, val name: String, val uuid: String, val prefix: String, val perms: List<String>) {
|
data class ResponseUser(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 }) {
|
constructor(user: SteamwarUser) : this(user.userName, user.uuid.toString(), user.prefix().chatPrefix, user.perms().map { it.name }) {
|
||||||
synchronized(cache) {
|
synchronized(cache) {
|
||||||
cache[id] = this
|
cache[user.id] = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,32 +73,51 @@ fun Route.configureDataRoutes() {
|
|||||||
get {
|
get {
|
||||||
call.respondText("Hello World!")
|
call.respondText("Hello World!")
|
||||||
}
|
}
|
||||||
get("/schematicTypes") {
|
route("/admin") {
|
||||||
val types = mutableListOf<SchematicType>()
|
install(SWPermissionCheck) {
|
||||||
loadSchematicTypes(types, mutableMapOf())
|
mustAuth = true
|
||||||
call.respond(types.filter { !it.check() }.map { ResponseSchematicType(it.name(), it.toDB()) })
|
permission = UserPerm.PREFIX_MODERATOR
|
||||||
}
|
|
||||||
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")
|
get("/users") {
|
||||||
if (!file.exists()) {
|
call.respond(SteamwarUser.getAll().map { ResponseUser(it) })
|
||||||
call.respond(HttpStatusCode.NotFound, ResponseError("Gamemode not found"))
|
}
|
||||||
return@get
|
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") {
|
get("/team") {
|
||||||
call.respond(
|
call.respond(
|
||||||
@@ -108,19 +127,6 @@ fun Route.configureDataRoutes() {
|
|||||||
.mapValues { it.value.map { ResponseUser(it) } }
|
.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}") {
|
get("/skin/{uuid}") {
|
||||||
val uuid = call.parameters["uuid"]
|
val uuid = call.parameters["uuid"]
|
||||||
if (uuid == null || catchException { UUID.fromString(uuid) } == null) {
|
if (uuid == null || catchException { UUID.fromString(uuid) } == null) {
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ data class ResponseSchematicLong(val members: List<ResponseUser>, val path: Stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ResponseSchematicList(val breadcrumbs: List<ResponseBreadcrumb>, val schematics: List<ResponseSchematic>, val players: Map<Int, ResponseUser>) {
|
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.id })
|
constructor(schematics: List<ResponseSchematic>, breadcrumbs: List<ResponseBreadcrumb>) : this(breadcrumbs, schematics, schematics.map { it.owner }.distinct().map { ResponseUser.get(it) }.associateBy { it.uuid })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -132,7 +132,7 @@ fun Route.configureSchematic() {
|
|||||||
}
|
}
|
||||||
route("/schem") {
|
route("/schem") {
|
||||||
install(SWPermissionCheck)
|
install(SWPermissionCheck)
|
||||||
get {
|
/*get {
|
||||||
val user = call.principal<SWAuthPrincipal>()!!.user
|
val user = call.principal<SWAuthPrincipal>()!!.user
|
||||||
call.respond(ResponseSchematicList(SchematicNode.list(user, null).filter { it.name != "//copy" }.sortedWith { o1, o2 ->
|
call.respond(ResponseSchematicList(SchematicNode.list(user, null).filter { it.name != "//copy" }.sortedWith { o1, o2 ->
|
||||||
if (o1.isDir || o2.isDir) {
|
if (o1.isDir || o2.isDir) {
|
||||||
@@ -141,7 +141,7 @@ fun Route.configureSchematic() {
|
|||||||
o1.name.compareTo(o2.name)
|
o1.name.compareTo(o2.name)
|
||||||
}
|
}
|
||||||
}.map { ResponseSchematic(it) }, listOf()))
|
}.map { ResponseSchematic(it) }, listOf()))
|
||||||
}
|
}*/
|
||||||
|
|
||||||
post {
|
post {
|
||||||
val file = call.receive<UploadSchematic>()
|
val file = call.receive<UploadSchematic>()
|
||||||
@@ -166,7 +166,7 @@ fun Route.configureSchematic() {
|
|||||||
|
|
||||||
call.respond(ResponseSchematic(node))
|
call.respond(ResponseSchematic(node))
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
route("/{id}") {
|
route("/{id}") {
|
||||||
get {
|
get {
|
||||||
val user = call.principal<SWAuthPrincipal>()!!.user
|
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) }))
|
}.map { ResponseSchematic(it) }, parent.generateBreadcrumbsMap(user).map { ResponseBreadcrumb(it.key, it.value) }))
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -29,4 +29,4 @@ artifacts:
|
|||||||
"/binarys/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar"
|
"/binarys/VelocityCore.jar": "VelocityCore/build/libs/VelocityCore-all.jar"
|
||||||
"/binarys/deployarena.py": "VelocityCore/deployarena.py"
|
"/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"
|
||||||
Reference in New Issue
Block a user