From 110941bfdafaf388c7dd473b3f6ab1beb11672fb Mon Sep 17 00:00:00 2001 From: timtaran Date: Sun, 16 Aug 2026 15:42:00 +0500 Subject: [PATCH] feat: send players to original initialServer instead of keeping them in limbo when initialServers is empty (closes #45) --- CHANGELOG.md | 7 +++++++ build.gradle.kts | 2 +- .../spcode/navauth/common/config/GeneralConfig.kt | 2 +- .../velocity/infra/player/VelocityPlayerAdapter.kt | 3 +++ .../listener/velocity/ConnectionListeners.kt | 14 +++++++++++--- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49eb1da..528e4cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.1 + +### Changes +```diff ++ Send players to original initialServer instead of keeping them in limbo when initialServers is empty +``` + ## 0.2.0 diff --git a/build.gradle.kts b/build.gradle.kts index 8d479c7..00ba407 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ repositories { allprojects { group = "pl.spcode.navauth" - version = "0.2.0-SNAPSHOT" + version = "0.2.1-SNAPSHOT" } tasks.register("formatAll") { diff --git a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt index 6336db3..1a27b51 100644 --- a/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt +++ b/navauth-common/src/main/kotlin/pl/spcode/navauth/common/config/GeneralConfig.kt @@ -33,7 +33,7 @@ open class GeneralConfig : OkaeriConfig() { @Comment( "The backend servers players should be sent to after successful authentication.", "Players are LoadBalanced with 'least conn' by default.", - "If no servers are defined, then we won't do anything on the initial server event.", + "If no servers are defined, player will be sent to the initial server defined in velocity config.", ) var initialServers: List = listOf("paper") protected set diff --git a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/infra/player/VelocityPlayerAdapter.kt b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/infra/player/VelocityPlayerAdapter.kt index 64921f1..c0804a5 100644 --- a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/infra/player/VelocityPlayerAdapter.kt +++ b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/infra/player/VelocityPlayerAdapter.kt @@ -19,6 +19,7 @@ package pl.spcode.navauth.velocity.infra.player import com.velocitypowered.api.proxy.Player +import com.velocitypowered.api.proxy.server.RegisteredServer import net.kyori.adventure.text.Component import pl.spcode.navauth.common.component.TextColors import pl.spcode.navauth.common.domain.common.IPAddress @@ -28,6 +29,8 @@ import pl.spcode.navauth.common.domain.user.UserUuid class VelocityPlayerAdapter(val velocityPlayer: Player) : PlayerAdapter { + var originalInitialServer: RegisteredServer? = null + override fun getIPAddress(): IPAddress { return IPAddress.fromInetAddress(velocityPlayer.remoteAddress.address) } diff --git a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/listener/velocity/ConnectionListeners.kt b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/listener/velocity/ConnectionListeners.kt index f7b15ca..eb264e9 100644 --- a/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/listener/velocity/ConnectionListeners.kt +++ b/navauth-velocity/src/main/kotlin/pl/spcode/navauth/velocity/listener/velocity/ConnectionListeners.kt @@ -25,6 +25,7 @@ import com.velocitypowered.api.event.connection.DisconnectEvent import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent import com.velocitypowered.api.event.player.ServerPreConnectEvent import com.velocitypowered.api.proxy.Player +import kotlin.jvm.optionals.getOrNull import net.kyori.adventure.text.Component import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -136,7 +137,7 @@ constructor( } if (authSession.isAuthenticated) { - setInitialServerAuthenticated(event) + setInitialServerAuthenticated(event, authSession) } else { setInitialLimboUnauthenticated(event, authSession) } @@ -147,9 +148,14 @@ constructor( * If server found then sets it as the initial server, if there's no initial server defined, then * nothing happens. */ - private fun setInitialServerAuthenticated(event: PlayerChooseInitialServerEvent) { + private fun setInitialServerAuthenticated( + event: PlayerChooseInitialServerEvent, + authSession: AuthSession, + ) { val player = event.player - val initialServer = serverSelectionService.getInitialServer(player) + val initialServer = + serverSelectionService.getInitialServer(player) + ?: authSession.playerAdapter.originalInitialServer if (initialServer == null) { logger.debug( "PlayerChooseInitialServer: initial server not found for an authenticated user '${player.username}'" @@ -198,6 +204,8 @@ constructor( return } + authSession.playerAdapter.originalInitialServer = event.initialServer.getOrNull() + event.setInitialServer(limbo) logger.debug( "set user '{}' initial server to limbo server named {}",