1515import io .f1 .backend .domain .game .dto .MessageType ;
1616import io .f1 .backend .domain .game .dto .RoomEventType ;
1717import io .f1 .backend .domain .game .dto .request .GameSettingChanger ;
18+ import io .f1 .backend .domain .game .dto .response .GameResultListResponse ;
19+ import io .f1 .backend .domain .game .dto .response .GameResultResponse ;
1820import io .f1 .backend .domain .game .dto .response .PlayerListResponse ;
1921import io .f1 .backend .domain .game .event .GameCorrectAnswerEvent ;
2022import io .f1 .backend .domain .game .event .GameTimeoutEvent ;
2123import io .f1 .backend .domain .game .event .RoomUpdatedEvent ;
24+ import io .f1 .backend .domain .game .model .ConnectionState ;
2225import io .f1 .backend .domain .game .model .Player ;
2326import io .f1 .backend .domain .game .model .Room ;
2427import io .f1 .backend .domain .game .model .RoomState ;
2730import io .f1 .backend .domain .question .entity .Question ;
2831import io .f1 .backend .domain .quiz .app .QuizService ;
2932import io .f1 .backend .domain .quiz .entity .Quiz ;
33+ import io .f1 .backend .domain .stat .app .StatService ;
3034import io .f1 .backend .domain .user .dto .UserPrincipal ;
3135import io .f1 .backend .global .exception .CustomException ;
3236import io .f1 .backend .global .exception .errorcode .GameErrorCode ;
@@ -52,6 +56,7 @@ public class GameService {
5256 private static final int CONTINUE_DELAY = 3 ;
5357 private static final String NONE_CORRECT_USER = "" ;
5458
59+ private final StatService statService ;
5560 private final QuizService quizService ;
5661 private final RoomService roomService ;
5762 private final TimerService timerService ;
@@ -167,10 +172,15 @@ public void gameEnd(Room room) {
167172 Map <String , Player > playerSessionMap = room .getPlayerSessionMap ();
168173
169174 // TODO : 랭킹 정보 업데이트
175+ GameResultListResponse gameResultListResponse = toGameResultListResponse (playerSessionMap ,
176+ room .getRound ());
177+
170178 messageSender .sendBroadcast (
171179 destination ,
172180 MessageType .GAME_RESULT ,
173- toGameResultListResponse (playerSessionMap , room .getGameSetting ().getRound ()));
181+ toGameResultListResponse (playerSessionMap , room .getRound ()));
182+
183+ updateRank (room , gameResultListResponse );
174184
175185 room .initializeRound ();
176186 room .initializePlayers ();
@@ -196,6 +206,32 @@ public void gameEnd(Room room) {
196206 destination , MessageType .ROOM_SETTING , toRoomSettingResponse (room ));
197207 }
198208
209+ private void updateRank (Room room , GameResultListResponse gameResultListResponse ) {
210+
211+ List <GameResultResponse > result = gameResultListResponse .result ();
212+
213+ for (GameResultResponse gameResultResponse : result ) {
214+ Long playerId = gameResultResponse .id ();
215+ int rank = gameResultResponse .rank ();
216+ int score = gameResultResponse .score ();
217+
218+ Player player = room .getPlayerByUserId (playerId );
219+
220+ if (Objects .equals (player .getState (), ConnectionState .DISCONNECTED )) {
221+ statService .updateRank (playerId , false , 0 );
222+ continue ;
223+ }
224+
225+ if (rank == 1 ) {
226+ statService .updateRank (playerId , true , score );
227+ continue ;
228+ }
229+
230+ statService .updateRank (playerId , false , score );
231+
232+ }
233+ }
234+
199235 public void handlePlayerReady (Long roomId , String sessionId ) {
200236
201237 Room room = findRoom (roomId );
0 commit comments