Skip to content

Commit

Permalink
feat(shulker-proxy-agent): release agones server if proxy is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Feb 6, 2024
1 parent 6cde3d9 commit 2aa396b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import java.util.logging.Logger
import kotlin.system.exitProcess

class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Logger) {
companion object {
private const val INITIAL_AGONES_RESERVATION_SECONDS = 180L
}

lateinit var agonesGateway: AgonesSDK
private lateinit var jedisPool: JedisPool

Expand Down Expand Up @@ -87,7 +91,7 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo
}

this.cache.registerProxy(Configuration.PROXY_NAME, this.proxyInterface.getPlayerCapacity())
this.agonesGateway.setAllocated()
this.agonesGateway.setReserved(INITIAL_AGONES_RESERVATION_SECONDS)
} catch (@Suppress("TooGenericExceptionCaught") e: Exception) {
this.logger.log(Level.SEVERE, "Shulker Agent crashed, stopping proxy", e)
this.shutdown()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ class PlayerMovementService(private val agent: ShulkerProxyAgentCommon) {
if (!this.acceptingPlayers) {
return PlayerPreLoginHookResult.disallow(MSG_NOT_ACCEPTING_PLAYERS)
}

return PlayerPreLoginHookResult.allow()
}

private fun onPlayerLogin(player: Player) {
this.agent.cache.updateCachedPlayerName(player.uniqueId, player.name)
this.agent.agonesGateway.setAllocated()

if (this.isProxyConsideredFull()) {
this.setAcceptingPlayers(false)
Expand All @@ -90,6 +92,10 @@ class PlayerMovementService(private val agent: ShulkerProxyAgentCommon) {
private fun onPlayerDisconnect(player: Player) {
this.agent.cache.unsetPlayerPosition(player.uniqueId)

if (this.agent.proxyInterface.getPlayerCount() == 0) {
this.agent.agonesGateway.setReady()
}

if (!this.isProxyConsideredFull()) {
this.setAcceptingPlayers(true)
}
Expand Down

0 comments on commit 2aa396b

Please sign in to comment.