fix(multiplayer): get ip from hiper log.
This commit is contained in:
@@ -217,6 +217,7 @@ public final class MultiplayerManager {
|
|||||||
|
|
||||||
public static class HiperSession extends ManagedProcess {
|
public static class HiperSession extends ManagedProcess {
|
||||||
private final EventManager<HiperExitEvent> onExit = new EventManager<>();
|
private final EventManager<HiperExitEvent> onExit = new EventManager<>();
|
||||||
|
private final EventManager<HiperIPEvent> onIPAllocated = new EventManager<>();
|
||||||
private final BufferedWriter writer;
|
private final BufferedWriter writer;
|
||||||
|
|
||||||
HiperSession(Process process, List<String> commands) {
|
HiperSession(Process process, List<String> commands) {
|
||||||
@@ -262,6 +263,11 @@ public final class MultiplayerManager {
|
|||||||
public EventManager<HiperExitEvent> onExit() {
|
public EventManager<HiperExitEvent> onExit() {
|
||||||
return onExit;
|
return onExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EventManager<HiperIPEvent> onIPAllocated() {
|
||||||
|
return onIPAllocated;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class HiperExitEvent extends Event {
|
public static class HiperExitEvent extends Event {
|
||||||
@@ -282,6 +288,19 @@ public final class MultiplayerManager {
|
|||||||
public static final int CERTIFICATE_EXPIRED = 11;
|
public static final int CERTIFICATE_EXPIRED = 11;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class HiperIPEvent extends Event {
|
||||||
|
private final String ip;
|
||||||
|
|
||||||
|
public HiperIPEvent(Object source, String ip) {
|
||||||
|
super(source);
|
||||||
|
this.ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIP() {
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class HiperExitException extends RuntimeException {
|
public static class HiperExitException extends RuntimeException {
|
||||||
private final int exitCode;
|
private final int exitCode;
|
||||||
private final boolean ready;
|
private final boolean ready;
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
||||||
@@ -57,6 +56,7 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
|||||||
private final StringProperty address = new SimpleStringProperty();
|
private final StringProperty address = new SimpleStringProperty();
|
||||||
|
|
||||||
private Consumer<MultiplayerManager.HiperExitEvent> onExit;
|
private Consumer<MultiplayerManager.HiperExitEvent> onExit;
|
||||||
|
private Consumer<MultiplayerManager.HiperIPEvent> onIPAllocated;
|
||||||
|
|
||||||
public MultiplayerPage() {
|
public MultiplayerPage() {
|
||||||
testNAT();
|
testNAT();
|
||||||
@@ -205,7 +205,11 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
|||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
MultiplayerManager.startHiper(globalConfig().getMultiplayerToken())
|
MultiplayerManager.startHiper(globalConfig().getMultiplayerToken())
|
||||||
.thenAcceptAsync(this.session::set, Schedulers.javafx())
|
.thenAcceptAsync(session -> {
|
||||||
|
this.session.set(session);
|
||||||
|
onExit = session.onExit().registerWeak(this::onExit);
|
||||||
|
onIPAllocated = session.onIPAllocated().registerWeak(this::onIPAllocated);
|
||||||
|
}, Schedulers.javafx())
|
||||||
.exceptionally(throwable -> {
|
.exceptionally(throwable -> {
|
||||||
runInFX(() -> Controllers.dialog(localizeErrorMessage(throwable), null, MessageDialogPane.MessageType.ERROR));
|
runInFX(() -> Controllers.dialog(localizeErrorMessage(throwable), null, MessageDialogPane.MessageType.ERROR));
|
||||||
return null;
|
return null;
|
||||||
@@ -221,6 +225,14 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
|||||||
|
|
||||||
private void clearSession() {
|
private void clearSession() {
|
||||||
this.session.set(null);
|
this.session.set(null);
|
||||||
|
this.onExit = null;
|
||||||
|
this.onIPAllocated = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onIPAllocated(MultiplayerManager.HiperIPEvent event) {
|
||||||
|
runInFX(() -> {
|
||||||
|
this.address.set(event.getIP());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onExit(MultiplayerManager.HiperExitEvent event) {
|
private void onExit(MultiplayerManager.HiperExitEvent event) {
|
||||||
|
|||||||
Reference in New Issue
Block a user