diff options
Diffstat (limited to 'backend/game')
| -rw-r--r-- | backend/game/http.go | 12 | ||||
| -rw-r--r-- | backend/game/hub.go | 24 | ||||
| -rw-r--r-- | backend/game/ws.go | 1 |
3 files changed, 19 insertions, 18 deletions
diff --git a/backend/game/http.go b/backend/game/http.go index 865c724..d513593 100644 --- a/backend/game/http.go +++ b/backend/game/http.go @@ -9,17 +9,17 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/auth" ) -type sockHandler struct { - hubs *GameHubs +type SockHandler struct { + hubs *Hubs } -func newSockHandler(hubs *GameHubs) *sockHandler { - return &sockHandler{ +func newSockHandler(hubs *Hubs) *SockHandler { + return &SockHandler{ hubs: hubs, } } -func (h *sockHandler) HandleSockGolfPlay(c echo.Context) error { +func (h *SockHandler) HandleSockGolfPlay(c echo.Context) error { jwt := c.QueryParam("token") claims, err := auth.ParseJWT(jwt) if err != nil { @@ -38,7 +38,7 @@ func (h *sockHandler) HandleSockGolfPlay(c echo.Context) error { return servePlayerWs(hub, c.Response(), c.Request(), claims.UserID) } -func (h *sockHandler) HandleSockGolfWatch(c echo.Context) error { +func (h *SockHandler) HandleSockGolfWatch(c echo.Context) error { jwt := c.QueryParam("token") claims, err := auth.ParseJWT(jwt) if err != nil { diff --git a/backend/game/hub.go b/backend/game/hub.go index 11a466b..dc56f03 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -544,15 +544,15 @@ func (hub *gameHub) closeWatcherClient(watcher *watcherClient) { close(watcher.s2cMessages) } -type GameHubs struct { +type Hubs struct { hubs map[int]*gameHub q *db.Queries taskQueue *taskqueue.Queue taskResults chan taskqueue.TaskResult } -func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue, taskResults chan taskqueue.TaskResult) *GameHubs { - return &GameHubs{ +func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue, taskResults chan taskqueue.TaskResult) *Hubs { + return &Hubs{ hubs: make(map[int]*gameHub), q: q, taskQueue: taskQueue, @@ -560,18 +560,18 @@ func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue, taskResults chan tas } } -func (hubs *GameHubs) Close() { +func (hubs *Hubs) Close() { log.Println("closing all game hubs") for _, hub := range hubs.hubs { hub.close() } } -func (hubs *GameHubs) getHub(gameID int) *gameHub { +func (hubs *Hubs) getHub(gameID int) *gameHub { return hubs.hubs[gameID] } -func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { +func (hubs *Hubs) RestoreFromDB(ctx context.Context) error { games, err := hubs.q.ListGames(ctx) if err != nil { return err @@ -581,12 +581,12 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { if row.StartedAt.Valid { startedAt = &row.StartedAt.Time } - var problem_ *problem + var pr *problem if row.ProblemID != nil { if row.Title == nil || row.Description == nil { panic("inconsistent data") } - problem_ = &problem{ + pr = &problem{ problemID: int(*row.ProblemID), title: *row.Title, description: *row.Description, @@ -603,14 +603,14 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { state: gameState(row.State), displayName: row.DisplayName, startedAt: startedAt, - problem: problem_, + problem: pr, playerCount: len(playerRows), }, hubs.q, hubs.taskQueue) } return nil } -func (hubs *GameHubs) Run() { +func (hubs *Hubs) Run() { for _, hub := range hubs.hubs { go hub.run() go hub.processTaskResults() @@ -626,11 +626,11 @@ func (hubs *GameHubs) Run() { } } -func (hubs *GameHubs) SockHandler() *sockHandler { +func (hubs *Hubs) SockHandler() *SockHandler { return newSockHandler(hubs) } -func (hubs *GameHubs) StartGame(gameID int) error { +func (hubs *Hubs) StartGame(gameID int) error { hub := hubs.getHub(gameID) if hub == nil { return errors.New("no such game") diff --git a/backend/game/ws.go b/backend/game/ws.go index 8e219d6..0dbd0ab 100644 --- a/backend/game/ws.go +++ b/backend/game/ws.go @@ -20,6 +20,7 @@ var upgrader = websocket.Upgrader{ WriteBufferSize: 1024, CheckOrigin: func(r *http.Request) bool { // TODO: insecure! + _ = r return true }, } |
