Skip to content

Commit

Permalink
Merge pull request #247 from DongHoonYu96/hotfix-be-#1
Browse files Browse the repository at this point in the history
[BE] hotfix#1
  • Loading branch information
NewCodes7 authored Nov 21, 2024
2 parents b10c90c + d0bbc1c commit 00bf451
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 81 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ jobs:
cd
cd /home/ubuntu/nest-server/current/FE
npm i
npx pm2 stop backend-server || true
npx pm2 delete quiz-ground-was1 quiz-ground-was2 || true
cd /home/ubuntu/nest-server/current/BE
npx pm2 start dist/src/main.js --name "backend-server"
npx pm2 start ecosystem.config.js
# todo: # FrontEnd 배포
# # Frontend 배포
Expand Down
18 changes: 18 additions & 0 deletions BE/ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
apps: [
{
name: 'quiz-ground-was1',
script: 'dist/src/main.js',
env: {
WAS_PORT: 3000
}
},
{
name: 'quiz-ground-was2',
script: 'dist/src/main.js',
env: {
WAS_PORT: 3001
}
}
]
};
18 changes: 0 additions & 18 deletions BE/src/auth/auth.controller.spec.ts

This file was deleted.

18 changes: 0 additions & 18 deletions BE/src/auth/auth.service.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion BE/src/game/dto/create-game.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ export class CreateGameDto {
message: '잘λͺ»λœ boolean κ°’μž…λ‹ˆλ‹€'
});
})
isPublicGame: boolean;
isPublic: boolean;
}
2 changes: 1 addition & 1 deletion BE/src/game/dto/update-room-option.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export class UpdateRoomOptionDto {
message: '잘λͺ»λœ boolean κ°’μž…λ‹ˆλ‹€'
});
})
isPublicGame: boolean;
isPublic: boolean;
}
3 changes: 1 addition & 2 deletions BE/src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export class GameGateway {
if (client.data.user) {
dto.playerName = client.data.user.nickname;
}
const players = await this.gameRoomService.joinRoom(dto, client.id);
client.join(dto.gameId);
const players = await this.gameRoomService.joinRoom(client, dto, client.id);
client.emit(SocketEvents.JOIN_ROOM, { players });
}

Expand Down
6 changes: 3 additions & 3 deletions BE/src/game/redis/subscribers/room.subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ export class RoomSubscriber extends RedisSubscriber {
server.to(gameId).emit(SocketEvents.UPDATE_ROOM_OPTION, {
title: roomData.title,
gameMode: roomData.gameMode,
maxPlayerCount: roomData.maxPlayerCount,
isPublic: roomData.isPublic
maxPlayerCount: parseInt(roomData.maxPlayerCount),
isPublic: roomData.isPublic === '1'
});
this.logger.verbose(`Room option updated: ${gameId}`);
break;

case 'Quizset':
server.to(gameId).emit(SocketEvents.UPDATE_ROOM_QUIZSET, {
quizSetId: roomData.quizSetId,
quizCount: roomData.quizCount
quizCount: parseInt(roomData.quizCount)
});
this.logger.verbose(`Room quizset updated: ${gameId}`);
break;
Expand Down
19 changes: 15 additions & 4 deletions BE/src/game/service/game.room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SocketEvents from '../../common/constants/socket-events';
import { UpdateRoomOptionDto } from '../dto/update-room-option.dto';
import { UpdateRoomQuizsetDto } from '../dto/update-room-quizset.dto';
import { Cron, CronExpression } from '@nestjs/schedule';
import { Socket } from 'socket.io';

@Injectable()
export class GameRoomService {
Expand All @@ -32,7 +33,7 @@ export class GameRoomService {
title: gameConfig.title,
gameMode: gameConfig.gameMode,
maxPlayerCount: gameConfig.maxPlayerCount.toString(),
isPublicGame: gameConfig.isPublicGame ? '1' : '0',
isPublic: gameConfig.isPublic ? '1' : '0',
isWaiting: '1',
lastActivityAt: new Date().getTime().toString(),
quizSetId: '-1', // λ―Έμ„€μ •μ‹œ κΈ°λ³Έν€΄μ¦ˆλ₯Ό 진행, -1은 κΈ°λ³Έ ν€΄μ¦ˆμ…‹
Expand All @@ -47,7 +48,7 @@ export class GameRoomService {
return roomId;
}

async joinRoom(dto: JoinRoomDto, clientId: string) {
async joinRoom(client: Socket, dto: JoinRoomDto, clientId: string) {
const roomKey = REDIS_KEY.ROOM(dto.gameId);
const room = await this.redis.hgetall(roomKey);
this.gameValidator.validateRoomExists(SocketEvents.JOIN_ROOM, room);
Expand All @@ -60,6 +61,8 @@ export class GameRoomService {
);
this.gameValidator.validateRoomProgress(SocketEvents.JOIN_ROOM, room.status, room.isWaiting);

client.join(dto.gameId); //validation 후에 쑰인해야함

const playerKey = REDIS_KEY.PLAYER(clientId);
const positionX = Math.random();
const positionY = Math.random();
Expand All @@ -86,13 +89,21 @@ export class GameRoomService {
});
}

const roomData = await this.redis.hgetall(REDIS_KEY.ROOM(dto.gameId));
client.emit(SocketEvents.UPDATE_ROOM_OPTION, {
title: roomData.title,
gameMode: roomData.gameMode,
maxPlayerCount: parseInt(roomData.maxPlayerCount),
isPublic: roomData.isPublic === '1'
});

this.logger.verbose(`κ²Œμž„ λ°© μž…μž₯ μ™„λ£Œ: ${dto.gameId} - ${clientId} (${dto.playerName})`);

return players;
}

async updateRoomOption(updateRoomOptionDto: UpdateRoomOptionDto, clientId: string) {
const { gameId, gameMode, title, maxPlayerCount, isPublicGame } = updateRoomOptionDto;
const { gameId, gameMode, title, maxPlayerCount, isPublic } = updateRoomOptionDto;
const roomKey = `Room:${gameId}`;

const room = await this.redis.hgetall(roomKey);
Expand All @@ -105,7 +116,7 @@ export class GameRoomService {
title: title,
gameMode: gameMode,
maxPlayerCount: maxPlayerCount.toString(),
isPublicGame: isPublicGame ? '1' : '0'
isPublic: isPublic ? '1' : '0'
});
this.logger.verbose(`κ²Œμž„λ°© μ˜΅μ…˜ λ³€κ²½: ${gameId}`);
}
Expand Down
18 changes: 0 additions & 18 deletions BE/src/user/user.service.spec.ts

This file was deleted.

28 changes: 14 additions & 14 deletions BE/test/integration/game.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('GameGateway (e2e)', () => {
title: 'hello world!',
gameMode: 'RANKING',
maxPlayerCount: 2,
isPublicGame: true
isPublic: true
};

const response = await new Promise<{ gameId: string }>((resolve) => {
Expand All @@ -213,19 +213,19 @@ describe('GameGateway (e2e)', () => {
const invalidConfigs = [
{
case: '빈 title',
config: { title: '', gameMode: 'RANKING', maxPlayerCount: 2, isPublicGame: true }
config: { title: '', gameMode: 'RANKING', maxPlayerCount: 2, isPublic: true }
},
{
case: '빈 gameMode',
config: { title: 'hello', gameMode: '', maxPlayerCount: 2, isPublicGame: true }
config: { title: 'hello', gameMode: '', maxPlayerCount: 2, isPublic: true }
},
{
case: '잘λͺ»λœ gameMode',
config: { title: 'hello', gameMode: 'invalid', maxPlayerCount: 2, isPublicGame: true }
config: { title: 'hello', gameMode: 'invalid', maxPlayerCount: 2, isPublic: true }
},
{
case: 'μ΅œμ†Œ 인원 미달',
config: { title: 'hello', gameMode: 'RANKING', maxPlayerCount: 0, isPublicGame: true }
config: { title: 'hello', gameMode: 'RANKING', maxPlayerCount: 0, isPublic: true }
}
];

Expand All @@ -251,7 +251,7 @@ describe('GameGateway (e2e)', () => {
title: 'Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});

Expand Down Expand Up @@ -304,7 +304,7 @@ describe('GameGateway (e2e)', () => {
title: 'Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});

// 순차적으둜 이벀트 처리
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('GameGateway (e2e)', () => {
title: 'Chat Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});

Expand Down Expand Up @@ -393,7 +393,7 @@ describe('GameGateway (e2e)', () => {
title: 'Chat Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});

Expand Down Expand Up @@ -442,7 +442,7 @@ describe('GameGateway (e2e)', () => {
title: 'Chat Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});

Expand Down Expand Up @@ -489,7 +489,7 @@ describe('GameGateway (e2e)', () => {
title: 'Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});
const gameId = createResponse.gameId;
Expand Down Expand Up @@ -531,7 +531,7 @@ describe('GameGateway (e2e)', () => {
title: 'Cache Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});
const gameId = createResponse.gameId;
Expand Down Expand Up @@ -613,7 +613,7 @@ describe('GameGateway (e2e)', () => {
title: 'Cache Hit Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});
const gameId = createResponse.gameId;
Expand Down Expand Up @@ -693,7 +693,7 @@ describe('GameGateway (e2e)', () => {
title: 'Expiry Test Room',
gameMode: 'RANKING',
maxPlayerCount: 5,
isPublicGame: true
isPublic: true
});
});
const gameId = createResponse.gameId;
Expand Down

0 comments on commit 00bf451

Please sign in to comment.