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

Commit 7415ea0

Browse files
committed
fix: update punishment cache to only fetch active mutes and bans
- Renamed `mutes` and `bans` to `activeMutes` and `activeBans` for clarity. - Ensured active punishments are correctly fetched and used across the system. - Added `allowed` property to punishment result types for improved validation logic.
1 parent f5dbe9f commit 7415ea0

File tree

5 files changed

+28
-15
lines changed

5 files changed

+28
-15
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,35 @@ interface PunishmentLoginValidation {
9595

9696
@NonExtendable
9797
interface PunishmentCache {
98-
val mutes: List<PunishmentMute>
99-
val bans: List<PunishmentBan>
98+
val activeMutes: List<PunishmentMute>
99+
val activeBans: List<PunishmentBan>
100100
val kicks: List<PunishmentKick>
101101
val warnings: List<PunishmentWarn>
102102
}
103103

104104
@Serializable
105+
@Suppress("ClassName")
105106
sealed interface Result {
107+
val allowed: Boolean
106108

107109
@Serializable
108-
data object ALLOWED : Result
110+
data object ALLOWED : Result {
111+
override val allowed: Boolean = true
112+
}
109113

110114
@Serializable
111-
data class DENIED(val reason: Component) : Result
115+
data class DENIED(val reason: Component) : Result {
116+
override val allowed: Boolean = false
117+
}
112118

113119
@Serializable
114-
data object ERROR : Result
120+
data object ERROR : Result {
121+
override val allowed: Boolean = false
122+
}
123+
124+
@Serializable
125+
data object NOT_HANDLED : Result {
126+
override val allowed: Boolean = true
127+
}
115128
}
116129
}

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/player/PunishmentCacheImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import kotlinx.serialization.Serializable
99

1010
@Serializable
1111
data class PunishmentCacheImpl(
12-
override val mutes: List<PunishmentMuteImpl>,
13-
override val bans: List<PunishmentBanImpl>,
12+
override val activeMutes: List<PunishmentMuteImpl>,
13+
override val activeBans: List<PunishmentBanImpl>,
1414
override val kicks: List<PunishmentKickImpl>,
1515
override val warnings: List<PunishmentWarnImpl>,
1616
) : PunishmentLoginValidation.PunishmentCache

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/player/punishment/CloudPlayerPunishmentManagerBridgeImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class CloudPlayerPunishmentManagerBridgeImpl : CloudPlayerPunishmentManagerBridg
9898
return PrePlayerJoinTask.Result.ERROR
9999
}
100100

101-
val longestBan = cache.bans.find { it.active }
101+
val longestBan = cache.activeBans.find { it.active }
102102
val banResult = if (longestBan != null) {
103103
PrePlayerJoinTask.Result.DENIED(
104104
MessageManager.Punish.Ban(longestBan).banDisconnectComponent()
@@ -114,7 +114,7 @@ class CloudPlayerPunishmentManagerBridgeImpl : CloudPlayerPunishmentManagerBridg
114114

115115
for (validation in loginValidations) {
116116
val result = validation.performLoginCheck(player, cache)
117-
if (result !is PunishmentLoginValidation.Result.ALLOWED) {
117+
if (!result.allowed) {
118118
return wrap(result)
119119
}
120120
}
@@ -126,6 +126,7 @@ class CloudPlayerPunishmentManagerBridgeImpl : CloudPlayerPunishmentManagerBridg
126126
PunishmentLoginValidation.Result.ALLOWED -> PrePlayerJoinTask.Result.ALLOWED
127127
is PunishmentLoginValidation.Result.DENIED -> PrePlayerJoinTask.Result.DENIED(from.reason)
128128
PunishmentLoginValidation.Result.ERROR -> PrePlayerJoinTask.Result.ERROR
129+
else -> PrePlayerJoinTask.Result.ERROR
129130
}
130131
}
131132
}

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/player/punishment/PunishmentManagerImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,14 @@ class PunishmentManagerImpl(private val service: PunishmentService) : Punishment
343343
}
344344

345345
private suspend fun fetchPunishmentCache(uuid: UUID): PunishmentCacheImpl = coroutineScope {
346-
val mutesDeferred = async { fetchMutes(uuid, onlyActive = false) }
347-
val bansDeferred = async { fetchBans(uuid, onlyActive = false) }
346+
val mutesDeferred = async { fetchMutes(uuid, onlyActive = true) }
347+
val bansDeferred = async { fetchBans(uuid, onlyActive = true) }
348348
val kicksDeferred = async { fetchKicks(uuid) }
349349
val warningsDeferred = async { fetchWarnings(uuid) }
350350

351351
PunishmentCacheImpl(
352-
mutes = mutesDeferred.await().sorted().toObjectList(),
353-
bans = bansDeferred.await().sorted().toObjectList(),
352+
activeMutes = mutesDeferred.await().sorted().toObjectList(),
353+
activeBans = bansDeferred.await().sorted().toObjectList(),
354354
kicks = kicksDeferred.await().toObjectList(),
355355
warnings = warningsDeferred.await().toObjectList()
356356
)

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/player/punishment/handler/DefaultBanPunishmentHandler.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class DefaultBanPunishmentHandler(private val punishmentManager: PunishmentManag
5858
return PrePlayerJoinTask.Result.ERROR
5959
}
6060
val player = player as StandaloneCloudPlayerImpl
61-
val activeBans = cache.bans.filter { it.active }
62-
activeBans.mapAsync { it.attachIpAddress(player.ip) }.awaitAll()
61+
cache.activeBans.mapAsync { it.attachIpAddress(player.ip) }.awaitAll()
6362

6463
return PrePlayerJoinTask.Result.ALLOWED
6564
}

0 commit comments

Comments
 (0)