eros: server status refresh button

This commit is contained in:
Bixilon 2021-07-24 21:16:18 +02:00
parent 9d9daca730
commit f63d386069
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 42 additions and 9 deletions

View File

@ -160,10 +160,19 @@ class ServerListController : EmbeddedJavaFXController<Pane>() {
} }
GridPane().let { GridPane().let {
it.columnConstraints += ColumnConstraints()
it.columnConstraints += ColumnConstraints()
it.columnConstraints += ColumnConstraints(0.0, -1.0, Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT, true) it.columnConstraints += ColumnConstraints(0.0, -1.0, Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT, true)
it.add(Button("Delete"), 1, 0) it.add(Button("Delete"), 1, 0)
it.add(Button("Edit"), 2, 0) it.add(Button("Edit"), 2, 0)
it.add(Button("Refresh").apply {
setOnAction {
serverCard.server.ping().ping()
}
isDisable = serverCard.server.ping != null && serverCard.server.ping?.state != StatusConnectionStates.PING_DONE && serverCard.server.ping?.state != StatusConnectionStates.ERROR
}, 3, 0)
it.add(Button("Connect").apply { it.add(Button("Connect").apply {
setOnAction { setOnAction {
isDisable = true isDisable = true
@ -193,7 +202,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>() {
(serverCard.server.forcedVersion ?: ping.serverVersion == null) || (serverCard.server.forcedVersion ?: ping.serverVersion == null) ||
Minosoft.config.config.account.selected?.connections?.containsKey(serverCard.server) == true Minosoft.config.config.account.selected?.connections?.containsKey(serverCard.server) == true
// ToDo: Also disable, if currently connecting // ToDo: Also disable, if currently connecting
}, 3, 0) }, 4, 0)
it.hgap = 5.0 it.hgap = 5.0

View File

@ -50,7 +50,10 @@ class JavaFXInitializer internal constructor() : Application() {
@Synchronized @Synchronized
fun start() { fun start() {
check(LATCH.count == 2) { "Already initialized!" } check(LATCH.count == 2) { "Already initialized!" }
Thread.setDefaultUncaughtExceptionHandler { _, exception -> exception.crash() } Thread.setDefaultUncaughtExceptionHandler { _, exception ->
exception.printStackTrace(Log.FATAL_PRINT_STREAM)
exception.crash()
}
Log.log(LogMessageType.JAVAFX, LogLevels.VERBOSE) { "Initializing JavaFX Toolkit..." } Log.log(LogMessageType.JAVAFX, LogLevels.VERBOSE) { "Initializing JavaFX Toolkit..." }
Thread({ Application.launch(JavaFXInitializer::class.java) }, "JavaFX Toolkit Initializing Thread").start() Thread({ Application.launch(JavaFXInitializer::class.java) }, "JavaFX Toolkit Initializing Thread").start()

View File

@ -34,6 +34,7 @@ import de.bixilon.minosoft.util.Util;
import de.bixilon.minosoft.util.logging.Log; import de.bixilon.minosoft.util.logging.Log;
import kotlin.jvm.Synchronized; import kotlin.jvm.Synchronized;
@Deprecated
public abstract class Network { public abstract class Network {
protected final Connection connection; protected final Connection connection;
protected int compressionThreshold = -1; protected int compressionThreshold = -1;

View File

@ -48,7 +48,7 @@ class StatusConnection(
var pingQuery: PingQuery? = null var pingQuery: PingQuery? = null
var lastPongEvent: StatusPongReceiveEvent? = null var lastPongEvent: StatusPongReceiveEvent? = null
lateinit var realAddress: ServerAddress var realAddress: ServerAddress? = null
private set private set
private var addresses: List<ServerAddress>? = null private var addresses: List<ServerAddress>? = null
@ -64,13 +64,15 @@ class StatusConnection(
get() = super.error get() = super.error
set(value) { set(value) {
super.error = value super.error = value
value?.let { state = StatusConnectionStates.ERROR } value?.let {
state = StatusConnectionStates.ERROR
protocolState = ProtocolStates.DISCONNECTED
}
} }
fun resolve() { private fun resolve() {
state = StatusConnectionStates.RESOLVING state = StatusConnectionStates.RESOLVING
error = null
var addresses = this.addresses var addresses = this.addresses
if (addresses == null) { if (addresses == null) {
@ -81,6 +83,19 @@ class StatusConnection(
} }
fun ping() { fun ping() {
if (protocolState != ProtocolStates.DISCONNECTED) {
error("Already connecting!")
}
realAddress = null
this.addresses = null
lastServerStatus = null
pingQuery = null
lastPongEvent = null
serverVersion = null
error = null
state = StatusConnectionStates.WAITING
DefaultThreadPool += execute@{ DefaultThreadPool += execute@{
try { try {
resolve() resolve()
@ -108,7 +123,7 @@ class StatusConnection(
when (value) { when (value) {
ProtocolStates.HANDSHAKING -> { ProtocolStates.HANDSHAKING -> {
state = StatusConnectionStates.HANDSHAKING state = StatusConnectionStates.HANDSHAKING
network.sendPacket(HandshakeC2SP(realAddress, ProtocolStates.STATUS, Versions.AUTOMATIC_VERSION.protocolId)) network.sendPacket(HandshakeC2SP(realAddress!!, ProtocolStates.STATUS, Versions.AUTOMATIC_VERSION.protocolId))
protocolState = ProtocolStates.STATUS protocolState = ProtocolStates.STATUS
} }
ProtocolStates.STATUS -> { ProtocolStates.STATUS -> {

View File

@ -89,6 +89,7 @@ public class BlockingSocketNetwork extends Network {
this.connection.setProtocolState(ProtocolStates.CONNECTING); this.connection.setProtocolState(ProtocolStates.CONNECTING);
this.socketReceiveThread = new Thread(() -> { this.socketReceiveThread = new Thread(() -> {
try { try {
this.shouldDisconnect = false;
this.socket = new Socket(); this.socket = new Socket();
this.socket.setSoTimeout(ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); this.socket.setSoTimeout(ProtocolDefinition.SOCKET_CONNECT_TIMEOUT);
this.socket.connect(new InetSocketAddress(address.getHostname(), address.getPort()), ProtocolDefinition.SOCKET_CONNECT_TIMEOUT); this.socket.connect(new InetSocketAddress(address.getHostname(), address.getPort()), ProtocolDefinition.SOCKET_CONNECT_TIMEOUT);
@ -133,6 +134,7 @@ public class BlockingSocketNetwork extends Network {
this.connection.setError(exception); this.connection.setError(exception);
disconnect(); disconnect();
} }
this.socketReceiveThread = null;
}, String.format("%d/Socket", this.connection.getConnectionId())); }, String.format("%d/Socket", this.connection.getConnectionId()));
this.socketReceiveThread.start(); this.socketReceiveThread.start();
} }
@ -210,6 +212,7 @@ public class BlockingSocketNetwork extends Network {
} }
} catch (IOException | InterruptedException ignored) { } catch (IOException | InterruptedException ignored) {
} }
this.socketSendThread = null;
}, String.format("%d/Sending", this.connection.getConnectionId())); }, String.format("%d/Sending", this.connection.getConnectionId()));
this.socketSendThread.start(); this.socketSendThread.start();
} }

View File

@ -32,8 +32,10 @@ object Log {
private val LOG_QUEUE = LinkedBlockingQueue<MessageToSend>() private val LOG_QUEUE = LinkedBlockingQueue<MessageToSend>()
private val SYSTEM_ERR_STREAM = System.err private val SYSTEM_ERR_STREAM = System.err
private val SYSTEM_OUT_STREAM = System.out private val SYSTEM_OUT_STREAM = System.out
private val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.WARN)
private val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.INFO) val FATAL_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.FATAL)
val ERROR_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.WARN)
val OUT_PRINT_STREAM: PrintStream = LogPrintStream(LogMessageType.OTHER, LogLevels.INFO)
init { init {