|
|
|
@ -6,10 +6,12 @@ import eu.jonahbauer.wizard.common.messages.server.*;
|
|
|
|
|
import eu.jonahbauer.wizard.common.model.Configuration;
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
@Log4j2
|
|
|
|
|
@Getter
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public final class AwaitingJoinSession extends Awaiting {
|
|
|
|
@ -21,7 +23,7 @@ public final class AwaitingJoinSession extends Awaiting {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Optional<ClientState> onEnter(Client client) {
|
|
|
|
|
System.out.println("Waiting for acknowledgment...");
|
|
|
|
|
log.info("Waiting for acknowledgment...");
|
|
|
|
|
client.getGame().setScreen(new LoadingScreen(client.getGame()));
|
|
|
|
|
return super.onEnter(client);
|
|
|
|
|
}
|
|
|
|
@ -29,19 +31,26 @@ public final class AwaitingJoinSession extends Awaiting {
|
|
|
|
|
@Override
|
|
|
|
|
public Optional<ClientState> onMessage(Client client, ServerMessage message) {
|
|
|
|
|
if (message instanceof SessionJoinedMessage joined) {
|
|
|
|
|
if (session != null && !session.equals(joined.getSession())) throw new RuntimeException();
|
|
|
|
|
if (session != null && !session.equals(joined.getSession())) {
|
|
|
|
|
return super.onMessage(client, message);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("There are {} players in this session.", joined.getPlayers().size());
|
|
|
|
|
log.info("Your uuid is {}.", joined.getPlayer());
|
|
|
|
|
log.info("Your secret is {}.", joined.getSecret());
|
|
|
|
|
return Optional.of(new Session(joined, sessionName, configuration, playerName));
|
|
|
|
|
}
|
|
|
|
|
} else if (message instanceof NackMessage nack) {
|
|
|
|
|
switch (nack.getCode()) {
|
|
|
|
|
case NackMessage.GAME_ALREADY_STARTED -> System.out.println("Error: Game has already started.");
|
|
|
|
|
case NackMessage.SESSION_FULL -> System.out.println("Error: The session is full.");
|
|
|
|
|
case NackMessage.SESSION_NOT_FOUND -> System.out.println("Error: Session not found.");
|
|
|
|
|
case NackMessage.NAME_TAKEN -> System.out.println("Error: Name already taken.");
|
|
|
|
|
case NackMessage.GAME_ALREADY_STARTED -> log.error("Game has already started.");
|
|
|
|
|
case NackMessage.SESSION_FULL -> log.error("The session is full.");
|
|
|
|
|
case NackMessage.SESSION_NOT_FOUND -> log.error("Session not found.");
|
|
|
|
|
case NackMessage.NAME_TAKEN -> log.error("Name already taken.");
|
|
|
|
|
default -> { return super.onMessage(client, message); }
|
|
|
|
|
}
|
|
|
|
|
return Optional.of(new AwaitingJoinLobby());
|
|
|
|
|
} else if (message instanceof SessionModifiedMessage || message instanceof SessionRemovedMessage) {
|
|
|
|
|
// drop
|
|
|
|
|
log.debug("Dropped message {}.", message);
|
|
|
|
|
return Optional.empty();
|
|
|
|
|
} else {
|
|
|
|
|
return super.onMessage(client, message);
|
|
|
|
|