diff options
Diffstat (limited to 'backend/game/http.go')
| -rw-r--r-- | backend/game/http.go | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/backend/game/http.go b/backend/game/http.go deleted file mode 100644 index 0ac7fc6..0000000 --- a/backend/game/http.go +++ /dev/null @@ -1,65 +0,0 @@ -package game - -import ( - "net/http" - "strconv" - - "github.com/labstack/echo/v4" - - "github.com/nsfisis/phperkaigi-2025-albatross/backend/auth" -) - -type SockHandler struct { - hubs *Hubs -} - -func newSockHandler(hubs *Hubs) *SockHandler { - return &SockHandler{ - hubs: hubs, - } -} - -func (h *SockHandler) HandleSockGolfPlay(c echo.Context) error { - jwt := c.QueryParam("token") - claims, err := auth.ParseJWT(jwt) - if err != nil { - return echo.NewHTTPError(http.StatusUnauthorized, err.Error()) - } - // TODO: check user permission - - gameID, err := strconv.Atoi(c.Param("gameID")) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id") - } - hub := h.hubs.getHub(gameID) - if hub == nil { - return echo.NewHTTPError(http.StatusNotFound, "Game not found") - } - return servePlayerWs(hub, c.Response(), c.Request(), claims.UserID) -} - -func (h *SockHandler) HandleSockGolfWatch(c echo.Context) error { - jwt := c.QueryParam("token") - claims, err := auth.ParseJWT(jwt) - if err != nil { - return echo.NewHTTPError(http.StatusUnauthorized, err.Error()) - } - if !claims.IsAdmin { - return echo.NewHTTPError(http.StatusForbidden, "Permission denied") - } - - gameID, err := strconv.Atoi(c.Param("gameID")) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Invalid game id") - } - hub := h.hubs.getHub(gameID) - if hub == nil { - return echo.NewHTTPError(http.StatusNotFound, "Game not found") - } - - if hub.game.gameType != gameType1v1 { - return echo.NewHTTPError(http.StatusBadRequest, "Only 1v1 game is supported") - } - - return serveWatcherWs(hub, c.Response(), c.Request()) -} |
