-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
795b004
commit 89f4e34
Showing
11 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package game | ||
|
||
enum class GameMode { | ||
Entropy, | ||
Vectropy, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package game | ||
|
||
data class GameSettings( | ||
val mode: GameMode, | ||
val jokerQuantity: Int, | ||
val jokerValue: Int, | ||
val includeMoons: Boolean, | ||
val includeStars: Boolean, | ||
val negativeJacks: Boolean, | ||
val cardReveal: Boolean, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package http | ||
|
||
object CustomHeader { | ||
const val SESSION_ID = "session-id" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package http.dto | ||
|
||
data class LobbyResponse(val rooms: List<RoomSummary>, val users: List<OnlineUser>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package http.dto | ||
|
||
data class OnlineUser(val name: String) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package http.dto | ||
|
||
import game.GameSettings | ||
|
||
data class RoomSummary( | ||
val name: String, | ||
val gameSettings: GameSettings, | ||
val capacity: Int, | ||
val players: Int, | ||
val observers: Int, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package routes | ||
|
||
import auth.Session | ||
import http.CustomHeader | ||
import http.INVALID_SESSION | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.request.header | ||
import java.util.UUID | ||
import util.ServerGlobals | ||
|
||
suspend fun requiresSession(call: ApplicationCall, fn: suspend (session: Session) -> Unit) { | ||
val sessionIdStr = | ||
call.request.header(CustomHeader.SESSION_ID) | ||
?: throw ClientException( | ||
HttpStatusCode.Unauthorized, | ||
INVALID_SESSION, | ||
"Missing session id", | ||
) | ||
|
||
try { | ||
UUID.fromString(sessionIdStr) | ||
} catch (e: IllegalArgumentException) { | ||
throw ClientException( | ||
HttpStatusCode.BadRequest, | ||
INVALID_SESSION, | ||
"Session ID was not a valid UUID", | ||
e, | ||
) | ||
} | ||
|
||
val session = | ||
ServerGlobals.sessionStore.find(sessionIdStr) | ||
?: throw ClientException( | ||
HttpStatusCode.Unauthorized, | ||
INVALID_SESSION, | ||
"No session found for ID $sessionIdStr", | ||
) | ||
|
||
fn(session) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package routes.lobby | ||
|
||
import http.Routes | ||
import io.ktor.server.application.Application | ||
import io.ktor.server.application.ApplicationCall | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respond | ||
import io.ktor.server.routing.get | ||
import io.ktor.server.routing.routing | ||
import routes.requiresSession | ||
|
||
object LobbyController { | ||
private val lobbyService = LobbyService() | ||
|
||
fun installRoutes(application: Application) { | ||
application.routing { get(Routes.LOBBY) { doGetLobby(call) } } | ||
} | ||
|
||
private suspend fun doGetLobby(call: ApplicationCall) = | ||
requiresSession(call) { | ||
val response = lobbyService.getLobby() | ||
call.respond(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package routes.lobby | ||
|
||
import http.dto.LobbyResponse | ||
|
||
class LobbyService { | ||
fun getLobby(): LobbyResponse { | ||
return LobbyResponse(emptyList(), emptyList()) | ||
} | ||
} |