diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-05 03:07:30 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-05 03:07:30 +0900 |
| commit | 9ff9c151e5defd9eed5cba3c88bc341b4360d09c (patch) | |
| tree | bf5b9e721274ffa58df66823d39f9ceadebc9f98 /backend/game/hub.go | |
| parent | ff959dadb1f990173b9df3105ccfc96b1c6c092e (diff) | |
| parent | 498ad23eaaae1e856c71f44ad0bf3912a6d7e5b7 (diff) | |
| download | iosdc-japan-2024-albatross-9ff9c151e5defd9eed5cba3c88bc341b4360d09c.tar.gz iosdc-japan-2024-albatross-9ff9c151e5defd9eed5cba3c88bc341b4360d09c.tar.zst iosdc-japan-2024-albatross-9ff9c151e5defd9eed5cba3c88bc341b4360d09c.zip | |
Merge branch 'feat/multiplayer-mode'
Diffstat (limited to 'backend/game/hub.go')
| -rw-r--r-- | backend/game/hub.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go index 239f5da..70bf71f 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -81,7 +81,7 @@ func (hub *gameHub) run() { entriedPlayerCount++ } } - if entriedPlayerCount == 2 { + if entriedPlayerCount == hub.game.playerCount { err := hub.q.UpdateGameState(hub.ctx, db.UpdateGameStateParams{ GameID: int32(hub.game.gameID), State: string(gameStateWaitingStart), @@ -101,7 +101,7 @@ func (hub *gameHub) run() { readyPlayerCount++ } } - if readyPlayerCount == 2 { + if readyPlayerCount == hub.game.playerCount { startAt := time.Now().Add(11 * time.Second).UTC() for player := range hub.players { player.s2cMessages <- &playerMessageS2CStart{ @@ -300,6 +300,11 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { description: *row.Description, } } + // TODO: N+1 + playerRows, err := hubs.q.ListGamePlayers(ctx, int32(row.GameID)) + if err != nil { + return err + } hubs.hubs[int(row.GameID)] = newGameHub(ctx, &game{ gameID: int(row.GameID), durationSeconds: int(row.DurationSeconds), @@ -307,6 +312,7 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { displayName: row.DisplayName, startedAt: startedAt, problem: problem_, + playerCount: len(playerRows), }, hubs.q) } return nil |
