diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-07 22:31:55 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-08 04:02:37 +0900 |
| commit | 963292574fd72ec62ebc75c308f1275de531a2e9 (patch) | |
| tree | 99f6caccda5f2d9c18c0c8a045925d14e3a6b8d7 /backend | |
| parent | f7f511326aaa5175501494c2566ec43166e81a7c (diff) | |
| download | iosdc-japan-2024-albatross-963292574fd72ec62ebc75c308f1275de531a2e9.tar.gz iosdc-japan-2024-albatross-963292574fd72ec62ebc75c308f1275de531a2e9.tar.zst iosdc-japan-2024-albatross-963292574fd72ec62ebc75c308f1275de531a2e9.zip | |
feat(backend): separate game hub worker channel
* processing incoming WebSocket messages
* processing task results
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/game/hub.go | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go index 84f7a84..605edf5 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -169,20 +169,6 @@ func (hub *gameHub) run() { default: log.Printf("unexpected message type: %T", message.message) } - case executionResult := <-hub.testcaseExecution: - for player := range hub.players { - if player.playerID != executionResult.Task.UserID { - continue - } - player.s2cMessages <- &playerMessageS2CExecResult{ - Type: playerMessageTypeS2CExecResult, - Data: playerMessageS2CExecResultPayload{ - Score: nil, - Status: api.GamePlayerMessageS2CExecResultPayloadStatus(executionResult.Result), - }, - } - } - // broadcast to watchers case <-ticker.C: if hub.game.state == gameStateStarting { if time.Now().After(*hub.game.startedAt) { @@ -213,6 +199,24 @@ func (hub *gameHub) run() { } } +func (hub *gameHub) processTaskResults() { + for executionResult := range hub.testcaseExecution { + for player := range hub.players { + if player.playerID != executionResult.Task.UserID { + continue + } + player.s2cMessages <- &playerMessageS2CExecResult{ + Type: playerMessageTypeS2CExecResult, + Data: playerMessageS2CExecResultPayload{ + Score: nil, + Status: api.GamePlayerMessageS2CExecResultPayloadStatus(executionResult.Result), + }, + } + } + // broadcast to watchers + } +} + func (hub *gameHub) startGame() error { for player := range hub.players { player.s2cMessages <- &playerMessageS2CPrepare{ @@ -331,6 +335,7 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { func (hubs *GameHubs) Run() { for _, hub := range hubs.hubs { go hub.run() + go hub.processTaskResults() } for taskResult := range hubs.taskResults { |
