Skip to content

Commit

Permalink
Merge pull request #863 from solaris-games/feature/no-spectator-deano…
Browse files Browse the repository at this point in the history
…nymizing

Feature/no spectator deanonymizing
  • Loading branch information
SpacialCircumstances authored Apr 26, 2024
2 parents 70a2ed5 + b12d31c commit 88b3842
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion server/services/gameGalaxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,9 @@ export default class GameGalaxyService {

// If the user is spectating then they can see from the perspectives of all
// players who they are spectating.
// If they are a player themselves, the spectator perspective is ignored
if (userId && this.spectatorService.isSpectatingEnabled(game)) {
let spectating = this.spectatorService.listSpectatingPlayers(game, userId);
const spectating = this.spectatorService.listSpectatingPlayers(game, userId);

if (spectating.length) {
return spectating.map(p => p._id);
Expand Down
18 changes: 14 additions & 4 deletions server/services/gameList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,21 @@ export default class GameListService {
async listSpectating(userId: DBObjectId) {
return await this.gameRepo.find({
'state.endDate': { $eq: null }, // Game is in progress
'galaxy.players.spectators': { // User is spectating at least one player.
$elemMatch: {
$in: [userId]
$and: [{
'galaxy.players.spectators': { // User is spectating at least one player.
$elemMatch: {
$in: [userId]
}
}
},
{
'galaxy.players': {
$not: {
$elemMatch: { userId }
}
}
}
}
]
},
{
'settings.general.type': 1,
Expand Down
8 changes: 0 additions & 8 deletions server/services/spectator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import user from "../api/controllers/user";
import ValidationError from "../errors/validation";
import PlayerService from "./player";
import Repository from "./repository";
Expand Down Expand Up @@ -39,13 +38,6 @@ export default class SpectatorService {
throw new ValidationError(`A player with the username ${username} does not exist.`);
}

// Make sure the user isn't already playing in the game.
const existingPlayer = this.playerService.getByUserId(game, user._id);

if (existingPlayer) {
throw new ValidationError(`The user ${username} is already playing in this game, they cannot be invited to spectate.`);
}

await this.gameRepo.updateOne({
_id: game._id,
'galaxy.players._id': player._id
Expand Down

0 comments on commit 88b3842

Please sign in to comment.