diff --git a/server/game-manager/queue.go b/server/game-manager/queue.go index 0879598..55edb71 100644 --- a/server/game-manager/queue.go +++ b/server/game-manager/queue.go @@ -116,6 +116,8 @@ func (q *Queue) ProcessQueue(ctx context.Context) { case "collect-entry": query := fmt.Sprintf(`UPDATE public.users SET "solanaBalance" = "solanaBalance" - $1 WHERE id IN (%s) AND "solanaBalance" >= $1`, taskPayload["ids"]) _, err = lib.Pool.Exec(context.Background(), query, taskPayload["entry"]) + case "join-game": + GetInstance().JoinGame(taskPayload["userId"].(string), taskPayload["gameTypeId"].(string)) } if err != nil { diff --git a/server/main.go b/server/main.go index 09543c7..9dffee6 100644 --- a/server/main.go +++ b/server/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "flappy-bird-server/admin" "flappy-bird-server/auth" @@ -73,7 +74,10 @@ func handleWebSocket(w http.ResponseWriter, r *http.Request) { } } else { log.Println("joining game", messageData["userId"].(string)) - gameManager.GetInstance().JoinGame(messageData["userId"].(string), messageData["gameTypeId"].(string)) + gameManager.GetInstance().Queue.Enqueue(context.Background(), map[string]interface{}{ + "type": "join-game", + "data": messageData, + }) } case "update-board": gameManager.GetInstance().UpdateBoard(messageData["gameId"].(string), messageData["userId"].(string))