From dc16e903999af89d87364ad6619e7c8b41301da4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 5 Aug 2024 05:35:37 +0900 Subject: feat: show execution result in play page --- backend/game/hub.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'backend/game/hub.go') diff --git a/backend/game/hub.go b/backend/game/hub.go index 0b12ce9..bb82170 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -34,6 +34,7 @@ type gameHub struct { watchers map[*watcherClient]bool registerWatcher chan *watcherClient unregisterWatcher chan *watcherClient + testcaseExecution chan string } func newGameHub(ctx context.Context, game *game, q *db.Queries, taskQueue *taskqueue.Queue) *gameHub { @@ -49,6 +50,7 @@ func newGameHub(ctx context.Context, game *game, q *db.Queries, taskQueue *taskq watchers: make(map[*watcherClient]bool), registerWatcher: make(chan *watcherClient), unregisterWatcher: make(chan *watcherClient), + testcaseExecution: make(chan string), } } @@ -185,6 +187,16 @@ func (hub *gameHub) run() { default: log.Printf("unexpected message type: %T", message.message) } + case executionStatus := <-hub.testcaseExecution: + for player := range hub.players { + player.s2cMessages <- &playerMessageS2CExecResult{ + Type: playerMessageTypeS2CExecResult, + Data: playerMessageS2CExecResultPayload{ + Score: nil, + Status: api.GamePlayerMessageS2CExecResultPayloadStatus(executionStatus), + }, + } + } case <-ticker.C: if hub.game.state == gameStateStarting { if time.Now().After(*hub.game.startedAt) { @@ -344,3 +356,7 @@ func (hubs *GameHubs) StartGame(gameID int) error { } return hub.startGame() } + +func (hubs *GameHubs) C() chan string { + return hubs.hubs[4].testcaseExecution +} -- cgit v1.2.3-70-g09d2