wip: eros reconnecting

This commit is contained in:
Bixilon 2021-12-29 16:25:10 +01:00
parent ac528e5f1f
commit 4fdb8e4c79
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 20 additions and 9 deletions

View File

@ -18,6 +18,7 @@ import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.gui.eros.controller.DialogController
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.text
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import javafx.fxml.FXML
import javafx.scene.control.Button
@ -28,6 +29,7 @@ class KickDialog(
val header: Any,
val description: Any? = null,
val reason: ChatComponent,
val connection: PlayConnection? = null,
) : DialogController() {
@FXML private lateinit var headerFX: TextFlow
@FXML private lateinit var descriptionFX: TextFlow
@ -48,10 +50,12 @@ class KickDialog(
descriptionFX.text = description?.let { Minosoft.LANGUAGE_MANAGER.translate(it) } ?: ChatComponent.EMPTY
reasonFX.text = reason
reconnectButtonFX.isDisable = true // ToDo
closeButtonFX.setOnAction {
stage.hide()
if (connection == null) {
reconnectButtonFX.isDisable = true
} else {
reconnectButtonFX.setOnAction { connection.connect() }
}
closeButtonFX.setOnAction { stage.hide() }
}
companion object {

View File

@ -149,6 +149,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
header = "minosoft:connection.kick.header".toResourceLocation(),
description = TranslatableComponents.CONNECTION_KICK_DESCRIPTION(server, account),
reason = event.reason,
connection = connection,
).show()
})
connection.registerEvent(JavaFXEventInvoker.of<LoginKickEvent> { event ->
@ -159,11 +160,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
reason = event.reason,
).show()
})
val latch = CountUpAndDownLatch(0)
val assetsDialog = VerifyAssetsDialog(latch = latch).apply { show() }
connection.registerEvent(JavaFXEventInvoker.of<PlayConnectionStateChangeEvent> { if (it.state.disconnected) assetsDialog.close() })
ConnectingDialog(connection).show()
connection.connect(latch)
connect(connection)
}
}
}
@ -407,5 +404,13 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
"minosoft:server_info.active_connections".toResourceLocation() to { it.connections.size },
)
fun connect(connection: PlayConnection) {
val latch = CountUpAndDownLatch(0)
val assetsDialog = VerifyAssetsDialog(latch = latch).apply { show() }
connection.registerEvent(JavaFXEventInvoker.of<PlayConnectionStateChangeEvent> { if (it.state.disconnected) assetsDialog.close() })
ConnectingDialog(connection).show()
connection.connect(latch)
}
}
}

View File

@ -215,7 +215,9 @@ class PlayConnection(
fun connect(latch: CountUpAndDownLatch = CountUpAndDownLatch(0)) {
val count = latch.count
check(!wasConnected) { "Connection was already connected!" }
if (protocolState != ProtocolStates.DISCONNECTED) {
throw IllegalStateException("Still connected!")
}
try {
state = PlayConnectionStates.LOADING_ASSETS
fireEvent(RegistriesLoadEvent(this, registries, RegistriesLoadEvent.States.PRE))