Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
52 lines
1.8 KiB
package org.openrs2.archive.web
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper
|
|
import io.ktor.application.call
|
|
import io.ktor.application.install
|
|
import io.ktor.features.ContentNegotiation
|
|
import io.ktor.http.ContentType
|
|
import io.ktor.jackson.JacksonConverter
|
|
import io.ktor.routing.get
|
|
import io.ktor.routing.routing
|
|
import io.ktor.server.engine.embeddedServer
|
|
import io.ktor.server.netty.Netty
|
|
import io.ktor.thymeleaf.Thymeleaf
|
|
import org.openrs2.json.Json
|
|
import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect
|
|
import org.thymeleaf.templatemode.TemplateMode
|
|
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
|
|
import javax.inject.Inject
|
|
import javax.inject.Singleton
|
|
|
|
@Singleton
|
|
public class WebServer @Inject constructor(
|
|
private val cachesController: CachesController,
|
|
private val keysController: KeysController,
|
|
@Json private val mapper: ObjectMapper
|
|
) {
|
|
public fun start() {
|
|
embeddedServer(Netty, port = 8000) {
|
|
install(ContentNegotiation) {
|
|
register(ContentType.Application.Json, JacksonConverter(mapper))
|
|
}
|
|
|
|
install(Thymeleaf) {
|
|
addDialect(Java8TimeDialect())
|
|
|
|
setTemplateResolver(ClassLoaderTemplateResolver().apply {
|
|
prefix = "/org/openrs2/archive/templates/"
|
|
templateMode = TemplateMode.HTML
|
|
})
|
|
}
|
|
|
|
routing {
|
|
get("/caches") { cachesController.index(call) }
|
|
get("/caches/{id}.zip") { cachesController.export(call) }
|
|
get("/caches/{id}.json") { cachesController.exportKeys(call) }
|
|
|
|
// ideally we'd use POST /keys here, but I want to be compatible with the RuneLite/OpenOSRS API
|
|
get("/keys/submit") { keysController.create(call) }
|
|
}
|
|
}.start(wait = true)
|
|
}
|
|
}
|
|
|