diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:13:05 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:13:05 +0900 |
| commit | 8dbdf96e674c1e26d7c98af8d0608f30bc1bf166 (patch) | |
| tree | 7c82476f6bbbc71d72ab7e71e39559eca197fd95 /backend/game/http.go | |
| parent | 54316868c3bec1ff9b04643dfe6c13cf56bf3246 (diff) | |
| parent | 1e6df136d8202c8adf65948527f4c3e7583b338c (diff) | |
| download | phperkaigi-2025-albatross-8dbdf96e674c1e26d7c98af8d0608f30bc1bf166.tar.gz phperkaigi-2025-albatross-8dbdf96e674c1e26d7c98af8d0608f30bc1bf166.tar.zst phperkaigi-2025-albatross-8dbdf96e674c1e26d7c98af8d0608f30bc1bf166.zip | |
Merge branch 'phperkaigi-2025-ws-to-polling' into phperkaigi-2025
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()) -} |
