-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b476030
commit 9485bdd
Showing
45 changed files
with
1,715 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Title: Server Discovery Update | ||
Summary: Improved Server List | ||
|
||
## Multiplayer Menu | ||
- Replaced the "Featured" tab with "Discover" | ||
|
||
## Bug Fixes | ||
- Fixed crash when exporting in Flashback mod | ||
- Fixed crash when changing tick speed with G4mespeed mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
always=true | ||
new_ice_backend=true | ||
server_discovery=true | ||
updated_gifting_modal=true | ||
updated_coins_purchase_modal=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
gui/essential/src/main/kotlin/gg/essential/gui/serverdiscovery/VersionDownloadModal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2024 ModCore Inc. All rights reserved. | ||
* | ||
* This code is part of ModCore Inc.'s Essential Mod repository and is protected | ||
* under copyright registration # TX0009138511. For the full license, see: | ||
* https://github.com/EssentialGG/Essential/blob/main/LICENSE | ||
* | ||
* You may not use, copy, reproduce, modify, sell, license, distribute, | ||
* commercialize, or otherwise exploit, or create derivative works based | ||
* upon, this file or any other in this repository, all of which is reserved by Essential. | ||
*/ | ||
package gg.essential.gui.serverdiscovery | ||
|
||
import gg.essential.gui.EssentialPalette | ||
import gg.essential.gui.common.StyledButton | ||
import gg.essential.gui.common.modal.EssentialModal2 | ||
import gg.essential.gui.common.textStyle | ||
import gg.essential.gui.layoutdsl.Arrangement | ||
import gg.essential.gui.layoutdsl.LayoutScope | ||
import gg.essential.gui.layoutdsl.Modifier | ||
import gg.essential.gui.layoutdsl.color | ||
import gg.essential.gui.layoutdsl.image | ||
import gg.essential.gui.layoutdsl.row | ||
import gg.essential.gui.layoutdsl.tag | ||
import gg.essential.gui.layoutdsl.text | ||
import gg.essential.gui.layoutdsl.width | ||
import gg.essential.gui.layoutdsl.wrappedText | ||
import gg.essential.gui.overlay.ModalManager | ||
import gg.essential.util.openInBrowser | ||
import java.net.URI | ||
|
||
class VersionDownloadModal(modalManager: ModalManager, private val recommendedVersion: String) : EssentialModal2(modalManager) { | ||
override fun LayoutScope.layoutTitle() { | ||
wrappedText( | ||
"Your Minecraft version is not\nsupported. We recommend\nMinecraft $recommendedVersion to join.", | ||
Modifier.color(EssentialPalette.MODAL_TITLE_BLUE), | ||
centered = true | ||
) | ||
} | ||
|
||
override fun LayoutScope.layoutBody() { | ||
description("Easily install the required version\nusing the Essential Installer.") | ||
} | ||
|
||
override fun LayoutScope.layoutButtons() { | ||
row(Arrangement.spacedBy(8f)) { | ||
cancelButton("Cancel") | ||
|
||
styledButton( | ||
Modifier.width(91f).tag(PrimaryAction), | ||
style = StyledButton.Style.BLUE, | ||
action = { | ||
openInBrowser(URI.create("https://essential.gg/download")) | ||
} | ||
) { style -> | ||
row(Arrangement.spacedBy(5f)) { | ||
text("Download", Modifier.textStyle(style)) | ||
image(EssentialPalette.ARROW_UP_RIGHT_5X5, Modifier.textStyle(style)) | ||
} | ||
} | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...rc/main/kotlin/gg/essential/network/connectionmanager/knownservers/KnownServersManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2024 ModCore Inc. All rights reserved. | ||
* | ||
* This code is part of ModCore Inc.'s Essential Mod repository and is protected | ||
* under copyright registration # TX0009138511. For the full license, see: | ||
* https://github.com/EssentialGG/Essential/blob/main/LICENSE | ||
* | ||
* You may not use, copy, reproduce, modify, sell, license, distribute, | ||
* commercialize, or otherwise exploit, or create derivative works based | ||
* upon, this file or any other in this repository, all of which is reserved by Essential. | ||
*/ | ||
package gg.essential.network.connectionmanager.knownservers | ||
|
||
import gg.essential.connectionmanager.common.model.knownserver.KnownServer | ||
import gg.essential.connectionmanager.common.packet.knownservers.ClientKnownServersRequestPacket | ||
import gg.essential.connectionmanager.common.packet.knownservers.ServerKnownServersResponsePacket | ||
import gg.essential.gui.elementa.state.v2.State | ||
import gg.essential.gui.elementa.state.v2.combinators.map | ||
import gg.essential.gui.elementa.state.v2.mutableStateOf | ||
import gg.essential.network.CMConnection | ||
import gg.essential.network.connectionmanager.NetworkedManager | ||
import kotlinx.coroutines.launch | ||
import java.util.regex.Pattern | ||
|
||
class KnownServersManager(val connectionManager: CMConnection) : NetworkedManager { | ||
private val mutableKnownServers = mutableStateOf(listOf<KnownServer>()) | ||
val knownServers: State<List<KnownServer>> = mutableKnownServers | ||
|
||
private val serversByAddress = knownServers.map { servers -> | ||
servers.flatMap { server -> server.addresses.filter { !isRegex(it) }.map { it to server } }.toMap() | ||
} | ||
|
||
private val serversByRegex = knownServers.map { servers -> | ||
servers.flatMap { server -> server.addresses.filter{ isRegex(it) }.map { Pattern.compile(it) to server } }.toMap() | ||
} | ||
|
||
override fun onConnected() { | ||
connectionManager.connectionScope.launch { refreshKnownServers() } | ||
} | ||
|
||
private suspend fun refreshKnownServers() { | ||
val response = | ||
connectionManager.call(ClientKnownServersRequestPacket()) | ||
.exponentialBackoff() | ||
.await<ServerKnownServersResponsePacket>() | ||
mutableKnownServers.set(response.knownServers) | ||
} | ||
|
||
fun findServerByAddress(address: String): KnownServer? { | ||
serversByAddress.getUntracked()[address]?.let { return it } | ||
|
||
for ((pattern, server) in serversByRegex.getUntracked()) { | ||
if (pattern.matcher(address).matches()) { | ||
return server | ||
} | ||
} | ||
|
||
return null | ||
} | ||
|
||
fun normalizeAddress(address: String): String { | ||
findServerByAddress(address)?.let { return it.addresses[0] } | ||
return address | ||
} | ||
|
||
companion object { | ||
private fun isRegex(address: String) = address.startsWith("^") && address.endsWith("$") | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...otlin/gg/essential/network/connectionmanager/serverdiscovery/NewServerDiscoveryManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2024 ModCore Inc. All rights reserved. | ||
* | ||
* This code is part of ModCore Inc.'s Essential Mod repository and is protected | ||
* under copyright registration # TX0009138511. For the full license, see: | ||
* https://github.com/EssentialGG/Essential/blob/main/LICENSE | ||
* | ||
* You may not use, copy, reproduce, modify, sell, license, distribute, | ||
* commercialize, or otherwise exploit, or create derivative works based | ||
* upon, this file or any other in this repository, all of which is reserved by Essential. | ||
*/ | ||
package gg.essential.network.connectionmanager.serverdiscovery | ||
|
||
import gg.essential.connectionmanager.common.packet.serverdiscovery.ClientServerDiscoveryRequestPacket | ||
import gg.essential.connectionmanager.common.packet.serverdiscovery.ServerServerDiscoveryResponsePacket | ||
import gg.essential.gui.elementa.state.v2.State | ||
import gg.essential.gui.elementa.state.v2.mutableStateOf | ||
import gg.essential.network.connectionmanager.NetworkedManager | ||
import gg.essential.connectionmanager.common.model.serverdiscovery.Server | ||
import gg.essential.connectionmanager.common.packet.telemetry.ClientTelemetryPacket | ||
import gg.essential.network.CMConnection | ||
import gg.essential.network.connectionmanager.knownservers.KnownServersManager | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.launch | ||
import java.time.Instant | ||
import java.util.function.Consumer | ||
|
||
class NewServerDiscoveryManager( | ||
val connectionManager: CMConnection, | ||
val knownServersManager: KnownServersManager, | ||
val telemetryPacketConsumer: Consumer<ClientTelemetryPacket>, | ||
) : NetworkedManager { | ||
private var refreshServersJob: Job? = null | ||
|
||
private val mutableServers = mutableStateOf(Servers(listOf(), listOf())) | ||
val servers: State<Servers> = mutableServers | ||
|
||
override fun onConnected() { | ||
refreshServers() | ||
} | ||
|
||
fun refreshServers() { | ||
if (refreshServersJob == null || refreshServersJob?.isCompleted == true) { | ||
refreshServersJob = connectionManager.connectionScope.launch { | ||
val response = | ||
connectionManager.call(ClientServerDiscoveryRequestPacket()) | ||
.exponentialBackoff() | ||
.await<ServerServerDiscoveryResponsePacket>() | ||
mutableServers.set(Servers(response.featuredServers, response.recommendedServers)) | ||
} | ||
} | ||
} | ||
|
||
fun interface ImpressionConsumer : Consumer<String> | ||
|
||
inner class ImpressionTracker { | ||
private val featured = mutableSetOf<String>() | ||
private val recommended = mutableSetOf<String>() | ||
|
||
val featuredConsumer = ImpressionConsumer { trackImpression(it, featured::add) } | ||
val recommendedConsumer = ImpressionConsumer { trackImpression(it, recommended::add) } | ||
|
||
private fun trackImpression(ip: String, idConsumer: Consumer<String>) { | ||
knownServersManager.findServerByAddress(ip)?.also { idConsumer.accept(it.id) } | ||
} | ||
|
||
fun submit() { | ||
if (featured.isEmpty() && recommended.isEmpty()) return | ||
telemetryPacketConsumer.accept(ClientTelemetryPacket("DISCOVER_SERVER_IMPRESSION_1", mapOf( | ||
"featured" to featured.toSet(), | ||
"recommended" to recommended.toSet(), | ||
))) | ||
featured.clear() | ||
recommended.clear() | ||
} | ||
} | ||
|
||
data class Servers(val featured: List<Server>, val recommended: List<Server>) { | ||
fun isEmpty() = featured.isEmpty() && recommended.isEmpty() | ||
} | ||
|
||
companion object { | ||
val NEW_TAG_END_DATE = Instant.parse("2024-12-01T00:00:00Z") | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/gg/essential/mixins/transformers/client/gui/AbstractListAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 ModCore Inc. All rights reserved. | ||
* | ||
* This code is part of ModCore Inc.'s Essential Mod repository and is protected | ||
* under copyright registration # TX0009138511. For the full license, see: | ||
* https://github.com/EssentialGG/Essential/blob/main/LICENSE | ||
* | ||
* You may not use, copy, reproduce, modify, sell, license, distribute, | ||
* commercialize, or otherwise exploit, or create derivative works based | ||
* upon, this file or any other in this repository, all of which is reserved by Essential. | ||
*/ | ||
package gg.essential.mixins.transformers.client.gui; | ||
|
||
import gg.essential.mixins.DummyTarget; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@Mixin(DummyTarget.class) | ||
public class AbstractListAccessor { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.