fix: 暂存
This commit is contained in:
@@ -239,10 +239,9 @@ public class GameServiceImpl implements GameService {
|
|||||||
List<RoomPlayerEntity> remaining = roomPlayerRepository.findByRoomId(roomId);
|
List<RoomPlayerEntity> remaining = roomPlayerRepository.findByRoomId(roomId);
|
||||||
|
|
||||||
if (remaining.isEmpty()) {
|
if (remaining.isEmpty()) {
|
||||||
// 无人了,房间标记为结束
|
// 无人了,物理删除房间(对局记录和走棋记录保留用于历史查询)
|
||||||
room.setStatus("finished");
|
gameRoomRepository.delete(room);
|
||||||
gameRoomRepository.save(room);
|
log.info("[游戏服务] 房间无人,已删除, roomId={}", roomId);
|
||||||
log.info("[游戏服务] 房间无人,标记为结束, roomId={}", roomId);
|
|
||||||
} else if (userId.equals(room.getCreatorId())) {
|
} else if (userId.equals(room.getCreatorId())) {
|
||||||
// 房主离开,顺位转让给下一个玩家
|
// 房主离开,顺位转让给下一个玩家
|
||||||
RoomPlayerEntity nextOwner = remaining.get(0);
|
RoomPlayerEntity nextOwner = remaining.get(0);
|
||||||
|
|||||||
@@ -229,10 +229,16 @@ public class GomokuGameServiceImpl implements GomokuGameService {
|
|||||||
)));
|
)));
|
||||||
|
|
||||||
if (remaining.isEmpty()) {
|
if (remaining.isEmpty()) {
|
||||||
// 无人了,房间标记为结束
|
// 无人了,关闭对局记录(如果进行中)并删除房间
|
||||||
room.setStatus("finished");
|
if ("playing".equals(room.getStatus())) {
|
||||||
gameRoomRepository.save(room);
|
gameRecordRepository.findByRoomId(roomId).ifPresent(record -> {
|
||||||
log.info("[五子棋] 房间无人,标记为结束, roomId={}", roomId);
|
record.setEndedAt(LocalDateTime.now());
|
||||||
|
record.setResultType("abandoned");
|
||||||
|
gameRecordRepository.save(record);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
gameRoomRepository.delete(room);
|
||||||
|
log.info("[五子棋] 房间无人,已删除, roomId={}", roomId);
|
||||||
// SSE: 大厅移除房间
|
// SSE: 大厅移除房间
|
||||||
sseEventPublisher.broadcast(SseEventType.ROOM_REMOVED, Map.of("roomId", roomId));
|
sseEventPublisher.broadcast(SseEventType.ROOM_REMOVED, Map.of("roomId", roomId));
|
||||||
} else if (userId.equals(room.getCreatorId())) {
|
} else if (userId.equals(room.getCreatorId())) {
|
||||||
@@ -382,6 +388,8 @@ public class GomokuGameServiceImpl implements GomokuGameService {
|
|||||||
log.info("[五子棋] 断线超时:对局中自动判负, roomId={}, userId={}", roomId, userId);
|
log.info("[五子棋] 断线超时:对局中自动判负, roomId={}, userId={}", roomId, userId);
|
||||||
// 自动认输
|
// 自动认输
|
||||||
resign(roomId, userId, sessionManager);
|
resign(roomId, userId, sessionManager);
|
||||||
|
// 移除断线玩家记录(对手仍留在房间,离开时触发删除)
|
||||||
|
leaveRoom(roomId, userId, sessionManager);
|
||||||
} else {
|
} else {
|
||||||
log.info("[五子棋] 断线超时:等待中自动离开, roomId={}, userId={}", roomId, userId);
|
log.info("[五子棋] 断线超时:等待中自动离开, roomId={}, userId={}", roomId, userId);
|
||||||
// 自动离开房间
|
// 自动离开房间
|
||||||
|
|||||||
Reference in New Issue
Block a user