Basic structure of Dropbox replacement self-serving
This commit is contained in:
parent
07889130b4
commit
1c04ba50cb
1 changed files with 59 additions and 0 deletions
|
@ -10,6 +10,16 @@ import com.badlogic.gdx.graphics.Texture
|
|||
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||
import com.unciv.UncivGame
|
||||
import com.unciv.models.translations.tr
|
||||
import io.ktor.application.call
|
||||
import io.ktor.http.HttpStatusCode
|
||||
import io.ktor.request.receiveText
|
||||
import io.ktor.response.respond
|
||||
import io.ktor.response.respondText
|
||||
import io.ktor.routing.get
|
||||
import io.ktor.routing.post
|
||||
import io.ktor.routing.routing
|
||||
import io.ktor.server.engine.embeddedServer
|
||||
import io.ktor.server.netty.Netty
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.concurrent.timer
|
||||
|
@ -39,6 +49,55 @@ internal object DesktopLauncher {
|
|||
LwjglApplication(game, config)
|
||||
}
|
||||
|
||||
private fun startMultiplayerServer() {
|
||||
// val games = HashMap<String, GameSetupInfo>()
|
||||
val files = HashMap<String, String>()
|
||||
embeddedServer(Netty, 8080) {
|
||||
routing {
|
||||
get("/files/getFile/{fileName}") {
|
||||
val fileName = call.parameters["fileName"]
|
||||
if (!files.containsKey(fileName)) call.respond(HttpStatusCode.NotFound,
|
||||
"Game with the name $fileName does not exist")
|
||||
else call.respondText(files[fileName]!!)
|
||||
}
|
||||
|
||||
post("/files/{fileName}") {
|
||||
val fileName = call.parameters["fileName"]!!
|
||||
val body = call.receiveText()
|
||||
files[fileName] = body
|
||||
}
|
||||
//
|
||||
// get("/getGame/{gameName}") {
|
||||
// val gameName = call.parameters["gameName"]
|
||||
// if(!games.containsKey(gameName)) call.respond(HttpStatusCode.NotFound,
|
||||
// "Game with the name $gameName does not exist")
|
||||
// else call.respondText(Json().toJson(games[gameName]))
|
||||
// }
|
||||
// get("/getGameNames"){
|
||||
// call.respondText(Json().toJson(games.keys.toList()))
|
||||
// }
|
||||
// post("/addNewGame/{gameName}") {
|
||||
// val gameName = call.parameters["gameName"]!!
|
||||
// if (games.containsKey(gameName)) {
|
||||
// call.respond(HttpStatusCode.NotAcceptable, "A game with the name $gameName already exists")
|
||||
// return@post
|
||||
// }
|
||||
// val body = call.receiveText()
|
||||
// val newGameInfo:GameSetupInfo
|
||||
// try{
|
||||
// newGameInfo = Json().apply { ignoreUnknownFields }.fromJson(GameSetupInfo::class.java, body)
|
||||
// }
|
||||
// catch (ex:Exception){
|
||||
// call.respond(HttpStatusCode.NotAcceptable, "Could not deserialize json")
|
||||
// return@post
|
||||
// }
|
||||
// games[gameName] = newGameInfo
|
||||
// }
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
|
||||
private fun packImages() {
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
|
|
Loading…
Reference in a new issue