Skip to content

Commit

Permalink
Added queue for join game
Browse files Browse the repository at this point in the history
  • Loading branch information
atul24112001 committed Nov 8, 2024
1 parent d3e655b commit aaf84c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/game-manager/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"encoding/json"
"flappy-bird-server/admin"
"flappy-bird-server/auth"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit aaf84c0

Please sign in to comment.