Skip to content

Commit

Permalink
hotfix: useGuard 수정 및 주석처리
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-byeong committed Dec 3, 2024
1 parent 3d864c3 commit bfb1605
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
25 changes: 11 additions & 14 deletions packages/server/src/module/game/games/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return participantSid;
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('participant notice')
async handleParticipantNotice(client: Socket, dto) {
const { pinCode } = dto;
client.to(pinCode).emit('participant notice');
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('participant info')
async handleNickname(client: Socket, dto) {
const { pinCode, sid } = dto;
Expand All @@ -170,8 +170,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return { myPosition, participantList };
}


@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('start quiz')
async handleStartQuiz(client: Socket, payload: StartQuizRequestDto) {
const { sid, pinCode } = payload;
Expand Down Expand Up @@ -226,8 +225,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return { isStarted: true };
}


@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('show quiz')
async handleShowQuiz(client: Socket, payload: ShowQuizRequestDto) {
const { pinCode } = payload;
Expand All @@ -253,7 +251,6 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return { quizMaxNum, currentQuizData, startTime, isLast };
}


private async storeQuizToRedis(classId: number) {
const cachedQuizData = await this.redisService.get(`classId=${classId}`);

Expand All @@ -269,7 +266,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return quizData;
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('submit answer')
async handleSubmitAnswer(client: Socket, payload: SubmitAnswerRequestDto) {
const { pinCode, sid, selectedAnswer, submitTime } = payload;
Expand Down Expand Up @@ -343,7 +340,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return { submitOrder: totalSubmit };
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('emoji')
async handleEmoji(client: Socket, payload: EmojiRequestDto) {
const { pinCode, currentOrder, emoji } = payload;
Expand All @@ -367,15 +364,15 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return 0;
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('time end')
async handleTimeEnd(client: Socket, payload: any) {
const { pinCode } = payload;
const gameInfo = JSON.parse(await this.redisService.get(`gameId=${pinCode}`));
await this.redisService.set(`gameId=${pinCode}`, JSON.stringify(gameInfo));
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('show ranking')
async handleShowRanking(client: Socket, payload: ShowRankingRequestDto) {
const { pinCode, sid } = payload;
Expand Down Expand Up @@ -403,7 +400,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return showRankingData;
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('end quiz')
async handleEndQuiz(client: Socket, payload: EndQuizRequestDto) {
const { sid, pinCode } = payload;
Expand Down Expand Up @@ -435,7 +432,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return equals(selectedAnswer, correctAnswers);
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('leaderboard')
async handleLeaderboard(client: Socket, payload: LeaderboardRequestDto) {
const { pinCode } = payload;
Expand Down Expand Up @@ -464,7 +461,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
return leaderboardData;
}

@UseGuards(SessionGuard)
// @UseGuards(SessionGuard)
@SubscribeMessage('message')
async handleMessage(client: Socket, payload: MessageRequestDto) {
const { pinCode, message, position } = payload;
Expand Down
8 changes: 6 additions & 2 deletions packages/server/src/module/guards/session.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ export class SessionGuard implements CanActivate {

const { sid } = client.handshake.auth;

console.log('sid', sid);

if (!sid) {
client.emit('error', { message: 'Session ID not exists in Cookie.' });
return false;
}

if (
(await this.redisService.exists(`master_sid=${sid}`)) ||
(await this.redisService.exists(`participant_sid=${sid}`))
!(
(await this.redisService.exists(`master_sid=${sid}`)) ||
(await this.redisService.exists(`participant_sid=${sid}`))
)
) {
client.emit('error', { message: 'Session ID not exists in Redis.' });
}
Expand Down

0 comments on commit bfb1605

Please sign in to comment.