Skip to content

Commit 5b18c3e

Browse files
committed
notify both players of game start
1 parent 770f117 commit 5b18c3e

File tree

3 files changed

+3
-10
lines changed

3 files changed

+3
-10
lines changed

src/main/client/src/feature/lobby/Lobby.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function Lobby() {
7373
initialized.current = true
7474
let sub = stompClient.subscribe("/topic/gamestart", (message) => {
7575
let r = JSON.parse(message.body)
76-
if (r.opponent === auth.name) {
76+
if (r.players.includes(auth.name)) {
7777
navigate(base + "/game/" + r.id)
7878
}
7979
})

src/main/client/src/feature/lobby/Requests.jsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import {
88
twJoin,
99
} from "tailwind-merge"
1010
import {
11-
useNavigate,
12-
} from "react-router-dom"
13-
import {
14-
base,
1511
StompContext,
1612
tfetch,
1713
doTry,
@@ -24,7 +20,6 @@ export function Requests({lobbyState}) {
2420
let [requests, setRequests] = useState([])
2521
let openGameId = lobbyState.openGameId
2622
let stompClient = useContext(StompContext)
27-
let navigate = useNavigate()
2823
let auth = useAuthStore(state => state.auth)
2924
let initialized = useRef()
3025
useEffect(() => {
@@ -47,7 +42,7 @@ export function Requests({lobbyState}) {
4742
return () => {
4843
sub1.unsubscribe()
4944
}
50-
}, [auth, initialized, stompClient, navigate, openGameId])
45+
}, [auth, initialized, stompClient, openGameId])
5146
if (!openGameId) {
5247
return <div />
5348
}
@@ -65,7 +60,6 @@ export function Requests({lobbyState}) {
6560
}
6661

6762
function Request({request}) {
68-
let navigate = useNavigate()
6963
let auth = useAuthStore(state => state.auth)
7064
return (
7165
<div
@@ -79,7 +73,6 @@ function Request({request}) {
7973
},
8074
body: JSON.stringify(request),
8175
})
82-
navigate(base + "/game/" + request.game.id)
8376
})
8477
}}
8578
className={twJoin(

src/main/java/com/bernd/GameController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public ResponseEntity<?> start(@RequestBody AcceptRequest acceptRequest) {
154154
chat.messages().add(startMessage);
155155
operations.convertAndSend("/topic/chat/" + chat.id(), startMessage);
156156
operations.convertAndSend("/topic/gamestart", Map.of(
157-
"opponent", acceptRequest.opponent(),
157+
"players", List.of(principal, acceptRequest.opponent()),
158158
"id", openGame.id()));
159159
operations.convertAndSend("/topic/lobby/open_games", openGames.games());
160160
operations.convertAndSend("/topic/lobby/active_games", activeGames.games());

0 commit comments

Comments
 (0)