Skip to content

Commit

Permalink
fix: 디스커넥트는 서버가 다 한다
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoziyun committed Dec 28, 2023
1 parent 8b477f9 commit 9b40c5c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/game/dto/emit-event-match-end-param.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { GameType } from '../../common/enum';

export class EmitEventMatchEndParamDto {
gameType: GameType;
rivalName: string;
rivalAvatar: string;
rivalScore: number | null;
myScore: number | null;
isWin: boolean | null;
Expand Down
19 changes: 12 additions & 7 deletions src/game/dto/game.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,24 @@ export class GameDto {

async setResult() {
if (this.gameType === GameType.NONE) {
this.scoreLeft = this.scoreRight = 0;
this.winnerId = this.playerLeftId;
this.winnerScore = 0;
this.winnerScore = this.loserScore = 0;
this.loserId = this.playerRightId;
this.loserScore = 0;
return;
}
if (this.loserId) {
this.loserScore = 0;
this.winnerScore = this.maxScore;
this.winnerId =
this.loserId === this.playerLeftId
? this.playerRightId
: this.playerLeftId;
const isLoserLeft = this.loserId === this.playerLeftId;
if (isLoserLeft) {
this.scoreLeft = this.loserScore = 0;
this.scoreRight = this.winnerScore = this.maxScore;
this.winnerId = this.playerRightId;
} else {
this.scoreRight = this.loserScore = 0;
this.scoreLeft = this.winnerScore = this.maxScore;
this.winnerId = this.playerLeftId;
}
} else {
if (this.scoreLeft === this.maxScore) {
this.winnerScore = this.scoreLeft;
Expand Down
6 changes: 6 additions & 0 deletions src/game/game.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
) {
const leftMatchEndParamDtos: EmitEventMatchEndParamDto = {
gameType: gameDto.gameType,
rivalName: right.nickname,
rivalAvatar: right.avatar,
rivalScore: gameDto.scoreRight,
myScore: gameDto.scoreLeft,
isWin: gameDto.scoreLeft > gameDto.scoreRight,
Expand All @@ -726,6 +728,8 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
};
const rightMatchEndParamDtos: EmitEventMatchEndParamDto = {
gameType: gameDto.gameType,
rivalName: left.nickname,
rivalAvatar: left.avatar,
rivalScore: gameDto.scoreLeft,
myScore: gameDto.scoreRight,
isWin: gameDto.scoreRight > gameDto.scoreLeft,
Expand All @@ -739,6 +743,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
console.log(
`${playerSockets.left.id}에 matchEnd 이벤트 보낸다 !!!`,
);
console.log(`내용은: ${JSON.stringify(leftMatchEndParamDtos)}`);
this.server
.to(playerSockets.left.id)
.emit(EVENT_MATCH_END, leftMatchEndParamDtos);
Expand All @@ -747,6 +752,7 @@ export class GameGateway implements OnGatewayConnection, OnGatewayDisconnect {
console.log(
`${playerSockets.right.id}에 matchEnd 이벤트 보낸다 !!!`,
);
console.log(`내용은: ${JSON.stringify(rightMatchEndParamDtos)}`);
this.server
.to(playerSockets.right.id)
.emit(EVENT_MATCH_END, rightMatchEndParamDtos);
Expand Down

0 comments on commit 9b40c5c

Please sign in to comment.