summaryrefslogtreecommitdiff
path: root/sw-server/src
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-21 13:46:30 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-21 13:58:28 +0200
commit4f3eec40a87c5e4f52fc89238642dd7a17650540 (patch)
treec910270b5477975100bfd82852d784409346f334 /sw-server/src
parentPrevent bots with already used names (diff)
downloadseven-wonders-4f3eec40a87c5e4f52fc89238642dd7a17650540.tar.gz
seven-wonders-4f3eec40a87c5e4f52fc89238642dd7a17650540.tar.bz2
seven-wonders-4f3eec40a87c5e4f52fc89238642dd7a17650540.zip
Allow custom player icons
Diffstat (limited to 'sw-server/src')
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/api/Converters.kt2
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/HomeController.kt4
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/lobby/Player.kt4
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/repositories/PlayerRepository.kt6
-rw-r--r--sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/HomeControllerTest.kt4
5 files changed, 13 insertions, 7 deletions
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 1386c855..6ef13b8e 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
@@ -15,4 +15,4 @@ fun Lobby.toDTO(): LobbyDTO = LobbyDTO(
maxPlayersReached = maxPlayersReached()
)
-fun Player.toDTO() = PlayerDTO(username, displayName, index, isGameOwner, isReady)
+fun Player.toDTO() = PlayerDTO(username, displayName, icon, index, isGameOwner, isReady)
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 c2619f8c..ff668fd9 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
@@ -34,10 +34,10 @@ class HomeController @Autowired constructor(
@SendToUser("/queue/nameChoice")
fun chooseName(@Validated action: ChooseNameAction, principal: Principal): ConnectedPlayer {
val username = principal.name
- val player = playerRepository.createOrUpdate(username, action.playerName)
+ val player = playerRepository.createOrUpdate(username, action.playerName, action.icon)
logger.info("Player '{}' chose the name '{}'", username, player.displayName)
- return ConnectedPlayer(username, player.displayName)
+ return ConnectedPlayer(username, player.displayName, player.icon)
}
companion object {
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 8ed7d048..95b37643 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
@@ -1,11 +1,13 @@
package org.luxons.sevenwonders.server.lobby
import org.luxons.sevenwonders.engine.Game
+import org.luxons.sevenwonders.model.api.actions.Icon
import org.luxons.sevenwonders.server.ApiMisuseException
class Player(
val username: String,
- var displayName: String
+ var displayName: String,
+ 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 b31d2cee..e76bdaea 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
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.server.repositories
+import org.luxons.sevenwonders.model.api.actions.Icon
import org.luxons.sevenwonders.server.ApiMisuseException
import org.luxons.sevenwonders.server.lobby.Player
import org.springframework.stereotype.Repository
@@ -12,9 +13,10 @@ class PlayerRepository {
operator fun contains(username: String): Boolean = players.containsKey(username)
- fun createOrUpdate(username: String, displayName: String): Player {
- val p = players.computeIfAbsent(username) { Player(username, displayName) }
+ fun createOrUpdate(username: String, displayName: String, icon: Icon? = null): Player {
+ val p = players.computeIfAbsent(username) { Player(username, displayName, icon) }
p.displayName = displayName
+ p.icon = icon
return p
}
diff --git a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/HomeControllerTest.kt b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/HomeControllerTest.kt
index 31b957e4..d7206490 100644
--- a/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/HomeControllerTest.kt
+++ b/sw-server/src/test/kotlin/org/luxons/sevenwonders/server/controllers/HomeControllerTest.kt
@@ -2,6 +2,7 @@ package org.luxons.sevenwonders.server.controllers
import org.junit.Test
import org.luxons.sevenwonders.model.api.actions.ChooseNameAction
+import org.luxons.sevenwonders.model.api.actions.Icon
import org.luxons.sevenwonders.server.repositories.PlayerRepository
import kotlin.test.assertEquals
@@ -12,12 +13,13 @@ class HomeControllerTest {
val playerRepository = PlayerRepository()
val homeController = HomeController(playerRepository)
- val action = ChooseNameAction("Test User")
+ val action = ChooseNameAction("Test User", Icon("person"))
val principal = TestPrincipal("testuser")
val player = homeController.chooseName(action, principal)
assertEquals("testuser", player.username)
assertEquals("Test User", player.displayName)
+ assertEquals("person", player.icon?.name)
}
}
bgstack15