fix: fix cannot reset room's bug
This commit is contained in:
parent
da60653963
commit
2b3b8fa9e6
@ -197,6 +197,8 @@ public class ChessController {
|
||||
WebSocketUtils.sendPacketIfPossible(new PlayerWinPacket(), roomByPlayer.getBlackSession());
|
||||
WebSocketUtils.sendPacketIfPossible(new PlayerLosePacket(), roomByPlayer.getWhiteSession());
|
||||
}
|
||||
roomByPlayer.setState(Room.RoomState.FINISHED);
|
||||
roomByPlayer.broadcast(roomByPlayer.getRoomInfo(users));
|
||||
});
|
||||
}
|
||||
if (payload instanceof ResetRoomRequest) {
|
||||
|
@ -64,11 +64,14 @@ public class Room {
|
||||
WebSocketUtils.sendPacket(new PlayerSideAllocationPacket(false), session);
|
||||
WebSocketUtils.sendPacketIfPossible(new PlayerJoinRoomPacket(user, this), whiteSession);
|
||||
this.blackSession = session;
|
||||
this.setState(RoomState.GAMING);
|
||||
} else {
|
||||
WebSocketUtils.sendPacket(new PlayerSideAllocationPacket(true), session);
|
||||
WebSocketUtils.sendPacketIfPossible(new PlayerJoinRoomPacket(user, this), blackSession);
|
||||
this.whiteSession = session;
|
||||
}
|
||||
if (this.isFull()) {
|
||||
this.setState(RoomState.GAMING);
|
||||
} else {
|
||||
this.setState(RoomState.WAITING);
|
||||
}
|
||||
return Optional.empty();
|
||||
@ -96,7 +99,7 @@ public class Room {
|
||||
Session blackSession = this.getBlackSession();
|
||||
User whiteUser = whiteSession != null ? users.get(whiteSession.getId()) : null;
|
||||
User blackUser = blackSession != null ? users.get(blackSession.getId()) : null;
|
||||
return new RoomInfoPacket(this.id, whiteUser, blackUser, this.state, pieces);
|
||||
return new RoomInfoPacket(this.id, whiteUser, blackUser, this.state, pieces, this.isWhiteAcceptRestart, this.isBlackAcceptRestart, this.canWhiteDown);
|
||||
}
|
||||
|
||||
public void broadcast(Object packet) {
|
||||
@ -164,6 +167,11 @@ public class Room {
|
||||
}
|
||||
if (isBlackAcceptRestart && isWhiteAcceptRestart) {
|
||||
this.resetPieces();
|
||||
if (whiteSession == null || blackSession == null) {
|
||||
this.setState(RoomState.WAITING);
|
||||
return;
|
||||
}
|
||||
this.setState(RoomState.GAMING);
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +191,8 @@ public class Room {
|
||||
public enum RoomState {
|
||||
CREATED,
|
||||
WAITING,
|
||||
GAMING
|
||||
GAMING,
|
||||
FINISHED
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
@ -5,5 +5,6 @@ import org.mmga.clubs.entities.user.User;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record RoomInfoPacket(UUID roomId, User whiteUser, User blackUser, Room.RoomState state, byte[][] pieces) {
|
||||
public record RoomInfoPacket(UUID roomId, User whiteUser, User blackUser, Room.RoomState state, byte[][] pieces,
|
||||
boolean whiteRequestRestart, boolean blackRequestRestart, boolean canWhiteDown) {
|
||||
}
|
||||
|
@ -3,5 +3,8 @@ package org.mmga.clubs.entities.user;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@Schema(description = "用户登录参数类")
|
||||
public record UserLoginVo(@Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED) String username, @Schema(description = "用户密码(使用MD5摘要后的hex字符串)") String password/*, @Schema(description = "验证码密钥") String key, @Schema(description = "验证码") String code*/) {
|
||||
public record UserLoginVo(@Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED) String username,
|
||||
@Schema(description = "用户密码(使用MD5摘要后的hex字符串)") String password,
|
||||
@Schema(description = "验证码密钥") String key,
|
||||
@Schema(description = "验证码") String code) {
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user