Skip to content

Commit

Permalink
feat: update API
Browse files Browse the repository at this point in the history
  • Loading branch information
Apehum committed May 18, 2024
1 parent 8ef1dbb commit 1cd0526
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 41 deletions.
40 changes: 3 additions & 37 deletions common/src/main/kotlin/su/plo/voice/groups/ActivationListener.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
package su.plo.voice.groups

import su.plo.voice.api.event.EventPriority
import su.plo.voice.api.event.EventSubscribe
import su.plo.voice.api.server.PlasmoBaseVoiceServer
import su.plo.voice.api.server.audio.capture.SelfActivationInfo
import su.plo.voice.api.server.audio.capture.PlayerActivationInfo
import su.plo.voice.api.server.audio.capture.ServerActivation
import su.plo.voice.api.server.audio.source.ServerBroadcastSource
import su.plo.voice.api.server.audio.source.ServerDirectSource
import su.plo.voice.api.server.event.audio.source.ServerSourcePacketEvent
import su.plo.voice.api.server.player.VoicePlayer
import su.plo.voice.proto.packets.tcp.clientbound.SourceAudioEndPacket
import su.plo.voice.proto.packets.tcp.clientbound.SourceInfoPacket
import su.plo.voice.proto.packets.tcp.serverbound.PlayerAudioEndPacket
import su.plo.voice.proto.packets.udp.clientbound.SourceAudioPacket
import su.plo.voice.proto.packets.udp.serverbound.PlayerAudioPacket

class ActivationListener(
voiceServer: PlasmoBaseVoiceServer,
private val groupManager: GroupsManager,
activation: ServerActivation
) {
Expand All @@ -26,8 +19,6 @@ class ActivationListener(
activation.onPlayerActivationEnd(this::onActivationEnd)
}

private val selfActivationInfo = SelfActivationInfo(voiceServer.udpConnectionManager)

private fun onActivation(player: VoicePlayer, packet: PlayerAudioPacket): ServerActivation.Result {
groupManager.sourceByPlayer[player.instance.uuid]?.let {
if (sendAudioPacket(player, it, packet)) {
Expand All @@ -48,28 +39,6 @@ class ActivationListener(
return ServerActivation.Result.IGNORED
}

@EventSubscribe(priority = EventPriority.HIGHEST)
fun onSourceSendPacket(event: ServerSourcePacketEvent) {
val source = event.source as? ServerDirectSource ?: return
val sender = source.sender ?: return

if (!selfActivationInfo.lastPlayerActivationIds
.containsKey(sender.instance.uuid)
) {
return
}

if (event.packet is SourceInfoPacket) {
selfActivationInfo.updateSelfSourceInfo(
sender,
source,
(event.packet as SourceInfoPacket).sourceInfo
)
} else if (event.packet is SourceAudioEndPacket) {
sender.sendPacket(event.packet)
}
}

private fun sendAudioPacket(
player: VoicePlayer,
source: ServerBroadcastSource,
Expand All @@ -80,11 +49,8 @@ class ActivationListener(
packet.data,
source.id, 0.toShort()
)
if (source.sendAudioPacket(sourcePacket, packet.activationId)) {
selfActivationInfo.sendAudioInfo(player, source, packet.activationId, sourcePacket)
return true
}
return false

return source.sendAudioPacket(sourcePacket, PlayerActivationInfo(player, packet))
}

private fun sendAudioEndPacket(
Expand Down
4 changes: 1 addition & 3 deletions common/src/main/kotlin/su/plo/voice/groups/GroupsAddon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ abstract class GroupsAddon : AddonInitializer {
groupManager.groupByPlayer[it.key] = group
} }

voiceServer.eventBus.register(this, ActivationListener(
voiceServer, groupManager, activation
))
voiceServer.eventBus.register(this, ActivationListener(groupManager, activation))

voiceServer.eventBus.register(this, groupManager)
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kotlinx-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", ve

plasmovoice-server = { module = "su.plo.voice.api:server", version.ref = "plasmovoice" }
plasmovoice-proxy = { module = "su.plo.voice.api:proxy", version.ref = "plasmovoice" }
plasmovoice-server-common = { module = "su.plo.voice.api:server-common", version.ref = "plasmovoice" }
plasmovoice-server-common = { module = "su.plo.voice.api:server-proxy-common", version.ref = "plasmovoice" }

[plugins]
plasmovoice = { id = "su.plo.voice.plugin.entrypoints", version.ref = "plasmovoice-plugin" }
Expand Down

0 comments on commit 1cd0526

Please sign in to comment.