Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.f1.backend.domain.game.model.Room;
import io.f1.backend.domain.game.websocket.MessageSender;
import io.f1.backend.domain.question.entity.Question;
import io.f1.backend.domain.user.dto.UserPrincipal;

import lombok.RequiredArgsConstructor;

Expand All @@ -24,7 +25,7 @@ public class ChatService {
private final ApplicationEventPublisher eventPublisher;

// todo 동시성적용
public void chat(Long roomId, String sessionId, ChatMessage chatMessage) {
public void chat(Long roomId, UserPrincipal userPrincipal, ChatMessage chatMessage) {

Room room = roomService.findRoom(roomId);

Expand All @@ -42,7 +43,8 @@ public void chat(Long roomId, String sessionId, ChatMessage chatMessage) {

if (answer.equals(chatMessage.message())) {
eventPublisher.publishEvent(
new GameCorrectAnswerEvent(room, sessionId, chatMessage, answer));
new GameCorrectAnswerEvent(
room, userPrincipal.getUserId(), chatMessage, answer));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public void onCorrectAnswer(GameCorrectAnswerEvent event) {

Room room = event.room();
log.debug(room.getId() + "번 방 채팅으로 정답! 현재 라운드 : " + room.getCurrentRound());
String sessionId = event.sessionId();
Long userId = event.userId();
ChatMessage chatMessage = event.chatMessage();
String answer = event.answer();

String destination = getDestination(room.getId());

room.increasePlayerCorrectCount(sessionId);
room.increasePlayerCorrectCount(userId);

messageSender.sendBroadcast(
destination,
Expand Down Expand Up @@ -168,13 +168,13 @@ public void gameEnd(Room room) {
Long roomId = room.getId();
String destination = getDestination(roomId);

Map<String, Player> playerSessionMap = room.getPlayerSessionMap();
Map<Long, Player> playerMap = room.getPlayerMap();

// TODO : 랭킹 정보 업데이트
messageSender.sendBroadcast(
destination,
MessageType.GAME_RESULT,
toGameResultListResponse(playerSessionMap, room.getGameSetting().getRound()));
toGameResultListResponse(playerMap, room.getGameSetting().getRound()));

room.initializeRound();
room.initializePlayers();
Expand All @@ -201,11 +201,11 @@ public void gameEnd(Room room) {
}

@DistributedLock(prefix = "room", key = "#roomId")
public void handlePlayerReady(Long roomId, String sessionId) {
public void handlePlayerReady(Long roomId, UserPrincipal userPrincipal) {

Room room = findRoom(roomId);

Player player = room.getPlayerBySessionId(sessionId);
Player player = room.getPlayerByUserId(userPrincipal.getUserId());

toggleReadyIfPossible(room, player);

Expand Down
Loading