Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.slne.surf.cloud.api.common.event.player.afk

import dev.slne.surf.cloud.api.common.event.player.CloudPlayerEvent
import dev.slne.surf.cloud.api.common.player.CloudPlayer

class AfkStateChangeEvent(val isAfk: Boolean, source: Any, player: CloudPlayer) :
CloudPlayerEvent(source, player)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dev.slne.surf.cloud.core.client.netty.network
import com.google.common.flogger.StackSize
import dev.slne.surf.cloud.api.common.event.offlineplayer.punishment.CloudPlayerPunishEvent
import dev.slne.surf.cloud.api.common.event.offlineplayer.punishment.CloudPlayerPunishmentUpdatedEvent
import dev.slne.surf.cloud.api.common.event.player.afk.AfkStateChangeEvent
import dev.slne.surf.cloud.api.common.netty.network.ConnectionProtocol
import dev.slne.surf.cloud.api.common.netty.network.protocol.respond
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
Expand Down Expand Up @@ -274,6 +275,7 @@ class ClientRunningPacketListenerImpl(
playerManagerImpl.getPlayer(packet.uuid)?.let { player ->
require(player is ClientCloudPlayerImpl<*>) { "Player $player is not a client player" }
player.afk = packet.isAfk
AfkStateChangeEvent(packet.isAfk, this, player).postAndForget()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class CloudPlayerPlaytimeManager(private val service: CloudPlayerService) : Disp
sessionsCache.put(uuid, newSession)
toCreate += uuid to newSession
} else {
if (player.afk) return@forEach
if (player.isAfk()) return@forEach
// Just increment current session
currentSession.accumulatedSeconds++
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.slne.surf.cloud.standalone.player

import dev.slne.surf.cloud.api.common.event.player.afk.AfkStateChangeEvent
import dev.slne.surf.cloud.api.common.netty.network.protocol.await
import dev.slne.surf.cloud.api.common.netty.network.protocol.awaitOrThrow
import dev.slne.surf.cloud.api.common.netty.packet.NettyPacket
Expand Down Expand Up @@ -51,6 +52,7 @@ import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
import java.util.*
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -88,8 +90,7 @@ class StandaloneCloudPlayerImpl(uuid: UUID, name: String, val ip: Inet4Address)
private val ppdcMutex = Mutex()
private var firstSeenCache: ZonedDateTime? = null

var afk = false
private set
private val afk = AtomicBoolean(false)

var sessionStartTime: ZonedDateTime = ZonedDateTime.now()

Expand All @@ -105,7 +106,7 @@ class StandaloneCloudPlayerImpl(uuid: UUID, name: String, val ip: Inet4Address)
}

override fun isAfk(): Boolean {
return afk
return afk.get()
}

override suspend fun currentSessionDuration(): Duration {
Expand All @@ -114,15 +115,15 @@ class StandaloneCloudPlayerImpl(uuid: UUID, name: String, val ip: Inet4Address)
}

fun updateAfkStatus(newValue: Boolean) {
if (newValue == afk) return
afk = newValue
if (!afk.compareAndSet(!newValue, newValue)) return

nettyServer.connection.broadcast(UpdateAFKStatePacket(uuid, afk))
nettyServer.connection.broadcast(UpdateAFKStatePacket(uuid, newValue))
AfkStateChangeEvent(newValue, this, this).postAndForget()

sendText {
appendPrefix()
info("Du bist nun ")
if (afk) {
if (newValue) {
info("AFK und erhältst keine weiteren Paychecks.")
} else {
info("nicht mehr AFK.")
Expand Down