summaryrefslogtreecommitdiff
path: root/sw-server/src
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-15 03:05:09 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-15 03:29:28 +0200
commit07295f3e96a16efc517e5a5e6ae0af4e3d5c5035 (patch)
tree3d35ea3d249d6f1205700d73996f9d93b6582162 /sw-server/src
parentSend score at end of game (diff)
downloadseven-wonders-07295f3e96a16efc517e5a5e6ae0af4e3d5c5035.tar.gz
seven-wonders-07295f3e96a16efc517e5a5e6ae0af4e3d5c5035.tar.bz2
seven-wonders-07295f3e96a16efc517e5a5e6ae0af4e3d5c5035.zip
Add dumb bots feature
Diffstat (limited to 'sw-server/src')
-rw-r--r--sw-server/src/main/kotlin/org/luxons/sevenwonders/server/controllers/LobbyController.kt16
1 files changed, 16 insertions, 0 deletions
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 403a4696..cdb636fb 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
@@ -1,6 +1,8 @@
package org.luxons.sevenwonders.server.controllers
import org.hildan.livedoc.core.annotations.Api
+import org.luxons.sevenwonders.bot.SevenWondersBot
+import org.luxons.sevenwonders.model.api.actions.AddBotAction
import org.luxons.sevenwonders.model.api.actions.ReorderPlayersAction
import org.luxons.sevenwonders.model.api.actions.UpdateSettingsAction
import org.luxons.sevenwonders.model.hideHandsAndWaitForReadiness
@@ -16,6 +18,8 @@ import org.springframework.messaging.simp.SimpMessagingTemplate
import org.springframework.stereotype.Controller
import org.springframework.validation.annotation.Validated
import java.security.Principal
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.launch
/**
* Handles actions in the game's lobby. The lobby is the place where players gather before a game.
@@ -78,6 +82,18 @@ class LobbyController @Autowired constructor(
sendLobbyUpdateToPlayers(lobby)
}
+ @MessageMapping("/lobby/addBot")
+ fun addBot(@Validated action: AddBotAction, principal: Principal) {
+ val lobby = principal.player.ownedLobby
+ val bot = SevenWondersBot(action.botDisplayName)
+ GlobalScope.launch {
+ bot.play("localhost:8000", lobby.id)
+ }
+
+ logger.info("Added bot {} to game '{}'", action.botDisplayName, lobby.name)
+ sendLobbyUpdateToPlayers(lobby)
+ }
+
internal fun sendLobbyUpdateToPlayers(lobby: Lobby) {
lobby.getPlayers().forEach {
template.convertAndSendToUser(it.username, "/queue/lobby/updated", lobby.toDTO())
bgstack15