mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-17 11:24:56 -04:00
eros: play: check if server type is active
This commit is contained in:
parent
49491141fe
commit
e257313205
@ -51,7 +51,14 @@ class PlayController : EmbeddedJavaFXController<Pane>() {
|
|||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
playTypeListViewFX.setCellFactory { ServerTypeCardController.build() }
|
playTypeListViewFX.setCellFactory { ServerTypeCardController.build() }
|
||||||
playTypeListViewFX.items += ServerTypes.VALUES
|
for (type in ServerTypes.VALUES) {
|
||||||
|
if (!type.active) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
playTypeListViewFX.items += type
|
||||||
|
}
|
||||||
|
// ToDo
|
||||||
|
check(playTypeListViewFX.items.size > 0)
|
||||||
|
|
||||||
|
|
||||||
playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
|
playTypeListViewFX.selectionModel.selectedItemProperty().addListener { _, _, new ->
|
||||||
|
@ -25,10 +25,11 @@ import org.kordamp.ikonli.fontawesome5.FontAwesomeSolid
|
|||||||
|
|
||||||
enum class ServerTypes(
|
enum class ServerTypes(
|
||||||
val icon: Ikon,
|
val icon: Ikon,
|
||||||
|
private val activeSupplier: (() -> Boolean)? = null,
|
||||||
private val countSupplier: () -> Int,
|
private val countSupplier: () -> Int,
|
||||||
) : Translatable {
|
) : Translatable {
|
||||||
CUSTOM(FontAwesomeSolid.SERVER, { Minosoft.config.config.server.entries.size }),
|
CUSTOM(FontAwesomeSolid.SERVER, null, { Minosoft.config.config.server.entries.size }),
|
||||||
LAN(FontAwesomeSolid.NETWORK_WIRED, { LANServerListener.SERVERS.size }),
|
LAN(FontAwesomeSolid.NETWORK_WIRED, { LANServerListener.active }, { LANServerListener.SERVERS.size }),
|
||||||
;
|
;
|
||||||
|
|
||||||
override val translationKey: ResourceLocation = "minosoft:server_type.${name.lowercase()}".asResourceLocation()
|
override val translationKey: ResourceLocation = "minosoft:server_type.${name.lowercase()}".asResourceLocation()
|
||||||
@ -36,6 +37,9 @@ enum class ServerTypes(
|
|||||||
val count: Int
|
val count: Int
|
||||||
get() = countSupplier()
|
get() = countSupplier()
|
||||||
|
|
||||||
|
val active: Boolean
|
||||||
|
get() = activeSupplier?.invoke() ?: true
|
||||||
|
|
||||||
companion object : ValuesEnum<ServerTypes> {
|
companion object : ValuesEnum<ServerTypes> {
|
||||||
override val VALUES: Array<ServerTypes> = values()
|
override val VALUES: Array<ServerTypes> = values()
|
||||||
override val NAME_MAP: Map<String, ServerTypes> = KUtil.getEnumValues(VALUES)
|
override val NAME_MAP: Map<String, ServerTypes> = KUtil.getEnumValues(VALUES)
|
||||||
|
@ -28,6 +28,8 @@ import java.nio.charset.StandardCharsets
|
|||||||
import java.util.concurrent.CountDownLatch
|
import java.util.concurrent.CountDownLatch
|
||||||
|
|
||||||
object LANServerListener {
|
object LANServerListener {
|
||||||
|
var active: Boolean = false
|
||||||
|
private set
|
||||||
val SERVERS: HashBiMap<InetAddress, Server> = HashBiMap.create()
|
val SERVERS: HashBiMap<InetAddress, Server> = HashBiMap.create()
|
||||||
private const val MOTD_START_STRING = "[MOTD]"
|
private const val MOTD_START_STRING = "[MOTD]"
|
||||||
private const val MOTD_END_STRING = "[/MOTD]"
|
private const val MOTD_END_STRING = "[/MOTD]"
|
||||||
@ -44,6 +46,7 @@ object LANServerListener {
|
|||||||
val buffer = ByteArray(256) // this should be enough, if the packet is longer, it is probably invalid
|
val buffer = ByteArray(256) // this should be enough, if the packet is longer, it is probably invalid
|
||||||
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Listening for LAN servers..." }
|
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Listening for LAN servers..." }
|
||||||
latch.countDown()
|
latch.countDown()
|
||||||
|
active = true
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
val packet = DatagramPacket(buffer, buffer.size)
|
val packet = DatagramPacket(buffer, buffer.size)
|
||||||
@ -75,6 +78,7 @@ object LANServerListener {
|
|||||||
latch.countDown()
|
latch.countDown()
|
||||||
}
|
}
|
||||||
SERVERS.clear()
|
SERVERS.clear()
|
||||||
|
active = false
|
||||||
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Stop listening for LAN servers..." }
|
Log.log(LogMessageType.NETWORK_STATUS, LogLevels.INFO) { "Stop listening for LAN servers..." }
|
||||||
}, "LAN Server Listener").start()
|
}, "LAN Server Listener").start()
|
||||||
latch.await()
|
latch.await()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user