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

Commit d2d84e0

Browse files
committed
feat: implement player mute synchronization task and supporting packets
- Added `SynchronizePlayerPunishmentManagers` task for synchronizing player mute data. - Introduced `ClientboundSynchronizePlayerMutes` packet with supporting `STREAM_CODEC`. - Updated synchronization protocols to include new packet type. - Expanded punishment manager with methods to manage raw cached mutes. - Enhanced server-client packet listeners to handle and process mute synchronization.
1 parent e581884 commit d2d84e0

File tree

7 files changed

+104
-6
lines changed

7 files changed

+104
-6
lines changed

surf-cloud-core/surf-cloud-core-client/src/main/kotlin/dev/slne/surf/cloud/core/client/netty/network/ClientSynchronizingPacketListenerImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,18 @@ class ClientSynchronizingPacketListenerImpl(
246246
player.overwritePpdc(tag)
247247
}
248248

249+
override fun handleSynchronizePlayerMutes(packet: ClientboundSynchronizePlayerMutes) {
250+
val player = commonPlayerManagerImpl.getPlayer(packet.playerUuid)
251+
252+
if (player == null) {
253+
log.atWarning()
254+
.log("Received mute update for unknown player (%s)", packet.playerUuid)
255+
return
256+
}
257+
258+
player.punishmentManager.updateMutes(packet.mutes)
259+
}
260+
249261
override fun handlePacket(packet: NettyPacket) {
250262
val listeners = NettyListenerRegistry.getListeners(packet.javaClass) ?: return
251263
if (listeners.isEmpty()) return

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/ClientSynchronizingPacketListener.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ interface ClientSynchronizingPacketListener : ClientCommonPacketListener,
3333
fun handleSyncLargerPlayerPersistentDataContainerChunk(packet: ClientboundSyncLargePlayerPersistentDataContainerChunkPacket)
3434
fun handleSyncLargerPlayerPersistentDataContainerEnd(packet: ClientboundSyncLargePlayerPersistentDataContainerEndPacket)
3535

36+
fun handleSynchronizePlayerMutes(packet: ClientboundSynchronizePlayerMutes)
37+
3638
fun handlePacket(packet: NettyPacket)
3739
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package dev.slne.surf.cloud.core.common.netty.network.protocol.synchronizing
2+
3+
import dev.slne.surf.cloud.api.common.meta.SurfNettyPacket
4+
import dev.slne.surf.cloud.api.common.netty.network.ConnectionProtocol
5+
import dev.slne.surf.cloud.api.common.netty.network.codec.ByteBufCodecs
6+
import dev.slne.surf.cloud.api.common.netty.network.codec.StreamCodec
7+
import dev.slne.surf.cloud.api.common.netty.network.protocol.PacketFlow
8+
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
9+
import dev.slne.surf.cloud.api.common.netty.packet.PacketHandlerMode
10+
import dev.slne.surf.cloud.core.common.netty.network.InternalNettyPacket
11+
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentMuteImpl
12+
import java.util.*
13+
14+
@SurfNettyPacket(
15+
"cloud:clientbound:synchronize_punishments/mutes",
16+
PacketFlow.CLIENTBOUND,
17+
ConnectionProtocol.SYNCHRONIZING,
18+
handlerMode = PacketHandlerMode.NETTY
19+
)
20+
class ClientboundSynchronizePlayerMutes(
21+
val playerUuid: UUID,
22+
val mutes: MutableList<PunishmentMuteImpl>
23+
) : NettyPacket(), InternalNettyPacket<ClientSynchronizingPacketListener> {
24+
companion object {
25+
val STREAM_CODEC = StreamCodec.composite(
26+
ByteBufCodecs.UUID_CODEC,
27+
ClientboundSynchronizePlayerMutes::playerUuid,
28+
PunishmentMuteImpl.STREAM_CODEC.apply(ByteBufCodecs.list()),
29+
ClientboundSynchronizePlayerMutes::mutes,
30+
::ClientboundSynchronizePlayerMutes
31+
)
32+
}
33+
34+
override fun handle(listener: ClientSynchronizingPacketListener) {
35+
listener.handleSynchronizePlayerMutes(this)
36+
}
37+
}

surf-cloud-core/surf-cloud-core-common/src/main/kotlin/dev/slne/surf/cloud/core/common/netty/network/protocol/synchronizing/SynchronizingProtocols.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object SynchronizingProtocols {
3232
.addPacket(ClientboundSyncLargePlayerPersistentDataContainerStartPacket.STREAM_CODEC)
3333
.addPacket(ClientboundSyncLargePlayerPersistentDataContainerEndPacket.STREAM_CODEC)
3434
.addPacket(ClientboundSyncLargePlayerPersistentDataContainerChunkPacket.STREAM_CODEC)
35+
.addPacket(ClientboundSynchronizePlayerMutes.STREAM_CODEC)
3536
}
3637

3738
val CLIENTBOUND by lazy { CLIENTBOUND_TEMPLATE.bind(::SurfByteBuf) }

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import dev.slne.surf.cloud.api.common.player.punishment.type.ban.PunishmentBan
99
import dev.slne.surf.cloud.api.common.player.punishment.type.kick.PunishmentKick
1010
import dev.slne.surf.cloud.api.common.player.punishment.type.mute.PunishmentMute
1111
import dev.slne.surf.cloud.api.common.player.punishment.type.warn.PunishmentWarn
12-
import dev.slne.surf.surfapi.core.api.util.emptyObjectList
13-
import dev.slne.surf.surfapi.core.api.util.toObjectList
1412
import dev.slne.surf.cloud.core.common.player.PunishmentManager
1513
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentBanImpl
1614
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentKickImpl
1715
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentMuteImpl
1816
import dev.slne.surf.cloud.core.common.player.punishment.type.PunishmentWarnImpl
1917
import dev.slne.surf.cloud.core.common.util.bean
18+
import dev.slne.surf.surfapi.core.api.util.emptyObjectList
2019
import dev.slne.surf.surfapi.core.api.util.logger
20+
import dev.slne.surf.surfapi.core.api.util.toObjectList
2121
import it.unimi.dsi.fastutil.objects.ObjectList
2222
import org.jetbrains.annotations.Unmodifiable
2323
import java.util.*
@@ -66,6 +66,28 @@ class CloudPlayerPunishmentManagerImpl(private val playerUuid: UUID) :
6666
return (if (sort) mutes.sorted() else mutes).toObjectList()
6767
}
6868

69+
fun rawCachedMutes(): MutableList<PunishmentMuteImpl> {
70+
return cachedMutes
71+
}
72+
73+
fun updateMutes(updated: List<PunishmentMuteImpl>) {
74+
if (!cachedMutesFetched) {
75+
cachedMutes = CopyOnWriteArrayList(updated)
76+
cachedMutesFetched = true
77+
return
78+
}
79+
80+
val iterator = cachedMutes.iterator()
81+
while (iterator.hasNext()) {
82+
val mute = iterator.next()
83+
if (updated.any { it.punishmentId == mute.punishmentId }) {
84+
iterator.remove()
85+
}
86+
}
87+
88+
cachedMutes.addAll(updated)
89+
}
90+
6991
@Suppress("UNCHECKED_CAST")
7092
suspend fun cacheMutes() {
7193
cachedMutes = CopyOnWriteArrayList(fetchMutes() as ObjectList<PunishmentMuteImpl>)

surf-cloud-standalone/src/main/kotlin/dev/slne/surf/cloud/standalone/netty/server/network/ServerSynchronizingPacketListenerImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import dev.slne.surf.cloud.core.common.netty.registry.listener.NettyListenerRegi
1919
import dev.slne.surf.cloud.core.common.plugin.task.CloudSynchronizeTaskManager
2020
import dev.slne.surf.cloud.standalone.netty.server.NettyServerImpl
2121
import dev.slne.surf.cloud.standalone.netty.server.ServerClientImpl
22-
import dev.slne.surf.cloud.standalone.netty.server.network.config.SetVelocitySecretTask
23-
import dev.slne.surf.cloud.standalone.netty.server.network.config.SynchronizeRegistriesTask
24-
import dev.slne.surf.cloud.standalone.netty.server.network.config.SynchronizeServersTask
25-
import dev.slne.surf.cloud.standalone.netty.server.network.config.SynchronizeUserTask
22+
import dev.slne.surf.cloud.standalone.netty.server.network.config.*
2623
import dev.slne.surf.cloud.standalone.sync.SyncRegistryImpl
2724
import dev.slne.surf.surfapi.core.api.util.logger
2825
import kotlinx.coroutines.launch
@@ -59,6 +56,8 @@ class ServerSynchronizingPacketListenerImpl(
5956
SynchronizeServersTask.execute(client)
6057
SynchronizeRegistriesTask.execute(client)
6158
SynchronizeUserTask.execute(client)
59+
SynchronizePlayerPunishmentManagers.execute(client)
60+
6261
CloudSynchronizeTaskManager.executeTasks(client)
6362

6463
state = State.WAIT_FOR_CLIENT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package dev.slne.surf.cloud.standalone.netty.server.network.config
2+
3+
import dev.slne.surf.cloud.api.common.netty.NettyClient
4+
import dev.slne.surf.cloud.api.common.plugin.spring.task.CloudInitialSynchronizeTask
5+
import dev.slne.surf.cloud.core.common.netty.network.protocol.synchronizing.ClientboundSynchronizePlayerMutes
6+
import dev.slne.surf.cloud.standalone.player.StandaloneCloudPlayerImpl
7+
import dev.slne.surf.cloud.standalone.player.standalonePlayerManagerImpl
8+
9+
object SynchronizePlayerPunishmentManagers : CloudInitialSynchronizeTask {
10+
override suspend fun execute(client: NettyClient) {
11+
val players = standalonePlayerManagerImpl.getRawOnlinePlayers()
12+
synchronizeCachedMutes(client, players)
13+
}
14+
15+
private fun synchronizeCachedMutes(
16+
client: NettyClient,
17+
players: List<StandaloneCloudPlayerImpl>
18+
) {
19+
for (player in players) {
20+
val mutes = player.punishmentManager.rawCachedMutes()
21+
if (mutes.isEmpty()) continue
22+
client.fireAndForget(ClientboundSynchronizePlayerMutes(player.uuid, mutes))
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)