mirror of
https://github.com/YuzuZensai/Minikura.git
synced 2026-01-06 04:32:37 +00:00
🐛 fix: don't allow migrating to current proxy
This commit is contained in:
@@ -9,6 +9,7 @@ import cafe.kirameki.minikuraVelocity.utils.createWebSocketClient
|
|||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI
|
||||||
import com.velocitypowered.api.command.CommandManager
|
import com.velocitypowered.api.command.CommandManager
|
||||||
import com.velocitypowered.api.command.CommandMeta
|
import com.velocitypowered.api.command.CommandMeta
|
||||||
import com.velocitypowered.api.command.SimpleCommand
|
import com.velocitypowered.api.command.SimpleCommand
|
||||||
@@ -43,6 +44,7 @@ class Main @Inject constructor(private val logger: Logger, private val server: P
|
|||||||
private val apiUrl: String = System.getenv("MINIKURA_API_URL") ?: "http://localhost:3000"
|
private val apiUrl: String = System.getenv("MINIKURA_API_URL") ?: "http://localhost:3000"
|
||||||
private val websocketUrl: String = System.getenv("MINIKURA_WEBSOCKET_URL") ?: "ws://localhost:3000/ws"
|
private val websocketUrl: String = System.getenv("MINIKURA_WEBSOCKET_URL") ?: "ws://localhost:3000/ws"
|
||||||
private var acceptingTransfers = AtomicBoolean(false)
|
private var acceptingTransfers = AtomicBoolean(false)
|
||||||
|
private val redisBungeeApi = RedisBungeeAPI.getRedisBungeeApi()
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
fun onProxyInitialization(event: ProxyInitializeEvent?) {
|
fun onProxyInitialization(event: ProxyInitializeEvent?) {
|
||||||
@@ -85,6 +87,7 @@ class Main @Inject constructor(private val logger: Logger, private val server: P
|
|||||||
.plugin(this)
|
.plugin(this)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
// TODO: Rework this command and support <origin> and <destination> arguments
|
||||||
val migrateCommand = SimpleCommand { p ->
|
val migrateCommand = SimpleCommand { p ->
|
||||||
val source = p.source()
|
val source = p.source()
|
||||||
val args = p.arguments()
|
val args = p.arguments()
|
||||||
@@ -102,6 +105,11 @@ class Main @Inject constructor(private val logger: Logger, private val server: P
|
|||||||
return@SimpleCommand
|
return@SimpleCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (targetServer.name == redisBungeeApi.proxyId) {
|
||||||
|
source.sendMessage(Component.text("Target server cannot be the current proxy server."))
|
||||||
|
return@SimpleCommand
|
||||||
|
}
|
||||||
|
|
||||||
ProxyTransferUtils.migratePlayersToServer(targetServer)
|
ProxyTransferUtils.migratePlayersToServer(targetServer)
|
||||||
source.sendMessage(Component.text("Migrating players to server '$targetServerName'..."))
|
source.sendMessage(Component.text("Migrating players to server '$targetServerName'..."))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,13 @@ object ProxyTransferUtils {
|
|||||||
val targetAddress = InetSocketAddress(targetServer.address, targetServer.port)
|
val targetAddress = InetSocketAddress(targetServer.address, targetServer.port)
|
||||||
val currentProxyName = redisBungeeApi.proxyId
|
val currentProxyName = redisBungeeApi.proxyId
|
||||||
|
|
||||||
val players = server.allPlayers.toList()
|
val playerOnThisProxy = redisBungeeApi.getPlayersOnProxy(currentProxyName)
|
||||||
|
.map { it.toString() }
|
||||||
|
|
||||||
|
val players = server.allPlayers
|
||||||
|
.toList()
|
||||||
|
.filter { playerOnThisProxy.contains(it.uniqueId.toString()) }
|
||||||
|
|
||||||
val batchSize = (players.size * 0.05).coerceAtLeast(1.0).toInt() // 5% of players per batch to avoid overloading the server
|
val batchSize = (players.size * 0.05).coerceAtLeast(1.0).toInt() // 5% of players per batch to avoid overloading the server
|
||||||
|
|
||||||
var currentIndex = 0
|
var currentIndex = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user