bugfixes in server and cli-client
parent
ce739933cb
commit
e222ef6ce6
@ -1,43 +0,0 @@
|
|||||||
package eu.jonahbauer.wizard.client.cli.state;
|
|
||||||
|
|
||||||
import eu.jonahbauer.wizard.client.cli.Client;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.server.AckMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.server.Response;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.server.ServerMessage;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public final class AwaitingAcknowledgement extends Awaiting {
|
|
||||||
private final Supplier<ClientState> success;
|
|
||||||
private final Function<ServerMessage, ClientState> failure;
|
|
||||||
|
|
||||||
public AwaitingAcknowledgement(Supplier<ClientState> success, Function<ServerMessage, ClientState> failure) {
|
|
||||||
this.success = success;
|
|
||||||
this.failure = failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AwaitingAcknowledgement(Supplier<ClientState> success) {
|
|
||||||
this.success = success;
|
|
||||||
this.failure = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onEnter(Client client) {
|
|
||||||
client.println("Waiting for acknowledgment...");
|
|
||||||
return super.onEnter(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onMessage(Client client, ServerMessage message) {
|
|
||||||
if (message instanceof AckMessage) {
|
|
||||||
return Optional.of(success.get());
|
|
||||||
} else if (failure != null) {
|
|
||||||
return Optional.of(failure.apply(message));
|
|
||||||
} else {
|
|
||||||
return super.onMessage(client, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,16 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("org.springframework.boot").version("2.5.6")
|
id(SpringBoot.plugin) version SpringBoot.version
|
||||||
//id("io.spring.dependency-management").version("1.0.7-RELEASE")
|
id(SpringDependencyManagement.plugin) version SpringDependencyManagement.version
|
||||||
id("java")
|
id("java")
|
||||||
}
|
id("war")
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":wizard-core"))
|
implementation(project(":wizard-core"))
|
||||||
implementation(project(":wizard-common"))
|
implementation(project(":wizard-common"))
|
||||||
implementation("org.springframework.boot:spring-boot-starter-websocket:2.5.6")
|
implementation(SpringBoot.starterWebsocket) {
|
||||||
|
exclude(group = SpringBoot.group, module = "spring-boot-starter-logging")
|
||||||
|
}
|
||||||
|
implementation(SpringBoot.starterLog4j2)
|
||||||
|
providedRuntime(SpringBoot.starterTomcat)
|
||||||
}
|
}
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
package eu.jonahbauer.wizard.server.machine.states;
|
|
||||||
|
|
||||||
import eu.jonahbauer.wizard.common.messages.client.ClientMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.client.LeaveSessionMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.server.NackMessage;
|
|
||||||
import eu.jonahbauer.wizard.common.messages.server.StartingGameMessage;
|
|
||||||
import eu.jonahbauer.wizard.server.machine.ClientState;
|
|
||||||
import eu.jonahbauer.wizard.server.machine.Player;
|
|
||||||
import org.springframework.web.socket.CloseStatus;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class InGame implements ClientState {
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onEnter(Player context) {
|
|
||||||
context.send(new StartingGameMessage());
|
|
||||||
|
|
||||||
return ClientState.super.onEnter(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onExit(Player context) {
|
|
||||||
ClientState.super.onExit(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onOpen(Player player) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onMessage(Player player, ClientMessage message) {
|
|
||||||
if(message instanceof LeaveSessionMessage) {
|
|
||||||
//?
|
|
||||||
return Optional.empty();
|
|
||||||
} else {
|
|
||||||
player.send(new NackMessage(0, "Error: Invalid Message!"));
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Optional<ClientState> onClose(Player player, CloseStatus status) {
|
|
||||||
return Optional.empty();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue