From f86e2b3e2375ed1f2e3a2d3afec18bf1dcdb55e9 Mon Sep 17 00:00:00 2001 From: Jakub Kasprzyk Date: Fri, 15 Sep 2023 15:08:56 +0200 Subject: [PATCH] Prevent starting race and joining the room on the server side #223 --- packages/client/src/index.html | 99 +++++++++++++------------- packages/client/src/main.ts | 8 --- packages/server/src/sockets/sockets.ts | 10 +++ 3 files changed, 61 insertions(+), 56 deletions(-) diff --git a/packages/client/src/index.html b/packages/client/src/index.html index b37aba0..fafafe5 100644 --- a/packages/client/src/index.html +++ b/packages/client/src/index.html @@ -1,52 +1,55 @@ - - - - - Rally Online - - - -
-
0
-
0
-
- - -
-
- - -
- -
-
-
-
- -
-
content
- + + + + + + Rally Online + + + + +
+
0
+
0
+
+ + +
+
+ + +
+ +
+
+
+
+
+
content
+
- - - +
+ + + + \ No newline at end of file diff --git a/packages/client/src/main.ts b/packages/client/src/main.ts index 40f87ec..8a3c569 100644 --- a/packages/client/src/main.ts +++ b/packages/client/src/main.ts @@ -11,14 +11,6 @@ import { debounce, toggleStartRaceBtns } from "./utils"; import type { Game, GameConfig, GameObject, Position } from "@neu5/types/src"; import type { Quaternion } from "@babylonjs/core"; -// import type { -// GameConfig, -// GameObject, -// Player, -// Position, -// ServerToClientEvents, -// } from "@neu5/types/src"; - type PlayerFromServer = { color: string; userID: string; diff --git a/packages/server/src/sockets/sockets.ts b/packages/server/src/sockets/sockets.ts index 5c8b29e..b63f15c 100644 --- a/packages/server/src/sockets/sockets.ts +++ b/packages/server/src/sockets/sockets.ts @@ -206,6 +206,11 @@ const createSocketHandlers = ({ ); socket.on("client:join race room", async () => { + if (game.race.isStarted) { + socket.emit("server:show error", { message: "The race is already going on! You can't join the room now." }); + return; + } + roomRace.join(socket.data.sessionID); emitRoomInfo({ io, room: roomRace, sessionStore }); @@ -224,6 +229,11 @@ const createSocketHandlers = ({ }); socket.on("client:start the race", async () => { + if (game.race.isStarted) { + socket.emit("server:show error", { message: "The race is already going on!" }); + return; + } + game.race.isStarted = true; game.config = { width: 100,