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 {
it.columnConstraints += ColumnConstraints()
it.columnConstraints += ColumnConstraints()
it.columnConstraints += ColumnConstraints(0.0, -1.0, Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT, true)
it.add(Button("Delete"), 1, 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 {
setOnAction {
isDisable = true
@ -193,7 +202,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>() {
(serverCard.server.forcedVersion ?: ping.serverVersion == null) ||
Minosoft.config.config.account.selected?.connections?.containsKey(serverCard.server) == true
// ToDo: Also disable, if currently connecting
}, 3, 0)
}, 4, 0)
it.hgap = 5.0

View File

@ -50,7 +50,10 @@ class JavaFXInitializer internal constructor() : Application() {
@Synchronized
fun start() {
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..." }
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 kotlin.jvm.Synchronized;
@Deprecated
public abstract class Network {
protected final Connection connection;
protected int compressionThreshold = -1;

View File

@ -48,7 +48,7 @@ class StatusConnection(
var pingQuery: PingQuery? = null
var lastPongEvent: StatusPongReceiveEvent? = null
lateinit var realAddress: ServerAddress
var realAddress: ServerAddress? = null
private set
private var addresses: List<ServerAddress>? = null
@ -64,13 +64,15 @@ class StatusConnection(
get() = super.error
set(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
error = null
var addresses = this.addresses
if (addresses == null) {
@ -81,6 +83,19 @@ class StatusConnection(
}
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@{
try {
resolve()
@ -108,7 +123,7 @@ class StatusConnection(
when (value) {
ProtocolStates.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
}
ProtocolStates.STATUS -> {

View File

@ -89,6 +89,7 @@ public class BlockingSocketNetwork extends Network {
this.connection.setProtocolState(ProtocolStates.CONNECTING);
this.socketReceiveThread = new Thread(() -> {
try {
this.shouldDisconnect = false;
this.socket = new Socket();
this.socket.setSoTimeout(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);
disconnect();
}
this.socketReceiveThread = null;
}, String.format("%d/Socket", this.connection.getConnectionId()));
this.socketReceiveThread.start();
}
@ -210,6 +212,7 @@ public class BlockingSocketNetwork extends Network {
}
} catch (IOException | InterruptedException ignored) {
}
this.socketSendThread = null;
}, String.format("%d/Sending", this.connection.getConnectionId()));
this.socketSendThread.start();
}

View File

@ -32,8 +32,10 @@ object Log {
private val LOG_QUEUE = LinkedBlockingQueue<MessageToSend>()
private val SYSTEM_ERR_STREAM = System.err
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 {