forked from SteamWar/SteamWar
Fixes
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user