Skip to content

Commit

Permalink
feat(shulker-proxy-agent): grant all permissions to network admins
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylvln committed Nov 2, 2023
1 parent cafc0cb commit 0f96077
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import net.kyori.adventure.text.Component
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer
import net.md_5.bungee.api.ProxyServer
import net.md_5.bungee.api.connection.ProxiedPlayer
import net.md_5.bungee.api.event.PermissionCheckEvent
import net.md_5.bungee.api.event.PlayerDisconnectEvent
import net.md_5.bungee.api.event.PostLoginEvent
import net.md_5.bungee.api.event.PreLoginEvent
Expand Down Expand Up @@ -135,6 +136,21 @@ class ProxyInterfaceBungeeCord(
)
}

override fun prepareNetworkAdminsPermissions(playerIds: List<UUID>) {
this.proxy.pluginManager.registerListener(
this.plugin,
object : Listener {
@EventHandler(priority = EventPriority.HIGHEST)
fun onPermissionCheck(event: PermissionCheckEvent) {
val player = event.sender as? ProxiedPlayer ?: return
if (playerIds.contains(player.uniqueId)) {
event.setHasPermission(true)
}
}
}
)
}

override fun teleportPlayerOnServer(playerName: String, serverName: String) {
val server = this.proxy.getServerInfo(serverName)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package io.shulkermc.proxyagent

import java.util.UUID

object Configuration {
val PROXY_NAMESPACE = getStringEnv("SHULKER_PROXY_NAMESPACE")
val PROXY_NAME = getStringEnv("SHULKER_PROXY_NAME")
val PROXY_TTL_SECONDS = getLongEnv("SHULKER_PROXY_TTL_SECONDS")

val NETWORK_ADMINS = getStringEnv("SHULKER_NETWORK_ADMINS").split(",").map(UUID::fromString)

val REDIS_HOST = getStringEnv("SHULKER_PROXY_REDIS_HOST")
val REDIS_PORT = getIntEnv("SHULKER_PROXY_REDIS_PORT")
val REDIS_USERNAME = getOptionalStringEnv("SHULKER_PROXY_REDIS_USERNAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.shulkermc.proxyagent.platform.ProxyPingHook
import io.shulkermc.proxyagent.platform.ServerPostConnectHook
import io.shulkermc.proxyagent.platform.ServerPreConnectHook
import java.net.InetSocketAddress
import java.util.UUID
import java.util.concurrent.TimeUnit

interface ProxyInterface {
Expand All @@ -22,6 +23,7 @@ interface ProxyInterface {
fun addServerPreConnectHook(hook: ServerPreConnectHook, postOrder: HookPostOrder)
fun addServerPostConnectHook(hook: ServerPostConnectHook, postOrder: HookPostOrder)

fun prepareNetworkAdminsPermissions(playerIds: List<UUID>)
fun teleportPlayerOnServer(playerName: String, serverName: String)
fun getPlayerCount(): Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class ShulkerProxyAgentCommon(val proxyInterface: ProxyInterface, val logger: Lo
this.healthcheckTask = HealthcheckTask(this).schedule()
this.lostProxyPurgeTask = LostProxyPurgeTask(this).schedule()

if (Configuration.NETWORK_ADMINS.isNotEmpty()) {
this.proxyInterface.prepareNetworkAdminsPermissions(Configuration.NETWORK_ADMINS)
}

this.cache.registerProxy(Configuration.PROXY_NAME)
this.agonesGateway.setAllocated()
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.shulkermc.proxyagent.velocity

import com.velocitypowered.api.permission.PermissionFunction
import com.velocitypowered.api.permission.PermissionProvider
import com.velocitypowered.api.permission.PermissionSubject
import com.velocitypowered.api.permission.Tristate

class AdminPermissionProvider : PermissionProvider, PermissionFunction {
companion object {
val INSTANCE = AdminPermissionProvider()
}

override fun createFunction(subject: PermissionSubject?): PermissionFunction = this
override fun getPermissionValue(permission: String?): Tristate = Tristate.TRUE
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.velocitypowered.api.event.PostOrder
import com.velocitypowered.api.event.connection.DisconnectEvent
import com.velocitypowered.api.event.connection.LoginEvent
import com.velocitypowered.api.event.connection.PreLoginEvent
import com.velocitypowered.api.event.permission.PermissionsSetupEvent
import com.velocitypowered.api.event.player.ServerPostConnectEvent
import com.velocitypowered.api.event.player.ServerPreConnectEvent
import com.velocitypowered.api.event.proxy.ProxyPingEvent
Expand Down Expand Up @@ -110,6 +111,19 @@ class ProxyInterfaceVelocity(
) { event -> hook(this.wrapPlayer(event.player), event.player.currentServer.get().serverInfo.name) }
}

override fun prepareNetworkAdminsPermissions(playerIds: List<UUID>) {
this.proxy.eventManager.register(
this.plugin,
PermissionsSetupEvent::class.java,
PostOrder.LAST
) { event ->
val player = event.subject as? Player ?: return@register
if (playerIds.contains(player.uniqueId)) {
event.provider = AdminPermissionProvider.INSTANCE
}
}
}

override fun teleportPlayerOnServer(playerName: String, serverName: String) {
this.proxy.getPlayer(playerName).ifPresent { player ->
this.proxy.getServer(serverName).ifPresent { server ->
Expand Down

0 comments on commit 0f96077

Please sign in to comment.