Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/16/backend flow game start #35

Merged
merged 9 commits into from
Sep 15, 2023

Conversation

ShadowSunCat
Copy link
Collaborator

完成 #16

1. add StartGameJob to trigger start games regularly
2. set game status to STARTED, direction to RIGHT, mode to LIGHT
3. assign initial player
4. random deal
5. send sse broadcast event
6. send personal events
7. presenter for personal events and broadcast event
8. add event type for join broadcast event, started broadcast event, started personal event
9. refactor: 改 exception
10. refactor: use Optional to handle emitter not found for SseService send broadcast event

Closes #16
將發送 sse event 跟產 response 的工作搬到 use case 層,這樣 controller 就不用管 presenter。
問題: 沒加 synchronized 前,在同一時間有多個 join request 進來時,有可能會同時拿不到可加入的遊戲。
結果:
1.
建立了多個新的遊戲,玩家會分散掉。
2. 沒有先將玩家湊滿才開新遊戲
解法: 方法加上 synchronized,確保同一時間只有一個請求可以
join game
延伸問題: 此解法在多台 api 時會失效,屆時需再想其他解法。

Closes #16
1. 移除 job,直接在 GameJoinUseCase 中判斷
game.isFull(),並讓
GameStartPresenter
產生遊戲開始相關的 event,由 sseService 送出。
2.
修正 join 的 e2e
測試,因為有調整廣播 event 內容,加上 eventType,但測試忘記調整。

Closes #16
@ShadowSunCat ShadowSunCat linked an issue Sep 3, 2023 that may be closed by this pull request
5 tasks
@ankertim ankertim self-requested a review September 5, 2023 04:59
@ShadowSunCat ShadowSunCat merged commit 247bc0b into main Sep 15, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[backend] 流程開發 - 遊戲開始
1 participant