From 6847d580b92b40109ea5732e2dd6bcb60b513333 Mon Sep 17 00:00:00 2001 From: Janis Date: Mon, 1 Dec 2025 19:49:04 +0100 Subject: [PATCH] feat(api): BAC-10 Websockets - Kick Users --- knockoutwhist | 2 +- knockoutwhistweb/app/model/sessions/UserSession.scala | 9 +++++++++ knockoutwhistweb/app/views/lobby/lobby.scala.html | 2 +- knockoutwhistweb/public/javascripts/events.js | 2 +- knockoutwhistweb/public/javascripts/interact.js | 4 +++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/knockoutwhist b/knockoutwhist index d833932..ef7397f 160000 --- a/knockoutwhist +++ b/knockoutwhist @@ -1 +1 @@ -Subproject commit d833932f1652554db5a49d77033d3016051d23f9 +Subproject commit ef7397f7f1312e0d87ab7ccaab94159d7f7e9773 diff --git a/knockoutwhistweb/app/model/sessions/UserSession.scala b/knockoutwhistweb/app/model/sessions/UserSession.scala index 0c1608f..64776fc 100644 --- a/knockoutwhistweb/app/model/sessions/UserSession.scala +++ b/knockoutwhistweb/app/model/sessions/UserSession.scala @@ -64,6 +64,15 @@ class UserSession(val user: User, val host: Boolean, val gameLobby: GameLobby) e case None => println("Card Index not found or is not a number.") } + case "KickPlayer" => + val maybePlayerId: Option[String] = (data \ "playerId").asOpt[String] + maybePlayerId match { + case Some(id) => + val playerUUID = UUID.fromString(id) + gameLobby.leaveGame(playerUUID, true) + case None => + println("Player ID not found or is not a valid UUID.") + } } } lock.unlock() diff --git a/knockoutwhistweb/app/views/lobby/lobby.scala.html b/knockoutwhistweb/app/views/lobby/lobby.scala.html index 32b7fbc..dd7413b 100644 --- a/knockoutwhistweb/app/views/lobby/lobby.scala.html +++ b/knockoutwhistweb/app/views/lobby/lobby.scala.html @@ -60,7 +60,7 @@ Remove } else {
@playersession.name
-
+
Remove
}
diff --git a/knockoutwhistweb/public/javascripts/events.js b/knockoutwhistweb/public/javascripts/events.js index b796bf8..09af240 100644 --- a/knockoutwhistweb/public/javascripts/events.js +++ b/knockoutwhistweb/public/javascripts/events.js @@ -227,7 +227,7 @@ function receiveLobbyUpdateEvent(eventData) { const inner = user.self ? `
${user.name} (You)
Remove` : `
${user.name}
-
Remove
` +
Remove
` newHtml += `
diff --git a/knockoutwhistweb/public/javascripts/interact.js b/knockoutwhistweb/public/javascripts/interact.js index 16eb2b6..f035832 100644 --- a/knockoutwhistweb/public/javascripts/interact.js +++ b/knockoutwhistweb/public/javascripts/interact.js @@ -73,5 +73,7 @@ function handleTrumpSelection(object) { } function handleKickPlayer(playerId) { - // TODO needs implementation + sendEvent("KickPlayer", { + playerId: playerId + }) }