File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
test/sc/protocol/requests Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ class Lobby : IClientListener {
5454 source.removeClientListener(this )
5555 }
5656
57- /* * handle requests or moves of clients */
57+ /* * Handle requests or moves of clients. */
5858 @Throws(RescuableClientException ::class , InvalidGameStateException ::class )
5959 override fun onRequest (source : Client , callback : PacketCallback ) {
6060 val packet = callback.packet
@@ -101,18 +101,16 @@ class Lobby : IClientListener {
101101 val room = this .gameManager.findRoom(packet.roomId)
102102 val slot = room.slots[packet.slot]
103103 slot.role.player.isCanTimeout = packet.activate
104-
105104 }
106105 is StepRequest -> // It is not checked whether there is a prior pending StepRequest
107106 if (source.isAdministrator) {
108107 val room = this .gameManager.findRoom(packet.roomId)
109108 room.step(packet.forced)
110109 }
111110 is CancelRequest -> if (source.isAdministrator) {
111+ requireNotNull(packet.roomId) { " Can't cancel a game with roomId null!" }
112112 val room = this .gameManager.findRoom(packet.roomId)
113113 room.cancel()
114- // TODO check whether all clients receive game over message
115- this .gameManager.games.remove(room)
116114 }
117115 is TestModeRequest -> if (source.isAdministrator) {
118116 val testMode = packet.testMode
Original file line number Diff line number Diff line change @@ -308,18 +308,20 @@ class RequestTest : RealServerTest() {
308308
309309 @Test
310310 fun cancelRequest () {
311+ val listener = TestLobbyClientListener ()
312+ player1.addListener(listener)
313+
311314 player1.authenticate(PASSWORD )
312315 player1.joinRoomRequest(TestPlugin .TEST_PLUGIN_UUID )
313316 player2.joinRoomRequest(TestPlugin .TEST_PLUGIN_UUID )
314- val listener = TestLobbyClientListener ()
315- player1.addListener(listener)
316317
317- // Wait for messages to get to server
318+ // Wait for server to go
318319 assertTrue(TestHelper .waitUntilTrue({ lobby.gameManager.games.isNotEmpty() }, 1000 ))
320+ assertTrue(TestHelper .waitUntilTrue({ listener.roomId != null }, 2000 ))
319321
320322 player1.send(CancelRequest (listener.roomId))
321- assertTrue(TestHelper .waitUntilTrue({ lobby.gameManager.games.isEmpty() }, 3000 ))
322- assertEquals(0 , lobby.gameManager.games.size.toLong() )
323+ assertTrue(TestHelper .waitUntilTrue({ lobby.gameManager.games.isEmpty() }, 10000 ))
324+ assertEquals(0 , lobby.gameManager.games.size)
323325 }
324326
325327 @Test
You can’t perform that action at this time.
0 commit comments