From d5a573f0320a6229c231e4ef2fa9e7bf10f24d93 Mon Sep 17 00:00:00 2001 From: forrest1398 <129135885+forrest1398@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:19:10 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix=20:=20Redis=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=EB=A5=BC=20=EC=B0=BE=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD=20(GameMemberEssentialDTO=20->?= =?UTF-8?q?=20=EB=8B=89=EB=84=A4=EC=9E=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/impl/GameRoomServiceImpl.java | 11 +++++++---- src/main/java/jungle/HandTris/domain/GameMember.java | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/jungle/HandTris/application/impl/GameRoomServiceImpl.java b/src/main/java/jungle/HandTris/application/impl/GameRoomServiceImpl.java index 95c4abf..9e3aab6 100644 --- a/src/main/java/jungle/HandTris/application/impl/GameRoomServiceImpl.java +++ b/src/main/java/jungle/HandTris/application/impl/GameRoomServiceImpl.java @@ -95,18 +95,21 @@ public GameRoom exitGameRoom(@UserNicknameFromJwt String nickname, String roomCo Pair memberDetails = memberProfileService.getMemberProfileWithStatsByNickname(nickname); GameMemberEssentialDTO dto = new GameMemberEssentialDTO(nickname, memberDetails.getFirst(), memberDetails.getSecond()); - if (!gameMember.isPresentMember(dto)) { + if (!gameMember.isPresentMember(nickname)) { throw new MemberNotFoundException(); } // gameMember에서 해당 유저 삭제 - gameMember.removeMember(dto); + gameMember.removeMember(nickname); - // Redis에 업데이트 + // 만약 인원이 0명이라면 if (gameRoom.getParticipantCount() == 0) { gameRoomRepository.delete(gameRoom); redisTemplate.delete(key); - } else { + } + // 인원이 남아있다면 + else { + redisTemplate.delete(key); redisTemplate.opsForValue().set(key, gameMember.toString()); } return gameRoom; diff --git a/src/main/java/jungle/HandTris/domain/GameMember.java b/src/main/java/jungle/HandTris/domain/GameMember.java index a0657ec..e01c38c 100644 --- a/src/main/java/jungle/HandTris/domain/GameMember.java +++ b/src/main/java/jungle/HandTris/domain/GameMember.java @@ -38,12 +38,16 @@ public void addMember(GameMemberEssentialDTO dto) { this.members.add(dto); } - public void removeMember(GameMemberEssentialDTO dto) { - this.members.remove(dto); + public void removeMember(String nickname) { + + GameMemberEssentialDTO foundDTO = this.members.stream().filter(gameMemberEssentialDTO -> gameMemberEssentialDTO.nickname().equals(nickname)).findAny().orElse(null); + this.members.remove(foundDTO); } - public boolean isPresentMember(GameMemberEssentialDTO dto) { - return this.members.contains(dto); + public boolean isPresentMember(String nickname) { + + GameMemberEssentialDTO foundDTO = this.members.stream().filter(gameMemberEssentialDTO -> gameMemberEssentialDTO.nickname().equals(nickname)).findAny().orElse(null); + return foundDTO != null; } public GameMember(String id, GameMemberEssentialDTO member) { From e109729f94597694447de1c3b3d04eb6a4561ce5 Mon Sep 17 00:00:00 2001 From: forrest1398 <129135885+forrest1398@users.noreply.github.com> Date: Sun, 14 Jul 2024 19:20:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EC=9C=A0=EC=A0=80=20=ED=83=88?= =?UTF-8?q?=EC=A3=BC=EC=8B=9C=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=9D=98=20?= =?UTF-8?q?board=20=EB=B3=80=EA=B2=BD=20(=20null=20=EA=B0=92=20->=20?= =?UTF-8?q?=EB=B9=88=20board=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/TetrisController.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/jungle/HandTris/presentation/TetrisController.java b/src/main/java/jungle/HandTris/presentation/TetrisController.java index 0d01ef1..bc06476 100644 --- a/src/main/java/jungle/HandTris/presentation/TetrisController.java +++ b/src/main/java/jungle/HandTris/presentation/TetrisController.java @@ -60,7 +60,26 @@ public void handleDisconnect(SimpMessageHeaderAccessor headerAccessor, @Destinat // message에서 isStart 확인 boolean isStart = headerAccessor.getFirstNativeHeader("isStart").equals("true"); if (isStart) { - String[][] emptyBoard = {{}}; + String[][] emptyBoard = {{"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "orange", "orange", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}, + {"#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030", "#303030"}}; // 탈주 유저의 상대에게 승리 메세지 보내기 ------------------------------ TetrisMessageReq win = new TetrisMessageReq(emptyBoard, true, false, false); String otherUser = headerAccessor.getHeader("otherUser").toString();