reconnect in server and cli
This commit is contained in:
@@ -6,6 +6,7 @@ import eu.jonahbauer.wizard.client.cli.state.Lobby;
|
||||
import eu.jonahbauer.wizard.client.cli.state.Menu;
|
||||
import eu.jonahbauer.wizard.common.messages.client.CreateSessionMessage;
|
||||
import eu.jonahbauer.wizard.common.messages.client.JoinSessionMessage;
|
||||
import eu.jonahbauer.wizard.common.messages.client.RejoinMessage;
|
||||
import eu.jonahbauer.wizard.common.messages.data.SessionData;
|
||||
import eu.jonahbauer.wizard.common.model.Configuration;
|
||||
import lombok.Getter;
|
||||
@@ -85,6 +86,16 @@ public class LobbyCommand {
|
||||
return new AwaitingJoinSession();
|
||||
}
|
||||
|
||||
@Command(name = "rejoin")
|
||||
public AwaitingJoinSession rejoin(
|
||||
@Parameters(index = "0", paramLabel = "<session>", description = "session uuid", completionCandidates = SessionCompleter.class) UUID session,
|
||||
@Parameters(index = "1", paramLabel = "<player>", description = "player uuid") UUID player,
|
||||
@Parameters(index = "2", paramLabel = "<secret>", description = "player secret") String secret
|
||||
) {
|
||||
client.send(new RejoinMessage(session, player, secret));
|
||||
return new AwaitingJoinSession();
|
||||
}
|
||||
|
||||
public static class SessionCompleter implements Iterable<String> {
|
||||
private final Lobby lobby;
|
||||
|
||||
|
@@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
public final class Game extends BaseState {
|
||||
private final UUID self;
|
||||
private final UUID session;
|
||||
private final String secret;
|
||||
|
||||
private final Map<UUID, String> players;
|
||||
private final Map<UUID, Integer> scores = new HashMap<>();
|
||||
@@ -37,9 +38,10 @@ public final class Game extends BaseState {
|
||||
private Card trumpCard;
|
||||
private Card.Suit trumpSuit;
|
||||
|
||||
public Game(UUID self, UUID session, Map<UUID, String> players) {
|
||||
public Game(UUID self, UUID session, String secret, Map<UUID, String> players) {
|
||||
this.self = self;
|
||||
this.session = session;
|
||||
this.secret = secret;
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
@@ -185,6 +187,7 @@ public final class Game extends BaseState {
|
||||
return Optional.of(new Session(
|
||||
self,
|
||||
session,
|
||||
secret,
|
||||
false,
|
||||
players.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
|
@@ -20,6 +20,7 @@ public final class Session extends BaseState {
|
||||
|
||||
private final UUID self;
|
||||
private final UUID session;
|
||||
private final String secret;
|
||||
private final Map<UUID, PlayerData> players = new HashMap<>();
|
||||
|
||||
private boolean ready;
|
||||
@@ -30,12 +31,14 @@ public final class Session extends BaseState {
|
||||
this.self = joined.getPlayer();
|
||||
this.session = joined.getSession();
|
||||
this.ready = false;
|
||||
this.secret = joined.getSecret();
|
||||
joined.getPlayers().forEach(player -> players.put(player.getUuid(), player));
|
||||
}
|
||||
|
||||
public Session(UUID self, UUID session, boolean ready, Map<UUID, PlayerData> players) {
|
||||
public Session(UUID self, UUID session, String secret, boolean ready, Map<UUID, PlayerData> players) {
|
||||
this.self = self;
|
||||
this.session = session;
|
||||
this.secret = secret;
|
||||
this.players.putAll(players);
|
||||
this.ready = ready;
|
||||
}
|
||||
@@ -47,6 +50,7 @@ public final class Session extends BaseState {
|
||||
} else {
|
||||
client.printfln("Successfully joined session %s. There are %d other players.", session, players.size() - 1);
|
||||
}
|
||||
client.printfln("You are %s. Your secret is %s", self, secret);
|
||||
return super.onEnter(client);
|
||||
}
|
||||
|
||||
@@ -70,6 +74,7 @@ public final class Session extends BaseState {
|
||||
return Optional.of(new Game(
|
||||
self,
|
||||
session,
|
||||
secret,
|
||||
players.values().stream().collect(Collectors.toMap(PlayerData::getUuid, PlayerData::getName))
|
||||
));
|
||||
} else if (nextReady != null && message instanceof NackMessage nack) {
|
||||
|
Reference in New Issue
Block a user