Skip to content

Commit 24e3293

Browse files
committed
Merge remote-tracking branch 'origin/dev' into refactor/163
# Conflicts: # backend/src/main/java/io/f1/backend/domain/game/app/RoomService.java # backend/src/main/java/io/f1/backend/domain/game/websocket/controller/GameSocketController.java # backend/src/main/java/io/f1/backend/domain/game/websocket/eventlistener/WebsocketEventListener.java
2 parents f0ee4f2 + 739ebc9 commit 24e3293

File tree

23 files changed

+858
-154
lines changed

23 files changed

+858
-154
lines changed

backend/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ dependencies {
3737

3838
/* DATABASE */
3939
runtimeOnly 'com.mysql:mysql-connector-j'
40+
implementation 'org.flywaydb:flyway-mysql'
41+
implementation 'org.flywaydb:flyway-core'
4042

4143
/* MONITORING */
4244
implementation 'io.micrometer:micrometer-registry-prometheus'

backend/src/main/java/io/f1/backend/BackendApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import org.springframework.boot.autoconfigure.SpringBootApplication;
77
import org.springframework.boot.context.properties.EnableConfigurationProperties;
88
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
9+
import org.springframework.scheduling.annotation.EnableScheduling;
910

11+
@EnableScheduling
1012
@EnableJpaAuditing
1113
@SpringBootApplication
1214
@EnableConfigurationProperties(OAuthRedirectProperties.class)

backend/src/main/java/io/f1/backend/domain/game/app/ChatService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
public class ChatService {
2121

2222
private final RoomService roomService;
23-
private final TimerService timerService;
2423
private final MessageSender messageSender;
2524
private final ApplicationEventPublisher eventPublisher;
2625

@@ -41,7 +40,12 @@ public void chat(Long roomId, UserPrincipal userPrincipal, ChatMessage chatMessa
4140

4241
String answer = currentQuestion.getAnswer();
4342

44-
if (answer.equals(chatMessage.message())) {
43+
if (!answer.equals(chatMessage.message())) {
44+
return;
45+
}
46+
47+
// false -> true
48+
if (room.compareAndSetAnsweredFlag(false, true)) {
4549
eventPublisher.publishEvent(
4650
new GameCorrectAnswerEvent(
4751
room, userPrincipal.getUserId(), chatMessage, answer));

backend/src/main/java/io/f1/backend/domain/game/app/GameService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ public void onCorrectAnswer(GameCorrectAnswerEvent event) {
123123
ofPlayerEvent(chatMessage.nickname(), RoomEventType.CORRECT_ANSWER));
124124

125125
timerService.cancelTimer(room);
126+
room.compareAndSetAnsweredFlag(true, false);
126127

127128
if (!timerService.validateCurrentRound(room)) {
128129
gameEnd(room);
@@ -142,6 +143,12 @@ public void onCorrectAnswer(GameCorrectAnswerEvent event) {
142143
@EventListener
143144
public void onTimeout(GameTimeoutEvent event) {
144145
Room room = event.room();
146+
147+
// false -> true 여야 하는데 실패했을 때 => 이미 정답 처리가 된 경우 (onCorrectAnswer 로직 실행 중)
148+
if (!room.compareAndSetAnsweredFlag(false, true)) {
149+
return;
150+
}
151+
145152
log.debug(room.getId() + "번 방 타임아웃! 현재 라운드 : " + room.getCurrentRound());
146153

147154
String destination = getDestination(room.getId());
@@ -167,6 +174,8 @@ public void onTimeout(GameTimeoutEvent event) {
167174
destination,
168175
MessageType.QUESTION_START,
169176
toQuestionStartResponse(room, CONTINUE_DELAY));
177+
178+
room.compareAndSetAnsweredFlag(true, false);
170179
}
171180

172181
public void gameEnd(Room room) {

0 commit comments

Comments
 (0)