feat(multiplayer): auto rejection.
This commit is contained in:
@@ -176,8 +176,11 @@ public final class MessageDialogPane extends StackPane {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (timeout < 0) {
|
||||
if (timeout <= 0) {
|
||||
cancel();
|
||||
runInFX(() -> {
|
||||
cancelButton.fire();
|
||||
});
|
||||
return;
|
||||
}
|
||||
timeout -= 1000;
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.logging.Level;
|
||||
|
||||
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
||||
import static org.jackhuang.hmcl.ui.FXUtils.runInFX;
|
||||
import static org.jackhuang.hmcl.util.Lang.resolveException;
|
||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||
|
||||
@@ -215,7 +216,7 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
session.getServer().setOnClientAdding((client, resolveClient, rejectClient) -> {
|
||||
runInFX(() -> {
|
||||
Controllers.dialog(new MessageDialogPane.Builder(i18n("multiplayer.session.create.join.prompt", client.getUsername()), i18n("multiplayer.session.create.join"), MessageDialogPane.MessageType.INFO)
|
||||
.yesOrNo(resolveClient, () -> rejectClient.accept(""))
|
||||
.yesOrNo(resolveClient, () -> rejectClient.accept(i18n("multiplayer.session.join.wait_timeout")))
|
||||
.cancelOnTimeout(30 * 1000)
|
||||
.build());
|
||||
});
|
||||
@@ -314,20 +315,21 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
resolve.run();
|
||||
}, Platform::runLater)
|
||||
.exceptionally(throwable -> {
|
||||
if (throwable instanceof CancellationException) {
|
||||
Throwable resolved = resolveException(throwable);
|
||||
if (resolved instanceof CancellationException) {
|
||||
LOG.info("Connection rejected by the server");
|
||||
reject.accept(i18n("multiplayer.session.join.rejected"));
|
||||
return null;
|
||||
} else if (throwable instanceof MultiplayerManager.CatoAlreadyStartedException) {
|
||||
} else if (resolved instanceof MultiplayerManager.CatoAlreadyStartedException) {
|
||||
LOG.info("Cato already started");
|
||||
reject.accept(i18n("multiplayer.session.error.already_started"));
|
||||
return null;
|
||||
} else if (throwable instanceof MultiplayerManager.JoinRequestTimeoutException) {
|
||||
} else if (resolved instanceof MultiplayerManager.JoinRequestTimeoutException) {
|
||||
LOG.info("Cato already started");
|
||||
reject.accept(i18n("multiplayer.session.join.wait_timeout"));
|
||||
return null;
|
||||
} else {
|
||||
LOG.log(Level.WARNING, "Failed to join sessoin");
|
||||
LOG.log(Level.WARNING, "Failed to join session", resolved);
|
||||
reject.accept(i18n("multiplayer.session.join.error"));
|
||||
}
|
||||
return null;
|
||||
@@ -389,7 +391,9 @@ public class MultiplayerPage extends DecoratorAnimatedPage implements DecoratorP
|
||||
}
|
||||
|
||||
private void stopCatoSession() {
|
||||
getSession().stop();
|
||||
if (getSession() != null) {
|
||||
getSession().stop();
|
||||
}
|
||||
clearCatoSession();
|
||||
}
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ multiplayer.session.create.token.prompt=默认为临时 Token。你可以在 noi
|
||||
multiplayer.session.error.already_started=本地已经开启 cato 服务,请检查是否有其他 HMCL 正在运行联机服务。或者你可以在任务管理器里杀掉 cato 进程以继续。
|
||||
multiplayer.session.expired=联机会话连续使用时间超过了 3 小时,你需要重新创建/加入房间以继续联机。
|
||||
multiplayer.session.join=加入房间
|
||||
multiplayer.session.join.error=加入房间失败
|
||||
multiplayer.session.join.error=加入房间失败。如果你或对方的网络类型是差(对称型),可能无法使用联机功能。
|
||||
multiplayer.session.join.hint=你需要向已经创建好房间的玩家索要邀请码以便加入多人联机房间
|
||||
multiplayer.session.join.invitation_code=邀请码
|
||||
multiplayer.session.join.invitation_code.error=邀请码不正确,请向开服玩家获取邀请码
|
||||
|
||||
Reference in New Issue
Block a user