diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-29 03:44:10 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-29 19:38:39 +0900 |
| commit | d73fd8bf5bf589a4a391c867e980761fadb647ce (patch) | |
| tree | 15f2454b48cae461a6d8acc7edb2c2111d445d3e /backend | |
| parent | 3f95e0e6d62267cf8863e98f3ab7de8971a91000 (diff) | |
| download | iosdc-japan-2024-albatross-d73fd8bf5bf589a4a391c867e980761fadb647ce.tar.gz iosdc-japan-2024-albatross-d73fd8bf5bf589a4a391c867e980761fadb647ce.tar.zst iosdc-japan-2024-albatross-d73fd8bf5bf589a4a391c867e980761fadb647ce.zip | |
feat: partially implement watching
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/api/generated.go | 224 | ||||
| -rw-r--r-- | backend/api/handlers.go | 48 | ||||
| -rw-r--r-- | backend/game/client.go | 5 | ||||
| -rw-r--r-- | backend/game/http.go | 9 | ||||
| -rw-r--r-- | backend/game/hub.go | 28 | ||||
| -rw-r--r-- | backend/game/message.go | 12 | ||||
| -rw-r--r-- | backend/game/ws.go | 3 | ||||
| -rw-r--r-- | backend/main.go | 1 |
8 files changed, 289 insertions, 41 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index e39e3ba..7e64929 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -34,7 +34,12 @@ const ( // Defines values for GamePlayerMessageS2CExecResultPayloadStatus. const ( - Success GamePlayerMessageS2CExecResultPayloadStatus = "success" + GamePlayerMessageS2CExecResultPayloadStatusSuccess GamePlayerMessageS2CExecResultPayloadStatus = "success" +) + +// Defines values for GameWatcherMessageS2CExecResultPayloadStatus. +const ( + GameWatcherMessageS2CExecResultPayloadStatusSuccess GameWatcherMessageS2CExecResultPayloadStatus = "success" ) // Game defines model for Game. @@ -123,6 +128,57 @@ type GamePlayerMessageS2CStartPayload struct { StartAt int `json:"start_at"` } +// GameWatcherMessage defines model for GameWatcherMessage. +type GameWatcherMessage struct { + union json.RawMessage +} + +// GameWatcherMessageS2C defines model for GameWatcherMessageS2C. +type GameWatcherMessageS2C struct { + union json.RawMessage +} + +// GameWatcherMessageS2CCode defines model for GameWatcherMessageS2CCode. +type GameWatcherMessageS2CCode struct { + Data GameWatcherMessageS2CCodePayload `json:"data"` + Type string `json:"type"` +} + +// GameWatcherMessageS2CCodePayload defines model for GameWatcherMessageS2CCodePayload. +type GameWatcherMessageS2CCodePayload struct { + Code string `json:"code"` + PlayerId int `json:"player_id"` +} + +// GameWatcherMessageS2CExecResult defines model for GameWatcherMessageS2CExecResult. +type GameWatcherMessageS2CExecResult struct { + Data GameWatcherMessageS2CExecResultPayload `json:"data"` + Type string `json:"type"` +} + +// GameWatcherMessageS2CExecResultPayload defines model for GameWatcherMessageS2CExecResultPayload. +type GameWatcherMessageS2CExecResultPayload struct { + PlayerId int `json:"player_id"` + Score *int `json:"score"` + Status GameWatcherMessageS2CExecResultPayloadStatus `json:"status"` + Stderr string `json:"stderr"` + Stdout string `json:"stdout"` +} + +// GameWatcherMessageS2CExecResultPayloadStatus defines model for GameWatcherMessageS2CExecResultPayload.Status. +type GameWatcherMessageS2CExecResultPayloadStatus string + +// GameWatcherMessageS2CStart defines model for GameWatcherMessageS2CStart. +type GameWatcherMessageS2CStart struct { + Data GameWatcherMessageS2CStartPayload `json:"data"` + Type string `json:"type"` +} + +// GameWatcherMessageS2CStartPayload defines model for GameWatcherMessageS2CStartPayload. +type GameWatcherMessageS2CStartPayload struct { + StartAt int `json:"start_at"` +} + // JwtPayload defines model for JwtPayload. type JwtPayload struct { DisplayName string `json:"display_name"` @@ -397,6 +453,130 @@ func (t *GamePlayerMessageS2C) UnmarshalJSON(b []byte) error { return err } +// AsGameWatcherMessageS2C returns the union data inside the GameWatcherMessage as a GameWatcherMessageS2C +func (t GameWatcherMessage) AsGameWatcherMessageS2C() (GameWatcherMessageS2C, error) { + var body GameWatcherMessageS2C + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromGameWatcherMessageS2C overwrites any union data inside the GameWatcherMessage as the provided GameWatcherMessageS2C +func (t *GameWatcherMessage) FromGameWatcherMessageS2C(v GameWatcherMessageS2C) error { + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeGameWatcherMessageS2C performs a merge with any union data inside the GameWatcherMessage, using the provided GameWatcherMessageS2C +func (t *GameWatcherMessage) MergeGameWatcherMessageS2C(v GameWatcherMessageS2C) error { + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + +func (t GameWatcherMessage) MarshalJSON() ([]byte, error) { + b, err := t.union.MarshalJSON() + return b, err +} + +func (t *GameWatcherMessage) UnmarshalJSON(b []byte) error { + err := t.union.UnmarshalJSON(b) + return err +} + +// AsGameWatcherMessageS2CStart returns the union data inside the GameWatcherMessageS2C as a GameWatcherMessageS2CStart +func (t GameWatcherMessageS2C) AsGameWatcherMessageS2CStart() (GameWatcherMessageS2CStart, error) { + var body GameWatcherMessageS2CStart + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromGameWatcherMessageS2CStart overwrites any union data inside the GameWatcherMessageS2C as the provided GameWatcherMessageS2CStart +func (t *GameWatcherMessageS2C) FromGameWatcherMessageS2CStart(v GameWatcherMessageS2CStart) error { + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeGameWatcherMessageS2CStart performs a merge with any union data inside the GameWatcherMessageS2C, using the provided GameWatcherMessageS2CStart +func (t *GameWatcherMessageS2C) MergeGameWatcherMessageS2CStart(v GameWatcherMessageS2CStart) error { + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + +// AsGameWatcherMessageS2CCode returns the union data inside the GameWatcherMessageS2C as a GameWatcherMessageS2CCode +func (t GameWatcherMessageS2C) AsGameWatcherMessageS2CCode() (GameWatcherMessageS2CCode, error) { + var body GameWatcherMessageS2CCode + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromGameWatcherMessageS2CCode overwrites any union data inside the GameWatcherMessageS2C as the provided GameWatcherMessageS2CCode +func (t *GameWatcherMessageS2C) FromGameWatcherMessageS2CCode(v GameWatcherMessageS2CCode) error { + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeGameWatcherMessageS2CCode performs a merge with any union data inside the GameWatcherMessageS2C, using the provided GameWatcherMessageS2CCode +func (t *GameWatcherMessageS2C) MergeGameWatcherMessageS2CCode(v GameWatcherMessageS2CCode) error { + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + +// AsGameWatcherMessageS2CExecResult returns the union data inside the GameWatcherMessageS2C as a GameWatcherMessageS2CExecResult +func (t GameWatcherMessageS2C) AsGameWatcherMessageS2CExecResult() (GameWatcherMessageS2CExecResult, error) { + var body GameWatcherMessageS2CExecResult + err := json.Unmarshal(t.union, &body) + return body, err +} + +// FromGameWatcherMessageS2CExecResult overwrites any union data inside the GameWatcherMessageS2C as the provided GameWatcherMessageS2CExecResult +func (t *GameWatcherMessageS2C) FromGameWatcherMessageS2CExecResult(v GameWatcherMessageS2CExecResult) error { + b, err := json.Marshal(v) + t.union = b + return err +} + +// MergeGameWatcherMessageS2CExecResult performs a merge with any union data inside the GameWatcherMessageS2C, using the provided GameWatcherMessageS2CExecResult +func (t *GameWatcherMessageS2C) MergeGameWatcherMessageS2CExecResult(v GameWatcherMessageS2CExecResult) error { + b, err := json.Marshal(v) + if err != nil { + return err + } + + merged, err := runtime.JSONMerge(t.union, b) + t.union = merged + return err +} + +func (t GameWatcherMessageS2C) MarshalJSON() ([]byte, error) { + b, err := t.union.MarshalJSON() + return b, err +} + +func (t *GameWatcherMessageS2C) UnmarshalJSON(b []byte) error { + err := t.union.UnmarshalJSON(b) + return err +} + // ServerInterface represents all server handlers. type ServerInterface interface { // List games @@ -730,26 +910,28 @@ func (sh *strictHandler) PostLogin(ctx echo.Context) error { // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ -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j/Z9S5B+3RzDFDHS7XbrbFEhsYM5OoP1gRBwVQ/yDdzeCF0Ygp4laq8OBzIns6", + "nlw1DZZXzspsJBZHNwewysa011ao5Z9wMFGfzb/B3s/2Nc4a6ZL9udu2VwnnO48megNCG6gQOjqP+6bz", + "g/hCOQu9QEFozqIce6Vzbj/PpieVV6SzyvDfEZTnaJ2mafp3AAAA///2zTVTJhwAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/api/handlers.go b/backend/api/handlers.go index cd8b3b5..f50558d 100644 --- a/backend/api/handlers.go +++ b/backend/api/handlers.go @@ -179,26 +179,46 @@ func _assertJwtPayloadIsCompatibleWithJWTClaims() { _ = p } +func setupJWTFromAuthorizationHeader(c echo.Context) error { + authorization := c.Request().Header.Get("Authorization") + const prefix = "Bearer " + if !strings.HasPrefix(authorization, prefix) { + return echo.NewHTTPError(http.StatusUnauthorized) + } + token := authorization[len(prefix):] + claims, err := auth.ParseJWT(token) + if err != nil { + return echo.NewHTTPError(http.StatusUnauthorized, err.Error()) + } + c.Set("user", claims) + c.SetRequest(c.Request().WithContext(context.WithValue(c.Request().Context(), "user", claims))) + return nil +} + +func NewEchoJWTMiddleware() echo.MiddlewareFunc { + return func(next echo.HandlerFunc) echo.HandlerFunc { + return func(c echo.Context) error { + err := setupJWTFromAuthorizationHeader(c) + if err != nil { + return echo.NewHTTPError(http.StatusUnauthorized, err.Error()) + } + return next(c) + } + } +} + func NewJWTMiddleware() StrictMiddlewareFunc { return func(handler StrictHandlerFunc, operationID string) StrictHandlerFunc { if operationID == "PostLogin" { return handler - } else { - return func(c echo.Context, request interface{}) (response interface{}, err error) { - authorization := c.Request().Header.Get("Authorization") - const prefix = "Bearer " - if !strings.HasPrefix(authorization, prefix) { - return nil, echo.NewHTTPError(http.StatusUnauthorized) - } - token := authorization[len(prefix):] + } - claims, err := auth.ParseJWT(token) - if err != nil { - return nil, echo.NewHTTPError(http.StatusUnauthorized) - } - c.SetRequest(c.Request().WithContext(context.WithValue(c.Request().Context(), "user", claims))) - return handler(c, request) + return func(c echo.Context, request interface{}) (interface{}, error) { + err := setupJWTFromAuthorizationHeader(c) + if err != nil { + return nil, echo.NewHTTPError(http.StatusUnauthorized, err.Error()) } + return handler(c, request) } } } diff --git a/backend/game/client.go b/backend/game/client.go index 7cd66a4..fa699ce 100644 --- a/backend/game/client.go +++ b/backend/game/client.go @@ -12,12 +12,13 @@ type playerClient struct { hub *gameHub conn *websocket.Conn s2cMessages chan playerMessageS2C + playerID int } // Receives messages from the client and sends them to the hub. func (c *playerClient) readPump() { defer func() { - log.Printf("closing client") + log.Printf("closing player client") c.hub.unregisterPlayer <- c c.conn.Close() }() @@ -87,7 +88,7 @@ func (c *watcherClient) writePump() { defer func() { ticker.Stop() c.conn.Close() - log.Printf("closing watcher") + log.Printf("closing watcher client") c.hub.unregisterWatcher <- c }() for { diff --git a/backend/game/http.go b/backend/game/http.go index beda46c..1ac77b0 100644 --- a/backend/game/http.go +++ b/backend/game/http.go @@ -5,6 +5,7 @@ import ( "strconv" "github.com/labstack/echo/v4" + // "github.com/nsfisis/iosdc-2024-albatross/backend/auth" ) type sockHandler struct { @@ -18,7 +19,11 @@ func newSockHandler(hubs *GameHubs) *sockHandler { } func (h *sockHandler) HandleSockGolfPlay(c echo.Context) error { - // TODO: auth + // user := c.Get("user").(*auth.JWTClaims) + // if user == nil { + // return echo.NewHTTPError(http.StatusUnauthorized) + // } + // TODO: check user permission gameId := c.Param("gameId") gameIdInt, err := strconv.Atoi(gameId) if err != nil { @@ -34,7 +39,7 @@ func (h *sockHandler) HandleSockGolfPlay(c echo.Context) error { if foundHub == nil { return echo.NewHTTPError(http.StatusNotFound, "Game not found") } - return servePlayerWs(foundHub, c.Response(), c.Request(), "a") + return servePlayerWs(foundHub, c.Response(), c.Request(), 1) } func (h *sockHandler) HandleSockGolfWatch(c echo.Context) error { diff --git a/backend/game/hub.go b/backend/game/hub.go index d4a9231..770d257 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -121,6 +121,14 @@ func (hub *gameHub) run() { }, } } + for watcher := range hub.watchers { + watcher.s2cMessages <- &watcherMessageS2CStart{ + Type: watcherMessageTypeS2CStart, + Data: watcherMessageS2CStartPayload{ + StartAt: int(startAt.Unix()), + }, + } + } err := hub.q.UpdateGameStartedAt(hub.ctx, db.UpdateGameStartedAtParams{ GameID: int32(hub.game.gameID), StartedAt: pgtype.Timestamp{ @@ -151,9 +159,27 @@ func (hub *gameHub) run() { Type: playerMessageTypeS2CExecResult, Data: playerMessageS2CExecResultPayload{ Score: &score, - Status: api.Success, + Status: api.GamePlayerMessageS2CExecResultPayloadStatusSuccess, }, } + for watcher := range hub.watchers { + watcher.s2cMessages <- &watcherMessageS2CCode{ + Type: watcherMessageTypeS2CCode, + Data: watcherMessageS2CCodePayload{ + PlayerId: message.client.playerID, + Code: code, + }, + } + watcher.s2cMessages <- &watcherMessageS2CExecResult{ + Type: watcherMessageTypeS2CExecResult, + Data: watcherMessageS2CExecResultPayload{ + PlayerId: message.client.playerID, + Score: &score, + Stdout: "", + Stderr: "", + }, + } + } default: log.Fatalf("unexpected message type: %T", message.message) } diff --git a/backend/game/message.go b/backend/game/message.go index 9116bde..bb57eb5 100644 --- a/backend/game/message.go +++ b/backend/game/message.go @@ -66,4 +66,16 @@ func asPlayerMessageC2S(raw map[string]json.RawMessage) (playerMessageC2S, error } } +const ( + watcherMessageTypeS2CStart = "watcher:s2c:start" + watcherMessageTypeS2CExecResult = "watcher:s2c:execreslut" + watcherMessageTypeS2CCode = "watcher:s2c:code" +) + type watcherMessageS2C = interface{} +type watcherMessageS2CStart = api.GameWatcherMessageS2CStart +type watcherMessageS2CStartPayload = api.GameWatcherMessageS2CStartPayload +type watcherMessageS2CCode = api.GameWatcherMessageS2CCode +type watcherMessageS2CCodePayload = api.GameWatcherMessageS2CCodePayload +type watcherMessageS2CExecResult = api.GameWatcherMessageS2CExecResult +type watcherMessageS2CExecResultPayload = api.GameWatcherMessageS2CExecResultPayload diff --git a/backend/game/ws.go b/backend/game/ws.go index 013db7a..9a3956b 100644 --- a/backend/game/ws.go +++ b/backend/game/ws.go @@ -23,7 +23,7 @@ var upgrader = websocket.Upgrader{ }, } -func servePlayerWs(hub *gameHub, w http.ResponseWriter, r *http.Request, team string) error { +func servePlayerWs(hub *gameHub, w http.ResponseWriter, r *http.Request, playerID int) error { conn, err := upgrader.Upgrade(w, r, nil) if err != nil { return err @@ -32,6 +32,7 @@ func servePlayerWs(hub *gameHub, w http.ResponseWriter, r *http.Request, team st hub: hub, conn: conn, s2cMessages: make(chan playerMessageS2C), + playerID: playerID, } hub.registerPlayer <- player diff --git a/backend/main.go b/backend/main.go index 91caa73..fe113dc 100644 --- a/backend/main.go +++ b/backend/main.go @@ -71,6 +71,7 @@ func main() { } defer gameHubs.Close() sockGroup := e.Group("/sock") + // sockGroup.Use(api.NewEchoJWTMiddleware()) sockHandler := gameHubs.SockHandler() sockGroup.GET("/golf/:gameId/play", func(c echo.Context) error { return sockHandler.HandleSockGolfPlay(c) |
