Skip to content

Commit

Permalink
leaveWorld.ts - reduce player count only if user has a valid world
Browse files Browse the repository at this point in the history
  • Loading branch information
React-1 committed Nov 19, 2024
1 parent 71c4a7f commit 978ff16
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/src/services/maproom/v2/leaveWorld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ import { ORMContext } from "../../../server";
export const leaveWorld = async (user: User, save: Save) => {
const world = await ORMContext.em.findOne(World, { uuid: save.worldid });

// Decrement the player count
world.playerCount -= 1;
if (world) {
// Decrement the player count
world.playerCount -= 1;
await ORMContext.em.persistAndFlush(world);
}

// Reset the user's save data
save.worldid = null;
Expand All @@ -31,7 +34,7 @@ export const leaveWorld = async (user: User, save: Save) => {

// Remove user's cells from the world
await removeUserCells(user);
await ORMContext.em.persistAndFlush([world, save, user]);
await ORMContext.em.persistAndFlush([save, user]);
};

const removeUserCells = async (user: User) => {
Expand Down

0 comments on commit 978ff16

Please sign in to comment.