Skip to content

Commit cd0324e

Browse files
committed
fix(server): set ScoreCauses when players did not join
1 parent 232bb38 commit cd0324e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

server/src/main/java/sc/server/gaming/GameRoom.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ public synchronized void step(boolean forced) {
381381

382382
/** Kick all players, destroy the game and remove it from the manager. */
383383
public void cancel() {
384+
playerSlots.forEach(slot -> { if(slot.isEmpty()) slot.getPlayer().setLeft(XStreamClient.DisconnectCause.NOT_CONNECTED); });
384385
// this will invoke onGameOver and thus stop everything else
385386
this.game.stop();
386387
}
@@ -409,9 +410,6 @@ protected void setStatus(GameStatus status) {
409410
/** Remove a player and stop the game. */
410411
public void removePlayer(Player player, XStreamClient.DisconnectCause cause) {
411412
logger.info("Removing {} from {}", player, this);
412-
// Mark all non-joined players as left to trigger a draw when noone joined
413-
// Might be superfluous through the check in "step", but keeping for safety
414-
playerSlots.forEach(slot -> slot.getPlayer().setLeft(slot.isEmpty() ? cause : null));
415413
player.setLeft(cause);
416414
if (!isOver())
417415
cancel();

server/src/test/java/sc/server/network/LobbyGameTest.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.kotest.assertions.timing.eventually
44
import io.kotest.assertions.until.Interval
55
import io.kotest.assertions.until.fibonacci
66
import io.kotest.assertions.withClue
7+
import io.kotest.core.datatest.forAll
78
import io.kotest.core.spec.style.WordSpec
89
import io.kotest.matchers.*
910
import io.kotest.matchers.collections.*
@@ -29,6 +30,8 @@ import sc.server.plugins.TestGame
2930
import sc.server.plugins.TestMove
3031
import sc.server.plugins.TestPlugin
3132
import sc.shared.GameResult
33+
import sc.shared.PlayerScore
34+
import sc.shared.ScoreCause
3235
import sc.shared.SlotDescriptor
3336
import kotlin.time.Duration
3437
import kotlin.time.ExperimentalTime
@@ -78,8 +81,10 @@ class LobbyGameTest: WordSpec({
7881
val roomListener = observeRoom(room.id)
7982
admin.control(room.id).step(true)
8083
val result = roomListener.waitForMessage(GameResult::class)
84+
playerHandlers[0].gameResult shouldBe result
8185
result.winner shouldBe Team.ONE
82-
playerHandlers[0].gameResult?.winner shouldBe Team.ONE
86+
result.isRegular shouldBe false
87+
result.scores.values.last().cause shouldBe ScoreCause.LEFT
8388
admin.closed shouldBe false
8489
}
8590
playerClients[0].stop()
@@ -103,6 +108,10 @@ class LobbyGameTest: WordSpec({
103108
val result = roomListener.waitForMessage(GameResult::class)
104109
withClue("No Winner") {
105110
result.winner shouldBe null
111+
result.isRegular shouldBe false
112+
forAll<PlayerScore>(result.scores.mapKeys { it.key.displayName }.toList()) {
113+
it.cause shouldBe ScoreCause.LEFT
114+
}
106115
}
107116
adminListener.waitForMessage(RemovedFromGame::class)
108117
roomListener.clearMessages() shouldBe 0

0 commit comments

Comments
 (0)