@@ -221,7 +221,10 @@ apiRouter.get("/game-state", (req, res) => {
221
221
return res . status ( 400 ) . send ( { message : "No game is currently active" } ) ;
222
222
}
223
223
const clientType = clientManager . getClientType ( req . cookies . id ) ;
224
- return res . send ( gameManager . getGameState ( clientType ) ) ;
224
+ return res . send ( {
225
+ state : gameManager . getGameState ( clientType ) ,
226
+ pause : gamePaused . flag ,
227
+ } ) ;
225
228
} ) ;
226
229
227
230
/**
@@ -575,26 +578,32 @@ apiRouter.get("/pause-game", (_, res) => {
575
578
* Todo: add authentication instead of an exposed unpause call
576
579
*/
577
580
apiRouter . get ( "/unpause-game" , async ( _ , res ) => {
578
- gamePaused . flag = false ;
579
- const ids = clientManager . getIds ( ) ;
580
- if ( ids ) {
581
- const oldSave = SaveManager . loadGame ( ids [ 0 ] ) ;
582
- gameManager ?. chess . loadFen ( oldSave ! . oldPos ) ;
583
- setAllRobotsToDefaultPositions (
584
- new Map (
585
- oldSave ! . oldRobotPos ?. map < [ string , GridIndices ] > ( ( obj ) => [
586
- obj [ 1 ] ,
587
- new GridIndices (
588
- parseInt ( obj [ 0 ] . split ( ", " ) [ 0 ] ) ,
589
- parseInt ( obj [ 0 ] . split ( ", " ) [ 1 ] ) ,
590
- ) ,
591
- ] ) ,
592
- ) ,
581
+ if ( gamePaused . flag ) {
582
+ gamePaused . flag = false ;
583
+ const ids = clientManager . getIds ( ) ;
584
+ if ( ids ) {
585
+ const oldSave = SaveManager . loadGame ( ids [ 0 ] ) ;
586
+ gameManager ?. chess . loadFen ( oldSave ! . oldPos ) ;
587
+ setAllRobotsToDefaultPositions (
588
+ new Map (
589
+ oldSave ! . oldRobotPos ?. map < [ string , GridIndices ] > ( ( obj ) => [
590
+ obj [ 1 ] ,
591
+ new GridIndices (
592
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 0 ] ) ,
593
+ parseInt ( obj [ 0 ] . split ( ", " ) [ 1 ] ) ,
594
+ ) ,
595
+ ] ) ,
596
+ ) ,
597
+ ) ;
598
+ socketManager . sendToAll ( new SetChessMessage ( oldSave ! . oldPos ) ) ;
599
+ }
600
+ socketManager . sendToAll (
601
+ new GameHoldMessage ( GameHoldReason . GAME_UNPAUSED ) ,
593
602
) ;
594
- socketManager . sendToAll ( new SetChessMessage ( oldSave ! . oldPos ) ) ;
603
+ return res . send ( { message : "success" } ) ;
604
+ } else {
605
+ return res . send ( { message : "game not paused" } ) ;
595
606
}
596
- socketManager . sendToAll ( new GameHoldMessage ( GameHoldReason . GAME_UNPAUSED ) ) ;
597
- return res . send ( { message : "success" } ) ;
598
607
} ) ;
599
608
600
609
/**
0 commit comments