Skip to content

Commit 5c78210

Browse files
coder-pmMarcin Polak
authored and
Marcin Polak
committed
Fixed another critical exception that might crash server (respawn of client who quit the game)
1 parent f3036e5 commit 5c78210

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/server/classes/Game/Game.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,13 @@ export default class Game {
249249
// check if its possible to spawn tank here
250250
if (this.world.isIntersecting(tank, Collision.BLOCK_MOVE).length === 0) {
251251
const client = this.clients[tank.id];
252-
tank.location = this.spawnPoints[client.spawnId];
253-
this.tanks[tank.id] = tank;
254-
this.world.registerObject(tank, Collision.BLOCK_ALL);
255-
this.io.emit(NetworkPacket.BOARD_STATE_TANKS, Object.values(this.tanks));
252+
// abort respawning if client quit
253+
if (typeof client === 'object') {
254+
tank.location = this.spawnPoints[client.spawnId];
255+
this.tanks[tank.id] = tank;
256+
this.world.registerObject(tank, Collision.BLOCK_ALL);
257+
this.io.emit(NetworkPacket.BOARD_STATE_TANKS, Object.values(this.tanks));
258+
}
256259
} else {
257260
// defer spawning
258261
setTimeout(() => this.spawnTank(tank), 1000);

0 commit comments

Comments
 (0)