Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/no spectator deanonymizing #863

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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