Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 게임 결과 json 변환 #91

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Changes from all 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
@@ -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) {}
}
}
Loading