Some more changes for the new game handling api and also rate limiting #13

Merged
marco merged 4 commits from game-handler into master 2024-05-12 13:48:23 +00:00
2 changed files with 8 additions and 4 deletions
Showing only changes of commit 97ad45e505 - Show all commits

View File

@ -1,4 +1,4 @@
package websocket
package handler
import (
"context"
@ -21,6 +21,8 @@ var upgrader = gorillaws.Upgrader{
}
func RegisterWebSocketConnection(c *gin.Context) {
limiter.Take()
log.Println(c.Request)
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
@ -31,6 +33,8 @@ func RegisterWebSocketConnection(c *gin.Context) {
}
func waitForAndHandlePlayerID(ctx context.Context, conn *gorillaws.Conn) {
limiter.Take()
msgType, msg, err := conn.ReadMessage()
if err != nil {
errorMessage := fmt.Sprintf("Reading from websocket connection did not work: %s", err)
@ -72,5 +76,6 @@ func waitForAndHandlePlayerID(ctx context.Context, conn *gorillaws.Conn) {
}
func ConnectWsForGame(c *gin.Context) {
limiter.Take()
}

View File

@ -4,7 +4,6 @@ import (
"flag"
"log"
"mchess_server/api/handler"
"mchess_server/api/websocket"
"github.com/gin-gonic/gin"
)
@ -26,10 +25,10 @@ func main() {
router := gin.Default()
router.GET("/api/hostPrivate", handler.HostGameHandler)
router.POST("/api/joinPrivate", handler.JoinPrivateGame)
router.GET("/api/ws", websocket.RegisterWebSocketConnection)
router.GET("/api/ws", handler.RegisterWebSocketConnection)
router.GET("/api/getLobbyForPassphrase/:phrase", handler.GetLobbyForPassphraseHandler)
router.GET("/api/registerWsForGame/:id", websocket.ConnectWsForGame)
router.GET("/api/registerWsForGame/:id", handler.ConnectWsForGame)
router.POST("/api/joinGame/:id", handler.JoinGameHandler)
if debugMode {