Skip to content

Commit

Permalink
Merge pull request #92 from KU-Taverse/fix/taggame
Browse files Browse the repository at this point in the history
[FIx] 게임 종료 response 추가
  • Loading branch information
david-parkk authored Nov 1, 2024
2 parents bb2cd6d + 8832684 commit cec4444
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package kutaverse.game.websocket.taggame.dto.response;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@AllArgsConstructor
@Builder
@Getter
public class TagGameEndResponse {

private String message;

public static TagGameEndResponse toDto(String message){
return TagGameEndResponse.builder()
.message(message)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import kutaverse.game.websocket.taggame.dto.request.TagGameEndRequest;
import kutaverse.game.websocket.taggame.dto.request.TagGameRequest;
import kutaverse.game.websocket.taggame.dto.request.TagGameResultStatus;
import kutaverse.game.websocket.taggame.dto.response.TagGameEndResponse;
import kutaverse.game.websocket.taggame.util.TagGameRoom;
import kutaverse.game.websocket.taggame.util.TagGameRoomManager;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -66,17 +67,19 @@ private void playerWin(TagGameRoom tagGameRoom) {

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

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

0 comments on commit cec4444

Please sign in to comment.