diff --git a/sdk/src/server-api/sc/protocol/requests/ControlTimeoutRequest.kt b/sdk/src/server-api/sc/protocol/requests/ControlTimeoutRequest.kt index af4e5defc..e4c172db9 100644 --- a/sdk/src/server-api/sc/protocol/requests/ControlTimeoutRequest.kt +++ b/sdk/src/server-api/sc/protocol/requests/ControlTimeoutRequest.kt @@ -4,6 +4,8 @@ import com.thoughtworks.xstream.annotations.XStreamAlias import com.thoughtworks.xstream.annotations.XStreamAsAttribute /** Used to change whether a player in a slot can time out. */ +// TODO this shouldn't need changing after a game was started +// instead, a game should be preparable without reservations @XStreamAlias("timeout") data class ControlTimeoutRequest( @XStreamAsAttribute diff --git a/server/src/sc/server/Lobby.kt b/server/src/sc/server/Lobby.kt index a722f0b8a..b99e48f0b 100644 --- a/server/src/sc/server/Lobby.kt +++ b/server/src/sc/server/Lobby.kt @@ -84,8 +84,10 @@ open class Lobby: GameRoomManager(), IClientListener, Closeable { } is ControlTimeoutRequest -> { val room = this.findRoom(packet.roomId) + room.ensureOpenSlots(packet.slot + 1) val slot = room.slots[packet.slot] - slot.role.player.canTimeout = packet.activate + slot.descriptor = slot.descriptor.copy(canTimeout = packet.activate) + slot.role?.player?.canTimeout = packet.activate } is ObservationRequest -> { val room = this.findRoom(packet.roomId) diff --git a/server/src/sc/server/gaming/GameRoom.java b/server/src/sc/server/gaming/GameRoom.java index 6888f2149..f743dc3e4 100644 --- a/server/src/sc/server/gaming/GameRoom.java +++ b/server/src/sc/server/gaming/GameRoom.java @@ -384,6 +384,23 @@ public List getSlots() { return Collections.unmodifiableList(this.playerSlots); } + public void ensureOpenSlots(int count) throws TooManyPlayersException { + if (count > getMaximumPlayerCount()) { + throw new TooManyPlayersException(); + } + while (playerSlots.size() < count) { + this.playerSlots.add(new PlayerSlot(this)); + } + } + + /** Set descriptors of PlayerSlots. */ + public void openSlots(SlotDescriptor[] descriptors) throws TooManyPlayersException { + ensureOpenSlots(descriptors.length); + for (int i = 0; i < descriptors.length; i++) { + this.playerSlots.get(i).setDescriptor(descriptors[i]); + } + } + /** * Threadsafe method to reserve all PlayerSlots. * @@ -538,20 +555,6 @@ public void onPaused(Player nextPlayer) { observerBroadcast(new RoomPacket(getId(), new GamePausedEvent(nextPlayer))); } - /** Set descriptors of PlayerSlots. */ - public void openSlots(SlotDescriptor[] descriptors) - throws TooManyPlayersException { - if (descriptors.length > getMaximumPlayerCount()) { - throw new TooManyPlayersException(); - } - this.playerSlots.add(new PlayerSlot(this)); - this.playerSlots.add(new PlayerSlot(this)); - - for (int i = 0; i < descriptors.length; i++) { - this.playerSlots.get(i).setDescriptor(descriptors[i]); - } - } - /** Return true if GameStatus is OVER. */ public boolean isOver() { return getStatus() == GameStatus.OVER;