summaryrefslogtreecommitdiff
path: root/sw-server/src/main
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/main
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/main')
-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
4 files changed, 10 insertions, 6 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
}
bgstack15