Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

Commit 812f598

Browse files
committed
feat: add whitelist support and associated networking protocols
- Implemented whitelist service, repository, and data models (`WhitelistEntry`, `MutableWhitelistEntry`, `WhitelistStatus`, etc.). - Added new network protocols for whitelist operations, including `ServerboundRequestWhitelistPacket`, `WhitelistResponsePacket`, and others. - Introduced `CloudPlayerWhitelistManagerImpl` for managing player whitelists. - Enhanced `CloudServer` and `ProxyCloudServer` with companion methods for retrieving entries. - Integrated whitelist handling across Cloud API and Core modules. - Removed unused `ArgumentSuggestion` and `LtwTestAspect` components.
1 parent 741faa2 commit 812f598

File tree

61 files changed

+1492
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1492
-49
lines changed

.idea/externalDependencies.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
22
import dev.slne.surf.surfapi.gradle.util.slnePublic
3+
import jdk.javadoc.internal.tool.resources.javadoc
4+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmExtension
35

46
buildscript {
57
repositories {
@@ -45,6 +47,13 @@ allprojects {
4547
testImplementation(kotlin("test"))
4648
}
4749

50+
afterEvaluate {
51+
extensions.findByType<KotlinJvmExtension>()?.apply {
52+
compilerOptions {
53+
freeCompilerArgs.add("-Xnested-type-aliases")
54+
}
55+
}
56+
}
4857

4958
tasks {
5059
configureShadowJar()

surf-cloud-api/surf-cloud-api-client/surf-cloud-api-client-common/src/main/kotlin/dev/slne/surf/cloud/api/client/server/CloudClientServerManager.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@ package dev.slne.surf.cloud.api.client.server
22

33
import dev.slne.surf.cloud.api.common.server.CloudServer
44
import dev.slne.surf.cloud.api.common.server.CloudServerManager
5+
import dev.slne.surf.cloud.api.common.server.CommonCloudServer
6+
import dev.slne.surf.cloud.api.common.server.ProxyCloudServer
57
import dev.slne.surf.cloud.api.common.util.annotation.InternalApi
68

79
interface CloudClientServerManager : CloudServerManager {
10+
fun current(): CommonCloudServer
811
fun currentServer(): CloudServer
12+
fun currentProxy(): ProxyCloudServer
913

1014
@OptIn(InternalApi::class)
1115
companion object :
1216
CloudClientServerManager by CloudServerManager.instance as CloudClientServerManager
17+
}
18+
19+
fun CommonCloudServer.Companion.current(): CommonCloudServer {
20+
return CloudClientServerManager.current()
21+
}
22+
23+
fun CloudServer.Companion.current(): CloudServer {
24+
return CloudClientServerManager.currentServer()
25+
}
26+
27+
fun ProxyCloudServer.Companion.current(): ProxyCloudServer {
28+
return CloudClientServerManager.currentProxy()
1329
}

surf-cloud-api/surf-cloud-api-client/surf-cloud-api-client-velocity/src/main/kotlin/dev/slne/surf/cloud/api/client/velocity/command/args/CloudServerGroupArgument.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import dev.jorel.commandapi.arguments.ArgumentSuggestions
1111
import dev.jorel.commandapi.arguments.CommandAPIArgumentType
1212
import dev.jorel.commandapi.executors.CommandArguments
1313
import dev.slne.surf.cloud.api.common.server.CloudServerManager
14+
import dev.slne.surf.cloud.api.common.server.CommonCloudServer
1415
import dev.slne.surf.cloud.api.common.util.annotation.InternalApi
1516
import dev.slne.surf.surfapi.core.api.messages.adventure.text
1617

@@ -22,7 +23,7 @@ class CloudServerGroupArgument(nodeName: String) :
2223

2324
init {
2425
replaceSuggestions(ArgumentSuggestions.stringCollection {
25-
CloudServerManager.retrieveAllServers()
26+
CommonCloudServer.all()
2627
.filter { it.group.isNotEmpty() }
2728
.map { it.group }
2829
.distinct()

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/player/OfflineCloudPlayer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import dev.slne.surf.cloud.api.common.netty.network.codec.kotlinx.cloud.OfflineC
44
import dev.slne.surf.cloud.api.common.player.name.NameHistory
55
import dev.slne.surf.cloud.api.common.player.playtime.Playtime
66
import dev.slne.surf.cloud.api.common.player.punishment.CloudPlayerPunishmentManager
7+
import dev.slne.surf.cloud.api.common.player.whitelist.CloudPlayerWhitelistManager
78
import dev.slne.surf.cloud.api.common.server.CloudServer
89
import kotlinx.serialization.Serializable
910
import net.kyori.adventure.text.Component
@@ -34,6 +35,7 @@ interface OfflineCloudPlayer {
3435
val player: CloudPlayer?
3536

3637
val punishmentManager: CloudPlayerPunishmentManager
38+
val whitelistManager: CloudPlayerWhitelistManager
3739

3840
/**
3941
* Suspends until the display name of the player is retrieved.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package dev.slne.surf.cloud.api.common.player.whitelist
2+
3+
import dev.slne.surf.cloud.api.common.server.CloudServer
4+
import org.jetbrains.annotations.ApiStatus
5+
6+
@ApiStatus.NonExtendable
7+
interface CloudPlayerWhitelistManager {
8+
suspend fun whitelistStatusForGroup(group: WhitelistEntry.Group): WhitelistStatus
9+
suspend fun whitelistStatusForServer(server: CloudServer): WhitelistStatus
10+
suspend fun whitelistStatusForServer(serverName: WhitelistEntry.ServerName): WhitelistStatus
11+
12+
suspend fun whitelistForGroup(group: WhitelistEntry.Group): WhitelistEntry?
13+
suspend fun whitelistForServer(server: CloudServer): WhitelistEntry?
14+
suspend fun whitelistForServer(serverName: WhitelistEntry.ServerName): WhitelistEntry?
15+
16+
17+
suspend fun editWhitelistForGroup(
18+
group: WhitelistEntry.Group,
19+
edit: MutableWhitelistEntry.() -> Unit
20+
): Boolean
21+
22+
suspend fun editWhitelistForServer(
23+
server: CloudServer,
24+
edit: MutableWhitelistEntry.() -> Unit
25+
): Boolean
26+
27+
suspend fun editWhitelistForServer(
28+
serverName: WhitelistEntry.ServerName,
29+
edit: MutableWhitelistEntry.() -> Unit
30+
): Boolean
31+
32+
suspend fun createWhitelistForGroup(blocked: Boolean, group: WhitelistEntry.Group): WhitelistEntry?
33+
suspend fun createWhitelistForServer(blocked: Boolean, server: CloudServer): WhitelistEntry?
34+
suspend fun createWhitelistForServer(blocked: Boolean, serverName: WhitelistEntry.ServerName): WhitelistEntry?
35+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package dev.slne.surf.cloud.api.common.player.whitelist
2+
3+
import dev.slne.surf.cloud.api.common.server.CloudServer
4+
import dev.slne.surf.cloud.api.common.util.Either
5+
import java.time.ZonedDateTime
6+
import java.util.*
7+
8+
interface WhitelistEntry {
9+
val uuid: UUID
10+
val groupOrServerName: Either<Group, ServerName>
11+
val blocked: Boolean
12+
13+
val createdAt: ZonedDateTime
14+
val updatedAt: ZonedDateTime
15+
16+
typealias Group = String
17+
typealias ServerName = String
18+
}
19+
20+
21+
interface MutableWhitelistEntry : WhitelistEntry {
22+
override var blocked: Boolean
23+
fun forGroup(group: String)
24+
fun forServer(server: CloudServer)
25+
fun forServer(serverName: String)
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dev.slne.surf.cloud.api.common.player.whitelist
2+
3+
import dev.slne.surf.cloud.api.common.CloudInstance
4+
import dev.slne.surf.cloud.api.common.server.CloudServer
5+
import it.unimi.dsi.fastutil.objects.ObjectSet
6+
import org.jetbrains.annotations.Unmodifiable
7+
8+
interface WhitelistSettings {
9+
fun enforcedGroups(): @Unmodifiable ObjectSet<String>
10+
fun enforcedServers(): @Unmodifiable ObjectSet<String>
11+
12+
fun isWhitelistEnforcedFor(server: CloudServer): Boolean
13+
fun isWhitelistEnforcedForGroup(group: String): Boolean
14+
fun isWhitelistEnforcedForServer(server: String): Boolean
15+
16+
fun enforceWhitelistForGroup(group: String)
17+
fun enforceWhitelistForServer(server: String)
18+
fun enforceWhitelistForServer(server: CloudServer)
19+
20+
fun disableWhitelistForGroup(group: String)
21+
fun disableWhitelistForServer(server: String)
22+
fun disableWhitelistForServer(server: CloudServer)
23+
24+
25+
/**
26+
* Refreshes the whitelist-enforcement state for all online players
27+
* and disconnects anyone that is not permitted to stay.
28+
*/
29+
fun refresh()
30+
31+
companion object : WhitelistSettings by CloudInstance.getBean(WhitelistSettings::class.java)
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dev.slne.surf.cloud.api.common.player.whitelist
2+
3+
enum class WhitelistStatus {
4+
NONE,
5+
ACTIVE,
6+
BLOCKED,
7+
UNKNOWN;
8+
}

surf-cloud-api/surf-cloud-api-common/src/main/kotlin/dev/slne/surf/cloud/api/common/server/CloudServer.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ interface CloudServer : CommonCloudServer {
2727
val lobby: Boolean
2828

2929
suspend fun pullPlayers(players: Collection<CloudPlayer>): @Unmodifiable ObjectList<Pair<CloudPlayer, ConnectionResultEnum>>
30+
31+
companion object {
32+
fun all() = CloudServerManager.retrieveServers()
33+
}
3034
}

0 commit comments

Comments
 (0)