summaryrefslogtreecommitdiff
path: root/sw-server
diff options
context:
space:
mode:
Diffstat (limited to 'sw-server')
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/Converters.kt7
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt5
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/AnonymousUsersHandshakeHandler.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/TopicSubscriptionInterceptor.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt3
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt14
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt3
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/LobbyControllerTest.kt6
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/lobby/LobbyTest.kt7
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt6
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt6
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt2
17 files changed, 43 insertions, 30 deletions
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/Converters.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/Converters.kt
index 3958260c..aef121ee 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/Converters.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/Converters.kt
@@ -6,8 +6,11 @@ import org.springframework.validation.ObjectError
fun ObjectError.toDTO() = (this as? FieldError)?.fieldError() ?: objectError()
-fun FieldError.fieldError(): ValidationErrorDTO =
- ValidationErrorDTO("$objectName.$field", "Invalid value for field '$field': $defaultMessage", rejectedValue?.toString())
+fun FieldError.fieldError(): ValidationErrorDTO = ValidationErrorDTO(
+ path = "$objectName.$field",
+ message = "Invalid value for field '$field': $defaultMessage",
+ rejectedValue = rejectedValue?.toString(),
+)
fun ObjectError.objectError(): ValidationErrorDTO =
ValidationErrorDTO(objectName, "Invalid value for object '$objectName': $defaultMessage")
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
index 61bcad89..12f346a2 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt
@@ -14,8 +14,7 @@ fun Lobby.toDTO(): LobbyDTO = LobbyDTO(
allWonders = allWonders,
state = state,
hasEnoughPlayers = hasEnoughPlayers(),
- maxPlayersReached = maxPlayersReached()
+ maxPlayersReached = maxPlayersReached(),
)
-private fun Player.toDTO(wonder: AssignedWonder) =
- PlayerDTO(username, displayName, icon, wonder, isGameOwner, isReady)
+private fun Player.toDTO(wonder: AssignedWonder) = PlayerDTO(username, displayName, icon, wonder, isGameOwner, isReady)
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/AnonymousUsersHandshakeHandler.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/AnonymousUsersHandshakeHandler.kt
index 56b3400f..06b46d17 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/AnonymousUsersHandshakeHandler.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/AnonymousUsersHandshakeHandler.kt
@@ -16,7 +16,7 @@ internal class AnonymousUsersHandshakeHandler : DefaultHandshakeHandler() {
override fun determineUser(
request: ServerHttpRequest,
wsHandler: WebSocketHandler,
- attributes: Map<String, Any>
+ attributes: Map<String, Any>,
): Principal? {
var p = super.determineUser(request, wsHandler, attributes)
if (p == null) {
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/TopicSubscriptionInterceptor.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/TopicSubscriptionInterceptor.kt
index d8181f8a..d32fa0a6 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/TopicSubscriptionInterceptor.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/TopicSubscriptionInterceptor.kt
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Component
@Component
class TopicSubscriptionInterceptor(
- private val destinationAccessValidator: DestinationAccessValidator
+ private val destinationAccessValidator: DestinationAccessValidator,
) : ChannelInterceptor {
override fun preSend(message: Message<*>, channel: MessageChannel): Message<*>? {
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt
index 1911f5b9..aad1c2ce 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/config/WebSocketConfig.kt
@@ -14,7 +14,7 @@ import org.springframework.web.socket.server.support.DefaultHandshakeHandler
@Configuration
@EnableWebSocketMessageBroker
class WebSocketConfig(
- private val topicSubscriptionInterceptor: TopicSubscriptionInterceptor
+ private val topicSubscriptionInterceptor: TopicSubscriptionInterceptor,
) : WebSocketMessageBrokerConfigurer {
override fun configureMessageBroker(config: MessageBrokerRegistry) {
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt
index c3dcf87c..3236a6c9 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameBrowserController.kt
@@ -27,7 +27,7 @@ class GameBrowserController(
private val lobbyController: LobbyController,
private val lobbyRepository: LobbyRepository,
private val playerRepository: PlayerRepository,
- private val template: SimpMessagingTemplate
+ private val template: SimpMessagingTemplate,
) {
/**
* Gets the created or updated games. The list of existing games is received on this topic at once upon
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
index c15f7a68..f3d8aaef 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/GameController.kt
@@ -20,7 +20,7 @@ import java.security.Principal
@Controller
class GameController(
private val template: SimpMessagingTemplate,
- private val playerRepository: PlayerRepository
+ private val playerRepository: PlayerRepository,
) {
private val Principal.player
get() = playerRepository.find(name)
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt
index 4a9fe0a2..c34756a8 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt
@@ -18,7 +18,7 @@ import java.security.Principal
@Api(name = "Home")
@Controller
class HomeController(
- private val playerRepository: PlayerRepository
+ private val playerRepository: PlayerRepository,
) {
/**
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
index 1c8cf17e..64e75a8f 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt
@@ -31,8 +31,7 @@ class LobbyController(
private val lobbyRepository: LobbyRepository,
private val playerRepository: PlayerRepository,
private val template: SimpMessagingTemplate,
- @Value("\${server.port}")
- private val serverPort: String
+ @Value("\${server.port}") private val serverPort: String,
) {
private val Principal.player: Player
get() = playerRepository.find(name)
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
index ed8add56..6ebe39c1 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Lobby.kt
@@ -12,7 +12,7 @@ class Lobby(
val id: Long,
val name: String,
var owner: Player,
- private val gameDefinition: GameDefinition
+ private val gameDefinition: GameDefinition,
) {
private val players: MutableList<Player> = ArrayList(gameDefinition.maxPlayers)
@@ -49,8 +49,7 @@ class Lobby(
assignedWonders.add(pickRandomWonder())
}
- private fun pickRandomWonder(): AssignedWonder =
- allWonders.filter { !it.isAssigned() }.random().withRandomSide()
+ private fun pickRandomWonder(): AssignedWonder = allWonders.filter { !it.isAssigned() }.random().withRandomSide()
private fun PreGameWonder.isAssigned() = name in assignedWonders.map { it.name }
@@ -122,11 +121,9 @@ class Lobby(
state = State.FINISHED
}
- internal class GameAlreadyStartedException(name: String) :
- IllegalStateException("Game '$name' has already started")
+ internal class GameAlreadyStartedException(name: String) : IllegalStateException("Game '$name' has already started")
- internal class PlayerOverflowException(max: Int) :
- IllegalStateException("Maximum $max players allowed")
+ internal class PlayerOverflowException(max: Int) : IllegalStateException("Maximum $max players allowed")
internal class PlayerUnderflowException(min: Int) :
IllegalStateException("Minimum $min players required to start a game")
@@ -134,8 +131,7 @@ class Lobby(
internal class PlayerNameAlreadyUsedException(displayName: String, gameName: String) :
IllegalArgumentException("Name '$displayName' is already used by a player in game '$gameName'")
- internal class UnknownPlayerException(username: String) :
- IllegalArgumentException("Unknown player '$username'")
+ internal class UnknownPlayerException(username: String) : IllegalArgumentException("Unknown player '$username'")
internal class PlayerListMismatchException(usernames: List<String>) :
IllegalArgumentException("Newly ordered usernames $usernames don't match the current player list")
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt
index 95b37643..94ae9742 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt
@@ -7,7 +7,7 @@ import org.luxons.sevenwonders.server.ApiMisuseException
class Player(
val username: String,
var displayName: String,
- var icon: Icon? = null
+ var icon: Icon? = null,
) {
var index: Int = -1
diff --git a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt
index e76bdaea..c5dd6215 100644
--- a/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt
+++ b/sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt
@@ -25,5 +25,4 @@ class PlayerRepository {
fun remove(username: String): Player = players.remove(username) ?: throw PlayerNotFoundException(username)
}
-internal class PlayerNotFoundException(username: String) :
- ApiMisuseException("Player '$username' doesn't exist")
+internal class PlayerNotFoundException(username: String) : ApiMisuseException("Player '$username' doesn't exist")
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/LobbyControllerTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/LobbyControllerTest.kt
index 2f6e2cdb..73a24ef0 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/LobbyControllerTest.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/LobbyControllerTest.kt
@@ -15,7 +15,11 @@ import org.luxons.sevenwonders.server.repositories.PlayerNotFoundException
import org.luxons.sevenwonders.server.repositories.PlayerRepository
import org.luxons.sevenwonders.server.test.mockSimpMessagingTemplate
import java.util.HashMap
-import kotlin.test.*
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertFalse
+import kotlin.test.assertSame
+import kotlin.test.assertTrue
class LobbyControllerTest {
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/lobby/LobbyTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/lobby/LobbyTest.kt
index 1742dc93..4125810f 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/lobby/LobbyTest.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/lobby/LobbyTest.kt
@@ -17,7 +17,12 @@ import org.luxons.sevenwonders.server.lobby.Lobby.PlayerNameAlreadyUsedException
import org.luxons.sevenwonders.server.lobby.Lobby.PlayerOverflowException
import org.luxons.sevenwonders.server.lobby.Lobby.PlayerUnderflowException
import org.luxons.sevenwonders.server.lobby.Lobby.UnknownPlayerException
-import kotlin.test.*
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertFalse
+import kotlin.test.assertNotNull
+import kotlin.test.assertSame
+import kotlin.test.assertTrue
@RunWith(Theories::class)
class LobbyTest {
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt
index 898a56fc..c59dc49f 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/LobbyRepositoryTest.kt
@@ -3,7 +3,11 @@ package org.luxons.sevenwonders.server.repositories
import org.junit.Before
import org.junit.Test
import org.luxons.sevenwonders.server.lobby.Player
-import kotlin.test.*
+import kotlin.test.assertFailsWith
+import kotlin.test.assertNotNull
+import kotlin.test.assertSame
+import kotlin.test.assertTrue
+import kotlin.test.fail
class LobbyRepositoryTest {
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt
index b5c849a7..fc016903 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepositoryTest.kt
@@ -2,7 +2,11 @@ package org.luxons.sevenwonders.server.repositories
import org.junit.Before
import org.junit.Test
-import kotlin.test.*
+import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
+import kotlin.test.assertFalse
+import kotlin.test.assertSame
+import kotlin.test.assertTrue
class PlayerRepositoryTest {
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
index 194fb8f1..efd40a6d 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/test/TestUtils.kt
@@ -12,7 +12,7 @@ fun mockSimpMessagingTemplate(): SimpMessagingTemplate = SimpMessagingTemplate(
object : MessageChannel {
override fun send(message: Message<*>): Boolean = true
override fun send(message: Message<*>, timeout: Long): Boolean = true
- }
+ },
)
fun runAsyncTest(timeoutMillis: Long = 10000, block: suspend CoroutineScope.() -> Unit) = runBlocking {
bgstack15