diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-05 05:35:37 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-05 05:35:37 +0900 |
| commit | dc16e903999af89d87364ad6619e7c8b41301da4 (patch) | |
| tree | 529f1debc2972ac1486e8c0ca4b25827ccd069a6 /backend/game/hub.go | |
| parent | 2a551a05d714657d7cd3b581290054c97398e968 (diff) | |
| download | phperkaigi-2025-albatross-dc16e903999af89d87364ad6619e7c8b41301da4.tar.gz phperkaigi-2025-albatross-dc16e903999af89d87364ad6619e7c8b41301da4.tar.zst phperkaigi-2025-albatross-dc16e903999af89d87364ad6619e7c8b41301da4.zip | |
feat: show execution result in play page
Diffstat (limited to 'backend/game/hub.go')
| -rw-r--r-- | backend/game/hub.go | 16 |
1 files changed, 16 insertions, 0 deletions
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 +} |
