2020-09-23 20:51:45 +00:00
|
|
|
package dev.araozu
|
|
|
|
|
|
|
|
import com.google.gson.Gson
|
|
|
|
import io.ktor.http.cio.websocket.*
|
|
|
|
import io.ktor.routing.*
|
|
|
|
import io.ktor.websocket.*
|
|
|
|
|
|
|
|
val gson = Gson()
|
|
|
|
|
2020-09-25 19:41:02 +00:00
|
|
|
data class DatosDescarte(val idJuego: String, val idUsuario: String, val carta: Int)
|
|
|
|
|
2020-09-23 20:51:45 +00:00
|
|
|
fun Routing.juegows() {
|
|
|
|
|
|
|
|
webSocket("/juego") {
|
|
|
|
|
|
|
|
for (frame in incoming) when (frame) {
|
|
|
|
is Frame.Text -> {
|
|
|
|
val sol = gson.fromJson(frame.readText(), Conexion::class.java)
|
|
|
|
when (sol.operacion) {
|
|
|
|
"conectar" -> {
|
|
|
|
val datos = gson.fromJson(sol.datos, ConexionNueva::class.java)
|
|
|
|
GestorJuegos.conectarASala(datos.idJuego, datos.idUsuario, this)
|
|
|
|
}
|
2020-09-25 19:41:02 +00:00
|
|
|
"descarte" -> {
|
|
|
|
val datos = gson.fromJson(sol.datos, DatosDescarte::class.java)
|
|
|
|
GestorJuegos.manejarDescarte(datos.idJuego, datos.idUsuario, datos.carta)
|
|
|
|
}
|
2020-09-23 20:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|