Skip to content

Commit

Permalink
Merge pull request #91 from KU-Taverse/fix/taggame
Browse files Browse the repository at this point in the history
[Fix] 게임 결과 json 변환
  • Loading branch information
david-parkk authored Nov 1, 2024
2 parents 634a23d + 34a8f24 commit bb2cd6d
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kutaverse.game.websocket.taggame.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import kutaverse.game.taggame.domain.Role;
import kutaverse.game.taggame.repository.TagGameUserRepository;
import kutaverse.game.taggame.service.TagGameUserService;
Expand All @@ -18,7 +20,7 @@
@Component
public class TagGameEndHandler implements CustomHandler {

private final TagGameUserService tagGameUserService;
private ObjectMapper objectMapper = new ObjectMapper();
private final TagGameUserRepository tagGameUserRepository;

@Override
Expand Down Expand Up @@ -63,12 +65,20 @@ private void playerWin(TagGameRoom tagGameRoom) {
}

private void sendWinMessage(WebSocketSession webSocketSession) {
WebSocketMessage webSocketMessage = webSocketSession.textMessage("승리하였습니다.");
webSocketSession.send(Mono.just(webSocketMessage)).subscribe();
String winMessage = "승리하였습니다.";
try {
String jsonMessage = objectMapper.writeValueAsString(winMessage);
WebSocketMessage webSocketMessage = webSocketSession.textMessage(jsonMessage);
webSocketSession.send(Mono.just(webSocketMessage)).subscribe();
} catch (JsonProcessingException e) {}
}

private void sendLoseMessage(WebSocketSession webSocketSession) {
WebSocketMessage webSocketMessage = webSocketSession.textMessage("패배하였습니다.");
webSocketSession.send(Mono.just(webSocketMessage)).subscribe();
String winMessage = "패배하였습니다.";
try {
String jsonMessage = objectMapper.writeValueAsString(winMessage);
WebSocketMessage webSocketMessage = webSocketSession.textMessage(jsonMessage);
webSocketSession.send(Mono.just(webSocketMessage)).subscribe();
} catch (JsonProcessingException e) {}
}
}

0 comments on commit bb2cd6d

Please sign in to comment.